Started to reorganize the Buffer{Model|View|Filter}. Mostly cleanup at the moment.
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 20 Oct 2007 17:21:34 +0000 (17:21 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 20 Oct 2007 17:21:34 +0000 (17:21 +0000)
Added a static Method Client::fakeInput(BufferId, Message) to help easy automation of stuff like joining channels.

src/client/buffertreemodel.cpp
src/client/buffertreemodel.h
src/client/client.cpp
src/client/client.h
src/qtui/bufferview.cpp
src/qtui/bufferview.h
src/qtui/bufferviewfilter.cpp
src/qtui/topicwidget.cpp
src/qtui/topicwidget.h

index 568f7e6..26612f9 100644 (file)
@@ -79,10 +79,10 @@ QVariant BufferTreeItem::data(int column, int role) const {
     case BufferTreeModel::BufferNameRole:
       return buf->bufferName();
     case BufferTreeModel::BufferTypeRole:
-      return buf->bufferType();
+      return int(buf->bufferType());
     case BufferTreeModel::BufferActiveRole:
       return buf->isActive();
-    case BufferTreeModel::BufferInfoRole:
+    case BufferTreeModel::BufferUidRole:
       return buf->bufferInfo().uid();
     default:
       return QVariant();
@@ -238,15 +238,6 @@ void BufferTreeModel::changeCurrent(const QModelIndex &current, const QModelInde
   }
 }
 
-// we received a double click on a buffer, so we're going to join it
-void BufferTreeModel::doubleClickReceived(const QModelIndex &clicked) {
-  if(isBufferIndex(clicked)) {
-    Buffer *buffer = getBufferByIndex(clicked);
-    if(!buffer->isStatusBuffer()) 
-      emit fakeUserInput(buffer->bufferInfo(), QString("/join " + buffer->bufferName()));
-  }
-}
-
 void BufferTreeModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buffer) {
   BufferTreeItem *bufferItem = static_cast<BufferTreeItem*>(getOrCreateBufferItemIndex(buffer).internalPointer());
   if(buffer != currentBuffer)
index 7053ef7..602cf57 100644 (file)
@@ -79,7 +79,7 @@ public:
     BufferTypeRole = Qt::UserRole,
     BufferActiveRole,
     BufferNameRole,
-    BufferInfoRole
+    BufferUidRole
   };
   
   BufferTreeModel(QObject *parent = 0);
@@ -89,7 +89,6 @@ public slots:
   void bufferUpdated(Buffer *);    
   void changeCurrent(const QModelIndex &, const QModelIndex &);
   void selectBuffer(Buffer *buffer);
-  void doubleClickReceived(const QModelIndex &);
   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
   
 signals:
index 73316ca..4a6111e 100644 (file)
@@ -196,6 +196,18 @@ bool Client::isConnected() {
   return instance()->connectedToCore;
 }
 
+void Client::fakeInput(uint bufferUid, QString message) {
+  Buffer *buff = buffer(bufferUid);
+  if(!buff)
+    qWarning() << "No Buffer with uid" << bufferUid << "can't send Input" << message;
+  else
+    emit instance()->sendInput(buff->bufferInfo(), message);
+}
+
+void Client::fakeInput(BufferInfo bufferInfo, QString message) {
+  fakeInput(bufferInfo, message);
+}
+
 void Client::connectToCore(const QVariantMap &conn) {
   // TODO implement SSL
   coreConnectionInfo = conn;
index fabed9d..7970651 100644 (file)
@@ -66,6 +66,9 @@ public:
 
   static bool isConnected();
 
+  static void fakeInput(uint bufferUid, QString message);
+  static void fakeInput(BufferInfo bufferInfo, QString message);
+  
   static void storeSessionData(const QString &key, const QVariant &data);
   static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
   static QStringList sessionDataKeys();
index b5460db..c57737f 100644 (file)
@@ -18,7 +18,9 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include "client.h"
 #include "bufferview.h"
+#include "buffertreemodel.h"
 
 /*****************************************
 * The TreeView showing the Buffers
@@ -46,15 +48,13 @@ void BufferView::init() {
   connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
           model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
   
-  connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
-          model(), SLOT(doubleClickReceived(const QModelIndex &)));
-  
   connect(model(), SIGNAL(selectionChanged(const QModelIndex &)),
           this, SLOT(select(const QModelIndex &)));
   
   connect(this, SIGNAL(selectionChanged(const QModelIndex &, QItemSelectionModel::SelectionFlags)),
           selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
 
+  connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
 }
 
 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
@@ -83,6 +83,15 @@ void BufferView::dropEvent(QDropEvent *event) {
   QTreeView::dropEvent(event);    
 }
 
+void BufferView::joinChannel(const QModelIndex &index) {
+  Buffer::Type bufferType = (Buffer::Type)index.data(BufferTreeModel::BufferTypeRole).toInt();
+
+  if(bufferType != Buffer::ChannelBuffer)
+    return;
+  
+  Client::fakeInput(index.data(BufferTreeModel::BufferUidRole).toUInt(), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));
+}
+
 void BufferView::keyPressEvent(QKeyEvent *event) {
   if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
     event->accept();
index 8a130d6..0c06caf 100644 (file)
@@ -46,8 +46,9 @@ signals:
   void removeBuffer(const QModelIndex &);
   void selectionChanged(const QModelIndex &, QItemSelectionModel::SelectionFlags);
   
-protected:
+private slots:
   void dropEvent(QDropEvent *);
+  void joinChannel(const QModelIndex &index);
   void keyPressEvent(QKeyEvent *);
   void rowsInserted (const QModelIndex & parent, int start, int end);
 };
index 8dca8fa..84dc447 100644 (file)
@@ -37,9 +37,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, const Modes &filte
   
   connect(this, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
           model, SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
-  
-  connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
-          model, SLOT(doubleClickReceived(const QModelIndex &)));
 }
 
 void BufferViewFilter::invalidateMe() {
@@ -99,7 +96,7 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) {
   if(index.parent() == QModelIndex())
     return; // only child elements can be deleted
   
-  uint bufferuid = index.data(BufferTreeModel::BufferInfoRole).toUInt();
+  uint bufferuid = index.data(BufferTreeModel::BufferUidRole).toUInt();
   if(customBuffers.contains(bufferuid)) {
     beginRemoveRows(index.parent(), index.row(), index.row());
     customBuffers.removeAt(customBuffers.indexOf(bufferuid));
@@ -121,7 +118,7 @@ bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex)
   if((mode & NoInactive) && !isActive) return false;
 
   if((mode & FullCustom)) {
-    uint bufferuid = source_bufferIndex.data(BufferTreeModel::BufferInfoRole).toUInt();
+    uint bufferuid = source_bufferIndex.data(BufferTreeModel::BufferUidRole).toUInt();
     if(!customBuffers.contains(bufferuid))
       return false;
   }
@@ -138,7 +135,7 @@ bool BufferViewFilter::filterAcceptNetwork(const QModelIndex &source_index) cons
     int childcount = sourceModel()->rowCount(source_index);
     for(int rowid = 0; rowid < childcount; rowid++) {
       QModelIndex child = sourceModel()->index(rowid, 0, source_index);
-      uint bufferuid = child.data(BufferTreeModel::BufferInfoRole).toUInt();
+      uint bufferuid = child.data(BufferTreeModel::BufferUidRole).toUInt();
       if(customBuffers.contains(bufferuid))
         return true;
     }
index a16807f..0d9cb25 100644 (file)
@@ -26,7 +26,14 @@ TopicWidget::TopicWidget(QWidget *parent)
   : QWidget(parent)
 {
   ui.setupUi(this);
-  ui.topicLineEdit->setText("+++ DUMMY TOPIC +++ DUMMY TOPIC +++");
+}
+
+QString TopicWidget::topic() const {
+  return ui.topicLineEdit->text();
+}
+
+void TopicWidget::setTopic(const QString &newtopic) {
+  ui.topicLineEdit->setText(newtopic);
 }
 
 TopicWidget::~TopicWidget() {
index d6c1ab9..deb5f90 100644 (file)
 
 class TopicWidget : public QWidget {
   Q_OBJECT
+  Q_PROPERTY(QString topic READ topic WRITE setTopic STORED false)
 
 public:
   TopicWidget(QWidget *parent = 0);
   virtual ~TopicWidget();
 
+  QString topic() const;
+  void setTopic(const QString &newtopic);
   
 private:
   Ui::TopicWidget ui;