1 /***************************************************************************
2 * Copyright (C) 2005-2014 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "qtuiapplication.h"
24 #include <QStringList>
27 # include <KStandardDirs>
31 #include "cliparser.h"
34 #include "qtuisettings.h"
36 QtUiApplication::QtUiApplication(int &argc, char **argv)
40 : QApplication(argc, argv),
46 Q_UNUSED(argc); Q_UNUSED(argv);
48 // We need to setup KDE's data dirs
49 QStringList dataDirs = KGlobal::dirs()->findDirs("data", "");
50 for (int i = 0; i < dataDirs.count(); i++)
51 dataDirs[i].append("quassel/");
52 dataDirs.append(":/data/");
53 setDataDirPaths(dataDirs);
57 setDataDirPaths(findDataDirPaths());
61 #if defined(HAVE_KDE) || defined(Q_OS_MAC)
62 disableCrashhandler();
63 #endif /* HAVE_KDE || Q_OS_MAC */
64 setRunMode(Quassel::ClientOnly);
66 #if QT_VERSION < 0x050000
67 qInstallMsgHandler(Client::logMessage);
69 qInstallMessageHandler(Client::logMessage);
72 // Some platforms don't set a default icon theme; chances are we can find our bundled Oxygen theme though
73 if (QIcon::themeName().isEmpty())
74 QIcon::setThemeName("oxygen");
78 bool QtUiApplication::init()
80 if (Quassel::init()) {
81 // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
82 // Move settings, note this does not delete the old files
84 QSettings newSettings("quassel-irc.org", "quasselclient");
88 QSettings::Format format = QSettings::IniFormat;
90 QSettings::Format format = QSettings::NativeFormat;
93 QString newFilePath = Quassel::configDirPath() + "quasselclient"
94 + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
95 QSettings newSettings(newFilePath, format);
98 if (newSettings.value("Config/Version").toUInt() == 0) {
100 QString org = "quassel-irc.org";
102 QString org = "Quassel Project";
104 QSettings oldSettings(org, "Quassel Client");
105 if (oldSettings.allKeys().count()) {
106 qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
107 foreach(QString key, oldSettings.allKeys())
108 newSettings.setValue(key, oldSettings.value(key));
109 newSettings.setValue("Config/Version", 1);
110 qWarning() << "* Your client settings have been migrated to" << newSettings.fileName();
111 qWarning() << "*** Migration completed.\n\n";
117 // check settings version
118 // so far, we only have 1
120 if (s.version() != 1) {
121 qCritical() << "Invalid client settings version, terminating!";
126 QtUi *gui = new QtUi();
128 // init gui only after the event loop has started
129 // QTimer::singleShot(0, gui, SLOT(init()));
131 resumeSessionIfPossible();
138 QtUiApplication::~QtUiApplication()
144 void QtUiApplication::quit()
146 QtUi::mainWindow()->quit();
150 void QtUiApplication::commitData(QSessionManager &manager)
157 void QtUiApplication::saveState(QSessionManager &manager)
159 //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
160 // AccountId activeCore = Client::currentCoreAccount().accountId(); // FIXME store this!
161 SessionSettings s(manager.sessionId());
163 QtUi::mainWindow()->saveStateToSettings(s);
167 void QtUiApplication::resumeSessionIfPossible()
170 if (isSessionRestored()) {
171 qDebug() << QString("restoring from session %1").arg(sessionId());
172 SessionSettings s(sessionId());
175 QtUi::mainWindow()->restoreStateFromSettings(s);
179 SessionSettings s(QString("1"));