31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 |
*
|
55
|
14 |
* Description: This class adds a setting view to main window, and restore previous view when back key clicked.
|
31
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cpviewlauncher.h"
|
|
19 |
#include <hbinstance.h>
|
|
20 |
#include <hbview.h>
|
|
21 |
#include <hbmainwindow.h>
|
36
|
22 |
#include <QCoreApplication>
|
31
|
23 |
|
|
24 |
static HbMainWindow *mainWindow()
|
|
25 |
{
|
|
26 |
QList< HbMainWindow* > mainWindows = hbInstance->allMainWindows();
|
|
27 |
if (!mainWindows.isEmpty()) {
|
|
28 |
return mainWindows.front();
|
|
29 |
}
|
|
30 |
return 0;
|
|
31 |
}
|
|
32 |
|
|
33 |
void CpViewLauncher::launchView(HbView *view)
|
|
34 |
{
|
|
35 |
if (view) {
|
|
36 |
CpViewLauncher *launcher = new CpViewLauncher();
|
|
37 |
launcher->internalLaunchView(view);
|
|
38 |
}
|
|
39 |
}
|
|
40 |
|
|
41 |
CpViewLauncher::CpViewLauncher() :
|
|
42 |
mView(0),
|
|
43 |
mPreView(0)
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
CpViewLauncher::~CpViewLauncher()
|
|
48 |
{
|
|
49 |
}
|
|
50 |
|
|
51 |
void CpViewLauncher::internalLaunchView(HbView *view)
|
|
52 |
{
|
|
53 |
//Q_ASSERT(view); should not use
|
|
54 |
|
|
55 |
HbMainWindow *mainWnd = ::mainWindow();
|
|
56 |
|
|
57 |
if (mainWnd && view)
|
|
58 |
{
|
|
59 |
mView = view;
|
|
60 |
|
|
61 |
mPreView = mainWnd->currentView();
|
36
|
62 |
|
|
63 |
if (mPreView) {
|
|
64 |
QObject::connect(mView, SIGNAL(aboutToClose()), this, SLOT(viewDone()));
|
|
65 |
}
|
|
66 |
else {
|
|
67 |
QObject::connect(mView, SIGNAL(aboutToClose()), qApp, SLOT(quit()));
|
|
68 |
}
|
|
69 |
|
31
|
70 |
|
|
71 |
// activates the plugin view
|
|
72 |
mainWnd->addView(mView);
|
|
73 |
mainWnd->setCurrentView(mView);
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
void CpViewLauncher::viewDone()
|
37
|
78 |
{
|
31
|
79 |
HbMainWindow *mainWnd = ::mainWindow();
|
|
80 |
|
37
|
81 |
if (mainWnd) {
|
|
82 |
if (mView) {
|
|
83 |
//restore previous status
|
|
84 |
mainWnd->removeView(mView);
|
|
85 |
|
|
86 |
mView->deleteLater();
|
|
87 |
mView = 0;
|
|
88 |
|
|
89 |
mainWnd->setCurrentView(mPreView);
|
|
90 |
}
|
31
|
91 |
}
|
|
92 |
|
|
93 |
deleteLater();
|
|
94 |
}
|
37
|
95 |
|
|
96 |
//End of File
|