[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Konversation] dcaca9f: Right click a channel list item and you get a
From:       Stephan Binner <binner () kde ! org>
Date:       2010-07-01 13:27:07
Message-ID: 20100701132707.B9628BB5511 () projects ! kde ! org
[Download RAW message or body]

commit dcaca9f78699804997b2c79151abc1d39892734e
Author: Stephan Binner <binner@kde.org>
Date:   Thu Dec 4 17:20:19 2003 +0000

    Right click a channel list item and you get a menu to open the URLs found in the \
channel's topic  
    svn path=/trunk/kdeextragear-2/konversation/; revision=271190

diff --git a/TODO b/TODO
index 9cd4965..7f6dff6 100644
--- a/TODO
+++ b/TODO
@@ -23,7 +23,6 @@ Fix the /query oneuser, /msg anotheruser problem
 Don't trigger events when we did highlight ourselves
 
 Channel List Panel:
-Make URLs in topic clickable or at least selectable
 and a "channel or topic" checkbox would be nice, or better, make the current \
checkboxes work as "or" not as "and"  
 /WHOWAS after /WHOIS if /WHOIS returns unknown nickname
diff --git a/konversation/channellistpanel.cpp b/konversation/channellistpanel.cpp
index b046454..0adca5a 100644
--- a/konversation/channellistpanel.cpp
+++ b/konversation/channellistpanel.cpp
@@ -23,12 +23,14 @@
 #include <qcheckbox.h>
 #include <qtimer.h>
 
+#include <krun.h>
 #include <klistview.h>
 #include <klineedit.h>
 #include <klocale.h>
 #include <kdebug.h>
 #include <kfiledialog.h>
 #include <kmessagebox.h>
+#include <kpopupmenu.h>
 
 #include "channellistpanel.h"
 #include "channellistviewitem.h"
@@ -115,6 +117,9 @@ ChannelListPanel::ChannelListPanel(QWidget* parent) :
   connect(channelListView,SIGNAL (doubleClicked(QListViewItem*)),
                        this,SLOT (joinChannelClicked()) );
 
+  connect(channelListView,SIGNAL (contextMenu (KListView*, QListViewItem*, const \
QPoint&) ), +                       this, SLOT (contextMenu (KListView*, \
QListViewItem*, const QPoint&)) ); +
   connect(minUsersSpin,SIGNAL (valueChanged(int)),this,SLOT(setMinUsers(int)) );
   connect(maxUsersSpin,SIGNAL (valueChanged(int)),this,SLOT(setMaxUsers(int)) );
   connect(this,SIGNAL (adjustMinValue(int)),minUsersSpin,SLOT (setValue(int)) );
@@ -403,4 +408,69 @@ void ChannelListPanel::adjustFocus()
 {
 }
 
+void ChannelListPanel::contextMenu (KListView* l, QListViewItem* i, const QPoint& p)
+{
+  KPopupMenu* showURLmenu = new KPopupMenu(this);
+  showURLmenu->setTitle( i18n("Open URL") );
+ 
+  QString filteredLine(i->text(2));
+  
+  QRegExp pattern("((http://|https://|ftp://|nntp://|news://|gopher://|www\\.|ftp\\.)"
 +                  // IP Address
+                  "([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|"
+                  // Decimal IP address
+                  "[0-9]{1,12}|"
+                  // Standard host name
+                  "[a-z0-9][\\.@%a-z0-9_-]+\\.[a-z]{2,}"
+                  // Port number, path to document
+                  ")(:[0-9]{1,5})?(/[^)>\"'\\s]*)?|"
+                  // eDonkey2000 links need special treatment
+                  "ed2k://\\|([^|]+\\|){4})");
+
+  pattern.setCaseSensitive(false);
+
+  int pos=0;
+  while(static_cast<unsigned int>(pos) < filteredLine.length())
+  {
+    if(pattern.search(filteredLine,pos)!=-1) {
+      // Remember where we found the url
+      pos=pattern.pos();
+
+      // Extract url
+      QString url=pattern.capturedTexts()[0];
+      QString href(url);
+
+      // clean up href for browser
+      if(href.startsWith("www.")) href="http://"+href;
+      else if(href.startsWith("ftp.")) href="ftp://"+href;
+
+      // Replace all spaces with %20 in href
+      href.replace(QRegExp(" "),"%20");
+      href.replace("&","&&");
+      
+      // next search begins right after the link
+      pos+=url.length();
+      
+      // tell the program that we have found a new url
+      showURLmenu->insertItem(href);
+    }
+    else {
+      pos++;
+    }
+  }
+  
+  if (showURLmenu->count()==1) {
+    showURLmenu->insertItem(i18n("<<No URL found>>"),5);
+    showURLmenu->setItemEnabled(5,false);
+  }
+  
+  int selected = showURLmenu->exec(p);  
+  if (selected!=-1) {
+    QMenuItem* item = showURLmenu->findItem( selected );
+    new KRun(item->text().replace("&&","&"));
+  }
+  
+  delete showURLmenu;
+}
+
 #include "channellistpanel.moc"
diff --git a/konversation/channellistpanel.h b/konversation/channellistpanel.h
index 8edc275..4498e34 100644
--- a/konversation/channellistpanel.h
+++ b/konversation/channellistpanel.h
@@ -65,6 +65,8 @@ class ChannelListPanel : public ChatWindow
     void topicTargetClicked();
     void regExpClicked();
 
+    void contextMenu (KListView* l, QListViewItem* i, const QPoint& p);
+    
   protected:
     int getNumChannels();
     int getNumUsers();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic