videocollection/videocollectionview/inc/videocollectionuiloader.h
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 38 ff53afa8ad05
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    20 
    20 
    21 // System includes
    21 // System includes
    22 #include <hbdocumentloader.h>
    22 #include <hbdocumentloader.h>
    23 #include <qhash.h>
    23 #include <qhash.h>
    24 #include <qmap.h>
    24 #include <qmap.h>
    25 
    25 #include <qset.h>
    26 // Constants
    26 
    27 static const char* DOCML_VIDEOCOLLECTIONVIEW_FILE         = ":/layout/collectionview.docml";
    27 #include "videocollectionuiloaderdef.h"
    28 static const char* DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST = "listsSection";
       
    29 static const char* DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT = "hintSection";
       
    30 static const char* DOCML_NAME_VIEW                        = "view";
       
    31 
       
    32 // Videocollection View
       
    33 static const char* DOCML_NAME_VC_HEADINGBANNER            = "vc:mBanner";
       
    34 static const char* DOCML_NAME_VC_COLLECTIONWIDGET         = "vc:mCollectionWidget";
       
    35 static const char* DOCML_NAME_VC_COLLECTIONCONTENTWIDGET  = "vc:mCollectionContentWidget";
       
    36 static const char* DOCML_NAME_VC_VIDEOLISTWIDGET          = "vc:mListWidget";
       
    37 static const char* DOCML_NAME_VC_VIDEOHINTWIDGET          = "vc:mHintWidget";
       
    38 
       
    39 // Videocollection Options Menu
       
    40 static const char* DOCML_NAME_OPTIONS_MENU                = "vc:mOptionsMenu";
       
    41 static const char* DOCML_NAME_SORT_MENU                   = "vc:mSortBy";
       
    42 
       
    43 static const char* DOCML_NAME_SORT_BY_DATE                = "vc:mDate";
       
    44 static const char* DOCML_NAME_SORT_BY_NAME                = "vc:mName";
       
    45 static const char* DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS     = "vc:mNumberOfItems";
       
    46 static const char* DOCML_NAME_SORT_BY_RATING              = "vc:mRating";
       
    47 static const char* DOCML_NAME_SORT_BY_SIZE                = "vc:mSize";
       
    48 
       
    49 static const char* DOCML_NAME_ADD_TO_COLLECTION           = "vc:mAddtoCollection";
       
    50 static const char* DOCML_NAME_CREATE_COLLECTION           = "vc:mCreateNewCollection";
       
    51 static const char* DOCML_NAME_DELETE_MULTIPLE             = "vc:mDeleteMultiple";
       
    52 
       
    53 // Videocollection hint widget
       
    54 static const char* DOCML_NAME_HINT_BUTTON                 = "vc:mHintButton";
       
    55 static const char* DOCML_NAME_HINT_LABEL                  = "vc:mHintTextLabel";
       
    56 static const char* DOCML_NAME_NO_VIDEOS_LABEL             = "vc:mNoVideosLabel";
       
    57 
       
    58 // video multiselection dialog
       
    59 static const char* DOCML_VIDEOSELECTIONDIALOG_FILE        = ":/layout/videolistselectiondialog.docml";
       
    60 static const char* DOCML_NAME_DIALOG                      = "mMultiSelectionDialog";
       
    61 static const char* DOCML_NAME_DLG_HEADINGLBL              = "mHeadingLabel";
       
    62 static const char* DOCML_NAME_CHECK_CONTAINER             = "mCheckBoxContainer";
       
    63 static const char* DOCML_NAME_MARKALL                     = "mCheckMarkAll";
       
    64 static const char* DOCML_NAME_LBL_SELECTION               = "mSelectionCount";
       
    65 static const char* DOCML_NAME_LIST_CONTAINER              = "mListContainer";
       
    66 
       
    67 // async loading timeout
       
    68 static const int ASYNC_FIND_TIMEOUT                       = 50; // ms
       
    69 
       
    70 // Effect constants
       
    71 static const char* EFFECT_SLIDE_IN_TO_LEFT_FILENAME       = ":/effects/slide_in_to_left_and_fade_in.fxml";
       
    72 static const char* EFFECT_SLIDE_OUT_TO_LEFT_FILENAME      = ":/effects/slide_out_to_left_and_fade_out.fxml";
       
    73 
       
    74 static const char* EFFECT_SLIDE_IN_TO_LEFT                = "slide_in_to_left_and_fade_in";
       
    75 static const char* EFFECT_SLIDE_OUT_TO_LEFT               = "slide_out_to_left_and_fade_out";
       
    76 
    28 
    77 // Forward declarations
    29 // Forward declarations
    78 class QActionGroup;
    30 class QActionGroup;
    79 class HbAction;
    31 class HbAction;
    80 
    32 
    83     public QObject,
    35     public QObject,
    84     public HbDocumentLoader
    36     public HbDocumentLoader
    85 {
    37 {
    86     Q_OBJECT
    38     Q_OBJECT
    87     
    39     
    88 private:
    40 public:
    89     /** actions used in menus and toolbars */
    41     /** actions used in menus and toolbars */
    90     enum ActionIds
    42     enum ActionIds
    91     {
    43     {
    92         EActionSortBy          =  1,
    44         EActionSortBy          =  1,
    93         EActionSortByDate,
    45         EActionSortByDate,
   102         ETBActionServices,
    54         ETBActionServices,
   103         ETBActionAddVideos,
    55         ETBActionAddVideos,
   104         ETBActionRemoveVideos
    56         ETBActionRemoveVideos
   105     };
    57     };
   106     
    58     
   107     /** VideoCollectionUiLoader parameter class */ 
       
   108     class Params
       
   109     {
       
   110     public:
       
   111         Params(const QString& name,
       
   112             bool isWidget = false,
       
   113             QObject *receiver = 0,
       
   114             const char *docml = 0,
       
   115             const char *section = 0,
       
   116             const char *member = 0):
       
   117             mName(name),
       
   118             mIsWidget(isWidget),
       
   119             mReceiver(receiver),
       
   120             mDocml(docml),
       
   121             mSection(section),
       
   122             mMember(member)
       
   123             {
       
   124             // nothing to do 
       
   125             }
       
   126         
       
   127         bool isDuplicate(const Params& params) const
       
   128             {
       
   129             bool isSame(false);
       
   130             
       
   131             if (mName == params.mName &&
       
   132                 mReceiver == params.mReceiver &&
       
   133                 mDocml == params.mDocml &&
       
   134                 mSection == params.mSection &&
       
   135                 mMember == params.mMember)
       
   136             {
       
   137                 isSame = true;
       
   138             }
       
   139             
       
   140             return isSame;
       
   141             }
       
   142         
       
   143     public:
       
   144         QString mName;
       
   145         bool mIsWidget;
       
   146         QObject *mReceiver;
       
   147         const char *mDocml;
       
   148         const char *mSection;
       
   149         const char *mMember;
       
   150     };
       
   151 
       
   152 public:
    59 public:
   153     /**
    60     /**
   154      * C++ constructor.
    61      * C++ constructor.
   155      */
    62      */
   156     VideoCollectionUiLoader();
    63     VideoCollectionUiLoader();
   159      * C++ destructor.
    66      * C++ destructor.
   160      */
    67      */
   161     virtual ~VideoCollectionUiLoader();
    68     virtual ~VideoCollectionUiLoader();
   162     
    69     
   163     /**
    70     /**
   164      * Starts to load a specified UI section.
    71      * Adds data to ui loader loading queue.
   165      * 
    72      */
   166      * @param uiSection, UI section to load.
    73     void addData(QList<VideoCollectionUiLoaderParam> params,
   167      * @param receiver, Receiver of a ready signal.
       
   168      * @param widgetSlot, Slot which is called when a widget is ready.
       
   169      * @param objectSlot, Slot which is called when an object is ready.
       
   170      * @return None.
       
   171      */
       
   172     void startLoading(QSet<QString> uiSections,
       
   173         QObject *receiver,
    74         QObject *receiver,
   174         const char *widgetSlot,
    75         const char *slot);
   175         const char *objectSlot);
    76     
   176 
       
   177     /**
    77     /**
   178      * Returns the requested widget casted to correct type
    78      * Returns the requested widget casted to correct type
   179      *
    79      *
   180      * @param name Name of the widget
    80      * @param name Name of the widget
   181      * @return Pointer to the widget
    81      * @return Pointer to the widget
   204     void setIsService(bool isService);
   104     void setIsService(bool isService);
   205     
   105     
   206     /**
   106     /**
   207      * load
   107      * load
   208      */
   108      */
   209     QObjectList load( const QString &fileName, bool *ok = 0 );
   109     void load(const QString &fileName, bool *ok = 0);
   210 
   110 
   211     /**
   111     /**
   212      * load
   112      * load
   213      */
   113      */
   214     QObjectList load( const QString &fileName, const QString &section , bool *ok = 0 );
   114     void load(const QString &fileName, const QString &section , bool *ok = 0);
   215 
   115     
       
   116 public slots:
       
   117     /**
       
   118      * Starts loading ui components belonging to the defined phase.
       
   119      */
       
   120     void loadPhase(int loadPhase);
       
   121     
       
   122 private slots:
       
   123     /**
       
   124      * Remove object from list since it has been already deleted.
       
   125      */
       
   126     void removeOrphanFromList(QObject *object);
       
   127     
   216 signals:
   128 signals:
   217     /**
       
   218      * Signals that widget has been loaded asynchonously.
       
   219      * 
       
   220      * @param widget, Widget which was loaded.
       
   221      * @param name, Name of the widget in document.
       
   222      * @return None.
       
   223      */
       
   224     void widgetReady(QGraphicsWidget *widget, const QString &name);
       
   225 
       
   226     /**
   129     /**
   227      * Signals that object has been loaded asynchonously.
   130      * Signals that object has been loaded asynchonously.
   228      * 
   131      * 
   229      * @param object, Object which was loaded.
   132      * @param object, Object which was loaded.
   230      * @param name, Name of the object in document.
   133      * @param name, Name of the object in document.
   231      * @return None.
   134      * @return None.
   232      */
   135      */
   233     void objectReady(QObject *object, const QString &name);
   136     void objectReady(QObject *object, const QString &name);
   234 
   137     
   235 public:
   138 protected:
       
   139 
   236     /**
   140     /**
   237      * Loads widget from document.
   141      * Loads widget from document.
   238      * 
   142      * 
   239      * @param name, Widget name.
   143      * @param name, Widget name.
   240      * @return QGraphicsWidget*.
   144      * @return QGraphicsWidget*.
   242     QGraphicsWidget* doFindWidget(const QString &name);
   146     QGraphicsWidget* doFindWidget(const QString &name);
   243     
   147     
   244     /**
   148     /**
   245      * Loads object from document.
   149      * Loads object from document.
   246      * 
   150      * 
   247      * @param name, Widget name.
   151      * @param name, Object name.
   248      * @return QGraphicsWidget*.
   152      * @return QObject*.
   249      */
   153      */
   250     QObject* doFindObject(const QString &name);
   154     QObject* doFindObject(const QString &name);
   251     
   155     
   252 private:
       
   253     /**
   156     /**
   254      * Adds a ui section to async loading queue.
   157      * Adds a ui section to async loading queue.
   255      */
   158      */
   256     void addToQueue(Params &params);
   159     void addToQueue(VideoCollectionUiLoaderParam &param,
   257     
   160         QObject *receiver,
   258     /**
   161         const char *slot);
   259      * Init a specific widget.
   162     
   260      */
   163     /**
   261     void initWidget(QGraphicsWidget *widget,
   164      * Finds an object or widget from docml based on the parameter.
   262         const QString &name);
   165      */
       
   166     QObject* getObject(const VideoCollectionUiLoaderParam &param);
       
   167     
       
   168     /**
       
   169      * Loads and prepares docml and sections if found from param.
       
   170      */
       
   171     bool prepareDocmlAndSection(const char *docml, const char *section);
   263     
   172     
   264     /**
   173     /**
   265      * Init a specific object.
   174      * Init a specific object.
   266      */
   175      */
   267     void initObject(QObject *object,
   176     void initObject(QObject *object, const QString& name);
   268         const QString& name);
   177     
       
   178     /**
       
   179      * Execute ui loader request.
       
   180      */
       
   181     QObject* executeRequest(const VideoCollectionUiLoaderParam &param);
       
   182     
       
   183     /**
       
   184      * Gets index of the item in queue, if one found.
       
   185      */
       
   186     int indexInQueue(const QString &name);
       
   187     
       
   188     /**
       
   189      * Removes request from queue.
       
   190      */
       
   191     void removeFromQueue(const QString &name);
   269     
   192     
   270 private:
   193 private:
   271     /** from QObject */
   194     /** from QObject */
   272     void timerEvent(QTimerEvent *event); 
   195     void timerEvent(QTimerEvent *event); 
   273     
   196     
   281     void runNext();
   204     void runNext();
   282     
   205     
   283     /**
   206     /**
   284      * Check that set params are valid.
   207      * Check that set params are valid.
   285      */
   208      */
   286     bool isValid(const Params &params);
   209     bool isValid(const VideoCollectionUiLoaderParam &param);
       
   210     
       
   211     /**
       
   212      * Store object without a parent. 
       
   213      */
       
   214     void storeOrphans(const QObjectList &list);
   287     
   215     
   288 private:
   216 private:
   289     /** async queue */
   217     /** async queue */
   290     QList<Params> mQueue;
   218     QList<VideoCollectionUiLoaderParam> mQueue;
   291     
   219     
   292     /** timer id */
   220     /** timer id */
   293     int mTimerId;
   221     int mTimerId;
   294     
   222     
   295     /** list of loaded widgets */
   223     /** list of initialized objects */
   296     QHash<QString, QGraphicsWidget*> mWidgets;
       
   297 
       
   298     /** list of loaded objects */
       
   299     QHash<QString, QObject*> mObjects;
   224     QHash<QString, QObject*> mObjects;
   300     
   225     
   301     /** menu actions */
   226     /** menu actions */
   302     QMap<ActionIds, HbAction*> mMenuActions;
   227     QMap<ActionIds, HbAction*> mMenuActions;
   303     
   228     
   304     /** toolbar actions */
   229     /** toolbar actions */
   305     QMap<ActionIds, HbAction*> mToolbarActions;
   230     QMap<ActionIds, HbAction*> mToolbarActions;
   306     
   231     
   307     /** loaded docml's */
   232     /** loaded docmls */
   308     QList<QString> mDocmls;
   233     QSet<QString> mDocmls;
       
   234     
       
   235     /** loaded sections */
       
   236     QSet<QString> mSections;
   309     
   237     
   310     /** action group for "sort by" actions */
   238     /** action group for "sort by" actions */
   311     QActionGroup* mSortGroup;
   239     QActionGroup* mSortGroup;
   312     
   240     
   313     /** is service */
   241     /** is service */
   314     bool mIsService;
   242     bool mIsService;
       
   243     
       
   244     /** load phases currently active */
       
   245     QSet<int> mPhases;
       
   246     
       
   247     /**
       
   248      * objects without a parent - these needs to be deleted manually unless
       
   249      * a parent is set.
       
   250      */
       
   251     QObjectList mOrphans;
   315 };
   252 };
   316 
   253 
   317 #endif // _VIDEOCOLLECTIONUILOADER_H_
   254 #endif // _VIDEOCOLLECTIONUILOADER_H_