Use dbusnotify module to fixed notify window can't hide when popup new notify.
Andy Stewart
6 years ago
15 | 15 | src/colormenu.h \ |
16 | 16 | src/clipboard.h \ |
17 | 17 | src/animation.h \ |
18 | src/dbusnotify.h \ | |
18 | 19 | src/settings.h \ |
19 | 20 | src/utils.h |
20 | 21 | SOURCES += src/picker.cpp \ |
22 | 23 | src/colormenu.cpp \ |
23 | 24 | src/clipboard.cpp \ |
24 | 25 | src/animation.cpp \ |
26 | src/dbusnotify.cpp \ | |
25 | 27 | src/settings.cpp \ |
26 | 28 | src/utils.cpp \ |
27 | 29 | src/main.cpp |
18 | 18 | * |
19 | 19 | * You should have received a copy of the GNU General Public License |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | |
21 | */ | |
22 | 22 | |
23 | 23 | #include "clipboard.h" |
24 | #include "dbusnotify.h" | |
24 | 25 | #include "settings.h" |
25 | 26 | #include "utils.h" |
26 | 27 | #include <QApplication> |
35 | 36 | |
36 | 37 | Clipboard::~Clipboard() |
37 | 38 | { |
38 | ||
39 | ||
39 | 40 | } |
40 | 41 | |
41 | 42 | void Clipboard::copyToClipboard(QColor color, QString colorType) |
53 | 54 | } else if (colorType == "Float_RGBA") { |
54 | 55 | colorString = Utils::colorToFloatRGBA(color); |
55 | 56 | } |
56 | ||
57 | ||
57 | 58 | Settings *settings = new Settings(); |
58 | 59 | settings->setOption("color_type", colorType); |
59 | ||
60 | ||
60 | 61 | // Popup notify. |
61 | // We need poup notify in first time, because copy to clipboard maybe block event loop. | |
62 | QDBusInterface notification("org.freedesktop.Notifications", | |
63 | "/org/freedesktop/Notifications", | |
64 | "org.freedesktop.Notifications", | |
65 | QDBusConnection::sessionBus()); | |
62 | DBusNotify* notifyDBus = new DBusNotify(this); | |
63 | notifyDBus->CloseNotification(0); // we need hide last time system notify first | |
66 | 64 | |
67 | 65 | QStringList actions; |
68 | 66 | QVariantMap hints; |
69 | ||
70 | QList<QVariant> arg; | |
71 | arg << (QCoreApplication::applicationName()) // appname | |
72 | << ((unsigned int) 0) // id | |
73 | << QString("deepin-picker") // icon | |
74 | << "" // summary | |
75 | << QString(tr("Copy color %1 to clipboard")).arg(colorString) // body | |
76 | << actions // actions | |
77 | << hints // hints | |
78 | << (int) -1; // timeout | |
79 | notification.callWithArgumentList(QDBus::AutoDetect, "Notify", arg); | |
80 | ||
67 | ||
68 | notifyDBus->Notify( | |
69 | QCoreApplication::applicationName(), | |
70 | 0, | |
71 | "deepin-picker", | |
72 | "", | |
73 | QString(tr("Copy color %1 to clipboard")).arg(colorString), // body | |
74 | actions, | |
75 | hints, | |
76 | 0); | |
77 | ||
81 | 78 | // Copy to clipbard. |
82 | 79 | QClipboard *clipboard = QApplication::clipboard(); |
83 | 80 | clipboard->setText(colorString); |
84 | ||
81 | ||
85 | 82 | // Quit application. |
86 | 83 | QApplication::quit(); |
87 | 84 | } |
0 | /* | |
1 | * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. | |
2 | * | |
3 | * Maintainer: Peng Hui<penghui@deepin.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 | * 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 | ||
19 | /* | |
20 | * This file was generated by qdbusxml2cpp version 0.8 | |
21 | * Command line was: qdbusxml2cpp -c DBusNotify -p dbusnotify org.freedesktop.Notifications.xml | |
22 | * | |
23 | * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. | |
24 | * | |
25 | * This is an auto-generated file. | |
26 | * This file may have been hand-edited. Look for HAND-EDIT comments | |
27 | * before re-generating it. | |
28 | */ | |
29 | ||
30 | #include "dbusnotify.h" | |
31 | ||
32 | /* | |
33 | * Implementation of interface class DBusNotify | |
34 | */ | |
35 | ||
36 | const QString NOTIFY_DBUS_NAME = "org.freedesktop.Notifications"; | |
37 | const QString NOTIFY_DBUS_PATH = "/org/freedesktop/Notifications"; | |
38 | ||
39 | DBusNotify::DBusNotify(QObject *parent) | |
40 | : QDBusAbstractInterface(NOTIFY_DBUS_NAME, NOTIFY_DBUS_PATH, | |
41 | staticInterfaceName(), QDBusConnection::sessionBus(), parent) | |
42 | { | |
43 | QDBusConnection::sessionBus().connect(this->service(), this->path(), | |
44 | "org.freedesktop.DBus.Properties", "PropertiesChanged","sa{sv}as", | |
45 | this, SLOT(__propertyChanged__(QDBusMessage))); | |
46 | } | |
47 | ||
48 | DBusNotify::~DBusNotify() | |
49 | { | |
50 | QDBusConnection::sessionBus().disconnect(service(), path(), | |
51 | "org.freedesktop.DBus.Properties", "PropertiesChanged", "sa{sv}as", | |
52 | this, SLOT(propertyChanged(QDBusMessage))); | |
53 | } | |
54 |
0 | /* | |
1 | * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. | |
2 | * | |
3 | * This program is free software: you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation, either version 3 of the License, or | |
6 | * any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | */ | |
16 | /* | |
17 | * This file was generated by qdbusxml2cpp version 0.8 | |
18 | * Command line was: qdbusxml2cpp -c DBusNotify -p dbusnotify org.freedesktop.Notifications.xml | |
19 | * | |
20 | * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. | |
21 | * | |
22 | * This is an auto-generated file. | |
23 | * Do not edit! All changes made to it will be lost. | |
24 | */ | |
25 | ||
26 | #ifndef DBUSNOTIFY_H | |
27 | #define DBUSNOTIFY_H | |
28 | ||
29 | #include <QtCore/QObject> | |
30 | #include <QtCore/QByteArray> | |
31 | #include <QtCore/QList> | |
32 | #include <QtCore/QMap> | |
33 | #include <QtCore/QString> | |
34 | #include <QtCore/QStringList> | |
35 | #include <QtCore/QVariant> | |
36 | #include <QtDBus/QtDBus> | |
37 | ||
38 | /* | |
39 | * Proxy class for interface org.freedesktop.Notifications | |
40 | */ | |
41 | class DBusNotify: public QDBusAbstractInterface | |
42 | { | |
43 | Q_OBJECT | |
44 | Q_SLOT void __propertyChanged__(const QDBusMessage& msg) | |
45 | { | |
46 | QList<QVariant> arguments = msg.arguments(); | |
47 | if (3 != arguments.count()) | |
48 | return; | |
49 | QString interfaceName = msg.arguments().at(0).toString(); | |
50 | if (interfaceName !="org.freedesktop.Notifications") | |
51 | return; | |
52 | QVariantMap changedProps = qdbus_cast<QVariantMap>(arguments.at(1).value<QDBusArgument>()); | |
53 | QStringList keys = changedProps.keys(); | |
54 | foreach(const QString &prop, keys) { | |
55 | const QMetaObject* self = metaObject(); | |
56 | for (int i=self->propertyOffset(); i < self->propertyCount(); ++i) { | |
57 | QMetaProperty p = self->property(i); | |
58 | if (p.name() == prop) { | |
59 | Q_EMIT p.notifySignal().invoke(this); | |
60 | } | |
61 | } | |
62 | } | |
63 | } | |
64 | public: | |
65 | static inline const char *staticInterfaceName() | |
66 | { return "org.freedesktop.Notifications"; } | |
67 | ||
68 | public: | |
69 | DBusNotify(QObject *parent = 0); | |
70 | ||
71 | ~DBusNotify(); | |
72 | ||
73 | public Q_SLOTS: // METHODS | |
74 | inline QDBusPendingReply<> ClearRecords() | |
75 | { | |
76 | QList<QVariant> argumentList; | |
77 | return asyncCallWithArgumentList(QStringLiteral("ClearRecords"), argumentList); | |
78 | } | |
79 | ||
80 | inline QDBusPendingReply<> CloseNotification(uint in0) | |
81 | { | |
82 | QList<QVariant> argumentList; | |
83 | argumentList << QVariant::fromValue(in0); | |
84 | return asyncCallWithArgumentList(QStringLiteral("CloseNotification"), argumentList); | |
85 | } | |
86 | ||
87 | inline QDBusPendingReply<QString> GetAllRecords() | |
88 | { | |
89 | QList<QVariant> argumentList; | |
90 | return asyncCallWithArgumentList(QStringLiteral("GetAllRecords"), argumentList); | |
91 | } | |
92 | ||
93 | inline QDBusPendingReply<QStringList> GetCapbilities() | |
94 | { | |
95 | QList<QVariant> argumentList; | |
96 | return asyncCallWithArgumentList(QStringLiteral("GetCapbilities"), argumentList); | |
97 | } | |
98 | ||
99 | inline QDBusPendingReply<QString, QString, QString, QString> GetServerInformation() | |
100 | { | |
101 | QList<QVariant> argumentList; | |
102 | return asyncCallWithArgumentList(QStringLiteral("GetServerInformation"), argumentList); | |
103 | } | |
104 | inline QDBusReply<QString> GetServerInformation(QString &out1, QString &out2, QString &out3) | |
105 | { | |
106 | QList<QVariant> argumentList; | |
107 | QDBusMessage reply = callWithArgumentList(QDBus::Block, QStringLiteral("GetServerInformation"), argumentList); | |
108 | if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 4) { | |
109 | out1 = qdbus_cast<QString>(reply.arguments().at(1)); | |
110 | out2 = qdbus_cast<QString>(reply.arguments().at(2)); | |
111 | out3 = qdbus_cast<QString>(reply.arguments().at(3)); | |
112 | } | |
113 | return reply; | |
114 | } | |
115 | ||
116 | inline QDBusPendingReply<uint> Notify(const QString &in0, uint in1, const QString &in2, const QString &in3, const QString &in4, const QStringList &in5, const QVariantMap &in6, int in7) | |
117 | { | |
118 | QList<QVariant> argumentList; | |
119 | argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2) << QVariant::fromValue(in3) << QVariant::fromValue(in4) << QVariant::fromValue(in5) << QVariant::fromValue(in6) << QVariant::fromValue(in7); | |
120 | return asyncCallWithArgumentList(QStringLiteral("Notify"), argumentList); | |
121 | } | |
122 | ||
123 | inline QDBusPendingReply<> RemoveRecord(const QString &in0) | |
124 | { | |
125 | QList<QVariant> argumentList; | |
126 | argumentList << QVariant::fromValue(in0); | |
127 | return asyncCallWithArgumentList(QStringLiteral("RemoveRecord"), argumentList); | |
128 | } | |
129 | ||
130 | Q_SIGNALS: // SIGNALS | |
131 | void ActionInvoked(uint in0, const QString &in1); | |
132 | void NotificationClosed(uint in0, uint in1); | |
133 | void RecordAdded(const QString &in0); | |
134 | }; | |
135 | ||
136 | namespace org { | |
137 | namespace freedesktop { | |
138 | typedef ::DBusNotify Notifications; | |
139 | } | |
140 | } | |
141 | #endif |
0 | <?xml version="1.0" ?><!DOCTYPE TS><TS language="zh_CN" version="2.1"> | |
0 | <?xml version="1.0" encoding="utf-8"?> | |
1 | <!DOCTYPE TS> | |
2 | <TS version="2.1" language="zh_CN"> | |
1 | 3 | <context> |
2 | 4 | <name>Clipboard</name> |
3 | 5 | <message> |
4 | <location filename="../src/clipboard.cpp" line="76"/> | |
5 | 6 | <source>Copy color %1 to clipboard</source> |
6 | 7 | <translation>拷贝颜色%1到剪切板</translation> |
7 | 8 | </message> |
9 | 10 | <context> |
10 | 11 | <name>MainWindow</name> |
11 | 12 | <message> |
12 | <location filename="../src/main.cpp" line="45"/> | |
13 | 13 | <source>Deepin picker is a small, easy-to-use screen picker.</source> |
14 | 14 | <translation>深度取色器是一个小巧易用的屏幕取色器。</translation> |
15 | 15 | </message> |
16 | 16 | <message> |
17 | <location filename="../src/main.cpp" line="60"/> | |
18 | 17 | <source>Deepin Picker</source> |
19 | 18 | <translation>深度取色器</translation> |
20 | 19 | </message> |
21 | 20 | </context> |
22 | </TS>⏎ | |
21 | </TS> |