Making channel names clickable
[quassel.git] / src / uisupport / networkmodelactionprovider.cpp
index 44dd460..12fd2e4 100644 (file)
@@ -29,6 +29,7 @@
 #include "iconloader.h"
 #include "identity.h"
 #include "network.h"
+#include "util.h"
 
 NetworkModelActionProvider::NetworkModelActionProvider(QObject *parent)
 : AbstractActionProvider(parent),
@@ -67,9 +68,9 @@ NetworkModelActionProvider::NetworkModelActionProvider(QObject *parent)
   registerAction(NickDeop, tr("Take Operator Status"));
   registerAction(NickVoice, tr("Give Voice"));
   registerAction(NickDevoice, tr("Take Voice"));
-  registerAction(NickKick, tr("Kick"));
-  registerAction(NickBan, tr("Ban"));
-  registerAction(NickKickBan, tr("Kickban"));
+  registerAction(NickKick, tr("Kick From Channel"));
+  registerAction(NickBan, tr("Ban From Channel"));
+  registerAction(NickKickBan, tr("Kick && Ban"));
 
   registerAction(HideBufferTemporarily, tr("Hide Buffer(s) Temporarily"));
   registerAction(HideBufferPermanently, tr("Hide Buffer(s) Permanently"));
@@ -105,7 +106,11 @@ NetworkModelActionProvider::NetworkModelActionProvider(QObject *parent)
   nickModeMenu->addAction(action(NickDeop));
   nickModeMenu->addAction(action(NickVoice));
   nickModeMenu->addAction(action(NickDevoice));
-  _nickModeMenuAction = new Action(tr("Modes"), 0);
+  nickModeMenu->addSeparator();
+  nickModeMenu->addAction(action(NickKick));
+  nickModeMenu->addAction(action(NickBan));
+  nickModeMenu->addAction(action(NickKickBan));
+  _nickModeMenuAction = new Action(tr("Actions"), 0);
   _nickModeMenuAction->setMenu(nickModeMenu);
 }
 
@@ -203,13 +208,36 @@ void NetworkModelActionProvider::addActions(QMenu *menu,
     // ChatView actions
     if(_contextItem.isEmpty()) {
       // a) query buffer: handle like ircuser
-      // b) general chatview: only react if _contextItem is set (i.e. we right-clicked on something)
+      // b) general chatview: handle like channel iff it displays a single buffer
       // NOTE stuff breaks probably with merged buffers, need to rework a lot around here then
-      // for now, use the item type of a random buffer... assuming we never mix channel and query buffers
-      //if(!_messageFilter->containedBuffers.count())
-      //  return;
-      //BufferId randomBuf = _messageFilter->containedBuffers.values().at(0);
+      if(_messageFilter->containedBuffers().count() == 1) {
+        // we can handle this like a single bufferItem
+        QModelIndex index = Client::networkModel()->bufferIndex(_messageFilter->containedBuffers().values().at(0));
+        _indexList = QList<QModelIndex>() << index;
+        addBufferItemActions(menu, index);
+        return;
+      } else {
+        // TODO: actions for merged buffers... _indexList contains the index of the message we clicked on
 
+      }
+    } else {
+      // context item = chan or nick, _indexList = buf where the msg clicked on originated
+      if(isChannelName(_contextItem)) {
+        QModelIndex msgIdx = _indexList.at(0);
+        if(!msgIdx.isValid())
+          return;
+        NetworkId networkId = msgIdx.data(NetworkModel::NetworkIdRole).value<NetworkId>();
+        BufferId bufId = Client::networkModel()->bufferId(networkId, _contextItem);
+        if(bufId.isValid()) {
+          QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId);
+          _indexList = QList<QModelIndex>() << targetIdx;
+          addAction(BufferJoin, menu, targetIdx, InactiveState);
+          addAction(BufferSwitchTo, menu, targetIdx, ActiveState);
+        } else
+          addAction(JoinChannel, menu);
+      } else {
+        // TODO: actions for a nick
+      }
     }
   }
 }
@@ -502,6 +530,8 @@ void NetworkModelActionProvider::handleHideAction(ActionType type, QAction *acti
 }
 
 void NetworkModelActionProvider::handleGeneralAction(ActionType type, QAction *action) {
+  Q_UNUSED(action)
+
   if(!_indexList.count())
     return;
   NetworkId networkId = _indexList.at(0).data(NetworkModel::NetworkIdRole).value<NetworkId>();
@@ -509,17 +539,17 @@ void NetworkModelActionProvider::handleGeneralAction(ActionType type, QAction *a
     return;
 
   switch(type) {
-    case JoinChannel:
-    {
-    //  FIXME no QInputDialog in Qtopia
-#   ifndef Q_WS_QWS
-      bool ok;
-      QString channelName = QInputDialog::getText(0, tr("Join Channel"), tr("Input channel name:"), QLineEdit::Normal, QString(), &ok);
-      if(ok && !channelName.isEmpty()) {
-        Client::instance()->userInput(BufferInfo::fakeStatusBuffer(networkId),
-                                      QString("/JOIN %1").arg(channelName));
+    case JoinChannel: {
+      QString channelName = _contextItem;
+      if(channelName.isEmpty()) {
+        bool ok;
+        channelName = QInputDialog::getText(0, tr("Join Channel"), tr("Input channel name:"), QLineEdit::Normal, QString(), &ok);
+        if(!ok)
+          return;
+      }
+      if(!channelName.isEmpty()) {
+        Client::instance()->userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(channelName));
       }
-#   endif
       break;
     }
     case ShowChannelList: