Making channel names clickable
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 14 Dec 2008 00:03:12 +0000 (01:03 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 14 Dec 2008 00:03:12 +0000 (01:03 +0100)
Add a context menu for #channelnames in a ChatView.
Also clean up NetworkModel's #includes...

src/client/networkmodel.h
src/qtui/chatitem.cpp
src/uisupport/networkmodelactionprovider.cpp

index 807403e..6fd078e 100644 (file)
 #ifndef NETWORKMODEL_H
 #define NETWORKMODEL_H
 
 #ifndef NETWORKMODEL_H
 #define NETWORKMODEL_H
 
-#include <QtCore>
-
-#include "treemodel.h"
 #include "bufferinfo.h"
 #include "bufferinfo.h"
-
-#include <QPointer>
-
-class BufferInfo;
-
-#include "selectionmodelsynchronizer.h"
-#include "modelpropertymapper.h"
 #include "clientsettings.h"
 #include "clientsettings.h"
-#include "ircchannel.h"
-#include "ircuser.h"
 #include "message.h"
 #include "network.h"
 #include "message.h"
 #include "network.h"
+#include "treemodel.h"
 
 
-class MappedSelectionModel;
-class QAbstractItemView;
 class BufferItem;
 
 /*****************************************
 class BufferItem;
 
 /*****************************************
index a5eae80..be792c9 100644 (file)
@@ -509,7 +509,7 @@ void ContentsChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clic
         case Clickable::Url:
           if(!str.contains("://"))
             str = "http://" + str;
         case Clickable::Url:
           if(!str.contains("://"))
             str = "http://" + str;
-         QDesktopServices::openUrl(QUrl::fromEncoded(str.toUtf8(), QUrl::TolerantMode));
+          QDesktopServices::openUrl(QUrl::fromEncoded(str.toUtf8(), QUrl::TolerantMode));
           break;
         case Clickable::Channel:
           // TODO join or whatever...
           break;
         case Clickable::Channel:
           // TODO join or whatever...
@@ -561,8 +561,11 @@ void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
       onClickable = true;
       showWebPreview(click);
     } else if(click.type == Clickable::Channel) {
       onClickable = true;
       showWebPreview(click);
     } else if(click.type == Clickable::Channel) {
-      // TODO: don't make clickable if it's our own name
-      // onClickable = true; //FIXME disabled for now
+      // don't make clickable if it's our own name
+      QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+      BufferId myId = data(MessageModel::BufferIdRole).value<BufferId>();
+      if(Client::networkModel()->bufferName(myId) != name)
+        onClickable = true;
     }
     if(onClickable) {
       setCursor(Qt::PointingHandCursor);
     }
     if(onClickable) {
       setCursor(Qt::PointingHandCursor);
@@ -579,13 +582,21 @@ void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) {
   Q_UNUSED(pos); // we assume that the current mouse cursor pos is the point of invocation
 
   if(privateData()->currentClickable.isValid()) {
   Q_UNUSED(pos); // we assume that the current mouse cursor pos is the point of invocation
 
   if(privateData()->currentClickable.isValid()) {
-    switch(privateData()->currentClickable.type) {
+    Clickable click = privateData()->currentClickable;
+    switch(click.type) {
       case Clickable::Url:
       case Clickable::Url:
-        privateData()->activeClickable = privateData()->currentClickable;
+        privateData()->activeClickable = click;
         menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"),
                          &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
         break;
         menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"),
                          &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
         break;
-
+      case Clickable::Channel: {
+        // Hide existing menu actions, they confuse us when right-clicking on a clickable
+        foreach(QAction *action, menu->actions())
+          action->setVisible(false);
+        QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+        Client::mainUi()->actionProvider()->addActions(menu, chatScene()->filter(), data(MessageModel::BufferIdRole).value<BufferId>(), name);
+        break;
+      }
       default:
         break;
     }
       default:
         break;
     }
index 31117f4..12fd2e4 100644 (file)
@@ -29,6 +29,7 @@
 #include "iconloader.h"
 #include "identity.h"
 #include "network.h"
 #include "iconloader.h"
 #include "identity.h"
 #include "network.h"
+#include "util.h"
 
 NetworkModelActionProvider::NetworkModelActionProvider(QObject *parent)
 : AbstractActionProvider(parent),
 
 NetworkModelActionProvider::NetworkModelActionProvider(QObject *parent)
 : AbstractActionProvider(parent),
@@ -219,6 +220,24 @@ void NetworkModelActionProvider::addActions(QMenu *menu,
         // TODO: actions for merged buffers... _indexList contains the index of the message we clicked on
 
       }
         // 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
+      }
     }
   }
 }
     }
   }
 }
@@ -520,17 +539,17 @@ void NetworkModelActionProvider::handleGeneralAction(ActionType type, QAction *a
     return;
 
   switch(type) {
     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:
       break;
     }
     case ShowChannelList: