Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#537
  • Loading branch information
deepin-ci-robot committed Nov 13, 2023
1 parent 50bd273 commit 89d1d77
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 159 deletions.
1 change: 0 additions & 1 deletion include/DWidget/DDesktopServices

This file was deleted.

4 changes: 3 additions & 1 deletion include/util/ddesktopservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

DWIDGET_BEGIN_NAMESPACE

class DDesktopServices
class
D_DECL_DEPRECATED_X("Use Dtk::Gui::DDesktopServices")
DDesktopServices
{
public:

Expand Down
176 changes: 26 additions & 150 deletions src/util/ddesktopservices_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,245 +6,121 @@
#include <QtDBus/QtDBus>
#include <QDebug>
#include <QFile>
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <QGSettings/QGSettings>
#endif

DWIDGET_BEGIN_NAMESPACE

#define EASY_CALL_DBUS(name) \
QDBusInterface *interface = fileManager1DBusInterface(); \
return interface && \
interface->call(#name, urls2uris(urls), startupId).type() != \
QDBusMessage::ErrorMessage;

static const QStringList SOUND_EFFECT_LIST {
"message",
"camera-shutter",
"trash-empty",
"x-deepin-app-sent-to-desktop",
"desktop-login",
"system-shutdown",
"desktop-logout",
"suspend-resume",
"audio-volume-change",
"power-unplug-battery-low",
"power-plug",
"power-unplug",
"device-added",
"device-removed",
"dialog-error",
};

static QDBusInterface *fileManager1DBusInterface()
{
static QDBusInterface interface(QStringLiteral("org.freedesktop.FileManager1"),
QStringLiteral("/org/freedesktop/FileManager1"),
QStringLiteral("org.freedesktop.FileManager1"));
return &interface;
}

static QStringList urls2uris(const QList<QUrl> &urls)
{
QStringList list;

list.reserve(urls.size());

for (const QUrl &url : urls) {
list << url.toString();
}

return list;
}

static QList<QUrl> path2urls(const QList<QString> &paths)
{
QList<QUrl> list;

list.reserve(paths.size());

for (const QString &path : paths) {
list << QUrl::fromLocalFile(path);
}

return list;
}

/*!
\brief Converts \a name from 'key-name' notation
to camel case 'keyName' or 'KeyName'.
This function converts GSettings key names to names
suitable for Qt getters and setters.
Well fsck this.
\a name key name
\return key name converted to camel case
\internal
*/
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
static QString GSettingsKeyToCamelCase(const QString name)
{
QStringList parts = name.split('-',Qt::SkipEmptyParts);
for (int i=1; i<parts.size(); ++i)
parts[i][0] = parts[i][0].toUpper();

return parts.join("");
}
#endif

static bool systemSoundEffectEnabled(const QString &name)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QGSettings settings("com.deepin.dde.sound-effect");
#include <DDesktopServices>
using DGuiDesktopServices = DTK_GUI_NAMESPACE::DDesktopServices;
using DGuiSystemSoundEffect = DGuiDesktopServices::SystemSoundEffect;

const bool effEnabled = settings.get("enabled").toBool();
QString newName = GSettingsKeyToCamelCase(name);

if (effEnabled) {
const QStringList list = settings.keys();
if (!list.contains(newName)) {
return false;
}

return settings.get(newName).toBool();
}

return effEnabled;
#else
return false;
#endif
}
DWIDGET_BEGIN_NAMESPACE

bool DDesktopServices::showFolder(QString localFilePath, const QString &startupId)
{
return showFolder(QUrl::fromLocalFile(localFilePath), startupId);
return DGuiDesktopServices::showFolder(localFilePath, startupId);
}

bool DDesktopServices::showFolders(const QList<QString> localFilePaths, const QString &startupId)
{
return showFolders(path2urls(localFilePaths), startupId);
return DGuiDesktopServices::showFolders(localFilePaths, startupId);
}

bool DDesktopServices::showFolder(QUrl url, const QString &startupId)
{
return showFolders(QList<QUrl>() << url, startupId);
return DGuiDesktopServices::showFolder(url, startupId);
}

bool DDesktopServices::showFolders(const QList<QUrl> urls, const QString &startupId)
{
EASY_CALL_DBUS(ShowFolders)
return DGuiDesktopServices::showFolders(urls, startupId);
}

bool DDesktopServices::showFileItemPropertie(QString localFilePath, const QString &startupId)
{
return showFileItemPropertie(QUrl::fromLocalFile(localFilePath), startupId);
return DGuiDesktopServices::showFileItemProperty(localFilePath , startupId);
}

bool DDesktopServices::showFileItemProperties(const QList<QString> localFilePaths, const QString &startupId)
{
return showFileItemProperties(path2urls(localFilePaths), startupId);
return DGuiDesktopServices::showFileItemProperties(localFilePaths, startupId);
}

bool DDesktopServices::showFileItemPropertie(QUrl url, const QString &startupId)
{
return showFileItemProperties(QList<QUrl>() << url, startupId);
return DGuiDesktopServices::showFileItemProperty(url, startupId);
}

bool DDesktopServices::showFileItemProperties(const QList<QUrl> urls, const QString &startupId)
{
EASY_CALL_DBUS(ShowItemProperties)
return DGuiDesktopServices::showFileItemProperties(urls, startupId);
}

bool DDesktopServices::showFileItem(QString localFilePath, const QString &startupId)
{
return showFileItem(QUrl::fromLocalFile(localFilePath), startupId);
return DGuiDesktopServices::showFileItem(localFilePath, startupId);
}

bool DDesktopServices::showFileItems(const QList<QString> localFilePaths, const QString &startupId)
{
return showFileItems(path2urls(localFilePaths), startupId);
return DGuiDesktopServices::showFileItems(localFilePaths, startupId);
}

bool DDesktopServices::showFileItem(QUrl url, const QString &startupId)
{
return showFileItems(QList<QUrl>() << url, startupId);
return DGuiDesktopServices::showFileItem(url, startupId);
}

bool DDesktopServices::showFileItems(const QList<QUrl> urls, const QString &startupId)
{
EASY_CALL_DBUS(ShowItems)
return DGuiDesktopServices::showFileItems(urls, startupId);
}

bool DDesktopServices::trash(QString localFilePath)
{
return trash(QUrl::fromLocalFile(localFilePath));
return DGuiDesktopServices::trash(localFilePath);
}

bool DDesktopServices::trash(const QList<QString> localFilePaths)
{
return trash(path2urls(localFilePaths));
return DGuiDesktopServices::trash(localFilePaths);
}

bool DDesktopServices::trash(QUrl url)
{
return trash(QList<QUrl>() << url);
return DGuiDesktopServices::trash(url);
}

bool DDesktopServices::trash(const QList<QUrl> urls)
{
QDBusInterface *interface = fileManager1DBusInterface();
return interface && interface->call("Trash", urls2uris(urls)).type() != QDBusMessage::ErrorMessage;
return DGuiDesktopServices::trash(urls);
}

bool DDesktopServices::playSystemSoundEffect(const DDesktopServices::SystemSoundEffect &effect)
{
return playSystemSoundEffect(SOUND_EFFECT_LIST.at(static_cast<int>(effect)));
return DGuiDesktopServices::playSystemSoundEffect(DGuiSystemSoundEffect(effect));
}

bool DDesktopServices::playSystemSoundEffect(const QString &name)
{
if (!systemSoundEffectEnabled(name)) {
return false;
}

return previewSystemSoundEffect(name);
return DGuiDesktopServices::playSystemSoundEffect(name);
}

bool DDesktopServices::previewSystemSoundEffect(const DDesktopServices::SystemSoundEffect &effect)
{
return previewSystemSoundEffect(SOUND_EFFECT_LIST.at(static_cast<int>(effect)));
return DGuiDesktopServices::previewSystemSoundEffect(DGuiSystemSoundEffect(effect));
}

bool DDesktopServices::previewSystemSoundEffect(const QString &name)
{
if (name.isEmpty()) {
return false;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
const auto& infc = QDBusConnection::sessionBus().interface();
QStringList activatableServiceNames = infc->activatableServiceNames();
bool isNewInterface = activatableServiceNames.contains(QLatin1String("org.deepin.dde.SoundEffect1"));
#else
bool isNewInterface = false; // Qt 5.14 以下就直接用旧的接口
#endif
const QLatin1String service(isNewInterface ? "org.deepin.dde.SoundEffect1" :"com.deepin.daemon.SoundEffect");
const QLatin1String path(isNewInterface ? "/org/deepin/dde/SoundEffect1" : "/com/deepin/daemon/SoundEffect");
const QLatin1String interface(isNewInterface ? "org.deepin.dde.SoundEffect1" :"com.deepin.daemon.SoundEffect");

// 使用后端 dbus 接口播放系统音频,音频存放目录: /usr/share/sounds/deepin/stereo/
return QDBusInterface(service, path, interface).call("PlaySound", name).type() != QDBusMessage::ErrorMessage;
return DGuiDesktopServices::previewSystemSoundEffect(name);
}

QString DDesktopServices::getNameByEffectType(const DDesktopServices::SystemSoundEffect &effect)
{
return SOUND_EFFECT_LIST.at(static_cast<int>(effect));
return DGuiDesktopServices::getNameByEffectType(DGuiSystemSoundEffect(effect));
}

QString DDesktopServices::errorMessage()
{
return fileManager1DBusInterface()->lastError().message();
return DGuiDesktopServices::errorMessage();
}

DWIDGET_END_NAMESPACE
8 changes: 6 additions & 2 deletions src/widgets/darrowrectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ QPainterPath DArrowRectanglePrivate::getLeftCornerPath()
border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90);

if (radiusArrowStyleEnable) {
border.lineTo(bottomLeft.x() + arrowWidth, bottomLeft.y());
border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
border.arcTo(bottomLeft.x(), bottomLeft.y() - widgetRadius, widgetRadius, widgetRadius, -90, -90);
border.lineTo(bottomLeft.x(), cornerPoint.y() + m_arrowWidth / 2 + radius / 2);

Expand All @@ -818,9 +818,11 @@ QPainterPath DArrowRectanglePrivate::getLeftCornerPath()

border.lineTo(topLeft.x(), cornerPoint.y() - m_arrowWidth / 2 - radius / 2);
border.arcTo(topLeft.x(), topLeft.y(), widgetRadius, widgetRadius, -180, -90);

border.lineTo(topLeft.x() + radius, topLeft.y());
} else {
if (leftRightRadius) {
border.lineTo(bottomLeft.x() + arrowWidth, bottomLeft.y());
border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
border.arcTo(bottomLeft.x(), bottomLeft.y() - widgetRadius, widgetRadius, widgetRadius, -90, -90);
border.lineTo(bottomLeft.x(), cornerPoint.y() + m_arrowWidth / 2);
} else {
Expand Down Expand Up @@ -900,6 +902,8 @@ QPainterPath DArrowRectanglePrivate::getRightCornerPath()

border.lineTo(bottomRight.x(), cornerPoint.y() + m_arrowWidth / 2 + radius / 2);
border.arcTo(bottomRight.x() - widgetRadius, bottomRight.y() - widgetRadius, widgetRadius, widgetRadius, 0, -90);

border.lineTo(bottomRight.x() - radius, bottomRight.y());
} else {
if (leftRightRadius) {
border.lineTo(topRight.x() - radius, topRight.y());
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dlicensedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DLicenseDialogPrivate::DLicenseDialogPrivate(DLicenseDialog *qq)
: DAbstractDialogPrivate(qq)
, backwardBtn(new DIconButton(QStyle::SP_ArrowBack))
, listView(new DListView)
, listModel(new QStandardItemModel)
, listModel(new QStandardItemModel(listView))
, stackedLayout(new QStackedLayout)
, componentNameLabel(new QLabel)
, componentVersionLabel(new QLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,22 @@ StartupNotificationMonitor::StartupNotificationMonitor() :
return;

int screen = 0;

xcb_screen_t *s = xcb_aux_get_screen (QX11Info::connection(), screen);
const uint32_t select_input_val[] = { XCB_EVENT_MASK_PROPERTY_CHANGE };
xcb_change_window_attributes (QX11Info::connection(), s->root, XCB_CW_EVENT_MASK,
select_input_val);
xcb_get_window_attributes_cookie_t attr_cookie = xcb_get_window_attributes (QX11Info::connection(), s->root);
xcb_get_window_attributes_reply_t *attr_reply = xcb_get_window_attributes_reply (QX11Info::connection(), attr_cookie, NULL);

if (attr_reply) {
uint32_t old_event_mask = attr_reply->your_event_mask;
if (!(old_event_mask & XCB_EVENT_MASK_PROPERTY_CHANGE)) {
const uint32_t select_input_val[] = { XCB_EVENT_MASK_PROPERTY_CHANGE | old_event_mask };

xcb_change_window_attributes (QX11Info::connection(), s->root, XCB_CW_EVENT_MASK,
select_input_val);
}
free(attr_reply);
} else {
qWarning() << "can not get xcb window attributes reply";
}

display = sn_xcb_display_new (QX11Info::connection(), NULL, NULL);

Expand Down

0 comments on commit 89d1d77

Please sign in to comment.