Codebase list deepin-picker / b4b61e4
Use dbusnotify module to fixed notify window can't hide when popup new notify. Andy Stewart 6 years ago
5 changed file(s) with 222 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
1515 src/colormenu.h \
1616 src/clipboard.h \
1717 src/animation.h \
18 src/dbusnotify.h \
1819 src/settings.h \
1920 src/utils.h
2021 SOURCES += src/picker.cpp \
2223 src/colormenu.cpp \
2324 src/clipboard.cpp \
2425 src/animation.cpp \
26 src/dbusnotify.cpp \
2527 src/settings.cpp \
2628 src/utils.cpp \
2729 src/main.cpp
1818 *
1919 * You should have received a copy of the GNU General Public License
2020 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
21 */
2222
2323 #include "clipboard.h"
24 #include "dbusnotify.h"
2425 #include "settings.h"
2526 #include "utils.h"
2627 #include <QApplication>
3536
3637 Clipboard::~Clipboard()
3738 {
38
39
3940 }
4041
4142 void Clipboard::copyToClipboard(QColor color, QString colorType)
5354 } else if (colorType == "Float_RGBA") {
5455 colorString = Utils::colorToFloatRGBA(color);
5556 }
56
57
5758 Settings *settings = new Settings();
5859 settings->setOption("color_type", colorType);
59
60
6061 // 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
6664
6765 QStringList actions;
6866 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
8178 // Copy to clipbard.
8279 QClipboard *clipboard = QApplication::clipboard();
8380 clipboard->setText(colorString);
84
81
8582 // Quit application.
8683 QApplication::quit();
8784 }
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">
13 <context>
24 <name>Clipboard</name>
35 <message>
4 <location filename="../src/clipboard.cpp" line="76"/>
56 <source>Copy color %1 to clipboard</source>
67 <translation>拷贝颜色%1到剪切板</translation>
78 </message>
910 <context>
1011 <name>MainWindow</name>
1112 <message>
12 <location filename="../src/main.cpp" line="45"/>
1313 <source>Deepin picker is a small, easy-to-use screen picker.</source>
1414 <translation>深度取色器是一个小巧易用的屏幕取色器。</translation>
1515 </message>
1616 <message>
17 <location filename="../src/main.cpp" line="60"/>
1817 <source>Deepin Picker</source>
1918 <translation>深度取色器</translation>
2019 </message>
2120 </context>
22 </TS>
21 </TS>