Skip to content

Commit

Permalink
Support the action_hints hint
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentijnvdBeek committed Sep 12, 2018
1 parent 7380ad8 commit 3ea9b78
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,17 @@ void Notification::setValues(const QString &application,
// TODO/FIXME: Urgencies - how to handle it?
}

bool action_icons = !hints[QL1S("action-icons")].isNull();
// Actions
if (actions.count() && m_actionWidget == 0)
if (actions.count())
{
if (m_actionWidget != 0)
delete m_actionWidget;

if (actions.count()/2 < 4)
m_actionWidget = new NotificationActionsButtonsWidget(actions, this);
m_actionWidget = new NotificationActionsButtonsWidget(actions, this, action_icons);
else
m_actionWidget = new NotificationActionsComboWidget(actions, this);
m_actionWidget = new NotificationActionsComboWidget(actions, this, action_icons);

connect(m_actionWidget, &NotificationActionsWidget::actionTriggered,
this, &Notification::actionTriggered);
Expand Down Expand Up @@ -256,7 +260,7 @@ QPixmap Notification::getPixmapFromHint(const QVariant &argument) const
QPixmap Notification::getPixmapFromString(const QString &str) const
{
QUrl url(str);
if (url.isValid() && QFile::exists(url.toLocalFile()))
if (url.isLocalFile() && QFile::exists(url.toLocalFile()))
{
// qDebug() << " getPixmapFromString by URL" << url;
return QPixmap(url.toLocalFile());
Expand All @@ -265,7 +269,7 @@ QPixmap Notification::getPixmapFromString(const QString &str) const
{
// qDebug() << " getPixmapFromString by XdgIcon theme" << str << ICONSIZE << XdgIcon::themeName();
// qDebug() << " " << XdgIcon::fromTheme(str) << "isnull:" << XdgIcon::fromTheme(str).isNull();
// They say: do not display an icon if it;s not found - see #325
// They say: do not display an icon if it's not found - see #325
return XdgIcon::fromTheme(str/*, XdgIcon::defaultApplicationIcon()*/).pixmap(ICONSIZE);
}
}
Expand Down
32 changes: 27 additions & 5 deletions src/notificationwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@

#include <LXQt/Globals>

#include <XdgIcon>
#include <QComboBox>
#include <QHBoxLayout>
#include <QButtonGroup>
#include <QAbstractButton>
#include <QPushButton>
#include <QLabel>

#include "notificationwidgets.h"

#include <QtDebug>

#define ICONSIZE QSize(32, 32)

NotificationActionsWidget::NotificationActionsWidget(const QStringList& actions, QWidget *parent)
: QWidget(parent)
Expand Down Expand Up @@ -65,8 +67,7 @@ NotificationActionsWidget::NotificationActionsWidget(const QStringList& actions,
m_defaultAction = m_actions[0].first;
}


NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent)
NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent, const bool action_icons)
: NotificationActionsWidget(actions, parent)
{
QHBoxLayout *l = new QHBoxLayout();
Expand All @@ -78,12 +79,24 @@ NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QString
{
QPushButton *b = new QPushButton(action.second, this);
b->setObjectName(action.first);

if (action_icons)
{
QIcon icon = XdgIcon::fromTheme(action.first).pixmap(ICONSIZE);

if (! icon.isNull()) {
b->setText(QString());
b->setIcon(icon);
}
}

l->addWidget(b);
group->addButton(b);

if (action.first == m_defaultAction)
b->setFocus(Qt::OtherFocusReason);
}

connect(group, static_cast<void (QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
this, &NotificationActionsButtonsWidget::actionButtonActivated);
}
Expand All @@ -94,7 +107,7 @@ void NotificationActionsButtonsWidget::actionButtonActivated(QAbstractButton* bu
}


NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList& actions, QWidget *parent)
NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList& actions, QWidget *parent, bool action_icons)
: NotificationActionsWidget(actions, parent)
{
QHBoxLayout *l = new QHBoxLayout();
Expand All @@ -107,8 +120,17 @@ NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList
for (int i = 0; i < m_actions.count(); ++i)
{
auto const & action = m_actions[i];

m_comboBox->addItem(action.second, action.first);

if (action_icons)
{
QIcon icon = XdgIcon::fromTheme(action.first).pixmap(ICONSIZE);
if (!icon.isNull())
{
m_comboBox->setItemIcon(i, icon);
}
}

if (action.first == m_defaultAction)
{
currentIndex = i;
Expand Down
4 changes: 2 additions & 2 deletions src/notificationwidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NotificationActionsButtonsWidget : public NotificationActionsWidget
/*! Create new widget.
* \param actions a list of actions in form: (key1, display1, key2, display2, ..., keyN, displayN)
*/
NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent);
NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent, const bool action_icons);
private slots:
void actionButtonActivated(QAbstractButton* button);
};
Expand All @@ -89,7 +89,7 @@ class NotificationActionsComboWidget : public NotificationActionsWidget
/*! Create new widget.
* \param actions a list of actions in form: (key1, display1, key2, display2, ..., keyN, displayN)
*/
NotificationActionsComboWidget(const QStringList& actions, QWidget *parent);
NotificationActionsComboWidget(const QStringList& actions, QWidget *parent, const bool action_icons);

private:
QComboBox *m_comboBox;
Expand Down
2 changes: 1 addition & 1 deletion src/notifyd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ QStringList Notifyd::GetCapabilities()
QStringList caps;
caps
<< QSL("actions")
// << "action-icons"
<< QSL("action-icons")
<< QSL("body")
<< QSL("body-hyperlinks")
<< QSL("body-images")
Expand Down

0 comments on commit 3ea9b78

Please sign in to comment.