|
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 * Description: Main. |
|
15 * |
|
16 */ |
|
17 #include <QTranslator> |
|
18 #include <QMessageBox> |
|
19 #include <hbapplication.h> |
|
20 #include <hbmainwindow.h> |
|
21 #include "hshomescreen.h" |
|
22 #include "hsapptranslator.h" |
|
23 #include "hstest_global.h" |
|
24 |
|
25 namespace |
|
26 { |
|
27 const char TR_FILE_PATH[] = "resource/qt/translations"; |
|
28 } |
|
29 |
|
30 #ifdef Q_OS_SYMBIAN |
|
31 |
|
32 #include <QFile> |
|
33 #include <QDir> |
|
34 #include <f32file.h> |
|
35 #include <eikenv.h> |
|
36 #include <e32debug.h> |
|
37 #include <apgwgnam.h> |
|
38 |
|
39 // it is temporary class used for getting notifcation about APA messages |
|
40 // it is used for processing message send by AVKON to activate Menu |
|
41 class HsMessageObserver: public MCoeMessageObserver { |
|
42 |
|
43 TMessageResponse HandleMessageL(TUint32 /*aClientHandleOfTargetWindowGroup*/, |
|
44 TUid /*aMessageUid*/, |
|
45 const TDesC8& /*aMessageParameters*/) |
|
46 { |
|
47 // move application to foreground |
|
48 QApplication::topLevelAt(0,0)->raise(); |
|
49 return EMessageHandled; |
|
50 } |
|
51 }; |
|
52 |
|
53 void setHomescreenAsSystemAppL(CEikonEnv* eikonEnv) |
|
54 { |
|
55 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(eikonEnv->WsSession()); |
|
56 wgName->SetSystem(ETrue); // Allow only application with PowerManagement cap to shut us down |
|
57 wgName->SetCaptionL(_L("HsApplication")); |
|
58 wgName->SetAppUid(TUid::Uid(0x20022F35)); |
|
59 wgName->SetWindowGroupName(eikonEnv->RootWin()); |
|
60 CleanupStack::PopAndDestroy(); |
|
61 } |
|
62 |
|
63 |
|
64 |
|
65 void myMessageOutput(QtMsgType type, const char *msg) |
|
66 { |
|
67 switch (type) { |
|
68 |
|
69 case QtDebugMsg: |
|
70 RDebug::Printf("[HS] Debug: %s\n", msg); |
|
71 break; |
|
72 |
|
73 case QtWarningMsg: |
|
74 RDebug::Printf("[HS] Warning: %s\n", msg); |
|
75 break; |
|
76 |
|
77 case QtCriticalMsg: |
|
78 RDebug::Printf("[HS] Critical: %s\n", msg); |
|
79 break; |
|
80 |
|
81 case QtFatalMsg: |
|
82 RDebug::Printf("[HS] Fatal: %s\n", msg); |
|
83 abort(); |
|
84 } |
|
85 } |
|
86 |
|
87 #endif //Q_OS_SYMBIAN |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 int main(int argc, char *argv[]) |
|
96 { |
|
97 #ifdef Q_OS_SYMBIAN |
|
98 qInstallMsgHandler(myMessageOutput); |
|
99 #endif |
|
100 |
|
101 HSTEST_FUNC_ENTRY("HS::main()"); |
|
102 |
|
103 HbApplication app(argc, argv); |
|
104 |
|
105 #ifdef Q_OS_SYMBIAN |
|
106 QString currentPath = QString(argv[0]).left(2); |
|
107 QDir::setCurrent(currentPath); |
|
108 QString debugMsg = "HS::main() - HsApplication's current dir set to: " + currentPath; |
|
109 HSDEBUG(debugMsg); |
|
110 #endif //Q_OS_SYMBIAN |
|
111 |
|
112 HsAppTranslator *appTranslator = HsAppTranslator::instance(); |
|
113 appTranslator->setLanguage(); |
|
114 |
|
115 // add translator for homescreen and application library |
|
116 QString locale = QLocale::system().name(); |
|
117 |
|
118 QTranslator hsTranslator; |
|
119 QString hsTrFile = QString("homescreen_") + locale; |
|
120 |
|
121 QTranslator alTranslator; |
|
122 QString alTrFile = QString("hsapplibrary_") + locale; |
|
123 #ifdef Q_OS_SYMBIAN |
|
124 // TRAP is must here, otherwise it crashes |
|
125 TRAP_IGNORE( |
|
126 bool hsLoaded(false); |
|
127 hsLoaded = hsTranslator.load(hsTrFile, QString("z:/") + TR_FILE_PATH); |
|
128 if (!hsLoaded) |
|
129 hsTranslator.load(hsTrFile, QString("c:/") + TR_FILE_PATH); |
|
130 |
|
131 bool alLoaded(false); |
|
132 alLoaded = alTranslator.load(alTrFile, QString("z:/") + TR_FILE_PATH); |
|
133 if (!alLoaded) |
|
134 alTranslator.load(alTrFile, QString("c:/") + TR_FILE_PATH); |
|
135 ); |
|
136 #else |
|
137 hsTranslator.load(hsTrFile, QString(TR_FILE_PATH) ); |
|
138 alTranslator.load(alTrFile, QString(TR_FILE_PATH) ); |
|
139 #endif //Q_OS_SYMBIAN |
|
140 app.installTranslator(&hsTranslator); |
|
141 app.installTranslator(&alTranslator); |
|
142 |
|
143 #ifdef Q_OS_SYMBIAN |
|
144 QFile file("c:/private/20022f35/homescreendb"); |
|
145 //If DB file does not exist copy default DB from z: (ROM) |
|
146 if(!file.exists()) { |
|
147 HSTEST("HS::main() - homescreendb not in c:"); |
|
148 file.setFileName("z:/private/20022f35/homescreendb"); |
|
149 if(!file.exists()) { |
|
150 HSTEST("HS::main() - homescreendb not in ROM!"); |
|
151 } |
|
152 else { |
|
153 HSTEST("HS::main() - homescreendb found from z:"); |
|
154 //We need to first create private folder if not exists |
|
155 QDir dir("c:/private/20022f35/"); |
|
156 if(!dir.exists()) { |
|
157 HSTEST("HS::main() - c:/private/20022f35/ does not exist."); |
|
158 RFs fsSession; |
|
159 if(fsSession.Connect() != KErrNone){ |
|
160 HSTEST("HS::main() - Homescreen private dir creation failed!"); |
|
161 } |
|
162 fsSession.CreatePrivatePath(EDriveC); |
|
163 HSTEST("HS::main() - c:/private/20022f35/ created."); |
|
164 fsSession.Close(); |
|
165 if(!dir.exists()) { |
|
166 HSTEST("HS::main() - c:/private/20022f35/ creation failed."); |
|
167 } |
|
168 } |
|
169 HSTEST("HS::main() - c:/private/20022f35/ exists."); |
|
170 //Copy DB from z: to c: |
|
171 if (!file.copy("c:/private/20022f35/homescreendb")) { |
|
172 HSTEST("HS::main() - homescreendb copy from ROM to c: failed!"); |
|
173 } |
|
174 HSTEST("HS::main() - homescreendb copied from ROM to c:!"); |
|
175 file.setFileName("c:/private/20022f35/homescreendb"); |
|
176 if(!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) { |
|
177 HSTEST("HS::main() - homescreendb ReadWrite permission settings on c: failed!"); |
|
178 } |
|
179 HSTEST("HS::main() - homescreendb permission set to ReadWrite!"); |
|
180 } |
|
181 } |
|
182 #ifdef __WINS__ |
|
183 else if(!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) { |
|
184 HSTEST("HS::main() - homescreendb ReadWrite permission settings on emulator's c: failed!"); |
|
185 } |
|
186 #endif |
|
187 { |
|
188 QDir dir("c:/private/20022f35/wallpapers"); |
|
189 if(!dir.exists()) { |
|
190 dir.mkpath("c:/private/20022f35/wallpapers/"); |
|
191 QDir dir2("z:/private/20022f35/wallpapers"); |
|
192 dir2.setFilter(QDir::Files); |
|
193 QStringList files = dir2.entryList(); |
|
194 foreach(QString file, files) |
|
195 { |
|
196 QString targetFile("c:/private/20022f35/wallpapers/" + file); |
|
197 QFile::copy(dir2.absoluteFilePath(file), targetFile); |
|
198 qDebug() << "image copied" << dir2.absoluteFilePath(file); |
|
199 QFile createdFile(targetFile); |
|
200 if(!createdFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) { |
|
201 qDebug() << "read write permission set failed for file" << targetFile; |
|
202 } |
|
203 } |
|
204 |
|
205 } |
|
206 |
|
207 |
|
208 } |
|
209 |
|
210 #endif //Q_OS_SYMBIAN |
|
211 |
|
212 HbMainWindow window; |
|
213 window.setViewSwitchingEnabled(false); |
|
214 |
|
215 HsHomeScreen hs; |
|
216 QObject::connect(&app, SIGNAL(aboutToQuit()) ,&hs, SLOT(stop())); |
|
217 QObject::connect(&hs, SIGNAL(exit()), &app, SLOT(quit()),Qt::QueuedConnection); |
|
218 hs.start(); |
|
219 |
|
220 app.installEventFilter(appTranslator); |
|
221 |
|
222 #ifdef Q_OS_SYMBIAN |
|
223 CEikonEnv * env = CEikonEnv::Static(); |
|
224 #ifdef S60APP_KEY |
|
225 env->RootWin().CaptureKeyUpAndDowns( EStdKeyApplication0, 0, 0 ); |
|
226 #endif //S60APP_KEY |
|
227 TRAP_IGNORE(setHomescreenAsSystemAppL(env)); |
|
228 HsMessageObserver observer; |
|
229 TRAP_IGNORE( env->AddMessageObserverL(observer)); |
|
230 #endif //Q_OS_SYMBIAN |
|
231 |
|
232 HSTEST("HS::main() call app.exec"); |
|
233 try { |
|
234 app.exec(); |
|
235 |
|
236 } catch(...) { |
|
237 HSTEST("HS::main() app.exec() catch"); |
|
238 } |
|
239 return 0; |
|
240 } |
|
241 |
|
242 |