Falkon Develop
Cross-platform Qt-based web browser
gm_notification.cpp
Go to the documentation of this file.
1/* ============================================================
2* GreaseMonkey plugin for Falkon
3* Copyright (C) 2012-2017 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "gm_notification.h"
19#include "ui_gm_notification.h"
20#include "gm_manager.h"
21#include "gm_script.h"
22
23#include "iconprovider.h"
24
25#include <QFile>
26
27GM_Notification::GM_Notification(GM_Manager* manager, const QString &tmpfileName, const QString &fileName)
28 : AnimatedWidget(AnimatedWidget::Down, 300, nullptr)
29 , ui(new Ui::GM_Notification)
30 , m_manager(manager)
31 , m_tmpFileName(tmpfileName)
32 , m_fileName(fileName)
33{
34 setAutoFillBackground(true);
35 ui->setupUi(widget());
36
37 ui->iconLabel->setPixmap(QIcon(QSL(":gm/data/icon.svg")).pixmap(24));
38 ui->close->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
39
40 connect(ui->install, &QAbstractButton::clicked, this, &GM_Notification::installScript);
41 connect(ui->close, SIGNAL(clicked()), this, SLOT(hide()));
42
44}
45
46void GM_Notification::installScript()
47{
48 bool success = false;
49
50 GM_Script* script = nullptr;
51 QString message = tr("Cannot install script");
52
53 if (QFile::copy(m_tmpFileName, m_fileName)) {
54 script = new GM_Script(m_manager, m_fileName);
55 success = m_manager->addScript(script);
56 }
57
58 if (success) {
59 message = tr("'%1' installed successfully").arg(script->name());
60 }
61
62 m_manager->showNotification(message);
63
64 hide();
65}
66
68{
69 delete ui;
70}
QWidget * widget()
void showNotification(const QString &message, const QString &title=QString())
Definition: gm_manager.cpp:230
bool addScript(GM_Script *script)
Definition: gm_manager.cpp:190
GM_Notification(GM_Manager *manager, const QString &tmpfileName, const QString &fileName)
QString name() const
Definition: gm_script.cpp:57
static QIcon standardIcon(QStyle::StandardPixmap icon)
#define QSL(x)
Definition: qzcommon.h:40