- small tweak to tabcompletion
authorMarcus Eggenberger <egs@quassel-irc.org>
Thu, 17 May 2007 16:44:32 +0000 (16:44 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Thu, 17 May 2007 16:44:32 +0000 (16:44 +0000)
- doubleclick on channel now joins the channel

core/server.cpp
gui/channelwidgetinput.cpp
gui/networkview.cpp
gui/networkview.h
gui/tabcompleter.cpp
gui/tabcompleter.h

index 442fe0f..df7b576 100644 (file)
@@ -726,7 +726,6 @@ void Server::handleServer432(QString prefix, QStringList params) {
 
 /* ERR_NICKNAMEINUSE */
 void Server::handleServer433(QString prefix, QStringList params) {
 
 /* ERR_NICKNAMEINUSE */
 void Server::handleServer433(QString prefix, QStringList params) {
-  qDebug() << "433:" << params;
   QString errnick = params[0];
   emit displayMsg(Message::Error, "", tr("Nick %1 is already taken").arg(errnick));
   // if there is a problem while connecting to the server -> we handle it
   QString errnick = params[0];
   emit displayMsg(Message::Error, "", tr("Nick %1 is already taken").arg(errnick));
   // if there is a problem while connecting to the server -> we handle it
index 813d1c8..c4d1a06 100644 (file)
@@ -32,13 +32,9 @@ ChannelWidgetInput::~ChannelWidgetInput() {
 }
 
 void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) {
 }
 
 void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) {
-  if(event->key() == Qt::Key_Tab) {
-    // Tabcomplete
-    if(text().length() > 0) {
-      tabComplete->complete();
-    }
+  if(event->key() == Qt::Key_Tab) { // Tabcomplete
+    tabComplete->complete();
     event->accept();
     event->accept();
-    
   } else {
     tabComplete->disable();
     if(event->key() == Qt::Key_Up) {
   } else {
     tabComplete->disable();
     if(event->key() == Qt::Key_Up) {
index c97e288..e9f1bd6 100644 (file)
@@ -46,6 +46,9 @@ NetworkView::NetworkView(QString n, int m, QStringList nets, QWidget *parent) :
   tree->header()->hide();
   tree->setSortingEnabled(true);
   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(itemClicked(QTreeWidgetItem*)));
   tree->header()->hide();
   tree->setSortingEnabled(true);
   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(itemClicked(QTreeWidgetItem*)));
+  connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*)));
+  connect(this, SIGNAL(fakeUserInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString)));
+  
 }
 
 void NetworkView::setBuffers(QList<Buffer *> buffers) {
 }
 
 void NetworkView::setBuffers(QList<Buffer *> buffers) {
@@ -127,6 +130,15 @@ void NetworkView::itemClicked(QTreeWidgetItem *item) {
   }
 }
 
   }
 }
 
+void NetworkView::itemDoubleClicked(QTreeWidgetItem *item) {
+  Buffer *b = bufitems.key(item);
+  if(b) {
+    if(Buffer::ChannelBuffer == b->bufferType()) {
+      emit fakeUserInput(b->bufferId(), QString("/join " + b->bufferName()));
+    }
+  }
+}
+
 void NetworkView::selectBuffer(Buffer *b) {
   QTreeWidgetItem *item = 0;
   if(bufitems.contains(b)) item = bufitems[b];
 void NetworkView::selectBuffer(Buffer *b) {
   QTreeWidgetItem *item = 0;
   if(bufitems.contains(b)) item = bufitems[b];
index 2ed94b6..f6842b6 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <QtGui>
 #include "ui_networkview.h"
 
 #include <QtGui>
 #include "ui_networkview.h"
+#include "guiproxy.h"
 #include "buffer.h"
 
 typedef QHash<QString, QHash<QString, Buffer*> > BufferHash;
 #include "buffer.h"
 
 typedef QHash<QString, QHash<QString, Buffer*> > BufferHash;
@@ -71,10 +72,12 @@ class NetworkView : public QDockWidget {
 
   signals:
     void bufferSelected(Buffer *);
 
   signals:
     void bufferSelected(Buffer *);
-
+    void fakeUserInput(BufferId, QString);
+    
   private slots:
     void itemClicked(QTreeWidgetItem *item);
   private slots:
     void itemClicked(QTreeWidgetItem *item);
-
+    void itemDoubleClicked(QTreeWidgetItem *item);
+    
   private:
     int mode;
     QString name;
   private:
     int mode;
     QString name;
index c9a7860..5b3e97f 100644 (file)
@@ -23,6 +23,7 @@
 TabCompleter::TabCompleter(QLineEdit *l, QObject *parent) : QObject(parent) {
   lineEdit = l;
   enabled = false;
 TabCompleter::TabCompleter(QLineEdit *l, QObject *parent) : QObject(parent) {
   lineEdit = l;
   enabled = false;
+  startOfLineSuffix = QString(": "); // TODO make start of line suffix configurable
 }
 
 void TabCompleter::updateNickList(QStringList l) {
 }
 
 void TabCompleter::updateNickList(QStringList l) {
@@ -30,7 +31,7 @@ void TabCompleter::updateNickList(QStringList l) {
 }
 
 void TabCompleter::updateChannelList(QStringList l) {
 }
 
 void TabCompleter::updateChannelList(QStringList l) {
-
+  channelList = l;
 }
 
 void TabCompleter::buildCompletionList() {
 }
 
 void TabCompleter::buildCompletionList() {
@@ -58,10 +59,22 @@ void TabCompleter::complete() {
     for (int i = 0; i < lastCompletionLength; i++) {
       lineEdit->backspace();
     }
     for (int i = 0; i < lastCompletionLength; i++) {
       lineEdit->backspace();
     }
-    lineEdit->insert(*nextCompletion + ' ');
-    lastCompletionLength = nextCompletion->length() + 1;
+    
+    // insert completion
+    lineEdit->insert(*nextCompletion);
+    
+    // remember charcount to delete next time and advance to next completion
+    lastCompletionLength = nextCompletion->length();
     nextCompletion++;
     nextCompletion++;
-  } else if (completionList.begin() != completionList.end()) {
+    
+    // we're completing the first word of the line
+    if(lineEdit->text().length() == lastCompletionLength) {
+      lineEdit->insert(startOfLineSuffix);
+      lastCompletionLength += 2;
+    }
+
+  // we're at the end of the list -> start over again
+  } else {
     nextCompletion = completionList.begin();
   }
   
     nextCompletion = completionList.begin();
   }
   
index b6d9db3..c8a75f7 100644 (file)
@@ -38,17 +38,17 @@ class TabCompleter : public QObject {
     void updateChannelList(QStringList);
     
   private:
     void updateChannelList(QStringList);
     
   private:
+    bool enabled;
+    QString startOfLineSuffix;
     QLineEdit *lineEdit;
     QStringList completionTemplates;
     QLineEdit *lineEdit;
     QStringList completionTemplates;
-    QStringList nickList;
     QStringList channelList;
     QStringList channelList;
-    int lastCompletionLength;
-    bool enabled;
-      
 
 
+    QStringList nickList;
     QStringList completionList;
     QStringList::Iterator nextCompletion;
     QStringList completionList;
     QStringList::Iterator nextCompletion;
-    
+    int lastCompletionLength;
+        
     void buildCompletionList();
     
 };
     void buildCompletionList();
     
 };