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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ find_package(
Widgets
WaylandClient)
find_package(Qt6WaylandScannerTools REQUIRED)
find_package(Dtk6 REQUIRED COMPONENTS Core Widget)
find_package(X11 REQUIRED)

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

add_executable(${PROJECT_NAME}
Expand All @@ -78,12 +82,14 @@ qt6_generate_wayland_protocol_client_sources(${PROJECT_NAME}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
${DtkWidget_LIBRARIES}
Qt::Core
Qt::Widgets
Qt::Gui
Qt::DBus
Qt::Concurrent
Qt::WaylandClient
${X11_LIBRARIES}
xdg-desktop-portal-dde-wayland
)

Expand Down
33 changes: 3 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 @@ -26,34 +27,6 @@ uint AccessPortal::AccessDialog(
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;
accessDialog dialog(app_id,parent_window,title,subtitle,body,options);
return dialog.exec();
}
89 changes: 89 additions & 0 deletions src/accessdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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>

Display* getX11Display() {
// 使用 XOpenDisplay 获取 X11 Display
Display *display = XOpenDisplay(nullptr); // 使用默认的 Display
if (!display) {
qWarning() << "Failed to open X11 display";
}
return display;
}

// 从 X11 Display 获取屏幕几何信息
QRect getScreenGeometryFromX11(Display *display, Window screenNumber) {
if (!display) {
return QRect();
}
QRect geometry;
geometry.setLeft(0);
geometry.setTop(0);
geometry.setWidth(DisplayWidth(display, screenNumber));
geometry.setHeight(DisplayHeight(display, screenNumber));
return geometry;
}

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("不允许", QMessageBox::RejectRole);
}


int allowButton;
if (options.contains(QStringLiteral("grant_label"))) {
addButton(options.value(QStringLiteral("grant_label")).toString(), QMessageBox::AcceptRole);
} else {
addButton("好", 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
Loading