|
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() for messaging application. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbapplication.h> |
|
19 #include <QTranslator> |
|
20 #include <QLocale> |
|
21 #include <QFile> |
|
22 #include "debugtraces.h" |
|
23 #include <QDateTime> |
|
24 #include <QPointer> |
|
25 #include <HbSplashScreen> |
|
26 |
|
27 #include "msgmainwindow.h" |
|
28 #include "msgactivityhandler.h" |
|
29 |
|
30 //Localised constants |
|
31 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
|
32 |
|
33 const QString debugFileName("c:/art2_app_log.txt"); |
|
34 const QString activityParam("-activity"); |
|
35 const int INVALID_MSGID = -1; |
|
36 |
|
37 #ifdef _DEBUG_TRACES_ |
|
38 void debugInit(QtMsgType type, const char *msg) |
|
39 { |
|
40 |
|
41 QFile ofile(debugFileName); |
|
42 if (!ofile.open(QIODevice::Append | QIODevice::Text)) |
|
43 { |
|
44 qFatal("error opening results file"); |
|
45 return; |
|
46 } |
|
47 QDateTime dt = QDateTime::currentDateTime(); |
|
48 |
|
49 QTextStream out(&ofile); |
|
50 switch (type) |
|
51 { |
|
52 case QtDebugMsg: |
|
53 out << " DEBUG:"; |
|
54 out << msg; |
|
55 break; |
|
56 case QtWarningMsg: |
|
57 out << " WARN:"; |
|
58 out << msg; |
|
59 break; |
|
60 case QtCriticalMsg: |
|
61 out << "\n "; |
|
62 out << dt.toString("dd/MM/yyyy hh:mm:ss.zzz:ap"); |
|
63 out << " CRITICAL:"; |
|
64 out << msg; |
|
65 break; |
|
66 case QtFatalMsg: |
|
67 out << " FATAL:"; |
|
68 out << msg; |
|
69 abort(); |
|
70 break; |
|
71 default: |
|
72 out << " No Log Selection Type:"; |
|
73 out << msg; |
|
74 break; |
|
75 |
|
76 } |
|
77 } |
|
78 |
|
79 #endif |
|
80 int main(int argc, char *argv[]) |
|
81 { |
|
82 |
|
83 QCRITICAL_WRITE("MsgApp start."); |
|
84 |
|
85 QString firstArg(argv[1]); |
|
86 bool serviceRequest = false; |
|
87 // check for argc is greater than 1 and its not from activity |
|
88 if(argc >1 && firstArg != activityParam ) |
|
89 { |
|
90 serviceRequest = true; |
|
91 HbSplashScreen::setScreenId("dummy"); |
|
92 } |
|
93 else |
|
94 { |
|
95 HbSplashScreen::setScreenId("clv"); |
|
96 } |
|
97 |
|
98 // Application |
|
99 HbApplication app(argc, argv); |
|
100 |
|
101 //TODO: Uncomment the lines when actual translation files are available in sdk and remove loading locally. |
|
102 QString locale = QLocale::system().name(); |
|
103 QString path = "z:/resource/qt/translations/"; |
|
104 QTranslator translator; |
|
105 QTranslator translator_comm; |
|
106 translator.load(path + QString("messaging_") + locale); |
|
107 translator_comm.load(path + QString("common_") + locale); |
|
108 app.installTranslator(&translator); |
|
109 app.installTranslator(&translator_comm); |
|
110 |
|
111 app.setApplicationName(LOC_TITLE); |
|
112 |
|
113 #ifdef _DEBUG_TRACES_ |
|
114 //Debug Logs |
|
115 QFile ofile; |
|
116 if (ofile.exists(debugFileName)) |
|
117 { |
|
118 ofile.remove(debugFileName); |
|
119 } |
|
120 qInstallMsgHandler(debugInit); |
|
121 #endif |
|
122 |
|
123 |
|
124 |
|
125 MsgActivityHandler* activityHandler = new MsgActivityHandler(&app); |
|
126 // connect to aboutToQuit signal to save activity |
|
127 QObject::connect(&app, SIGNAL(aboutToQuit()), |
|
128 activityHandler, SLOT(saveActivity())); |
|
129 |
|
130 int activityMsgId = INVALID_MSGID; |
|
131 if(app.activateReason() == Hb::ActivationReasonActivity) { |
|
132 // restoring an activity, not a fresh startup or a service |
|
133 QVariant data = app.activateData(); |
|
134 activityMsgId = activityHandler->parseActivityData(data); |
|
135 // set service request to false , since its a activity launch |
|
136 serviceRequest = false; |
|
137 } |
|
138 // clear the old activities |
|
139 activityHandler->clearActivities(); |
|
140 |
|
141 // Main window |
|
142 QPointer<MsgMainWindow> mainWindow = new MsgMainWindow(serviceRequest,activityMsgId); |
|
143 // Set the main window pointer to activity handler. |
|
144 activityHandler->setMainWindow(mainWindow); |
|
145 mainWindow->show(); |
|
146 |
|
147 // Event loop |
|
148 int error = app.exec(); |
|
149 HbApplication::processEvents(); |
|
150 |
|
151 // delete main window and return error |
|
152 delete mainWindow; |
|
153 |
|
154 return error; |
|
155 } |
|
156 |
|
157 // End of file |