piprofilerui/ui/hb/src/pimainwindow.cpp
changeset 51 b048e15729d6
parent 44 5db69f4c3d06
child 52 36d60d12b4af
equal deleted inserted replaced
44:5db69f4c3d06 51:b048e15729d6
     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 // System include
       
    20 #include <QDebug>
       
    21 #include <hbaction.h>
       
    22 #include <hbdocumentloader.h>
       
    23 #include <hbapplication.h>
       
    24 #include <hbicon.h>
       
    25 #include <hbprogressdialog.h>
       
    26 
       
    27 // User includes
       
    28 #include "pimainwindow.h"
       
    29 //#include "mcsendengine.h"
       
    30 #include "pimainview.h"
       
    31 #include "pisettingsview.h"
       
    32 #include "generalattributes.h"
       
    33 #include "piprofilerengine.h"
       
    34 #include "notifications.h"
       
    35 
       
    36 // xml definition of view
       
    37 const char *PI_MAINVIEW_XML = ":/xml/pimainview.docml";
       
    38 
       
    39 // name of the application view object in the xml file.
       
    40 const char *APPLICATIONVIEW = "PIMainView";
       
    41 
       
    42 // ViewManager Constructor
       
    43 PIMainWindow::PIMainWindow(PIProfilerEngine* engine, HbDocumentLoader &loader, HbApplication *app) :
       
    44     mEngine(engine), mMainView(0), mSettingsView(0), mBackAction(0)
       
    45 {
       
    46 
       
    47     HbProgressDialog *note = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
    48     note->setAttribute(Qt::WA_DeleteOnClose);
       
    49     note->setText("Loading PI Profiler plug-ins...");
       
    50     note->open();
       
    51 
       
    52     // Add the views to the main window
       
    53     addMainView(loader, app);
       
    54     addSettingsView();
       
    55 
       
    56     // Set main view to be displayed on startup
       
    57     activateMainView();
       
    58 
       
    59     connect(mEngine, SIGNAL(pluginListUpdated(QList<PluginAttributes>&)), this,
       
    60         SLOT(setPluginList(QList<PluginAttributes>&)));
       
    61 
       
    62     QMetaObject::connectSlotsByName(this);
       
    63 
       
    64     mEngine->notifyUIReady();
       
    65 
       
    66     note->close();
       
    67 
       
    68 }
       
    69 
       
    70 PIMainWindow::~PIMainWindow()
       
    71 {
       
    72     if (mMainView != 0) {
       
    73         delete mMainView;
       
    74         mMainView = 0;
       
    75     }
       
    76     if (mSettingsView != 0) {
       
    77         delete mSettingsView;
       
    78         mSettingsView = 0;
       
    79     }
       
    80 
       
    81 }
       
    82 
       
    83 // Methods to add views to the main window
       
    84 
       
    85 void PIMainWindow::addMainView(HbDocumentLoader &loader, HbApplication *app)
       
    86 {
       
    87     // Load xml-file
       
    88     bool ok = false;
       
    89     loader.load(PI_MAINVIEW_XML, &ok);
       
    90 
       
    91     // Load Application View:
       
    92     QGraphicsWidget *widget = loader.findWidget(APPLICATIONVIEW);
       
    93     Q_ASSERT_X(ok && (widget != 0), "PIProfiler", "Invalid docml file");
       
    94     mMainView = qobject_cast<PIMainView *> (widget);
       
    95 
       
    96     mMainView->init(this, app, loader, mEngine);
       
    97 
       
    98     // Add view to main window
       
    99     this->addView(mMainView);
       
   100 
       
   101 }
       
   102 
       
   103 void PIMainWindow::addSettingsView()
       
   104 {
       
   105     mSettingsView = new PISettingsView(mEngine);
       
   106     mBackAction = new HbAction("back", this);
       
   107 
       
   108     bool value = connect(mBackAction, SIGNAL(triggered()), this, SLOT(settingsViewClosed()));
       
   109     mSettingsView->setNavigationAction(mBackAction);
       
   110     mSettingsView->navigationAction()->setIcon(HbIcon(":/gfx/enabled.svg"));
       
   111     addView(mSettingsView);
       
   112 }
       
   113 
       
   114 // Slots to handle view change
       
   115 void PIMainWindow::activateMainView()
       
   116 {
       
   117     setCurrentView(mMainView);
       
   118 }
       
   119 
       
   120 void PIMainWindow::activateSettingsView(int uid)
       
   121 {
       
   122     if (uid != 0) {
       
   123         mSettingsView->expandPluginGroup(uid);
       
   124     }
       
   125     setCurrentView(mSettingsView);
       
   126 }
       
   127 
       
   128 void PIMainWindow::settingsViewClosed()
       
   129 {
       
   130     if (currentView() == mSettingsView) {
       
   131         bool error = false;
       
   132         if (!mEngine->saveGeneralSettings(mSettingsView->getGeneralAttributes())) {
       
   133             error = true;
       
   134         }
       
   135 
       
   136         mSettingsView->readPluginSettings();
       
   137 
       
   138         for (int index = 0; index < mPluginAttributes.size(); index++) {
       
   139             if (!mEngine->savePluginSettings(mPluginAttributes.at(index))) {
       
   140                 error = true;
       
   141             }
       
   142         }
       
   143 
       
   144         if (error) {
       
   145             Notifications::showErrorNote("Unable to save some of the settings into engine");
       
   146         }
       
   147         activateMainView();
       
   148         emit returnedFromSettings();
       
   149     }
       
   150     else {
       
   151         qWarning("Back action is not triggered at the correct view!");
       
   152     }
       
   153 }
       
   154 
       
   155 void PIMainWindow::setPluginList(QList<PluginAttributes> &pluginList)
       
   156 {
       
   157     mPluginAttributes = pluginList;
       
   158     mMainView->setPluginList(&mPluginAttributes);
       
   159     mSettingsView->setPluginSettings(&mPluginAttributes);
       
   160 }