1 /***************************************************************************
2 * Copyright (C) 2005-2013 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"
23 #include <QStringList>
26 # include <KStandardDirs>
30 #include "cliparser.h"
33 #include "qtuisettings.h"
35 QtUiApplication::QtUiApplication(int &argc, char **argv)
39 : QApplication(argc, argv),
45 Q_UNUSED(argc); Q_UNUSED(argv);
47 // We need to setup KDE's data dirs
48 QStringList dataDirs = KGlobal::dirs()->findDirs("data", "");
49 for (int i = 0; i < dataDirs.count(); i++)
50 dataDirs[i].append("quassel/");
51 dataDirs.append(":/data/");
52 setDataDirPaths(dataDirs);
56 setDataDirPaths(findDataDirPaths());
60 #if defined(HAVE_KDE) || defined(Q_OS_MAC)
61 disableCrashhandler();
62 #endif /* HAVE_KDE || Q_OS_MAC */
63 setRunMode(Quassel::ClientOnly);
65 qInstallMsgHandler(Client::logMessage);
69 bool QtUiApplication::init()
71 if (Quassel::init()) {
72 // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
73 // Move settings, note this does not delete the old files
75 QSettings newSettings("quassel-irc.org", "quasselclient");
79 QSettings::Format format = QSettings::IniFormat;
81 QSettings::Format format = QSettings::NativeFormat;
84 QString newFilePath = Quassel::configDirPath() + "quasselclient"
85 + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
86 QSettings newSettings(newFilePath, format);
89 if (newSettings.value("Config/Version").toUInt() == 0) {
91 QString org = "quassel-irc.org";
93 QString org = "Quassel Project";
95 QSettings oldSettings(org, "Quassel Client");
96 if (oldSettings.allKeys().count()) {
97 qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
98 foreach(QString key, oldSettings.allKeys())
99 newSettings.setValue(key, oldSettings.value(key));
100 newSettings.setValue("Config/Version", 1);
101 qWarning() << "* Your client settings have been migrated to" << newSettings.fileName();
102 qWarning() << "*** Migration completed.\n\n";
108 // check settings version
109 // so far, we only have 1
111 if (s.version() != 1) {
112 qCritical() << "Invalid client settings version, terminating!";
117 QtUi *gui = new QtUi();
119 // init gui only after the event loop has started
120 // QTimer::singleShot(0, gui, SLOT(init()));
122 resumeSessionIfPossible();
129 QtUiApplication::~QtUiApplication()
135 void QtUiApplication::quit()
137 QtUi::mainWindow()->quit();
141 void QtUiApplication::commitData(QSessionManager &manager)
148 void QtUiApplication::saveState(QSessionManager &manager)
150 //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
151 // AccountId activeCore = Client::currentCoreAccount().accountId(); // FIXME store this!
152 SessionSettings s(manager.sessionId());
154 QtUi::mainWindow()->saveStateToSettings(s);
158 void QtUiApplication::resumeSessionIfPossible()
161 if (isSessionRestored()) {
162 qDebug() << QString("restoring from session %1").arg(sessionId());
163 SessionSettings s(sessionId());
166 QtUi::mainWindow()->restoreStateFromSettings(s);
170 SessionSettings s(QString("1"));