diff --git a/CMakeLists.txt b/CMakeLists.txt index bb4778b..e9fec97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(SRCS src/listmodelmanager.cpp src/iconitem.cpp src/processprovider.cpp + src/appmanager.cpp ) set(RESOURCES diff --git a/qml/GridItemDelegate.qml b/qml/GridItemDelegate.qml index 01ccb03..fa1ebb2 100755 --- a/qml/GridItemDelegate.qml +++ b/qml/GridItemDelegate.qml @@ -21,6 +21,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtGraphicalEffects 1.0 import QtQuick.Window 2.12 +import QtQuick.Layouts 1.12 import FishUI 1.0 as FishUI import Cutefish.Launcher 1.0 @@ -134,6 +135,16 @@ Item { onTriggered: launcherModel.removeFromDock(model.appId) } + MenuItem { + id: uninstallItem + text: qsTr("Uninstall") + onTriggered: { + root.uninstallDialog.desktopPath = model.appId + root.uninstallDialog.appName = model.name + root.uninstallDialog.visible = true + } + } + // MenuItem { // text: qsTr("Uninstall") // onTriggered: {} @@ -155,6 +166,7 @@ Item { if (mouse.button == Qt.LeftButton) launcherModel.launch(model.appId) else if (mouse.button == Qt.RightButton) { + uninstallItem.visible = appManager.isCutefishOS() _itemMenu.updateActions() _itemMenu.popup() } diff --git a/qml/main.qml b/qml/main.qml index d207e27..076fc19 100755 --- a/qml/main.qml +++ b/qml/main.qml @@ -39,6 +39,69 @@ Item { property bool showed: launcher.showed property int iconSize: root.height < 960 ? 96 : 128 + property alias uninstallDialog: _uninstallDialog + + AppManager { + id: appManager + } + + Dialog { + id: _uninstallDialog + + property var desktopPath: "" + property var appName: "" + + width: _uninstallDialogLayout.implicitWidth + FishUI.Units.largeSpacing * 2 + height: _uninstallDialogLayout.implicitHeight + FishUI.Units.largeSpacing * 2 + + modal: true + + x: (root.width - width) / 2 + y: (root.height - height) / 2 + + ColumnLayout { + id: _uninstallDialogLayout + anchors.centerIn: parent + anchors.margins: FishUI.Units.largeSpacing + spacing: FishUI.Units.largeSpacing * 1.5 + + Label { + text: qsTr("Are you sure you want to uninstall %1 ?").arg(_uninstallDialog.appName) + wrapMode: Text.WordWrap + } + + RowLayout { + spacing: FishUI.Units.largeSpacing + + Button { + text: qsTr("Cancel") + onClicked: _uninstallDialog.close() + Layout.fillWidth: true + } + + Button { + flat: true + text: qsTr("Uninstall") + Layout.fillWidth: true + onClicked: { + _uninstallDialog.close() + appManager.uninstall(_uninstallDialog.desktopPath) + } + } + } + } + } + + Connections { + target: launcher + + function onVisibleChanged(visible) { + if (!visible) { + _uninstallDialog.close() + } + } + } + // onShowedChanged: { // appViewOpacityAni.restart() // blurAnimation.restart() diff --git a/src/appmanager.cpp b/src/appmanager.cpp new file mode 100644 index 0000000..b3d72b3 --- /dev/null +++ b/src/appmanager.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 CutefishOS. + * + * Author: Kate Leet + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "appmanager.h" +#include + +AppManager::AppManager(QObject *parent) + : QObject(parent) + , m_iface("com.cutefish.Daemon", + "/AppManager", + "com.cutefish.AppManager", QDBusConnection::sessionBus()) +{ + +} + +void AppManager::uninstall(const QString &desktopFile) +{ + if (m_iface.isValid()) { + m_iface.asyncCall("uninstall", desktopFile); + } +} + +bool AppManager::isCutefishOS() +{ + return QFile::exists("/etc/cutefishos"); +} diff --git a/src/appmanager.h b/src/appmanager.h new file mode 100644 index 0000000..4bb9c04 --- /dev/null +++ b/src/appmanager.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 CutefishOS. + * + * Author: Kate Leet + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef APPMANAGER_H +#define APPMANAGER_H + +#include +#include +#include + +class AppManager : public QObject +{ + Q_OBJECT + +public: + explicit AppManager(QObject *parent = nullptr); + + Q_INVOKABLE void uninstall(const QString &desktopFile); + + Q_INVOKABLE bool isCutefishOS(); + +private: + QDBusInterface m_iface; +}; + +#endif // APPMANAGER_H diff --git a/src/main.cpp b/src/main.cpp index d093a8e..5a84886 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,7 @@ #include "launchermodel.h" #include "pagemodel.h" #include "iconitem.h" +#include "appmanager.h" #include #include @@ -45,6 +46,7 @@ int main(int argc, char *argv[]) qmlRegisterType(uri, 1, 0, "LauncherModel"); qmlRegisterType(uri, 1, 0, "PageModel"); qmlRegisterType(uri, 1, 0, "IconItem"); + qmlRegisterType(uri, 1, 0, "AppManager"); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) qmlRegisterType(); diff --git a/translations/en_US.ts b/translations/en_US.ts index 1116ef6..9f8da21 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -4,25 +4,30 @@ GridItemDelegate - + Open Open - + Send to dock Send to dock - + Send to desktop - + Remove from dock Remove from dock + + + Uninstall + + Launcher @@ -35,12 +40,27 @@ main - + + Are you sure you want to uninstall %1 ? + + + + + Cancel + + + + + Uninstall + + + + Search Search - + Not found Not found diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index e27c8fa..3186a20 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -4,25 +4,30 @@ GridItemDelegate - + Open 打开 - + Send to dock 发送到程序坞 - + Send to desktop 发送到桌面 - + Remove from dock 在程序坞中移除 + + + Uninstall + 卸载 + Launcher @@ -35,12 +40,27 @@ main - + + Are you sure you want to uninstall %1 ? + 您确定是否要卸载 %1 ? + + + + Cancel + 取消 + + + + Uninstall + 卸载 + + + Search 搜索 - + Not found 未找到