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"
37 QtUiApplication::QtUiApplication(int &argc, char **argv)
39 : KApplication(), // KApplication is deprecated in KF5
41 : QApplication(argc, argv),
47 Q_UNUSED(argc); Q_UNUSED(argv);
49 // Setup KDE's data dirs
50 // Because we can't use KDE stuff in (the class) Quassel directly, we need to do this here...
51 QStringList dataDirs = KGlobal::dirs()->findDirs("data", "");
53 // Just in case, also check our install prefix
54 dataDirs << QCoreApplication::applicationDirPath() + "/../share/apps/";
56 // Normalize and append our application name
57 for (int i = 0; i < dataDirs.count(); i++)
58 dataDirs[i] = QDir::cleanPath(dataDirs.at(i)) + "/quassel/";
60 // Add resource path and just in case.
61 // Workdir should have precedence
62 dataDirs.prepend(QCoreApplication::applicationDirPath() + "/data/");
63 dataDirs.append(":/data/");
65 // Append trailing '/' and check for existence
66 auto iter = dataDirs.begin();
67 while (iter != dataDirs.end()) {
68 if (!iter->endsWith(QDir::separator()) && !iter->endsWith('/'))
69 iter->append(QDir::separator());
70 if (!QFile::exists(*iter))
71 iter = dataDirs.erase(iter);
76 dataDirs.removeDuplicates();
77 setDataDirPaths(dataDirs);
81 setDataDirPaths(findDataDirPaths());
83 #endif /* HAVE_KDE4 */
85 #if defined(HAVE_KDE4) || defined(Q_OS_MAC)
86 disableCrashhandler();
87 #endif /* HAVE_KDE4 || Q_OS_MAC */
88 setRunMode(Quassel::ClientOnly);
90 #if QT_VERSION < 0x050000
91 qInstallMsgHandler(Client::logMessage);
93 qInstallMessageHandler(Client::logMessage);
98 bool QtUiApplication::init()
100 if (Quassel::init()) {
101 // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
102 // Move settings, note this does not delete the old files
104 QSettings newSettings("quassel-irc.org", "quasselclient");
108 QSettings::Format format = QSettings::IniFormat;
110 QSettings::Format format = QSettings::NativeFormat;
113 QString newFilePath = Quassel::configDirPath() + "quasselclient"
114 + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
115 QSettings newSettings(newFilePath, format);
116 #endif /* Q_OS_MAC */
118 if (newSettings.value("Config/Version").toUInt() == 0) {
120 QString org = "quassel-irc.org";
122 QString org = "Quassel Project";
124 QSettings oldSettings(org, "Quassel Client");
125 if (oldSettings.allKeys().count()) {
126 qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
127 foreach(QString key, oldSettings.allKeys())
128 newSettings.setValue(key, oldSettings.value(key));
129 newSettings.setValue("Config/Version", 1);
130 qWarning() << "* Your client settings have been migrated to" << newSettings.fileName();
131 qWarning() << "*** Migration completed.\n\n";
137 // check settings version
138 // so far, we only have 1
140 if (s.version() != 1) {
141 qCritical() << "Invalid client settings version, terminating!";
145 // Set the icon theme
146 if (Quassel::isOptionSet("icontheme"))
147 QIcon::setThemeName(Quassel::optionValue("icontheme"));
148 else if (QIcon::themeName().isEmpty())
149 // Some platforms don't set a default icon theme; chances are we can find our bundled Oxygen theme though
150 QIcon::setThemeName("oxygen");
153 QtUi *gui = new QtUi();
155 // init gui only after the event loop has started
156 // QTimer::singleShot(0, gui, SLOT(init()));
158 resumeSessionIfPossible();
165 QtUiApplication::~QtUiApplication()
171 void QtUiApplication::quit()
173 QtUi::mainWindow()->quit();
177 void QtUiApplication::commitData(QSessionManager &manager)
184 void QtUiApplication::saveState(QSessionManager &manager)
186 //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
187 // AccountId activeCore = Client::currentCoreAccount().accountId(); // FIXME store this!
188 SessionSettings s(manager.sessionId());
190 QtUi::mainWindow()->saveStateToSettings(s);
194 void QtUiApplication::resumeSessionIfPossible()
197 if (isSessionRestored()) {
198 qDebug() << QString("restoring from session %1").arg(sessionId());
199 SessionSettings s(sessionId());
202 QtUi::mainWindow()->restoreStateFromSettings(s);
206 SessionSettings s(QString("1"));