Release 0.3-1 (Including all changes)
[marketstoday] / src / cpp / main.cpp
1 /*
2 @version: 0.2
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 <QGraphicsObject>
16 #include "logutility.h"
17 #include "connectionutility.h"
18 #include "sharedcontext.h"
19
20 int main(int argc, char *argv[])
21 {
22
23     bool isDesktopWidget = false;
24
25     if (argc > 2 && QString(argv[1]).contains("-plugin-id")) {
26         isDesktopWidget = true;
27     }
28
29     QApplication app(argc, argv);
30
31     //QNetworkConfigurationManager manager;
32     //ConnectionUtility connectionUtility;
33
34     //Signal to check available networks when auto-update is triggered
35     //QObject::connect(&manager,SIGNAL(updateCompleted()),&connectionUtility,SLOT(connectionListUpdated()));
36
37
38     MarketsTodayQMLView qmlView;
39
40 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
41     //For maemo fremantle or harmattan use a common path
42     qmlView.engine()->setOfflineStoragePath("/home/user/.marketstoday/OfflineStorage");
43 #else
44     qmlView.engine()->setOfflineStoragePath("qml/OfflineStorage");
45 #endif
46     qmlView.setResizeMode(QDeclarativeView::SizeRootObjectToView);    
47     qmlView.setWindowTitle("Markets Today");
48     qmlView.setFixedSize(400,325);    
49
50     LogUtility logUtility;
51     logUtility.logMessage(qmlView.engine()->offlineStoragePath());
52
53     SharedContext *sharedContextObj = new SharedContext(&qmlView);
54     sharedContextObj->setComponentToDisplay("StockQuotesUI");
55     qmlView.rootContext()->setContextProperty("sharedContext",sharedContextObj);
56
57
58     if (isDesktopWidget) {
59         QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor(&qmlView);
60         adaptor->setSettingsAvailable(true); //Use the standard widget settings button for home screen widget
61         QObject::connect(adaptor, SIGNAL(settingsRequested()), &qmlView, SLOT(displayConfigWindow()));        
62
63         qmlView.setSource(QUrl("qrc:/qml/MarketsTodayWidget.qml"));
64         qmlView.show();
65     }
66     else{
67         qmlView.setSource(QUrl("qrc:/qml/MarketsTodayApp.qml"));
68         qmlView.showFullScreen();
69     }
70
71     QObject *rootObject = qmlView.rootObject();
72     //Singal to display stock quote details full screen
73     QObject::connect(rootObject, SIGNAL(showStockDetails(QString)), &qmlView, SLOT(displayStockDetails(QString)));
74
75     //Signal to reload configuration and update quotes after config window is clicked
76     QObject::connect(&qmlView, SIGNAL(initializeWidget()), rootObject, SLOT(initialize()));
77
78     //QObject::connect(rootObject, SIGNAL(checkNetworkStatus()), &connectionUtility, SLOT(checkConnectionStatus()));
79     //QObject::connect(&connectionUtility, SIGNAL(connectionsAvailable()), rootObject, SLOT(reloadData()));
80     QObject::connect((QObject*)qmlView.engine(), SIGNAL(quit()), &app, SLOT(quit()));
81
82     app.exec();
83 }