PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/quassel-0.7.3/src/qtui/qtuiapplication.cpp

#
C++ | 162 lines | 108 code | 24 blank | 30 comment | 11 complexity | 24cf31bdadb89d58800e905568ce680b MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2005-2010 by the Quassel Project *
  3. * devel@quassel-irc.org *
  4. * *
  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. *
  9. * *
  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. *
  14. * *
  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. ***************************************************************************/
  20. #include "qtuiapplication.h"
  21. #include <QStringList>
  22. #ifdef HAVE_KDE
  23. # include <KStandardDirs>
  24. #endif
  25. #include "client.h"
  26. #include "cliparser.h"
  27. #include "mainwin.h"
  28. #include "qtui.h"
  29. #include "qtuisettings.h"
  30. QtUiApplication::QtUiApplication(int &argc, char **argv)
  31. #ifdef HAVE_KDE
  32. : KApplication(),
  33. #else
  34. : QApplication(argc, argv),
  35. #endif
  36. Quassel(),
  37. _aboutToQuit(false)
  38. {
  39. #ifdef HAVE_KDE
  40. Q_UNUSED(argc); Q_UNUSED(argv);
  41. // We need to setup KDE's data dirs
  42. QStringList dataDirs = KGlobal::dirs()->findDirs("data", "");
  43. for(int i = 0; i < dataDirs.count(); i++)
  44. dataDirs[i].append("quassel/");
  45. dataDirs.append(":/data/");
  46. setDataDirPaths(dataDirs);
  47. #else /* HAVE_KDE */
  48. setDataDirPaths(findDataDirPaths());
  49. #endif /* HAVE_KDE */
  50. #if defined(HAVE_KDE) || defined(Q_OS_MAC)
  51. disableCrashhandler();
  52. #endif /* HAVE_KDE || Q_OS_MAC */
  53. setRunMode(Quassel::ClientOnly);
  54. qInstallMsgHandler(Client::logMessage);
  55. }
  56. bool QtUiApplication::init() {
  57. if(Quassel::init()) {
  58. // FIXME: MIGRATION 0.3 -> 0.4: Move database and core config to new location
  59. // Move settings, note this does not delete the old files
  60. #ifdef Q_WS_MAC
  61. QSettings newSettings("quassel-irc.org", "quasselclient");
  62. #else
  63. # ifdef Q_WS_WIN
  64. QSettings::Format format = QSettings::IniFormat;
  65. # else
  66. QSettings::Format format = QSettings::NativeFormat;
  67. # endif
  68. QString newFilePath = Quassel::configDirPath() + "quasselclient"
  69. + ((format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"));
  70. QSettings newSettings(newFilePath, format);
  71. #endif /* Q_WS_MAC */
  72. if(newSettings.value("Config/Version").toUInt() == 0) {
  73. # ifdef Q_WS_MAC
  74. QString org = "quassel-irc.org";
  75. # else
  76. QString org = "Quassel Project";
  77. # endif
  78. QSettings oldSettings(org, "Quassel Client");
  79. if(oldSettings.allKeys().count()) {
  80. qWarning() << "\n\n*** IMPORTANT: Config and data file locations have changed. Attempting to auto-migrate your client settings...";
  81. foreach(QString key, oldSettings.allKeys())
  82. newSettings.setValue(key, oldSettings.value(key));
  83. newSettings.setValue("Config/Version", 1);
  84. qWarning() << "* Your client settings have been migrated to" << newSettings.fileName();
  85. qWarning() << "*** Migration completed.\n\n";
  86. }
  87. }
  88. // MIGRATION end
  89. // check settings version
  90. // so far, we only have 1
  91. QtUiSettings s;
  92. if(s.version() != 1) {
  93. qCritical() << "Invalid client settings version, terminating!";
  94. return false;
  95. }
  96. // session resume
  97. QtUi *gui = new QtUi();
  98. Client::init(gui);
  99. // init gui only after the event loop has started
  100. // QTimer::singleShot(0, gui, SLOT(init()));
  101. gui->init();
  102. resumeSessionIfPossible();
  103. return true;
  104. }
  105. return false;
  106. }
  107. QtUiApplication::~QtUiApplication() {
  108. Client::destroy();
  109. }
  110. void QtUiApplication::quit() {
  111. QtUi::mainWindow()->quit();
  112. }
  113. void QtUiApplication::commitData(QSessionManager &manager) {
  114. Q_UNUSED(manager)
  115. _aboutToQuit = true;
  116. }
  117. void QtUiApplication::saveState(QSessionManager & manager) {
  118. //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
  119. AccountId activeCore = Client::currentCoreAccount().accountId(); // FIXME store this!
  120. SessionSettings s(manager.sessionId());
  121. s.setSessionAge(0);
  122. QtUi::mainWindow()->saveStateToSettings(s);
  123. }
  124. void QtUiApplication::resumeSessionIfPossible() {
  125. // load all sessions
  126. if(isSessionRestored()) {
  127. qDebug() << QString("restoring from session %1").arg(sessionId());
  128. SessionSettings s(sessionId());
  129. s.sessionAging();
  130. s.setSessionAge(0);
  131. QtUi::mainWindow()->restoreStateFromSettings(s);
  132. s.cleanup();
  133. } else {
  134. SessionSettings s(QString("1"));
  135. s.sessionAging();
  136. s.cleanup();
  137. }
  138. }