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 "sessionsettings.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 setRunMode(Quassel::ClientOnly);
61 qInstallMsgHandler(Client::logMessage);
64 bool QtUiApplication::init() {
68 // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
69 // Move settings, note this does not delete the old files
71 QSettings::Format format = QSettings::IniFormat;
73 QSettings::Format format = QSettings::NativeFormat;
75 QString newFilePath = Quassel::configDirPath() + "quasselclient"
76 + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
77 QSettings newSettings(newFilePath, format);
79 if(newSettings.value("Config/Version").toUInt() != 1) {
80 qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
82 QString org = "quassel-irc.org";
84 QString org = "Quassel Project";
86 QSettings oldSettings(org, "Quassel Client");
87 if(oldSettings.allKeys().count()) {
88 foreach(QString key, oldSettings.allKeys())
89 newSettings.setValue(key, oldSettings.value(key));
90 newSettings.setValue("Config/Version", 1);
91 qWarning() << "* Your client settings have been migrated to" << newFilePath;
93 qWarning() << "*** Migration completed.\n\n";
95 #endif /* !Q_WS_MAC */
99 QtUi *gui = new QtUi();
101 // init gui only after the event loop has started
102 // QTimer::singleShot(0, gui, SLOT(init()));
104 resumeSessionIfPossible();
110 QtUiApplication::~QtUiApplication() {
114 void QtUiApplication::commitData(QSessionManager &manager) {
119 void QtUiApplication::saveState(QSessionManager & manager) {
120 //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
121 AccountId activeCore = Client::currentCoreAccount();
122 SessionSettings s(manager.sessionId());
124 emit saveStateToSession(manager.sessionId());
125 emit saveStateToSessionSettings(s);
128 void QtUiApplication::resumeSessionIfPossible() {
130 if(isSessionRestored()) {
131 qDebug() << QString("restoring from session %1").arg(sessionId());
132 SessionSettings s(sessionId());
135 emit resumeFromSession(sessionId());
136 emit resumeFromSessionSettings(s);
139 SessionSettings s(QString("1"));