-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notify encapsulation of org.freedesktop.Notifications for easy callers to send simple notifications Change-Id: If13a6b0051535e62049f3425682a41eee81857ef
- Loading branch information
1 parent
62c6912
commit 89bbcd7
Showing
4 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "dnotifysender.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (C) 2017 ~ 2019 Deepin Technology Co., Ltd. | ||
* | ||
* Author: justforlxz <zhangdingyuan@deepin.com> | ||
* | ||
* Maintainer: justforlxz <zhangdingyuan@deepin.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "dnotifysender.h" | ||
#include "ddbussender.h" | ||
|
||
DCORE_BEGIN_NAMESPACE | ||
|
||
namespace DUtil { | ||
|
||
struct DNotifyData { | ||
uint m_replaceId; | ||
int m_timeOut; | ||
QString m_body; | ||
QString m_summary; | ||
QString m_appIcon; | ||
QString m_appName; | ||
QStringList m_actions; | ||
QVariantMap m_hints; | ||
}; | ||
|
||
DNotifySender::DNotifySender(const QString &summary) : m_dbusData(std::make_shared<DNotifyData>()) | ||
{ | ||
m_dbusData->m_summary = summary; | ||
} | ||
|
||
DNotifySender DNotifySender::appName(const QString &appName) | ||
{ | ||
m_dbusData->m_appName = appName; | ||
|
||
return *this; | ||
} | ||
|
||
DNotifySender DNotifySender::appIcon(const QString &appIcon) | ||
{ | ||
m_dbusData->m_appIcon = appIcon; | ||
|
||
return *this; | ||
} | ||
|
||
DNotifySender DNotifySender::appBody(const QString &appBody) | ||
{ | ||
m_dbusData->m_body = appBody; | ||
|
||
return *this; | ||
} | ||
|
||
DNotifySender DNotifySender::replaceId(const uint replaceId) | ||
{ | ||
m_dbusData->m_replaceId = replaceId; | ||
|
||
return *this; | ||
} | ||
|
||
DNotifySender DNotifySender::timeOut(const int timeOut) | ||
{ | ||
m_dbusData->m_timeOut = timeOut; | ||
|
||
return *this; | ||
} | ||
|
||
DNotifySender DNotifySender::actions(const QStringList &actions) | ||
{ | ||
m_dbusData->m_actions = actions; | ||
|
||
return *this; | ||
} | ||
|
||
DNotifySender DNotifySender::hints(const QVariantMap &hints) | ||
{ | ||
m_dbusData->m_hints = hints; | ||
|
||
return *this; | ||
} | ||
|
||
QDBusPendingCall DNotifySender::call() | ||
{ | ||
return DDBusSender() | ||
.service("org.freedesktop.Notifications") | ||
.path("/org/freedesktop/Notifications") | ||
.interface("org.freedesktop.Notifications") | ||
.method(QString("Notify")) | ||
.arg(m_dbusData->m_appName) | ||
.arg(m_dbusData->m_replaceId) | ||
.arg(m_dbusData->m_appIcon) | ||
.arg(m_dbusData->m_summary) | ||
.arg(m_dbusData->m_body) | ||
.arg(m_dbusData->m_actions) | ||
.arg(m_dbusData->m_hints) | ||
.arg(m_dbusData->m_timeOut) | ||
.call(); | ||
} | ||
|
||
} // namespace DUtil | ||
|
||
DCORE_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef DNOTIFYSENDER_H | ||
#define DNOTIFYSENDER_H | ||
|
||
#include "dtkcore_global.h" | ||
|
||
#include <QDBusPendingCall> | ||
#include <memory> | ||
|
||
DCORE_BEGIN_NAMESPACE | ||
|
||
namespace DUtil { | ||
struct DNotifyData; | ||
class LIBDTKCORESHARED_EXPORT DNotifySender { | ||
public: | ||
DNotifySender(const QString &summary); | ||
DNotifySender appName(const QString &appName = QString()); | ||
DNotifySender appIcon(const QString &appIcon = QString()); | ||
DNotifySender appBody(const QString &appBody = QString()); | ||
DNotifySender replaceId(const uint replaceId = 0); | ||
DNotifySender timeOut(const int timeOut = -1); | ||
DNotifySender actions(const QStringList &actions = QStringList()); | ||
DNotifySender hints(const QVariantMap &hints = QVariantMap()); | ||
QDBusPendingCall call(); | ||
|
||
private: | ||
std::shared_ptr<DNotifyData> m_dbusData; | ||
}; | ||
} // namespace DUtil | ||
|
||
DCORE_END_NAMESPACE | ||
|
||
#endif // DNOTIFYSENDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters