初始化项目结构
This commit is contained in:
parent
407a0193b1
commit
f2085a9890
|
@ -0,0 +1,73 @@
|
||||||
|
# This file is used to ignore files which are generated
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
*~
|
||||||
|
*.autosave
|
||||||
|
*.a
|
||||||
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*_pch.h.cpp
|
||||||
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
|
.#*
|
||||||
|
*.*#
|
||||||
|
core
|
||||||
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
|
/.qmake.cache
|
||||||
|
/.qmake.stash
|
||||||
|
|
||||||
|
# qtcreator generated files
|
||||||
|
*.pro.user*
|
||||||
|
|
||||||
|
# xemacs temporary files
|
||||||
|
*.flc
|
||||||
|
|
||||||
|
# Vim temporary files
|
||||||
|
.*.swp
|
||||||
|
|
||||||
|
# Visual Studio generated files
|
||||||
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
|
# MinGW generated files
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
|
||||||
|
project(ukui-notification LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core LinguistTools DBus REQUIRED)
|
||||||
|
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core LinguistTools DBus REQUIRED)
|
||||||
|
include_directories()
|
||||||
|
add_subdirectory(notification-server)
|
||||||
|
add_subdirectory(libukui-notification)
|
||||||
|
|
||||||
|
|
34
README.en.md
34
README.en.md
|
@ -1,36 +1,4 @@
|
||||||
# ukui-notification
|
# ukui-notification
|
||||||
|
|
||||||
#### Description
|
#### Description
|
||||||
通知中心
|
ukui-notification
|
||||||
|
|
||||||
#### Software Architecture
|
|
||||||
Software architecture description
|
|
||||||
|
|
||||||
#### Installation
|
|
||||||
|
|
||||||
1. xxxx
|
|
||||||
2. xxxx
|
|
||||||
3. xxxx
|
|
||||||
|
|
||||||
#### Instructions
|
|
||||||
|
|
||||||
1. xxxx
|
|
||||||
2. xxxx
|
|
||||||
3. xxxx
|
|
||||||
|
|
||||||
#### Contribution
|
|
||||||
|
|
||||||
1. Fork the repository
|
|
||||||
2. Create Feat_xxx branch
|
|
||||||
3. Commit your code
|
|
||||||
4. Create Pull Request
|
|
||||||
|
|
||||||
|
|
||||||
#### Gitee Feature
|
|
||||||
|
|
||||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
|
||||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
|
||||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
|
||||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
|
||||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
|
||||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
||||||
|
|
33
README.md
33
README.md
|
@ -2,36 +2,3 @@
|
||||||
|
|
||||||
#### 介绍
|
#### 介绍
|
||||||
通知中心
|
通知中心
|
||||||
|
|
||||||
#### 软件架构
|
|
||||||
软件架构说明
|
|
||||||
|
|
||||||
|
|
||||||
#### 安装教程
|
|
||||||
|
|
||||||
1. xxxx
|
|
||||||
2. xxxx
|
|
||||||
3. xxxx
|
|
||||||
|
|
||||||
#### 使用说明
|
|
||||||
|
|
||||||
1. xxxx
|
|
||||||
2. xxxx
|
|
||||||
3. xxxx
|
|
||||||
|
|
||||||
#### 参与贡献
|
|
||||||
|
|
||||||
1. Fork 本仓库
|
|
||||||
2. 新建 Feat_xxx 分支
|
|
||||||
3. 提交代码
|
|
||||||
4. 新建 Pull Request
|
|
||||||
|
|
||||||
|
|
||||||
#### 特技
|
|
||||||
|
|
||||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
|
||||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
|
||||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
|
||||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
|
||||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
|
||||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
set(notificationServer_SRCS
|
||||||
|
server.h
|
||||||
|
server-private.h
|
||||||
|
server.cpp
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
qt_add_dbus_adaptor(notificationServer_SRCS dbus/org.freedesktop.Notifications.xml server-private.h NotificationServer::ServerPrivate)
|
||||||
|
qt_add_dbus_adaptor(notificationServer_SRCS dbus/org.ukui.notificationServer.xml server-private.h NotificationServer::ServerPrivate)
|
||||||
|
|
||||||
|
add_executable(ukui-notification-server ${notificationServer_SRCS})
|
||||||
|
target_link_libraries(ukui-notification-server
|
||||||
|
PRIVATE
|
||||||
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
|
Qt${QT_VERSION_MAJOR}::DBus
|
||||||
|
)
|
||||||
|
set(TS_FILES ukui-notification_zh_CN.ts)
|
||||||
|
if(COMMAND qt_create_translation)
|
||||||
|
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR}/translations ${TS_FILES})
|
||||||
|
else()
|
||||||
|
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR}/translations ${TS_FILES})
|
||||||
|
endif()
|
|
@ -0,0 +1,41 @@
|
||||||
|
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||||
|
<node>
|
||||||
|
<interface name="org.freedesktop.Notifications">
|
||||||
|
<method name="GetCapabilities">
|
||||||
|
<arg type="as" name="caps" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="Notify">
|
||||||
|
<annotation name="org.qtproject.QtDBus.QtTypeName.In6" value="QVariantMap"/>
|
||||||
|
<arg type="u" direction="out"/>
|
||||||
|
<arg name="app_name" type="s" direction="in"/>
|
||||||
|
<arg name="replaces_id" type="u" direction="in"/>
|
||||||
|
<arg name="app_icon" type="s" direction="in"/>
|
||||||
|
<arg name="summary" type="s" direction="in"/>
|
||||||
|
<arg name="body" type="s" direction="in"/>
|
||||||
|
<arg name="actions" type="as" direction="in"/>
|
||||||
|
<arg name="hints" type="a{sv}" direction="in"/>
|
||||||
|
<arg name="timeout" type="i" direction="in"/>
|
||||||
|
</method>
|
||||||
|
<method name="CloseNotification">
|
||||||
|
<arg name="id" type="u" direction="in"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetServerInformation">
|
||||||
|
<arg type="s" name="name" direction="out"/>
|
||||||
|
<arg type="s" name="vendor" direction="out"/>
|
||||||
|
<arg type="s" name="version" direction="out"/>
|
||||||
|
<arg type="s" name="spec_version" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<signal name="NotificationClosed">
|
||||||
|
<arg name="id" type="u" direction="out"/>
|
||||||
|
<arg name="reason" type="u" direction="out"/>
|
||||||
|
</signal>
|
||||||
|
<signal name="ActionInvoked">
|
||||||
|
<arg name="id" type="u" direction="out"/>
|
||||||
|
<arg name="action_key" type="s" direction="out"/>
|
||||||
|
</signal>
|
||||||
|
<signal name="ActivationToken">
|
||||||
|
<arg name="id" type="u" direction="out"/>
|
||||||
|
<arg name="activation_token" type="s" direction="out"/>
|
||||||
|
</signal>
|
||||||
|
</interface>
|
||||||
|
</node>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||||
|
<node>
|
||||||
|
<interface name="org.ukui.NotificationServer">
|
||||||
|
<method name="RegisterClient"/>
|
||||||
|
<method name="UnRegisterClient"/>
|
||||||
|
</interface>
|
||||||
|
</node>
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
QTranslator translator;
|
||||||
|
const QStringList uiLanguages = QLocale::system().uiLanguages();
|
||||||
|
for (const QString &locale : uiLanguages) {
|
||||||
|
const QString baseName = "ukui-notification_" + QLocale(locale).name();
|
||||||
|
if (translator.load(":/i18n/" + baseName)) {
|
||||||
|
a.installTranslator(&translator);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
//
|
||||||
|
// Created by zpf on 23-1-31.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef UKUI_NOTIFICATION_SERVER_PRIVATE_H
|
||||||
|
#define UKUI_NOTIFICATION_SERVER_PRIVATE_H
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDBusContext>
|
||||||
|
class QDBusServiceWatcher;
|
||||||
|
namespace NotificationServer {
|
||||||
|
|
||||||
|
class ServerPrivate : public QObject, protected QDBusContext
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ServerPrivate(QObject *parent);
|
||||||
|
~ServerPrivate();
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
static QString notificationServiceName();
|
||||||
|
static QString notificationServicePath();
|
||||||
|
static QString notificationServiceInterface();
|
||||||
|
|
||||||
|
QStringList GetCapabilities() const;
|
||||||
|
uint Notify(const QString &app_name,
|
||||||
|
uint replaces_id,
|
||||||
|
const QString &app_icon,
|
||||||
|
const QString &summary,
|
||||||
|
const QString &body,
|
||||||
|
const QStringList &actions,
|
||||||
|
const QVariantMap &hints,
|
||||||
|
int timeout);
|
||||||
|
void CloseNotification(uint id);
|
||||||
|
QString GetServerInformation(QString &vendor, QString &version, QString &specVersion) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册成为通知中心客户端
|
||||||
|
*/
|
||||||
|
void RegisterClient();
|
||||||
|
/**
|
||||||
|
* 注销
|
||||||
|
*/
|
||||||
|
void UnRegisterClient();
|
||||||
|
Q_SIGNALS:
|
||||||
|
void NotificationClosed(uint id, uint reason);
|
||||||
|
void ActionInvoked(uint id, const QString &actionKey);
|
||||||
|
void ActivationToken(uint id, const QString &ActivationToken);
|
||||||
|
private:
|
||||||
|
QDBusServiceWatcher *m_notificationWatchers = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // NotificationServer
|
||||||
|
|
||||||
|
#endif //UKUI_NOTIFICATION_SERVER_PRIVATE_H
|
|
@ -0,0 +1,99 @@
|
||||||
|
//
|
||||||
|
// Created by zpf on 23-1-31.
|
||||||
|
//
|
||||||
|
#include <QDBusServiceWatcher>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include "server.h"
|
||||||
|
#include "server-private.h"
|
||||||
|
#include "notificationsadaptor.h"
|
||||||
|
|
||||||
|
namespace NotificationServer {
|
||||||
|
ServerPrivate::ServerPrivate(QObject *parent) : QObject(parent), m_notificationWatchers(new QDBusServiceWatcher(this))
|
||||||
|
{
|
||||||
|
m_notificationWatchers->setConnection(QDBusConnection::sessionBus());
|
||||||
|
m_notificationWatchers->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
|
||||||
|
connect(m_notificationWatchers, &QDBusServiceWatcher::serviceUnregistered, m_notificationWatchers, &QDBusServiceWatcher::removeWatchedService);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerPrivate::~ServerPrivate() = default;
|
||||||
|
|
||||||
|
QStringList ServerPrivate::GetCapabilities() const
|
||||||
|
{
|
||||||
|
return QStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint ServerPrivate::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary,
|
||||||
|
const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServerPrivate::GetServerInformation(QString &vendor, QString &version, QString &specVersion) const
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerPrivate::CloseNotification(uint id)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServerPrivate::init()
|
||||||
|
{
|
||||||
|
new NotificationsAdaptor(this);
|
||||||
|
if(QDBusConnection::sessionBus().registerObject(notificationServicePath(), this)) {
|
||||||
|
qWarning() << "Failed to register Notification DBus object!";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto registration = QDBusConnection::sessionBus().interface()->registerService(notificationServiceName(),
|
||||||
|
QDBusConnectionInterface::ReplaceExistingService,
|
||||||
|
QDBusConnectionInterface::DontAllowReplacement);
|
||||||
|
if (registration.value() != QDBusConnectionInterface::ServiceRegistered) {
|
||||||
|
qWarning() << "Failed to register Notification service on DBus!";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServerPrivate::notificationServiceName()
|
||||||
|
{
|
||||||
|
return QStringLiteral("org.freedesktop.Notifications");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServerPrivate::notificationServicePath()
|
||||||
|
{
|
||||||
|
return QStringLiteral("/org/freedesktop/Notifications");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServerPrivate::notificationServiceInterface()
|
||||||
|
{
|
||||||
|
return QStringLiteral("org.freedesktop.Notifications");;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerPrivate::RegisterClient()
|
||||||
|
{
|
||||||
|
m_notificationWatchers->addWatchedService(message().service());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerPrivate::UnRegisterClient()
|
||||||
|
{
|
||||||
|
m_notificationWatchers->removeWatchedService(message().service());
|
||||||
|
}
|
||||||
|
|
||||||
|
Server::Server(QObject *parent): QObject(parent), d(new ServerPrivate(this))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Server &Server::self()
|
||||||
|
{
|
||||||
|
static Server self;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Server::init()
|
||||||
|
{
|
||||||
|
return d->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
Server::~Server() = default;
|
||||||
|
} // NotificationServer
|
|
@ -0,0 +1,25 @@
|
||||||
|
//
|
||||||
|
// Created by zpf on 23-1-31.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef UKUI_NOTIFICATION_SERVER_H
|
||||||
|
#define UKUI_NOTIFICATION_SERVER_H
|
||||||
|
#include <QObject>
|
||||||
|
namespace NotificationServer {
|
||||||
|
class ServerPrivate;
|
||||||
|
class Server : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
static Server &self();
|
||||||
|
~Server();
|
||||||
|
bool init();
|
||||||
|
private:
|
||||||
|
explicit Server(QObject *parent = nullptr);
|
||||||
|
Q_DISABLE_COPY(Server)
|
||||||
|
ServerPrivate *d = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // NotificationServer
|
||||||
|
|
||||||
|
#endif //UKUI_NOTIFICATION_SERVER_H
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="zh_CN">
|
||||||
|
</TS>
|
Loading…
Reference in New Issue