ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00195
[Branch ~agateau/plasma-indicatordisplay/trunk] Rev 83: Implemented server-type filtering in ListenerModel.
------------------------------------------------------------
revno: 83
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-indicatordisplay
timestamp: Tue 2009-09-15 15:56:48 +0200
message:
Implemented server-type filtering in ListenerModel.
Filter model does not work as it should.
modified:
src/indicatordisplay.cpp
src/listenermodel.cpp
src/listenermodel.h
--
lp:plasma-indicatordisplay
https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk
Your team ayatana-commits is subscribed to branch lp:plasma-indicatordisplay.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk/+edit-subscription.
=== modified file 'src/indicatordisplay.cpp'
--- src/indicatordisplay.cpp 2009-09-15 13:48:42 +0000
+++ src/indicatordisplay.cpp 2009-09-15 13:56:48 +0000
@@ -27,7 +27,7 @@
#include "view.h"
//#define DUMP_MODELS
-#define USE_FILTER
+//#define USE_FILTER
static const char* NO_NEW_STUFF_ICON = "mail-unread";
static const char* NEW_STUFF_ICON = "mail-unread-new";
@@ -85,7 +85,7 @@
void IndicatorDisplay::initSourceModel()
{
- mSourceModel = new ListenerModel(mListener);
+ mSourceModel = new ListenerModel(mListener, "messaging");
connect(mSourceModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
SLOT(slotRowsChanged(const QModelIndex&))
);
=== modified file 'src/listenermodel.cpp'
--- src/listenermodel.cpp 2009-09-15 12:16:56 +0000
+++ src/listenermodel.cpp 2009-09-15 13:56:48 +0000
@@ -36,11 +36,17 @@
typedef QPair<QIndicate::Listener::Server*, QIndicate::Listener::Indicator*> ServerIndicatorPair;
typedef QHash<ServerIndicatorPair, QStandardItem*> ItemForIndicatorHash;
+typedef QSet<QIndicate::Listener::Indicator*> IndicatorSet;
struct ListenerModelPrivate
{
ListenerModel* q;
QIndicate::Listener* mListener;
+ QString mAcceptedServerType;
+ // Servers and indicators we have received, but for which server type is
+ // either unknown or does not match mAcceptedServerType (we keep them in to
+ // avoid asking the server type again and again when indicators change)
+ QHash<QIndicate::Listener::Server*, IndicatorSet> mWaitingServers;
QHash<QIndicate::Listener::Server*, QStandardItem*> mItemForServer;
ItemForIndicatorHash mItemForIndicator;
@@ -72,11 +78,12 @@
}
};
-ListenerModel::ListenerModel(QIndicate::Listener* listener)
+ListenerModel::ListenerModel(QIndicate::Listener* listener, const QString& acceptedServerType)
: d(new ListenerModelPrivate)
{
d->q = this;
d->mListener = listener;
+ d->mAcceptedServerType = acceptedServerType;
connect(d->mListener,
SIGNAL(serverAdded(QIndicate::Listener::Server*, const QString&)),
SLOT(slotServerAdded(QIndicate::Listener::Server*))
@@ -121,12 +128,53 @@
kWarning() << "We already know about server" << server;
return;
}
+
+ if (d->mWaitingServers.contains(server)) {
+ kWarning() << "This server is already in the waiting list" << server;
+ return;
+ }
+
+ d->mWaitingServers.insert(server, IndicatorSet());
+
+ d->mListener->getServerType(server,
+ this,
+ SLOT(slotServerTypeReceived(
+ QIndicate::Listener::Server*,
+ const QByteArray&)
+ )
+ );
+}
+
+void ListenerModel::slotServerTypeReceived(QIndicate::Listener::Server* server, const QByteArray& _type)
+{
+ QString type = QIndicate::Decode::stringFromValue(_type);
+ if (d->mItemForServer.contains(server)) {
+ kError() << "We already display this server" << server;
+ return;
+ }
+
+ if (type != d->mAcceptedServerType) {
+ return;
+ }
+
+ IndicatorSet set;
+ if (d->mWaitingServers.contains(server)) {
+ set = d->mWaitingServers.take(server);
+ } else {
+ kWarning() << "Strange, the server is not in the waiting list" << server;
+ }
+
QStandardItem* item = new QStandardItem;
item->setData(QVariant::fromValue(server), ServerRole);
- item->setData(QVariant(0), IndicatorCountRole);
+ item->setData(type, ServerTypeRole);
d->mItemForServer.insert(server, item);
appendRow(item);
+ // Simulate slotIndicatorAdded for waiting indicators
+ Q_FOREACH(QIndicate::Listener::Indicator* indicator, set) {
+ slotIndicatorAdded(server, indicator);
+ }
+
d->mListener->getServerDesktopFile(server,
this,
SLOT(slotDesktopFileReceived(
@@ -136,6 +184,7 @@
);
}
+
void ListenerModel::slotDesktopFileReceived(QIndicate::Listener::Server* server, const QByteArray& _fileName)
{
QString fileName = QIndicate::Decode::stringFromValue(_fileName);
@@ -146,10 +195,7 @@
}
QStandardItem* item = d->mItemForServer.value(server);
- if (!item) {
- kError() << "No item for server" << server;
- return;
- }
+ Q_ASSERT(item);
item->setText(name);
#ifdef USE_ICONS_FOR_SERVERS
@@ -164,34 +210,15 @@
item->setData(QVariant(icon), Qt::DecorationRole);
}
#endif
-
- d->mListener->getServerType(server,
- this,
- SLOT(slotServerTypeReceived(
- QIndicate::Listener::Server*,
- const QByteArray&)
- )
- );
-}
-
-void ListenerModel::slotServerTypeReceived(QIndicate::Listener::Server* server, const QByteArray& _type)
-{
- QString type = QIndicate::Decode::stringFromValue(_type);
- QStandardItem* item = d->mItemForServer.value(server);
- if (!item) {
- kError() << "No item for server" << server;
- return;
- }
- // HACK: emit layoutAboutToBeChanged() and layoutChanged() because
- // otherwise FilterModel won't tell the view it should show the index
- // children.
- emit layoutAboutToBeChanged();
- item->setData(type, ServerTypeRole);
- emit layoutChanged();
}
void ListenerModel::slotServerRemoved(QIndicate::Listener::Server* server)
{
+ if (d->mWaitingServers.contains(server)) {
+ kDebug() << "Removing server from waiting list" << server;
+ d->mWaitingServers.remove(server);
+ return;
+ }
QStandardItem* item = d->mItemForServer.value(server);
if (!item) {
kWarning() << "No item found for server" << server;
@@ -215,7 +242,12 @@
QStandardItem* serverItem = d->mItemForServer.value(server);
if (!serverItem) {
- kError() << "No item for server" << server;
+ if (!d->mWaitingServers.contains(server)) {
+ kWarning() << "An indicator has been added for a server we don't know about" << server << indicator;
+ slotServerAdded(server);
+ }
+ // We will be called again when the server is ready
+ d->mWaitingServers[server].insert(indicator);
return;
}
@@ -234,7 +266,9 @@
{
QStandardItem* item = d->mItemForIndicator.value(ServerIndicatorPair(server, indicator));
if (!item) {
- kError() << "No item for indicator" << indicator;
+ if (!d->mWaitingServers.contains(server)) {
+ kError() << "No item for indicator" << indicator;
+ }
return;
}
@@ -250,6 +284,10 @@
void ListenerModel::slotIndicatorRemoved(QIndicate::Listener::Server* server,
QIndicate::Listener::Indicator* indicator)
{
+ if (d->mWaitingServers.contains(server)) {
+ d->mWaitingServers[server].remove(indicator);
+ return;
+ }
QStandardItem* item = d->mItemForIndicator.value(ServerIndicatorPair(server, indicator));
if (!item) {
kWarning() << "No item for indicator" << indicator;
=== modified file 'src/listenermodel.h'
--- src/listenermodel.h 2009-09-14 16:23:19 +0000
+++ src/listenermodel.h 2009-09-15 13:56:48 +0000
@@ -22,7 +22,7 @@
{
Q_OBJECT
public:
- ListenerModel(QIndicate::Listener*);
+ ListenerModel(QIndicate::Listener*, const QString& acceptedServerType);
~ListenerModel();
enum AdditionalRoles