videocollection/videocollectionview/src/videolistview.cpp
changeset 17 69946d1824c4
parent 15 cf5481c2bc0b
child 20 b9e04db066d4
equal deleted inserted replaced
15:cf5481c2bc0b 17:69946d1824c4
    13 *
    13 *
    14 * Description:   Videolist view class source code
    14 * Description:   Videolist view class source code
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 // Version : %version: 97 %
       
    19 
       
    20 // INCLUDE FILES
    18 #include <xqserviceutil.h>
    21 #include <xqserviceutil.h>
    19 #include <QActionGroup>
    22 #include <qactiongroup.h>
    20 #include <hbinstance.h>
    23 #include <hbinstance.h>
    21 #include <hbmainwindow.h>
    24 #include <hbmainwindow.h>
    22 #include <hbmessagebox.h>
    25 #include <hbmessagebox.h>
    23 #include <hbstackedwidget.h>
    26 #include <hbstackedwidget.h>
    24 #include <hbstackedlayout.h>
    27 #include <hbstackedlayout.h>
    40 #include "videocollectioncommon.h"
    43 #include "videocollectioncommon.h"
    41 #include "videocollectionwrapper.h"
    44 #include "videocollectionwrapper.h"
    42 #include "videosortfilterproxymodel.h"
    45 #include "videosortfilterproxymodel.h"
    43 #include "videocollectionuiloader.h"
    46 #include "videocollectionuiloader.h"
    44 #include "mpxhbvideocommondefs.h"
    47 #include "mpxhbvideocommondefs.h"
    45 
    48 #include "videocollectiontrace.h"
    46 // remove these
       
    47 #include <QDebug>
       
    48 
    49 
    49 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    50 // Constructor
    51 // Constructor
    51 // ---------------------------------------------------------------------------
    52 // ---------------------------------------------------------------------------
    52 //
    53 //
    53 VideoListView::VideoListView(VideoCollectionUiLoader *uiLoader, QGraphicsItem *parent) :
    54 VideoListView::VideoListView( VideoCollectionUiLoader *uiLoader, QGraphicsItem *parent ) 
    54 HbView(parent),
    55     : HbView( parent )
    55 mUiUtils(VideoCollectionViewUtils::instance()),
    56     , mUiUtils( VideoCollectionViewUtils::instance() )
    56 mWrapper(VideoCollectionWrapper::instance()),
    57     , mWrapper( VideoCollectionWrapper::instance() )
    57 mUiLoader(uiLoader),
    58     , mUiLoader( uiLoader )
    58 mIsService(false),
    59     , mIsService( false )
    59 mHintLoaded(false),
    60     , mModelReady( false )
    60 mListsLoaded(false),
    61     , mTransitionOngoing( false )
    61 mMultiselectionLoaded(false),
    62     , mHintLevel( VideoHintWidget::AllVideos )
    62 mModelReady(false),
    63     , mVideoServices( 0 )
    63 mTransitionOngoing(false),
    64     , mCurrentList( 0 )
    64 mHintLevel(VideoHintWidget::AllVideos),
    65     , mToolbarViewsActionGroup( 0 )
    65 mVideoServices(0),
    66     , mToolbarCollectionActionGroup( 0 )
    66 mCurrentList(0),
    67 {
    67 mToolbarViewsActionGroup(0),
    68 	FUNC_LOG;
    68 mToolbarCollectionActionGroup(0)
       
    69 {
       
    70     // NOP
       
    71 }
    69 }
    72 
    70 
    73 // ---------------------------------------------------------------------------
    71 // ---------------------------------------------------------------------------
    74 // Destructor
    72 // Destructor
    75 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    76 //
    74 //
    77 VideoListView::~VideoListView()
    75 VideoListView::~VideoListView()
    78 {
    76 {
    79     qDebug() << "VideoListView::~VideoListView()";
    77 	FUNC_LOG;
    80     
    78     
    81     toolBar()->clearActions();
    79     toolBar()->clearActions();
    82     
    80     
    83     mToolbarActions.clear();
    81     mToolbarActions.clear();
    84     mSortingRoles.clear();
    82     mSortingRoles.clear();
    94 // initializeView()
    92 // initializeView()
    95 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
    96 //
    94 //
    97 int VideoListView::initializeView()
    95 int VideoListView::initializeView()
    98 {
    96 {
       
    97 	FUNC_LOG;
    99 	if(!mUiLoader)
    98 	if(!mUiLoader)
   100 	{
    99 	{
   101         cleanup();
   100         cleanup();
   102 		return -1;
   101 		return -1;
   103 	}
   102 	}
   104 
   103 
   105     if (XQServiceUtil::isService() && !mVideoServices)
   104     if (XQServiceUtil::isService() && !mVideoServices)
   106     {
   105     {
   107     	mIsService = true;
   106         INFO("VideoListView::initializeView() service flag set to true.");
       
   107         mIsService = true;
   108 
   108 
   109     	mVideoServices = VideoServices::instance();
   109     	mVideoServices = VideoServices::instance();
   110 
   110 
   111     	if (!mVideoServices)
   111     	if (!mVideoServices)
   112         {
   112         {
       
   113     	    ERROR(-1, "VideoListView::initializeView() getting services instance failed.");
   113             cleanup();
   114             cleanup();
   114         	return -1;
   115         	return -1;
   115 		}
   116 		}
   116         else
   117         else
   117         {
   118         {
   118         	connect(mVideoServices, SIGNAL(titleReady(const QString&)), this, SLOT(titleReadySlot(const QString&)));
   119         	connect(mVideoServices, SIGNAL(titleReady(const QString&)), this, SLOT(titleReadySlot(const QString&)));
   119         }
   120         }
   120 	}
   121 	}
   121     
   122     
   122     // start open all videos model
   123     // start loading objects and widgets
   123     VideoSortFilterProxyModel *model =
   124     QList<VideoCollectionUiLoaderParam> params;
   124         mWrapper.getModel(VideoCollectionWrapper::EAllVideos);
   125     params.append(VideoCollectionUiLoaderParam(
   125     if (model)
   126         DOCML_NAME_VC_VIDEOLISTWIDGET,
   126     {
   127         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   127         model->open(VideoCollectionCommon::ELevelVideos);
   128         true,
       
   129         VideoCollectionUiLoaderParam::LoadPhasePrimary));
       
   130     params.append(VideoCollectionUiLoaderParam(
       
   131         DOCML_NAME_OPTIONS_MENU,
       
   132         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   133         true,
       
   134         VideoCollectionUiLoaderParam::LoadPhasePrimary));
       
   135     params.append(VideoCollectionUiLoaderParam(
       
   136         DOCML_NAME_ADD_TO_COLLECTION,
       
   137         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   138         false,
       
   139         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   140     params.append(VideoCollectionUiLoaderParam(
       
   141         DOCML_NAME_CREATE_COLLECTION,
       
   142         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   143         false,
       
   144         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   145     params.append(VideoCollectionUiLoaderParam(
       
   146         DOCML_NAME_DELETE_MULTIPLE,
       
   147         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   148         false,
       
   149         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   150     params.append(VideoCollectionUiLoaderParam(
       
   151         DOCML_NAME_VC_HEADINGBANNER,
       
   152         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   153         true,
       
   154         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   155     params.append(VideoCollectionUiLoaderParam(
       
   156         DOCML_NAME_SORT_MENU,
       
   157         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   158         true,
       
   159         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   160     params.append(VideoCollectionUiLoaderParam(
       
   161         DOCML_NAME_SORT_BY_DATE,
       
   162         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   163         false,
       
   164         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   165     params.append(VideoCollectionUiLoaderParam(
       
   166         DOCML_NAME_SORT_BY_NAME,
       
   167         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   168         false,
       
   169         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   170     params.append(VideoCollectionUiLoaderParam(
       
   171         DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS,
       
   172         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   173         false,
       
   174         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   175     params.append(VideoCollectionUiLoaderParam(
       
   176         DOCML_NAME_SORT_BY_SIZE,
       
   177         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   178         false,
       
   179         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   180     params.append(VideoCollectionUiLoaderParam(
       
   181         DOCML_NAME_VC_COLLECTIONWIDGET,
       
   182         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   183         DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
       
   184         true,
       
   185         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   186     params.append(VideoCollectionUiLoaderParam(
       
   187         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET,
       
   188         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   189         DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
       
   190         true,
       
   191         VideoCollectionUiLoaderParam::LoadPhaseSecondary)); // widget
       
   192     params.append(VideoCollectionUiLoaderParam(
       
   193         DOCML_NAME_DIALOG,
       
   194         DOCML_VIDEOSELECTIONDIALOG_FILE,
       
   195         true,
       
   196         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   197     params.append(VideoCollectionUiLoaderParam(
       
   198         DOCML_NAME_VC_VIDEOHINTWIDGET,
       
   199         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   200         DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT,
       
   201         true,
       
   202         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   203     params.append(VideoCollectionUiLoaderParam(
       
   204         DOCML_NAME_HINT_BUTTON,
       
   205         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   206         DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT,
       
   207         true,
       
   208         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   209     params.append(VideoCollectionUiLoaderParam(
       
   210         DOCML_NAME_NO_VIDEOS_LABEL,
       
   211         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   212         DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT,
       
   213         true,
       
   214         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   215     mUiLoader->addData(params,
       
   216         this,
       
   217         SLOT(objectReadySlot(QObject*, const QString&)));
       
   218     mUiLoader->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary);
       
   219     params.clear();
       
   220     
       
   221     return 0;
       
   222 }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // titleReadySlot()
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void VideoListView::titleReadySlot(const QString& title)
       
   229 {
       
   230 	FUNC_LOG;
       
   231 	setTitle(title);
       
   232 }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // activateView()
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 int VideoListView::activateView(const TMPXItemId &itemId)
       
   239 {
       
   240 	FUNC_LOG;
       
   241 
       
   242     int err = 0;
       
   243     
       
   244     // activate collection to correct view
       
   245     if (itemId == TMPXItemId::InvalidId())
       
   246     {
       
   247         err = activateVideosView();
   128     }
   248     }
   129     else
   249     else
   130     {
   250     {
   131         cleanup();
   251         err = activateCollectionContentView(itemId);
   132         return -1;
   252     }
   133     }
   253     
   134     
   254     // connect signals if everything went ok
   135     // start loading widgets
   255     if (err == 0)
   136     QSet<QString> uiItems;
   256     {
   137     uiItems.insert(DOCML_NAME_VC_VIDEOLISTWIDGET);
   257         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   138     uiItems.insert(DOCML_NAME_VC_HEADINGBANNER);
   258         mainWnd->setOrientation(Qt::Vertical, false);
   139     uiItems.insert(DOCML_NAME_OPTIONS_MENU);
   259         if (!connect(
   140     if(!mIsService)
   260                 mainWnd, SIGNAL(aboutToChangeOrientation()),
   141     {
   261                 this, SLOT( aboutToChangeOrientationSlot())) ||
   142 		uiItems.insert(DOCML_NAME_ADD_TO_COLLECTION);
   262             !connect(
   143 		uiItems.insert(DOCML_NAME_CREATE_COLLECTION);
   263                 mainWnd, SIGNAL(orientationChanged(Qt::Orientation)),
   144 		uiItems.insert(DOCML_NAME_DELETE_MULTIPLE);
   264                 this, SLOT(orientationChangedSlot(Qt::Orientation))) ||
   145     }
   265             !connect(
   146     uiItems.insert(DOCML_NAME_SORT_MENU);
   266                 &mWrapper, SIGNAL(asyncStatus(int, QVariant&)),
   147     uiItems.insert(DOCML_NAME_SORT_BY_DATE);
   267                 this, SLOT(handleAsyncStatusSlot(int, QVariant&))) ||
   148     uiItems.insert(DOCML_NAME_SORT_BY_NAME);
   268             !connect(
   149     uiItems.insert(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
   269                 mCurrentList->getModel().sourceModel(), SIGNAL(modelChanged()),
   150     uiItems.insert(DOCML_NAME_SORT_BY_RATING);
   270                 this, SLOT(layoutChangedSlot())) ||
   151     uiItems.insert(DOCML_NAME_SORT_BY_SIZE);
   271             !connect(
   152     mUiLoader->startLoading(uiItems,
   272                 mCurrentList->getModel().sourceModel(), SIGNAL(modelReady()),
   153         this,
   273                 this, SLOT(modelReadySlot())))
   154         SLOT(widgetReadySlot(QGraphicsWidget*, const QString&)),
   274         {
   155         SLOT(objectReadySlot(QObject*, const QString&)));
   275             ERROR(-1, "VideoListView::activateView() failed to connect signals.");
   156     uiItems.clear();
   276             // deactivate view so we get rid of dangling connections.
   157     
       
   158     // TODO: create toolbar temporarily here until it has been moved to docml
       
   159     if (createToolbar() != 0)
       
   160     {
       
   161         cleanup();
       
   162         return -1;
       
   163     }
       
   164 
       
   165     return 0;
       
   166 }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // titleReadySlot()
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void VideoListView::titleReadySlot(const QString& title)
       
   173 {
       
   174 	setTitle(title);
       
   175 }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // activateView()
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 int VideoListView::activateView()
       
   182 {
       
   183     VideoListWidget *videoList =
       
   184         mUiLoader->findWidget<VideoListWidget>(
       
   185             DOCML_NAME_VC_VIDEOLISTWIDGET);
       
   186     if (videoList)
       
   187     {
       
   188     	VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
       
   189         if (mCurrentList)
       
   190         {
       
   191         	level = mCurrentList->getLevel();
       
   192         }
       
   193         else
       
   194         {
       
   195         	mCurrentList = videoList;
       
   196         }
       
   197         
       
   198     	int result = mCurrentList->activate(level);
       
   199         if(result < 0)
       
   200         {
       
   201             // activate failed, deactivate view so we get rid of dangling connections.
       
   202             deactivateView();
   277             deactivateView();
   203             return -1;
   278             err = -1;
   204         }
   279         }
   205         
   280     }
   206         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   281     
   207         if (mainWnd)
   282     return err;
   208         {
       
   209         mainWnd->setOrientation(Qt::Vertical, false);
       
   210             if(!connect(
       
   211                     mainWnd, SIGNAL(aboutToChangeOrientation()),
       
   212                     this, SLOT( aboutToChangeOrientationSlot())) ||
       
   213                !connect(
       
   214                    mainWnd, SIGNAL(orientationChanged(Qt::Orientation)),
       
   215                    this, SLOT(orientationChangedSlot(Qt::Orientation))) ||
       
   216                !connect(
       
   217                    &mWrapper, SIGNAL(asyncStatus(int, QVariant&)),
       
   218                    this, SLOT(handleAsyncStatusSlot(int, QVariant&))) ||
       
   219                !connect(
       
   220                    mCurrentList->getModel().sourceModel(), SIGNAL(modelChanged()),
       
   221                    this, SLOT(layoutChangedSlot())) ||
       
   222                !connect(
       
   223                    mCurrentList->getModel().sourceModel(), SIGNAL(modelReady()),
       
   224                    this, SLOT(modelReadySlot())))
       
   225             {
       
   226                 // deactivate view so we get rid of dangling connections.
       
   227                 deactivateView();
       
   228                 return -1;
       
   229             }
       
   230         }
       
   231         else
       
   232         {
       
   233             return -1;
       
   234         }
       
   235     }
       
   236     else
       
   237     {
       
   238         return -1;
       
   239     }
       
   240     
       
   241     return 0;
       
   242 }
       
   243 
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // loadMultiSelection
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void VideoListView::loadMultiSelection()
       
   250 {
       
   251 	if(!mIsService)
       
   252     {
       
   253 		if(!mMultiselectionLoaded)
       
   254 		{
       
   255 			QSet<QString> uiItems;
       
   256 			uiItems.insert(DOCML_NAME_DIALOG);
       
   257 			mUiLoader->startLoading(uiItems,
       
   258 				this,
       
   259 				SLOT(widgetReadySlot(QGraphicsWidget*, const QString&)),
       
   260 				SLOT(objectReadySlot(QObject*, const QString&)));
       
   261 			uiItems.clear();
       
   262 			mMultiselectionLoaded = true;
       
   263 		}
       
   264     }
       
   265 }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // loadLists
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void VideoListView::loadLists(bool doAsync)
       
   272 {
       
   273 	if(!mListsLoaded)
       
   274 	{
       
   275 		QSet<QString> uiItems;
       
   276 		uiItems.insert(DOCML_NAME_VC_COLLECTIONWIDGET);
       
   277 		uiItems.insert(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   278 		mUiLoader->startLoading(uiItems,
       
   279 			this,
       
   280 			SLOT(widgetReadySlot(QGraphicsWidget*, const QString&)),
       
   281 			SLOT(objectReadySlot(QObject*, const QString&)));
       
   282 		uiItems.clear();
       
   283 
       
   284 		if(!doAsync)
       
   285 		{
       
   286 			VideoListWidget* widget(0);
       
   287 			widget = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONWIDGET);
       
   288 			widget->setVisible(false);
       
   289 			widget = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   290 			widget->setVisible(false);
       
   291 		}
       
   292 	    mListsLoaded = true;
       
   293 	}
       
   294 }
   283 }
   295 
   284 
   296 // ---------------------------------------------------------------------------
   285 // ---------------------------------------------------------------------------
   297 // doDelayedsSlot
   286 // doDelayedsSlot
   298 // ---------------------------------------------------------------------------
   287 // ---------------------------------------------------------------------------
   299 //
   288 //
   300 void VideoListView::doDelayedsSlot()
   289 void VideoListView::doDelayedsSlot()
   301 {
   290 {
   302 	loadLists(true);
   291 	FUNC_LOG;
   303 	loadMultiSelection();
   292     mUiLoader->loadPhase(VideoCollectionUiLoaderParam::LoadPhaseSecondary);
   304 	loadHint(true);
       
   305 	emit doDelayeds();
   293 	emit doDelayeds();
   306 }
   294 }
   307 
   295 
   308 // ---------------------------------------------------------------------------
   296 // ---------------------------------------------------------------------------
   309 // modelReadySlot
   297 // modelReadySlot
   310 // ---------------------------------------------------------------------------
   298 // ---------------------------------------------------------------------------
   311 //
   299 //
   312 void VideoListView::modelReadySlot()
   300 void VideoListView::modelReadySlot()
   313 {
   301 {
       
   302 	FUNC_LOG;
   314     mModelReady = true;
   303     mModelReady = true;
   315     
   304     
   316     // since the reset signal arrives after
   305     // since the reset signal arrives after
   317     // layout changed, need to make sure that
   306     // layout changed, need to make sure that
   318     // view is updated in case needed
   307     // view is updated in case needed
   323 // layoutChangedSlot
   312 // layoutChangedSlot
   324 // ---------------------------------------------------------------------------
   313 // ---------------------------------------------------------------------------
   325 //
   314 //
   326 void VideoListView::layoutChangedSlot()
   315 void VideoListView::layoutChangedSlot()
   327 {
   316 {
       
   317 	FUNC_LOG;
   328     updateSubLabel();
   318     updateSubLabel();
   329     
   319     
   330     if(mModelReady)
   320     if(mModelReady)
   331     {
   321     {
   332         showHint();
   322         showHint();
   337 // deactivateView()
   327 // deactivateView()
   338 // ---------------------------------------------------------------------------
   328 // ---------------------------------------------------------------------------
   339 //
   329 //
   340 void VideoListView::deactivateView()
   330 void VideoListView::deactivateView()
   341 {
   331 {
       
   332 	FUNC_LOG;
   342     HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   333     HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   343     
   334     
   344     mainWnd->unsetOrientation();
   335     mainWnd->unsetOrientation();
   345     
   336     
   346     disconnect(mainWnd, SIGNAL(aboutToChangeOrientation()),
   337     disconnect(mainWnd, SIGNAL(aboutToChangeOrientation()),
   380 // back()
   371 // back()
   381 // ---------------------------------------------------------------------------
   372 // ---------------------------------------------------------------------------
   382 //
   373 //
   383 void VideoListView::back()
   374 void VideoListView::back()
   384 {
   375 {
   385     // NOP
   376 	FUNC_LOG;
   386 }
   377 }
   387 
   378 
   388 // ---------------------------------------------------------------------------
   379 // ---------------------------------------------------------------------------
   389 // cleanup()
   380 // cleanup()
   390 // ---------------------------------------------------------------------------
   381 // ---------------------------------------------------------------------------
   391 //
   382 //
   392 void VideoListView::cleanup()
   383 void VideoListView::cleanup()
   393 {
   384 {
       
   385 	FUNC_LOG;
   394     delete mToolbarViewsActionGroup;
   386     delete mToolbarViewsActionGroup;
   395     mToolbarViewsActionGroup = 0;
   387     mToolbarViewsActionGroup = 0;
   396 
   388 
   397     delete mToolbarCollectionActionGroup;
   389     delete mToolbarCollectionActionGroup;
   398     mToolbarCollectionActionGroup = 0;
   390     mToolbarCollectionActionGroup = 0;
   405 // Creates toolbar, toolbar actions and toolbar icons
   397 // Creates toolbar, toolbar actions and toolbar icons
   406 // ---------------------------------------------------------------------------
   398 // ---------------------------------------------------------------------------
   407 //
   399 //
   408 int VideoListView::createToolbar()
   400 int VideoListView::createToolbar()
   409 {
   401 {
       
   402 	FUNC_LOG;
   410     // Create actiongroup and add all actions to it. This ensures that only one is
   403     // Create actiongroup and add all actions to it. This ensures that only one is
   411     // active at certain moment.
   404     // active at certain moment.
   412 
   405 
   413     if(!mToolbarViewsActionGroup && !mToolbarCollectionActionGroup)
   406     if(!mToolbarViewsActionGroup && !mToolbarCollectionActionGroup)
   414     {
   407     {
   415     	mToolbarViewsActionGroup = new QActionGroup(this);
   408     	mToolbarViewsActionGroup = new QActionGroup(this);
   416         mToolbarCollectionActionGroup = new QActionGroup(this);
   409         mToolbarCollectionActionGroup = new QActionGroup(this);
   417 
       
   418         if(!mToolbarViewsActionGroup || !mToolbarCollectionActionGroup)
       
   419         {
       
   420             delete mToolbarViewsActionGroup;
       
   421             mToolbarViewsActionGroup = 0;
       
   422 
       
   423             delete mToolbarCollectionActionGroup;
       
   424             mToolbarCollectionActionGroup = 0;
       
   425 
       
   426             return -1;
       
   427         }
       
   428 
   410 
   429         // create toolbar item actions
   411         // create toolbar item actions
   430 
   412 
   431         // All Videos tab
   413         // All Videos tab
   432         mToolbarActions[ETBActionAllVideos] = createAction(":/images/qtg_mono_video_all.svg",
   414         mToolbarActions[ETBActionAllVideos] = createAction(":/images/qtg_mono_video_all.svg",
   446 			        createAction("qtg_mono_add_to_video_collection",
   428 			        createAction("qtg_mono_add_to_video_collection",
   447 					mToolbarCollectionActionGroup, SLOT(addVideosToCollectionSlot()));
   429 					mToolbarCollectionActionGroup, SLOT(addVideosToCollectionSlot()));
   448 
   430 
   449 			// Remove Videos tab
   431 			// Remove Videos tab
   450 			mToolbarActions[ETBActionRemoveVideos] = 
   432 			mToolbarActions[ETBActionRemoveVideos] = 
   451 			        createAction(":/images/qtg_mono_remove_from_video_collection.svg",
   433 			        createAction("qtg_mono_remove_from_video_collection",
   452 					mToolbarCollectionActionGroup, SLOT(removeVideosFromCollectionSlot()));
   434 					mToolbarCollectionActionGroup, SLOT(removeVideosFromCollectionSlot()));
   453         }
   435         }
   454 
   436 
   455         HbToolBar *bar = toolBar(); // First call to toolBar() creates the object, so on failure it could return 0.
   437         HbToolBar *bar = toolBar(); // First call to toolBar() creates the object, so on failure it could return 0.
   456 
   438 
   457         if(   !bar
   439         if(   !bar
   458 		   || !mToolbarActions[ETBActionAllVideos]
   440 		   || !mToolbarActions[ETBActionAllVideos]
   459            || !mToolbarActions[ETBActionCollections]
   441            || !mToolbarActions[ETBActionCollections]
   460            || (!mToolbarActions[ETBActionServices]     && !mIsService)
   442            || ( !mIsService && (!mToolbarActions[ETBActionServices] 
   461            || (!mToolbarActions[ETBActionAddVideos]    && !mIsService)
   443               || !mToolbarActions[ETBActionAddVideos]
   462            || (!mToolbarActions[ETBActionRemoveVideos] && !mIsService))
   444               || !mToolbarActions[ETBActionRemoveVideos])))
   463         {
   445         {
       
   446             ERROR(-1, "VideoListView::createToolbar() failed to create all actions or the toolbar.");
   464         	delete mToolbarActions[ETBActionAllVideos];
   447         	delete mToolbarActions[ETBActionAllVideos];
   465             delete mToolbarActions[ETBActionCollections];
   448             delete mToolbarActions[ETBActionCollections];
   466             delete mToolbarActions[ETBActionServices];
   449             delete mToolbarActions[ETBActionServices];
   467             delete mToolbarActions[ETBActionAddVideos];
   450             delete mToolbarActions[ETBActionAddVideos];
   468             delete mToolbarActions[ETBActionRemoveVideos];
   451             delete mToolbarActions[ETBActionRemoveVideos];
   480 
   463 
   481         // Allvideos is checked at creation phase
   464         // Allvideos is checked at creation phase
   482         mToolbarActions[ETBActionAllVideos]->setChecked(true);
   465         mToolbarActions[ETBActionAllVideos]->setChecked(true);
   483 
   466 
   484         bar->addActions(mToolbarViewsActionGroup->actions());
   467         bar->addActions(mToolbarViewsActionGroup->actions());
   485         bar->setVisible(true);
       
   486     }
   468     }
   487 
   469 
   488     return 0;
   470     return 0;
   489 }
   471 }
   490 
   472 
   493 // ---------------------------------------------------------------------------
   475 // ---------------------------------------------------------------------------
   494 //
   476 //
   495 HbAction* VideoListView::createAction(QString icon,
   477 HbAction* VideoListView::createAction(QString icon,
   496         QActionGroup* actionGroup, const char *slot)
   478         QActionGroup* actionGroup, const char *slot)
   497 {
   479 {
       
   480 	FUNC_LOG;
   498     HbAction* action = new HbAction(actionGroup);
   481     HbAction* action = new HbAction(actionGroup);
   499     if(!action) {
       
   500         return 0;
       
   501     }
       
   502 
   482 
   503     HbIcon hbIcon(icon);
   483     HbIcon hbIcon(icon);
   504     action->setIcon(hbIcon);
   484     action->setIcon(hbIcon);
   505 
   485 
   506     if(!connect(action, SIGNAL(triggered()), this, slot)) {
   486     if(!connect(action, SIGNAL(triggered()), this, slot)) {
   512 
   492 
   513     return action;
   493     return action;
   514 }
   494 }
   515 
   495 
   516 // ---------------------------------------------------------------------------
   496 // ---------------------------------------------------------------------------
   517 // loadHint
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void VideoListView::loadHint(bool doAsync)
       
   521 {
       
   522 	if(!mHintLoaded)
       
   523 	{
       
   524 		QSet<QString> uiItems;
       
   525 	    uiItems.insert(DOCML_NAME_VC_VIDEOHINTWIDGET);
       
   526 	    uiItems.insert(DOCML_NAME_HINT_BUTTON);
       
   527 	    uiItems.insert(DOCML_NAME_NO_VIDEOS_LABEL);
       
   528 		mUiLoader->startLoading(uiItems,
       
   529 			this,
       
   530 			SLOT(widgetReadySlot(QGraphicsWidget*, const QString&)),
       
   531 			SLOT(objectReadySlot(QObject*, const QString&)));
       
   532 		uiItems.clear();
       
   533 
       
   534 		if(!doAsync)
       
   535 		{
       
   536 			HbPushButton* button = mUiLoader->findWidget<HbPushButton>(DOCML_NAME_HINT_BUTTON);
       
   537 		}
       
   538 		mHintLoaded = true;
       
   539 	}
       
   540 }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // showHint
   497 // showHint
   544 // ---------------------------------------------------------------------------
   498 // ---------------------------------------------------------------------------
   545 //
   499 //
   546 void VideoListView::showHint(bool show)
   500 void VideoListView::showHint(bool show)
   547 {
   501 {
       
   502 	FUNC_LOG;
   548     if(!mCurrentList)
   503     if(!mCurrentList)
   549     {
   504     {
   550         return;
   505         return;
   551     }
   506     }
   552 
   507 
   553     VideoSortFilterProxyModel &model = mCurrentList->getModel();
   508     VideoSortFilterProxyModel &model = mCurrentList->getModel();
   554 
   509     
   555     HbGroupBox *subLabel =
   510     // prepare hint widget
   556         mUiLoader->findWidget<HbGroupBox>(DOCML_NAME_VC_HEADINGBANNER);
       
   557 
       
   558     if((!mHintLoaded && !show) || (!mHintLoaded && model.rowCount() != 0))
       
   559     {
       
   560     	if(subLabel)
       
   561     	{
       
   562     		subLabel->show();
       
   563     	}
       
   564     	return;
       
   565     }
       
   566     else if(!mHintLoaded)
       
   567     {
       
   568     	loadHint(false);
       
   569     }
       
   570 
       
   571     VideoHintWidget *hintWidget =
   511     VideoHintWidget *hintWidget =
   572         mUiLoader->findWidget<VideoHintWidget>(
   512         mUiLoader->findWidget<VideoHintWidget>(
   573             DOCML_NAME_VC_VIDEOHINTWIDGET);
   513             DOCML_NAME_VC_VIDEOHINTWIDGET);
   574 
       
   575     if (hintWidget)
   514     if (hintWidget)
   576     {
   515     {
   577         hintWidget->setLevel(mHintLevel);
   516         hintWidget->setLevel(mHintLevel);
   578     }
   517         if (mModelReady &&
   579 
   518             model.rowCount() == 0)
   580     if (mModelReady &&
   519         {
   581         model.rowCount() == 0 &&
   520             show ? hintWidget->activate() : hintWidget->deactivate();
   582         hintWidget)
   521         }
   583     {
   522         else
   584         show ? hintWidget->activate() : hintWidget->deactivate();
   523         {
   585     }
   524             show = false;
   586     else if (hintWidget)
   525             hintWidget->deactivate();
   587     {
   526         }
   588         show = false;
   527         if(show)
   589         hintWidget->deactivate();
   528         {
   590     }
   529             bool showHintBtns = (mCurrentList->getLevel() != VideoCollectionCommon::ELevelDefaultColl); 
   591 
   530             hintWidget->setButtonShown(showHintBtns);
   592     if(show && mToolbarViewsActionGroup && mToolbarCollectionActionGroup) 
   531         }
   593     {
   532         else
   594     	if(!mIsService)
       
   595     	{
       
   596     		mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
       
   597     	}
       
   598         if(mCurrentList->getLevel() == VideoCollectionCommon::ELevelDefaultColl) 
       
   599         {
       
   600         	if(!mIsService)
       
   601         	{
       
   602         		mToolbarActions[ETBActionAddVideos]->setVisible(false);
       
   603         	}
       
   604        		hintWidget->setButtonShown(false);
       
   605         } 
       
   606         else 
       
   607         {
   533         {
   608             hintWidget->setButtonShown(true);
   534             hintWidget->setButtonShown(true);
   609         }
   535         }
   610     } 
   536     }
   611     else if(mToolbarViewsActionGroup && mToolbarCollectionActionGroup)
   537 
   612     {
   538     if (mToolbarViewsActionGroup && mToolbarCollectionActionGroup && !mIsService)
   613     	if(!mIsService)
   539     {
   614     	{
   540         if (show)
   615 			if(mToolbarActions[ETBActionRemoveVideos]->isVisible() == false) 
   541         {
   616 			{
   542             mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
   617 				mToolbarActions[ETBActionRemoveVideos]->setVisible(true);
   543 
   618 			}
   544             if(mCurrentList->getLevel() == VideoCollectionCommon::ELevelDefaultColl) 
   619 	        if(mToolbarActions[ETBActionAddVideos]->isVisible() == false) 
   545             {
   620 	        {
   546                 mToolbarActions[ETBActionAddVideos]->setVisible(false);
   621 	            mToolbarActions[ETBActionAddVideos]->setVisible(true);
   547             } 
   622 	        }
   548         }
   623     	}
   549         else
   624         hintWidget->setButtonShown(true);
   550         {
   625     }
   551             if(mToolbarActions[ETBActionRemoveVideos]->isVisible() == false)
   626     
   552             {
       
   553                 mToolbarActions[ETBActionRemoveVideos]->setVisible(true);
       
   554             }
       
   555             if(mToolbarActions[ETBActionAddVideos]->isVisible() == false) 
       
   556             {
       
   557                 mToolbarActions[ETBActionAddVideos]->setVisible(true);
       
   558             }
       
   559         }
       
   560     }
       
   561 
       
   562     // prepare sublabel
       
   563     HbGroupBox *subLabel =
       
   564         mUiLoader->findWidget<HbGroupBox>(
       
   565             DOCML_NAME_VC_HEADINGBANNER);
   627     if (subLabel)
   566     if (subLabel)
   628     {
   567     {
   629         if (show &&
   568         if (show &&
   630             subLabel->isVisible() &&
       
   631             mCurrentList->getLevel() == VideoCollectionCommon::ELevelVideos)
   569             mCurrentList->getLevel() == VideoCollectionCommon::ELevelVideos)
   632         {
   570         {
   633             subLabel->hide();
   571             subLabel->hide();
   634         }
   572         }
   635         else if (!subLabel->isVisible())
   573         else
   636         {
   574         {
   637             subLabel->show();
   575             subLabel->show();
   638         }
   576         }
   639     }
   577     }
   640 }
   578 }
   643 // setHintLevel
   581 // setHintLevel
   644 // ---------------------------------------------------------------------------
   582 // ---------------------------------------------------------------------------
   645 //
   583 //
   646 void VideoListView::setHintLevel(VideoHintWidget::HintLevel level)
   584 void VideoListView::setHintLevel(VideoHintWidget::HintLevel level)
   647 {
   585 {
       
   586 	FUNC_LOG;
   648 	mHintLevel = level;
   587 	mHintLevel = level;
   649 }
   588 }
   650 
   589 
   651 // ---------------------------------------------------------------------------
   590 // ---------------------------------------------------------------------------
   652 // updateSubLabel
   591 // updateSubLabel
   653 // ---------------------------------------------------------------------------
   592 // ---------------------------------------------------------------------------
   654 //
   593 //
   655 void VideoListView::updateSubLabel()
   594 void VideoListView::updateSubLabel()
   656 {
   595 {
       
   596 	FUNC_LOG;
   657     VideoSortFilterProxyModel *model = 0;
   597     VideoSortFilterProxyModel *model = 0;
   658     if(mCurrentList)
   598     if(mCurrentList)
   659     {
   599     {
   660         model = &mCurrentList->getModel(); 
   600         model = &mCurrentList->getModel(); 
   661     }
   601     }
   662     
   602     
   663     if (model)
   603     if (model)
   664     {
   604     {
   665         int itemCount = model->rowCount();
   605         int itemCount = model->rowCount();
   666         VideoListWidget *videoListWidget =
       
   667             mUiLoader->findWidget<VideoListWidget>(
       
   668                 DOCML_NAME_VC_VIDEOLISTWIDGET);
       
   669         
       
   670         VideoListWidget *collectionWidget =
       
   671             mUiLoader->findWidget<VideoListWidget>(
       
   672                 DOCML_NAME_VC_COLLECTIONWIDGET);
       
   673         
       
   674         VideoListWidget *collectionContentWidget =
       
   675             mUiLoader->findWidget<VideoListWidget>(
       
   676                 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   677         
   606         
   678         HbGroupBox *subLabel = 
   607         HbGroupBox *subLabel = 
   679             mUiLoader->findWidget<HbGroupBox>(
   608             mUiLoader->findWidget<HbGroupBox>(
   680                 DOCML_NAME_VC_HEADINGBANNER);
   609                 DOCML_NAME_VC_HEADINGBANNER);
   681 
   610 
   682         if(subLabel)
   611         if(subLabel && mCurrentList)
   683         {
   612         {
   684 			if (mCurrentList == videoListWidget)
   613 			if (mCurrentList->getLevel() == VideoCollectionCommon::ELevelVideos)
   685 			{
   614 			{
   686 				subLabel->setHeading(hbTrId("txt_videos_subtitle_ln_videos", itemCount));
   615 			    // no need to update sublabel if there are no items in videolist
       
   616 			    // hint widget is shown instead
       
   617 			    if (itemCount)
       
   618 			    {
       
   619 	                subLabel->setHeading(hbTrId("txt_videos_subtitle_ln_videos", itemCount));
       
   620 			    }
   687 			}
   621 			}
   688 			else if (mCurrentList == collectionWidget)
   622 			else if (mCurrentList->getLevel() == VideoCollectionCommon::ELevelCategory)
   689 			{
   623 			{
   690 				subLabel->setHeading(hbTrId("txt_videos_subtitle_ln_collections", itemCount));
   624 				subLabel->setHeading(hbTrId("txt_videos_subtitle_ln_collections", itemCount));
   691 			}
   625 			}
   692 			else if(mCurrentList == collectionContentWidget)
   626 			else
   693 			{
   627 			{
   694 				subLabel->setHeading(hbTrId("txt_videos_subtitle_1_l2").arg(mCollectionName).arg(itemCount));
   628 				subLabel->setHeading(hbTrId("txt_videos_subtitle_1_l2").arg(mCollectionName).arg(itemCount));
   695 			}
   629 			}
   696         }
   630         }
   697     }
   631     }
   701 // showAction()
   635 // showAction()
   702 // ---------------------------------------------------------------------------
   636 // ---------------------------------------------------------------------------
   703 //
   637 //
   704 void VideoListView::showAction(bool show, const QString &name)
   638 void VideoListView::showAction(bool show, const QString &name)
   705 {
   639 {
       
   640 	FUNC_LOG;
   706     HbAction *action = mUiLoader->findObject<HbAction>(name);
   641     HbAction *action = mUiLoader->findObject<HbAction>(name);
   707     if (!action)
   642     if (!action)
   708     {
   643     {
   709         // must be menu widget
   644         // must be menu widget
   710         HbMenu *menu = mUiLoader->findWidget<HbMenu>(name);
   645         HbMenu *menu = mUiLoader->findWidget<HbMenu>(name);
   720         action->setVisible(show);
   655         action->setVisible(show);
   721     }
   656     }
   722 }
   657 }
   723 
   658 
   724 // ---------------------------------------------------------------------------
   659 // ---------------------------------------------------------------------------
   725 // isActionChecked()
   660 // activateVideosView()
   726 // ---------------------------------------------------------------------------
   661 // ---------------------------------------------------------------------------
   727 //
   662 //
   728 bool VideoListView::isActionChecked(const QString &name)
   663 int VideoListView::activateVideosView()
   729 {
   664 {
   730     bool isChecked = false;
   665     FUNC_LOG;
   731     
   666     VideoListWidget *videoList =
   732     HbAction *action = mUiLoader->findObject<HbAction>(name);
   667         mUiLoader->findWidget<VideoListWidget>(
   733     if (!action)
   668             DOCML_NAME_VC_VIDEOLISTWIDGET);
   734     {
   669     if (videoList)
   735         // must be menu widget
   670     {
   736         HbMenu *menu = mUiLoader->findWidget<HbMenu>(name);
   671         VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
   737         if (menu)
   672         if (mCurrentList)
   738         {
   673         {
   739             action = menu->menuAction();
   674             level = mCurrentList->getLevel();
   740         }
   675         }
   741     }
   676         else
   742 
   677         {
   743     // check if action is checked
   678             mCurrentList = videoList;
   744     if (action)
   679         }
   745     {
   680         
   746         isChecked = action->isChecked();
   681         int result = mCurrentList->activate(level);
   747     }
   682         if(result < 0)
   748     
   683         {
   749     return isChecked;
   684             ERROR(result, "VideoListView::activateVideosView() failed to activate.");
   750 }
   685             // activate failed, deactivate view so we get rid of dangling connections.
   751 
   686             deactivateView();
   752 // ---------------------------------------------------------------------------
   687             return -1;
   753 // isActionChecked()
   688         }
   754 // ---------------------------------------------------------------------------
   689         
   755 //
   690         if (createToolbar() != 0)
   756 void VideoListView::setActionChecked(bool setChecked, const QString &name)
   691         {
   757 {
   692             ERROR(result, "VideoListView::activateVideosView() failed to create toolbar.");
   758     HbAction *action = mUiLoader->findObject<HbAction>(name);
   693             deactivateView();
   759     if (!action)
   694             return -1;
   760     {
   695         }
   761         // must be menu widget
   696     }
   762         HbMenu *menu = mUiLoader->findWidget<HbMenu>(name);
   697     else
   763         if (menu)
   698     {
   764         {
   699         return -1;
   765             action = menu->menuAction();
   700     }
   766         }
   701     
   767     }
   702     return 0;
   768 
   703 }
   769     // update action check state
   704 
   770     if (action)
   705 // ---------------------------------------------------------------------------
   771     {
   706 // activateCollectionContentView()
   772         action->setChecked(setChecked);
   707 // ---------------------------------------------------------------------------
   773     }
   708 //
       
   709 int VideoListView::activateCollectionContentView(const TMPXItemId &itemId)
       
   710 {
       
   711     FUNC_LOG;
       
   712     int err = 0;
       
   713     
       
   714     if (itemId.iId2 == KVcxMvcMediaTypeCategory ||
       
   715         itemId.iId2 == KVcxMvcMediaTypeAlbum)
       
   716     {
       
   717         // currently only captured and downloaded categories are supported
       
   718         switch (itemId.iId1)
       
   719         {
       
   720             case KVcxMvcCategoryIdDownloads:
       
   721             case KVcxMvcCategoryIdCaptured:
       
   722             {
       
   723                 VideoListWidget *collectionContentWidget =
       
   724                     mUiLoader->findWidget<VideoListWidget>(
       
   725                         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   726                 if (collectionContentWidget)
       
   727                 {
       
   728                     // no need to deactivate since there cannot be previous widget
       
   729                     mCurrentList = collectionContentWidget;
       
   730                     
       
   731                     // hide toolbar
       
   732                     HbToolBar *toolBar = this->toolBar();
       
   733                     if (toolBar)
       
   734                     {
       
   735                         toolBar->hide();
       
   736                     }
       
   737                     
       
   738                     // resolve collection name
       
   739                     if (itemId.iId1 == KVcxMvcCategoryIdDownloads)
       
   740                     {
       
   741                         mCollectionName = hbTrId("txt_videos_dblist_downloaded");
       
   742                     }
       
   743                     else if (itemId.iId1 == KVcxMvcCategoryIdCaptured)
       
   744                     {
       
   745                         mCollectionName = hbTrId("txt_videos_dblist_captured");
       
   746                     }
       
   747                     
       
   748                     // activate collection content widget
       
   749                     mCurrentList->activate(VideoCollectionCommon::ELevelDefaultColl);
       
   750                     
       
   751                     // open the model
       
   752                     VideoSortFilterProxyModel &model = mCurrentList->getModel();
       
   753                     model.openItem(itemId);
       
   754                     
       
   755                     // sort model
       
   756                     model.doSorting(VideoCollectionCommon::KeyDateTime, Qt::AscendingOrder);
       
   757                     
       
   758                     // set hint level to collections
       
   759                     setHintLevel(VideoHintWidget::Collection);
       
   760                 }
       
   761                 else
       
   762                 {
       
   763                     ERROR(-1, "VideoListView::activateVideosView() failed to get collection content widget.");
       
   764                     err = -1;
       
   765                 }
       
   766                 break;
       
   767             }
       
   768             default:
       
   769             {
       
   770                 // by default open videos view
       
   771                 err = activateVideosView();
       
   772                 break;
       
   773             }
       
   774         }
       
   775         
       
   776     }
       
   777     else
       
   778     {
       
   779         // open videos view
       
   780         err = activateVideosView();
       
   781     }
       
   782 
       
   783     return err;
   774 }
   784 }
   775 
   785 
   776 // ---------------------------------------------------------------------------
   786 // ---------------------------------------------------------------------------
   777 // openAllVideosViewSlot()
   787 // openAllVideosViewSlot()
   778 // ---------------------------------------------------------------------------
   788 // ---------------------------------------------------------------------------
   779 //
   789 //
   780 void VideoListView::openAllVideosViewSlot()
   790 void VideoListView::openAllVideosViewSlot()
   781 {
   791 {
   782 	if(!mListsLoaded)
   792 	FUNC_LOG;
   783 	{
       
   784 		loadLists(false);
       
   785 	}
       
   786 
       
   787     VideoListWidget *videoListWidget =
   793     VideoListWidget *videoListWidget =
   788         mUiLoader->findWidget<VideoListWidget>(
   794         mUiLoader->findWidget<VideoListWidget>(
   789             DOCML_NAME_VC_VIDEOLISTWIDGET);
   795             DOCML_NAME_VC_VIDEOLISTWIDGET);
   790     
   796     
   791     if (mCurrentList &&
   797     if (mCurrentList &&
   811 // openCollectionViewSlot()
   817 // openCollectionViewSlot()
   812 // ---------------------------------------------------------------------------
   818 // ---------------------------------------------------------------------------
   813 //
   819 //
   814 void VideoListView::openCollectionViewSlot()
   820 void VideoListView::openCollectionViewSlot()
   815 {
   821 {
   816 	if(!mListsLoaded)
   822 	FUNC_LOG;
   817 	{
       
   818 		loadLists(false);
       
   819 	}
       
   820 
       
   821     VideoListWidget *collectionWidget =
   823     VideoListWidget *collectionWidget =
   822         mUiLoader->findWidget<VideoListWidget>(
   824         mUiLoader->findWidget<VideoListWidget>(
   823             DOCML_NAME_VC_COLLECTIONWIDGET);
   825             DOCML_NAME_VC_COLLECTIONWIDGET);
   824     
   826     
   825     if (mCurrentList &&
   827     if (mCurrentList &&
   831         // activate video collection widget
   833         // activate video collection widget
   832         mCurrentList = collectionWidget;
   834         mCurrentList = collectionWidget;
   833         mCurrentList->activate(VideoCollectionCommon::ELevelCategory);
   835         mCurrentList->activate(VideoCollectionCommon::ELevelCategory);
   834         
   836         
   835         VideoSortFilterProxyModel &model = mCurrentList->getModel(); 
   837         VideoSortFilterProxyModel &model = mCurrentList->getModel(); 
   836         VideoCollectionViewUtils::sortModel(&model, false);
   838 
       
   839         VideoCollectionViewUtils::sortModel(&model, false, mCurrentList->getLevel());
   837 
   840 
   838         // the collection view is not empty, so we can hide the hint in advance.
   841         // the collection view is not empty, so we can hide the hint in advance.
   839         showHint(false);
   842         showHint(false);
   840     }
   843     }
   841 }
   844 }
   846 //
   849 //
   847 void VideoListView::openNewAlbumSlot(const QModelIndex &parent,
   850 void VideoListView::openNewAlbumSlot(const QModelIndex &parent,
   848     int start,
   851     int start,
   849     int end)
   852     int end)
   850 {
   853 {
       
   854 	FUNC_LOG;
   851     Q_UNUSED(end);
   855     Q_UNUSED(end);
   852     if(!mCurrentList)
   856     if(!mCurrentList)
   853     {
   857     {
   854         return;
   858         return;
   855     }
   859     }
   873 // openservicesViewSlot()
   877 // openservicesViewSlot()
   874 // ---------------------------------------------------------------------------
   878 // ---------------------------------------------------------------------------
   875 //
   879 //
   876 void VideoListView::openServicesViewSlot()
   880 void VideoListView::openServicesViewSlot()
   877 {
   881 {
       
   882 	FUNC_LOG;
   878     debugNotImplementedYet();
   883     debugNotImplementedYet();
   879 }
   884 }
   880 
   885 
   881 // ---------------------------------------------------------------------------
   886 // ---------------------------------------------------------------------------
   882 // startSorting()
   887 // startSorting()
   883 // ---------------------------------------------------------------------------
   888 // ---------------------------------------------------------------------------
   884 //
   889 //
   885 void VideoListView::startSorting()
   890 void VideoListView::startSorting()
   886 {
   891 {
       
   892 	FUNC_LOG;
   887     HbMenu *optionsMenu =
   893     HbMenu *optionsMenu =
   888         mUiLoader->findWidget<HbMenu>(
   894         mUiLoader->findWidget<HbMenu>(
   889             DOCML_NAME_OPTIONS_MENU);
   895             DOCML_NAME_OPTIONS_MENU);
   890     if (optionsMenu)
   896     if (optionsMenu && mCurrentList)
   891     {
   897     {
   892         // get sorting role from active action
   898         // get sorting role from active action
   893         HbAction *action = optionsMenu->activeAction()->menu()->activeAction();
   899         HbAction* action = optionsMenu->activeAction();
   894         if(action)
   900         HbMenu* sortMenu = mUiLoader->findWidget<HbMenu>(DOCML_NAME_SORT_MENU);
   895 		{
   901         if(action == sortMenu->menuAction()) // make sure that active action is the sort menu. 
   896 			doSorting(mSortingRoles[action]);
   902         {
   897 		}
   903             HbAction* action = sortMenu->activeAction();
       
   904             if(action)
       
   905             {
       
   906                 doSorting(mSortingRoles[action]);
       
   907             }
       
   908         }
   898     }
   909     }
   899 }
   910 }
   900 
   911 
   901 // ---------------------------------------------------------------------------
   912 // ---------------------------------------------------------------------------
   902 // doSorting()
   913 // doSorting()
   903 // ---------------------------------------------------------------------------
   914 // ---------------------------------------------------------------------------
   904 //
   915 //
   905 void VideoListView::doSorting(int role)
   916 void VideoListView::doSorting(int role)
   906 {
   917 {
       
   918 	FUNC_LOG;
   907 	// sort model
   919 	// sort model
   908 	Qt::SortOrder order(Qt::AscendingOrder);
   920 	Qt::SortOrder order(Qt::AscendingOrder);
   909 	VideoSortFilterProxyModel &model = mCurrentList->getModel();
   921 	VideoSortFilterProxyModel &model = mCurrentList->getModel();
   910 	if(model.sortRole() == role && model.sortOrder() == Qt::AscendingOrder)
   922 	if(model.sortRole() == role && model.sortOrder() == Qt::AscendingOrder)
   911 	{
   923 	{
   912 		order = Qt::DescendingOrder;
   924 		order = Qt::DescendingOrder;
   913 	}
   925 	}
   914 	model.doSorting(role, order);
   926 	model.doSorting(role, order);
   915 
   927 
       
   928 	if (mCurrentList == mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET))
       
   929 	{
       
   930 		mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_VIDEOLISTWIDGET)->getModel().doSorting(role, order);	
       
   931 	}
       
   932 
   916 	// save sorting values
   933 	// save sorting values
   917 	mUiUtils.saveSortingValues(role, order);
   934 	mUiUtils.saveSortingValues(role, order, mCurrentList->getLevel());
   918 }
   935 }
   919 
   936 
   920 // -------------------------------------------------------------------------------------------------
   937 // -------------------------------------------------------------------------------------------------
   921 // aboutToChangeOrientationSlot()
   938 // aboutToChangeOrientationSlot()
   922 // hide all items in the window during orientation change
   939 // hide all items in the window during orientation change
   923 // -------------------------------------------------------------------------------------------------
   940 // -------------------------------------------------------------------------------------------------
   924 //
   941 //
   925 void VideoListView::aboutToChangeOrientationSlot()
   942 void VideoListView::aboutToChangeOrientationSlot()
   926 {
   943 {
       
   944 	FUNC_LOG;
   927     // this method is required for changing from to mediawall
   945     // this method is required for changing from to mediawall
   928 }
   946 }
   929 
   947 
   930 // -------------------------------------------------------------------------------------------------
   948 // -------------------------------------------------------------------------------------------------
   931 // orientationChangedSlot()
   949 // orientationChangedSlot()
   932 // orientation changed, items can be put back to visible after view has handled the change
   950 // orientation changed, items can be put back to visible after view has handled the change
   933 // -------------------------------------------------------------------------------------------------
   951 // -------------------------------------------------------------------------------------------------
   934 //
   952 //
   935 void VideoListView::orientationChangedSlot( Qt::Orientation orientation )
   953 void VideoListView::orientationChangedSlot( Qt::Orientation orientation )
   936 {
   954 {
       
   955 	FUNC_LOG;
   937     // this method is required for changing from to mediawall
   956     // this method is required for changing from to mediawall
   938     
   957     
   939     // in landscape we need to hide the title and the toolbar. (also required for the mediawall?)
   958     // in landscape we need to hide the title and the toolbar. (also required for the mediawall?)
   940     // TODO: how about the feature where the toolbar comes visible if screen is tapped?
   959     // TODO: how about the feature where the toolbar comes visible if screen is tapped?
   941     this->setItemVisible(Hb::AllItems, orientation == Qt::Vertical);
   960     this->setItemVisible(Hb::AllItems, orientation == Qt::Vertical);
   945 // deleteItemsSlot
   964 // deleteItemsSlot
   946 // -------------------------------------------------------------------------------------------------
   965 // -------------------------------------------------------------------------------------------------
   947 //
   966 //
   948 void VideoListView::deleteItemsSlot()
   967 void VideoListView::deleteItemsSlot()
   949 {
   968 {
       
   969 	FUNC_LOG;
   950     if(!mCurrentList)
   970     if(!mCurrentList)
   951     {
   971     {
   952         return;
   972         return;
   953     }
       
   954 
       
   955     if(!mMultiselectionLoaded)
       
   956     {
       
   957     	loadMultiSelection();
       
   958     }
   973     }
   959 
   974 
   960     VideoListSelectionDialog *dialog =
   975     VideoListSelectionDialog *dialog =
   961         mUiLoader->findWidget<VideoListSelectionDialog>(
   976         mUiLoader->findWidget<VideoListSelectionDialog>(
   962             DOCML_NAME_DIALOG);
   977             DOCML_NAME_DIALOG);
   972 // createCollectionSlot
   987 // createCollectionSlot
   973 // -------------------------------------------------------------------------------------------------
   988 // -------------------------------------------------------------------------------------------------
   974 //
   989 //
   975 void VideoListView::createCollectionSlot()
   990 void VideoListView::createCollectionSlot()
   976 {
   991 {
       
   992 	FUNC_LOG;
   977     if(!mCurrentList)
   993     if(!mCurrentList)
   978     {
   994     {
   979         return;
   995         return;
   980     }
   996     }
   981     
   997     
   982     VideoSortFilterProxyModel &model = mCurrentList->getModel();
   998     VideoSortFilterProxyModel &model = mCurrentList->getModel();
   983 
       
   984     
   999     
   985     bool ok = false;
  1000     bool ok = false;
   986     // query a name for the collection
  1001     // query a name for the collection
   987     QString label(hbTrId("txt_videos_title_enter_name"));
  1002     QString label(hbTrId("txt_videos_title_enter_name"));
   988     QString text(hbTrId("txt_videos_dialog_entry_new_collection"));
  1003     QString text(hbTrId("txt_videos_dialog_entry_new_collection"));
  1008 // addVideosToCollectionSlot
  1023 // addVideosToCollectionSlot
  1009 // -------------------------------------------------------------------------------------------------
  1024 // -------------------------------------------------------------------------------------------------
  1010 //
  1025 //
  1011 void VideoListView::addVideosToCollectionSlot()
  1026 void VideoListView::addVideosToCollectionSlot()
  1012 {
  1027 {
       
  1028 	FUNC_LOG;
  1013     if(!mCurrentList)
  1029     if(!mCurrentList)
  1014     {
  1030     {
  1015         return;
  1031         return;
  1016     }
       
  1017 
       
  1018     if(!mMultiselectionLoaded)
       
  1019     {
       
  1020     	loadMultiSelection();
       
  1021     }
  1032     }
  1022 
  1033 
  1023     VideoListSelectionDialog *dialog =
  1034     VideoListSelectionDialog *dialog =
  1024         mUiLoader->findWidget<VideoListSelectionDialog>(
  1035         mUiLoader->findWidget<VideoListSelectionDialog>(
  1025             DOCML_NAME_DIALOG);
  1036             DOCML_NAME_DIALOG);
  1059 // removeVideosFromCollectionSlot
  1070 // removeVideosFromCollectionSlot
  1060 // -------------------------------------------------------------------------------------------------
  1071 // -------------------------------------------------------------------------------------------------
  1061 //
  1072 //
  1062 void VideoListView::removeVideosFromCollectionSlot()
  1073 void VideoListView::removeVideosFromCollectionSlot()
  1063 {
  1074 {
       
  1075 	FUNC_LOG;
  1064     if(!mCurrentList)
  1076     if(!mCurrentList)
  1065     {
  1077     {
  1066         return;
  1078         return;
  1067     }
  1079     }
  1068     // not allowed if for some reason current widget 
  1080     // not allowed if for some reason current widget 
  1071        !mCurrentList->getModel().rowCount())
  1083        !mCurrentList->getModel().rowCount())
  1072     {
  1084     {
  1073         return;
  1085         return;
  1074     }
  1086     }
  1075 
  1087 
  1076     if(!mMultiselectionLoaded)
       
  1077     {
       
  1078     	loadMultiSelection();
       
  1079     }
       
  1080 
       
  1081     VideoListSelectionDialog *dialog =
  1088     VideoListSelectionDialog *dialog =
  1082             mUiLoader->findWidget<VideoListSelectionDialog>(
  1089             mUiLoader->findWidget<VideoListSelectionDialog>(
  1083                         DOCML_NAME_DIALOG);
  1090                         DOCML_NAME_DIALOG);
  1084     if (!dialog)
  1091     if (!dialog)
  1085     {
  1092     {
  1086         // fatal: no selection dialog
  1093         ERROR(-1, "VideoListView::removeVideosFromCollectionSlot() failed to load selection dialog.");
  1087         return;
  1094         return;
  1088     }
  1095     }
  1089     TMPXItemId collectionId = mCurrentList->getModel().getOpenItem();
  1096     TMPXItemId collectionId = mCurrentList->getModel().getOpenItem();
  1090     if(collectionId != TMPXItemId::InvalidId() && collectionId.iId2 != KVcxMvcMediaTypeVideo)
  1097     if(collectionId != TMPXItemId::InvalidId() && collectionId.iId2 != KVcxMvcMediaTypeVideo)
  1091     {
  1098     {
  1098 // aboutToShowMainMenuSlot
  1105 // aboutToShowMainMenuSlot
  1099 // -------------------------------------------------------------------------------------------------
  1106 // -------------------------------------------------------------------------------------------------
  1100 //
  1107 //
  1101 void VideoListView::aboutToShowMainMenuSlot()
  1108 void VideoListView::aboutToShowMainMenuSlot()
  1102 {
  1109 {
       
  1110     if (mIsService &&
       
  1111         mVideoServices &&
       
  1112         mVideoServices->currentService() == VideoServices::EBrowse)
       
  1113     {
       
  1114         prepareBrowseServiceMenu();
       
  1115         return;
       
  1116     }
       
  1117     
  1103 	if (!mCurrentList ||
  1118 	if (!mCurrentList ||
  1104 	    !mToolbarViewsActionGroup ||
  1119 	    !mToolbarViewsActionGroup ||
  1105 	    !mToolbarCollectionActionGroup)
  1120 	    !mToolbarCollectionActionGroup)
  1106 	{
  1121 	{
  1107 		return;
  1122 		return;
  1112     showAction(false, DOCML_NAME_CREATE_COLLECTION);
  1127     showAction(false, DOCML_NAME_CREATE_COLLECTION);
  1113     showAction(false, DOCML_NAME_DELETE_MULTIPLE);
  1128     showAction(false, DOCML_NAME_DELETE_MULTIPLE);
  1114     showAction(false, DOCML_NAME_SORT_BY_DATE);
  1129     showAction(false, DOCML_NAME_SORT_BY_DATE);
  1115     showAction(false, DOCML_NAME_SORT_BY_NAME);
  1130     showAction(false, DOCML_NAME_SORT_BY_NAME);
  1116     showAction(false, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
  1131     showAction(false, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
  1117     showAction(false, DOCML_NAME_SORT_BY_RATING);
       
  1118     showAction(false, DOCML_NAME_SORT_BY_SIZE);
  1132     showAction(false, DOCML_NAME_SORT_BY_SIZE);
  1119     showAction(false, DOCML_NAME_SORT_MENU);
  1133     showAction(false, DOCML_NAME_SORT_MENU);
  1120     
  1134     
  1121     VideoSortFilterProxyModel &model = mCurrentList->getModel();
  1135     VideoSortFilterProxyModel &model = mCurrentList->getModel();
  1122     if (!model.rowCount(QModelIndex()))
  1136     if (!model.rowCount())
  1123     {
  1137     {
  1124         return;
  1138         return;
  1125     }
  1139     }
  1126     
  1140     
  1127     // get current sorting values
  1141     // get current sorting values
  1133 
  1147 
  1134     if(mToolbarViewsActionGroup->checkedAction() == mToolbarActions[ETBActionAllVideos] &&
  1148     if(mToolbarViewsActionGroup->checkedAction() == mToolbarActions[ETBActionAllVideos] &&
  1135        firstAction == mToolbarActions[ETBActionAllVideos])
  1149        firstAction == mToolbarActions[ETBActionAllVideos])
  1136     {
  1150     {
  1137         showAction(true, DOCML_NAME_SORT_MENU);
  1151         showAction(true, DOCML_NAME_SORT_MENU);
       
  1152 
  1138         showAction(true, DOCML_NAME_SORT_BY_DATE);
  1153         showAction(true, DOCML_NAME_SORT_BY_DATE);
  1139         if (isActionChecked(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS))
       
  1140         {
       
  1141             //TODO: when changing between videos and categories, sorting order needs to be changed, if new
       
  1142             //      view does not have the previously active sorting order supported
       
  1143             showAction(true, DOCML_NAME_SORT_BY_DATE);
       
  1144         }
       
  1145         else
       
  1146         {
       
  1147             HbAction* action = mSortingRoles.key(role);
       
  1148             if (action)
       
  1149             {
       
  1150                 action->setChecked(true);
       
  1151             }
       
  1152         }
       
  1153         
       
  1154         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1154         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1155         showAction(true, DOCML_NAME_SORT_BY_SIZE);
  1155         showAction(true, DOCML_NAME_SORT_BY_SIZE);
  1156 
  1156 
       
  1157         HbAction* action = mSortingRoles.key(role);
       
  1158 		if (action)
       
  1159 		{
       
  1160 			action->setChecked(true);
       
  1161 		}
       
  1162 
  1157         if (!mIsService)
  1163         if (!mIsService)
  1158         {
  1164         {
  1159             showAction(true, DOCML_NAME_ADD_TO_COLLECTION);
  1165             showAction(true, DOCML_NAME_ADD_TO_COLLECTION);
  1160             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1166             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1161         }
  1167         }
  1167         {
  1173         {
  1168             showAction(true, DOCML_NAME_CREATE_COLLECTION);
  1174             showAction(true, DOCML_NAME_CREATE_COLLECTION);
  1169         }
  1175         }
  1170         showAction(true, DOCML_NAME_SORT_MENU);
  1176         showAction(true, DOCML_NAME_SORT_MENU);
  1171         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1177         showAction(true, DOCML_NAME_SORT_BY_NAME);
       
  1178         showAction(true, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
  1172     	
  1179     	
  1173         if (isActionChecked(DOCML_NAME_SORT_BY_DATE) ||
  1180 		HbAction* action = mSortingRoles.key(role);
  1174             isActionChecked(DOCML_NAME_SORT_BY_SIZE))
  1181 		if (action)
  1175     	{
  1182 		{
  1176             //TODO: when changing between videos and categories, sorting order needs to be changed, if new
  1183 			action->setChecked(true);
  1177             //      view does not have the previously active sorting order supported
  1184 		}
  1178             setActionChecked(true, DOCML_NAME_SORT_BY_NAME);
       
  1179     	}
       
  1180         else
       
  1181         {
       
  1182             HbAction* action = mSortingRoles.key(role);
       
  1183             if (action)
       
  1184             {
       
  1185                 action->setChecked(true);
       
  1186             }
       
  1187         }
       
  1188         
       
  1189         showAction(true, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
       
  1190     }
  1185     }
  1191     else if(firstAction != mToolbarActions[ETBActionAllVideos])
  1186     else if(firstAction != mToolbarActions[ETBActionAllVideos])
  1192     {
  1187     {
  1193         showAction(true, DOCML_NAME_SORT_MENU);
  1188         showAction(true, DOCML_NAME_SORT_MENU);
  1194         showAction(true, DOCML_NAME_SORT_BY_DATE);
  1189         showAction(true, DOCML_NAME_SORT_BY_DATE);
  1195         if (isActionChecked(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS))
       
  1196         {
       
  1197             //TODO: when changing between videos and categories, sorting order needs to be changed, if new
       
  1198             //      view does not have the previously active sorting order supported
       
  1199             showAction(true, DOCML_NAME_SORT_BY_DATE);
       
  1200         }
       
  1201         else
       
  1202         {
       
  1203             HbAction* action = mSortingRoles.key(role);
       
  1204             if (action)
       
  1205             {
       
  1206                 action->setChecked(true);
       
  1207             }
       
  1208         }
       
  1209 
       
  1210         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1190         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1211         showAction(true, DOCML_NAME_SORT_BY_SIZE);
  1191         showAction(true, DOCML_NAME_SORT_BY_SIZE);
  1212 
  1192 
       
  1193         HbAction* action = mSortingRoles.key(role);
       
  1194 		if (action)
       
  1195 		{
       
  1196 			action->setChecked(true);
       
  1197 		}
       
  1198 
  1213         if (!mIsService)
  1199         if (!mIsService)
  1214         {
  1200         {
  1215             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1201             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1216         }
  1202         }
  1217     }
  1203     }
  1218 }
  1204 }
  1219 
  1205 
  1220 // -------------------------------------------------------------------------------------------------
  1206 // -------------------------------------------------------------------------------------------------
       
  1207 // prepareBrowseServiceMenu
       
  1208 // -------------------------------------------------------------------------------------------------
       
  1209 //
       
  1210 void VideoListView::prepareBrowseServiceMenu()
       
  1211 {
       
  1212     if (!mCurrentList)
       
  1213     {
       
  1214         return;
       
  1215     }
       
  1216     
       
  1217     // hide all actions by default
       
  1218     showAction(false, DOCML_NAME_ADD_TO_COLLECTION);
       
  1219     showAction(false, DOCML_NAME_CREATE_COLLECTION);
       
  1220     showAction(false, DOCML_NAME_DELETE_MULTIPLE);
       
  1221     showAction(false, DOCML_NAME_SORT_BY_DATE);
       
  1222     showAction(false, DOCML_NAME_SORT_BY_NAME);
       
  1223     showAction(false, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
       
  1224     showAction(false, DOCML_NAME_SORT_BY_SIZE);
       
  1225     showAction(false, DOCML_NAME_SORT_MENU);
       
  1226     
       
  1227     VideoSortFilterProxyModel &model = mCurrentList->getModel();
       
  1228     if (!model.rowCount())
       
  1229     {
       
  1230         return;
       
  1231     }
       
  1232     
       
  1233     // show delete action
       
  1234     showAction(true, DOCML_NAME_DELETE_MULTIPLE);
       
  1235     
       
  1236     // show sort actions
       
  1237     showAction(true, DOCML_NAME_SORT_MENU);
       
  1238     showAction(true, DOCML_NAME_SORT_BY_DATE);
       
  1239     showAction(true, DOCML_NAME_SORT_BY_NAME);
       
  1240     showAction(true, DOCML_NAME_SORT_BY_SIZE);
       
  1241     
       
  1242     // set current sort action selected
       
  1243     int role;
       
  1244     Qt::SortOrder order;
       
  1245     model.getSorting(role, order);
       
  1246     HbAction* action = mSortingRoles.key(role);
       
  1247     if (action)
       
  1248     {
       
  1249         action->setChecked(true);
       
  1250     }
       
  1251 }
       
  1252 
       
  1253 // -------------------------------------------------------------------------------------------------
  1221 // handleAsyncStatusSlot
  1254 // handleAsyncStatusSlot
  1222 // -------------------------------------------------------------------------------------------------
  1255 // -------------------------------------------------------------------------------------------------
  1223 //
  1256 //
  1224 void VideoListView::handleAsyncStatusSlot(int statusCode, QVariant &additional)
  1257 void VideoListView::handleAsyncStatusSlot(int statusCode, QVariant &additional)
  1225 {
  1258 {
       
  1259 	FUNC_LOG;
  1226     // show msg from status
  1260     // show msg from status
  1227     mUiUtils.showStatusMsgSlot(statusCode, additional);
  1261     mUiUtils.showStatusMsgSlot(statusCode, additional);
  1228 }
  1262 }
  1229 
  1263 
  1230 // -------------------------------------------------------------------------------------------------
  1264 // -------------------------------------------------------------------------------------------------
  1233 //
  1267 //
  1234 void VideoListView::collectionOpenedSlot(bool collectionOpened,
  1268 void VideoListView::collectionOpenedSlot(bool collectionOpened,
  1235     const QString& collection,
  1269     const QString& collection,
  1236     const QModelIndex &index)
  1270     const QModelIndex &index)
  1237 {
  1271 {
       
  1272 	FUNC_LOG;
  1238 	if(mTransitionOngoing)
  1273 	if(mTransitionOngoing)
  1239 	{
  1274 	{
  1240 		return;
  1275 		return;
  1241 	}
  1276 	}
  1242 	else
  1277 	else
  1243 	{
  1278 	{
  1244 	    // clear toolbar actions.
  1279 	    // clear toolbar actions.
  1245 	    toolBar()->clearActions();
  1280 	    toolBar()->clearActions();
  1246 	}
  1281 	}
  1247 	
  1282 
  1248     // update collection specific information
  1283 	if(collectionOpened)
  1249     mCollectionName = collection;
       
  1250 
       
  1251     if(collectionOpened)
       
  1252     {
  1284     {
  1253         if(!index.isValid())
  1285         if(!index.isValid())
  1254         {   
  1286         {   
  1255             return;
  1287             return;
  1256         }
  1288         }
  1258         // open album view
  1290         // open album view
  1259         VideoListWidget *collectionContentWidget =
  1291         VideoListWidget *collectionContentWidget =
  1260             mUiLoader->findWidget<VideoListWidget>(
  1292             mUiLoader->findWidget<VideoListWidget>(
  1261                 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
  1293                 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
  1262         
  1294         
  1263         if (mCurrentList &&
  1295         if (!mCurrentList || mCurrentList == collectionContentWidget)
  1264             mCurrentList != collectionContentWidget)
  1296         {
  1265         {
  1297             // no currentlist or currentlist is already list 
  1266             // get item id before deactivating
  1298             // we're about to transit
  1267             TMPXItemId itemId = TMPXItemId::InvalidId();
  1299             return;
  1268             itemId = mCurrentList->getModel().getMediaIdAtIndex(index);
  1300         }
  1269             
  1301 
  1270             // only category or album can be activated here
  1302         // get item id before deactivating
  1271             if(itemId == TMPXItemId::InvalidId() ||
  1303         TMPXItemId itemId = TMPXItemId::InvalidId();
  1272                (itemId.iId2 != KVcxMvcMediaTypeCategory && 
  1304         itemId = mCurrentList->getModel().getMediaIdAtIndex(index);
  1273                 itemId.iId2 != KVcxMvcMediaTypeAlbum))
  1305         
  1274             {
  1306         // only category or album can be activated here
  1275                 return;
  1307         if(itemId == TMPXItemId::InvalidId() ||
  1276             }
  1308            (itemId.iId2 != KVcxMvcMediaTypeCategory && 
  1277             
  1309             itemId.iId2 != KVcxMvcMediaTypeAlbum))
  1278             // Send level that is opened with the effect.
  1310         {
  1279             QVariant nextLevel;
  1311             return;
  1280             if(itemId.iId2 ==  KVcxMvcMediaTypeCategory)
  1312         }
  1281             {
  1313         
  1282                 nextLevel = QVariant(VideoCollectionCommon::ELevelDefaultColl);
  1314         // Send level that is opened with the effect.
  1283             }
  1315         QVariant nextLevel;
  1284             else if(itemId.iId2 == KVcxMvcMediaTypeAlbum)
  1316         if(itemId.iId2 ==  KVcxMvcMediaTypeCategory)
  1285             {
  1317         {
  1286                 nextLevel = QVariant(VideoCollectionCommon::ELevelAlbum);
  1318             nextLevel = QVariant(VideoCollectionCommon::ELevelDefaultColl);
  1287             }            
  1319         }
  1288             
  1320         else if(itemId.iId2 == KVcxMvcMediaTypeAlbum)
  1289             // Start fetching content.
  1321         {
  1290             collectionContentWidget->getModel().openItem(itemId);
  1322             nextLevel = QVariant(VideoCollectionCommon::ELevelAlbum);
  1291             
  1323         }            
  1292             HbEffect::start(collectionContentWidget,
  1324         
  1293                             EFFECT_SLIDE_IN_TO_LEFT,
  1325         // Start fetching content.
  1294                             this,
  1326         collectionContentWidget->getModel().openItem(itemId);
  1295                             "finishCollectionOpenedSlot",
  1327         
  1296                             nextLevel);
  1328         HbEffect::start(collectionContentWidget,
  1297             
  1329                         EFFECT_SLIDE_IN_TO_LEFT,
  1298             mTransitionOngoing = true;
  1330                         this,
  1299         }
  1331                         "finishCollectionOpenedSlot",
       
  1332                         nextLevel);
       
  1333         
       
  1334         mTransitionOngoing = true;
  1300     }
  1335     }
  1301     else
  1336     else
  1302     {
  1337     {
  1303         // open categories view.
  1338         // open categories view.
  1304         VideoListWidget *collectionContentWidget =
  1339         VideoListWidget *collectionContentWidget =
  1310                         this,
  1345                         this,
  1311                         "finishCollectionClosedSlot");
  1346                         "finishCollectionClosedSlot");
  1312         
  1347         
  1313         mTransitionOngoing = true;
  1348         mTransitionOngoing = true;
  1314     }
  1349     }
       
  1350 	// update collection specific information
       
  1351 	mCollectionName = collection;
  1315 }
  1352 }
  1316 
  1353 
  1317 // -------------------------------------------------------------------------------------------------
  1354 // -------------------------------------------------------------------------------------------------
  1318 // finishCollectionOpenedSlot
  1355 // finishCollectionOpenedSlot
  1319 // -------------------------------------------------------------------------------------------------
  1356 // -------------------------------------------------------------------------------------------------
  1320 //
  1357 //
  1321 void VideoListView::finishCollectionOpenedSlot(const HbEffect::EffectStatus &status)
  1358 void VideoListView::finishCollectionOpenedSlot(const HbEffect::EffectStatus &status)
  1322 {
  1359 {
       
  1360 	FUNC_LOG;
  1323     Q_UNUSED(status);
  1361     Q_UNUSED(status);
  1324     
  1362     
  1325     mTransitionOngoing = false;
  1363     mTransitionOngoing = false;
  1326     
  1364     
  1327     // deactivat current widget.
  1365     // deactivat current widget.
  1338     
  1376     
  1339     updateSubLabel();
  1377     updateSubLabel();
  1340 
  1378 
  1341     VideoCollectionCommon::TCollectionLevels level =
  1379     VideoCollectionCommon::TCollectionLevels level =
  1342             static_cast<VideoCollectionCommon::TCollectionLevels>(status.userData.toInt());
  1380             static_cast<VideoCollectionCommon::TCollectionLevels>(status.userData.toInt());
  1343     mCurrentList->activate(level);
  1381 	mCurrentList->activate(level);
  1344     
  1382 
       
  1383     VideoCollectionViewUtils::sortModel(&mCurrentList->getModel(), false, VideoCollectionCommon::ELevelVideos);
       
  1384     mCurrentList->getModel().invalidate();
       
  1385 
  1345     // update hint widget
  1386     // update hint widget
  1346     setHintLevel(VideoHintWidget::Collection);
  1387     setHintLevel(VideoHintWidget::Collection);
  1347     showHint();
  1388     showHint();
  1348 
  1389 
  1349     // update toolbar for albums, default categories don't have one.
  1390     // update toolbar for albums, default categories don't have one.
  1359 // finishCollectionClosedSlot
  1400 // finishCollectionClosedSlot
  1360 // -------------------------------------------------------------------------------------------------
  1401 // -------------------------------------------------------------------------------------------------
  1361 //
  1402 //
  1362 void VideoListView::finishCollectionClosedSlot(const HbEffect::EffectStatus &status)
  1403 void VideoListView::finishCollectionClosedSlot(const HbEffect::EffectStatus &status)
  1363 {
  1404 {
       
  1405 	FUNC_LOG;
  1364     Q_UNUSED(status);
  1406     Q_UNUSED(status);
  1365     
  1407     
  1366     mTransitionOngoing = false;
  1408     mTransitionOngoing = false;
  1367     
  1409     
  1368     // open collection view
  1410     // open collection view
  1375         mToolbarActions[ETBActionCollections]->setChecked(true);
  1417         mToolbarActions[ETBActionCollections]->setChecked(true);
  1376     }
  1418     }
  1377 }
  1419 }
  1378 
  1420 
  1379 // -------------------------------------------------------------------------------------------------
  1421 // -------------------------------------------------------------------------------------------------
  1380 // widgetReadySlot
  1422 // objectReadySlot
  1381 // -------------------------------------------------------------------------------------------------
  1423 // -------------------------------------------------------------------------------------------------
  1382 //
  1424 //
  1383 void VideoListView::widgetReadySlot(QGraphicsWidget *widget, const QString &name)
  1425 void VideoListView::objectReadySlot(QObject *object, const QString &name)
  1384 {
  1426 {
       
  1427 	FUNC_LOG;
  1385     if (name.compare(DOCML_NAME_VC_VIDEOLISTWIDGET) == 0)
  1428     if (name.compare(DOCML_NAME_VC_VIDEOLISTWIDGET) == 0)
  1386     {
  1429     {
  1387         connect(widget, SIGNAL(command(int)), this, SIGNAL(command(int)));
  1430         connect(object, SIGNAL(command(int)), this, SIGNAL(command(int)));
  1388         connect(this, SIGNAL(doDelayeds()), widget, SLOT(doDelayedsSlot()));
  1431         connect(this, SIGNAL(doDelayeds()), object, SLOT(doDelayedsSlot()));
  1389     }
  1432     }
  1390     else if (name.compare(DOCML_NAME_VC_COLLECTIONWIDGET) == 0)
  1433     else if (name.compare(DOCML_NAME_VC_COLLECTIONWIDGET) == 0)
  1391     {
  1434     {
  1392         connect(
  1435         connect(
  1393             widget, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
  1436             object, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
  1394             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
  1437             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
  1395             connect(this, SIGNAL(doDelayeds()), widget, SLOT(doDelayedsSlot()));
  1438             connect(this, SIGNAL(doDelayeds()), object, SLOT(doDelayedsSlot()));
  1396             emit(doDelayeds());
  1439             emit(doDelayeds());
  1397     }
  1440     }
  1398     else if (name.compare(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) == 0)
  1441     else if (name.compare(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) == 0)
  1399     {
  1442     {
  1400         connect(widget, SIGNAL(command(int)), this, SIGNAL(command(int)));
  1443         connect(object, SIGNAL(command(int)), this, SIGNAL(command(int)));
  1401         connect(
  1444         connect(
  1402             widget, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
  1445             object, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
  1403             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
  1446             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
  1404             connect(this, SIGNAL(doDelayeds()), widget, SLOT(doDelayedsSlot()));
  1447             connect(this, SIGNAL(doDelayeds()), object, SLOT(doDelayedsSlot()));
  1405             emit(doDelayeds());
  1448             emit(doDelayeds());
  1406     }
  1449     }
  1407     else if (name.compare(DOCML_NAME_OPTIONS_MENU) == 0)
  1450     else if (name.compare(DOCML_NAME_OPTIONS_MENU) == 0)
  1408     {
  1451     {
  1409         connect(
  1452         connect(
  1410             widget, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMainMenuSlot()));
  1453             object, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMainMenuSlot()));
  1411     }
  1454     }
  1412     else if (name.compare(DOCML_NAME_HINT_BUTTON) == 0)
  1455     else if (name.compare(DOCML_NAME_HINT_BUTTON) == 0)
  1413     {
  1456     {
  1414         connect(widget, SIGNAL(clicked(bool)), this, SLOT(openServicesViewSlot()));
  1457         connect(object, SIGNAL(clicked(bool)), this, SLOT(openServicesViewSlot()));
  1415     }
  1458     }
  1416 }
  1459     else if (name.compare(DOCML_NAME_SORT_BY_DATE) == 0)
  1417 
       
  1418 // -------------------------------------------------------------------------------------------------
       
  1419 // objectReadySlot
       
  1420 // -------------------------------------------------------------------------------------------------
       
  1421 //
       
  1422 void VideoListView::objectReadySlot(QObject *object, const QString &name)
       
  1423 {
       
  1424 	if (name.compare(DOCML_NAME_SORT_BY_DATE) == 0)
       
  1425     {
  1460     {
  1426         HbAction *action = qobject_cast<HbAction*>(object);
  1461         HbAction *action = qobject_cast<HbAction*>(object);
  1427         if (action)
  1462         if (action)
  1428         {
  1463         {
  1429         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
  1464         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
  1434     {
  1469     {
  1435         HbAction *action = qobject_cast<HbAction*>(object);
  1470         HbAction *action = qobject_cast<HbAction*>(object);
  1436         if (action)
  1471         if (action)
  1437         {
  1472         {
  1438         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
  1473         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
  1439             mSortingRoles[action] = Qt::DisplayRole;
  1474             mSortingRoles[action] = VideoCollectionCommon::KeyTitle;
  1440         }
  1475         }
  1441     }
  1476     }
  1442     else if (name.compare(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS) == 0)
  1477     else if (name.compare(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS) == 0)
  1443     {
  1478     {
  1444         HbAction *action = qobject_cast<HbAction*>(object);
  1479         HbAction *action = qobject_cast<HbAction*>(object);
  1445         if (action)
  1480         if (action)
  1446         {
  1481         {
  1447         	// TODO: implement
  1482             connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
  1448             connect(action, SIGNAL(triggered()), this, SLOT(debugNotImplementedYet()));
  1483             mSortingRoles[action] = VideoCollectionCommon::KeyNumberOfItems;
  1449             mSortingRoles[action] = 0;
       
  1450         }
  1484         }
  1451     }
  1485     }
  1452     else if (name.compare(DOCML_NAME_SORT_BY_SIZE) == 0)
  1486     else if (name.compare(DOCML_NAME_SORT_BY_SIZE) == 0)
  1453     {
  1487     {
  1454         HbAction *action = qobject_cast<HbAction*>(object);
  1488         HbAction *action = qobject_cast<HbAction*>(object);
  1485 }
  1519 }
  1486 
  1520 
  1487 // Just for testing, remove this
  1521 // Just for testing, remove this
  1488 void VideoListView::debugNotImplementedYet()
  1522 void VideoListView::debugNotImplementedYet()
  1489 {
  1523 {
       
  1524 	FUNC_LOG;
  1490     HbMessageBox::information(tr("Not implemented yet"));
  1525     HbMessageBox::information(tr("Not implemented yet"));
  1491 }
  1526 }
  1492 
  1527 
  1493 // end of file
  1528 // end of file
  1494 
  1529