Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modify accessdialog to dtk style #56

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .tx/deepin.conf

This file was deleted.

11 changes: 11 additions & 0 deletions .tx/transifex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0
filters:
- filter_type: file
source_file: misc/translations/translations/xdg-desktop-portal-dde_en.ts
file_format: QT
source_language: en_US
translation_files_expression: misc/translations/translations/xdg-desktop-portal-dde_<lang>.ts
settings:
pr_branch_name: transifex_update_<br_unique_id>
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)
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Build-Depends:
libpipewire-0.3-dev,
libwayland-dev,
wlr-protocols,
libdtk6widget-dev,
libdtk6core-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)
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();
}
62 changes: 62 additions & 0 deletions src/accessdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2024 Wenhao Peng <[email protected]>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#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(){

}
28 changes: 28 additions & 0 deletions src/accessdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2024 Wenhao Peng <[email protected]>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#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
Loading