- connect(network, SIGNAL(networkNameSet(QString)),
- this, SLOT(setNetworkName(QString)));
- connect(network, SIGNAL(currentServerSet(QString)),
- this, SLOT(setCurrentServer(QString)));
- connect(network, SIGNAL(ircChannelAdded(QString)),
- this, SLOT(attachIrcChannel(QString)));
- // FIXME: connect this and that...
+ IrcChannel *ircChannel = net->ircChannel(bufferInfo.bufferName());
+ if(ircChannel)
+ attachIrcChannel(ircChannel);
+}
+
+QVariant ChannelBufferItem::data(int column, int role) const {
+ switch(role) {
+ case NetworkModel::IrcChannelRole:
+ return QVariant::fromValue<QObject *>(_ircChannel);
+ default:
+ return BufferItem::data(column, role);
+ }
+}
+
+QString ChannelBufferItem::toolTip(int column) const {
+ Q_UNUSED(column);
+ QStringList toolTip;
+
+ toolTip.append(tr("<b>Channel %1</b>").arg(bufferName()));
+ if(isActive()) {
+ //TODO: add channel modes
+ toolTip.append(tr("<b>Users:</b> %1").arg(nickCount()));
+ if(_ircChannel) {
+ QString channelMode = _ircChannel->channelModeString(); // channelModeString is compiled on the fly -> thus cache the result
+ if(!channelMode.isEmpty())
+ toolTip.append(tr("<b>Mode:</b> %1").arg(channelMode));
+ }
+
+ BufferSettings s;
+ bool showTopic = s.value("DisplayTopicInTooltip", QVariant(false)).toBool();
+ if(showTopic) {
+ QString _topic = topic();
+ if(_topic != "") {
+ _topic = stripFormatCodes(_topic);
+ _topic.replace(QString("<"), QString("<"));
+ _topic.replace(QString(">"), QString(">"));
+ toolTip.append(QString("<font size='-2'> </font>"));
+ toolTip.append(tr("<b>Topic:</b> %1").arg(_topic));
+ }
+ }
+ } else {
+ toolTip.append(tr("Not active <br /> Double-click to join"));
+ }
+
+ return tr("<p> %1 </p>").arg(toolTip.join("<br />"));
+}
+
+void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel) {
+ Q_ASSERT(!_ircChannel && ircChannel);
+
+ _ircChannel = ircChannel;
+
+ connect(ircChannel, SIGNAL(topicSet(QString)),
+ this, SLOT(setTopic(QString)));
+ connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *>)),
+ this, SLOT(join(QList<IrcUser *>)));
+ connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
+ this, SLOT(part(IrcUser *)));
+ connect(ircChannel, SIGNAL(parted()),
+ this, SLOT(ircChannelParted()));
+ connect(ircChannel, SIGNAL(ircUserModesSet(IrcUser *, QString)),
+ this, SLOT(userModeChanged(IrcUser *)));
+ connect(ircChannel, SIGNAL(ircUserModeAdded(IrcUser *, QString)),
+ this, SLOT(userModeChanged(IrcUser *)));
+ connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
+ this, SLOT(userModeChanged(IrcUser *)));
+
+ if(!ircChannel->ircUsers().isEmpty())
+ join(ircChannel->ircUsers());
+
+ emit dataChanged();
+}