Harmattan font changes completed
[marketstoday] / src / cpp / main.cpp
1 /*
2 @version: 0.5
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 #include "qmaemo5homescreenadaptor.h"
8 #include "marketstodayqmlview.h"
9
10 #include <QtGui>
11 #include <QDeclarativeEngine>
12 #include <QDeclarativeContext>
13 #include <QDebug>
14 //#include <QNetworkConfigurationManager>
15 #include <QDir>
16 #include <QGraphicsObject>
17 #include "logutility.h"
18 #include "connectionutility.h"
19 #include "sharedcontext.h"
20
21 int main(int argc, char *argv[])
22 {
23
24     bool isDesktopWidget = false;
25
26     if (argc > 2 && QString(argv[1]).contains("-plugin-id")) {
27         isDesktopWidget = true;
28     }
29
30     QApplication app(argc, argv);
31
32     //QNetworkConfigurationManager manager;
33     //ConnectionUtility connectionUtility;
34
35     //Signal to check available networks when auto-update is triggered
36     //QObject::connect(&manager,SIGNAL(updateCompleted()),&connectionUtility,SLOT(connectionListUpdated()));
37
38
39     MarketsTodayQMLView qmlView;
40
41     QString strPath;
42
43 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
44     //For maemo fremantle or harmattan use a common path
45     strPath = QDir().homePath() + "/.marketstoday/OfflineStorage";
46     QDir configDir(strPath);
47     qDebug() << "Config path is " << strPath;
48     if (!configDir.exists()){
49         bool created = configDir.mkpath(strPath);
50         if (!created){
51             qDebug() << "Unable to create config directory at " << strPath;
52         }
53     }
54     qmlView.engine()->setOfflineStoragePath(strPath);
55 #else
56     qmlView.engine()->setOfflineStoragePath("qml/OfflineStorage");
57 #endif
58
59     qmlView.setResizeMode(QDeclarativeView::SizeRootObjectToView);    
60     qmlView.setWindowTitle("Markets Today"); 
61
62     LogUtility logUtility;
63     logUtility.logMessage(qmlView.engine()->offlineStoragePath());
64
65     SharedContext *sharedContextObj = new SharedContext(&qmlView);
66     sharedContextObj->setComponentToDisplay("StockQuotesUI");
67     qmlView.rootContext()->setContextProperty("sharedContext",sharedContextObj);
68
69
70     if (isDesktopWidget) {
71         QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor(&qmlView);
72         adaptor->setSettingsAvailable(true); //Use the standard widget settings button for home screen widget
73         QObject::connect(adaptor, SIGNAL(settingsRequested()), &qmlView, SLOT(displayConfigWindow()));        
74
75         qmlView.setFixedSize(400,325);
76         qmlView.setSource(QUrl("qrc:/qml/MarketsTodayWidget.qml"));
77         qmlView.show();
78     }
79     else{
80 #if defined(Q_WS_MAEMO_5)
81         //For Fremantle, use QML without harmattan-components
82         qmlView.setFixedSize(400,325);
83         qmlView.setSource(QUrl("qrc:/qml/MarketsTodayLegacyApp.qml"));
84 #else
85         qmlView.setAttribute(Qt::WA_AutoOrientation,true);
86         qmlView.setSource(QUrl("qrc:/qml/MarketsTodayApp.qml"));
87 #endif
88         qmlView.showFullScreen();
89     }
90
91     QObject *rootObject = qmlView.rootObject();
92     //Singal to display stock quote details full screen
93     QObject::connect(rootObject, SIGNAL(showStockDetails(QString)), &qmlView, SLOT(displayStockDetails(QString)));
94
95     //Signal to reload configuration and update quotes after config window is clicked
96     QObject::connect(&qmlView, SIGNAL(initializeWidget()), rootObject, SLOT(initialize()));
97
98     //QObject::connect(rootObject, SIGNAL(checkNetworkStatus()), &connectionUtility, SLOT(checkConnectionStatus()));
99     //QObject::connect(&connectionUtility, SIGNAL(connectionsAvailable()), rootObject, SLOT(reloadData()));
100     QObject::connect((QObject*)qmlView.engine(), SIGNAL(quit()), &app, SLOT(quit()));
101
102     app.exec();
103 }
104