From: Marcus Eggenberger Date: Sat, 12 Jan 2008 16:10:39 +0000 (+0000) Subject: Features come and features go... X-Git-Tag: 0.2.0-alpha1~236 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=50706d89d4d60e258ebb6873d3778383621898e4 Features come and features go... - the Buffer object is stripped down as possible but still exists in as a Hash in the Client. This will be changed once the Auth Process is redone. - the client lib no longer depends on QtGui \o/ - channel activities are no longer shown (will be fixed soon) :( - networks and channels are now once again greyed out when not in use \o/ - basic tabcompletion works again \o/ --- diff --git a/src/client/buffer.cpp b/src/client/buffer.cpp index f5328d45..10f395cf 100644 --- a/src/client/buffer.cpp +++ b/src/client/buffer.cpp @@ -22,111 +22,25 @@ #include "buffer.h" #include "client.h" -#include "ircchannel.h" -#include "nickmodel.h" #include "util.h" Buffer::Buffer(BufferInfo bufferid, QObject *parent) : QObject(parent), - _bufferInfo(bufferid), - _active(false), - _ircChannel(0), _nickModel(0) + _bufferInfo(bufferid) { - if(bufferid.buffer().isEmpty()) - _type = StatusType; - else if(isChannelName(bufferid.buffer())) - _type = ChannelType; - else - _type = QueryType; - - _nickModel = new NickModel(0, this); -/* - QSettings s; - s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(netname).arg(bufname)); - state->splitterState = s.value("Splitter").toByteArray(); - s.endGroup(); - */ - emit bufferUpdated(this); -} - -Buffer::~Buffer() { - //delete widget; - /* - QSettings s; - s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(networkName).arg(bufferName)); - s.setValue("Splitter", state->splitterState); - s.endGroup(); -*/ - //delete state; -} - -Buffer::Type Buffer::bufferType() const { - return _type; -} - -bool Buffer::isActive() const { - // FIXME determine status by checking for a network objekt - return true; } BufferInfo Buffer::bufferInfo() const { - return _bufferInfo; -} - -void Buffer::updateBufferInfo(BufferInfo bufferid) { - _bufferInfo = bufferid; -} - -uint Buffer::uid() const { - return bufferInfo().uid(); -} - -uint Buffer::networkId() const { - return bufferInfo().networkId(); -} - -QString Buffer::networkName() const { - return bufferInfo().network(); -} - -QString Buffer::name() const { - if(bufferType() == StatusType) - return tr("Status Buffer"); - else - return bufferInfo().buffer(); + // still needed to process user input... *sigh* + // ... and for the gui *sigh* to request the backlogs *sigh* + return _bufferInfo; } QList Buffer::contents() const { return layoutedMsgs; } -QVariantMap Buffer::nickList() const { - // FIXME should return a Map or List of IrcUsers in the future - return QVariantMap(); -} - -QString Buffer::topic() const { - if(ircChannel()) return ircChannel()->topic(); - return QString(); -} - -QString Buffer::ownNick() const { - // FIXME if(ircChannel()) return ircChannel()->ownNick(); - return QString(); -} - -bool Buffer::isStatusBuffer() const { - return bufferType() == StatusType; -} - -void Buffer::setActive(bool a) { -// if(a != active) { -// active = a; -// emit bufferUpdated(this); -// } -} - void Buffer::appendMsg(const Message &msg) { AbstractUiMsg *m = Client::layoutMsg(msg); layoutedMsgs.append(m); @@ -151,54 +65,3 @@ void Buffer::processUserInput(QString msg) { emit userInput(_bufferInfo, msg); } -NickModel *Buffer::nickModel() const { - return _nickModel; -} - -IrcChannel *Buffer::ircChannel() const { - return _ircChannel; -} - -void Buffer::setIrcChannel(IrcChannel *ircchan) { - if(_ircChannel) { - disconnect(_ircChannel, 0, this, 0); - } - _ircChannel = ircchan; - if(_ircChannel) { - emit topicSet(_ircChannel->topic()); - connect(_ircChannel, SIGNAL(topicSet(QString)), this, SIGNAL(topicSet(QString))); - connect(_ircChannel, SIGNAL(destroyed()), this, SLOT(setIrcChannel())); - } - _nickModel->setIrcChannel(ircChannel()); -} - -// no longer needed -// back reference: - -// void Buffer::addNick(QString nick, QVariantMap props) { -// if(nick == ownNick()) setActive(true); -// nicks[nick] = props; -// emit nickListChanged(nicks); -// } - -// void Buffer::updateNick(QString nick, QVariantMap props) { -// nicks[nick] = props; -// emit nickListChanged(nicks); -// } - -// void Buffer::renameNick(QString oldnick, QString newnick) { -// QVariant v = nicks.take(oldnick); -// nicks[newnick] = v; -// emit nickListChanged(nicks); -// } - -// void Buffer::removeNick(QString nick) { -// if(nick == ownNick()) setActive(false); -// nicks.remove(nick); -// emit nickListChanged(nicks); -// } - -// void Buffer::setOwnNick(QString nick) { -// _ownNick = nick; -// emit ownNickSet(nick); -// } diff --git a/src/client/buffer.h b/src/client/buffer.h index 3cd6f6a7..f7439137 100644 --- a/src/client/buffer.h +++ b/src/client/buffer.h @@ -30,8 +30,6 @@ struct BufferState; #include "message.h" #include "bufferinfo.h" -#include - //!\brief Encapsulates the contents of a single channel, query or server status context. /** A Buffer maintains a list of existing nicks and their status. */ @@ -40,90 +38,31 @@ class Buffer : public QObject { public: Buffer(BufferInfo, QObject *parent = 0); - virtual ~Buffer(); - - enum Type { - StatusType, - ChannelType, - QueryType - }; - - enum Activity { - NoActivity = 0x00, - OtherActivity = 0x01, - NewMessage = 0x02, - Highlight = 0x40 - }; - Q_DECLARE_FLAGS(ActivityLevel, Activity) - - bool isStatusBuffer() const; - Type bufferType() const; - bool isActive() const; BufferInfo bufferInfo() const; - void updateBufferInfo(BufferInfo bufferid); - BufferId uid() const; - NetworkId networkId() const; - - QString networkName() const; - QString name() const; - QList contents() const; - QVariantMap nickList() const; - QString topic() const; - QString ownNick() const; - - //! Returns a pointer to the associated IrcChannel object for the buffer. - /** A buffer has an IrcChannel object only if it is a channel buffer - * (i.e. bufferType() == ChannelType), and if it is active at the moment. - * \returns A pointer to the associated IrcChannel object, if the buffer is a channel and online; 0 else. - */ - IrcChannel *ircChannel() const; - NickModel *nickModel() const; - signals: void userInput(const BufferInfo &, QString); - void nickListChanged(QVariantMap nicks); - void topicSet(QString topic); - void ownNickSet(QString ownNick); - void bufferUpdated(Buffer *); void msgAppended(AbstractUiMsg *); void msgPrepended(AbstractUiMsg *); void layoutQueueEmpty(); public slots: - void setActive(bool active = true); void appendMsg(const Message &); void prependMsg(const Message &); bool layoutMsg(); - void setIrcChannel(IrcChannel *chan = 0); - - // no longer needed -// void setTopic(QString); -// //void setNicks(QStringList); -// void addNick(QString nick, QVariantMap props); -// void renameNick(QString oldnick, QString newnick); -// void removeNick(QString nick); -// void updateNick(QString nick, QVariantMap props); -// void setOwnNick(QString nick); void processUserInput(QString); private: BufferInfo _bufferInfo; - bool _active; - Type _type; - BufferState *state; - QPointer _ircChannel; - QPointer _nickModel; QList layoutQueue; QList layoutedMsgs; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel) #endif diff --git a/src/client/buffermodel.cpp b/src/client/buffermodel.cpp index df5d99ff..440fff08 100644 --- a/src/client/buffermodel.cpp +++ b/src/client/buffermodel.cpp @@ -74,22 +74,16 @@ void BufferModel::mapProperty(int column, int role, QObject *target, const QByte // This Slot indicates that the user has selected a different buffer in the gui void BufferModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { Q_UNUSED(command) - Buffer *newCurrentBuffer; - NetworkModel *networkModel = qobject_cast(parent()); - if(networkModel->isBufferIndex(mapToSource(index)) && currentBuffer != (newCurrentBuffer = networkModel->getBufferByIndex(mapToSource(index)))) { + + BufferId newCurrentBuffer; + if(index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType && currentBuffer != (newCurrentBuffer = index.data(NetworkModel::BufferIdRole).toUInt())) { currentBuffer = newCurrentBuffer; - networkModel->bufferActivity(Buffer::NoActivity, currentBuffer); - emit bufferSelected(currentBuffer); + // FIXME: to something like: index.setData(ActivitRole, NoActivity); + // networkModel->bufferActivity(BufferItem::NoActivity, currentBuffer); emit selectionChanged(index); } } -void BufferModel::selectBuffer(Buffer *buffer) { - QModelIndex index = (qobject_cast(parent()))->bufferIndex(buffer->bufferInfo()); - if(!index.isValid()) { - qWarning() << "BufferModel::selectBuffer(): unknown Buffer has been selected."; - return; - } - // SUPER UGLY! - setCurrentIndex(mapFromSource(index), 0); +QModelIndex BufferModel::currentIndex() { + return propertyMapper()->selectionModel()->currentIndex(); } diff --git a/src/client/buffermodel.h b/src/client/buffermodel.h index 4fb610db..e45c60e6 100644 --- a/src/client/buffermodel.h +++ b/src/client/buffermodel.h @@ -25,10 +25,10 @@ #include #include +#include "types.h" + class NetworkModel; -//class SelectionModelSynchronizer; #include "selectionmodelsynchronizer.h" -//class ModelPropertyMapper; #include "modelpropertymapper.h" class MappedSelectionModel; class QAbstractItemView; @@ -51,17 +51,16 @@ public: void mapProperty(int column, int role, QObject *target, const QByteArray &property); public slots: + QModelIndex currentIndex(); void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); - void selectBuffer(Buffer *buffer); signals: - void bufferSelected(Buffer *); void selectionChanged(const QModelIndex &); private: QPointer _selectionModelSynchronizer; QPointer _propertyMapper; - Buffer *currentBuffer; + BufferId currentBuffer; }; #endif // BUFFERMODEL_H diff --git a/src/client/client.cpp b/src/client/client.cpp index 3c5de534..49c45f4c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -70,15 +70,10 @@ void Client::init() { blockSize = 0; _networkModel = new NetworkModel(this); - _bufferModel = new BufferModel(_networkModel); + connect(this, SIGNAL(bufferUpdated(BufferInfo)), + _networkModel, SLOT(bufferUpdated(BufferInfo))); - connect(this, SIGNAL(bufferSelected(Buffer *)), - _bufferModel, SLOT(selectBuffer(Buffer *))); - - connect(this, SIGNAL(bufferUpdated(Buffer *)), - _networkModel, SLOT(bufferUpdated(Buffer *))); - connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), - _networkModel, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *))); + _bufferModel = new BufferModel(_networkModel); SignalProxy *p = signalProxy(); p->attachSignal(this, SIGNAL(sendSessionData(const QString &, const QVariant &)), @@ -162,34 +157,15 @@ Buffer *Client::buffer(BufferInfo id) { connect(buff, SIGNAL(userInput(BufferInfo, QString)), client, SLOT(userInput(BufferInfo, QString))); - connect(buff, SIGNAL(bufferUpdated(Buffer *)), - client, SIGNAL(bufferUpdated(Buffer *))); connect(buff, SIGNAL(destroyed()), client, SLOT(bufferDestroyed())); client->_buffers[id.uid()] = buff; - emit client->bufferUpdated(buff); + emit client->bufferUpdated(id); } Q_ASSERT(buff); return buff; } -// FIXME switch to netids! -// WHEN IS THIS NEEDED ANYHOW!? -// ...only for finding the Buffer for a channel, I guess... -BufferInfo Client::bufferInfo(QString net, QString buf) { - foreach(Buffer *buffer_, buffers()) { - BufferInfo bufferInfo = buffer_->bufferInfo(); - if(!bufferInfo.network().compare(net, Qt::CaseInsensitive) && !bufferInfo.buffer().compare(buf, Qt::CaseInsensitive)) - return bufferInfo; - } - Q_ASSERT(false); // should never happen! - return BufferInfo(); -} - -BufferInfo Client::statusBufferInfo(QString net) { - return bufferInfo(net, ""); -} - NetworkModel *Client::networkModel() { return instance()->_networkModel; } @@ -529,45 +505,38 @@ void Client::networkConnected(uint netid) { connect(netinfo, SIGNAL(ircUserInitDone()), this, SLOT(updateCoreConnectionProgress())); connect(netinfo, SIGNAL(ircChannelInitDone()), this, SLOT(updateCoreConnectionProgress())); } - connect(netinfo, SIGNAL(ircChannelAdded(QString)), this, SLOT(ircChannelAdded(QString))); connect(netinfo, SIGNAL(destroyed()), this, SLOT(networkDestroyed())); _network[netid] = netinfo; } void Client::networkDisconnected(uint networkid) { - foreach(Buffer *buffer, buffers()) { - if(buffer->bufferInfo().networkId() != networkid) - continue; - - //buffer->displayMsg(Message(bufferid, Message::Server, tr("Server disconnected."))); FIXME - buffer->setActive(false); + if(!_network.contains(networkid)) { + qWarning() << "Client::networkDisconnected(uint): unknown Network" << networkid; + return; } - Q_ASSERT(network(networkid)); - if(!network(networkid)->initialized()) { + Network *net = _network.take(networkid); + if(!net->initialized()) { qDebug() << "Network" << networkid << "disconnected while not yet initialized!"; updateCoreConnectionProgress(); } -} - -void Client::ircChannelAdded(QString chanName) { - Network *netInfo = qobject_cast(sender()); - Q_ASSERT(netInfo); - Buffer *buf = buffer(bufferInfo(netInfo->networkName(), chanName)); - Q_ASSERT(buf); - buf->setIrcChannel(netInfo->ircChannel(chanName)); - + net->deleteLater(); } void Client::updateBufferInfo(BufferInfo id) { - buffer(id)->updateBufferInfo(id); + emit bufferUpdated(id); } void Client::bufferDestroyed() { Buffer *buffer = static_cast(sender()); - uint bufferUid = buffer->uid(); - if(_buffers.contains(bufferUid)) - _buffers.remove(bufferUid); + QHash::iterator iter = _buffers.begin(); + while(iter != _buffers.end()) { + if(iter.value() == buffer) { + iter = _buffers.erase(iter); + break; + } + iter++; + } } void Client::networkDestroyed() { @@ -580,14 +549,14 @@ void Client::networkDestroyed() { void Client::recvMessage(const Message &msg) { Buffer *b = buffer(msg.buffer()); - Buffer::ActivityLevel level = Buffer::OtherActivity; - if(msg.type() == Message::Plain || msg.type() == Message::Notice){ - level |= Buffer::NewMessage; - } - if(msg.flags() & Message::Highlight){ - level |= Buffer::Highlight; - } - emit bufferActivity(level, b); +// Buffer::ActivityLevel level = Buffer::OtherActivity; +// if(msg.type() == Message::Plain || msg.type() == Message::Notice){ +// level |= Buffer::NewMessage; +// } +// if(msg.flags() & Message::Highlight){ +// level |= Buffer::Highlight; +// } +// emit bufferActivity(level, b); b->appendMsg(msg); } diff --git a/src/client/client.h b/src/client/client.h index 53ad0b5b..33347920 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -58,8 +58,6 @@ public: static QList buffers(); static Buffer *buffer(uint bufferUid); static Buffer *buffer(BufferInfo); - static BufferInfo statusBufferInfo(QString net); - static BufferInfo bufferInfo(QString net, QString buf); static QList identityIds(); static const Identity * identity(IdentityId); @@ -102,9 +100,7 @@ public: signals: void sendInput(BufferInfo, QString message); void showBuffer(Buffer *); - void bufferSelected(Buffer *); - void bufferUpdated(Buffer *); - void bufferActivity(Buffer::ActivityLevel, Buffer *); + void bufferUpdated(BufferInfo bufferInfo); void backlogReceived(Buffer *, QList); void requestBacklog(BufferInfo, QVariant, QVariant); void requestNetworkStates(); @@ -176,7 +172,6 @@ private slots: void bufferDestroyed(); void networkDestroyed(); - void ircChannelAdded(QString); void coreIdentityCreated(const Identity &); void coreIdentityRemoved(IdentityId); diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 6c2426de..73208201 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -18,8 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include // FIXME Dependency on QtGui! - #include "networkmodel.h" #include @@ -31,59 +29,78 @@ #include "ircchannel.h" #include "ircuser.h" +#include "util.h" // get rid of this (needed for isChannelName) + /***************************************** * Fancy Buffer Items *****************************************/ -BufferItem::BufferItem(Buffer *buffer, AbstractTreeItem *parent) +BufferItem::BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent) : PropertyMapItem(QStringList() << "bufferName" << "topic" << "nickCount", parent), - buf(buffer), - activity(Buffer::NoActivity) + _bufferInfo(bufferInfo), + _activity(NoActivity) { + // determine BufferType + if(bufferInfo.buffer().isEmpty()) + _type = StatusType; + else if(isChannelName(bufferInfo.buffer())) + _type = ChannelType; + else + _type = QueryType; + Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; - if(buf->bufferType() == Buffer::QueryType) + if(bufferType() == QueryType) flags |= Qt::ItemIsDropEnabled; setFlags(flags); } + +const BufferInfo &BufferItem::bufferInfo() const { + return _bufferInfo; +} + quint64 BufferItem::id() const { - return buf->bufferInfo().uid(); + return bufferInfo().uid(); } -void BufferItem::setActivity(const Buffer::ActivityLevel &level) { - activity = level; +bool BufferItem::isStatusBuffer() const { + return bufferType() == StatusType; } -QColor BufferItem::foreground(int column) const { - Q_UNUSED(column) - // for the time beeing we ignore the column :) - if(activity & Buffer::Highlight) { - return QColor(Qt::red); - } else if(activity & Buffer::NewMessage) { - return QColor(Qt::darkYellow); - } else if(activity & Buffer::OtherActivity) { - return QColor(Qt::darkGreen); - } else { - if(buf->isActive()) - return QColor(Qt::black); - else - return QColor(Qt::gray); - } +BufferItem::Type BufferItem::bufferType() const { + return _type; +} + +bool BufferItem::isActive() const { + if(bufferType() == ChannelType) + return _ircChannel; + else + return true; +} + +BufferItem::ActivityLevel BufferItem::activity() const { + return _activity; +} + +void BufferItem::setActivity(const ActivityLevel &level) { + _activity = level; +} + +void BufferItem::addActivity(const ActivityLevel &level) { + _activity |= level; } QVariant BufferItem::data(int column, int role) const { switch(role) { case NetworkModel::ItemTypeRole: return NetworkModel::BufferItemType; - case NetworkModel::BufferUidRole: - return buf->bufferInfo().uid(); + case NetworkModel::BufferIdRole: + return bufferInfo().uid(); case NetworkModel::NetworkIdRole: - return buf->bufferInfo().networkId(); + return bufferInfo().networkId(); case NetworkModel::BufferTypeRole: - return int(buf->bufferType()); - case NetworkModel::BufferActiveRole: - return buf->isActive(); - case Qt::ForegroundRole: - return foreground(column); + return int(bufferType()); + case NetworkModel::ItemActiveRole: + return isActive(); default: return PropertyMapItem::data(column, role); } @@ -101,10 +118,25 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) { this, SLOT(join(IrcUser *))); connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)), this, SLOT(part(IrcUser *))); + connect(ircChannel, SIGNAL(destroyed()), + this, SLOT(ircChannelDestroyed())); + + emit dataChanged(); +} + +void BufferItem::ircChannelDestroyed() { + emit dataChanged(); + for(int i = 0; i < childCount(); i++) { + emit childDestroyed(i); + removeChild(i); + } } QString BufferItem::bufferName() const { - return buf->name(); + if(bufferType() == StatusType) + return tr("Status Buffer"); + else + return bufferInfo().buffer(); } QString BufferItem::topic() const { @@ -153,6 +185,8 @@ QVariant NetworkItem::data(int column, int role) const { return _networkId; case NetworkModel::ItemTypeRole: return NetworkModel::NetworkItemType; + case NetworkModel::ItemActiveRole: + return isActive(); default: return PropertyMapItem::data(column, role); } @@ -162,6 +196,10 @@ quint64 NetworkItem::id() const { return _networkId; } +bool NetworkItem::isActive() const { + return _network; +} + QString NetworkItem::networkName() const { if(_network) return _network->networkName(); @@ -277,9 +315,7 @@ bool NetworkModel::isBufferIndex(const QModelIndex &index) const { Buffer *NetworkModel::getBufferByIndex(const QModelIndex &index) const { BufferItem *item = static_cast(index.internalPointer()); - // FIXME get rid of this - Q_ASSERT(item->buffer() == Client::instance()->buffer(item->id())); - return item->buffer(); + return Client::instance()->buffer(item->id()); } @@ -304,16 +340,19 @@ NetworkItem *NetworkModel::newNetwork(uint networkId, const QString &networkName return networkItem; } -QModelIndex NetworkModel::bufferIndex(BufferInfo bufferInfo) { - QModelIndex networkIdx = networkIndex(bufferInfo.networkId()); - if(!networkIdx.isValid()) - return QModelIndex(); - else - return indexById(bufferInfo.uid(), networkIdx); +QModelIndex NetworkModel::bufferIndex(BufferId bufferId) { + AbstractTreeItem *netItem, *bufferItem; + for(int i = 0; i < rootItem->childCount(); i++) { + netItem = rootItem->child(i); + if((bufferItem = netItem->childById(bufferId))) { + return indexById(bufferItem->id(), networkIndex(netItem->id())); + } + } + return QModelIndex(); } BufferItem *NetworkModel::buffer(BufferInfo bufferInfo) { - QModelIndex bufferIdx = bufferIndex(bufferInfo); + QModelIndex bufferIdx = bufferIndex(bufferInfo.uid()); if(bufferIdx.isValid()) return static_cast(bufferIdx.internalPointer()); else @@ -324,10 +363,7 @@ BufferItem *NetworkModel::newBuffer(BufferInfo bufferInfo) { BufferItem *bufferItem = buffer(bufferInfo); if(bufferItem == 0) { NetworkItem *networkItem = newNetwork(bufferInfo.networkId(), bufferInfo.network()); - - // FIXME: get rid of the buffer pointer - Buffer *buffer = Client::instance()->buffer(bufferInfo.uid()); - bufferItem = new BufferItem(buffer, networkItem); + bufferItem = new BufferItem(bufferInfo, networkItem); appendChild(networkItem, bufferItem); } @@ -374,7 +410,7 @@ QMimeData *NetworkModel::mimeData(const QModelIndexList &indexes) const { QString netid, uid, bufferid; foreach(QModelIndex index, indexes) { netid = QString::number(index.data(NetworkIdRole).toUInt()); - uid = QString::number(index.data(BufferUidRole).toUInt()); + uid = QString::number(index.data(BufferIdRole).toUInt()); bufferid = QString("%1:%2").arg(netid).arg(uid); if(!bufferlist.contains(bufferid)) bufferlist << bufferid; @@ -394,8 +430,8 @@ bool NetworkModel::dropMimeData(const QMimeData *data, Qt::DropAction action, in return false; // target must be a query - Buffer::Type targetType = (Buffer::Type)parent.data(NetworkModel::BufferTypeRole).toInt(); - if(targetType != Buffer::QueryType) + BufferItem::Type targetType = (BufferItem::Type)parent.data(NetworkModel::BufferTypeRole).toInt(); + if(targetType != BufferItem::QueryType) return false; QList< QPair > bufferList = mimeDataToBufferList(data); @@ -408,19 +444,19 @@ bool NetworkModel::dropMimeData(const QMimeData *data, Qt::DropAction action, in uint bufferId = bufferList.first().second; // no self merges (would kill us) - if(bufferId == parent.data(BufferUidRole).toUInt()) + if(bufferId == parent.data(BufferIdRole).toUInt()) return false; Q_ASSERT(rootItem->childById(netId)); Q_ASSERT(rootItem->childById(netId)->childById(bufferId)); // source must be a query too - Buffer::Type sourceType = (Buffer::Type)rootItem->childById(netId)->childById(bufferId)->data(0, BufferTypeRole).toInt(); - if(sourceType != Buffer::QueryType) + BufferItem::Type sourceType = (BufferItem::Type)rootItem->childById(netId)->childById(bufferId)->data(0, BufferTypeRole).toInt(); + if(sourceType != BufferItem::QueryType) return false; // TODO: warn user about buffermerge! - qDebug() << "merging" << bufferId << parent.data(BufferUidRole).toInt(); + qDebug() << "merging" << bufferId << parent.data(BufferIdRole).toInt(); removeRow(parent.row(), parent.parent()); return true; @@ -435,19 +471,19 @@ void NetworkModel::attachNetwork(Network *net) { networkItem->attachNetwork(net); } -void NetworkModel::bufferUpdated(Buffer *buffer) { - BufferItem *bufferItem = newBuffer(buffer->bufferInfo()); +void NetworkModel::bufferUpdated(BufferInfo bufferInfo) { + BufferItem *bufferItem = newBuffer(bufferInfo); QModelIndex itemindex = indexByItem(bufferItem); emit dataChanged(itemindex, itemindex); } -void NetworkModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buf) { - BufferItem *bufferItem = buffer(buf->bufferInfo()); - if(!bufferItem) { - qWarning() << "NetworkModel::bufferActivity(): received Activity Info for uknown Buffer"; - return; - } - bufferItem->setActivity(level); - bufferUpdated(buf); +void NetworkModel::bufferActivity(BufferItem::ActivityLevel level, BufferInfo bufferInfo) { +// BufferItem *bufferItem = buffer(buf->bufferInfo()); +// if(!bufferItem) { +// qWarning() << "NetworkModel::bufferActivity(): received Activity Info for uknown Buffer"; +// return; +// } +// bufferItem->setActivity(level); +// bufferUpdated(buf); } diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index e15cdd8e..09e1bd29 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -48,8 +48,9 @@ class BufferItem : public PropertyMapItem { Q_PROPERTY(int nickCount READ nickCount) public: - BufferItem(Buffer *, AbstractTreeItem *parent = 0); + BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent = 0); + const BufferInfo &bufferInfo() const; virtual quint64 id() const; virtual QVariant data(int column, int role) const; @@ -59,23 +60,45 @@ public: QString topic() const; int nickCount() const; + enum Type { + StatusType, + ChannelType, + QueryType + }; + + bool isStatusBuffer() const; + Type bufferType() const; + + bool isActive() const; - Buffer *buffer() const { return buf; } - void setActivity(const Buffer::ActivityLevel &); + enum Activity { + NoActivity = 0x00, + OtherActivity = 0x01, + NewMessage = 0x02, + Highlight = 0x40 + }; + Q_DECLARE_FLAGS(ActivityLevel, Activity) + + ActivityLevel activity() const; + void setActivity(const ActivityLevel &level); + void addActivity(const ActivityLevel &level); public slots: void setTopic(const QString &topic); void join(IrcUser *ircUser); void part(IrcUser *ircUser); + +private slots: + void ircChannelDestroyed(); private: - QColor foreground(int column) const; - - Buffer *buf; - Buffer::ActivityLevel activity; + BufferInfo _bufferInfo; + ActivityLevel _activity; + Type _type; QPointer _ircChannel; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel) /***************************************** * Network Items @@ -92,6 +115,8 @@ public: virtual QVariant data(int column, int row) const; virtual quint64 id() const; + bool isActive() const; + QString networkName() const; QString currentServer() const; int nickCount() const; @@ -140,8 +165,8 @@ class NetworkModel : public TreeModel { public: enum myRoles { BufferTypeRole = Qt::UserRole, - BufferActiveRole, - BufferUidRole, + ItemActiveRole, + BufferIdRole, NetworkIdRole, ItemTypeRole }; @@ -168,11 +193,11 @@ public: bool isBufferIndex(const QModelIndex &) const; Buffer *getBufferByIndex(const QModelIndex &) const; - QModelIndex bufferIndex(BufferInfo bufferInfo); + QModelIndex bufferIndex(BufferId bufferId); public slots: - void bufferUpdated(Buffer *); - void bufferActivity(Buffer::ActivityLevel, Buffer *buffer); + void bufferUpdated(BufferInfo bufferInfo); + void bufferActivity(BufferItem::ActivityLevel, BufferInfo bufferInfo); private: QModelIndex networkIndex(uint networkId); diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index ec6ce7af..e560a779 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -380,14 +380,20 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int rol void TreeModel::itemDataChanged(int column) { AbstractTreeItem *item = qobject_cast(sender()); - QModelIndex itemIndex; + QModelIndex leftIndex, rightIndex; - if(item == rootItem) - itemIndex = QModelIndex(); - else - itemIndex = createIndex(item->row(), column, item); + if(item == rootItem) + return; + + if(column == -1) { + leftIndex = createIndex(item->row(), 0, item); + rightIndex = createIndex(item->row(), item->columnCount(), item); + } else { + leftIndex = createIndex(item->row(), column, item); + rightIndex = leftIndex; + } - emit dataChanged(itemIndex, itemIndex); + emit dataChanged(leftIndex, rightIndex); } void TreeModel::appendChild(AbstractTreeItem *parent, AbstractTreeItem *child) { diff --git a/src/client/treemodel.h b/src/client/treemodel.h index 52ab5c59..d306e38d 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -67,7 +67,7 @@ public: AbstractTreeItem *parent(); signals: - void dataChanged(int column); + void dataChanged(int column = -1); void newChild(AbstractTreeItem *); void childDestroyed(int row); @@ -148,7 +148,7 @@ public: virtual void clear(); private slots: - void itemDataChanged(int column); + void itemDataChanged(int column = -1); void newChild(AbstractTreeItem *child); void childDestroyed(int row); diff --git a/src/common/bufferinfo.h b/src/common/bufferinfo.h index 82189aed..0597adcb 100644 --- a/src/common/bufferinfo.h +++ b/src/common/bufferinfo.h @@ -21,6 +21,7 @@ #define _BUFFERINFO_H_ #include +#include "types.h" class QString; class QDataStream; @@ -30,8 +31,8 @@ public: BufferInfo(); BufferInfo(uint id, uint networkid, uint gid = 0, QString net = QString(), QString buf = QString()); - inline uint uid() const { return _id; } - inline uint networkId() const { return _netid; } + inline BufferId uid() const { return _id; } + inline NetworkId networkId() const { return _netid; } inline uint groupId() const { return _gid; } inline QString network() const { return _networkName; } QString buffer() const; diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 12f70c23..1e567b5c 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -169,6 +169,8 @@ void IrcChannel::part(IrcUser *ircuser) { // if you wonder why there is no counterpart to ircUserParted: // the joines are propagted by the ircuser. the signal ircUserParted is only for convenience emit ircUserParted(ircuser); + if(network->isMyNick(ircuser)) + deleteLater(); } } diff --git a/src/qtui/bufferwidget.cpp b/src/qtui/bufferwidget.cpp index fc501c24..cf6ae830 100644 --- a/src/qtui/bufferwidget.cpp +++ b/src/qtui/bufferwidget.cpp @@ -23,9 +23,14 @@ #include "chatline-old.h" #include "chatwidget.h" #include "settings.h" +#include "client.h" -BufferWidget::BufferWidget(QWidget *parent) : QWidget(parent) { +BufferWidget::BufferWidget(QWidget *parent) + : QWidget(parent), + _currentBuffer(0) +{ ui.setupUi(this); + ui.ownNick->clear(); // TODO add nick history connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed())); } @@ -34,65 +39,53 @@ void BufferWidget::init() { } BufferWidget::~BufferWidget() { - } -void BufferWidget::setBuffer(Buffer *buf) { - /* - ChatView *chatView; - if(_chatViews.contains(buf->uid())) { - chatView = _chatViews[buf->uid()]; - } else { - chatView = new ChatView(buf, this); - ui.stackedWidget->addWidget(chatView); - _chatViews[buf->uid()] = chatView; - } - ui.stackedWidget->setCurrentWidget(chatView); - disconnect(this, SIGNAL(userInput(QString)), 0, 0); - connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString))); - //chatView->setFocusProxy(ui.inputEdit); - ui.inputEdit->setFocus(); - ui.ownNick->clear(); // TODO add nick history +BufferId BufferWidget::currentBuffer() const { + return _currentBuffer; } - */ - - // ui.ownNick->addItem(state->ownNick); +void BufferWidget::setCurrentBuffer(BufferId bufferId) { ChatWidget *chatWidget; - if(_chatWidgets.contains(buf)) { - chatWidget = _chatWidgets[buf]; + if(_chatWidgets.contains(bufferId)) { + chatWidget = _chatWidgets[bufferId]; } else { + Buffer *buf = Client::buffer(bufferId); + if(!buf) { + qWarning() << "BufferWidget::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId; + return; + } chatWidget = new ChatWidget(this); - chatWidget->init(buf->networkName(), buf->name()); + chatWidget->init(bufferId); QList lines; QList msgs = buf->contents(); foreach(AbstractUiMsg *msg, msgs) { lines.append(dynamic_cast(msg)); } chatWidget->setContents(lines); - connect(buf, SIGNAL(destroyed(QObject *)), this, SLOT(bufferDestroyed(QObject *))); connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *))); connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *))); - _chatWidgets[buf] = chatWidget; + _chatWidgets[bufferId] = chatWidget; ui.stackedWidget->addWidget(chatWidget); } ui.stackedWidget->setCurrentWidget(chatWidget); disconnect(this, SIGNAL(userInput(QString)), 0, 0); - connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString))); + connect(this, SIGNAL(userInput(QString)), Client::buffer(bufferId), SLOT(processUserInput(QString))); chatWidget->setFocusProxy(ui.inputEdit); ui.inputEdit->setFocus(); - ui.ownNick->clear(); // TODO add nick history - // ui.ownNick->addItem(state->ownNick); + } -void BufferWidget::bufferDestroyed(QObject *buf) { - QWidget *widget = _chatWidgets[(Buffer*)buf]; - ui.stackedWidget->removeWidget(widget); - widget->deleteLater(); +void BufferWidget::removeBuffer(BufferId bufferId) { + if(!_chatWidgets.contains(bufferId)) + return; + + ChatWidget *chatWidget = _chatWidgets.take(bufferId); + ui.stackedWidget->removeWidget(chatWidget); + chatWidget->deleteLater(); } void BufferWidget::saveState() { - } QSize BufferWidget::sizeHint() const { @@ -108,14 +101,6 @@ void BufferWidget::enterPressed() { ui.inputEdit->clear(); } -void BufferWidget::setActive(bool act) { - if(act != active) { - active = act; - //renderContents(); - //scrollToEnd(); - } -} - /* diff --git a/src/qtui/bufferwidget.h b/src/qtui/bufferwidget.h index 72ece0dc..980d0def 100644 --- a/src/qtui/bufferwidget.h +++ b/src/qtui/bufferwidget.h @@ -26,7 +26,6 @@ #include "chatview.h" #include "types.h" -class Buffer; class ChatView; class ChatWidget; class LayoutThread; @@ -37,6 +36,8 @@ class LayoutThread; class BufferWidget : public QWidget { Q_OBJECT + Q_PROPERTY(uint currentBuffer READ currentBuffer WRITE setCurrentBuffer) + public: BufferWidget(QWidget *parent = 0); virtual ~BufferWidget(); @@ -49,23 +50,18 @@ signals: void aboutToClose(); public slots: - void setBuffer(Buffer *); + BufferId currentBuffer() const; + void setCurrentBuffer(BufferId bufferId); void saveState(); private slots: void enterPressed(); - void setActive(bool act = true); - void bufferDestroyed(QObject *); - + void removeBuffer(BufferId bufferId); private: Ui::BufferWidget ui; - //QHash _chatViews; - QHash _chatWidgets; - bool active; - - QString _networkName; - QString _bufferName; + QHash _chatWidgets; + BufferId _currentBuffer; }; diff --git a/src/qtui/chatwidget.cpp b/src/qtui/chatwidget.cpp index 098961d8..520b2b9f 100644 --- a/src/qtui/chatwidget.cpp +++ b/src/qtui/chatwidget.cpp @@ -45,16 +45,15 @@ ChatWidget::ChatWidget(QWidget *parent) : QAbstractScrollArea(parent) { connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrollBarValChanged(int))); } -void ChatWidget::init(QString netname, QString bufname) { - networkName = netname; - bufferName = bufname; +void ChatWidget::init(BufferId id) { + bufferId = id; setBackgroundRole(QPalette::Base); setFont(QFont("Fixed")); UiSettings s; QVariant tsDef = s.value("DefaultTimestampColumnWidth", 90); QVariant senderDef = s.value("DefaultSenderColumnWidth", 100); - tsWidth = s.value(QString("%1/%2/TimestampColumnWidth").arg(netname, bufname), tsDef).toInt(); - senderWidth = s.value(QString("%1/%2/SenderColumnWidth").arg(netname, bufname), senderDef).toInt(); + tsWidth = s.value(QString("%1/TimestampColumnWidth").arg(bufferId), tsDef).toInt(); + senderWidth = s.value(QString("%1/SenderColumnWidth").arg(bufferId), senderDef).toInt(); computePositions(); adjustScrollBar(); verticalScrollBar()->setValue(verticalScrollBar()->maximum()); @@ -78,8 +77,8 @@ ChatWidget::~ChatWidget() { UiSettings s; s.setValue("DefaultTimestampColumnWidth", tsWidth); // FIXME stupid dirty quicky s.setValue("DefaultSenderColumnWidth", senderWidth); - s.setValue(QString("%1/%2/TimestampColumnWidth").arg(networkName, bufferName), tsWidth); - s.setValue(QString("%1/%2/SenderColumnWidth").arg(networkName, bufferName), senderWidth); + s.setValue(QString("%1/TimestampColumnWidth").arg(bufferId), tsWidth); + s.setValue(QString("%1/SenderColumnWidth").arg(bufferId), senderWidth); } QSize ChatWidget::sizeHint() const { diff --git a/src/qtui/chatwidget.h b/src/qtui/chatwidget.h index 0bd51cae..8e32783c 100644 --- a/src/qtui/chatwidget.h +++ b/src/qtui/chatwidget.h @@ -23,6 +23,8 @@ #include +#include "types.h" + class ChatLine; class AbstractUiMsg; @@ -43,7 +45,7 @@ class ChatWidget : public QAbstractScrollArea { public: ChatWidget(QWidget *parent = 0); ~ChatWidget(); - void init(QString net, QString buf); + void init(BufferId id); virtual QSize sizeHint() const; @@ -75,7 +77,7 @@ class ChatWidget : public QAbstractScrollArea { void handleScrollTimer(); private: - QString networkName, bufferName; + BufferId bufferId; enum SelectionMode { NoSelection, TextSelected, LinesSelected }; enum MouseMode { Normal, Pressed, DragTsSep, DragTextSep, MarkText, MarkLines }; enum MousePos { None, OverTsSep, OverTextSep, OverUrl }; diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index dfef33ca..1ad31414 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -125,6 +125,16 @@ void MainWin::init() { ui.menuViews->addAction(dock->toggleViewAction()); + + // attach the BufferWidget to the PropertyMapper + Client::bufferModel()->mapProperty(0, NetworkModel::BufferUidRole, ui.bufferWidget, "currentBuffer"); + connect(Client::networkModel(), SIGNAL(bufferAboutToBeRemoved(BufferId)), + ui.bufferWidget, SLOT(removeBuffer(BufferId))); + + // attach the NickList to the PropertyMapper + Client::bufferModel()->mapProperty(0, NetworkModel::BufferUidRole, nickListWidget, "currentBuffer"); + + #ifdef SPUTDEV showSettingsDlg(); #endif @@ -159,9 +169,7 @@ void MainWin::setupMenus() { } void MainWin::setupViews() { - BufferModel *model = Client::bufferModel(); - connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *))); addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QList()); addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QList()); @@ -169,18 +177,6 @@ void MainWin::setupViews() { addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QList()); addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QList()); -// QDockWidget *dock = new QDockWidget("FILTERTEST", this); -// dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); -// BufferView *view = new BufferView(dock); -// view->setModel(Client::bufferModel()); -// dock->setWidget(view); - -// addDockWidget(Qt::LeftDockWidgetArea, dock); -// ui.menuViews->addAction(dock->toggleViewAction()); - -// netViews.append(dock); - - ui.menuViews->addSeparator(); } @@ -188,13 +184,14 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, QDockWidget *dock = new QDockWidget(viewname, this); dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state! dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); - //dock->setContentsMargins(4,4,4,4); //create the view and initialize it's filter BufferView *view = new BufferView(dock); + view->show(); view->setFilteredModel(model, mode, nets); Client::bufferModel()->synchronizeView(view); dock->setWidget(view); + dock->show(); addDockWidget(Qt::LeftDockWidgetArea, dock); ui.menuViews->addAction(dock->toggleViewAction()); @@ -205,7 +202,6 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, void MainWin::setupSettingsDlg() { settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg)); - } void MainWin::connectedToCore() { @@ -283,17 +279,3 @@ void MainWin::closeEvent(QCloseEvent *event) //} } -void MainWin::showBuffer(BufferInfo id) { - showBuffer(Client::buffer(id)); -} - -void MainWin::showBuffer(Buffer *b) { - currentBuffer = b->bufferInfo().groupId(); - //emit bufferSelected(b); - //qApp->processEvents(); - ui.bufferWidget->setBuffer(b); - nickListWidget->setBuffer(b); - //if(b->bufferType() == Buffer::ChannelType) nickDock->show(); - //else nickDock->hide(); - //emit bufferSelected(b); -} diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 57638099..fc0ba025 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -64,9 +64,6 @@ class MainWin : public QMainWindow { void showCoreConnectionDlg(bool autoConnect = false); void coreConnectionDlgFinished(int result); - void showBuffer(BufferInfo); - void showBuffer(Buffer *); - signals: void connectToCore(const QVariantMap &connInfo); void disconnectFromCore(); diff --git a/src/qtui/nicklistwidget.cpp b/src/qtui/nicklistwidget.cpp index 490f9b60..df14b46c 100644 --- a/src/qtui/nicklistwidget.cpp +++ b/src/qtui/nicklistwidget.cpp @@ -22,30 +22,38 @@ #include "buffer.h" #include "nickview.h" +#include "client.h" +#include "networkmodel.h" -NickListWidget::NickListWidget(QWidget *parent) : QWidget(parent) { +NickListWidget::NickListWidget(QWidget *parent) + : QWidget(parent), + _currentBuffer(0) +{ ui.setupUi(this); +} + +BufferId NickListWidget::currentBuffer() const { + return _currentBuffer; } -void NickListWidget::setBuffer(Buffer *buf) { - if(!buf) { +void NickListWidget::setCurrentBuffer(BufferId bufferId) { + QModelIndex bufferIdx = Client::networkModel()->bufferIndex(bufferId); + + if(bufferIdx.data(NetworkModel::BufferTypeRole) != BufferItem::ChannelType) { ui.stackedWidget->setCurrentWidget(ui.emptyPage); return; } - if(buf->bufferType() != Buffer::ChannelType) { - ui.stackedWidget->setCurrentWidget(ui.emptyPage); + + if(nickViews.contains(bufferId)) { + ui.stackedWidget->setCurrentWidget(nickViews.value(bufferId)); } else { - if(nickViews.contains(buf)) { - ui.stackedWidget->setCurrentWidget(nickViews.value(buf)); - } else { - NickView *view = new NickView(this); - view->setModel(buf->nickModel()); - nickViews[buf] = view; - ui.stackedWidget->addWidget(view); - ui.stackedWidget->setCurrentWidget(view); - connect(buf, SIGNAL(destroyed(QObject *)), this, SLOT(bufferDestroyed(QObject *))); - } + NickView *view = new NickView(this); + view->setModel(Client::networkModel()); + view->setRootIndex(bufferIdx); + nickViews[bufferId] = view; + ui.stackedWidget->addWidget(view); + ui.stackedWidget->setCurrentWidget(view); } } @@ -57,10 +65,11 @@ void NickListWidget::reset() { nickViews.clear(); } -void NickListWidget::bufferDestroyed(QObject *buf) { - if(nickViews.contains((Buffer *)buf)) { - NickView *view = nickViews.take((Buffer *)buf); - ui.stackedWidget->removeWidget(view); - view->deleteLater(); - } +void NickListWidget::removeBuffer(BufferId bufferId) { + if(!nickViews.contains(bufferId)) + return; + + NickView *view = nickViews.take(bufferId); + ui.stackedWidget->removeWidget(view); + view->deleteLater(); } diff --git a/src/qtui/nicklistwidget.h b/src/qtui/nicklistwidget.h index e09ff33f..4e8ac8d5 100644 --- a/src/qtui/nicklistwidget.h +++ b/src/qtui/nicklistwidget.h @@ -22,6 +22,7 @@ #define _NICKLISTWIDGET_H_ #include "ui_nicklistwidget.h" +#include "types.h" #include @@ -31,20 +32,24 @@ class NickView; class NickListWidget : public QWidget { Q_OBJECT - public: - NickListWidget(QWidget *parent = 0); - - public slots: - void setBuffer(Buffer *); - void reset(); - - private slots: - void bufferDestroyed(QObject *); - - private: - Ui::NickListWidget ui; - QHash nickViews; - + Q_PROPERTY(uint currentBuffer READ currentBuffer WRITE setCurrentBuffer) + +public: + NickListWidget(QWidget *parent = 0); + +public slots: + BufferId currentBuffer() const; + void setCurrentBuffer(BufferId bufferId); + void reset(); + +private slots: + void removeBuffer(BufferId bufferId); + +private: + Ui::NickListWidget ui; + QHash nickViews; + BufferId _currentBuffer; + }; #endif diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 426c272c..5374338f 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -19,7 +19,7 @@ ***************************************************************************/ #include "client.h" -#include "buffer.h" +//#include "buffer.h" #include "bufferview.h" #include "networkmodel.h" @@ -82,9 +82,9 @@ void BufferView::setModel(QAbstractItemModel *model) { } void BufferView::joinChannel(const QModelIndex &index) { - Buffer::Type bufferType = (Buffer::Type)index.data(NetworkModel::BufferTypeRole).toInt(); + BufferItem::Type bufferType = (BufferItem::Type)index.data(NetworkModel::BufferTypeRole).toInt(); - if(bufferType != Buffer::ChannelType) + if(bufferType != BufferItem::ChannelType) return; Client::fakeInput(index.data(NetworkModel::BufferUidRole).toUInt(), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString())); diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index 4204ac0f..139ca894 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -20,6 +20,8 @@ #include "bufferviewfilter.h" +#include + #include "networkmodel.h" /***************************************** @@ -110,13 +112,13 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) { bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const { - Buffer::Type bufferType = (Buffer::Type) source_bufferIndex.data(NetworkModel::BufferTypeRole).toInt(); + BufferItem::Type bufferType = (BufferItem::Type) source_bufferIndex.data(NetworkModel::BufferTypeRole).toInt(); - if((mode & NoChannels) && bufferType == Buffer::ChannelType) + if((mode & NoChannels) && bufferType == BufferItem::ChannelType) return false; - if((mode & NoQueries) && bufferType == Buffer::QueryType) + if((mode & NoQueries) && bufferType == BufferItem::QueryType) return false; - if((mode & NoServers) && bufferType == Buffer::StatusType) + if((mode & NoServers) && bufferType == BufferItem::StatusType) return false; // bool isActive = source_bufferIndex.data(NetworkModel::BufferActiveRole).toBool(); @@ -162,3 +164,17 @@ bool BufferViewFilter::lessThan(const QModelIndex &left, const QModelIndex &righ return QSortFilterProxyModel::lessThan(left, right); } +QVariant BufferViewFilter::data(const QModelIndex &index, int role) const { + if(role == Qt::ForegroundRole) + return foreground(index); + else + return QSortFilterProxyModel::data(index, role); +} + +QVariant BufferViewFilter::foreground(const QModelIndex &index) const { + if(!index.data(NetworkModel::ItemActiveRole).toBool()) + return QColor(Qt::gray); + + // FIXME:: show colors depending on activity level + return QColor(Qt::black); +} diff --git a/src/uisupport/bufferviewfilter.h b/src/uisupport/bufferviewfilter.h index c6b53cc1..d20445dc 100644 --- a/src/uisupport/bufferviewfilter.h +++ b/src/uisupport/bufferviewfilter.h @@ -25,7 +25,7 @@ #include #include #include -#include "buffer.h" +// #include "buffer.h" /***************************************** * Buffer View Filter @@ -50,7 +50,10 @@ public: virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); - + + QVariant data(const QModelIndex &index, int role) const; + QVariant foreground(const QModelIndex &index) const; + public slots: void removeBuffer(const QModelIndex &); void invalidateFilter_(); diff --git a/src/uisupport/inputline.cpp b/src/uisupport/inputline.cpp index f6d71715..7511e07a 100644 --- a/src/uisupport/inputline.cpp +++ b/src/uisupport/inputline.cpp @@ -22,15 +22,15 @@ #include "tabcompleter.h" -InputLine::InputLine(QWidget *parent) : QLineEdit(parent) { - idx = 0; +InputLine::InputLine(QWidget *parent) + : QLineEdit(parent), + idx(0) +{ connect(this, SIGNAL(returnPressed()), this, SLOT(enter())); tabComplete = new TabCompleter(this); - connect(this, SIGNAL(nickListUpdated(QStringList)), tabComplete, SLOT(updateNickList(QStringList))); } InputLine::~InputLine() { - delete tabComplete; } void InputLine::keyPressEvent(QKeyEvent * event) { @@ -38,7 +38,7 @@ void InputLine::keyPressEvent(QKeyEvent * event) { tabComplete->complete(); event->accept(); } else { - tabComplete->disable(); + tabComplete->reset(); if(event->key() == Qt::Key_Up) { if(idx > 0) { idx--; setText(history[idx]); } event->accept(); diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index b8922920..fe4b9e76 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -35,8 +35,8 @@ NickView::NickView(QWidget *parent) : QTreeView(parent) { setSortingEnabled(true); sortByColumn(0, Qt::AscendingOrder); - filteredModel = new FilteredNickModel(this); - QTreeView::setModel(filteredModel); +// filteredModel = new FilteredNickModel(this); +// QTreeView::setModel(filteredModel); } NickView::~NickView() { @@ -44,10 +44,10 @@ NickView::~NickView() { } -void NickView::setModel(NickModel *model) { - filteredModel->setSourceModel(model); - expandAll(); -} +// void NickView::setModel(NickModel *model) { +// filteredModel->setSourceModel(model); +// expandAll(); +// } void NickView::rowsInserted(const QModelIndex &index, int start, int end) { QTreeView::rowsInserted(index, start, end); diff --git a/src/uisupport/nickview.h b/src/uisupport/nickview.h index 54313acc..70206cb7 100644 --- a/src/uisupport/nickview.h +++ b/src/uisupport/nickview.h @@ -37,11 +37,11 @@ class NickView : public QTreeView { protected: void rowsInserted(const QModelIndex &, int, int); - public slots: - void setModel(NickModel *model); +// public slots: +// void setModel(NickModel *model); - private: - QSortFilterProxyModel *filteredModel; +// private: +// QSortFilterProxyModel *filteredModel; }; diff --git a/src/uisupport/tabcompleter.cpp b/src/uisupport/tabcompleter.cpp index e4d0e608..60a74fb8 100644 --- a/src/uisupport/tabcompleter.cpp +++ b/src/uisupport/tabcompleter.cpp @@ -20,57 +20,87 @@ #include "tabcompleter.h" -TabCompleter::TabCompleter(QLineEdit *l, QObject *parent) : QObject(parent) { - lineEdit = l; - enabled = false; - startOfLineSuffix = QString(": "); // TODO make start of line suffix configurable -} - -void TabCompleter::updateNickList(QStringList l) { - nickList = l; -} +#include "inputline.h" +#include "client.h" +#include "buffermodel.h" +#include "networkmodel.h" +#include "network.h" +#include "ircchannel.h" +#include "ircuser.h" -void TabCompleter::updateChannelList(QStringList l) { - channelList = l; +TabCompleter::TabCompleter(InputLine *inputLine_) + : QObject(inputLine_), + inputLine(inputLine_), + enabled(false), + nickSuffix(": ") +{ } void TabCompleter::buildCompletionList() { // this is the first time tab is pressed -> build up the completion list and it's iterator - QString tabAbbrev = lineEdit->text().left(lineEdit->cursorPosition()).section(' ',-1,-1); + QModelIndex currentIndex = Client::bufferModel()->currentIndex(); + if(!currentIndex.data(NetworkModel::BufferIdRole).isValid()) + return; + + NetworkId networkId = currentIndex.data(NetworkModel::NetworkIdRole).toUInt(); + QString channelName = currentIndex.sibling(currentIndex.row(), 0).data().toString(); + + Network *network = Client::network(networkId); + if(!network) + return; + + IrcChannel *channel = network->ircChannel(channelName); + if(!channel) + return; + + disconnect(this, SLOT(ircUserJoinedOrParted(IrcUser *))); + connect(channel, SIGNAL(ircUserJoined(IrcUser *)), + this, SLOT(ircUserJoinedOrParted(IrcUser *))); + connect(channel, SIGNAL(ircUserParted(IrcUser *)), + this, SLOT(ircUserJoinedOrParted(IrcUser *))); + + completionList.clear(); + QString tabAbbrev = inputLine->text().left(inputLine->cursorPosition()).section(' ',-1,-1); completionList.clear(); - foreach(QString nick, nickList) { - if(nick.toLower().startsWith(tabAbbrev.toLower())) { - completionList << nick; + foreach(IrcUser *ircUser, channel->ircUsers()) { + if(ircUser->nick().toLower().startsWith(tabAbbrev.toLower())) { + completionList << ircUser->nick(); } } completionList.sort(); nextCompletion = completionList.begin(); lastCompletionLength = tabAbbrev.length(); + +} + +void TabCompleter::ircUserJoinedOrParted(IrcUser *ircUser) { + Q_UNUSED(ircUser) + buildCompletionList(); } void TabCompleter::complete() { - if (! enabled) { + if(!enabled) { buildCompletionList(); - enabled = true; + enabled = true; } if (nextCompletion != completionList.end()) { // clear previous completion for (int i = 0; i < lastCompletionLength; i++) { - lineEdit->backspace(); + inputLine->backspace(); } // insert completion - lineEdit->insert(*nextCompletion); + inputLine->insert(*nextCompletion); // remember charcount to delete next time and advance to next completion lastCompletionLength = nextCompletion->length(); nextCompletion++; // we're completing the first word of the line - if(lineEdit->text().length() == lastCompletionLength) { - lineEdit->insert(startOfLineSuffix); - lastCompletionLength += 2; + if(inputLine->text().length() == lastCompletionLength) { + inputLine->insert(nickSuffix); + lastCompletionLength += nickSuffix.length(); } // we're at the end of the list -> start over again @@ -80,7 +110,7 @@ void TabCompleter::complete() { } -void TabCompleter::disable() { +void TabCompleter::reset() { enabled = false; } diff --git a/src/uisupport/tabcompleter.h b/src/uisupport/tabcompleter.h index 00560dc6..b223fe6e 100644 --- a/src/uisupport/tabcompleter.h +++ b/src/uisupport/tabcompleter.h @@ -21,36 +21,38 @@ #ifndef _TABCOMPLETER_H_ #define _TABCOMPLETER_H_ -#include #include -#include +#include +#include + +class InputLine; +class IrcUser; class TabCompleter : public QObject { Q_OBJECT - public: - TabCompleter(QLineEdit *l, QObject *parent = 0); - void disable(); - void complete(); +public: + TabCompleter(InputLine *inputLine_); + + void reset(); + void complete(); + +private slots: + void ircUserJoinedOrParted(IrcUser *ircUser); - public slots: - void updateNickList(QStringList); - void updateChannelList(QStringList); - - private: - bool enabled; - QString startOfLineSuffix; - QLineEdit *lineEdit; - QStringList completionTemplates; - QStringList channelList; +private: + QPointer inputLine; + bool enabled; + QString nickSuffix; - QStringList nickList; - QStringList completionList; - QStringList::Iterator nextCompletion; - int lastCompletionLength; - - void buildCompletionList(); - + QStringList completionList; + // QStringList completionTemplates; + + QStringList::Iterator nextCompletion; + int lastCompletionLength; + + void buildCompletionList(); + }; #endif