X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.cpp;h=94d90b8d2c7e825bb7edaf9668f24d8776c93b1a;hb=e0872cf3b3cdb8c52c5a52f32c3140143a29409d;hp=be13afd55aef07a2ffc9e037418ad099581c4ce9;hpb=8010224cf5bfe5685dc2cf535e8dc1ec19c4c364;p=quassel.git diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index be13afd5..94d90b8d 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -29,19 +29,29 @@ #include "ircchannel.h" #include "ircuser.h" +#include "buffersettings.h" + #include "util.h" // get rid of this (needed for isChannelName) +// #define PHONDEV + /***************************************** * Fancy Buffer Items *****************************************/ BufferItem::BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent) : PropertyMapItem(QStringList() << "bufferName" << "topic" << "nickCount", parent), _bufferInfo(bufferInfo), + _bufferName(bufferInfo.bufferName()), _activity(Buffer::NoActivity) { Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; if(bufferType() == BufferInfo::QueryBuffer) flags |= Qt::ItemIsDropEnabled; + + if(bufferType() == BufferInfo::StatusBuffer) { + NetworkItem *networkItem = qobject_cast(parent); + connect(networkItem, SIGNAL(dataChanged()), this, SIGNAL(dataChanged())); + } setFlags(flags); } @@ -153,7 +163,15 @@ QString BufferItem::bufferName() const { if(bufferType() == BufferInfo::StatusBuffer) return tr("Status Buffer"); else - return bufferInfo().bufferName(); + return _bufferName; +} + +void BufferItem::setBufferName(const QString &name) { + _bufferName = name; + // as long as we need those bufferInfos, we have to update that one aswell. + // pretty ugly though :/ + _bufferInfo = BufferInfo(_bufferInfo.bufferId(), _bufferInfo.networkId(), _bufferInfo.type(), _bufferInfo.groupId(), _bufferInfo.bufferName()); + emit dataChanged(0); } QString BufferItem::topic() const { @@ -221,7 +239,12 @@ void BufferItem::part(IrcUser *ircUser) { } void BufferItem::removeUserFromCategory(IrcUser *ircUser) { - Q_ASSERT(_ircChannel); + if(!_ircChannel) { + // If we parted the channel there might still be some ircUsers connected. + // in that case we just ignore the call + Q_ASSERT(childCount() == 0); + return; + } bool success = false; UserCategoryItem *categoryItem = 0; @@ -263,6 +286,49 @@ void BufferItem::userModeChanged(IrcUser *ircUser) { addUserToCategory(ircUser); } +QString BufferItem::toolTip(int column) const { + Q_UNUSED(column); + QStringList toolTip; + + switch(bufferType()) { + case BufferInfo::StatusBuffer: { + QString netName = Client::network(bufferInfo().networkId())->networkName(); + toolTip.append(QString("Status buffer from %1").arg(netName)); + break; + } + case BufferInfo::ChannelBuffer: + toolTip.append(QString("

Channel %1

").arg(bufferName())); + if(isActive()) { + //TODO: add channel modes + toolTip.append(QString("Users: %1").arg(nickCount())); + + BufferSettings s; + bool showTopic = s.value("DisplayTopicInTooltip", QVariant(false)).toBool(); + if(showTopic) { + QString _topic = topic(); + if(_topic != "") { + _topic.replace(QString("<"), QString("<")); + _topic.replace(QString(">"), QString(">")); + toolTip.append(QString(" ")); + toolTip.append(QString("Topic: %1").arg(_topic)); + } + } + } else { + toolTip.append(QString("Not active
Double-click to join")); + } + break; + case BufferInfo::QueryBuffer: + toolTip.append(QString("Query with %1").arg(bufferName())); + if(topic() != "") toolTip.append(QString("Away Message: %1").arg(topic())); + break; + default: //this should not happen + toolTip.append(QString("%1 - %2").arg(bufferInfo().bufferId().toInt()).arg(bufferName())); + break; + } + + return QString("

%1

").arg(toolTip.join("
")); +} + /* void BufferItem::setLastMsgInsert(QDateTime msgDate) { if(msgDate.isValid() && msgDate > _lastMsgInsert) @@ -311,11 +377,6 @@ quint64 NetworkItem::id() const { return qHash(_networkId); } -void NetworkItem::setActive(bool connected) { - Q_UNUSED(connected); - emit dataChanged(); -} - bool NetworkItem::isActive() const { if(_network) return _network->isConnected(); @@ -357,7 +418,7 @@ void NetworkItem::attachNetwork(Network *network) { connect(network, SIGNAL(ircChannelAdded(QString)), this, SLOT(attachIrcChannel(QString))); connect(network, SIGNAL(connectedSet(bool)), - this, SLOT(setActive(bool))); + this, SIGNAL(dataChanged())); // FIXME: connect this and that... @@ -391,6 +452,18 @@ void NetworkItem::setCurrentServer(const QString &serverName) { emit dataChanged(1); } + +QString NetworkItem::toolTip(int column) const { + Q_UNUSED(column); + + QStringList toolTip(QString("%1").arg(networkName())); + toolTip.append(QString("Server: %1").arg(currentServer())); + toolTip.append(QString("Users: %1").arg(nickCount())); + + return QString("

%1

").arg(toolTip.join("
")); +} + + /***************************************** * User Category Items (like @vh etc.) *****************************************/ @@ -470,6 +543,8 @@ IrcUserItem::IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent) connect(ircUser, SIGNAL(nickSet(QString)), this, SLOT(setNick(QString))); + connect(ircUser, SIGNAL(awaySet(bool)), + this, SLOT(setAway(bool))); } QString IrcUserItem::nickName() const { @@ -553,6 +628,11 @@ void IrcUserItem::setNick(QString newNick) { emit dataChanged(0); } +void IrcUserItem::setAway(bool away) { + Q_UNUSED(away); + emit dataChanged(0); +} + /***************************************** * NetworkModel *****************************************/ @@ -738,6 +818,17 @@ void NetworkModel::bufferUpdated(BufferInfo bufferInfo) { emit dataChanged(itemindex, itemindex); } +void NetworkModel::removeBuffer(BufferId bufferId) { + const int numNetworks = rootItem->childCount(); + if(numNetworks == 0) + return; + + for(int i = 0; i < numNetworks; i++) { + if(rootItem->child(i)->removeChildById(qHash(bufferId))) + break; + } +} + /* void NetworkModel::updateBufferActivity(const Message &msg) { BufferItem *buff = bufferItem(msg.bufferInfo());