launcher/src/launchermainwindow.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 
       
    19 #include <hbapplication.h>
       
    20 #include <hbmainwindow.h>
       
    21 #include <hbdocumentloader.h>
       
    22 
       
    23 #include "enginewrapper.h"
       
    24 #include "commonActions.h"
       
    25 #include "applicationview.h"
       
    26 #include "outputview.h"
       
    27 #include "launchermainwindow.h"
       
    28 
       
    29 // Here we create custom document loader to be able to use custom views in XML.
       
    30 class LauncherDocumentLoader : public HbDocumentLoader
       
    31 {
       
    32 public:
       
    33     virtual QObject *createObject(const QString& type, const QString &name);
       
    34 };
       
    35 
       
    36 QObject *LauncherDocumentLoader::createObject(const QString& type, const QString &name)
       
    37 {
       
    38     // Application view
       
    39     if (type == ApplicationView::staticMetaObject.className()) {
       
    40         QObject *object = new ApplicationView;
       
    41         object->setObjectName(name);
       
    42         return object;
       
    43     }
       
    44     
       
    45     // Output view
       
    46     else if (type == OutputView::staticMetaObject.className()) {
       
    47         QObject *object = new OutputView;
       
    48         object->setObjectName(name);
       
    49         return object;
       
    50     }
       
    51     
       
    52     return HbDocumentLoader::createObject(type, name);
       
    53 }
       
    54 
       
    55 
       
    56 LauncherMainWindow::LauncherMainWindow( QWidget *parent ) : HbMainWindow( parent )
       
    57     ,mEngineWrapper(0)
       
    58     ,mApplicationView(0)
       
    59     ,mOutputView(0)
       
    60     ,mCommonActions(0)
       
    61     {
       
    62     }
       
    63 
       
    64 LauncherMainWindow::~LauncherMainWindow ()
       
    65     {
       
    66     if(mCommonActions)
       
    67         delete mCommonActions;
       
    68     if(mEngineWrapper)
       
    69         delete mEngineWrapper;
       
    70     }
       
    71 
       
    72 int LauncherMainWindow::init( HbApplication &app )
       
    73     {
       
    74     
       
    75     // Create Engine Wrapper and initialize it
       
    76     mEngineWrapper = new EngineWrapper(this);
       
    77     if (!mEngineWrapper->init()) {
       
    78         return EXIT_FAILURE;
       
    79     }
       
    80     
       
    81     // Create common actions class for actions that are used in all views of Launcher        
       
    82     mCommonActions = new CommonActions(mEngineWrapper, &app);
       
    83 
       
    84     // Create document loader
       
    85     LauncherDocumentLoader loader;
       
    86     
       
    87     // Create application view
       
    88     mApplicationView = ApplicationView::create(loader, mCommonActions, mEngineWrapper);
       
    89     // Add view to main window
       
    90     addView(mApplicationView);
       
    91 
       
    92     loader.reset();
       
    93     
       
    94     // Create output view
       
    95     mOutputView = OutputView::create(loader, mCommonActions);
       
    96     // Add view to main window
       
    97     addView(mOutputView);
       
    98     
       
    99     // Show ApplicationView at startup
       
   100     setCurrentView(mApplicationView);
       
   101     
       
   102     // Show HbMainWindow
       
   103     show();
       
   104 
       
   105     return 0;// no errors
       
   106     }
       
   107 
       
   108 void LauncherMainWindow::openApplicationView()
       
   109     {
       
   110     setCurrentView(mApplicationView);
       
   111     }
       
   112 
       
   113 void LauncherMainWindow::openOutputView()
       
   114     {
       
   115     setCurrentView(mOutputView);
       
   116     }
       
   117 
       
   118 void LauncherMainWindow::printText(const QString &text)
       
   119     {
       
   120     mOutputView->printText(text);
       
   121     }