-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
130 lines (116 loc) · 5.07 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This file is part of IRC Chatter, the first IRC Client for MeeGo.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright (C) 2011-2012, Timur Kristóf <venemo@fedoraproject.org>
// Copyright (C) 2011, Hiemanshu Sharma <mail@theindiangeek.in>
#include <QtCore/QSettings>
#if QT_VERSION >= 0x050000
#include <QtGui/QGuiApplication>
#include <QtQuick/QtQuick>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#if defined(USE_DESKTOP_UI)
#include <QtWidgets/QApplication>
#endif
#else
#include <QtGui/QApplication>
#include <QtDeclarative/QtDeclarative>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
#endif
#include "helpers/appeventlistener.h"
#include "model/ircmodel.h"
#include "model/settings/appsettings.h"
#if defined(HAVE_APPLAUNCHERD)
#include <MDeclarativeCache>
#endif
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QString appVersion(APP_VERSION);
bool isPreRelease = false;
#if defined(PRERELEASE)
appVersion += " (Unstable pre-release)";
isPreRelease = true;
#endif
QCoreApplication::setApplicationName("irc-chatter");
QCoreApplication::setOrganizationName("irc-chatter");
QCoreApplication::setApplicationVersion(APP_VERSION);
#if defined(HAVE_APPLAUNCHERD)
qDebug() << "IRC Chatter is using applauncherd";
QApplication *app = MDeclarativeCache::qApplication(argc, argv);
QDeclarativeView *view = MDeclarativeCache::qDeclarativeView();
#elif QT_VERSION >= 0x050000 && defined(USE_DESKTOP_UI)
QApplication *app = new QApplication(argc, argv);
QQuickView *view = new QQuickView();
#elif QT_VERSION >= 0x050000
QGuiApplication *app = new QGuiApplication(argc, argv);
QQuickView *view = new QQuickView();
#else
QApplication *app = new QApplication(argc, argv);
QDeclarativeView *view = new QDeclarativeView();
#endif
QCoreApplication::addLibraryPath("./plugins");
AppSettings *appSettings = new AppSettings(app);
IrcModel *model = new IrcModel(app, appSettings);
AppEventListener *eventListener = new AppEventListener(model);
app->installEventFilter(eventListener);
qDebug() << "QApplication, QDeclarativeView, IrcModel, AppEventListener instances created";
qmlRegisterType<ServerSettings>("net.venemo.ircchatter", 1, 0, "ServerSettings");
qmlRegisterType<AppSettings>("net.venemo.ircchatter", 1, 0, "AppSettings");
qmlRegisterUncreatableType<ChannelModel>("net.venemo.ircchatter", 1, 0, "ChannelModel", "This object is created in the model.");
qmlRegisterUncreatableType<IrcModel>("net.venemo.ircchatter", 1, 0, "IrcModel", "This object is created in the model.");
qDebug() << "QML types registered";
QObject::connect(eventListener, SIGNAL(applicationActivated()), view, SLOT(raise()));
QObject::connect(app, SIGNAL(aboutToQuit()), appSettings, SLOT(saveServerSettings()));
QObject::connect(view->engine(), SIGNAL(quit()), app, SLOT(quit()));
#if QT_VERSION >= 0x050000
view->setTitle("IRC Chatter");
#else
view->setWindowTitle("IRC Chatter");
view->setAttribute(Qt::WA_OpaquePaintEvent);
view->setAttribute(Qt::WA_NoSystemBackground);
view->viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
#endif
view->rootContext()->setContextProperty("ircModel", model);
view->rootContext()->setContextProperty("appVersion", appVersion);
view->rootContext()->setContextProperty("appSettings", appSettings);
view->rootContext()->setContextProperty("isPreRelease", isPreRelease);
qDebug() << "View set up";
#if defined(USE_MEEGO_UI)
view->setSource(QUrl("qrc:/qml/meego/AppWindow.qml"));
view->showFullScreen();
#elif defined(USE_DESKTOP_UI)
if (view->screen()->size().width() > 1024)
view->setMinimumSize(QSize(view->screen()->size().width() * 2 / 3, view->screen()->size().height() * 2 / 3));
else
view->setMinimumSize(QSize(800, 480));
view->setWidth(view->minimumWidth());
view->setHeight(view->minimumHeight());
view->setPosition(view->screen()->size().width() / 2 - view->width() / 2, view->screen()->size().height() / 2 - view->height() / 2);
view->setResizeMode(QQuickView::SizeRootObjectToView);
view->setSource(QUrl("qrc:/qml/desktop/AppWindow.qml"));
view->show();
#else
#error Please configure your build properly and select a UI.
#endif
qDebug() << "View shown";
int result = app->exec();
delete view;
delete app;
return result;
}