launcher/src/applicationview.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbdocumentloader.h>
       
    19 #include <hblistwidget.h>
       
    20 #include <qstandarditemmodel.h>
       
    21 #include <hbaction.h>
       
    22 #include <hbmenu.h>
       
    23 #include <qlist.h>
       
    24 
       
    25 #include "applicationview.h"
       
    26 #include "launchermainwindow.h"
       
    27 #include "enginewrapper.h"
       
    28 #include "notifications.h"
       
    29 #include "commonActions.h"
       
    30 #include "outputview.h"
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 // xml definition of view
       
    36 const char *APPLICATIONVIEW_XML = ":/xml/applicationview.xml";
       
    37 
       
    38 // name of the application view object in the xml file.
       
    39 const char *APPLICATIONVIEW = "applicationview";
       
    40 const char *LISTVIEW = "applicationList";
       
    41 const char *ACTIONREFRESH = "actionRefresh";
       
    42 const char *ACTIONLAUNCHAPPS = "actionLaunchApps";
       
    43 const char *ACTIONLAUNCHANDCLOSEAPPS = "actionLaunchAppsAndClose";
       
    44 const char *ACTIONSELECT = "actionSelectAll";
       
    45 const char *ACTIONUNSELECT = "actionUnselectAll";
       
    46 const char *ACTIONOPENOUTPUTVIEW = "actionOpenOutputView";
       
    47 const char *ACTIONSKIPHIDDEN = "actionSkipHidden";
       
    48 const char *ACTIONDONTSKIPHIDDEN = "actionDontSkipHidden";
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 
       
    52 ApplicationView* ApplicationView::create(HbDocumentLoader &loader, CommonActions *commonActions, EngineWrapper *engine)
       
    53 {
       
    54     
       
    55     // Load xml-file
       
    56     bool ok = false;
       
    57     qDebug("QTLauncher::load xml");
       
    58     loader.load(APPLICATIONVIEW_XML, &ok);
       
    59     
       
    60     // Load Application View:
       
    61     QGraphicsWidget *widget = loader.findWidget(APPLICATIONVIEW);
       
    62     Q_ASSERT_X(ok && (widget != 0), "Launcher", "Invalid launcher.xml file");
       
    63     ApplicationView *applicationView = qobject_cast<ApplicationView *>(widget);
       
    64       
       
    65     // Set enginewrappers pointer to applicationview and initialize it
       
    66     applicationView->setEngine(engine);
       
    67     applicationView->init(loader, commonActions);
       
    68     
       
    69     return applicationView;    
       
    70 }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 
       
    74 ApplicationView::ApplicationView()  
       
    75     :   mEngine(0),
       
    76         mActionRefresh(0),
       
    77         mActionLaunchApps(0),
       
    78         mActionLaunchAndCloseApps(0),
       
    79         mActionSkipHidden(0),
       
    80         mActionDontSkipHidden(0),
       
    81         mActionSelectAll(0),
       
    82         mActionUnselectAll(0),
       
    83         mActionOpenOutputView(0)
       
    84 {
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 
       
    89 void ApplicationView::setEngine(EngineWrapper *engine)
       
    90 {
       
    91     mEngine = engine;
       
    92 }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 
       
    96 ApplicationView::~ApplicationView()
       
    97 {
       
    98     if(mActionRefresh)
       
    99         mActionRefresh->deleteLater();
       
   100     if(mActionLaunchApps)
       
   101         mActionLaunchApps->deleteLater();
       
   102     if(mActionLaunchAndCloseApps)
       
   103         mActionLaunchAndCloseApps->deleteLater();
       
   104     if(mActionSkipHidden)
       
   105         mActionSkipHidden->deleteLater();
       
   106     if(mActionDontSkipHidden)
       
   107         mActionDontSkipHidden->deleteLater();
       
   108     if(mActionSelectAll)
       
   109         mActionSelectAll->deleteLater();
       
   110     if(mActionUnselectAll)
       
   111         mActionUnselectAll->deleteLater();
       
   112     if(mActionOpenOutputView)
       
   113         mActionOpenOutputView->deleteLater();
       
   114 }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 
       
   118 void ApplicationView::init(HbDocumentLoader &loader, CommonActions *commonActions)
       
   119 {
       
   120     // Load items from xml file
       
   121     loadItemsFromXml(loader);
       
   122     
       
   123     // Set actions checkable and select "Skip hidden & embed"
       
   124     mActionSkipHidden->setCheckable(true);
       
   125     mActionSkipHidden->setChecked(true);
       
   126     mActionDontSkipHidden->setCheckable(true);
       
   127     
       
   128     commonActions->addActionsToMenu(menu());
       
   129     
       
   130     // Set list widget settings
       
   131     mApplicationList->setClampingStyle(HbScrollArea::BounceBackClamping);
       
   132     mApplicationList->setSelectionMode(HbAbstractItemView::MultiSelection);
       
   133     
       
   134     // Refresh application list
       
   135     refreshAppList();
       
   136     
       
   137     // Connect signals and slots
       
   138     connectSignalsAndSlots();
       
   139    
       
   140 }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 
       
   144 void ApplicationView::refreshAppList()
       
   145 {
       
   146     // Clear list
       
   147 
       
   148     mApplicationList->clear();
       
   149     QStringList apps;
       
   150 
       
   151     // show wait dialog
       
   152     QObject *dialog =  static_cast<QObject*>(Notifications::showWaitDialog("Initializing"));
       
   153 
       
   154     // Get application list from engine
       
   155     if(!mEngine->listOfAllApps(apps)) {
       
   156         Notifications::showErrorNote("Unable to refresh list");
       
   157     }
       
   158     
       
   159     // Format values to list widget
       
   160     int i = 0;
       
   161     while(i < apps.size()) {
       
   162         mApplicationList->addItem(/*HbIcon(":/gfx/check.svg"),*/apps.at(i));
       
   163         i++;
       
   164     }
       
   165     mApplicationList->selectAll();
       
   166     
       
   167     // remove the wait dialog
       
   168     delete dialog;
       
   169 }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 
       
   173 void ApplicationView::connectSignalsAndSlots()
       
   174 {
       
   175     // Actions
       
   176     connect(mActionRefresh, SIGNAL(triggered()), this, SLOT(refreshAppList()));
       
   177     connect(mActionLaunchApps, SIGNAL(triggered()), this, SLOT(launchSelectedApplications()));
       
   178     connect(mActionLaunchAndCloseApps, SIGNAL(triggered()), this, SLOT(launchAndCloseSelectedApplications()));
       
   179     connect(mActionSelectAll, SIGNAL(triggered()), this, SLOT(selectAllItems()));
       
   180     connect(mActionUnselectAll, SIGNAL(triggered()), this, SLOT(unselectAllItems()));
       
   181     connect(mActionSkipHidden, SIGNAL(triggered()), this, SLOT(launchOptionsSkipHidden()));
       
   182     connect(mActionDontSkipHidden, SIGNAL(triggered()), this, SLOT(launchOptionsDontSkipHidden()));
       
   183     connect(mActionOpenOutputView, SIGNAL(triggered()), this, SLOT(openOutputView()));
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 
       
   188 
       
   189 void ApplicationView::loadItemsFromXml(HbDocumentLoader &loader)
       
   190 {
       
   191     
       
   192     // List widget:
       
   193     QGraphicsWidget *widget = loader.findWidget(LISTVIEW);
       
   194     Q_ASSERT_X((widget != 0), "Launcher", "Invalid launcher.xml file");
       
   195     mApplicationList = qobject_cast<HbListWidget *>(widget);
       
   196     
       
   197     /* ACTIONS: */
       
   198     //refresh
       
   199     QObject *object= loader.findObject(ACTIONREFRESH);
       
   200     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   201     mActionRefresh = qobject_cast<HbAction *>(object);
       
   202     
       
   203     // launch applications
       
   204     object= loader.findObject(ACTIONLAUNCHAPPS);
       
   205     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   206     mActionLaunchApps = qobject_cast<HbAction *>(object);
       
   207 
       
   208     // launch and close
       
   209     object= loader.findObject(ACTIONLAUNCHANDCLOSEAPPS);
       
   210     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   211     mActionLaunchAndCloseApps = qobject_cast<HbAction *>(object);
       
   212     
       
   213     // select all applications
       
   214     object= loader.findObject(ACTIONSELECT);
       
   215     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   216     mActionSelectAll = qobject_cast<HbAction *>(object);
       
   217     
       
   218     // unselect all applications
       
   219     object= loader.findObject(ACTIONUNSELECT);
       
   220     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   221     mActionUnselectAll = qobject_cast<HbAction *>(object);
       
   222     
       
   223     // open output view
       
   224     object= loader.findObject(ACTIONOPENOUTPUTVIEW);
       
   225     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   226     mActionOpenOutputView = qobject_cast<HbAction *>(object);
       
   227     
       
   228     // skip hidden
       
   229     object= loader.findObject(ACTIONSKIPHIDDEN);
       
   230     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   231     mActionSkipHidden = qobject_cast<HbAction *>(object);
       
   232     
       
   233     // do not skip hidden
       
   234     object= loader.findObject(ACTIONDONTSKIPHIDDEN);
       
   235     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
   236     mActionDontSkipHidden = qobject_cast<HbAction *>(object);
       
   237     
       
   238 }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 
       
   242 void ApplicationView::launchSelectedApplications()
       
   243 {
       
   244     QModelIndexList list = mApplicationList->selectionModel()->selectedIndexes();
       
   245     mEngine->startAppLaunching(list, false);
       
   246 }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 
       
   250 void ApplicationView::launchAndCloseSelectedApplications()
       
   251 {
       
   252     QModelIndexList list = mApplicationList->selectionModel()->selectedIndexes();
       
   253     mEngine->startAppLaunching(list, true);
       
   254 }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 
       
   258 void ApplicationView::selectAllItems()
       
   259 {
       
   260     mApplicationList->selectAll();
       
   261 }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 
       
   265 void ApplicationView::unselectAllItems()
       
   266 {
       
   267     mApplicationList->clearSelection();
       
   268 }
       
   269 // ---------------------------------------------------------------------------
       
   270 
       
   271 void ApplicationView::launchOptionsSkipHidden()
       
   272 {
       
   273     mActionSkipHidden->setChecked(true);
       
   274     mActionDontSkipHidden->setChecked(false);
       
   275     mEngine->setSkipHiddenAndEmbedOnly(true);
       
   276 }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 
       
   280 void ApplicationView::launchOptionsDontSkipHidden()
       
   281 {
       
   282     mActionSkipHidden->setChecked(false);
       
   283     mActionDontSkipHidden->setChecked(true);
       
   284     mEngine->setSkipHiddenAndEmbedOnly(false);
       
   285 }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 
       
   289 void ApplicationView::openOutputView()
       
   290 {
       
   291     qDebug("OpenOutputView");
       
   292     LauncherMainWindow *pMainWindow = static_cast< LauncherMainWindow * >( mainWindow() );
       
   293     if( pMainWindow )
       
   294         {
       
   295         pMainWindow->openOutputView();
       
   296         }
       
   297 }
       
   298 
       
   299 // ---------------------------------------------------------------------------