mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
plasma: complete the notifications applet application notifications widget
complete as in fully functional Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f4d40c28e9
commit
abcd9042b0
5 changed files with 51 additions and 14 deletions
|
@ -20,8 +20,10 @@
|
|||
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <Plasma/DataEngineManager>
|
||||
#include <Plasma/Service>
|
||||
#include <Plasma/IconWidget>
|
||||
#include <Plasma/ToolButton>
|
||||
#include <Plasma/PushButton>
|
||||
#include <KIconLoader>
|
||||
#include <KIcon>
|
||||
#include <KNotificationConfigWidget>
|
||||
#include <KDebug>
|
||||
|
@ -171,28 +173,32 @@ void ApplicationsWidget::dataUpdated(const QString &name, const Plasma::DataEngi
|
|||
// row insertation starts at 0, count is +1
|
||||
if (framelayout->rowCount() >= 4) {
|
||||
buttonslayout = static_cast<QGraphicsLinearLayout*>(framelayout->itemAt(3, 0));
|
||||
}
|
||||
if (buttonslayout) {
|
||||
// remove buttons in case of notification update
|
||||
QList<Plasma::ToolButton*> actionbuttons;
|
||||
// redo the buttons layout in case of notification update
|
||||
QList<Plasma::PushButton*> actionbuttons;
|
||||
for (int i = 0; i < buttonslayout->count(); i++) {
|
||||
Plasma::ToolButton* actionbutton = static_cast<Plasma::ToolButton*>(buttonslayout->itemAt(i));
|
||||
actionbuttons.append(actionbutton);
|
||||
Plasma::PushButton* actionbutton = static_cast<Plasma::PushButton*>(buttonslayout->itemAt(i));
|
||||
if (actionbutton) {
|
||||
actionbuttons.append(actionbutton);
|
||||
}
|
||||
buttonslayout->removeAt(i);
|
||||
}
|
||||
qDeleteAll(actionbuttons);
|
||||
actionbuttons.clear();
|
||||
framelayout->removeItem(buttonslayout);
|
||||
delete buttonslayout;
|
||||
buttonslayout = nullptr;
|
||||
}
|
||||
for (int i = 0; i < actions.size(); i++) {
|
||||
const QString actionid = actions[i];
|
||||
i++;
|
||||
const QString actionname = actions[i];
|
||||
const QString actionname = (i < actions.size() ? actions.at(i) : QString());
|
||||
if (actionid.isEmpty() || actionname.isEmpty()) {
|
||||
kWarning() << "Empty action ID or name" << actionid << actionname;
|
||||
continue;
|
||||
}
|
||||
|
||||
Plasma::ToolButton* actionbutton = new Plasma::ToolButton(frame);
|
||||
Plasma::PushButton* actionbutton = new Plasma::PushButton(frame);
|
||||
actionbutton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
actionbutton->setProperty("_k_name", framename);
|
||||
actionbutton->setProperty("_k_actionid", actionid);
|
||||
actionbutton->setText(actionname);
|
||||
|
@ -202,10 +208,12 @@ void ApplicationsWidget::dataUpdated(const QString &name, const Plasma::DataEngi
|
|||
);
|
||||
if (!buttonslayout) {
|
||||
buttonslayout = new QGraphicsLinearLayout(Qt::Horizontal, framelayout);
|
||||
buttonslayout->addStretch();
|
||||
}
|
||||
buttonslayout->addItem(actionbutton);
|
||||
}
|
||||
if (buttonslayout) {
|
||||
buttonslayout->addStretch();
|
||||
framelayout->addItem(buttonslayout, 3, 0, 1, 3);
|
||||
framelayout->setAlignment(buttonslayout, Qt::AlignCenter);
|
||||
}
|
||||
|
@ -256,12 +264,14 @@ void ApplicationsWidget::slotConfigureActivated()
|
|||
{
|
||||
const Plasma::IconWidget* configurewidget = qobject_cast<Plasma::IconWidget*>(sender());
|
||||
const QString frameapprealname = configurewidget->property("_k_apprealname").toString();
|
||||
// same thing the notifications service does
|
||||
KNotificationConfigWidget::configure(frameapprealname, nullptr);
|
||||
}
|
||||
|
||||
void ApplicationsWidget::slotActionClicked()
|
||||
{
|
||||
const Plasma::ToolButton* actionbutton = qobject_cast<Plasma::ToolButton*>(sender());
|
||||
QMutexLocker locker(&m_mutex);
|
||||
const Plasma::PushButton* actionbutton = qobject_cast<Plasma::PushButton*>(sender());
|
||||
const QString framename = actionbutton->property("_k_name").toString();
|
||||
const QString actionid = actionbutton->property("_k_actionid").toString();
|
||||
Plasma::Service* plasmaservice = m_dataengine->serviceForSource(framename);
|
||||
|
@ -272,7 +282,12 @@ void ApplicationsWidget::slotActionClicked()
|
|||
plasmaserviceargs["actionId"] = actionid;
|
||||
(void)plasmaservice->startOperationCall("invokeAction", plasmaserviceargs);
|
||||
}
|
||||
// TODO: remove notification too
|
||||
|
||||
// remove notification too (compat)
|
||||
Plasma::Frame* actionframe = qobject_cast<Plasma::Frame*>(actionbutton->parentObject());
|
||||
Q_ASSERT(actionframe != nullptr);
|
||||
Plasma::IconWidget* removewidget = qvariant_cast<Plasma::IconWidget*>(actionframe->property("_k_removewidget"));
|
||||
QMetaObject::invokeMethod(removewidget, "activated", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
#include "moc_applicationswidget.cpp"
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <Plasma/Label>
|
||||
#include <Plasma/Frame>
|
||||
#include <Plasma/DataEngine>
|
||||
#include <KIconLoader>
|
||||
|
||||
class NotificationsWidget;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ JobsWidget::~JobsWidget()
|
|||
|
||||
int JobsWidget::count() const
|
||||
{
|
||||
return 0;
|
||||
return m_frames.size();
|
||||
}
|
||||
|
||||
void JobsWidget::sourceAdded(const QString &name)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QGraphicsWidget>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <Plasma/Label>
|
||||
#include <Plasma/Frame>
|
||||
#include <Plasma/DataEngine>
|
||||
|
||||
class NotificationsWidget;
|
||||
|
@ -47,6 +48,7 @@ private:
|
|||
NotificationsWidget *m_notificationswidget;
|
||||
QGraphicsLinearLayout* m_layout;
|
||||
Plasma::Label* m_label;
|
||||
QList<Plasma::Frame*> m_frames;
|
||||
Plasma::DataEngine *m_dataengine;
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,25 @@
|
|||
#include <KDebug>
|
||||
|
||||
static const QSizeF s_minimumsize = QSizeF(290, 140);
|
||||
static const int s_svgiconsize = 256;
|
||||
|
||||
static QIcon kNotificationIcon(QObject *parent, const bool active)
|
||||
{
|
||||
QIcon result;
|
||||
Plasma::Svg plasmasvg(parent);
|
||||
plasmasvg.setImagePath("icons/notification");
|
||||
plasmasvg.setContainsMultipleImages(true);
|
||||
if (plasmasvg.isValid()) {
|
||||
QPixmap iconpixmap(s_svgiconsize, s_svgiconsize);
|
||||
iconpixmap.fill(Qt::transparent);
|
||||
QPainter iconpainter(&iconpixmap);
|
||||
plasmasvg.paint(&iconpainter, iconpixmap.rect(), active ? "notification-active" : "notification-disabled");
|
||||
result = QIcon(iconpixmap);
|
||||
} else {
|
||||
result = KIcon("preferences-desktop-notification");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class NotificationsWidget : public Plasma::TabBar
|
||||
{
|
||||
|
@ -86,8 +105,10 @@ void NotificationsWidget::slotCountChanged()
|
|||
{
|
||||
const int totalcount = (m_jobswidget->count() + m_applicationswidget->count());
|
||||
if (totalcount > 0) {
|
||||
m_notifications->setPopupIcon(kNotificationIcon(m_notifications, true));
|
||||
m_notifications->setStatus(Plasma::ItemStatus::ActiveStatus);
|
||||
} else {
|
||||
m_notifications->setPopupIcon(kNotificationIcon(m_notifications, false));
|
||||
m_notifications->setStatus(Plasma::ItemStatus::PassiveStatus);
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +121,7 @@ NotificationsApplet::NotificationsApplet(QObject *parent, const QVariantList &ar
|
|||
KGlobal::locale()->insertCatalog("plasma_applet_notifications");
|
||||
setAspectRatioMode(Plasma::AspectRatioMode::IgnoreAspectRatio);
|
||||
m_notificationswidget = new NotificationsWidget(this);
|
||||
setPopupIcon("preferences-desktop-notification");
|
||||
setPopupIcon(kNotificationIcon(this, false));
|
||||
}
|
||||
|
||||
NotificationsApplet::~NotificationsApplet()
|
||||
|
|
Loading…
Add table
Reference in a new issue