From 09312db1a755642802ff15595900878fbe76b21a Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 3 Jul 2008 13:08:47 +0200 Subject: [PATCH 1/1] urls are now properly identified if the topic is scrolled --- src/common/ircuser.cpp | 59 ++++++++++++++++++++++++++--------------- src/common/ircuser.h | 22 +++++++-------- src/common/network.cpp | 1 + src/common/network.h | 5 ++-- src/qtui/topiclabel.cpp | 21 ++++++--------- 5 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 22df0c94..af3cb3eb 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -21,18 +21,18 @@ #include "ircuser.h" #include "util.h" -#include "network.h" #include "signalproxy.h" #include "ircchannel.h" #include #include -IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(network), +IrcUser::IrcUser(const QString &hostmask, Network *network) + : SyncableObject(network), _initialized(false), - _nick(nickFromMask(hostmask)), - _user(userFromMask(hostmask)), - _host(hostFromMask(hostmask)), + _nick(network->encodeServerString(nickFromMask(hostmask))), + _user(network->encodeServerString(userFromMask(hostmask))), + _host(network->encodeServerString(hostFromMask(hostmask))), _realName(), _awayMessage(), _away(false), @@ -107,16 +107,22 @@ QByteArray IrcUser::encodeString(const QString &string) const { // PUBLIC SLOTS: // ==================== void IrcUser::setUser(const QString &user) { - if(!user.isEmpty() && _user != user) { - _user = user; - emit userSet(user); + if(!user.isEmpty()) { + QByteArray newUser = network()->encodeServerString(user); + if(newUser != _user) { + _user = newUser; + emit userSet(user); + } } } void IrcUser::setRealName(const QString &realName) { - if (!realName.isEmpty() && _realName != realName) { - _realName = realName; - emit realNameSet(realName); + if(!realName.isEmpty()) { + QByteArray newRealName = network()->encodeServerString(realName); + if(newRealName != _realName) { + _realName = newRealName; + emit realNameSet(realName); + } } } @@ -128,9 +134,12 @@ void IrcUser::setAway(const bool &away) { } void IrcUser::setAwayMessage(const QString &awayMessage) { - if(!awayMessage.isEmpty() && _awayMessage != awayMessage) { - _awayMessage = awayMessage; - emit awayMessageSet(awayMessage); + if(!awayMessage.isEmpty()) { + QByteArray newAwayMessage = network()->encodeServerString(awayMessage); + if(newAwayMessage != _awayMessage) { + _awayMessage = newAwayMessage; + emit awayMessageSet(awayMessage); + } } } @@ -171,17 +180,23 @@ void IrcUser::setLastAwayMessage(const int &lastAwayMessage) { } void IrcUser::setHost(const QString &host) { - if(!host.isEmpty() && _host != host) { - _host = host; - emit hostSet(host); + if(!host.isEmpty()) { + QByteArray newHost = network()->encodeServerString(host); + if(newHost != _host) { + _host = newHost; + emit hostSet(host); + } } } void IrcUser::setNick(const QString &nick) { - if(!nick.isEmpty() && nick != _nick) { - _nick = nick; - updateObjectName(); - emit nickSet(nick); + if(!nick.isEmpty()) { + QByteArray newNick = network()->encodeServerString(nick); + if(newNick != _nick) { + _nick = newNick; + updateObjectName(); + emit nickSet(nick); + } } } @@ -200,7 +215,7 @@ void IrcUser::setSuserHost(const QString &suserHost) { } void IrcUser::updateObjectName() { - renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick); + renameObject(QString::number(network()->networkId().toInt()) + "/" + nick()); } void IrcUser::updateHostmask(const QString &mask) { diff --git a/src/common/ircuser.h b/src/common/ircuser.h index 00df169c..f2f84ff0 100644 --- a/src/common/ircuser.h +++ b/src/common/ircuser.h @@ -28,9 +28,9 @@ #include #include "syncableobject.h" +#include "network.h" class SignalProxy; -class Network; class IrcChannel; class IrcUser : public SyncableObject { @@ -57,13 +57,13 @@ public: IrcUser(const QString &hostmask, Network *network); virtual ~IrcUser(); - inline QString user() const { return _user; } - inline QString host() const { return _host; } - inline QString nick() const { return _nick; } - inline QString realName() const { return _realName; } + inline QString user() const { return network()->decodeServerString(_user); } + inline QString host() const { return network()->decodeServerString(_host); } + inline QString nick() const { return network()->decodeServerString(_nick); } + inline QString realName() const { return network()->decodeServerString(_realName); } QString hostmask() const; inline bool isAway() const { return _away; } - inline QString awayMessage() const { return _awayMessage; } + inline QString awayMessage() const { return network()->decodeServerString(_awayMessage); } QDateTime idleTime(); inline QDateTime loginTime() const { return _loginTime; } inline QString server() const { return _server; } @@ -153,11 +153,11 @@ private: bool _initialized; - QString _nick; - QString _user; - QString _host; - QString _realName; - QString _awayMessage; + QByteArray _nick; + QByteArray _user; + QByteArray _host; + QByteArray _realName; + QByteArray _awayMessage; bool _away; QString _server; QDateTime _idleTime; diff --git a/src/common/network.cpp b/src/common/network.cpp index cfcda7de..38d5095a 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -22,6 +22,7 @@ #include #include +#include "ircuser.h" #include "util.h" QTextCodec *Network::_defaultCodecForServer = 0; diff --git a/src/common/network.h b/src/common/network.h index 3759e565..66310436 100644 --- a/src/common/network.h +++ b/src/common/network.h @@ -33,9 +33,10 @@ #include "syncableobject.h" #include "signalproxy.h" -#include "ircuser.h" #include "ircchannel.h" +class IrcUser; + // defined below! struct NetworkInfo; @@ -97,7 +98,7 @@ public: inline void setProxy(SignalProxy *proxy) { _proxy = proxy; } inline bool isMyNick(const QString &nick) const { return (myNick().toLower() == nick.toLower()); } - inline bool isMe(IrcUser *ircuser) const { return (ircuser->nick().toLower() == myNick().toLower()); } + inline bool isMe(IrcUser *ircuser) const { return (ircuser == me()); } bool isChannelName(const QString &channelname) const; diff --git a/src/qtui/topiclabel.cpp b/src/qtui/topiclabel.cpp index ec9fc4eb..5949777b 100644 --- a/src/qtui/topiclabel.cpp +++ b/src/qtui/topiclabel.cpp @@ -103,11 +103,9 @@ void TopicLabel::mouseMoveEvent(QMouseEvent *event) { int newOffset = event->pos().x() - dragStartX; if(newOffset > 0) offset = 0; - else if(width() < textWidth || offset < newOffset) + else if(width() + 1 < textWidth || offset < newOffset) offset = newOffset; -// qDebug() << offset << (width() - textWidth) << width() << textWidth; -// if(offset < width() - textWidth) -// offset = width() - textWidth; + update(); } @@ -131,22 +129,19 @@ void TopicLabel::mouseReleaseEvent(QMouseEvent *event) { void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) { #ifndef SPUTDEV event->accept(); - int textPart = 0; - int textOffset = 0; - if(textPartOffset.isEmpty()) return; // find the text part that contains the url. We don't expect color codes in urls so we expect only full parts (yet?) - int x = event->pos().x(); + int textPart = 0; + int x = event->pos().x() + offset; while(textPart + 1 < textPartOffset.count()) { - if(textPartOffset[textPart + 1] < x) { + if(textPartOffset[textPart + 1] < x) textPart++; - textOffset = textPartOffset[textPart]; - } else { + else break; - } } + int textOffset = textPartOffset[textPart]; // we've Identified the needed text part \o/ QString text = styledContents.plainText.mid(styledContents.formatList[textPart].start, styledContents.formatList[textPart].length); @@ -156,6 +151,7 @@ void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) { int start = 0; int spacePos = text.indexOf(" "); + x -= offset; // offset needs to go here as it's already in the textOffset while(spacePos != -1) { if(fontMetric.width(text.left(spacePos + 1)) + textOffset < x) { start = spacePos + 1; @@ -171,7 +167,6 @@ void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) { len = end - start; } QString word = text.mid(start, len); - qDebug() << word; QRegExp regex("^(h|f)t{1,2}ps?:\\/\\/"); if(regex.indexIn(word) != -1) { QDesktopServices::openUrl(QUrl(word)); -- 2.20.1