1 /***************************************************************************
2 * Copyright (C) 2005-2015 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());
59 #endif /* HAVE_KDE4 */
61 #if defined(HAVE_KDE4) || defined(Q_OS_MAC)
62 disableCrashhandler();
63 #endif /* HAVE_KDE4 || Q_OS_MAC */
64 setRunMode(Quassel::ClientOnly);
66 #if QT_VERSION < 0x050000
67 qInstallMsgHandler(Client::logMessage);
69 qInstallMessageHandler(Client::logMessage);
74 bool QtUiApplication::init()
76 if (Quassel::init()) {
77 // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
78 // Move settings, note this does not delete the old files
80 QSettings newSettings("quassel-irc.org", "quasselclient");
84 QSettings::Format format = QSettings::IniFormat;
86 QSettings::Format format = QSettings::NativeFormat;
89 QString newFilePath = Quassel::configDirPath() + "quasselclient"
90 + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
91 QSettings newSettings(newFilePath, format);
94 if (newSettings.value("Config/Version").toUInt() == 0) {
96 QString org = "quassel-irc.org";
98 QString org = "Quassel Project";
100 QSettings oldSettings(org, "Quassel Client");
101 if (oldSettings.allKeys().count()) {
102 qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
103 foreach(QString key, oldSettings.allKeys())
104 newSettings.setValue(key, oldSettings.value(key));
105 newSettings.setValue("Config/Version", 1);
106 qWarning() << "* Your client settings have been migrated to" << newSettings.fileName();
107 qWarning() << "*** Migration completed.\n\n";
113 // check settings version
114 // so far, we only have 1
116 if (s.version() != 1) {
117 qCritical() << "Invalid client settings version, terminating!";
121 // Set the icon theme
122 if (Quassel::isOptionSet("icontheme"))
123 QIcon::setThemeName(Quassel::optionValue("icontheme"));
124 else if (QIcon::themeName().isEmpty())
125 // Some platforms don't set a default icon theme; chances are we can find our bundled Oxygen theme though
126 QIcon::setThemeName("oxygen");
129 QtUi *gui = new QtUi();
131 // init gui only after the event loop has started
132 // QTimer::singleShot(0, gui, SLOT(init()));
134 resumeSessionIfPossible();
141 QtUiApplication::~QtUiApplication()
147 void QtUiApplication::quit()
149 QtUi::mainWindow()->quit();
153 void QtUiApplication::commitData(QSessionManager &manager)
160 void QtUiApplication::saveState(QSessionManager &manager)
162 //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
163 // AccountId activeCore = Client::currentCoreAccount().accountId(); // FIXME store this!
164 SessionSettings s(manager.sessionId());
166 QtUi::mainWindow()->saveStateToSettings(s);
170 void QtUiApplication::resumeSessionIfPossible()
173 if (isSessionRestored()) {
174 qDebug() << QString("restoring from session %1").arg(sessionId());
175 SessionSettings s(sessionId());
178 QtUi::mainWindow()->restoreStateFromSettings(s);
182 SessionSettings s(QString("1"));