Features come and features go...
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 12 Jan 2008 16:10:39 +0000 (16:10 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 12 Jan 2008 16:10:39 +0000 (16:10 +0000)
- 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/

28 files changed:
src/client/buffer.cpp
src/client/buffer.h
src/client/buffermodel.cpp
src/client/buffermodel.h
src/client/client.cpp
src/client/client.h
src/client/networkmodel.cpp
src/client/networkmodel.h
src/client/treemodel.cpp
src/client/treemodel.h
src/common/bufferinfo.h
src/common/ircchannel.cpp
src/qtui/bufferwidget.cpp
src/qtui/bufferwidget.h
src/qtui/chatwidget.cpp
src/qtui/chatwidget.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/nicklistwidget.cpp
src/qtui/nicklistwidget.h
src/uisupport/bufferview.cpp
src/uisupport/bufferviewfilter.cpp
src/uisupport/bufferviewfilter.h
src/uisupport/inputline.cpp
src/uisupport/nickview.cpp
src/uisupport/nickview.h
src/uisupport/tabcompleter.cpp
src/uisupport/tabcompleter.h

index f5328d4..10f395c 100644 (file)
 #include "buffer.h"
 
 #include "client.h"
 #include "buffer.h"
 
 #include "client.h"
-#include "ircchannel.h"
-#include "nickmodel.h"
 #include "util.h"
 
 
 Buffer::Buffer(BufferInfo bufferid, QObject *parent)
   : QObject(parent),
 #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 {
 }
 
 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<AbstractUiMsg *> Buffer::contents() const {
   return layoutedMsgs;
 }
 
 }
 
 QList<AbstractUiMsg *> 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);
 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);
 }
 
   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);
-// }
index 3cd6f6a..f743913 100644 (file)
@@ -30,8 +30,6 @@ struct BufferState;
 #include "message.h"
 #include "bufferinfo.h"
 
 #include "message.h"
 #include "bufferinfo.h"
 
-#include <QVariantMap>
-
 //!\brief Encapsulates the contents of a single channel, query or server status context.
 /** A Buffer maintains a list of existing nicks and their status.
  */
 //!\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);
 
 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;
 
   BufferInfo bufferInfo() const;
-  void updateBufferInfo(BufferInfo bufferid);
 
 
-  BufferId uid() const;
-  NetworkId networkId() const;
-  
-  QString networkName() const;
-  QString name() const;
-  
   QList<AbstractUiMsg *> contents() const;
   
   QList<AbstractUiMsg *> 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);
 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 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 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;
 
   void processUserInput(QString);
 
 private:
   BufferInfo _bufferInfo;
-  bool _active;
-  Type _type;
-  BufferState *state;
-  QPointer<IrcChannel> _ircChannel;
-  QPointer<NickModel> _nickModel;
 
   QList<Message> layoutQueue;
   QList<AbstractUiMsg *> layoutedMsgs;
 
 };
 
   QList<Message> layoutQueue;
   QList<AbstractUiMsg *> layoutedMsgs;
 
 };
-Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel)
 
 #endif
 
 #endif
index df5d99f..440fff0 100644 (file)
@@ -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)
 // 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<NetworkModel *>(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;
     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);
   }
 }
 
     emit selectionChanged(index);
   }
 }
 
-void BufferModel::selectBuffer(Buffer *buffer) {
-  QModelIndex index = (qobject_cast<NetworkModel *>(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();
 }
 }
index 4fb610d..e45c60e 100644 (file)
 #include <QItemSelectionModel>
 #include <QPointer>
 
 #include <QItemSelectionModel>
 #include <QPointer>
 
+#include "types.h"
+
 class NetworkModel;
 class NetworkModel;
-//class SelectionModelSynchronizer;
 #include "selectionmodelsynchronizer.h"
 #include "selectionmodelsynchronizer.h"
-//class ModelPropertyMapper;
 #include "modelpropertymapper.h"
 class MappedSelectionModel;
 class QAbstractItemView;
 #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:
   void mapProperty(int column, int role, QObject *target, const QByteArray &property);
 
 public slots:
+  QModelIndex currentIndex();
   void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
   void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
-  void selectBuffer(Buffer *buffer);
 
 signals:
 
 signals:
-  void bufferSelected(Buffer *);
   void selectionChanged(const QModelIndex &);
 
 private:
   QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
   QPointer<ModelPropertyMapper> _propertyMapper;
   void selectionChanged(const QModelIndex &);
 
 private:
   QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
   QPointer<ModelPropertyMapper> _propertyMapper;
-  Buffer *currentBuffer;
+  BufferId currentBuffer;
 };
 
 #endif // BUFFERMODEL_H
 };
 
 #endif // BUFFERMODEL_H
index 3c5de53..49c45f4 100644 (file)
@@ -70,15 +70,10 @@ void Client::init() {
   blockSize = 0;
 
   _networkModel = new NetworkModel(this);
   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 &)),
 
   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(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;
     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;
 }
 
   }
   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;
 }
 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(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) {
   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();
   }
     qDebug() << "Network" << networkid << "disconnected while not yet initialized!";
     updateCoreConnectionProgress();
   }
-}
-
-void Client::ircChannelAdded(QString chanName) {
-  Network *netInfo = qobject_cast<Network*>(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) {
 }
 
 void Client::updateBufferInfo(BufferInfo id) {
-  buffer(id)->updateBufferInfo(id);
+  emit bufferUpdated(id);
 }
 
 void Client::bufferDestroyed() {
   Buffer *buffer = static_cast<Buffer *>(sender());
 }
 
 void Client::bufferDestroyed() {
   Buffer *buffer = static_cast<Buffer *>(sender());
-  uint bufferUid = buffer->uid();
-  if(_buffers.contains(bufferUid))
-    _buffers.remove(bufferUid);
+  QHash<BufferId, Buffer *>::iterator iter = _buffers.begin();
+  while(iter != _buffers.end()) {
+    if(iter.value() == buffer) {
+      iter = _buffers.erase(iter);
+      break;
+    }
+    iter++;
+  }
 }
 
 void Client::networkDestroyed() {
 }
 
 void Client::networkDestroyed() {
@@ -580,14 +549,14 @@ void Client::networkDestroyed() {
 void Client::recvMessage(const Message &msg) {
   Buffer *b = buffer(msg.buffer());
 
 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);
 }
 
   b->appendMsg(msg);
 }
index 53ad0b5..3334792 100644 (file)
@@ -58,8 +58,6 @@ public:
   static QList<Buffer *> buffers();
   static Buffer *buffer(uint bufferUid);
   static Buffer *buffer(BufferInfo);
   static QList<Buffer *> buffers();
   static Buffer *buffer(uint bufferUid);
   static Buffer *buffer(BufferInfo);
-  static BufferInfo statusBufferInfo(QString net);
-  static BufferInfo bufferInfo(QString net, QString buf);
 
   static QList<IdentityId> identityIds();
   static const Identity * identity(IdentityId);
 
   static QList<IdentityId> identityIds();
   static const Identity * identity(IdentityId);
@@ -102,9 +100,7 @@ public:
 signals:
   void sendInput(BufferInfo, QString message);
   void showBuffer(Buffer *);
 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<Message>);
   void requestBacklog(BufferInfo, QVariant, QVariant);
   void requestNetworkStates();
   void backlogReceived(Buffer *, QList<Message>);
   void requestBacklog(BufferInfo, QVariant, QVariant);
   void requestNetworkStates();
@@ -176,7 +172,6 @@ private slots:
 
   void bufferDestroyed();
   void networkDestroyed();
 
   void bufferDestroyed();
   void networkDestroyed();
-  void ircChannelAdded(QString);
   void coreIdentityCreated(const Identity &);
   void coreIdentityRemoved(IdentityId);
 
   void coreIdentityCreated(const Identity &);
   void coreIdentityRemoved(IdentityId);
 
index 6c2426d..7320820 100644 (file)
@@ -18,8 +18,6 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#include <QColor>  // FIXME Dependency on QtGui!
-
 #include "networkmodel.h"
 
 #include <QAbstractItemView>
 #include "networkmodel.h"
 
 #include <QAbstractItemView>
 #include "ircchannel.h"
 #include "ircuser.h"
 
 #include "ircchannel.h"
 #include "ircuser.h"
 
+#include "util.h" // get rid of this (needed for isChannelName)
+
 /*****************************************
 *  Fancy Buffer Items
 *****************************************/
 /*****************************************
 *  Fancy Buffer Items
 *****************************************/
-BufferItem::BufferItem(Buffer *buffer, AbstractTreeItem *parent)
+BufferItem::BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent)
   : PropertyMapItem(QStringList() << "bufferName" << "topic" << "nickCount", 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;
   Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
-  if(buf->bufferType() == Buffer::QueryType)
+  if(bufferType() == QueryType)
     flags |= Qt::ItemIsDropEnabled;
   setFlags(flags);
 }
 
     flags |= Qt::ItemIsDropEnabled;
   setFlags(flags);
 }
 
+
+const BufferInfo &BufferItem::bufferInfo() const {
+  return _bufferInfo;
+}
+
 quint64 BufferItem::id() const {
 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;
 }
 
 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:
   case NetworkModel::NetworkIdRole:
-    return buf->bufferInfo().networkId();
+    return bufferInfo().networkId();
   case NetworkModel::BufferTypeRole:
   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);
   }
   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 *)));
          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 {
 }
 
 QString BufferItem::bufferName() const {
-  return buf->name();
+  if(bufferType() == StatusType)
+    return tr("Status Buffer");
+  else
+    return bufferInfo().buffer();
 }
 
 QString BufferItem::topic() const {
 }
 
 QString BufferItem::topic() const {
@@ -153,6 +185,8 @@ QVariant NetworkItem::data(int column, int role) const {
     return _networkId;
   case NetworkModel::ItemTypeRole:
     return NetworkModel::NetworkItemType;
     return _networkId;
   case NetworkModel::ItemTypeRole:
     return NetworkModel::NetworkItemType;
+  case NetworkModel::ItemActiveRole:
+    return isActive();
   default:
     return PropertyMapItem::data(column, role);
   }
   default:
     return PropertyMapItem::data(column, role);
   }
@@ -162,6 +196,10 @@ quint64 NetworkItem::id() const {
   return _networkId;
 }
 
   return _networkId;
 }
 
+bool NetworkItem::isActive() const {
+  return _network;
+}
+
 QString NetworkItem::networkName() const {
   if(_network)
     return _network->networkName();
 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<BufferItem *>(index.internalPointer());
 
 Buffer *NetworkModel::getBufferByIndex(const QModelIndex &index) const {
   BufferItem *item = static_cast<BufferItem *>(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;
 }
 
   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) {
 }
 
 BufferItem *NetworkModel::buffer(BufferInfo bufferInfo) {
-  QModelIndex bufferIdx = bufferIndex(bufferInfo);
+  QModelIndex bufferIdx = bufferIndex(bufferInfo.uid());
   if(bufferIdx.isValid())
     return static_cast<BufferItem *>(bufferIdx.internalPointer());
   else
   if(bufferIdx.isValid())
     return static_cast<BufferItem *>(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());
   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);
   }
 
     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());
   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;
     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
     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<uint, uint> > bufferList = mimeDataToBufferList(data);
     return false;
 
   QList< QPair<uint, uint> > 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)
   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
     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!
     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;
   removeRow(parent.row(), parent.parent());
   
   return true;
@@ -435,19 +471,19 @@ void NetworkModel::attachNetwork(Network *net) {
   networkItem->attachNetwork(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);
 }
 
   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);
 }
 
 }
 
index e15cdd8..09e1bd2 100644 (file)
@@ -48,8 +48,9 @@ class BufferItem : public PropertyMapItem {
   Q_PROPERTY(int nickCount READ nickCount)
 
 public:
   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;
 
   virtual quint64 id() const;
   virtual QVariant data(int column, int role) const;
 
@@ -59,23 +60,45 @@ public:
   QString topic() const;
   int nickCount() const;
 
   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);
 
 public slots:
   void setTopic(const QString &topic);
   void join(IrcUser *ircUser);
   void part(IrcUser *ircUser);
+
+private slots:
+  void ircChannelDestroyed();
   
 private:
   
 private:
-  QColor foreground(int column) const;
-
-  Buffer *buf;
-  Buffer::ActivityLevel activity;
+  BufferInfo _bufferInfo;
+  ActivityLevel _activity;
+  Type _type;
 
   QPointer<IrcChannel> _ircChannel;
 };
 
   QPointer<IrcChannel> _ircChannel;
 };
+Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
 
 /*****************************************
  *  Network Items
 
 /*****************************************
  *  Network Items
@@ -92,6 +115,8 @@ public:
   virtual QVariant data(int column, int row) const;
   virtual quint64 id() const;
 
   virtual QVariant data(int column, int row) const;
   virtual quint64 id() const;
 
+  bool isActive() const;
+  
   QString networkName() const;
   QString currentServer() const;
   int nickCount() const;
   QString networkName() const;
   QString currentServer() const;
   int nickCount() const;
@@ -140,8 +165,8 @@ class NetworkModel : public TreeModel {
 public:
   enum myRoles {
     BufferTypeRole = Qt::UserRole,
 public:
   enum myRoles {
     BufferTypeRole = Qt::UserRole,
-    BufferActiveRole,
-    BufferUidRole,
+    ItemActiveRole,
+    BufferIdRole,
     NetworkIdRole,
     ItemTypeRole
   };
     NetworkIdRole,
     ItemTypeRole
   };
@@ -168,11 +193,11 @@ public:
 
   bool isBufferIndex(const QModelIndex &) const;
   Buffer *getBufferByIndex(const QModelIndex &) const;
 
   bool isBufferIndex(const QModelIndex &) const;
   Buffer *getBufferByIndex(const QModelIndex &) const;
-  QModelIndex bufferIndex(BufferInfo bufferInfo);
+  QModelIndex bufferIndex(BufferId bufferId);
 
 public slots:
 
 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);
 
 private:
   QModelIndex networkIndex(uint networkId);
index ec6ce7a..e560a77 100644 (file)
@@ -380,14 +380,20 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int rol
 
 void TreeModel::itemDataChanged(int column) {
   AbstractTreeItem *item = qobject_cast<AbstractTreeItem *>(sender());
 
 void TreeModel::itemDataChanged(int column) {
   AbstractTreeItem *item = qobject_cast<AbstractTreeItem *>(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) {
 }
 
 void TreeModel::appendChild(AbstractTreeItem *parent, AbstractTreeItem *child) {
index 52ab5c5..d306e38 100644 (file)
@@ -67,7 +67,7 @@ public:
   AbstractTreeItem *parent();
 
 signals:
   AbstractTreeItem *parent();
 
 signals:
-  void dataChanged(int column);
+  void dataChanged(int column = -1);
   void newChild(AbstractTreeItem *);
   void childDestroyed(int row);
                                       
   void newChild(AbstractTreeItem *);
   void childDestroyed(int row);
                                       
@@ -148,7 +148,7 @@ public:
   virtual void clear();
 
 private slots:
   virtual void clear();
 
 private slots:
-  void itemDataChanged(int column);
+  void itemDataChanged(int column = -1);
   void newChild(AbstractTreeItem *child);
   void childDestroyed(int row);
 
   void newChild(AbstractTreeItem *child);
   void childDestroyed(int row);
 
index 82189ae..0597adc 100644 (file)
@@ -21,6 +21,7 @@
 #define _BUFFERINFO_H_
 
 #include <QtCore>
 #define _BUFFERINFO_H_
 
 #include <QtCore>
+#include "types.h"
 
 class QString;
 class QDataStream;
 
 class QString;
 class QDataStream;
@@ -30,8 +31,8 @@ public:
   BufferInfo();
   BufferInfo(uint id, uint networkid, uint gid = 0, QString net = QString(), QString buf = QString());
   
   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;
   inline uint groupId() const { return _gid; }
   inline QString network() const { return _networkName; }
   QString buffer() const;
index 12f70c2..1e567b5 100644 (file)
@@ -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 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();
   }
 }
 
   }
 }
 
index fc501c2..cf6ae83 100644 (file)
 #include "chatline-old.h"
 #include "chatwidget.h"
 #include "settings.h"
 #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.setupUi(this);
+  ui.ownNick->clear();  // TODO add nick history
   connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
 }
 
   connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
 }
 
@@ -34,65 +39,53 @@ void BufferWidget::init() {
 }
 
 BufferWidget::~BufferWidget() {
 }
 
 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;
   ChatWidget *chatWidget;
-  if(_chatWidgets.contains(buf)) {
-     chatWidget = _chatWidgets[buf];
+  if(_chatWidgets.contains(bufferId)) {
+     chatWidget = _chatWidgets[bufferId];
   } else {
   } else {
+    Buffer *buf = Client::buffer(bufferId);
+    if(!buf) {
+      qWarning() << "BufferWidget::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
+      return;
+    }
     chatWidget = new ChatWidget(this);
     chatWidget = new ChatWidget(this);
-    chatWidget->init(buf->networkName(), buf->name());
+    chatWidget->init(bufferId);
     QList<ChatLine *> lines;
     QList<AbstractUiMsg *> msgs = buf->contents();
     foreach(AbstractUiMsg *msg, msgs) {
       lines.append(dynamic_cast<ChatLine*>(msg));
     }
     chatWidget->setContents(lines);
     QList<ChatLine *> lines;
     QList<AbstractUiMsg *> msgs = buf->contents();
     foreach(AbstractUiMsg *msg, msgs) {
       lines.append(dynamic_cast<ChatLine*>(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 *)));
     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);
     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();
   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() {
 }
 
 void BufferWidget::saveState() {
-
 }
 
 QSize BufferWidget::sizeHint() const {
 }
 
 QSize BufferWidget::sizeHint() const {
@@ -108,14 +101,6 @@ void BufferWidget::enterPressed() {
   ui.inputEdit->clear();
 }
 
   ui.inputEdit->clear();
 }
 
-void BufferWidget::setActive(bool act) {
-  if(act != active) {
-    active = act;
-    //renderContents();
-    //scrollToEnd();
-  }
-}
-
 
 
 /*
 
 
 /*
index 72ece0d..980d0de 100644 (file)
@@ -26,7 +26,6 @@
 #include "chatview.h"
 #include "types.h"
 
 #include "chatview.h"
 #include "types.h"
 
-class Buffer;
 class ChatView;
 class ChatWidget;
 class LayoutThread;
 class ChatView;
 class ChatWidget;
 class LayoutThread;
@@ -37,6 +36,8 @@ class LayoutThread;
 class BufferWidget : public QWidget {
   Q_OBJECT
 
 class BufferWidget : public QWidget {
   Q_OBJECT
 
+  Q_PROPERTY(uint currentBuffer READ currentBuffer WRITE setCurrentBuffer)
+    
 public:
   BufferWidget(QWidget *parent = 0);
   virtual ~BufferWidget();
 public:
   BufferWidget(QWidget *parent = 0);
   virtual ~BufferWidget();
@@ -49,23 +50,18 @@ signals:
   void aboutToClose();
 
 public slots:
   void aboutToClose();
 
 public slots:
-  void setBuffer(Buffer *);
+  BufferId currentBuffer() const;
+  void setCurrentBuffer(BufferId bufferId);
   void saveState();
 
 private slots:
   void enterPressed();
   void saveState();
 
 private slots:
   void enterPressed();
-  void setActive(bool act = true);
-  void bufferDestroyed(QObject *);
-
+  void removeBuffer(BufferId bufferId);
 
 private:
   Ui::BufferWidget ui;
 
 private:
   Ui::BufferWidget ui;
-  //QHash<BufferId, ChatView*> _chatViews;
-  QHash<Buffer *, ChatWidget *> _chatWidgets;
-  bool active;
-
-  QString _networkName;
-  QString _bufferName;
+  QHash<BufferId, ChatWidget *> _chatWidgets;
+  BufferId _currentBuffer;
 };
 
 
 };
 
 
index 098961d..520b2b9 100644 (file)
@@ -45,16 +45,15 @@ ChatWidget::ChatWidget(QWidget *parent) : QAbstractScrollArea(parent) {
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrollBarValChanged(int)));
 }
 
   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);
   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());
   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);
   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 {
 }
 
 QSize ChatWidget::sizeHint() const {
index 0bd51ca..8e32783 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <QtGui>
 
 
 #include <QtGui>
 
+#include "types.h"
+
 class ChatLine;
 class AbstractUiMsg;
 
 class ChatLine;
 class AbstractUiMsg;
 
@@ -43,7 +45,7 @@ class ChatWidget : public QAbstractScrollArea {
   public:
     ChatWidget(QWidget *parent = 0);
     ~ChatWidget();
   public:
     ChatWidget(QWidget *parent = 0);
     ~ChatWidget();
-    void init(QString net, QString buf);
+    void init(BufferId id);
 
     virtual QSize sizeHint() const;
 
 
     virtual QSize sizeHint() const;
 
@@ -75,7 +77,7 @@ class ChatWidget : public QAbstractScrollArea {
     void handleScrollTimer();
 
   private:
     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 };
     enum SelectionMode { NoSelection, TextSelected, LinesSelected };
     enum MouseMode { Normal, Pressed, DragTsSep, DragTextSep, MarkText, MarkLines };
     enum MousePos { None, OverTsSep, OverTextSep, OverUrl };
index dfef33c..1ad3141 100644 (file)
@@ -125,6 +125,16 @@ void MainWin::init() {
 
   ui.menuViews->addAction(dock->toggleViewAction());
 
 
   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
 #ifdef SPUTDEV
   showSettingsDlg();
 #endif
@@ -159,9 +169,7 @@ void MainWin::setupMenus() {
 }
 
 void MainWin::setupViews() {
 }
 
 void MainWin::setupViews() {
-  
   BufferModel *model = Client::bufferModel();
   BufferModel *model = Client::bufferModel();
-  connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
 
   addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QList<uint>());
   addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QList<uint>());
 
   addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QList<uint>());
   addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QList<uint>());
@@ -169,18 +177,6 @@ void MainWin::setupViews() {
   addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QList<uint>());
   addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QList<uint>());
 
   addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QList<uint>());
   addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QList<uint>());
 
-//   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();
 }
 
   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);
   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);
 
   //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);
   view->setFilteredModel(model, mode, nets);
   Client::bufferModel()->synchronizeView(view);
   dock->setWidget(view);
+  dock->show();
 
   addDockWidget(Qt::LeftDockWidgetArea, dock);
   ui.menuViews->addAction(dock->toggleViewAction());
 
   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::setupSettingsDlg() {
   settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg));
   settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg));
-
 }
 
 void MainWin::connectedToCore() {
 }
 
 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);
-}
index 5763809..fc0ba02 100644 (file)
@@ -64,9 +64,6 @@ class MainWin : public QMainWindow {
     void showCoreConnectionDlg(bool autoConnect = false);
     void coreConnectionDlgFinished(int result);
 
     void showCoreConnectionDlg(bool autoConnect = false);
     void coreConnectionDlgFinished(int result);
 
-    void showBuffer(BufferInfo);
-    void showBuffer(Buffer *);
-
   signals:
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
   signals:
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
index 490f9b6..df14b46 100644 (file)
 
 #include "buffer.h"
 #include "nickview.h"
 
 #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);
   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;
   }
     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 {
   } 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();
 }
 
   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();
 }
 }
index e09ff33..4e8ac8d 100644 (file)
@@ -22,6 +22,7 @@
 #define _NICKLISTWIDGET_H_
 
 #include "ui_nicklistwidget.h"
 #define _NICKLISTWIDGET_H_
 
 #include "ui_nicklistwidget.h"
+#include "types.h"
 
 #include <QHash>
 
 
 #include <QHash>
 
@@ -31,20 +32,24 @@ class NickView;
 class NickListWidget : public QWidget {
   Q_OBJECT
 
 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<Buffer *, NickView *> 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<BufferId, NickView *> nickViews;
+  BufferId _currentBuffer;
+  
 };
 
 #endif
 };
 
 #endif
index 426c272..5374338 100644 (file)
@@ -19,7 +19,7 @@
  ***************************************************************************/
 
 #include "client.h"
  ***************************************************************************/
 
 #include "client.h"
-#include "buffer.h"
+//#include "buffer.h"
 #include "bufferview.h"
 #include "networkmodel.h"
 
 #include "bufferview.h"
 #include "networkmodel.h"
 
@@ -82,9 +82,9 @@ void BufferView::setModel(QAbstractItemModel *model) {
 }
 
 void BufferView::joinChannel(const QModelIndex &index) {
 }
 
 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()));
     return;
   
   Client::fakeInput(index.data(NetworkModel::BufferUidRole).toUInt(), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));
index 4204ac0..139ca89 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "bufferviewfilter.h"
 
 
 #include "bufferviewfilter.h"
 
+#include <QColor>
+
 #include "networkmodel.h"
 
 /*****************************************
 #include "networkmodel.h"
 
 /*****************************************
@@ -110,13 +112,13 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) {
 
 
 bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const {
 
 
 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;
     return false;
-  if((mode & NoQueries) && bufferType == Buffer::QueryType)
+  if((mode & NoQueries) && bufferType == BufferItem::QueryType)
     return false;
     return false;
-  if((mode & NoServers) && bufferType == Buffer::StatusType)
+  if((mode & NoServers) && bufferType == BufferItem::StatusType)
     return false;
 
 //   bool isActive = source_bufferIndex.data(NetworkModel::BufferActiveRole).toBool();
     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);
 }
 
     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);
+}
index c6b53cc..d20445d 100644 (file)
@@ -25,7 +25,7 @@
 #include <QDropEvent>
 #include <QSortFilterProxyModel>
 #include <QSet>
 #include <QDropEvent>
 #include <QSortFilterProxyModel>
 #include <QSet>
-#include "buffer.h"
+// #include "buffer.h"
 
 /*****************************************
  * Buffer View Filter
 
 /*****************************************
  * 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);
   
   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_();
 public slots:
   void removeBuffer(const QModelIndex &);
   void invalidateFilter_();
index f6d7171..7511e07 100644 (file)
 
 #include "tabcompleter.h"
 
 
 #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(returnPressed()), this, SLOT(enter()));
   tabComplete = new TabCompleter(this);
-  connect(this, SIGNAL(nickListUpdated(QStringList)), tabComplete, SLOT(updateNickList(QStringList)));
 }
 
 InputLine::~InputLine() {
 }
 
 InputLine::~InputLine() {
-  delete tabComplete;
 }
 
 void InputLine::keyPressEvent(QKeyEvent * event) {
 }
 
 void InputLine::keyPressEvent(QKeyEvent * event) {
@@ -38,7 +38,7 @@ void InputLine::keyPressEvent(QKeyEvent * event) {
     tabComplete->complete();
     event->accept();
   } else {
     tabComplete->complete();
     event->accept();
   } else {
-    tabComplete->disable();
+    tabComplete->reset();
     if(event->key() == Qt::Key_Up) {
       if(idx > 0) { idx--; setText(history[idx]); }
       event->accept();
     if(event->key() == Qt::Key_Up) {
       if(idx > 0) { idx--; setText(history[idx]); }
       event->accept();
index b892292..fe4b9e7 100644 (file)
@@ -35,8 +35,8 @@ NickView::NickView(QWidget *parent) : QTreeView(parent) {
   setSortingEnabled(true);
   sortByColumn(0, Qt::AscendingOrder);
 
   setSortingEnabled(true);
   sortByColumn(0, Qt::AscendingOrder);
 
-  filteredModel = new FilteredNickModel(this);
-  QTreeView::setModel(filteredModel);
+//   filteredModel = new FilteredNickModel(this);
+//   QTreeView::setModel(filteredModel);
 }
 
 NickView::~NickView() {
 }
 
 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);
 
 void NickView::rowsInserted(const QModelIndex &index, int start, int end) {
   QTreeView::rowsInserted(index, start, end);
index 54313ac..70206cb 100644 (file)
@@ -37,11 +37,11 @@ class NickView : public QTreeView {
   protected:
     void rowsInserted(const QModelIndex &, int, int);
 
   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;
 
 };
 
 
 };
 
index e4d0e60..60a74fb 100644 (file)
 
 #include "tabcompleter.h"
 
 
 #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
 }
 
 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();
   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();
     }
   }
   completionList.sort();
   nextCompletion = completionList.begin();
   lastCompletionLength = tabAbbrev.length();
+  
+}
+
+void TabCompleter::ircUserJoinedOrParted(IrcUser *ircUser) {
+  Q_UNUSED(ircUser)
+  buildCompletionList();
 }
 
 void TabCompleter::complete() {
 }
 
 void TabCompleter::complete() {
-  if (! enabled) {
+  if(!enabled) {
     buildCompletionList();
     buildCompletionList();
-    enabled = true;  
+    enabled = true;
   }
   
   if (nextCompletion != completionList.end()) {
     // clear previous completion
     for (int i = 0; i < lastCompletionLength; i++) {
   }
   
   if (nextCompletion != completionList.end()) {
     // clear previous completion
     for (int i = 0; i < lastCompletionLength; i++) {
-      lineEdit->backspace();
+      inputLine->backspace();
     }
     
     // insert completion
     }
     
     // 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
     
     // 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
     }
 
   // 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;
 }
 
   enabled = false;
 }
 
index 00560dc..b223fe6 100644 (file)
 #ifndef _TABCOMPLETER_H_
 #define _TABCOMPLETER_H_
 
 #ifndef _TABCOMPLETER_H_
 #define _TABCOMPLETER_H_
 
-#include <QtCore>
 #include <QObject>
 #include <QObject>
-#include <QLineEdit>
+#include <QStringList>
+#include <QPointer>
+
+class InputLine;
+class IrcUser;
 
 class TabCompleter : public QObject {
   Q_OBJECT
   
 
 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> 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
 };
 
 #endif