homescreenapp/hsutils/src/hsmenueventfactory.cpp
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
equal deleted inserted replaced
5:c743ef5928ba 35:f9ce957a272c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Menu Event Factory.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "hsmenuevent.h"
       
    19 #include "hsmenueventfactory.h"
       
    20 #include "hsapp_defs.h"
       
    21 
       
    22 
       
    23 /*!
       
    24     \class HsMenuEventFactory
       
    25     \ingroup group_hsmenustateplugin
       
    26 
       
    27     \brief Menu event factory class.
       
    28 
       
    29     \sa HsMenuEvent
       
    30 */
       
    31 
       
    32 /*!
       
    33     \fn HsMenuEvenFactory::HsMenuEventFactory()
       
    34     Not used. Declared private and undefined to prevent creating
       
    35     instances of the class.
       
    36 */
       
    37 
       
    38 /*!
       
    39     Prepares event triggered on add to home screen user request.
       
    40     \param entryId Id of an item to be added to home screen.
       
    41     \param entryTypeName Name of the entry type (e.g. application, widget).
       
    42     \param uri Widget uri.
       
    43     \param library Widget library path and name.
       
    44     \return Event for adding the widget to homescreen.
       
    45 */
       
    46 QEvent *HsMenuEventFactory::createAddToHomeScreenEvent(
       
    47     int entryId,
       
    48     const QString &entryTypeName,
       
    49     const QString &uri,
       
    50     const QString &library)
       
    51 {
       
    52     // get CaEntry type, and if widget get uri and library stored as properties...
       
    53     QVariantMap params;
       
    54 
       
    55     params.insert(itemIdKey(), entryId);
       
    56 
       
    57     if (entryTypeName == widgetTypeName()) {
       
    58         params.insert(
       
    59             widgetUriAttributeName(),
       
    60             uri);
       
    61 
       
    62         params.insert(
       
    63             widgetLibraryAttributeName(),
       
    64             library);
       
    65 
       
    66         params.insert(entryTypeNameKey(), entryTypeName);
       
    67     }
       
    68 
       
    69     return new HsMenuEvent(HsMenuEvent::AddToHomeScreen, params);
       
    70 }
       
    71 
       
    72 /*!
       
    73     Creates an HsMenuEvent::OpenCollection event.
       
    74 
       
    75     \param itemId Item id of the collection to be opened.
       
    76     \param collectionType type of the collection to be opened.
       
    77     \return Open collection event.
       
    78  */
       
    79 QEvent *HsMenuEventFactory::createOpenCollectionEvent(int itemId,
       
    80         const QString &collectionType)
       
    81 {
       
    82     QVariantMap params;
       
    83     params.insert(itemIdKey(), itemId);
       
    84     params.insert(entryTypeNameKey(), collectionType);
       
    85     return new HsMenuEvent(HsMenuEvent::OpenCollection, params);
       
    86 }
       
    87 
       
    88 /*!
       
    89     Creates an HsMenuEvent::RenameCollection event.
       
    90 
       
    91     \param aItemId Item id of the collection to be renamed.
       
    92     \return Rename collection event.
       
    93  */
       
    94 QEvent *HsMenuEventFactory::createRenameCollectionEvent(int aItemId)
       
    95 {
       
    96     QVariantMap params;
       
    97     params.insert(itemIdKey(), aItemId);
       
    98     return new HsMenuEvent(HsMenuEvent::RenameCollection, params);
       
    99 }
       
   100 
       
   101 /*!
       
   102     Creates an HsMenuEvent::RenameCollection event.
       
   103 
       
   104     \return Rename collection event.
       
   105  */
       
   106 QEvent *HsMenuEventFactory::createNewCollectionEvent()
       
   107 {
       
   108     QVariantMap params;
       
   109     params.insert(itemIdKey(), 0);
       
   110     return new HsMenuEvent(HsMenuEvent::CreateCollection, params);
       
   111 }
       
   112 
       
   113 /*!
       
   114     Creates an HsMenuEvent::DeleteCollection event.
       
   115 
       
   116     \param aItemId Item id of the collection to be deleted.
       
   117     \return Delete collection event.
       
   118  */
       
   119 QEvent *HsMenuEventFactory::createDeleteCollectionEvent(int aItemId)
       
   120 {
       
   121     QVariantMap params;
       
   122     params.insert(itemIdKey(), aItemId);
       
   123     return new HsMenuEvent(HsMenuEvent::DeleteCollection, params);
       
   124 }
       
   125 
       
   126 
       
   127 /*!
       
   128     Creates an HsMenuEvent::OpenApplicationLibrary event.
       
   129 
       
   130     \return Open Applications Library event.
       
   131  */
       
   132 QEvent *HsMenuEventFactory::createOpenAppLibraryEvent(HsMenuMode menuMode)
       
   133 {
       
   134     QVariantMap params;
       
   135     params.insert(menuModeType(), menuMode);
       
   136     return new HsMenuEvent(HsMenuEvent::OpenApplicationLibrary, params);
       
   137 }
       
   138 
       
   139 /*!
       
   140     Creates an HsMenuEvent::OpenHomeScreen event.
       
   141 
       
   142     \return Open HomeScreen event.
       
   143  */
       
   144 QEvent *HsMenuEventFactory::createOpenHomeScreenEvent()
       
   145 {
       
   146     return new HsMenuEvent(HsMenuEvent::OpenHomeScreen);
       
   147 }
       
   148 
       
   149 /*!
       
   150     Creates an HsMenuEvent::CollectionDeleted event.
       
   151 
       
   152     \return Collection deleted event.
       
   153  */
       
   154 QEvent *HsMenuEventFactory::createCollectionDeletedEvent()
       
   155 {
       
   156     return new HsMenuEvent(HsMenuEvent::CollectionDeleted);
       
   157 }
       
   158 
       
   159 /*!
       
   160     Creates an HsMenuEvent::AddAppsToCollection event.
       
   161 
       
   162     \param aApplicationsSortOder applications sort order.
       
   163     \param aCollectionsSortOder collections sort order.
       
   164     \param aItemId item id.
       
   165     \return Add applications to collection event.
       
   166  */
       
   167 QEvent *HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
       
   168     HsSortAttribute aApplicationsSortOder,
       
   169     HsSortAttribute aCollectionsSortOder,
       
   170     int aItemId)
       
   171 {
       
   172     QVariantMap params;
       
   173     params.insert(appSortOrderKey(), aApplicationsSortOder);
       
   174     params.insert(collectionSortOrderKey(), aCollectionsSortOder);
       
   175     params.insert(itemIdKey(), aItemId);
       
   176     return  new HsMenuEvent(HsMenuEvent::AddAppsToCollection, params);
       
   177 }
       
   178 
       
   179 /*!
       
   180     Creates an HsMenuEvent::AddAppsToCollection event.
       
   181 
       
   182     \param aCollectionId collection id.
       
   183     \param aApplicationId application id.
       
   184     \param aCollectionsSortOder collections sort order.
       
   185     \return Add applications to collection event.
       
   186  */
       
   187 QEvent *HsMenuEventFactory::createAddAppsFromCallectionViewEvent(
       
   188     int aCollectionId,
       
   189     int aApplicationId,
       
   190     HsSortAttribute aCollectionsSortOder)
       
   191 {
       
   192     QVariantMap params;
       
   193     params.insert(itemIdKey(), aApplicationId);
       
   194     params.insert(collectionIdKey(), aCollectionId);
       
   195     params.insert(collectionSortOrderKey(), aCollectionsSortOder);
       
   196     return new HsMenuEvent(HsMenuEvent::AddAppsToCollection, params);
       
   197 }
       
   198 
       
   199 /*!
       
   200     Creates an HsMenuEvent::RemoveAppFromCollection event.
       
   201 
       
   202     \param aItemId Item id of the application to be removed from a collection.
       
   203     \param aCollectionId Item id of the collection the application is to be removed from.
       
   204     \return RemoveAppFromCollection event.
       
   205  */
       
   206 QEvent *HsMenuEventFactory::createRemoveAppFromCollectionEvent(int aItemId,
       
   207         int aCollectionId)
       
   208 {
       
   209     QVariantMap params;
       
   210     params.insert(itemIdKey(), aItemId);
       
   211     params.insert(collectionIdKey(), aCollectionId);
       
   212     return new HsMenuEvent(HsMenuEvent::RemoveAppFromCollection, params);
       
   213 }
       
   214 
       
   215 /*!
       
   216     Creates an HsMenuEvent::ArrangeCollection event.
       
   217 
       
   218     \param aTopItemId Item id to be scrolled.
       
   219     \return ArrangeCollection event.
       
   220  */
       
   221 QEvent *HsMenuEventFactory::createArrangeCollectionEvent(int aTopItemId)
       
   222 {
       
   223     QVariantMap params;
       
   224     params.insert(itemIdKey(), aTopItemId);
       
   225     return new HsMenuEvent(HsMenuEvent::ArrangeCollection, params);
       
   226 }
       
   227 
       
   228 /*!
       
   229     Prepares event triggered on tap on Widget.
       
   230     \param entryId Id of an item.
       
   231     \param entryTypeName Name of the entry type (e.g. application, widget).
       
   232     \param uri Widget uri.
       
   233     \param library Widget library path and name.
       
   234     \return Event for preview the widget.
       
   235 */
       
   236 QEvent *HsMenuEventFactory::createPreviewHSWidgetEvent(
       
   237     int entryId,
       
   238     const QString &entryTypeName,
       
   239     const QString &uri,
       
   240     const QString &library)
       
   241 {
       
   242     // get CaEntry type, and if widget get uri and library stored as properties...
       
   243     QVariantMap params;
       
   244 
       
   245     params.insert(itemIdKey(), entryId);
       
   246 
       
   247     params.insert(
       
   248         widgetUriAttributeName(),
       
   249         uri);
       
   250 
       
   251     params.insert(
       
   252         widgetLibraryAttributeName(),
       
   253         library);
       
   254 
       
   255     params.insert(entryTypeNameKey(), entryTypeName);
       
   256 
       
   257     return new HsMenuEvent(HsMenuEvent::PreviewHSWidget, params);
       
   258 }
       
   259 
       
   260 /*!
       
   261     Creates an HsMenuEvent::Unknown event.
       
   262 
       
   263     \return Unknown event.
       
   264  */
       
   265 QEvent *HsMenuEventFactory::createUnknownEvent()
       
   266 {
       
   267     return new HsMenuEvent(HsMenuEvent::Unknown);
       
   268 }
       
   269