#include "cliparser.h"
#if defined BUILD_CORE
-#include <QCoreApplication>
#include <QDir>
#include "core.h"
#include "message.h"
#elif defined BUILD_QTUI
-#include <QApplication>
#include "client.h"
+#include "qtuiapplication.h"
#include "qtui.h"
#elif defined BUILD_MONO
-#include <QApplication>
#include "client.h"
#include "core.h"
#include "coresession.h"
+#include "qtuiapplication.h"
#include "qtui.h"
#else
#error "Something is wrong - you need to #define a build mode!"
#endif
+
#include <signal.h>
//! Signal handler for graceful shutdown.
Global::registerMetaTypes();
Global::setupVersion();
+/*
#if defined BUILD_CORE
Global::runMode = Global::CoreOnly;
QCoreApplication app(argc, argv);
Global::runMode = Global::Monolithic;
QApplication app(argc, argv);
#endif
+*/
+#if defined BUILD_CORE
+ Global::runMode = Global::CoreOnly;
+ QCoreApplication app(argc, argv);
+#elif defined BUILD_QTUI
+ Global::runMode = Global::ClientOnly;
+ QtUiApplication app(argc, argv);
+#else
+ Global::runMode = Global::Monolithic;
+ QtUiApplication app(argc, argv);
+#endif
+
+
Global::parser = CliParser(QCoreApplication::arguments());
QCoreApplication::setApplicationName("Quassel IRC");
QCoreApplication::setOrganizationName("Quassel Project");
+
#ifndef BUILD_QTUI
Core::instance(); // create and init the core
#endif
//Settings::init();
#ifndef BUILD_CORE
+ // session resume
QtUi *gui = new QtUi();
Client::init(gui);
// init gui only after the event loop has started
}
#endif
+#ifndef BUILD_CORE
+ app.resumeSessionIfPossible();
+#endif
+
int exitCode = app.exec();
#ifndef BUILD_QTUI
mainwin.cpp
msgprocessorstatuswidget.cpp
nicklistwidget.cpp
+ qtuiapplication.cpp
qtui.cpp
qtuimessageprocessor.cpp
qtuisettings.cpp
qtuistyle.cpp
+ sessionsettings.cpp
settingsdlg.cpp
settingspagedlg.cpp
titlesetter.cpp
msgprocessorstatuswidget.h
nicklistwidget.h
qtui.h
+ qtuiapplication.h
qtuimessageprocessor.h
settingsdlg.h
settingspagedlg.h
#include "coreconnectdlg.h"
#include "msgprocessorstatuswidget.h"
#include "qtuimessageprocessor.h"
+#include "qtuiapplication.h"
#include "networkmodel.h"
#include "buffermodel.h"
#include "nicklistwidget.h"
#include "uisettings.h"
#include "qtuisettings.h"
#include "jumpkeyhandler.h"
+#include "sessionsettings.h"
#include "selectionmodelsynchronizer.h"
#include "mappedselectionmodel.h"
connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint)));
connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&)));
#endif
+ QtUiApplication* app = dynamic_cast<QtUiApplication*> qApp;
+ connect(app, SIGNAL(saveStateToSession(const QString&)), this, SLOT(saveStateToSession(const QString&)));
+ connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), this, SLOT(saveStateToSessionSettings(SessionSettings&)));
}
void MainWin::init() {
view->resize(610, 300);
view->show();
}
+
+void MainWin::saveStateToSession(const QString &sessionId) {
+ return;
+ SessionSettings s(sessionId);
+
+ s.setValue("MainWinSize", size());
+ s.setValue("MainWinPos", pos());
+ s.setValue("MainWinState", saveState());
+}
+
+void MainWin::saveStateToSessionSettings(SessionSettings & s)
+{
+ s.setValue("MainWinSize", size());
+ s.setValue("MainWinPos", pos());
+ s.setValue("MainWinState", saveState());
+}
#include "qtui.h"
#include "titlesetter.h"
+#include "sessionsettings.h"
#include <QSystemTrayIcon>
#include <QTimer>
class MainWin : public QMainWindow {
Q_OBJECT
-public:
- MainWin(QWidget *parent = 0);
- virtual ~MainWin();
+ public:
+ MainWin(QWidget *parent = 0);
+ virtual ~MainWin();
- void init();
- void addBufferView(BufferViewConfig *config = 0);
+ void init();
+ void addBufferView(BufferViewConfig *config = 0);
- void displayTrayIconMessage(const QString &title, const QString &message);
+ void displayTrayIconMessage(const QString &title, const QString &message);
#ifdef HAVE_DBUS
- void sendDesktopNotification(const QString &title, const QString &message);
+ void sendDesktopNotification(const QString &title, const QString &message);
#endif
- virtual bool event(QEvent *event);
-
-public slots:
- void setTrayIconActivity(bool active = false);
-
-protected:
- void closeEvent(QCloseEvent *event);
- virtual void changeEvent(QEvent *event);
-
-protected slots:
- void connectedToCore();
- void setConnectedState();
- void updateLagIndicator(int lag);
- void securedConnection();
- void disconnectedFromCore();
- void setDisconnectedState();
- void systrayActivated( QSystemTrayIcon::ActivationReason );
-
-private slots:
- void addBufferView(int bufferViewConfigId);
- void removeBufferView(int bufferViewConfigId);
- void messagesInserted(const QModelIndex &parent, int start, int end);
- void showChannelList(NetworkId netId = NetworkId());
- void showCoreInfoDlg();
- void showSettingsDlg();
- void on_actionEditNetworks_triggered();
- void on_actionManageViews_triggered();
- void on_actionLockDockPositions_toggled(bool lock);
- void showAboutDlg();
- void on_actionDebugNetworkModel_triggered(bool);
-
- void showCoreConnectionDlg(bool autoConnect = false);
-
- void clientNetworkCreated(NetworkId);
- void clientNetworkRemoved(NetworkId);
- void clientNetworkUpdated();
- void connectOrDisconnectFromNet();
-
- void makeTrayIconBlink();
- void saveStatusBarStatus(bool enabled);
-
- void loadLayout();
- void saveLayout();
-
+ virtual bool event(QEvent *event);
+ public slots:
+ void setTrayIconActivity(bool active = false);
+ void saveStateToSession(const QString &sessionId);
+ void saveStateToSessionSettings(SessionSettings &s);
+
+ protected:
+ void closeEvent(QCloseEvent *event);
+ virtual void changeEvent(QEvent *event);
+
+ protected slots:
+ void connectedToCore();
+ void setConnectedState();
+ void updateLagIndicator(int lag);
+ void securedConnection();
+ void disconnectedFromCore();
+ void setDisconnectedState();
+ void systrayActivated( QSystemTrayIcon::ActivationReason );
+
+ private slots:
+ void addBufferView(int bufferViewConfigId);
+ void removeBufferView(int bufferViewConfigId);
+ void messagesInserted(const QModelIndex &parent, int start, int end);
+ void showChannelList(NetworkId netId = NetworkId());
+ void showCoreInfoDlg();
+ void showSettingsDlg();
+ void on_actionEditNetworks_triggered();
+ void on_actionManageViews_triggered();
+ void on_actionLockDockPositions_toggled(bool lock);
+ void showAboutDlg();
+ void on_actionDebugNetworkModel_triggered(bool);
+
+ void showCoreConnectionDlg(bool autoConnect = false);
+
+ void clientNetworkCreated(NetworkId);
+ void clientNetworkRemoved(NetworkId);
+ void clientNetworkUpdated();
+ void connectOrDisconnectFromNet();
+
+ void makeTrayIconBlink();
+ void saveStatusBarStatus(bool enabled);
+
+ void loadLayout();
+ void saveLayout();
+
#ifdef HAVE_DBUS
- void desktopNotificationClosed(uint id, uint reason);
- void desktopNotificationInvoked(uint id, const QString & action);
+ void desktopNotificationClosed(uint id, uint reason);
+ void desktopNotificationInvoked(uint id, const QString & action);
#endif
-
-signals:
- void connectToCore(const QVariantMap &connInfo);
- void disconnectFromCore();
- void requestBacklog(BufferInfo, QVariant, QVariant);
-
-private:
- Ui::MainWin ui;
-
- QMenu *systrayMenu;
- QLabel *coreLagLabel;
- QLabel *sslLabel;
- MsgProcessorStatusWidget *msgProcessorStatusWidget;
-
- TitleSetter _titleSetter;
-
- void setupMenus();
- void setupViews();
- void setupNickWidget();
- void setupChatMonitor();
- void setupInputWidget();
- void setupTopicWidget();
- void setupStatusBar();
- void setupSystray();
-
- void toggleVisibility();
-
- void enableMenus();
-
- QSystemTrayIcon *systray;
- QIcon activeTrayIcon;
- QIcon onlineTrayIcon;
- QIcon offlineTrayIcon;
- bool trayIconActive;
- QTimer *timer;
-
- BufferId currentBuffer;
- QString currentProfile;
-
- QList<QDockWidget *> _netViews;
- NickListWidget *nickListWidget;
-
+
+ signals:
+ void connectToCore(const QVariantMap &connInfo);
+ void disconnectFromCore();
+ void requestBacklog(BufferInfo, QVariant, QVariant);
+
+ private:
+ Ui::MainWin ui;
+
+ QMenu *systrayMenu;
+ QLabel *coreLagLabel;
+ QLabel *sslLabel;
+ MsgProcessorStatusWidget *msgProcessorStatusWidget;
+
+ TitleSetter _titleSetter;
+
+ void setupMenus();
+ void setupViews();
+ void setupNickWidget();
+ void setupChatMonitor();
+ void setupInputWidget();
+ void setupTopicWidget();
+ void setupStatusBar();
+ void setupSystray();
+
+ void toggleVisibility();
+ void enableMenus();
+
+ QSystemTrayIcon *systray;
+ QIcon activeTrayIcon;
+ QIcon onlineTrayIcon;
+ QIcon offlineTrayIcon;
+ bool trayIconActive;
+ QTimer *timer;
+
+ BufferId currentBuffer;
+ QString currentProfile;
+
+ QList<QDockWidget *> _netViews;
+ NickListWidget *nickListWidget;
+
#ifdef HAVE_DBUS
- org::freedesktop::Notifications *desktopNotifications;
- quint32 notificationId;
+ org::freedesktop::Notifications *desktopNotifications;
+ quint32 notificationId;
#endif
-
- friend class QtUi;
+
+ friend class QtUi;
};
#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <QStringList>
+
+#include "qtuiapplication.h"
+#include "sessionsettings.h"
+#include "client.h"
+
+QtUiApplication::QtUiApplication(int &argc, char **argv) : QApplication(argc, argv) {
+
+}
+
+void QtUiApplication::saveState(QSessionManager & manager) {
+ //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
+ AccountId activeCore = Client::currentCoreAccount();
+ SessionSettings s(manager.sessionId());
+ s.setSessionAge(0);
+ emit saveStateToSession(manager.sessionId());
+ emit saveStateToSessionSettings(s);
+}
+
+QtUiApplication::~ QtUiApplication() {
+}
+
+void QtUiApplication::resumeSessionIfPossible() {
+ // load all sessions
+ if(isSessionRestored()) {
+ qDebug() << QString("restoring from session %1").arg(sessionId());
+ SessionSettings s(sessionId());
+ s.sessionAging();
+ s.setSessionAge(0);
+ emit resumeFromSession(sessionId());
+ emit resumeFromSessionSettings(s);
+ s.cleanup();
+ } else {
+ SessionSettings s(QString("1"));
+ s.sessionAging();
+ s.cleanup();
+ }
+}
+
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef QTUIAPPLICATION_H_
+#define QTUIAPPLICATION_H_
+
+#include <QApplication>
+#include <QSessionManager>
+
+#include "sessionsettings.h"
+#include "qtui.h"
+
+class QtUiApplication : public QApplication {
+ Q_OBJECT
+ public:
+ QtUiApplication(int &, char**);
+ ~QtUiApplication();
+ void resumeSessionIfPossible();
+ virtual void saveState(QSessionManager & manager);
+ signals:
+ void saveStateToSession(const QString &sessionId);
+ void saveStateToSessionSettings(SessionSettings &s);
+ void resumeFromSession(const QString sessionId);
+ void resumeFromSessionSettings(SessionSettings &s);
+
+};
+
+#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "sessionsettings.h"
+
+#include <QStringList>
+
+void SessionSettings::setValue(const QString &key, const QVariant &data) {
+ setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
+}
+
+QVariant SessionSettings::value(const QString &key, const QVariant &def) {
+ return localValue(QString("%1/%2").arg(_sessionId, key), def);
+}
+
+void SessionSettings::removeKey(const QString &key) {
+ removeLocalKey(QString("%1/%2").arg(_sessionId, key));
+}
+
+void SessionSettings::cleanup() {
+ QStringList sessions = localChildGroups();
+ QString str;
+ SessionSettings s(sessionId());
+ foreach(str, sessions) {
+ // load session and check age
+ s.setSessionId(str);
+ if(s.sessionAge() > 3) {
+ s.removeSession();
+ }
+ }
+}
+
+int SessionSettings::sessionAge() {
+ QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
+ bool b = false;
+ int i = val.toInt(&b);
+ if(b) {
+ return i;
+ } else {
+ // no int saved, delete session
+ //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
+ removeSession();
+ }
+ return 10;
+}
+
+void SessionSettings::removeSession() {
+ QStringList keys = localChildKeys(sessionId());
+ foreach(QString k, keys) {
+ removeKey(k);
+ }
+}
+
+
+SessionSettings::SessionSettings(const QString & sessionId, const QString & group) : ClientSettings(group), _sessionId(sessionId) {
+}
+
+void SessionSettings::setSessionAge(int age) {
+ setValue(QString("_sessionAge"),age);
+}
+
+void SessionSettings::sessionAging() {
+ QStringList sessions = localChildGroups();
+ QString str;
+ SessionSettings s(sessionId());
+ foreach(str, sessions) {
+ // load session and check age
+ s.setSessionId(str);
+ s.setSessionAge(s.sessionAge()+1);
+ }
+}
+
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+
+#ifndef _SESSIONSETTINGS_H_
+#define _SESSIONSETTINGS_H_
+
+#include <QVariant>
+
+#include "clientsettings.h"
+
+class SessionSettings : public ClientSettings {
+
+ public:
+ SessionSettings(const QString &sessionId, const QString &group = "Session");
+
+ void setValue(const QString &key, const QVariant &data);
+ QVariant value(const QString &key, const QVariant &def = QVariant());
+
+ void removeKey(const QString &key);
+ void removeSession();
+
+ void cleanup();
+ void sessionAging();
+
+ int sessionAge();
+ void setSessionAge(int age);
+ inline const QString sessionId() { return _sessionId; };
+ inline void setSessionId(const QString &sessionId) { _sessionId = sessionId; }
+ private:
+ QString _sessionId;
+};
+
+#endif