[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: Re: [Panel-devel] Applet Manager Dialog
From: Chani <chanika () gmail ! com>
Date: 2007-12-08 6:34:05
Message-ID: 200712081434.14555.chanika () gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
I've got the code updating reliably now. it's still ugly and can't remove
applets.
> > -how do I make the ui addition not horrifically ugly?
>
> you mean visually? providing a link to a screenshot is probably the
> easiest/best way to go.
http://chani.ccdevnet.org/sshots/appletbrowser3.png
I'm kinda thinking that there isn't really space to just toss a 'remove' link
in there without reorganising or resizing stuff a bit...
> the Containment::appletAdded signal. applets themselves emit a signal on
> destruction (being QObjects)
this destruction signal is annoying me; I need to find the applet's name, and
by this point I can't do anything with the pointer I'm handed from the
destroyed() signal.
seems there are three options:
1) search my hash for a value matching the pointer (slooow)
2) keep an extra hash where the pointers are the keys instead of the values
(seems like a waste of space)
3) change the Applet code so that it emits a signal with its name() when it's
about to be destroyed
--
This message brought to you by evyl bananas, and the number 3.
www.chani3.com
["appletbrowser.diff" (text/x-diff)]
Index: appletbrowser.h
===================================================================
--- appletbrowser.h (revision 746168)
+++ appletbrowser.h (working copy)
@@ -29,6 +29,7 @@
class Corona;
class Containment;
+class Applet;
class PLASMA_EXPORT AppletBrowserWidget : public QWidget
{
@@ -48,12 +49,23 @@
void addApplet();
/**
+ * Tracks a new running applet
+ */
+ void appletAdded(Plasma::Applet* applet);
+
+ /**
+ * A running applet is no more
+ */
+ void appletDestroyed(QObject* applet);
+
+ /**
* Launches a download dialog to retrieve new applets from the Internet
*/
void downloadApplets();
private:
void init();
+ void initRunningApplets();
class Private;
Private * const d;
bool m_showButtons;
Index: appletbrowser.cpp
===================================================================
--- appletbrowser.cpp (revision 746168)
+++ appletbrowser.cpp (working copy)
@@ -27,6 +27,7 @@
#include "plasma/corona.h"
#include "plasma/containment.h"
+#include "plasma/applet.h"
#include "plasma/appletbrowser/plasmaappletitemmodel_p.h"
#include "plasma/appletbrowser/kcategorizeditemsview_p.h"
@@ -48,11 +49,14 @@
}
void initFilters();
+ //update the itemModel on our running applets
+ void updateRunningApplets();
QString application;
Plasma::Corona *corona;
Plasma::Containment *containment;
KCategorizedItemsView *appletList;
+ QMultiHash<QString,Plasma::Applet*> runningApplets;
KConfig config;
KConfigGroup configGroup;
@@ -96,6 +100,9 @@
filterModel.addFilter(i18n("Widgets I Have Used Before"),
KCategorizedItemsViewModels::Filter("used", true),
new KIcon("history"));
+ filterModel.addFilter(i18n("Currently Running Widgets"),
+ KCategorizedItemsViewModels::Filter("running", true),
+ new KIcon("history"));
filterModel.addSeparator(i18n("Categories:"));
@@ -105,7 +112,17 @@
}
}
+void AppletBrowserWidget::Private::updateRunningApplets()
+{
+ QHash<QString,int> appCount;
+ foreach (QString key, runningApplets.uniqueKeys()) {
+ appCount[key]=runningApplets.count(key);
+ }
+ kDebug() << appCount;
+ itemModel.setRunningApplets(appCount);
+}
+
AppletBrowserWidget::AppletBrowserWidget(Plasma::Corona * corona, bool showButtons, \
QWidget * parent, Qt::WindowFlags f) : QWidget(parent, f),
d(new Private(corona, 0, this)),
@@ -161,8 +178,39 @@
// Other models
d->appletList->setItemModel(&d->itemModel);
+ initRunningApplets();
}
+void AppletBrowserWidget::initRunningApplets()
+{
+//get applets from corona, count them, send results to model
+ kDebug() << d->runningApplets.count();
+ QHash<QString,int> appCount;
+ Plasma::Corona *c=d->corona;
+ if (!c && d->containment) {
+ c=d->containment->corona();
+ }
+ //we've tried our best to get a corona
+ //we don't want just one containment, we want them all
+ if (!c) {
+ kDebug() << "can't happen";
+ return;
+ }
+ QList<Containment*>containments=c->containments();
+ foreach (Containment * containment,containments) {
+ connect(containment, SIGNAL(appletAdded(Plasma::Applet*)), this, \
SLOT(appletAdded(Plasma::Applet*))); + //TODO track containments too?
+ QList<Applet*>applets=containment->applets();
+ foreach (Applet *applet,applets) {
+ d->runningApplets.insert(applet->name(),applet);
+ connect(applet, SIGNAL(destroyed(QObject*)), this, \
SLOT(appletDestroyed(QObject*))); + appCount[applet->name()]++;
+ }
+ }
+ kDebug() << appCount;
+ d->itemModel.setRunningApplets(appCount);
+}
+
void AppletBrowserWidget::setApplication(const QString& app)
{
@@ -173,6 +221,11 @@
//FIXME: AFAIK this shouldn't be necessary ... but here it is. need to find out \
what in that // maze of models and views is screwing up
d->appletList->setItemModel(&d->itemModel);
+ //FIXME: I don't know if this is needed, and if it is then I don't know if
+ //I'll need to worry about too many containments sending add signals
+ //initRunningApplets();
+ //perhaps I'll need to send the model a list of running apps, but not update my \
own settings. + d->updateRunningApplets();
}
QString AppletBrowserWidget::application()
@@ -199,6 +252,28 @@
}
}
+void AppletBrowserWidget::appletAdded(Plasma::Applet* applet)
+{
+ QString name = applet->name();
+ kDebug() << name;
+ d->runningApplets.insert(name, applet);
+ connect(applet, SIGNAL(destroyed(QObject*)), this, \
SLOT(appletDestroyed(QObject*))); + d->itemModel.setRunningApplets(name, \
d->runningApplets.count(name)); +}
+
+void AppletBrowserWidget::appletDestroyed(QObject* applet)
+{
+ kDebug() << applet;
+ Plasma::Applet* a = (Plasma::Applet*)applet; //don't care if it's valid, just \
need the address + //sadly we have to search the whole damn hash for this object
+ //because it's too late for it to give us its name.
+ //possible fix: emit destroying(name) from applet before it dies
+ QString name = d->runningApplets.key(a);
+ //if !name, was the applet not found or was the name actually ""?
+ d->runningApplets.remove(name, a);
+ d->itemModel.setRunningApplets(name, d->runningApplets.count(name));
+}
+
void AppletBrowserWidget::downloadApplets()
{
//TODO: implement
Index: appletbrowser/kcategorizeditemsviewdelegate.cpp
===================================================================
--- appletbrowser/kcategorizeditemsviewdelegate.cpp (revision 746168)
+++ appletbrowser/kcategorizeditemsviewdelegate.cpp (working copy)
@@ -80,6 +80,7 @@
QString title = item->name();
QString description = item->description();
+ int running = item->data().toMap()["runningCount"].toInt();
// Painting
@@ -99,6 +100,19 @@
top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
width - textInner, MAIN_ICON_SIZE / 2,
Qt::AlignTop | Qt::AlignLeft, description);
+ if (running) {
+ //removal text FIXME: overlap?
+ QString remove = i18n("Remove");
+ if (running > 1) {
+ remove += QString(" (%1)__").arg(running);
+ }
+ painter->setFont(local_option_normal.font);
+ painter->drawText(
+ left + (leftToRight ? textInner : 0),
+ top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
+ width - textInner, MAIN_ICON_SIZE / 2,
+ Qt::AlignTop | Qt::AlignRight, remove);
+ }
// Main icon
item->icon().paint(painter,
Index: appletbrowser/plasmaappletitemmodel.cpp
===================================================================
--- appletbrowser/plasmaappletitemmodel.cpp (revision 746168)
+++ appletbrowser/plasmaappletitemmodel.cpp (working copy)
@@ -69,6 +69,14 @@
}
}
+void PlasmaAppletItem::setRunning(int count)
+{
+ QMap<QString, QVariant> attrs = data().toMap();
+ attrs.insert("running", count > 0); //bool for the filter
+ attrs.insert("runningCount", count);
+ setData(QVariant(attrs));
+}
+
bool PlasmaAppletItem::passesFiltering(
const KCategorizedItemsViewModels::Filter & filter) const
{
@@ -138,6 +146,29 @@
}
}
+void PlasmaAppletItemModel::setRunningApplets(const QHash<QString, int> apps)
+{
+ //foreach item, find that string and set the count
+ for (int r=0; r<rowCount(); ++r) {
+ QStandardItem *i = item(r);
+ PlasmaAppletItem *p = (PlasmaAppletItem *)i;
+ if (p) {
+ p->setRunning(apps.value(p->name()));
+ }
+ }
+}
+
+void PlasmaAppletItemModel::setRunningApplets(const QString name, int count)
+{
+ for (int r=0; r<rowCount(); ++r) {
+ QStandardItem *i = item(r);
+ PlasmaAppletItem *p = (PlasmaAppletItem *)i;
+ if (p && p->name() == name) {
+ p->setRunning(count);
+ }
+ }
+}
+
QStringList PlasmaAppletItemModel::mimeTypes() const
{
QStringList types;
Index: appletbrowser/plasmaappletitemmodel_p.h
===================================================================
--- appletbrowser/plasmaappletitemmodel_p.h (revision 746168)
+++ appletbrowser/plasmaappletitemmodel_p.h (working copy)
@@ -48,6 +48,8 @@
QString pluginName() const;
virtual QString description() const;
virtual void setFavorite(bool favorite);
+ //set how many instances of this applet are running
+ virtual void setRunning(int count);
virtual bool passesFiltering(
const KCategorizedItemsViewModels::Filter & filter) const;
virtual QVariantList arguments() const;
@@ -68,6 +70,8 @@
void setFavorite(QString plugin, bool favorite);
void setApplication(const QString& app);
+ void setRunningApplets(const QHash<QString, int> apps);
+ void setRunningApplets(const QString name, int count);
QString& Application();
private:
["signature.asc" (application/pgp-signature)]
_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic