Skip to content

Commit

Permalink
feat: support send to dock and remove from dock
Browse files Browse the repository at this point in the history
添加用于检查应用是否被固定在任务栏的接口,并添加发送到任务栏/从任务栏
移除的相关支持

Log:
  • Loading branch information
BLumia committed Aug 15, 2023
1 parent 7f291e3 commit ebc6276
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 6 deletions.
20 changes: 20 additions & 0 deletions desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ QString DesktopIntegration::backgroundUrl() const
return QString("image://blurhash/%1").arg(m_appearanceIntegration->wallpaperBlurhash());
}

bool DesktopIntegration::isDockedApp(const QString &desktopId) const
{
// This is something we shouldn't do but anyway...
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
// Seems QML's list type doesn't have a contains() method...
return m_dockIntegration->isDocked(fullPath);
}

void DesktopIntegration::sendToDock(const QString &desktopId)
{
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
return m_dockIntegration->sendToDock(fullPath);
}

void DesktopIntegration::removeFromDock(const QString &desktopId)
{
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
return m_dockIntegration->removeFromDock(fullPath);
}

DesktopIntegration::DesktopIntegration(QObject *parent)
: QObject(parent)
, m_dockIntegration(new DdeDock(this))
Expand Down
4 changes: 4 additions & 0 deletions desktopintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class DesktopIntegration : public QObject
QRect dockGeometry() const;
QString backgroundUrl() const;

Q_INVOKABLE bool isDockedApp(const QString & desktopId) const;
Q_INVOKABLE void sendToDock(const QString & desktopId);
Q_INVOKABLE void removeFromDock(const QString & desktopId);

signals:
void dockPositionChanged();
void dockGeometryChanged();
Expand Down
19 changes: 15 additions & 4 deletions qml/AppItemMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Loader {
signal closed()

Component {
id: contextMenu
id: contextMenuComp

Menu {
id: contextMenu
MenuItem {
text: qsTr("Open")
onTriggered: {
Expand All @@ -46,12 +48,21 @@ Loader {
}
MenuSeparator {}
MenuItem { text: true ? qsTr("Send to desktop") : qsTr("Remove from desktop") }
MenuItem { text: true ? qsTr("Send to dock") : qsTr("Remove from dock") }
MenuItem {
text: DesktopIntegration.isDockedApp(appItem.desktopId) ? qsTr("Remove from dock") : qsTr("Send to dock")
onTriggered: {
if (DesktopIntegration.isDockedApp(appItem.desktopId)) {
DesktopIntegration.removeFromDock(appItem.desktopId);
} else {
DesktopIntegration.sendToDock(appItem.desktopId);
}
}
}
MenuSeparator {}
MenuItem { text: true ? qsTr("Add to startup") : qsTr("Remove from startup") }
MenuItem { text: qsTr("Use a proxy") }
MenuItem {
enabled: !AppsModel.appIsCompulsoryForDesktop(appItem.desktopId)
enabled: !DesktopIntegration.appIsCompulsoryForDesktop(appItem.desktopId)
text: qsTr("Uninstall")
}

Expand All @@ -63,7 +74,7 @@ Loader {
}

asynchronous: true
sourceComponent: contextMenu
sourceComponent: contextMenuComp

function popup() {
active = true;
Expand Down
10 changes: 8 additions & 2 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.deepin.launchpad 1.0
ApplicationWindow {
id: root

property bool isMenuShown: false

// title: activeFocusItem + " " + (activeFocusItem ? activeFocusItem.Accessible.name : "")
width: 780
height: 600
Expand Down Expand Up @@ -44,7 +46,7 @@ ApplicationWindow {
}

onActiveChanged: {
if (!active) {
if (!active && !isMenuShown) {
delayHideTimer.running = true
}
}
Expand All @@ -71,8 +73,12 @@ ApplicationWindow {
isFavoriteItem: isFavoriteItem,
hideFavoriteMenu: hideFavoriteMenu
});
// menu.closed.connect(function() { /**/ });
menu.closed.connect(function() {
root.isMenuShown = false
root.requestActivate()
});
menu.popup();
root.isMenuShown = true
}

function updateWindowVisibilityAndPosition() {
Expand Down
23 changes: 23 additions & 0 deletions src/ddeintegration/ddedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ QRect DdeDock::geometry() const
return m_rect;
}

bool DdeDock::isDocked(const QString &desktop) const
{
QDBusPendingReply<bool> reply(m_dbusDaemonDockIface->IsDocked(desktop));
reply.waitForFinished();

if (reply.isError()) {
qDebug() << reply.error();
return false;
}

return reply.value();
}

void DdeDock::sendToDock(const QString &desktop, int idx)
{
m_dbusDaemonDockIface->RequestDock(desktop, idx);
}

void DdeDock::removeFromDock(const QString &desktop)
{
m_dbusDaemonDockIface->RequestUndock(desktop);
}

void DdeDock::updateDockRectAndPositionFromDBus()
{
updateDockPositionFromDBus();
Expand Down
4 changes: 4 additions & 0 deletions src/ddeintegration/ddedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class DdeDock : public QObject
Qt::ArrowType direction() const;
QRect geometry() const;

bool isDocked(const QString & desktop) const;
void sendToDock(const QString & desktop, int idx = -1);
void removeFromDock(const QString & desktop);

signals:
void directionChanged();
void geometryChanged();
Expand Down
10 changes: 10 additions & 0 deletions src/gioutils/appinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ bool AppInfo::launchByDesktopId(const QString &desktopId)

return true;
}

QString AppInfo::fullPathByDesktopId(const QString &desktopId)
{
GDesktopAppInfo * appInfo = g_desktop_app_info_new(desktopId.toStdString().c_str());
if (!appInfo) return QString();

const char * filePath = g_desktop_app_info_get_filename(appInfo);

return QString::fromUtf8(filePath);
}
1 change: 1 addition & 0 deletions src/gioutils/appinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class AppInfo
{
public:
static bool launchByDesktopId(const QString & desktopId);
static QString fullPathByDesktopId(const QString & desktopId);
};

0 comments on commit ebc6276

Please sign in to comment.