1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2  * (c)LGPL2+
3  *
4  * LXQt - a lightweight, Qt based, desktop toolset
5  * https://lxqt.org
6  *
7  * Copyright (C) 2012  Alec Moskvin <alecm@gmx.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13 
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  * END_COMMON_COPYRIGHT_HEADER */
24 
25 #include "mainwindow.h"
26 #include "ui_mainwindow.h"
27 #include <LXQt/Notification>
28 #include <QDebug>
29 
MainWindow(QWidget * parent)30 MainWindow::MainWindow(QWidget *parent) :
31     QMainWindow(parent),
32     ui(new Ui::MainWindow)
33 {
34     ui->setupUi(this);
35     connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::createNotification);
36     LXQt::Notification::notify(QStringLiteral("1"));
37     LXQt::Notification::notify(QStringLiteral("2"));
38     LXQt::Notification::notify(QStringLiteral("3"));
39 }
40 
createNotification()41 void MainWindow::createNotification()
42 {
43     LXQt::Notification* n = new LXQt::Notification(QStringLiteral("Notification!"));
44     nlist.append(n);
45     connect(n, &LXQt::Notification::actionActivated, this, &MainWindow::clickEvent);
46     n->setActions(QStringList()
47             << QStringLiteral("Hi")
48             << QStringLiteral("Bye")
49             << QStringLiteral("foo")
50             << QStringLiteral("bar")
51             << QStringLiteral("lorem")
52             << QStringLiteral("ipsum"),
53     1);
54     n->setIcon(QStringLiteral("preferences-desktop-launch-feedback"));
55     n->update();
56 }
57 
clickEvent(int button)58 void MainWindow::clickEvent(int button)
59 {
60     LXQt::Notification* n = qobject_cast<LXQt::Notification*>(sender());
61     if (n)
62     {
63         if (button == 0)
64         {
65             n->setBody(QStringLiteral("Hello!"));
66         }
67         else
68         {
69             n->setBody(QStringLiteral("Closing..."));
70             n->setTimeout(1000);
71         }
72         n->update();
73     }
74 }
75 
~MainWindow()76 MainWindow::~MainWindow()
77 {
78     delete ui;
79     qDeleteAll(nlist);
80 }
81