tsdevicedialog/tsdevicedialogplugin/src/tsmodel.cpp
changeset 115 3ab5c078b490
parent 109 e0aa398e6810
child 116 305818acdca4
equal deleted inserted replaced
109:e0aa398e6810 115:3ab5c078b490
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: tsmodel.cpp
    14 * Description: tsmodel.cpp
    15 *
    15 *
    16 */
    16 */
       
    17 #include "tsmodel.h"
       
    18 
       
    19 #include <QVariant>
       
    20 #include <QList>
       
    21 
    17 #include <HbIcon>
    22 #include <HbIcon>
    18 #include <qvariant.h>
    23 
    19 #include <qlist.h>
       
    20 #include <afstorageglobals.h>
    24 #include <afstorageglobals.h>
    21 
    25 
    22 #ifdef Q_OS_SYMBIAN
    26 #ifdef Q_OS_SYMBIAN
    23 #include <XQSettingsManager>
    27 #include <XQSettingsManager>
    24 #include <apaid.h>
    28 #include <apaid.h>
    25 
    29 
    26 const int TSDeviceDialogUid = 0x2002677F;
    30 const int TSDeviceDialogUid = 0x2002677F;
    27 const int ItemsLimit = 0x00000001;
    31 const int ItemsLimit = 0x00000001;
    28 #endif
    32 #endif
    29 
    33 
    30 #include "tsmodel.h"
       
    31 #include "tsmodelitem.h"
    34 #include "tsmodelitem.h"
    32 #include "tsentrymodelitem.h"
    35 #include "tsentrymodelitem.h"
    33 #include "tsactivitymodelitem.h"
    36 #include "tsactivitymodelitem.h"
    34 #include "tsdataroles.h"
    37 #include "tsdataroles.h"
       
    38 #include "tstaskchangeinfo.h"
    35 
    39 
    36 const int maxItems(10);
    40 const int maxItems(10);
    37 /*!
    41 /*!
    38     \class TsModel
    42     \class TsModel
    39     \ingroup group_tsdevicedialogplugin
    43     \ingroup group_tsdevicedialogplugin
    67         }
    71         }
    68     }
    72     }
    69     iAppArcSession.Connect();
    73     iAppArcSession.Connect();
    70 #endif
    74 #endif
    71 
    75 
    72     connect(&activitySrv, 
    76     connect(&activitySrv,
    73             SIGNAL(dataChanged()), 
    77 	SIGNAL(dataChanged()),
    74             this, 
    78 			 this,
    75             SLOT(updateModel()));
    79 			 SLOT(updateActivities()));
    76     connect(&applicationSrv, 
    80     connect(&applicationSrv,
    77             SIGNAL(taskListChanged()), 
    81 	        SIGNAL(taskListChanged()),
    78             this, 
    82 			this,
    79             SLOT(updateModel()));
    83 			SLOT(updateApplications()));
    80     updateModel();
    84 
       
    85     fullUpdate();    
    81 }
    86 }
    82 
    87 
    83 /*!
    88 /*!
    84     Destructor
    89     Destructor
    85 */
    90 */
   100 {
   105 {
   101     Q_UNUSED(parent);
   106     Q_UNUSED(parent);
   102     return mEntries.count();
   107     return mEntries.count();
   103 }
   108 }
   104 
   109 
       
   110 bool TsModel::insertRows(int row, int count, TsModelItem* item, const QModelIndex & parent)
       
   111 {
       
   112     beginInsertRows(parent, row, row+count-1);
       
   113     mEntries.insert(row, item);
       
   114     endInsertRows();
       
   115     return true;
       
   116 }
       
   117 
       
   118 bool TsModel::removeRows(int row, int count, const QModelIndex & parent)
       
   119 {
       
   120     beginRemoveRows(parent, row, row + count - 1);
       
   121     mEntries.removeAt(row);
       
   122     endRemoveRows();
       
   123     return true;
       
   124 }
       
   125 
       
   126 
       
   127 bool TsModel::moveRows(int oldPosition, int newPosition, const QModelIndex & parent)
       
   128 {
       
   129    beginMoveRows(parent, oldPosition, oldPosition, parent, newPosition);
       
   130    mEntries.move(oldPosition, newPosition);
       
   131    endMoveRows();
       
   132    return true;
       
   133 }
       
   134 
       
   135 
       
   136 bool TsModel::updateRows(int row, TsModelItem* item)
       
   137 {
       
   138     TsModelItem *oldItem = mEntries.at(row);
       
   139     mEntries[row] = item;
       
   140     delete oldItem;
       
   141 
       
   142     emit dataChanged(index(row),index(row));
       
   143     return true;
       
   144 }
       
   145 
   105 /*!
   146 /*!
   106     Returns appropiate model's data
   147     Returns appropiate model's data
   107     \param index model index
   148     \param index model index
   108     \param role which data role to return
   149     \param role which data role to return
   109     \retval models data
   150     \retval models data
   148 }
   189 }
   149 
   190 
   150 /*!
   191 /*!
   151     Updates model with fresh entries
   192     Updates model with fresh entries
   152 */
   193 */
   153 void TsModel::updateModel()
   194 void TsModel::updateApplications()
   154 {
   195 {
   155     //clear current data
   196     RDebug::Printf( "TsModel::updateApps \n");
   156     beginResetModel();
   197     RDebug::Printf(" from %d \n: ",this);
       
   198     QList<TsTaskChange>  changes(mApplicationService.changeList());
       
   199     
       
   200     if(changes.count() == 0)
       
   201     {
       
   202         //no applications - only activities on list
       
   203         return;
       
   204     }
       
   205     //check 1st item whether we have cancel change - if so reset model
       
   206     if (changes[0].first.changeType() == TsTaskChangeInfo::EChangeCancel) {
       
   207         fullUpdate();
       
   208         return;
       
   209     }
       
   210     for (int iter(0); iter < changes.count(); iter++) {
       
   211         switch (changes[iter].first.changeType()) {
       
   212             case TsTaskChangeInfo::EChangeDelete :
       
   213                 removeRows(changes[iter].first.oldOffset(), 1);
       
   214             break;
       
   215             case TsTaskChangeInfo::EChangeInsert :
       
   216                 insertRows(changes[iter].first.newOffset(), 1,
       
   217                     new TsEntryModelItem(changes[iter].second));
       
   218             break;
       
   219             case TsTaskChangeInfo::EChangeMove :
       
   220                 moveRows(changes[iter].first.oldOffset(), changes[iter].first.newOffset());
       
   221             break;            
       
   222             case TsTaskChangeInfo::EChangeUpdate :
       
   223                 updateRows(changes[iter].first.oldOffset(),
       
   224                            new TsEntryModelItem(changes[iter].second));
       
   225             break;
       
   226             default:
       
   227             break;
       
   228         }
       
   229     }
       
   230 
       
   231     //because delete entries are at end of changelist - iterate backwards
       
   232 
       
   233 }
       
   234 
       
   235 /*!
       
   236     Updates model with fresh entries
       
   237 */
       
   238 void TsModel::updateActivities()
       
   239 {
       
   240     //as for now we need full update when activities change
       
   241     fullUpdate();
       
   242 }
       
   243 
       
   244 /*!
       
   245     reset model using full application and activities lists
       
   246 */
       
   247 void TsModel::fullUpdate()
       
   248 {
   157     qDeleteAll(mEntries);
   249     qDeleteAll(mEntries);
   158     mEntries.clear();
   250     mEntries.clear();
   159     getApplications();
   251     getApplications();
   160     getActivities();
   252     getActivities();
   161     endResetModel();
   253     endResetModel();
   165 /*!
   257 /*!
   166     Read list of running applications
   258     Read list of running applications
   167 */
   259 */
   168 void TsModel::getApplications()
   260 void TsModel::getApplications()
   169 {
   261 {
   170     //get running applications
   262     RDebug::Printf( "CTsTaskMonitorClientImpl::RunL \n");
   171     QList< QSharedPointer<TsTask> > tasks(mApplicationService.taskList());
   263     //get all running applications and append to entries list
   172     foreach (QSharedPointer<TsTask> taskData, tasks) {
   264     TsModelItem *entry(0);
   173         mEntries.append(new TsEntryModelItem(taskData));
   265     QList< TsTaskChange> tasks(mApplicationService.changeList(true));
       
   266     foreach (TsTaskChange taskData, tasks) {
       
   267         if (!taskData.second.isNull()) {
       
   268             entry = new TsEntryModelItem(taskData.second);
       
   269             if (entry) {
       
   270                 mEntries.append(entry);
       
   271             }
       
   272         }
   174     }
   273     }
   175 }
   274 }
   176 
   275 
   177 /*!
   276 /*!
   178     Read current activities
   277     Read current activities