47
|
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 |
*
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
* The source file of service utils private
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "fmserviceutilsprivate.h"
|
|
20 |
#include "fmserviceutilshandler.h"
|
|
21 |
#include "fmcommon.h"
|
|
22 |
#include <shareui.h>
|
|
23 |
#include <afactivitystorage.h>
|
|
24 |
|
49
|
25 |
// CONSTANTS
|
|
26 |
const int KAppCloseMiniSecTimeout = 1000;
|
|
27 |
|
|
28 |
FmServiceUtilsPrivate::FmServiceUtilsPrivate( QObject *parent ) : QObject( parent ),
|
|
29 |
mShareUi( 0 ), mServiceUtilsHandler( 0 ), mActivityStorage( 0 ),
|
|
30 |
mIsCloseAppsFinished( false ), mIsCloseAppsTimeup( false )
|
47
|
31 |
{
|
49
|
32 |
connect(&mCloseAppTimer, SIGNAL(timeout()), this, SLOT(onCloseAppTimeup()));
|
47
|
33 |
}
|
|
34 |
|
|
35 |
FmServiceUtilsPrivate::~FmServiceUtilsPrivate()
|
|
36 |
{
|
|
37 |
if( mShareUi ) {
|
|
38 |
delete mShareUi;
|
|
39 |
mShareUi = 0;
|
|
40 |
}
|
|
41 |
|
|
42 |
if( mServiceUtilsHandler ) {
|
|
43 |
delete mServiceUtilsHandler;
|
|
44 |
mServiceUtilsHandler = 0;
|
|
45 |
}
|
|
46 |
|
|
47 |
if( mActivityStorage ) {
|
|
48 |
delete mActivityStorage;
|
|
49 |
mActivityStorage = 0;
|
|
50 |
}
|
|
51 |
}
|
|
52 |
|
|
53 |
/*
|
|
54 |
return \a shareUi which is used to send files.
|
|
55 |
*/
|
|
56 |
ShareUi *FmServiceUtilsPrivate::shareUi()
|
|
57 |
{
|
|
58 |
if( !mShareUi ) {
|
|
59 |
mShareUi = new ShareUi;
|
|
60 |
}
|
|
61 |
return mShareUi;
|
|
62 |
}
|
|
63 |
|
|
64 |
/*
|
|
65 |
return \a AfActivityStorage which is used to save activity.
|
|
66 |
*/
|
|
67 |
AfActivityStorage *FmServiceUtilsPrivate::activityStorage()
|
|
68 |
{
|
|
69 |
if( !mActivityStorage ) {
|
|
70 |
mActivityStorage = new AfActivityStorage;
|
|
71 |
}
|
|
72 |
return mActivityStorage;
|
|
73 |
}
|
|
74 |
|
|
75 |
/*
|
|
76 |
return \a CFmServiceUtilsHandler which is used to closeApps and restartApps
|
|
77 |
*/
|
|
78 |
CFmServiceUtilsHandler *FmServiceUtilsPrivate::serviceUtilsHandler()
|
|
79 |
{
|
|
80 |
if( !mServiceUtilsHandler ) {
|
|
81 |
TRAPD(err, mServiceUtilsHandler = CFmServiceUtilsHandler::NewL());
|
49
|
82 |
if( err == KErrNone ) {
|
|
83 |
mServiceUtilsHandler->setObserver( this );
|
|
84 |
} else {
|
47
|
85 |
mServiceUtilsHandler = 0;
|
|
86 |
}
|
|
87 |
}
|
|
88 |
return mServiceUtilsHandler;
|
|
89 |
}
|
|
90 |
|
|
91 |
/*!
|
|
92 |
send files that included in \a filePathList via ShareUi
|
|
93 |
*/
|
|
94 |
void FmServiceUtilsPrivate::sendFile( const QStringList &filePathList )
|
|
95 |
{
|
|
96 |
// send do not accept const QStringList, so use QStringList()<<filePathList
|
|
97 |
shareUi()->send( QStringList()<<filePathList, true );
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
call CBaBackupSessionWrapper to close apps, for example, before formant, apps need be closed
|
|
102 |
this is synchronous which will take a while, please call this function in thread
|
|
103 |
*/
|
|
104 |
void FmServiceUtilsPrivate::closeApps()
|
|
105 |
{
|
|
106 |
CFmServiceUtilsHandler *utilsHandler = serviceUtilsHandler();
|
49
|
107 |
mIsCloseAppsFinished = false;
|
|
108 |
mIsCloseAppsTimeup = false;
|
47
|
109 |
if( utilsHandler ) {
|
|
110 |
TRAP_IGNORE( utilsHandler->CloseAppsL() );
|
|
111 |
}
|
49
|
112 |
|
|
113 |
// Memory card formatting cannot be executed if there are open files on it.
|
|
114 |
// It has been detected, that in some cases memory card using applications
|
|
115 |
// have no time to close file handles before formatting is tried to be executed.
|
|
116 |
// To address this issue, we need to add a delay here after client-notification
|
|
117 |
// about pending format and real formatting procedure.
|
|
118 |
mCloseAppTimer.start( KAppCloseMiniSecTimeout );
|
|
119 |
|
|
120 |
//loop will be closed on both mIsCloseAppsFinished and mIsCloseAppsTimeup turned to true
|
|
121 |
mCloseAppLoop.exec();
|
|
122 |
}
|
|
123 |
|
|
124 |
/*
|
|
125 |
This is observer function inherit from MServiceUtilsObserver
|
|
126 |
So end with L letter no matter if it will leave
|
|
127 |
handle close apps complete, exit loop if mIsCloseAppsTimeup is true
|
|
128 |
*/
|
|
129 |
void FmServiceUtilsPrivate::handleCloseAppCompleteL( TInt err )
|
|
130 |
{
|
|
131 |
Q_UNUSED( err );
|
|
132 |
mIsCloseAppsFinished = true;
|
|
133 |
if( mIsCloseAppsTimeup ) {
|
|
134 |
mCloseAppLoop.exit();
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
/*
|
|
139 |
handle close apps time up. exit loop if mIsCloseAppsFinished is true
|
|
140 |
*/
|
|
141 |
void FmServiceUtilsPrivate::onCloseAppTimeup()
|
|
142 |
{
|
|
143 |
mCloseAppTimer.stop();
|
|
144 |
mIsCloseAppsTimeup = true;
|
|
145 |
if( mIsCloseAppsFinished ) {
|
|
146 |
mCloseAppLoop.exit();
|
|
147 |
}
|
47
|
148 |
}
|
|
149 |
|
|
150 |
/*!
|
|
151 |
call CBaBackupSessionWrapper to restart apps
|
|
152 |
for example, after formant, closed apps need be restarted
|
|
153 |
this is synchronous which will return quickly.
|
|
154 |
*/
|
|
155 |
void FmServiceUtilsPrivate::restartApps()
|
|
156 |
{
|
|
157 |
CFmServiceUtilsHandler *utilsHandler = serviceUtilsHandler();
|
|
158 |
if( utilsHandler ) {
|
|
159 |
TRAP_IGNORE( serviceUtilsHandler()->RestartAppsL() );
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
call AfActivityStorage to save activity
|
|
165 |
*/
|
|
166 |
bool FmServiceUtilsPrivate::saveActivity(const QString &activityId, const QVariant &activityData, const QVariantHash &metadata)
|
|
167 |
{
|
|
168 |
return activityStorage()->saveActivity( activityId, activityData, metadata);
|
|
169 |
}
|
|
170 |
|
|
171 |
/*!
|
|
172 |
call AfActivityStorage to remove activity
|
|
173 |
*/
|
|
174 |
bool FmServiceUtilsPrivate::removeActivity(const QString &activityId)
|
|
175 |
{
|
|
176 |
return activityStorage()->removeActivity( activityId );
|
|
177 |
}
|