From: Marcus Eggenberger Date: Sat, 20 Oct 2007 17:21:34 +0000 (+0000) Subject: Started to reorganize the Buffer{Model|View|Filter}. Mostly cleanup at the moment. X-Git-Tag: 0.1.0~108 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=8a618fb4514d83a76cec8e7cd1319b935366a616 Started to reorganize the Buffer{Model|View|Filter}. Mostly cleanup at the moment. Added a static Method Client::fakeInput(BufferId, Message) to help easy automation of stuff like joining channels. --- diff --git a/src/client/buffertreemodel.cpp b/src/client/buffertreemodel.cpp index 568f7e6c..26612f97 100644 --- a/src/client/buffertreemodel.cpp +++ b/src/client/buffertreemodel.cpp @@ -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 ¤t, 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(getOrCreateBufferItemIndex(buffer).internalPointer()); if(buffer != currentBuffer) diff --git a/src/client/buffertreemodel.h b/src/client/buffertreemodel.h index 7053ef75..602cf57d 100644 --- a/src/client/buffertreemodel.h +++ b/src/client/buffertreemodel.h @@ -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: diff --git a/src/client/client.cpp b/src/client/client.cpp index 73316ca4..4a6111ee 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -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; diff --git a/src/client/client.h b/src/client/client.h index fabed9d6..7970651f 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -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(); diff --git a/src/qtui/bufferview.cpp b/src/qtui/bufferview.cpp index b5460db2..c57737f2 100644 --- a/src/qtui/bufferview.cpp +++ b/src/qtui/bufferview.cpp @@ -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(); diff --git a/src/qtui/bufferview.h b/src/qtui/bufferview.h index 8a130d68..0c06cafa 100644 --- a/src/qtui/bufferview.h +++ b/src/qtui/bufferview.h @@ -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); }; diff --git a/src/qtui/bufferviewfilter.cpp b/src/qtui/bufferviewfilter.cpp index 8dca8fa2..84dc447c 100644 --- a/src/qtui/bufferviewfilter.cpp +++ b/src/qtui/bufferviewfilter.cpp @@ -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; } diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index a16807f0..0d9cb250 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -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() { diff --git a/src/qtui/topicwidget.h b/src/qtui/topicwidget.h index d6c1ab9c..deb5f902 100644 --- a/src/qtui/topicwidget.h +++ b/src/qtui/topicwidget.h @@ -27,11 +27,14 @@ 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;