Fixes #410 - away log (you'll find it in the views menu)
authorMarcus Eggenberger <egs@quassel-irc.org>
Thu, 5 Feb 2009 14:23:40 +0000 (15:23 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Thu, 5 Feb 2009 14:23:51 +0000 (15:23 +0100)
14 files changed:
src/client/networkmodel.cpp
src/client/networkmodel.h
src/core/core.cpp
src/core/corenetwork.cpp
src/core/sessionthread.cpp
src/core/sessionthread.h
src/qtui/CMakeLists.txt
src/qtui/awaylogfilter.cpp [new file with mode: 0644]
src/qtui/awaylogfilter.h [new file with mode: 0644]
src/qtui/awaylogview.cpp [new file with mode: 0644]
src/qtui/awaylogview.h [new file with mode: 0644]
src/qtui/chatmonitorview.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h

index 2fad8d6..ee333ce 100644 (file)
@@ -960,6 +960,15 @@ MsgId NetworkModel::lastSeenMarkerMsgId(BufferId bufferId) const {
   return _bufferItemCache[bufferId]->lastSeenMarkerMsgId();
 }
 
+MsgId NetworkModel::lastSeenMsgId(const BufferId &bufferId) {
+  BufferItem *bufferItem = findBufferItem(bufferId);
+  if(!bufferItem) {
+    qDebug() << "NetworkModel::lastSeenMsgId(): buffer is unknown:" << bufferId;
+    return MsgId();
+  }
+  return bufferItem->lastSeenMsgId();
+}
+
 void NetworkModel::setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId) {
   BufferItem *bufferItem = findBufferItem(bufferId);
   if(!bufferItem) {
index 868de0b..f763a21 100644 (file)
@@ -323,6 +323,7 @@ public:
 public slots:
   void bufferUpdated(BufferInfo bufferInfo);
   void removeBuffer(BufferId bufferId);
+  MsgId lastSeenMsgId(const BufferId &bufferId);
   void setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId);
   void setBufferActivity(const BufferId &bufferId, BufferInfo::ActivityLevel activity);
   void clearBufferActivity(const BufferId &bufferId);
index aa1b7d4..4e7632f 100644 (file)
@@ -158,10 +158,21 @@ void Core::init() {
 }
 
 Core::~Core() {
+  _server.close();
+  _v6server.close();
   foreach(QTcpSocket *socket, blocksizes.keys()) {
     socket->disconnectFromHost();  // disconnect non authed clients
   }
-  qDeleteAll(sessions);
+
+  
+  foreach(SessionThread *session, sessions) {
+    session->stopSession();
+    session->wait();
+    delete session;
+    qDebug() << "next";
+  }
+
+//   qDeleteAll(sessions);
   qDeleteAll(_storageBackends);
 }
 
index a40b546..f056183 100644 (file)
@@ -82,6 +82,8 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
 CoreNetwork::~CoreNetwork() {
   if(connectionState() != Disconnected && connectionState() != Network::Reconnecting)
     disconnectFromIrc(false);      // clean up, but this does not count as requested disconnect!
+  else
+    socket.close();
   disconnect(&socket, 0, this, 0); // this keeps the socket from triggering events during clean up
   delete _ircServerHandler;
   delete _userInputHandler;
index 35caf13..c29d1ff 100644 (file)
@@ -36,9 +36,12 @@ SessionThread::SessionThread(UserId uid, bool restoreState, QObject *parent)
 }
 
 SessionThread::~SessionThread() {
-  // shut down thread gracefully
-  quit();
-  wait();
+  if(_session) {
+    _session->setParent(0);
+    _session->moveToThread(thread());
+    _session->deleteLater();
+    _session = 0;
+  }
 }
 
 CoreSession *SessionThread::session() {
@@ -103,5 +106,13 @@ void SessionThread::run() {
   emit initialized();
   exec();
   delete _session;
+  _session = 0;
 }
 
+void SessionThread::stopSession() {
+  if(_session) {
+    connect(_session, SIGNAL(destroyed()), this, SLOT(quit()));
+    _session->deleteLater();
+    _session = 0;
+  }
+}
index 810e858..f9280f0 100644 (file)
@@ -44,6 +44,7 @@ public:
 
 public slots:
   void addClient(QObject *peer);
+  void stopSession();
 
 private slots:
   void setSessionInitialized();
index 2e0d3cf..ca17c3a 100644 (file)
@@ -7,6 +7,8 @@ include(${QT_USE_FILE})
 
 set(SOURCES
     aboutdlg.cpp
+    awaylogfilter.cpp
+    awaylogview.cpp
     bufferwidget.cpp
     channellistdlg.cpp
     chatitem.cpp
@@ -50,6 +52,8 @@ set(SOURCES
 
 set(MOC_HDRS
     aboutdlg.h
+    awaylogfilter.h
+    awaylogview.h
     bufferwidget.h
     channellistdlg.h
     chatitem.h
diff --git a/src/qtui/awaylogfilter.cpp b/src/qtui/awaylogfilter.cpp
new file mode 100644 (file)
index 0000000..09964a4
--- /dev/null
@@ -0,0 +1,46 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   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 "awaylogfilter.h"
+
+AwayLogFilter::AwayLogFilter(MessageModel *model, QObject *parent)
+  : ChatMonitorFilter(model, parent)
+{
+}
+
+bool AwayLogFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
+  Q_UNUSED(sourceParent)
+
+  QModelIndex source_index = sourceModel()->index(sourceRow, 0);
+
+  Message::Flags flags = (Message::Flags)source_index.data(MessageModel::FlagsRole).toInt();
+  if(!(flags & Message::Backlog && flags & Message::Highlight))
+    return false;
+
+  BufferId bufferId = source_index.data(MessageModel::BufferIdRole).value<BufferId>();
+  if(!bufferId.isValid()) {
+    return false;
+  }
+
+  if(Client::networkModel()->lastSeenMsgId(bufferId) >= source_index.data(MessageModel::MsgIdRole).value<MsgId>())
+    return false;
+
+  return true;
+}
diff --git a/src/qtui/awaylogfilter.h b/src/qtui/awaylogfilter.h
new file mode 100644 (file)
index 0000000..bb80011
--- /dev/null
@@ -0,0 +1,36 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   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 AWAYLOGFILTER_H
+#define AWAYLOGFILTER_H
+
+#include "chatmonitorfilter.h"
+
+class AwayLogFilter : public ChatMonitorFilter {
+  Q_OBJECT
+
+public:
+  AwayLogFilter(MessageModel *model, QObject *parent = 0);
+
+  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+  virtual QString idString() const { return "AwayLog"; }
+};
+
+#endif //AWAYLOGFILTER_H
diff --git a/src/qtui/awaylogview.cpp b/src/qtui/awaylogview.cpp
new file mode 100644 (file)
index 0000000..cb26792
--- /dev/null
@@ -0,0 +1,53 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   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 "awaylogview.h"
+
+#include <QAction>
+#include <QMenu>
+
+#include "awaylogfilter.h"
+#include "chatlinemodel.h"
+#include "chatscene.h"
+
+AwayLogView::AwayLogView(AwayLogFilter *filter, QWidget *parent)
+  : ChatMonitorView(filter, parent)
+{
+}
+
+void AwayLogView::addActionsToMenu(QMenu *menu, const QPointF &pos) {
+  ChatView::addActionsToMenu(menu, pos);
+  if(!menu->isEmpty())
+    menu->addSeparator();
+
+  if(scene()->columnByScenePos(pos) == ChatLineModel::SenderColumn) {
+    menu->addSeparator();
+
+    QAction *showNetworkAction = menu->addAction(tr("Show Network Name"), this, SLOT(showFieldsChanged(bool)));
+    showNetworkAction->setCheckable(true);
+    showNetworkAction->setChecked(filter()->showFields() & ChatMonitorFilter::NetworkField);
+    showNetworkAction->setData(ChatMonitorFilter::NetworkField);
+
+    QAction *showBufferAction = menu->addAction(tr("Show Buffer Name"), this, SLOT(showFieldsChanged(bool)));
+    showBufferAction->setCheckable(true);
+    showBufferAction->setChecked(filter()->showFields() & ChatMonitorFilter::BufferField);
+    showBufferAction->setData(ChatMonitorFilter::BufferField);
+  }
+}
diff --git a/src/qtui/awaylogview.h b/src/qtui/awaylogview.h
new file mode 100644 (file)
index 0000000..542d8ea
--- /dev/null
@@ -0,0 +1,36 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   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 AWAYLOGVIEW_H
+#define AWAYLOGVIEW_H
+
+#include "chatmonitorview.h"
+
+class AwayLogFilter;
+
+class AwayLogView : public ChatMonitorView {
+  Q_OBJECT
+
+public:
+  AwayLogView(AwayLogFilter *filter, QWidget *parent = 0);
+  virtual void addActionsToMenu(QMenu *menu, const QPointF &pos);
+};
+
+#endif //AWAYLOGVIEW_H
index 06f1f15..f238f7b 100644 (file)
@@ -39,6 +39,9 @@ private slots:
   void showFieldsChanged(bool checked);
   void showSettingsPage();
 
+protected:
+  inline ChatMonitorFilter *filter() const { return _filter; }
+
 private:
   ChatMonitorFilter *_filter;
 };
index 10aedfa..555ac5d 100644 (file)
@@ -29,6 +29,8 @@
 #endif
 
 #include "aboutdlg.h"
+#include "awaylogfilter.h"
+#include "awaylogview.h"
 #include "action.h"
 #include "actioncollection.h"
 #include "buffermodel.h"
@@ -100,7 +102,8 @@ MainWin::MainWin(QWidget *parent)
     sslLabel(new QLabel()),
     msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
     _titleSetter(this),
-    _trayIcon(new QSystemTrayIcon(this))
+    _trayIcon(new QSystemTrayIcon(this)),
+    _awayLog(0)
 {
   QtUiSettings uiSettings;
   QString style = uiSettings.value("Style", QString()).toString();
@@ -222,7 +225,9 @@ void MainWin::setupActions() {
   connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
 
   coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
-                                                 0, 0, tr("Ctrl+F")))->setCheckable(true);
+                                               0, 0, tr("Ctrl+F")))->setCheckable(true);
+  coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
+                                           this, SLOT(showAwayLog())));
   coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
                                                  0, 0))->setCheckable(true);
 
@@ -270,6 +275,7 @@ void MainWin::setupMenus() {
   _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
   _viewMenu->addSeparator();
   _viewMenu->addAction(coll->action("ToggleSearchBar"));
+  _viewMenu->addAction(coll->action("ShowAwayLog"));
   _viewMenu->addAction(coll->action("ToggleStatusBar"));
   _viewMenu->addSeparator();
   _viewMenu->addAction(coll->action("LockDockPositions"));
@@ -652,6 +658,21 @@ void MainWin::showCoreInfoDlg() {
   CoreInfoDlg(this).exec();
 }
 
+void MainWin::showAwayLog() {
+  if(_awayLog)
+    return;
+  AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
+  _awayLog = new AwayLogView(filter, 0);
+  filter->setParent(_awayLog);
+  connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
+  _awayLog->setAttribute(Qt::WA_DeleteOnClose);
+  _awayLog->show();
+}
+
+void MainWin::awayLogDestroyed() {
+  _awayLog = 0;
+}
+
 void MainWin::showSettingsDlg() {
   SettingsDlg *dlg = new SettingsDlg();
 
index 682b37b..a4f6496 100644 (file)
@@ -92,6 +92,7 @@ class MainWin
 
   private slots:
     void addBufferView(int bufferViewConfigId);
+    void awayLogDestroyed();
     void removeBufferView(int bufferViewConfigId);
     void messagesInserted(const QModelIndex &parent, int start, int end);
     void showAboutDlg();
@@ -99,6 +100,7 @@ class MainWin
     void startInternalCore();
     void showCoreConnectionDlg(bool autoConnect = false);
     void showCoreInfoDlg();
+    void showAwayLog();
     void showSettingsDlg();
     void showNotificationsDlg();
 #ifdef HAVE_KDE
@@ -162,6 +164,7 @@ class MainWin
 
     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
 
+    QWidget *_awayLog;
     friend class QtUi;
 };