Skip to content

Commit

Permalink
fix: modify accessdialog to dtk style
Browse files Browse the repository at this point in the history
modify accessdialog to dtk style
  • Loading branch information
fuleyi committed Oct 9, 2024
1 parent eede71f commit 8b68690
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xdg-desktop-portal-dde.service DESTINA
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.impl.portal.desktop.dde.service DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services")
install(FILES ${CMAKE_CURRENT_LIST_DIR}/misc/dde.portal DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/xdg-desktop-portal/portals/")
install(FILES ${CMAKE_CURRENT_LIST_DIR}/misc/dde-portals.conf DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/xdg-desktop-portal/")

add_subdirectory(misc)
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Build-Depends:
libpipewire-0.3-dev,
libwayland-dev,
wlr-protocols,
libdtk6widget-dev,
Standards-Version: 4.5.0

Package: xdg-desktop-portal-dde
Expand Down
4 changes: 4 additions & 0 deletions misc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: None
#
# SPDX-License-Identifier: CC0-1.0
add_subdirectory(translations)
6 changes: 6 additions & 0 deletions misc/translations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# generate qm
execute_process(COMMAND bash "misc/translations/translate_generation.sh"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

file(GLOB QM_FILES "translations/*.qm")
install(FILES ${QM_FILES} DESTINATION share/${PROJECT_NAME}/translations)
15 changes: 15 additions & 0 deletions misc/translations/lupdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

CURRENT_DIR=$(pwd)
PROJECT_DIR=$(dirname $(realpath $(dirname $(realpath $(dirname $(realpath $0))))))
cd ${PROJECT_DIR}
echo 当前目录:${CURRENT_DIR}
echo 工程目录:${PROJECT_DIR}
# 执行目录会切换到工程目录

# xdg-desktop-portal-dde
lupdate ${PROJECT_DIR}/src -no-obsolete -no-ui-lines -locations none -ts ${PROJECT_DIR}/misc/translations/translations/xdg-desktop-portal-dde_en.ts

# 推送翻译
tx push -s --branch m23
cd ${CURRENT_DIR}
18 changes: 18 additions & 0 deletions misc/translations/translate_generation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# this file is used to auto-generate .qm file from .ts file.
# author: shibowen at linuxdeepin.com
CURRENT_DIR=$(pwd)
PROJECT_DIR=$CURRENT_DIR/misc/translations
cd ${PROJECT_DIR}
echo 当前目录:${CURRENT_DIR}
echo 工程目录:${PROJECT_DIR}

ts_list=(`ls translations/*.ts`)

for ts in "${ts_list[@]}"
do
printf "\nprocess ${ts}\n"
lrelease "${ts}"
done

cd ${CURRENT_DIR}
30 changes: 30 additions & 0 deletions misc/translations/translations/xdg-desktop-portal-dde_en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>AccessDialog</name>
<message>
<location filename="../../../src/accessdialog.cpp" line="51"/>
<source>Deny Access</source>
<translation>Deny Access</translation>
</message>
<message>
<location filename="../../../src/accessdialog.cpp" line="59"/>
<source>Grant Access</source>
<translation>Grant Access</translation>
</message>
</context>
<context>
<name>AppChooserDialog</name>
<message>
<location filename="../../../src/appchooserdialog.cpp" line="18"/>
<source>Cancel</source>
<translation>Cancel</translation>
</message>
<message>
<location filename="../../../src/appchooserdialog.cpp" line="19"/>
<source>Confirm</source>
<translation>Confirm</translation>
</message>
</context>
</TS>
30 changes: 30 additions & 0 deletions misc/translations/translations/xdg-desktop-portal-dde_zh_CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>AccessDialog</name>
<message>
<location filename="../../../src/accessdialog.cpp" line="51"/>
<source>Deny Access</source>
<translation>拒绝</translation>
</message>
<message>
<location filename="../../../src/accessdialog.cpp" line="59"/>
<source>Grant Access</source>
<translation>授权</translation>
</message>
</context>
<context>
<name>AppChooserDialog</name>
<message>
<location filename="../../../src/appchooserdialog.cpp" line="18"/>
<source>Cancel</source>
<translation>取消</translation>
</message>
<message>
<location filename="../../../src/appchooserdialog.cpp" line="19"/>
<source>Confirm</source>
<translation>确认</translation>
</message>
</context>
</TS>
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ find_package(
Widgets
WaylandClient)
find_package(Qt6WaylandScannerTools REQUIRED)
find_package(Dtk6 REQUIRED COMPONENTS Core Widget)

set_source_files_properties(
${CMAKE_SOURCE_DIR}/misc/org.freedesktop.Notifications.xml
Expand Down Expand Up @@ -67,6 +68,8 @@ set(SRC
utils.cpp
personalization_manager_client.h
personalization_manager_client.cpp
accessdialog.h
accessdialog.cpp
)

add_executable(${PROJECT_NAME}
Expand All @@ -78,6 +81,7 @@ qt6_generate_wayland_protocol_client_sources(${PROJECT_NAME}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
Dtk6::Widget
Qt::Core
Qt::Widgets
Qt::Gui
Expand Down
35 changes: 5 additions & 30 deletions src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QDBusPendingReply>
#include <QDBusConnection>
#include <QMessageBox>
#include "accessdialog.h"

Q_LOGGING_CATEGORY(XdgDestkopDDEAccess, "xdg-dde-access")

Expand All @@ -21,39 +22,13 @@ AccessPortal::AccessPortal(QObject *parent)
qCDebug(XdgDestkopDDEAccess) << "access init";
}

using AccessDialogClass = AccessDialog;

uint AccessPortal::AccessDialog(
const QDBusObjectPath &handle, const QString &app_id, const QString &parent_window, const QString &title,
const QString &subtitle, const QString &body, const QVariantMap &options, QVariantMap &results)
{
qCDebug(XdgDestkopDDEAccess) << "request for access dialog";

QMessageBox access_dialog;

if (options.contains(QStringLiteral("modal"))) {
access_dialog.setModal(options.value(QStringLiteral("modal")).toBool());
}

QPushButton *rejectButton = nullptr;
if (options.contains(QStringLiteral("deny_label"))) {
rejectButton = access_dialog.addButton(options.value(QStringLiteral("deny_label")).toString(), QMessageBox::RejectRole);
}


QPushButton *allowButton = nullptr;
if (options.contains(QStringLiteral("grant_label"))) {
allowButton = access_dialog.addButton(options.value(QStringLiteral("grant_label")).toString(), QMessageBox::AcceptRole);
}

access_dialog.setWindowTitle(title);
access_dialog.setText(body);
access_dialog.exec();

uint respnse = 2;
if (access_dialog.clickedButton() == (QAbstractButton*)rejectButton) {
respnse = 0;
} else if (access_dialog.clickedButton() == (QAbstractButton*)allowButton) {
respnse = 1;
}

return respnse;
AccessDialogClass dialog(app_id,parent_window,title,subtitle,body,options);
return dialog.exec();
}
67 changes: 67 additions & 0 deletions src/accessdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

//
// Created by uos on 24-9-9.
//

#include "accessdialog.h"
#include <QWindow>
#include <QMessageBox>
// X11的声明放在下面,防止编译报错
#include <X11/Xlib.h>

AccessDialog::AccessDialog(const QString &app_id, const QString &parent_window, const QString &title, const QString &subtitle, const QString &body, const QVariantMap &options) :
DDialog(),
m_titleLabel(new QLabel(this)),
m_subtitleLabel(new QLabel(this)),
m_bodyLabel(new QLabel(this))
{
setAccessibleName("AccessDialog");
setIcon(QIcon::fromTheme("dialog-warning"));
setAttribute(Qt::WA_QuitOnClose);
// 设置tittle
m_titleLabel->setObjectName("TitileText");
m_titleLabel->setAccessibleName("TitileText");
addContent(m_titleLabel, Qt::AlignTop | Qt::AlignHCenter);
QFont font = m_titleLabel->font();
font.setBold(true);
font.setPixelSize(16);
m_titleLabel->setFont(font);
m_titleLabel->setText(title);
// 设置subtitle
m_subtitleLabel->setObjectName("SubtitleText");
m_subtitleLabel->setAccessibleName("SubtitleText");
addContent(m_subtitleLabel, Qt::AlignTop | Qt::AlignHCenter);
m_subtitleLabel->setText(subtitle+"\n");
// 设置body
m_bodyLabel->setObjectName("BodyText");
m_bodyLabel->setAccessibleName("BodyText");
addContent(m_bodyLabel, Qt::AlignTop | Qt::AlignHCenter);
m_bodyLabel->setText(body);

if (options.contains(QStringLiteral("modal"))) {
setModal(options.value(QStringLiteral("modal")).toBool());
}

if (options.contains(QStringLiteral("deny_label"))) {
addButton(options.value(QStringLiteral("deny_label")).toString(), QMessageBox::RejectRole);
} else {
addButton(tr("Deny Access"), QMessageBox::RejectRole);
}


int allowButton;
if (options.contains(QStringLiteral("grant_label"))) {
addButton(options.value(QStringLiteral("grant_label")).toString(), QMessageBox::AcceptRole);
} else {
addButton(tr("Grant Access"), QMessageBox::AcceptRole);
}

setWindowFlag(Qt::WindowStaysOnTopHint);
}

AccessDialog::~AccessDialog(){

}
33 changes: 33 additions & 0 deletions src/accessdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

//
// Created by uos on 24-9-9.
//

#ifndef XDG_DESKTOP_PORTAL_DDE_ACCESSDIALOG_H
#define XDG_DESKTOP_PORTAL_DDE_ACCESSDIALOG_H

#include <ddialog.h>
#include <DWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QDialogButtonBox>

DWIDGET_USE_NAMESPACE
class LargeLabel;

class AccessDialog : public DDialog
{
Q_OBJECT
public:
explicit AccessDialog(const QString &app_id,const QString &parent_window,const QString &title,const QString &subtitle,const QString &body, const QVariantMap &options);
~AccessDialog();
private:
QLabel *m_titleLabel;
QLabel *m_subtitleLabel;
QLabel *m_bodyLabel;
};

#endif // XDG_DESKTOP_PORTAL_DDE_ACCESSDIALOG_H
9 changes: 9 additions & 0 deletions src/xdg-desktop-portal-dde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <QDBusConnection>
#include <qstringliteral.h>
#include <QLoggingCategory>
#include <QTranslator>
#include <QStandardPaths>

Q_LOGGING_CATEGORY(XdgDesktopDDE, "xdg-dde")

Expand All @@ -33,6 +35,13 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);

QTranslator translator;
QString languagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QString("xdg-desktop-portal-dde/translations"),
QStandardPaths::LocateDirectory);
translator.load(languagePath+"/xdg-desktop-portal-dde_" + QLocale::system().name());
a.installTranslator(&translator);

QDBusConnection sessionBus = QDBusConnection::sessionBus();
if (sessionBus.registerService(QStringLiteral("org.freedesktop.impl.portal.desktop.dde"))) {
if (onWayland()) {
Expand Down

0 comments on commit 8b68690

Please sign in to comment.