commit dcaca9f78699804997b2c79151abc1d39892734e Author: Stephan Binner 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 #include +#include #include #include #include #include #include #include +#include #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(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("<>"),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();