1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "qtuiapplication.h"
23 #include <QStringList>
26 # include <KStandardDirs>
30 #include "cliparser.h"
32 #include "qtuisettings.h"
34 QtUiApplication::QtUiApplication(int &argc, char **argv)
38 : QApplication(argc, argv),
44 Q_UNUSED(argc); Q_UNUSED(argv);
46 // We need to setup KDE's data dirs
47 QStringList dataDirs = KGlobal::dirs()->findDirs("data", "");
48 for(int i = 0; i < dataDirs.count(); i++)
49 dataDirs[i].append("quassel/");
50 dataDirs.append(":/data/");
51 setDataDirPaths(dataDirs);
55 setDataDirPaths(findDataDirPaths());
59 #if defined(HAVE_KDE) || defined(Q_OS_MAC)
60 disableCrashhandler();
61 #endif /* HAVE_KDE || Q_OS_MAC */
62 setRunMode(Quassel::ClientOnly);
64 qInstallMsgHandler(Client::logMessage);
67 bool QtUiApplication::init() {
70 // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
71 // Move settings, note this does not delete the old files
73 QSettings newSettings("quassel-irc.org", "quasselclient");
77 QSettings::Format format = QSettings::IniFormat;
79 QSettings::Format format = QSettings::NativeFormat;
82 QString newFilePath = Quassel::configDirPath() + "quasselclient"
83 + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
84 QSettings newSettings(newFilePath, format);
87 if(newSettings.value("Config/Version").toUInt() == 0) {
89 QString org = "quassel-irc.org";
91 QString org = "Quassel Project";
93 QSettings oldSettings(org, "Quassel Client");
94 if(oldSettings.allKeys().count()) {
95 qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
96 foreach(QString key, oldSettings.allKeys())
97 newSettings.setValue(key, oldSettings.value(key));
98 newSettings.setValue("Config/Version", 1);
99 qWarning() << "* Your client settings have been migrated to" << newSettings.fileName();
100 qWarning() << "*** Migration completed.\n\n";
106 // check settings version
107 // so far, we only have 1
109 if(s.version() != 1) {
110 qCritical() << "Invalid client settings version, terminating!";
115 QtUi *gui = new QtUi();
117 // init gui only after the event loop has started
118 // QTimer::singleShot(0, gui, SLOT(init()));
120 resumeSessionIfPossible();
126 QtUiApplication::~QtUiApplication() {
130 void QtUiApplication::quit() {
131 QtUi::mainWindow()->quit();
134 void QtUiApplication::commitData(QSessionManager &manager) {
139 void QtUiApplication::saveState(QSessionManager & manager) {
140 //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
141 AccountId activeCore = Client::currentCoreAccount(); // FIXME store this!
142 SessionSettings s(manager.sessionId());
144 QtUi::mainWindow()->saveStateToSettings(s);
147 void QtUiApplication::resumeSessionIfPossible() {
149 if(isSessionRestored()) {
150 qDebug() << QString("restoring from session %1").arg(sessionId());
151 SessionSettings s(sessionId());
154 QtUi::mainWindow()->restoreStateFromSettings(s);
157 SessionSettings s(QString("1"));