homescreenapp/serviceproviders/hsmenuserviceprovider/src/hsmenuservice.cpp
changeset 81 7dd137878ff8
parent 71 1db7cc813a4e
child 86 e4f038c420f7
equal deleted inserted replaced
76:3916af29624a 81:7dd137878ff8
    40  Returns all applications model
    40  Returns all applications model
    41  \param sortAttribute ::  SortAttribute
    41  \param sortAttribute ::  SortAttribute
    42  \retval HsMenuItemModel: AllApplicationsModel
    42  \retval HsMenuItemModel: AllApplicationsModel
    43  */
    43  */
    44 HsMenuItemModel *HsMenuService::getAllApplicationsModel(
    44 HsMenuItemModel *HsMenuService::getAllApplicationsModel(
    45     HsSortAttribute sortAttribute)
    45     Hs::HsSortAttribute sortAttribute)
    46 {
    46 {
    47     qDebug() << "HsMenuService::getAllApplicationsModel sortAttribute:"
    47     qDebug() << "HsMenuService::getAllApplicationsModel sortAttribute:"
    48              << sortAttribute;
    48              << sortAttribute;
    49     HSMENUTEST_FUNC_ENTRY("HsMenuService::getAllApplicationsModel");
    49     HSMENUTEST_FUNC_ENTRY("HsMenuService::getAllApplicationsModel");
    50     CaQuery query;
    50     CaQuery query;
    51     query.setEntryRoles(ItemEntryRole);
    51     query.setEntryRoles(ItemEntryRole);
    52     query.addEntryTypeName(applicationTypeName());
    52     query.addEntryTypeName(Hs::applicationTypeName);
    53     query.addEntryTypeName(urlTypeName());
    53     query.addEntryTypeName(Hs::urlTypeName);
    54     query.addEntryTypeName(widgetTypeName());
    54     query.addEntryTypeName(Hs::widgetTypeName);
    55     query.addEntryTypeName(templatedApplicationTypeName());
    55     query.addEntryTypeName(Hs::templatedApplicationTypeName);
    56     query.setFlagsOn(VisibleEntryFlag);
    56     query.setFlagsOn(VisibleEntryFlag);
    57     query.setFlagsOff(MissingEntryFlag);
    57     query.setFlagsOff(MissingEntryFlag);
    58     query.setSort(HsMenuServiceUtils::sortBy(sortAttribute),
    58     query.setSort(HsMenuServiceUtils::sortBy(sortAttribute),
    59                   HsMenuServiceUtils::sortOrder(sortAttribute));
    59                   HsMenuServiceUtils::sortOrder(sortAttribute));
    60     HsMenuItemModel *model = new HsMenuItemModel(query);
    60     HsMenuItemModel *model = new HsMenuItemModel(query);
    83  Returns native and java applications.
    83  Returns native and java applications.
    84  \param sortAttribute :: SortAttribute
    84  \param sortAttribute :: SortAttribute
    85  \retval HsMenuItemModel: installed model
    85  \retval HsMenuItemModel: installed model
    86  */
    86  */
    87 HsMenuItemModel *HsMenuService::getInstalledModel(
    87 HsMenuItemModel *HsMenuService::getInstalledModel(
    88     HsSortAttribute sortAttribute)
    88     Hs::HsSortAttribute sortAttribute)
    89 {
    89 {
    90     //TODO get proper items
    90     //TODO get proper items
    91     qDebug() << "HsMenuService::getInstalledModel" << "sortAttribute:"
    91     qDebug() << "HsMenuService::getInstalledModel" << "sortAttribute:"
    92              << sortAttribute;
    92              << sortAttribute;
    93     HSMENUTEST_FUNC_ENTRY("HsMenuService::getInstalledModel");
    93     HSMENUTEST_FUNC_ENTRY("HsMenuService::getInstalledModel");
    94     CaQuery query;
    94     CaQuery query;
    95     query.addEntryTypeName(packageTypeName());
    95     query.addEntryTypeName(Hs::packageTypeName);
    96     query.setFlagsOn(VisibleEntryFlag | RemovableEntryFlag);
    96     query.setFlagsOn(VisibleEntryFlag | RemovableEntryFlag);
    97     query.setFlagsOff(MissingEntryFlag);
    97     query.setFlagsOff(MissingEntryFlag);
    98     query.setSort(HsMenuServiceUtils::sortBy(sortAttribute),
    98     query.setSort(HsMenuServiceUtils::sortBy(sortAttribute),
    99                   HsMenuServiceUtils::sortOrder(sortAttribute));
    99                   HsMenuServiceUtils::sortOrder(sortAttribute));
   100     HsMenuItemModel *model = new HsMenuItemModel(query);
   100     HsMenuItemModel *model = new HsMenuItemModel(query);
   107  \param collectionId ::  id of this collection
   107  \param collectionId ::  id of this collection
   108  \param sortAttribute ::  SortAttribute
   108  \param sortAttribute ::  SortAttribute
   109  \retval HsMenuItemModel: collection model
   109  \retval HsMenuItemModel: collection model
   110  */
   110  */
   111 HsMenuItemModel *HsMenuService::getCollectionModel(int collectionId,
   111 HsMenuItemModel *HsMenuService::getCollectionModel(int collectionId,
   112         HsSortAttribute sortAttribute, const QString &collectionType)
   112         Hs::HsSortAttribute sortAttribute, const QString &collectionType)
   113 {
   113 {
   114     qDebug() << "HsMenuService::getCollectionModel sortAttribute:"
   114     qDebug() << "HsMenuService::getCollectionModel sortAttribute:"
   115              << sortAttribute;
   115              << sortAttribute;
   116     HSMENUTEST_FUNC_ENTRY("HsMenuService::getCollectionModel");
   116     HSMENUTEST_FUNC_ENTRY("HsMenuService::getCollectionModel");
   117     CaQuery query;
   117     CaQuery query;
   118     query.setFlagsOff(MissingEntryFlag);
   118     query.setFlagsOff(MissingEntryFlag);
   119     if (collectionType == collectionDownloadedTypeName()) {
   119     if (collectionType == Hs::collectionDownloadedTypeName) {
   120         query.setFlagsOn(RemovableEntryFlag | VisibleEntryFlag);
   120         query.setFlagsOn(RemovableEntryFlag | VisibleEntryFlag);
   121     } else {
   121     } else {
   122         query.setFlagsOn(VisibleEntryFlag);
   122         query.setFlagsOn(VisibleEntryFlag);
   123     }
   123     }
   124     if(!collectionId) {
   124     if(!collectionId) {
   184  */
   184  */
   185 int HsMenuService::executeAction(int entryId, const QString &actionName)
   185 int HsMenuService::executeAction(int entryId, const QString &actionName)
   186 {
   186 {
   187     qDebug() << "HsMenuService::executeAction entryId:" << entryId
   187     qDebug() << "HsMenuService::executeAction entryId:" << entryId
   188              << "actionName:" << actionName;
   188              << "actionName:" << actionName;
   189     int ret = CaService::instance()->executeCommand(entryId, actionName);
   189     return CaService::instance()->executeCommand(entryId, actionName);
   190 
       
   191 /*    // if its remove action we need to mark all items 
       
   192     // that are being uninstalled
       
   193     if (actionName == caCmdRemove && ret == 0) {
       
   194         QSharedPointer<CaEntry> entry(
       
   195                 CaService::instance()->getEntry(entryId));
       
   196         if (!entry.isNull()) {
       
   197             QString componentId = entry->attribute(
       
   198                     componentIdAttributeName());
       
   199             
       
   200             CaQuery query;
       
   201             query.setAttribute(componentIdAttributeName(), componentId);
       
   202             QList< QSharedPointer<CaEntry> > entries 
       
   203                     = CaService::instance()->getEntries(query);
       
   204             
       
   205             for (int i = 0; i < entries.count(); i++) {
       
   206                 entries[i]->setFlags(
       
   207                         entries.first()->flags()| UninstallEntryFlag);
       
   208                 CaService::instance()->updateEntry(*entries[i]);
       
   209             }
       
   210         }
       
   211     }*/
       
   212     return ret;
       
   213 }
   190 }
   214 
   191 
   215 /*!
   192 /*!
   216  Launch task switcher
   193  Launch task switcher
   217  \retval boolean launching status
   194  \retval boolean launching status
   219 bool HsMenuService::launchTaskSwitcher()
   196 bool HsMenuService::launchTaskSwitcher()
   220 {
   197 {
   221     qDebug() << "HsMenuService::launchTaskSwitcher";
   198     qDebug() << "HsMenuService::launchTaskSwitcher";
   222     HbDeviceDialog deviceDialog;
   199     HbDeviceDialog deviceDialog;
   223     QVariantMap params;
   200     QVariantMap params;
   224     return deviceDialog.show(TS_DEVICE_DIALOG_URI, params);
   201     return deviceDialog.show(Hs::tsDeviceDialogUri, params);
   225 }
   202 }
   226 
   203 
   227 /*!
   204 /*!
   228  Adds new collection
   205  Adds new collection
   229  \param name of the collection
   206  \param name of the collection
   233 {
   210 {
   234     qDebug() << "HsMenuService::addCollection name: " << name;
   211     qDebug() << "HsMenuService::addCollection name: " << name;
   235     HSMENUTEST_FUNC_ENTRY("HsMenuService::createCollection");
   212     HSMENUTEST_FUNC_ENTRY("HsMenuService::createCollection");
   236     int entryId = 0;
   213     int entryId = 0;
   237     CaEntry collection(GroupEntryRole);
   214     CaEntry collection(GroupEntryRole);
   238     collection.setEntryTypeName(collectionTypeName());
   215     collection.setEntryTypeName(Hs::collectionTypeName);
   239     collection.setText(name);
   216     collection.setText(name);
   240     collection.setAttribute(groupNameAttributeName(),name);
   217     collection.setAttribute(Hs::groupNameAttributeName,name);
   241     CaIconDescription iconDescription;
   218     CaIconDescription iconDescription;
   242     iconDescription.setFilename(defaultCollectionIconId());
   219     iconDescription.setFilename(Hs::defaultCollectionIconId);
   243     collection.setIconDescription(iconDescription);
   220     collection.setIconDescription(iconDescription);
   244     QSharedPointer<CaEntry> entry = CaService::instance()->createEntry(collection);
   221     QSharedPointer<CaEntry> entry = CaService::instance()->createEntry(collection);
   245     if (!entry.isNull()) {
   222     if (!entry.isNull()) {
   246         qDebug() << "HsMenuService::addCollection entry" << entry;
   223         qDebug() << "HsMenuService::addCollection entry" << entry;
   247         entryId = entry->id();
   224         entryId = entry->id();
   354         //sorting is set to (default, ascending) to assure that
   331         //sorting is set to (default, ascending) to assure that
   355         //proper entry is fetched, somebody can add item with
   332         //proper entry is fetched, somebody can add item with
   356         //"menucollections" typename to the storage, but even if he or she
   333         //"menucollections" typename to the storage, but even if he or she
   357         //do this we fetch entry that we wanted
   334         //do this we fetch entry that we wanted
   358         collectionsQuery.setSort(DefaultSortAttribute, Qt::AscendingOrder);
   335         collectionsQuery.setSort(DefaultSortAttribute, Qt::AscendingOrder);
   359         collectionsQuery.addEntryTypeName(menuCollectionsTypeName());
   336         collectionsQuery.addEntryTypeName(Hs::menuCollectionsTypeName);
   360         QList<int> ids = CaService::instance()->getEntryIds(
   337         QList<int> ids = CaService::instance()->getEntryIds(
   361                              collectionsQuery);
   338                              collectionsQuery);
   362         Q_ASSERT(ids.count() > 0);
   339         Q_ASSERT(ids.count() > 0);
   363         mAllCollectionsId = ids.at(0);
   340         mAllCollectionsId = ids.at(0);
   364         qDebug() << "HsMenuService::HsMenuService mAllCollectionsId"
   341         qDebug() << "HsMenuService::HsMenuService mAllCollectionsId"
   398 /*!
   375 /*!
   399  Touch action on an entry.
   376  Touch action on an entry.
   400  \param entryId of this entry.
   377  \param entryId of this entry.
   401  \retval boolean error code.
   378  \retval boolean error code.
   402  */
   379  */
   403 bool HsMenuService::touch(int entryId)
   380 void HsMenuService::touch(int entryId)
   404 {
   381 {
   405     QSharedPointer<CaEntry> entry = CaService::instance()->getEntry(entryId);
   382     QSharedPointer<CaEntry> entry = CaService::instance()->getEntry(entryId);
   406     return CaService::instance()->touch(* entry);
   383     if (entry->flags() & RemovableEntryFlag &&
       
   384         (entry->flags() & UsedEntryFlag) == 0 &&
       
   385         entry->role() == ItemEntryRole &&
       
   386         entry->entryTypeName() != QString(Hs::packageTypeName)) {
       
   387             CaService::instance()->touch(* entry);
       
   388     }
       
   389 }
       
   390 
       
   391 /*!
       
   392  Touch action on an lists of entries.
       
   393  \param entryIdList of this entry.
       
   394  \retval boolean error code.
       
   395  */
       
   396 void HsMenuService::touch(const QList<int> &entryIdList)
       
   397 {
       
   398     CaQuery query;
       
   399     query.setFlagsOn(RemovableEntryFlag);
       
   400     query.setFlagsOff(UsedEntryFlag);
       
   401     query.setEntryRoles(ItemEntryRole);
       
   402     QList<int> removableUnTouchEntries =
       
   403         CaService::instance()->getEntryIds(query);
       
   404     foreach (int item, entryIdList) {
       
   405         if (removableUnTouchEntries.contains(item)) {
       
   406             touch(item);
       
   407         }
       
   408     }
   407 }
   409 }
   408 
   410 
   409 /*!
   411 /*!
   410  Launch SoftwareUpdateApplication
   412  Launch SoftwareUpdateApplication
   411  \retval int launching status, 0 if no errors
   413  \retval int launching status, 0 if no errors
   412  */
   414  */
   413 int HsMenuService::launchSoftwareUpdate()
   415 int HsMenuService::launchSoftwareUpdate()
   414 {
   416 {
   415     qDebug() << "HsMenuService::launchSoftwareUpdate";
   417     qDebug() << "HsMenuService::launchSoftwareUpdate";
   416     QScopedPointer<CaEntry> tsEntry(new CaEntry);
   418     QScopedPointer<CaEntry> tsEntry(new CaEntry);
   417     tsEntry->setEntryTypeName(applicationTypeName());
   419     tsEntry->setEntryTypeName(Hs::applicationTypeName);
   418     tsEntry->setAttribute(
   420     tsEntry->setAttribute(
   419             applicationUidEntryKey(), QString::number(softwareUpdateApplicationUid));
   421             Hs::applicationUidEntryKey, QString::number(Hs::softwareUpdateApplicationUid));
   420     int retval = CaService::instance()->executeCommand(*tsEntry,
   422     int retval = CaService::instance()->executeCommand(*tsEntry,
   421             openActionIdentifier());
   423             Hs::openActionIdentifier);
   422     return retval;
   424     return retval;
   423 }
   425 }