improving the channel lists. errors are redirected to the channel widget and act...
authorMarcus Eggenberger <egs@quassel-irc.org>
Thu, 24 Jul 2008 13:38:22 +0000 (15:38 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Thu, 24 Jul 2008 13:40:20 +0000 (15:40 +0200)
src/common/irclisthelper.h
src/core/coreirclisthelper.cpp
src/core/coreirclisthelper.h
src/core/ircserverhandler.cpp
src/qtui/channellistdlg.cpp
src/qtui/channellistdlg.h
src/qtui/ui/channellistdlg.ui

index 0d8ad39..e62fda1 100644 (file)
@@ -49,10 +49,12 @@ public slots:
   inline virtual QVariantList requestChannelList(const NetworkId &netId, const QStringList &channelFilters) { emit channelListRequested(netId, channelFilters); return QVariantList(); }
   inline virtual void receiveChannelList(const NetworkId &, const QStringList &, const QVariantList &) {};
   inline virtual void reportFinishedList(const NetworkId &netId) { emit finishedListReported(netId); }
   inline virtual QVariantList requestChannelList(const NetworkId &netId, const QStringList &channelFilters) { emit channelListRequested(netId, channelFilters); return QVariantList(); }
   inline virtual void receiveChannelList(const NetworkId &, const QStringList &, const QVariantList &) {};
   inline virtual void reportFinishedList(const NetworkId &netId) { emit finishedListReported(netId); }
+  inline virtual void reportError(const QString &error) { emit errorReported(error); }
 
 signals:
   void channelListRequested(const NetworkId &netId, const QStringList &channelFilters);
   void finishedListReported(const NetworkId &netId);
 
 signals:
   void channelListRequested(const NetworkId &netId, const QStringList &channelFilters);
   void finishedListReported(const NetworkId &netId);
+  void errorReported(const QString &error);
 };
 
 #endif //IRCLISTHELPER_H
 };
 
 #endif //IRCLISTHELPER_H
index d8a317c..dbcdcc4 100644 (file)
@@ -23,7 +23,6 @@
 #include "networkconnection.h"
 #include "userinputhandler.h"
 
 #include "networkconnection.h"
 #include "userinputhandler.h"
 
-
 QVariantList CoreIrcListHelper::requestChannelList(const NetworkId &netId, const QStringList &channelFilters) {
   if(_finishedChannelLists.contains(netId))
     return _finishedChannelLists.take(netId);
 QVariantList CoreIrcListHelper::requestChannelList(const NetworkId &netId, const QStringList &channelFilters) {
   if(_finishedChannelLists.contains(netId))
     return _finishedChannelLists.take(netId);
@@ -31,13 +30,8 @@ QVariantList CoreIrcListHelper::requestChannelList(const NetworkId &netId, const
   if(_channelLists.contains(netId)) {
     _queuedQuery[netId] = channelFilters.join(",");
   } else {
   if(_channelLists.contains(netId)) {
     _queuedQuery[netId] = channelFilters.join(",");
   } else {
-    _channelLists[netId] = QList<ChannelDescription>();
-
-    NetworkConnection *networkConnection = coreSession()->networkConnection(netId);
-    if(networkConnection)
-      networkConnection->userInputHandler()->handleList(BufferInfo(), channelFilters.join(","));
+    dispatchQuery(netId, channelFilters.join(","));
   }
   }
-
   return QVariantList();
 }
 
   return QVariantList();
 }
 
@@ -49,17 +43,22 @@ bool CoreIrcListHelper::addChannel(const NetworkId &netId, const QString &channe
   return true;
 }
 
   return true;
 }
 
+bool CoreIrcListHelper::dispatchQuery(const NetworkId &netId, const QString &query) {
+  NetworkConnection *networkConnection = coreSession()->networkConnection(netId);
+  if(networkConnection) {
+    _channelLists[netId] = QList<ChannelDescription>();
+    networkConnection->userInputHandler()->handleList(BufferInfo(), query);
+    _queryTimeout[startTimer(10000)] = netId;
+    return true;
+  } else {
+    return false;
+  }
+}
+
 bool CoreIrcListHelper::endOfChannelList(const NetworkId &netId) {
   if(_queuedQuery.contains(netId)) {
     // we're no longer interessted in the current data. drop it and issue a new request.
 bool CoreIrcListHelper::endOfChannelList(const NetworkId &netId) {
   if(_queuedQuery.contains(netId)) {
     // we're no longer interessted in the current data. drop it and issue a new request.
-    _channelLists[netId] = QList<ChannelDescription>();
-    
-    NetworkConnection *networkConnection = coreSession()->networkConnection(netId);
-    if(networkConnection)
-      networkConnection->userInputHandler()->handleList(BufferInfo(), _queuedQuery[netId]);
-
-    _queuedQuery.remove(netId);
-    return true;
+    return dispatchQuery(netId, _queuedQuery.take(netId));
   } else if(_channelLists.contains(netId)) {
     QVariantList channelList;
     foreach(ChannelDescription channel, _channelLists[netId]) {
   } else if(_channelLists.contains(netId)) {
     QVariantList channelList;
     foreach(ChannelDescription channel, _channelLists[netId]) {
@@ -78,3 +77,9 @@ bool CoreIrcListHelper::endOfChannelList(const NetworkId &netId) {
   }
 }
 
   }
 }
 
+void CoreIrcListHelper::timerEvent(QTimerEvent *event) {
+  int timerId = event->timerId();
+  killTimer(timerId);
+  NetworkId netId = _queryTimeout.take(timerId);
+  endOfChannelList(netId);
+}
index 84303ad..c42d6a0 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "coresession.h"
 
 
 #include "coresession.h"
 
+class QTimerEvent;
+
 class CoreIrcListHelper : public IrcListHelper {
   Q_OBJECT
 
 class CoreIrcListHelper : public IrcListHelper {
   Q_OBJECT
 
@@ -35,17 +37,26 @@ public:
 
   inline CoreSession *coreSession() const { return _coreSession; }
 
 
   inline CoreSession *coreSession() const { return _coreSession; }
 
+  inline bool requestInProgress(const NetworkId &netId) const { return _channelLists.contains(netId); }
+
 public slots:
   virtual QVariantList requestChannelList(const NetworkId &netId, const QStringList &channelFilters);
   bool addChannel(const NetworkId &netId, const QString &channelName, quint32 userCount, const QString &topic);
   bool endOfChannelList(const NetworkId &netId);
 
 public slots:
   virtual QVariantList requestChannelList(const NetworkId &netId, const QStringList &channelFilters);
   bool addChannel(const NetworkId &netId, const QString &channelName, quint32 userCount, const QString &topic);
   bool endOfChannelList(const NetworkId &netId);
 
+protected:
+  void timerEvent(QTimerEvent *event);
+
+private:
+  bool dispatchQuery(const NetworkId &netId, const QString &query);
+
 private:
   CoreSession *_coreSession;
 
   QHash<NetworkId, QString> _queuedQuery;
   QHash<NetworkId, QList<ChannelDescription> > _channelLists;
   QHash<NetworkId, QVariantList> _finishedChannelLists;
 private:
   CoreSession *_coreSession;
 
   QHash<NetworkId, QString> _queuedQuery;
   QHash<NetworkId, QList<ChannelDescription> > _channelLists;
   QHash<NetworkId, QVariantList> _finishedChannelLists;
+  QHash<int, NetworkId> _queryTimeout;
 };
 
 #endif //COREIRCLISTHELPER_H
 };
 
 #endif //COREIRCLISTHELPER_H
index ae7736d..ec3789d 100644 (file)
@@ -153,7 +153,10 @@ void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const
          // many nets define their own WHOIS fields. we fetch those not in need of special attention here:
          emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", "[Whois] " + params.join(" "), prefix);
        } else {
          // many nets define their own WHOIS fields. we fetch those not in need of special attention here:
          emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", "[Whois] " + params.join(" "), prefix);
        } else {
-         emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", cmd + " " + params.join(" "), prefix);
+         if(networkConnection()->coreSession()->ircListHelper()->requestInProgress(network()->networkId()))
+           networkConnection()->coreSession()->ircListHelper()->reportError(params.join(" "));
+         else
+           emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", cmd + " " + params.join(" "), prefix);
        }
     }
     //qDebug() << prefix <<":"<<cmd<<params;
        }
     }
     //qDebug() << prefix <<":"<<cmd<<params;
index 4165c81..093ec22 100644 (file)
 #include "clientirclisthelper.h"
 
 #include <QHeaderView>
 #include "clientirclisthelper.h"
 
 #include <QHeaderView>
+#include <QHBoxLayout>
+#include <QSpacerItem>
 
 ChannelListDlg::ChannelListDlg(QWidget *parent)
   : QDialog(parent),
     _listFinished(true),
     _ircListModel(this),
 
 ChannelListDlg::ChannelListDlg(QWidget *parent)
   : QDialog(parent),
     _listFinished(true),
     _ircListModel(this),
-    _sortFilter(this)
+    _sortFilter(this),
+    _simpleModeSpacer(0),
+    _advancedMode(false)
 {
   _sortFilter.setSourceModel(&_ircListModel);
   _sortFilter.setFilterCaseSensitivity(Qt::CaseInsensitive);
 {
   _sortFilter.setSourceModel(&_ircListModel);
   _sortFilter.setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -47,19 +51,22 @@ ChannelListDlg::ChannelListDlg(QWidget *parent)
 
   ui.searchChannelsButton->setAutoDefault(false);
 
 
   ui.searchChannelsButton->setAutoDefault(false);
 
+  connect(ui.advancedModeLabel, SIGNAL(clicked()), this, SLOT(toggleMode()));
   connect(ui.searchChannelsButton, SIGNAL(clicked()), this, SLOT(requestSearch()));
   connect(ui.channelNameLineEdit, SIGNAL(returnPressed()), this, SLOT(requestSearch()));
   connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), &_sortFilter, SLOT(setFilterFixedString(QString)));
   connect(Client::ircListHelper(), SIGNAL(channelListReceived(const NetworkId &, const QStringList &, QList<IrcListHelper::ChannelDescription>)),
          this, SLOT(receiveChannelList(NetworkId , QStringList, QList<IrcListHelper::ChannelDescription>)));
   connect(Client::ircListHelper(), SIGNAL(finishedListReported(const NetworkId &)), this, SLOT(reportFinishedList()));
   connect(ui.searchChannelsButton, SIGNAL(clicked()), this, SLOT(requestSearch()));
   connect(ui.channelNameLineEdit, SIGNAL(returnPressed()), this, SLOT(requestSearch()));
   connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), &_sortFilter, SLOT(setFilterFixedString(QString)));
   connect(Client::ircListHelper(), SIGNAL(channelListReceived(const NetworkId &, const QStringList &, QList<IrcListHelper::ChannelDescription>)),
          this, SLOT(receiveChannelList(NetworkId , QStringList, QList<IrcListHelper::ChannelDescription>)));
   connect(Client::ircListHelper(), SIGNAL(finishedListReported(const NetworkId &)), this, SLOT(reportFinishedList()));
+  connect(Client::ircListHelper(), SIGNAL(errorReported(const QString &)), this, SLOT(showError(const QString &)));
   connect(ui.channelListView, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
 
   connect(ui.channelListView, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
 
+  setAdvancedMode(false);
   enableQuery(true);
   showFilterLine(false);
   enableQuery(true);
   showFilterLine(false);
+  showErrors(false);
 }
 
 }
 
-
 void ChannelListDlg::setNetwork(NetworkId netId) {
   if(_netId == netId)
     return;
 void ChannelListDlg::setNetwork(NetworkId netId) {
   if(_netId == netId)
     return;
@@ -72,6 +79,7 @@ void ChannelListDlg::setNetwork(NetworkId netId) {
 void ChannelListDlg::requestSearch() {
   _listFinished = false;
   enableQuery(false);
 void ChannelListDlg::requestSearch() {
   _listFinished = false;
   enableQuery(false);
+  showErrors(false);
   QStringList channelFilters;
   channelFilters << ui.channelNameLineEdit->text().trimmed();
   Client::ircListHelper()->requestChannelList(_netId, channelFilters);
   QStringList channelFilters;
   channelFilters << ui.channelNameLineEdit->text().trimmed();
   Client::ircListHelper()->requestChannelList(_netId, channelFilters);
@@ -97,10 +105,45 @@ void ChannelListDlg::enableQuery(bool enable) {
   ui.searchChannelsButton->setEnabled(enable);
 }
 
   ui.searchChannelsButton->setEnabled(enable);
 }
 
+void ChannelListDlg::setAdvancedMode(bool advanced) {
+  _advancedMode = advanced;
+  if(advanced) {
+    if(_simpleModeSpacer) {
+      ui.searchLayout->removeItem(_simpleModeSpacer);
+      delete _simpleModeSpacer;
+      _simpleModeSpacer = 0;
+    }
+    ui.advancedModeLabel->setPixmap(QPixmap(QString::fromUtf8(":/22x22/actions/oxygen/22x22/actions/edit-clear-locationbar-rtl.png")));
+  } else {
+    if(!_simpleModeSpacer) {
+      _simpleModeSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+      ui.searchLayout->insertSpacerItem(0, _simpleModeSpacer);
+    }
+    ui.advancedModeLabel->setPixmap(QPixmap(QString::fromUtf8(":/22x22/actions/oxygen/22x22/actions/edit-clear.png")));
+  }
+  ui.channelNameLineEdit->clear();
+  ui.channelNameLineEdit->setVisible(advanced);
+  ui.searchPatternLabel->setVisible(advanced);
+}
+
+void ChannelListDlg::showErrors(bool show) {
+  if(!show) {
+    ui.errorTextEdit->clear();
+  }
+  ui.errorLabel->setVisible(show);
+  ui.errorTextEdit->setVisible(show);
+}
+
+
 void ChannelListDlg::reportFinishedList() {
   _listFinished = true;
 }
 
 void ChannelListDlg::reportFinishedList() {
   _listFinished = true;
 }
 
+void ChannelListDlg::showError(const QString &error) {
+  showErrors(true);
+  ui.errorTextEdit->moveCursor(QTextCursor::End);
+  ui.errorTextEdit->insertPlainText(error + "\n");
+}
 
 void ChannelListDlg::joinChannel(const QModelIndex &index) {
   Client::instance()->userInput(BufferInfo::fakeStatusBuffer(_netId), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));
 
 void ChannelListDlg::joinChannel(const QModelIndex &index) {
   Client::instance()->userInput(BufferInfo::fakeStatusBuffer(_netId), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));
index 84e5b7a..dddd88e 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <QSortFilterProxyModel>
 
 
 #include <QSortFilterProxyModel>
 
+class QSpacerItem;
+
 class ChannelListDlg : public QDialog {
   Q_OBJECT
 
 class ChannelListDlg : public QDialog {
   Q_OBJECT
 
@@ -42,10 +44,16 @@ protected slots:
   void receiveChannelList(const NetworkId &netId, const QStringList &channelFilters, const QList<IrcListHelper::ChannelDescription> &channelList);
   void reportFinishedList();
   void joinChannel(const QModelIndex &);
   void receiveChannelList(const NetworkId &netId, const QStringList &channelFilters, const QList<IrcListHelper::ChannelDescription> &channelList);
   void reportFinishedList();
   void joinChannel(const QModelIndex &);
-  
+
+private slots:
+  inline void toggleMode() { setAdvancedMode(!_advancedMode); }
+  void showError(const QString &error);
+
 private:
   void showFilterLine(bool show);
 private:
   void showFilterLine(bool show);
+  void showErrors(bool show);
   void enableQuery(bool enable);
   void enableQuery(bool enable);
+  void setAdvancedMode(bool advanced);
 
   Ui::ChannelListDlg ui;
 
 
   Ui::ChannelListDlg ui;
 
@@ -53,6 +61,8 @@ private:
   NetworkId _netId;
   IrcListModel _ircListModel;
   QSortFilterProxyModel _sortFilter;
   NetworkId _netId;
   IrcListModel _ircListModel;
   QSortFilterProxyModel _sortFilter;
+  QSpacerItem *_simpleModeSpacer;
+  bool _advancedMode;
 };
 
 #endif //CHANNELLIST_H
 };
 
 #endif //CHANNELLIST_H
index 70c3c21..8b12aef 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>454</width>
-    <height>406</height>
+    <width>566</width>
+    <height>580</height>
    </rect>
   </property>
   <property name="windowTitle" >
    </rect>
   </property>
   <property name="windowTitle" >
@@ -24,7 +24,7 @@
     <number>0</number>
    </property>
    <item>
     <number>0</number>
    </property>
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout" >
+    <layout class="QHBoxLayout" name="searchLayout" >
      <property name="spacing" >
       <number>6</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
@@ -32,7 +32,7 @@
       <number>6</number>
      </property>
      <item>
       <number>6</number>
      </property>
      <item>
-      <widget class="QLabel" name="label" >
+      <widget class="QLabel" name="searchPatternLabel" >
        <property name="text" >
         <string>Search Pattern:</string>
        </property>
        <property name="text" >
         <string>Search Pattern:</string>
        </property>
      <item>
       <widget class="QLineEdit" name="channelNameLineEdit" />
      </item>
      <item>
       <widget class="QLineEdit" name="channelNameLineEdit" />
      </item>
+     <item>
+      <widget class="ClickableLabel" name="advancedModeLabel" >
+       <property name="toolTip" >
+        <string>Toggle between simple and advanced mode.
+Advanced mode allows to pass search strings to the IRC Server.</string>
+       </property>
+       <property name="text" >
+        <string/>
+       </property>
+       <property name="pixmap" >
+        <pixmap resource="../../icons/icons.qrc" >:/22x22/actions/oxygen/22x22/actions/edit-clear-locationbar-rtl.png</pixmap>
+       </property>
+      </widget>
+     </item>
      <item>
       <widget class="QPushButton" name="searchChannelsButton" >
        <property name="text" >
      <item>
       <widget class="QPushButton" name="searchChannelsButton" >
        <property name="text" >
-        <string>Search Channels</string>
+        <string>Show Channels</string>
        </property>
       </widget>
      </item>
        </property>
       </widget>
      </item>
     </layout>
    </item>
    <item>
     </layout>
    </item>
    <item>
-    <widget class="QTableView" name="channelListView" />
+    <widget class="QLabel" name="errorLabel" >
+     <property name="text" >
+      <string>Errors Occured:</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QTextEdit" name="errorTextEdit" >
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="minimumSize" >
+      <size>
+       <width>0</width>
+       <height>0</height>
+      </size>
+     </property>
+     <property name="maximumSize" >
+      <size>
+       <width>16777215</width>
+       <height>100</height>
+      </size>
+     </property>
+     <property name="acceptDrops" >
+      <bool>false</bool>
+     </property>
+     <property name="undoRedoEnabled" >
+      <bool>false</bool>
+     </property>
+     <property name="readOnly" >
+      <bool>true</bool>
+     </property>
+     <property name="html" >
+      <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">SUPER EVIL CATASTROPHIC ERROR!!11&lt;/p>
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QTableView" name="channelListView" >
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
    </item>
   </layout>
  </widget>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ClickableLabel</class>
+   <extends>QLabel</extends>
+   <header location="global" >clickablelabel.h</header>
+  </customwidget>
+ </customwidgets>
  <resources>
   <include location="../../icons/icons.qrc" />
  </resources>
  <resources>
   <include location="../../icons/icons.qrc" />
  </resources>