Store the type of the current tab completion (user or channel) in the TabCompleter...
authorHendrik Leppkes <h.leppkes@gmail.com>
Mon, 1 Feb 2010 22:01:05 +0000 (23:01 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 14 Feb 2010 19:24:31 +0000 (20:24 +0100)
src/uisupport/tabcompleter.cpp
src/uisupport/tabcompleter.h

index 751385a..7426ed4 100644 (file)
@@ -34,6 +34,7 @@
 const Network *TabCompleter::_currentNetwork;
 BufferId TabCompleter::_currentBufferId;
 QString TabCompleter::_currentBufferName;
 const Network *TabCompleter::_currentNetwork;
 BufferId TabCompleter::_currentBufferId;
 QString TabCompleter::_currentBufferName;
+TabCompleter::Type TabCompleter::_completionType;
 
 TabCompleter::TabCompleter(MultiLineEdit *_lineEdit)
   : QObject(_lineEdit),
 
 TabCompleter::TabCompleter(MultiLineEdit *_lineEdit)
   : QObject(_lineEdit),
@@ -70,7 +71,7 @@ void TabCompleter::buildCompletionList() {
     _completionType = ChannelTab;
     foreach(IrcChannel *ircChannel, _currentNetwork->ircChannels()) {
       if(regex.indexIn(ircChannel->name()) > -1)
     _completionType = ChannelTab;
     foreach(IrcChannel *ircChannel, _currentNetwork->ircChannels()) {
       if(regex.indexIn(ircChannel->name()) > -1)
-        _completionMap[CompletionKey(ircChannel->name(), ChannelTab)] = ircChannel->name();
+        _completionMap[ircChannel->name()] = ircChannel->name();
     }
   } else {
     // user completion
     }
   } else {
     // user completion
@@ -83,16 +84,16 @@ void TabCompleter::buildCompletionList() {
           return;
         foreach(IrcUser *ircUser, channel->ircUsers()) {
           if(regex.indexIn(ircUser->nick()) > -1)
           return;
         foreach(IrcUser *ircUser, channel->ircUsers()) {
           if(regex.indexIn(ircUser->nick()) > -1)
-            _completionMap[CompletionKey(ircUser->nick().toLower(), UserTab)] = ircUser->nick();
+            _completionMap[ircUser->nick().toLower()] = ircUser->nick();
         }
       }
       break;
     case BufferInfo::QueryBuffer:
       if(regex.indexIn(_currentBufferName) > -1)
         }
       }
       break;
     case BufferInfo::QueryBuffer:
       if(regex.indexIn(_currentBufferName) > -1)
-        _completionMap[CompletionKey(_currentBufferName.toLower(), UserTab)] = _currentBufferName;
+        _completionMap[_currentBufferName.toLower()] = _currentBufferName;
     case BufferInfo::StatusBuffer:
       if(!_currentNetwork->myNick().isEmpty() && regex.indexIn(_currentNetwork->myNick()) > -1)
     case BufferInfo::StatusBuffer:
       if(!_currentNetwork->myNick().isEmpty() && regex.indexIn(_currentNetwork->myNick()) > -1)
-        _completionMap[CompletionKey(_currentNetwork->myNick().toLower(), UserTab)] = _currentNetwork->myNick();
+        _completionMap[_currentNetwork->myNick().toLower()] = _currentNetwork->myNick();
       break;
     default:
       return;
       break;
     default:
       return;
@@ -161,7 +162,7 @@ bool TabCompleter::eventFilter(QObject *obj, QEvent *event) {
 
 // this determines the sort order
 bool TabCompleter::CompletionKey::operator<(const CompletionKey &other) const {
 
 // this determines the sort order
 bool TabCompleter::CompletionKey::operator<(const CompletionKey &other) const {
-  switch(this->type) {
+  switch(_completionType) {
     case UserTab:
       {
         IrcUser *thisUser = _currentNetwork->ircUser(this->contents);
     case UserTab:
       {
         IrcUser *thisUser = _currentNetwork->ircUser(this->contents);
index bb5c0b3..b8461ee 100644 (file)
@@ -35,6 +35,11 @@ class TabCompleter : public QObject {
   Q_OBJECT
 
 public:
   Q_OBJECT
 
 public:
+  enum Type {
+    UserTab = 0x01,
+    ChannelTab = 0x02
+  };
+
   explicit TabCompleter(MultiLineEdit *inputLine_);
 
   void reset();
   explicit TabCompleter(MultiLineEdit *inputLine_);
 
   void reset();
@@ -43,15 +48,10 @@ public:
   virtual bool eventFilter(QObject *obj, QEvent *event);
 
 private:
   virtual bool eventFilter(QObject *obj, QEvent *event);
 
 private:
-  enum Type {
-    UserTab = 0x01,
-    ChannelTab = 0x02
-  };
 
   struct CompletionKey {
 
   struct CompletionKey {
-    inline CompletionKey(const QString &n, const Type t) { contents = n; type = t; }
+    inline CompletionKey(const QString &n) { contents = n; }
     bool operator<(const CompletionKey &other) const;
     bool operator<(const CompletionKey &other) const;
-    Type type;
     QString contents;
   };
 
     QString contents;
   };
 
@@ -62,11 +62,11 @@ private:
   static const Network *_currentNetwork;
   static BufferId _currentBufferId;
   static QString _currentBufferName;
   static const Network *_currentNetwork;
   static BufferId _currentBufferId;
   static QString _currentBufferName;
+  static Type _completionType;
 
   QMap<CompletionKey, QString> _completionMap;
   // QStringList completionTemplates;
 
 
   QMap<CompletionKey, QString> _completionMap;
   // QStringList completionTemplates;
 
-  Type _completionType;
   QMap<CompletionKey, QString>::Iterator _nextCompletion;
   int _lastCompletionLength;
 
   QMap<CompletionKey, QString>::Iterator _nextCompletion;
   int _lastCompletionLength;