From 582e8cf2e9b4753571fdff3ca2650ee5a21a5308 Mon Sep 17 00:00:00 2001 From: Elysia Date: Fri, 29 Nov 2024 18:51:32 +0800 Subject: [PATCH] feat(notificationd): enable notificationd module and update to Qt6/KF6 --- CMakeLists.txt | 2 +- notificationd/CMakeLists.txt | 16 ++++++++-------- notificationd/datehelper.cpp | 4 +++- notificationd/dbus/notificationsadaptor.h | 15 +++++++-------- notificationd/historymodel.cpp | 6 +++--- notificationd/notificationpopup.cpp | 4 +++- notificationd/notificationwindow.cpp | 4 +++- notificationd/qml/IconButton.qml | 2 +- notificationd/qml/NotificationWindow.qml | 2 +- notificationd/qml/QmlNotificationPopup.qml | 2 +- notificationd/qml/main.qml | 2 +- notificationd/translations/en_US.ts | 18 +++++++++--------- notificationd/translations/zh_CN.ts | 18 +++++++++--------- 13 files changed, 50 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69fb4a9..e5257ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ add_subdirectory(powerman) add_subdirectory(cpufreq) add_subdirectory(cupdatecursor) add_subdirectory(gmenuproxy) -# add_subdirectory(notificationd) +add_subdirectory(notificationd) # add_subdirectory(sddm-helper) # add_subdirectory(clipboard) # add_subdirectory(chotkeys) diff --git a/notificationd/CMakeLists.txt b/notificationd/CMakeLists.txt index 258cc5d..a699146 100644 --- a/notificationd/CMakeLists.txt +++ b/notificationd/CMakeLists.txt @@ -17,10 +17,10 @@ set(SRCS main.cpp # for Ubuntu # qt_add_dbus_adaptor(SRCS org.freedesktop.Notifications.xml notificationserver.h NotificationServer) -qt5_add_dbus_adaptor(DBUS_SOURCES com.lingmo.Notification.xml application.h Application) +qt_add_dbus_adaptor(DBUS_SOURCES com.lingmo.Notification.xml application.h Application) set_source_files_properties(${DBUS_SOURCES} PROPERTIES SKIP_AUTOGEN ON) -find_package(KF5WindowSystem) +find_package(KF6WindowSystem) add_executable(lingmo-notificationd ${SRCS} ${DBUS_SOURCES}) @@ -29,14 +29,14 @@ foreach(filepath ${TS_FILES}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) list(APPEND ts_files_replaced ${filename}) endforeach() -qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${ts_files_replaced}) +qt6_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${ts_files_replaced}) target_link_libraries(lingmo-notificationd - Qt5::Core - Qt5::DBus - Qt5::Quick - Qt5::Widgets - KF5::WindowSystem + Qt6::Core + Qt6::DBus + Qt6::Quick + Qt6::Widgets + KF6::WindowSystem ) install(TARGETS lingmo-notificationd diff --git a/notificationd/datehelper.cpp b/notificationd/datehelper.cpp index 396fd01..995fb6a 100644 --- a/notificationd/datehelper.cpp +++ b/notificationd/datehelper.cpp @@ -1,5 +1,6 @@ #include "datehelper.h" #include +#include DateHelper::DateHelper(QObject *parent) : QObject(parent) { @@ -30,5 +31,6 @@ QString DateHelper::friendlyTime(const QDateTime &time) else if (days <= 10) return tr("%1 days ago").arg(days); - return time.toString(Qt::DefaultLocaleShortDate); + QLocale cLocale; + return cLocale.toString(time, QLocale::FormatType::LongFormat); } diff --git a/notificationd/dbus/notificationsadaptor.h b/notificationd/dbus/notificationsadaptor.h index 46c15ca..34cf850 100644 --- a/notificationd/dbus/notificationsadaptor.h +++ b/notificationd/dbus/notificationsadaptor.h @@ -15,14 +15,13 @@ #include #include #include "notificationserver.h" -QT_BEGIN_NAMESPACE -class QByteArray; -template class QList; -template class QMap; -class QString; -class QStringList; -class QVariant; -QT_END_NAMESPACE + +#include +#include +#include +#include +#include +#include /* * Adaptor class for interface org.freedesktop.Notifications diff --git a/notificationd/historymodel.cpp b/notificationd/historymodel.cpp index 50af0be..a2eba37 100644 --- a/notificationd/historymodel.cpp +++ b/notificationd/historymodel.cpp @@ -23,6 +23,7 @@ #include #include #include +#include static HistoryModel *s_historyModel = nullptr; @@ -136,8 +137,7 @@ void HistoryModel::save() settings.clear(); QByteArray datas; - QDataStream out(&datas, QIODevice::WriteOnly); - + QDataStream out(&datas, QDataStream::WriteOnly); out << m_notifications; settings.setValue("datas", datas); @@ -147,7 +147,7 @@ void HistoryModel::initDatas() { QSettings settings(QSettings::UserScope, "lingmoos", "notifications"); QByteArray listByteArray = settings.value("datas").toByteArray(); - QDataStream in(&listByteArray, QIODevice::ReadOnly); + QDataStream in(&listByteArray, QDataStream::WriteOnly); in >> m_notifications; } diff --git a/notificationd/notificationpopup.cpp b/notificationd/notificationpopup.cpp index c4c2b1b..6921efd 100644 --- a/notificationd/notificationpopup.cpp +++ b/notificationd/notificationpopup.cpp @@ -22,7 +22,9 @@ #include #include +#include #include +#include NotificationPopup::NotificationPopup(QQuickView *parent) : QQuickView(parent) @@ -36,7 +38,7 @@ NotificationPopup::NotificationPopup(QQuickView *parent) bool NotificationPopup::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Show) { - KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); + KX11Extras::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); } return QObject::eventFilter(object, event); diff --git a/notificationd/notificationwindow.cpp b/notificationd/notificationwindow.cpp index 7ff0c31..32503bd 100644 --- a/notificationd/notificationwindow.cpp +++ b/notificationd/notificationwindow.cpp @@ -24,7 +24,9 @@ #include #include +#include #include +#include NotificationWindow::NotificationWindow(QQuickView *parent) : QQuickView(parent) @@ -65,7 +67,7 @@ bool NotificationWindow::eventFilter(QObject *object, QEvent *event) QQuickView::setVisible(false); } } else if (event->type() == QEvent::Show) { - KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); + KX11Extras::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); HistoryModel::self()->updateTime(); } else if (event->type() == QEvent::Hide) { setMouseGrabEnabled(false); diff --git a/notificationd/qml/IconButton.qml b/notificationd/qml/IconButton.qml index e63e012..5474fda 100644 --- a/notificationd/qml/IconButton.qml +++ b/notificationd/qml/IconButton.qml @@ -20,7 +20,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 -import LingmoUI 1.0 as LingmoUI +import LingmoUI.Compatible 3.0 as LingmoUI Item { id: control diff --git a/notificationd/qml/NotificationWindow.qml b/notificationd/qml/NotificationWindow.qml index 5bab2b6..e760069 100644 --- a/notificationd/qml/NotificationWindow.qml +++ b/notificationd/qml/NotificationWindow.qml @@ -23,7 +23,7 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.0 -import LingmoUI 1.0 as LingmoUI +import LingmoUI.Compatible 3.0 as LingmoUI import Lingmo.Notification 1.0 Item { diff --git a/notificationd/qml/QmlNotificationPopup.qml b/notificationd/qml/QmlNotificationPopup.qml index 3b9f4e7..3c76850 100644 --- a/notificationd/qml/QmlNotificationPopup.qml +++ b/notificationd/qml/QmlNotificationPopup.qml @@ -22,7 +22,7 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.0 -import LingmoUI 1.0 as LingmoUI +import LingmoUI.Compatible 3.0 as LingmoUI import Lingmo.Notification 1.0 NotificationPopup { diff --git a/notificationd/qml/main.qml b/notificationd/qml/main.qml index b23b0f0..7bea991 100644 --- a/notificationd/qml/main.qml +++ b/notificationd/qml/main.qml @@ -10,7 +10,7 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.0 -import LingmoUI 1.0 as LingmoUI +import LingmoUI.Compatible 3.0 as LingmoUI import Lingmo.Notification 1.0 Item { diff --git a/notificationd/translations/en_US.ts b/notificationd/translations/en_US.ts index caba99f..7356796 100644 --- a/notificationd/translations/en_US.ts +++ b/notificationd/translations/en_US.ts @@ -4,37 +4,37 @@ DateHelper - + Now - + 1 minute ago - + %1 minutes ago - + 1 hour ago - + %1 hours ago - + 1 day ago - + %1 days ago @@ -42,12 +42,12 @@ NotificationWindow - + Notification Center - + No notifications diff --git a/notificationd/translations/zh_CN.ts b/notificationd/translations/zh_CN.ts index 1780ce0..385b71c 100644 --- a/notificationd/translations/zh_CN.ts +++ b/notificationd/translations/zh_CN.ts @@ -4,37 +4,37 @@ DateHelper - + Now 现在 - + 1 minute ago 一分钟前 - + %1 minutes ago %1分钟前 - + 1 hour ago 一小时前 - + %1 hours ago %1小时前 - + 1 day ago 一天前 - + %1 days ago %1天前 @@ -42,12 +42,12 @@ NotificationWindow - + Notification Center 通知中心 - + No notifications 无通知