peony-extensions/0000755000175000017500000000000014205133370013023 5ustar fengfengpeony-extensions/peony-bluetooth-plugin/0000755000175000017500000000000014205133370017454 5ustar fengfengpeony-extensions/peony-bluetooth-plugin/bluetoothplugin.cpp0000644000175000017500000000640214205133370023406 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: tang guang * */ #include "bluetoothplugin.h" #include #include using namespace Peony; BluetoothPlugin::BluetoothPlugin(QObject *parent) { QTranslator *t = new QTranslator(this); qDebug()<<"system().name:"<load(":/translations/peony-bluetooth-plugin_"+QLocale::system().name()); QApplication::installTranslator(t); } QList BluetoothPlugin::menuActions(Peony::MenuPluginInterface::Types types, const QString &uri, const QStringList &selectionUris) { qDebug() << Q_FUNC_INFO << uri << selectionUris; QList actions; QStringList target; for (auto str : selectionUris) { qDebug() << Q_FUNC_INFO << str << " = " << Peony::FileUtils::urlEncode(str); target << Peony::FileUtils::urlEncode(str); } QProcess process; process.start("rfkill list"); process.waitForFinished(); QByteArray output = process.readAllStandardOutput(); QString str_output = output; if(!str_output.contains(QString("bluetooth"), Qt::CaseInsensitive)) return actions; if(!QFileInfo::exists("/usr/bin/ukui-bluetooth")){ return actions; } if (types == MenuPluginInterface::DirectoryView || types == MenuPluginInterface::DesktopWindow) { if (! selectionUris.isEmpty()) { auto info = FileInfo::fromUri(selectionUris.first()); //special type mountable, return qDebug()<<"info isVirtual:"<isVirtual()<mimeType(); if (!selectionUris.first().startsWith("file:///")) return actions; else{ if(info->mimeType().split("/").at(1) != "directory"){ QAction *compress = new QAction(QIcon::fromTheme("blueman-tray"), tr("Send from bluetooth to..."), nullptr); actions << compress; connect(compress, &QAction::triggered, [=](){ QString path = selectionUris.at(0); QDBusMessage m = QDBusMessage::createMethodCall("org.ukui.bluetooth","/org/ukui/bluetooth","org.ukui.bluetooth","file_transfer"); m << target; qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; // 发送Message QDBusConnection::sessionBus().call(m); }); } } } } return actions; } peony-extensions/peony-bluetooth-plugin/peony-bluetooth-plugin.qrc0000644000175000017500000000017314205101224024606 0ustar fengfeng translations/peony-bluetooth-plugin_zh_CN.qm peony-extensions/peony-bluetooth-plugin/peony-bluetooth-plugin_global.h0000644000175000017500000000217614205101224025575 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: tang guang * */ #ifndef PEONYBLUETOOTHPLUGIN_GLOBAL_H #define PEONYBLUETOOTHPLUGIN_GLOBAL_H #include #if defined(PEONYENGRAMPAMENUPLUGIN_LIBRARY) # define PEONYQTENGRAMPAMENUPLUGINSHARED_EXPORT Q_DECL_EXPORT #else # define PEONYQTENGRAMPAMENUPLUGINSHARED_EXPORT Q_DECL_IMPORT #endif #endif // PEONYBLUETOOTHPLUGIN_GLOBAL_H peony-extensions/peony-bluetooth-plugin/bluetoothplugin.h0000644000175000017500000000422714205101224023047 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: tang guang * */ #ifndef BLUETOOTHPLUGIN_H #define BLUETOOTHPLUGIN_H #include #include #include "peony-bluetooth-plugin_global.h" #include #include #include #include #include #include #include #include #include #include namespace Peony { class PEONYQTENGRAMPAMENUPLUGINSHARED_EXPORT BluetoothPlugin: public QObject, public MenuPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID MenuPluginInterface_iid FILE "common.json") Q_INTERFACES(Peony::MenuPluginInterface) public: explicit BluetoothPlugin(QObject *parent = nullptr); PluginInterface::PluginType pluginType() override {return PluginInterface::MenuPlugin;} const QString name() override {return tr("Peony-Qt bluetooth Extension");} const QString description() override {return tr("bluetooth Menu Extension.");} const QIcon icon() override {return QIcon::fromTheme("blueman-tray");} void setEnable(bool enable) override {m_enable = enable;} bool isEnable() override {return m_enable;} QString testPlugin() override {return "test compress";} QList menuActions(Types types, const QString &uri, const QStringList &selectionUris) override; private: bool m_enable; }; } #endif // BLUETOOTHPLUGIN_H peony-extensions/peony-bluetooth-plugin/peony-bluetooth-plugin.pro0000644000175000017500000000253014205101224024620 0ustar fengfeng###################################################################### # Automatically generated by qmake (3.1) Wed Dec 2 15:23:52 2020 ###################################################################### QT += widgets dbus TEMPLATE = lib TARGET = peony-bluetooth-plugin #INCLUDEPATH += . DEFINES += PEONYENGRAMPAMENUPLUGIN_LIBRARY include(../common.pri) # The following define makes your compiler warn you if you use any # feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 CONFIG += debug link_pkgconfig plugin PKGCONFIG += peony TRANSLATIONS = translations/peony-bluetooth-plugin_zh_CN.ts #DESTDIR += ../testdir HEADERS += \ bluetoothplugin.h \ peony-bluetooth-plugin_global.h SOURCES += \ bluetoothplugin.cpp target.path = $$[QT_INSTALL_LIBS]/peony-extensions INSTALLS += target RESOURCES += \ peony-bluetooth-plugin.qrc peony-extensions/peony-bluetooth-plugin/translations/0000755000175000017500000000000014205133370022175 5ustar fengfengpeony-extensions/peony-bluetooth-plugin/translations/peony-bluetooth-plugin_zh_CN.qm0000644000175000017500000000045514205101224030243 0ustar fengfeng Peony::BluetoothPlugin Send from bluetooth to... 从蓝牙发送文件到... Peony-Qt bluetooth Extension 蓝牙插件 bluetooth Menu Extension. 蓝牙菜单扩展. peony-extensions/test-computer-view/0000755000175000017500000000000014205101224016577 5ustar fengfengpeony-extensions/test-computer-view/mainwindow.h0000644000175000017500000000050314205101224021122 0ustar fengfeng#ifndef MAINWINDOW_H #define MAINWINDOW_H #include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H peony-extensions/test-computer-view/mainwindow.cpp0000644000175000017500000000044014205101224021455 0ustar fengfeng#include "mainwindow.h" #include "ui_mainwindow.h" #include "computer-view.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); setCentralWidget(new ComputerView); } MainWindow::~MainWindow() { delete ui; } peony-extensions/test-computer-view/test-computer-view.pro0000644000175000017500000000201614205101224023103 0ustar fengfengQT += core gui dbus network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += debug c++11 no_keywords link_pkgconfig plugin PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 peony udisks2 libnotify # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS include(../common.pri) include(../peony-extension-computer-view/computer-view/computer-view.pri) # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui peony-extensions/test-computer-view/mainwindow.ui0000644000175000017500000000103014205101224021304 0ustar fengfeng MainWindow 0 0 800 600 MainWindow peony-extensions/test-computer-view/main.cpp0000644000175000017500000000025414205101224020230 0ustar fengfeng#include "mainwindow.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } peony-extensions/peony-send-to-device/0000755000175000017500000000000014205133370016761 5ustar fengfengpeony-extensions/peony-send-to-device/resources.qrc0000644000175000017500000000036314205101224021475 0ustar fengfeng translations/peony-send-to-device_cs.qm translations/peony-send-to-device_tr.qm translations/peony-send-to-device_zh_CN.qm peony-extensions/peony-send-to-device/send-to-device-plugin.cpp0000644000175000017500000002010514205133370023565 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Ding Jing * */ #include "send-to-device-plugin.h" #include "file-info.h" #include #include #include #include #include #include #include #include #include #include #include static QString getIconName (GIcon* icons); static void mounted_func (gpointer data, gpointer udata); static void handle_mount_added (GVolumeMonitor* monitor, GMount* mount, gpointer data); static void handle_mount_removed(GVolumeMonitor* monitor, GMount* mount, gpointer data); using namespace Peony; SendToPlugin::SendToPlugin(QObject *parent) : QObject(parent), mEnable(true) { // translator QTranslator *t = new QTranslator(this); t->load(":/translations/peony-send-to-device_"+QLocale::system().name()); QFile file(":/translations/peony-send-to-device_"+QLocale::system().name()+".ts"); QApplication::installTranslator(t); } QList SendToPlugin::menuActions(Types types, const QString &uri, const QStringList &selectionUris) { QList l; if (selectionUris.count() <= 0) { return l; } auto info = FileInfo::fromUri(selectionUris.first()); if (selectionUris.first().startsWith("computer:///") || selectionUris.first().startsWith("trash:///") || selectionUris.first().startsWith("filesafe:///") || info->isVirtual()) { return l; } QAction* action = new DriverAction(selectionUris); if (action) { l << action; } Q_UNUSED(uri) Q_UNUSED(types) return l; } DriverItem::DriverItem(QString uri, QIcon icon, QString name, QObject* parent) : QAction(parent), mName(name), mIcon(icon), mUri(uri) { setIcon(mIcon); setText(name); } const QIcon DriverItem::icon() { return mIcon; } const QString DriverItem::name() { return mName; } const QString DriverItem::uri() { return mUri; } static void handle_mount_added(GVolumeMonitor* monitor, GMount* mount, gpointer data) { DriverAction* drivers = (DriverAction*)data; mounted_func (mount, drivers); Q_UNUSED(monitor) } static void handle_mount_removed(GVolumeMonitor* monitor, GMount* mount, gpointer data) { char* path = nullptr; GFile* location = nullptr; if (!mount || !data) return; location = g_mount_get_default_location(mount); if (location) { path = g_file_get_uri(location); } if (nullptr != path) { ((DriverAction*)data)->driverRemove(path); } qDebug() << "remove uri:" << path; if (!path) g_free(path); if (!location) g_object_unref(location); Q_UNUSED(monitor) } static void mounted_func (gpointer data, gpointer udata) { GMount* mount = (GMount*)data; GFile* location = nullptr; char* uri = nullptr; char* name = nullptr; GIcon* icons = nullptr; QString icon = nullptr; if (!data || !udata) return; if (mount) { name = g_mount_get_name(mount); icons = g_mount_get_icon(mount); location = g_mount_get_default_location(mount); if (location) { uri = g_file_get_uri(location); } } icon = getIconName (icons); if (uri && name) { ((DriverAction*)udata)->driverAdded(uri, name, icon); } qDebug() << "name:" << name << " uri:" << uri << " icons:" << icons << " icon:" << icon; if (!uri) g_free(uri); if (!name) g_free(name); if (!location) g_object_unref(location); } static QString getIconName (GIcon* icons) { if (nullptr == icons) { return ""; } QString icon = nullptr; if (G_IS_ICON(icons)) { const gchar* const* iconNames = g_themed_icon_get_names(G_THEMED_ICON (icons)); if (iconNames) { auto p = iconNames; while (*p) { QIcon icont = QIcon::fromTheme(*p); if (!icont.isNull()) { icon = QString (*p); break; } else { p++; } } } g_object_unref(icons); } return icon; } DriverAction::DriverAction(const QStringList& uris, QObject *parent) : QAction(parent) { mMenu = new QMenu(); mVolumeMonitor = g_volume_monitor_get(); mDeviceAdd = g_signal_connect(G_OBJECT(mVolumeMonitor), "mount-added", G_CALLBACK(handle_mount_added), (gpointer)this); mDeviceRemove = g_signal_connect(G_OBJECT(mVolumeMonitor), "mount-removed", G_CALLBACK(handle_mount_removed), (gpointer)this); connect(this, &DriverAction::driverAdded, this, [=] (QString uri, QString name, QString icon) { if (!mDrivers.contains(uri)) { QString curUri = uri; if (curUri.endsWith("/")) { curUri.chop(1); } QString usrName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation).section("/", -1, -1); if ("file:///data" == curUri || "file:///backup" == curUri || "file:///boot" == curUri || "file:///tmp" == curUri || "file:///var" == curUri || "file:///media/" + usrName + "/SYSBOOT" == curUri || "file:///media/" + usrName + "/sysboot" == curUri || "file:///media/" + usrName + "/data" == curUri || "file:///media/" + usrName + "/DATA" == curUri || curUri.startsWith("burn://") || curUri.startsWith("ftp://") || curUri.startsWith("smb://") || curUri.startsWith("file:///media/" + usrName + "/KYLIN-") || curUri.startsWith("file:///media/" + usrName + "/kylin-") ) { return ; } auto it = new DriverItem (uri, QIcon::fromTheme(icon), name); it->connect(it, &QAction::triggered, it, [=] () { FileCopyOperation* op = new FileCopyOperation(uris, it->uri(), it); op->setAutoDelete(true); FileOperationManager::getInstance()->startOperation(op); }); mMenu->addAction(it); mDrivers[uri] = it; } showAction(); }); connect(this, &DriverAction::driverRemove, this, [=] (QString uri) { if (mDrivers.contains(uri)) { auto it = mDrivers[uri]; mMenu->removeAction(it); it->deleteLater(); mDrivers.remove(uri); } showAction(); }); GList* mounts = g_volume_monitor_get_mounts (mVolumeMonitor); if (mounts) { g_list_foreach (mounts, mounted_func, this); g_list_free_full(mounts, g_object_unref); } setMenu(mMenu); setText(tr("Send to a removable device")); } DriverAction::~DriverAction() { if (mMenu) delete mMenu; if (mVolumeMonitor) { g_signal_handler_disconnect(G_OBJECT(mVolumeMonitor), mDeviceAdd); g_signal_handler_disconnect(G_OBJECT(mVolumeMonitor), mDeviceRemove); g_object_unref(mVolumeMonitor); } for (auto it = mDrivers.begin(); it != mDrivers.end(); ++it) { it.value()->deleteLater(); } } void DriverAction::showAction() { setVisible(mDrivers.size() > 0 ? true : false); } peony-extensions/peony-send-to-device/send-to-device-plugin.h0000644000175000017500000000570314205101224023232 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Ding Jing * */ #ifndef ADMINMENUPLUGIN_H #define ADMINMENUPLUGIN_H #include #include #include #undef signals namespace Peony { class DriverItem; class RemoveableDriver; class SendToPlugin : public QObject, public MenuPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID MenuPluginInterface_iid FILE "common.json") Q_INTERFACES(Peony::MenuPluginInterface) public: explicit SendToPlugin(QObject *parent = nullptr); QString testPlugin() override {return "";} bool isEnable() override {return mEnable;} void setEnable(bool enable) override {mEnable = enable;} const QString description() override {return tr("Send to a removable device");} const QString name() override {return "Peony Qt Send to a removable device";} const QIcon icon() override {return QIcon::fromTheme("system-users-symbolic");} PluginInterface::PluginType pluginType() override {return PluginInterface::MenuPlugin;} QList menuActions(Types types, const QString &uri, const QStringList &selectionUris) override; private: bool mEnable; }; class DriverAction : public QAction { Q_OBJECT public: explicit DriverAction (const QStringList& uris, QObject* parent = nullptr); ~DriverAction (); Q_SIGNALS: void driverRemove (QString uri); void driverAdded (QString uri, QString name, QString icon); private: void showAction (); private: gulong mDeviceAdd; gulong mDeviceRemove; QMenu* mMenu; GVolumeMonitor* mVolumeMonitor; QMap mDrivers; }; class DriverItem : public QAction { friend class RemoveableDriverModel; Q_OBJECT public: explicit DriverItem (QString uri, QIcon icon, QString name, QObject* parent = nullptr); const QIcon icon (); const QString uri (); const QString name (); private: bool mConnect; QString mName; QIcon mIcon; QString mUri; }; } #endif peony-extensions/peony-send-to-device/peony-send-to-device.pro0000644000175000017500000000106214205101224023431 0ustar fengfengQT += core gui widgets concurrent include(../common.pri) TARGET = peony-send-to-device TEMPLATE = lib DEFINES += PEONYADMIN_LIBRARY PKGCONFIG += peony CONFIG += link_pkgconfig no_keywords c++11 plugin debug SOURCES += \ send-to-device-plugin.cpp HEADERS += \ send-to-device-plugin.h TRANSLATIONS += \ translations/peony-send-to-device_cs.ts \ translations/peony-send-to-device_tr.ts \ translations/peony-send-to-device_zh_CN.ts RESOURCES += \ resources.qrc target.path = $$[QT_INSTALL_LIBS]/peony-extensions INSTALLS += target peony-extensions/peony-send-to-device/translations/0000755000175000017500000000000014205133370021502 5ustar fengfengpeony-extensions/peony-send-to-device/translations/peony-send-to-device_tr.ts0000644000175000017500000000115114205133370026513 0ustar fengfeng Peony::DriverAction Send to a removable device Peony::SendToPlugin Send to a removable device peony-extensions/peony-send-to-device/translations/peony-send-to-device_cs.ts0000644000175000017500000000115114205133370026473 0ustar fengfeng Peony::DriverAction Send to a removable device Peony::SendToPlugin Send to a removable device peony-extensions/peony-send-to-device/translations/peony-send-to-device_tr.qm0000644000175000017500000000044114205101224026474 0ustar fengfeng Peony::DriverAction Send to a removable device 发送到移动设备 Peony::SendToPlugin Send to a removable device 发送到移动设备 peony-extensions/peony-send-to-device/translations/peony-send-to-device_zh_CN.qm0000644000175000017500000000033314205101224027050 0ustar fengfeng. * * Authors: Yue Lan * */ #ifndef MATETERMINALMENUPLUGIN_H #define MATETERMINALMENUPLUGIN_H #include "peony-menu-plugin-mate-terminal_global.h" #include #include #include namespace Peony { class PEONYQTMENUPLUGINMATETERMINALSHARED_EXPORT MateTerminalMenuPlugin : public QObject, public MenuPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID MenuPluginInterface_iid FILE "common.json") Q_INTERFACES(Peony::MenuPluginInterface) public: explicit MateTerminalMenuPlugin(QObject *parent = nullptr); PluginInterface::PluginType pluginType() override {return PluginInterface::MenuPlugin;} const QString name() override {return tr("Peony-Qt Mate Terminal Menu Extension");} const QString description() override {return tr("Open Terminal with menu.");} const QIcon icon() override {return QIcon::fromTheme("utilities-terminal-symbolic");} void setEnable(bool enable) override {m_enable = enable;} bool isEnable() override {return m_enable;} void openTerminal(); void tryOpenAgain(); QString testPlugin() override {return "test";} QList menuActions(Types types, const QString &uri, const QStringList &selectionUris) override; private: bool m_enable; }; } #endif // MATETERMINALMENUPLUGIN_H peony-extensions/peony-menu-plugin-mate-terminal/peony-menu-plugin-mate-terminal_global.h0000644000175000017500000000223714205101224030763 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef PEONYQTMENUPLUGINMATETERMINAL_GLOBAL_H #define PEONYQTMENUPLUGINMATETERMINAL_GLOBAL_H #include #if defined(PEONYMENUPLUGINMATETERMINAL_LIBRARY) # define PEONYQTMENUPLUGINMATETERMINALSHARED_EXPORT Q_DECL_EXPORT #else # define PEONYQTMENUPLUGINMATETERMINALSHARED_EXPORT Q_DECL_IMPORT #endif #endif // PEONYQTMENUPLUGINMATETERMINAL_GLOBAL_H peony-extensions/peony-menu-plugin-mate-terminal/mate-terminal-menu-plugin.cpp0000644000175000017500000001361214205133370026654 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "mate-terminal-menu-plugin.h" #include #include #include #include #include #include #include #include #include #include #include using namespace Peony; static QString terminal_cmd = nullptr; static QString m_uri = nullptr; MateTerminalMenuPlugin::MateTerminalMenuPlugin(QObject *parent) : QObject (parent) { QTranslator *t = new QTranslator(this); qDebug()<<"\n\n\n\n\n\n\ntranslate:"<load(":/translations/peony-mate-terminal-extension_"+QLocale::system().name()); QApplication::installTranslator(t); QtConcurrent::run([=]{ GList *infos = g_app_info_get_all(); GList *l = infos; while (l) { const char *cmd = g_app_info_get_executable(static_cast(l->data)); QString tmp = cmd; if (tmp.contains("terminal") || tmp.contains("terminator")) { qDebug() << "terminal cmd:" <next; continue; } else terminal_cmd = tmp; } l = l->next; } g_list_free_full(infos, g_object_unref); }); } void MateTerminalMenuPlugin::openTerminal(){ //qDebug()<<"triggered"<message; g_error_free(err); err = nullptr; //try again to open terminal //maybe this method is better,but still need more test to confirm tryOpenAgain(); } g_strfreev (argv); } void MateTerminalMenuPlugin::tryOpenAgain() { QUrl url = m_uri; auto absPath = url.path(); qDebug() << "tryOpenAgain terminal url:" < MateTerminalMenuPlugin::menuActions(Types types, const QString &uri, const QStringList &selectionUris) { QList actions; qDebug() << "terminal_cmd:" <isVirtual()) return actions; QAction *dirAction = new QAction(QIcon::fromTheme("utilities-terminal-symbolic"), tr("Open Directory in Terminal"), nullptr); dirAction->connect(dirAction, &QAction::triggered, [=](){ openTerminal(); }); actions<isVirtual()) return actions; if (info->isDir()) { m_uri = selectionUris.first(); QAction *dirAction = new QAction(QIcon::fromTheme("utilities-terminal-symbolic"), tr("Open Directory in Terminal"), nullptr); dirAction->connect(dirAction, &QAction::triggered, [=](){ openTerminal(); }); actions< Peony::MateTerminalMenuPlugin Open Directory in Terminal Otevřít složku v Terminálu Peony-Qt Mate Terminal Menu Extension Rozšíření do Peony-Qt pro nabídku Mate Terminal Open Terminal with menu. Otevřít Terminál z nabídky. peony-extensions/peony-menu-plugin-mate-terminal/translations/peony-mate-terminal-extension_zh_CN.ts0000644000175000017500000000425214205133370033226 0ustar fengfeng Peony::MateTerminalMenuPlugin Open Directory in Terminal 打开终端 Peony-Qt Mate Terminal Menu Extension UKUI文件管理器终端扩展 Open Terminal with menu. 使用右键菜单打开终端。 Open Directory in T&erminal 打开终端(&E) QObject Open terminal fail 打开终端失败 Open terminal failed, did you removed the default terminal? If it's true please reinstall it. 打开终端失败,您是否卸载过默认终端?如果是的请重新安装。 Open terminal failed, did you removed the default terminal? If you have reinstalled it please logout and relogin. 打开终端失败,您是否卸载过默认终端?如果已经重新安装了,请注销并重新登录后生效。 Open terminal failed, did you removed the default terminal? 打开终端失败,您是否卸载了默认的终端应用? peony-extensions/peony-menu-plugin-mate-terminal/translations/peony-mate-terminal-extension_cs.qm0000644000175000017500000000076214205101224032614 0ustar fengfeng Peony::MateTerminalMenuPlugin Open Directory in Terminal Dizini Terminalde Aç Peony-Qt Mate Terminal Menu Extension Peony-Qt Mate Terminal Menü Eklentisi Open Terminal with menu. Terminali menü ile aç QObject Open terminal fail Open terminal failed, did you removed the default terminal? If it's true please reinstall it. peony-extensions/peony-menu-plugin-mate-terminal/peony-menu-plugin-mate-terminal.qrc0000644000175000017500000000041614205101224027776 0ustar fengfeng translations/peony-mate-terminal-extension_zh_CN.qm translations/peony-mate-terminal-extension_tr.qm translations/peony-mate-terminal-extension_cs.qm peony-extensions/NEWS0000644000175000017500000000040114205101224013506 0ustar fengfeng### peony-extensions 2.0.0 * Rewrite the plugins according to the peony-2.0.0. ### peony-extensions 1.1.0 * Initial release. * Add archive extension. ### peony-extensions 1.1.4 * Drop peony-admin since python-gi and python-caja depends python2. peony-extensions/COPYING0000644000175000017500000001674314205101224014062 0ustar fengfeng GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. peony-extensions/common.json0000644000175000017500000000003314205133370015202 0ustar fengfeng{ "version": "3.2.2" } peony-extensions/peony-admin/0000755000175000017500000000000014205101224015234 5ustar fengfengpeony-extensions/peony-admin/resources.qrc0000644000175000017500000000033014205101224017751 0ustar fengfeng translations/peony-admin_zh_CN.qm translations/peony-admin_tr.qm translations/peony-admin_cs.qm peony-extensions/peony-admin/admin-menu-plugin.cpp0000644000175000017500000001034214205101224021266 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * Authors: Meihong * */ #include "admin-menu-plugin.h" #include "file-info.h" #include #include #include #include #include #include #include #include using namespace Peony; AdminMenuPlugin::AdminMenuPlugin(QObject *parent) : QObject(parent) { QTranslator *t = new QTranslator(this); bool b_load = t->load(":/translations/peony-admin_"+QLocale::system().name()); qDebug()<<"\n\n\n\n\n\n\n AdminMenuPlugin translate:"< AdminMenuPlugin::menuActions(Types types, const QString &uri, const QStringList &selectionUris) { #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) QList l; if (uri.startsWith("mtp://")) { return l; } if (selectionUris.isEmpty()) { auto directoryAction = new QAction(tr("Open Directory as Admin")); l<connect(directoryAction, &QAction::triggered, [=](){ QtConcurrent::run([=](){ QProcess p; QUrl url = uri; p.setProgram("pkexec"); QStringList args; args<<"peony"<isVirtual()<mimeType(); if (selectionUris.first().startsWith("computer:///") || selectionUris.first().startsWith("trash:///")|| info->isVirtual()) return l; if (info->isDir()) { auto directoryAction = new QAction(tr("Open Directory as Admin")); l<connect(directoryAction, &QAction::triggered, [=](){ QtConcurrent::run([=](){ QStringList args; QUrl url = selectionUris.first(); args<<"peony"<mimeType().startsWith("text")) { auto directoryAction = new QAction(tr("Open Text as Admin")); l<connect(directoryAction, &QAction::triggered, [=](){ QtConcurrent::run([=](){ QProcess p; QUrl url = selectionUris.first(); p.setProgram("pkexec"); p.setArguments(QStringList()<<"pluma"<. * * Authors: Yue Lan * */ #ifndef ADMINMENUPLUGIN_H #define ADMINMENUPLUGIN_H #include #include namespace Peony { class AdminMenuPlugin : public QObject, public MenuPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID MenuPluginInterface_iid FILE "common.json") Q_INTERFACES(Peony::MenuPluginInterface) public: explicit AdminMenuPlugin(QObject *parent = nullptr); PluginInterface::PluginType pluginType() override {return PluginInterface::MenuPlugin;} const QString name() override {return "Peony Qt Admin Extension";} const QString description() override {return "Allow user launch file/directory as admin";} const QIcon icon() override {return QIcon::fromTheme("system-users-symbolic");} void setEnable(bool enable) override {m_enable = enable;} bool isEnable() override {return m_enable;} QString testPlugin() override {return "";} QList menuActions(Types types, const QString &uri, const QStringList &selectionUris) override; private: bool m_enable; }; } #endif // ADMINMENUPLUGIN_H peony-extensions/peony-admin/translations/0000755000175000017500000000000014205101224017755 5ustar fengfengpeony-extensions/peony-admin/translations/peony-admin_tr.ts0000644000175000017500000000120314205101224023246 0ustar fengfeng Peony::AdminMenuPlugin Open Directory as Admin Klasörü Yönetici Olarak Aç Open Text as Admin Metin Dosyasını Yönetici Olarak Aç peony-extensions/peony-admin/translations/peony-admin_zh_CN.qm0000644000175000017500000000033014205101224023611 0ustar fengfeng Peony::AdminMenuPlugin Open Directory as Admin 以管理员身份打开目录 Open Text as Admin 以管理员身份打开文件 peony-extensions/peony-admin/translations/peony-admin_cs.qm0000644000175000017500000000043414205101224023222 0ustar fengfeng Peony::AdminMenuPlugin Open Directory as Admin Otevřít složku jako správce Open Text as Admin Otevřít text jako správce peony-extensions/peony-admin/org.freedesktop.peony-admin.policy.in0000644000175000017500000001747114205101224024414 0ustar fengfeng Peony Admin https://github.com/ukui/peony-extensions Run Peony as Root شغّل نوتلس كجذر Esegui Peony come Root Executar o Peony como Root Lancez Peony en tant qu'administrateur Запустить Peony как Администратор Paleisti failų naršyklę kaip Administratorius Ejecutar Peony como administrador Uruchom Peony jako Root Spustenie programu Peony ako správca Peony als Aministrator ausführen Authentication is required to run the File Manager as Administrator المصادقة مطلوبة لتشغيل مدير الملفات كمدير Autenticazione richiesta per lanciare il File Manager come Amministratore Autenticação é necessária para executar o Gestor de Ficheiros como Administrador L'authentification est requise pour lancer le gestionnaire de fichiers en tant qu'administrateur Для запуска Файлового Менеджера от имени Администратора требуется аутентификация Failų naršyklei paleisti Administratoriaus teisėmis reikia įvesti slaptažodį Se necesita autentificación para ejecutar el Gestor de Ficheros como Administrador Uwierzytelnienie jest wymagane aby uruchomić Menedżer Plików jako Administrator Na spustenie správcu súborov ako administrátor sa vyžaduje overenie totožnosti Authentifizierung ist erforderlich um den Datei-Manager als Administrator auszuführen 以超级用户身份运行 Peony system-file-manager auth_admin auth_admin auth_admin_keep $${PEONY_PATH} true Open Pluma as Root افتح محرر النصوص Pluma كجذر Abrir Pluma como Root Aprire Pluma come Root Ouvrir Pluma en tant qu'administrateur Открыть Pluma как Администратор Atverti teksto failą kaip Administratorius Abrir Pluma como Administrador Otwórz Pluma jako Root Otvorenie programu Pluma ako správca Öffne Pluma als Administrator Authentication is required to run the Text Editor as Administrator المصادقة مطلوبة لتشغيل محرر النصوص كمدير Autenticação é necessária para executar o Editor de Texto como Administrador L'authentification est requise pour lancer l'éditeur de texte en tant qu'administrateur Для запуска Текстового Редактора от имени Администратора требуется аутентификация Tekstų redagavimo programai paleisti Administratoriaus teisėmis reikia įvesti slaptažodį Autenticazione richiesta per eseguire l'Editor di Testo come Amministratore Se necesita autentificación para abrir el Editor de Texto como Administrador Uwierzytelnienie jest wymagane aby uruchomić Edytor tekstowy jako Administrator Na spustenie textového editora ako administrátor sa vyžaduje overenie totožnosti Authentifizierung ist erforderlich um den Text-Editor als Administrator auszuführen 以超级用户身份打开 Pluma accessories-text-editor auth_admin auth_admin auth_admin_keep $${PLUMA_PATH} true Run as Root شغّل كجذر Exécuter en tant qu'administrateur Eseguire come Root Executar como Root Запустить как Администратор Vykdyti Administratoriaus teisėmis Uruchom jako Root Spustenie ako správca Als Administrator ausführen Authentication is required to run as Administrator المصادقة مطلوبة للتشغيل كمدير L'authentification est requise pour exécuter en tant qu'administrateur Autenticazione necessaria per eseguire come Amministratore Autenticação é necessária para executar como Administrador Для запуска исполняемых файлов от имени Администратора требуется аутентификация Vykdomųjų failų paleidimui Administratoriaus teisėmis reikia įvesti slaptažodį Uwierzytelnienie jest wymagane aby uruchomić jako Administrator Na spustenie ako administrátor sa vyžaduje overenie totožnosti Authentifizierung ist erforderlich zum ausführen als Administrator 以超级用户身份运行 utilities-terminal auth_admin auth_admin auth_admin_keep $${TERMINAL_PATH} true peony-extensions/peony-admin/peony-admin.pro0000644000175000017500000000161714205101224020203 0ustar fengfengQT += core gui widgets concurrent include(../common.pri) TARGET = peony-admin TEMPLATE = lib DEFINES += PEONYADMIN_LIBRARY PKGCONFIG += peony CONFIG += link_pkgconfig \ c++11 \ plugin \ debug #DESTDIR += ../testdir PEONY_PATH = "/usr/bin/peony" PLUMA_PATH = "/usr/bin/pluma" TERMINAL_PATH = "/usr/bin/mate-terminal" policy.input = org.freedesktop.peony-admin.policy.in policy.output = org.freedesktop.peony-admin.policy policy.config = verbatim QMAKE_SUBSTITUTES += policy policy_file.files = org.freedesktop.peony-admin.policy policy_file.path = /usr/share/polkit-1/actions SOURCES += admin-menu-plugin.cpp HEADERS += admin-menu-plugin.h TRANSLATIONS += translations/peony-admin_cs.ts \ translations/peony-admin_tr.ts \ translations/peony-admin_zh_CN.ts RESOURCES += resources.qrc target.path = $$[QT_INSTALL_LIBS]/peony-extensions INSTALLS += target policy_file peony-extensions/peony-extensions.pro0000644000175000017500000000070114205133370017072 0ustar fengfengTEMPLATE = subdirs VERSION = 3.2.2 DEFINES += VERSION='\\"$${VERSION}\\"' SUBDIRS = \ # peony-admin \ peony-share \ peony-send-to-device \ peony-set-wallpaper \ peony-bluetooth-plugin \ peony-engrampa-menu-plugin \ peony-extension-computer-view \ peony-menu-plugin-mate-terminal \ # test-computer-view peony-extensions/peony-extension-computer-view/0000755000175000017500000000000014205133370020773 5ustar fengfengpeony-extensions/peony-extension-computer-view/peony-computer-view-plugin.h0000644000175000017500000000430714205101224026373 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef PEONYCOMPUTERVIEWPLUGIN_H #define PEONYCOMPUTERVIEWPLUGIN_H #include "peony-extension-computer-view_global.h" #include namespace Peony { class PEONYQTEXTENSIONCOMPUTERVIEW_EXPORT PeonyComputerViewPlugin : public QObject, public Peony::DirectoryViewPluginIface2 { Q_OBJECT Q_PLUGIN_METADATA(IID DirectoryViewPluginIface2_iid FILE "common.json") Q_INTERFACES(Peony::DirectoryViewPluginIface2) public: explicit PeonyComputerViewPlugin(QObject *parent = nullptr); //common PluginType pluginType() {return PluginType::DirectoryViewPlugin2;} const QString name() {return QObject::tr("Computer View");} const QString description() {return QObject::tr("Show drives, network and personal directories.");} const QIcon icon() {return QIcon::fromTheme("computer");} void setEnable(bool enable) {} bool isEnable() {return true;} //view QString viewIdentity() {return "Computer View";} QString viewName() {return name();} QIcon viewIcon() {return icon();} bool supportUri(const QString &uri) {return uri == "computer:///";} int zoom_level_hint() {return -1;} int minimumSupportedZoomLevel() {return -1;} int maximumSupportedZoomLevel() {return -1;} int priority(const QString &directoryUri); bool supportZoom() {return false;} DirectoryViewWidget *create(); }; } #endif // PEONYCOMPUTERVIEWPLUGIN_H peony-extensions/peony-extension-computer-view/computer-view-container.cpp0000644000175000017500000002760114205133370026273 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-view-container.h" #include "computer-view.h" #include "computer-proxy-model.h" #include "abstract-computer-item.h" #include "login-remote-filesystem.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void ask_question_cb(GMountOperation *op, char *message, char **choices, Peony::ComputerViewContainer *p_this); static void ask_password_cb(GMountOperation *op, const char *message, const char *default_user, const char *default_domain, GAskPasswordFlags flags, Peony::ComputerViewContainer *p_this); static GAsyncReadyCallback mount_enclosing_volume_callback(GFile *volume, GAsyncResult *res, Peony::ComputerViewContainer *p_this) { GError *err = nullptr; g_file_mount_enclosing_volume_finish (volume, res, &err); if ((nullptr == err) || (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED))) { qDebug() << "login successful!"; Q_EMIT p_this->updateWindowLocationRequest(p_this->m_remote_uri); } else if (err->message) { qDebug() << "login remote error: " <code<message<domain; QMessageBox::warning(nullptr, "log remote error", err->message, QMessageBox::Ok); } if (nullptr != err) { g_error_free(err); } if (nullptr != p_this->m_dlg) { p_this->m_dlg->deleteLater(); p_this->m_dlg = nullptr; } return nullptr; } void aborted_cb(GMountOperation *op, Peony::ComputerViewContainer *p_this) { g_mount_operation_reply(op, G_MOUNT_OPERATION_ABORTED); p_this->disconnect(); } Peony::ComputerViewContainer::ComputerViewContainer(QWidget *parent) : DirectoryViewWidget(parent) { setContextMenuPolicy(Qt::CustomContextMenu); m_op = g_mount_operation_new(); g_signal_connect (m_op, "aborted", G_CALLBACK (aborted_cb), this); g_signal_connect (m_op, "ask-question", G_CALLBACK(ask_question_cb), this); g_signal_connect (m_op, "ask-password", G_CALLBACK (ask_password_cb), this); connect(this, &QWidget::customContextMenuRequested, this, [=](const QPoint &pos){ auto selectedIndexes = m_view->selectionModel()->selectedIndexes(); auto index = m_view->indexAt(pos); if (!selectedIndexes.contains(index)) m_view->clearSelection(); if (index.isValid()) { m_view->selectionModel()->select(index, QItemSelectionModel::SelectCurrent); } QMenu menu; auto model = static_cast(m_view->model()); QStringList uris; QList items; for (auto index : m_view->selectionModel()->selectedIndexes()) { auto item = model->itemFromIndex(index); uris<uri(); if (item->uri() == "network:///") return; items<exec(); if (code == QDialog::Rejected) { return; } QUrl url = dlg->uri(); GFile* m_volume = g_file_new_for_uri(dlg->uri().toUtf8().constData()); m_remote_uri = dlg->uri(); g_file_mount_enclosing_volume(m_volume, G_MOUNT_MOUNT_NONE, m_op, nullptr, GAsyncReadyCallback(mount_enclosing_volume_callback), this); }); } else if (items.count() == 1 && items.first()->uri() != "" && items.first()->uri() != "network:///") { auto item = items.first(); bool unmountable = item->canUnmount(); menu.addAction(tr("Unmount"), [=](){ item->unmount(G_MOUNT_UNMOUNT_NONE); }); menu.actions().first()->setEnabled(unmountable); /*eject function for volume. fix #18216*/ auto ejectAction = menu.addAction(tr("Eject"), [=](){ item->eject(G_MOUNT_UNMOUNT_NONE); }); ejectAction->setEnabled(item->canEject()); auto uri = item->uri(); auto realUri = m_view->tryGetVolumeRealUriFromUri(uri); if (!realUri.isEmpty()) { uri = realUri; } auto info = FileInfo::fromUri(uri); if (info->displayName().isEmpty() || info->targetUri().isEmpty()) { FileInfoJob j(info); j.querySync(); } auto mount = VolumeManager::getMountFromUri(info->targetUri()); //fix bug#52491, CDROM and DVD can format issue if (nullptr != mount) { QString unixDevice = FileUtils::getUnixDevice(info->uri()); if (! unixDevice.isNull() && ! unixDevice.contains("/dev/sr") && info->isVolume() && info->canUnmount()) { auto fdMenu = menu.addAction(tr("format"), [=] () { auto fd = new Format_Dialog(info->uri(), nullptr, m_view); fd->show(); }); if (! mount) { fdMenu->setEnabled(false); } } } if (!item->uri().startsWith("network://")) { auto a = menu.addAction(tr("Property"), [=]() { if (uri.isNull()) { QMessageBox::warning(0, 0, tr("You have to mount this volume first")); } else { QProcess p; p.setProgram("peony"); QStringList args; args << "-p" << uri; p.setArguments(args); // p.startDetached(); p.startDetached(p.program(), p.arguments()); } }); a->setEnabled(!uri.isNull()); } } else if(items.first()->uri() != "" && items.first()->uri() != "network:///"){ qDebug() << "unable Property uri:" <uri(); menu.addAction(tr("Property")); menu.actions().first()->setEnabled(false); } if (!menu.isEmpty()) menu.exec(QCursor::pos()); }); } static void ask_question_cb(GMountOperation *op, char *message, char **choices, Peony::ComputerViewContainer *p_this) { qDebug()<<"ask question cb:"<setText(message); char **choice = choices; int i = 0; while (*choice) { qDebug()<<*choice; QPushButton *button = msg_box->addButton(QString(*choice), QMessageBox::ActionRole); p_this->m_dlg->connect(button, &QPushButton::clicked, [=]() { g_mount_operation_set_choice(op, i); }); *choice++; i++; } //block ui msg_box->exec(); msg_box->deleteLater(); qDebug()<<"msg_box done"; g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } static void ask_password_cb(GMountOperation *op, const char *message, const char *default_user, const char *default_domain, GAskPasswordFlags flags, Peony::ComputerViewContainer *p_this) { Q_UNUSED(message); Q_UNUSED(default_user); Q_UNUSED(default_domain); Q_UNUSED(flags); Q_UNUSED(p_this); Peony::ConnectServerLogin dlgLogin (p_this->m_remote_uri); int code = dlgLogin.exec(); g_mount_operation_set_anonymous(p_this->m_op, dlgLogin.anonymous()); if (code == QDialog::Rejected) { g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); return; } dlgLogin.syncRemoteServer(p_this->m_remote_uri); if (!dlgLogin.anonymous()) { g_mount_operation_set_username(p_this->m_op, dlgLogin.user().toUtf8().constData()); g_mount_operation_set_password(p_this->m_op, dlgLogin.password().toUtf8().constData()); g_mount_operation_set_domain(p_this->m_op, dlgLogin.domain().toUtf8().constData()); } g_mount_operation_set_password_save(p_this->m_op, dlgLogin.savePassword()? G_PASSWORD_SAVE_NEVER: G_PASSWORD_SAVE_FOR_SESSION); g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } Peony::ComputerViewContainer::~ComputerViewContainer() { if (nullptr != m_op) { g_object_unref(m_op); } } const QStringList Peony::ComputerViewContainer::getSelections() { QStringList uris; auto model = static_cast(m_view->model()); for (auto index : m_view->selectionModel()->selectedIndexes()) { auto item = model->itemFromIndex(index); uris<uri(); } return uris; } void Peony::ComputerViewContainer::paintEvent(QPaintEvent *e) { DirectoryViewWidget::paintEvent(e); } void Peony::ComputerViewContainer::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { if (m_enterAction) m_enterAction->triggered(); e->accept(); return; } QWidget::keyPressEvent(e); } void Peony::ComputerViewContainer::bindModel(Peony::FileItemModel *model, Peony::FileItemProxyFilterSortModel *proxyModel) { m_model = model; m_proxyModel = proxyModel; model->setRootUri("computer:///"); connect(model, &Peony::FileItemModel::findChildrenFinished, this, &Peony::DirectoryViewWidget::viewDirectoryChanged); if (m_view) m_view->deleteLater(); m_view = new ComputerView(this); auto layout = new QHBoxLayout; layout->addWidget(m_view); setLayout(layout); Q_EMIT viewDirectoryChanged(); auto selectionModel = m_view->selectionModel(); connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &DirectoryViewWidget::viewSelectionChanged);; connect(m_view, &QAbstractItemView::doubleClicked, this, [=](const QModelIndex &index){ if (!index.parent().isValid()) return; auto model = static_cast(m_view->model()); auto item = model->itemFromIndex(index); if (!item->uri().isEmpty()) { item->check(); this->updateWindowLocationRequest(item->uri()); } else { item->mount(); } }); m_enterAction = new QAction(this); m_enterAction->setShortcut(Qt::Key_Enter); addAction(m_enterAction); connect(m_enterAction, &QAction::triggered, this, [=](){ if (m_view->selectionModel()->selectedIndexes().count() == 1) { Q_EMIT m_view->doubleClicked(m_view->selectionModel()->selectedIndexes().first()); } }); connect(m_view, &ComputerView::updateLocationRequest, this, &ComputerViewContainer::updateWindowLocationRequest); } void Peony::ComputerViewContainer::beginLocationChange() { Q_EMIT viewDirectoryChanged(); m_view->refresh(); } void Peony::ComputerViewContainer::stopLocationChange() { Q_EMIT viewDirectoryChanged(); } peony-extensions/peony-extension-computer-view/peony-extension-computer-view_zh_CN.ts0000644000175000017500000002261414205133370030401 0ustar fengfeng ComputerItemDelegate You should mount volume first 需要首先挂载分区 ComputerNetworkItem Network Neighborhood 网上邻居 ComputerRemoteVolumeItem Remote 远程目录 ComputerUserShareItem User Share 共享数据 ComputerVolumeItem Volume 本地分区 File System 文件系统 LoginRemoteFilesystem Connect to Sever 连接到服务器 server information 服务器信息 user information 用户信息 tag 标签 user 用户名 password 密码 protocol 协议 server 服务端地址 directory 目录 SAMBA FTP FTP / / port 端口 20 20 21 21 137 137 138 138 139 139 445 445 ok 确定 cancel 取消 Peony::ComputerViewContainer Connect a server 连接远程服务器 sftp://, etc... 如sftp://... Cancel 取消 OK 确定 Unmount 卸载 Eject 弹出 format 格式化 Property 属性 You have to mount this volume first 需要首先挂载分区 QObject Computer View 电脑视图 Show drives, network and personal directories. 显示设备分区, 网络目录和个人目录. One or more programs prevented the unmount operation. 一个或多个程序阻止卸载操作。 Unmount failed 卸载失败 Error: %1 Do you want to unmount forcely? 错误:%1 是否强制卸载? Error: %1 Unable to unmount it, you may need to close some programs, such as: GParted etc. 无法卸载,您可能需要先关闭一些程序,如分区编辑器等。 %1 %1 Eject failed 弹出失败 Cancel 取消 Eject Anyway 无论如何弹出 peony-extensions/peony-extension-computer-view/peony-extension-computer-view_tr.ts0000644000175000017500000002313014205133370030017 0ustar fengfeng ComputerItemDelegate You should mount volume first Önce bölümü bağlamalısınız ComputerNetworkItem Network Neighborhood Ağ Komşuları ComputerRemoteVolumeItem Remote Uzak ComputerUserShareItem User Share ComputerVolumeItem Volume Bölüm File System Dosya Sistemi LoginRemoteFilesystem Connect to Sever Sunucuya bağlan server information Sunucu bilgisi user information Kullanıcı bilgisi tag Etiket user Kullanıcı password Parola protocol Protokol server Sunucu directory Dizin SAMBA SAMBA FTP FTP / / port Port 20 21 137 138 139 445 ok Tamam cancel İptal Peony::ComputerViewContainer Connect a server Servere bağlan sftp://, etc... sftp://, gibi... Unmount Bağlantıyı kes Eject Çıkar format Property Özellik You have to mount this volume first Önce bu bölümü bağlamalısınız QObject Computer View Bilgisayar Görünümü Show drives, network and personal directories. Sürücüleri, ağı ve kişisel dizinleri göster. One or more programs prevented the unmount operation. Unmount failed Bağlantıyı kesme başarısız Error: %1 Do you want to unmount forcely? Hata: %1 Zorla ayrılmak ister misin? Error: %1 Unable to unmount it, you may need to close some programs, such as: GParted etc. %1 Eject failed Çıkarma başarısız Cancel İptal Eject Anyway Yine de Çıkar peony-extensions/peony-extension-computer-view/login-remote-filesystem.cpp0000644000175000017500000000425114205101224026255 0ustar fengfeng/* * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "login-remote-filesystem.h" #include "ui_login-remote-filesystem.h" #include LoginRemoteFilesystem::LoginRemoteFilesystem(QWidget *parent) : QDialog(parent), ui(new Ui::LoginRemoteFilesystem) { ui->setupUi(this); ui->pwd_lineEdit->setEchoMode(QLineEdit::Password); ui->port_comboBox->setEditText("445"); // connect(ui->type_comboBox, &QComboBox::currentTextChanged, [=](QString& tp) { // if ("SAMBA" == tp) { // ui->port_comboBox->setEditText("445"); // } else if ("FTP" == tp) { // ui->port_comboBox->setEditText("21"); // } // }); } LoginRemoteFilesystem::~LoginRemoteFilesystem() { disconnect(); delete ui; } QString LoginRemoteFilesystem::user() { return ui->user_lineEdit->text(); } QString LoginRemoteFilesystem::password() { return ui->pwd_lineEdit->text(); } QString LoginRemoteFilesystem::domain() { return ui->ip_edit->text() + ":" + ui->port_comboBox->currentText(); } QString LoginRemoteFilesystem::uri() { QString uuri = ""; if (ui->type_comboBox->currentText() == "SAMBA") { uuri = "smb://" + ui->ip_edit->text() + ":" + ui->port_comboBox->currentText() + ui->file_lineEdit->text(); } else if (ui->type_comboBox->currentText() == "FTP") { uuri = "ftp://" + ui->ip_edit->text() + ":" + ui->port_comboBox->currentText() + ui->file_lineEdit->text(); } return uuri; } peony-extensions/peony-extension-computer-view/computer-view-container.h0000644000175000017500000000646314205101224025734 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERVIEWCONTAINER_H #define COMPUTERVIEWCONTAINER_H #include #include #include #include #include class ComputerView; namespace Peony { class ComputerViewContainer : public DirectoryViewWidget { Q_OBJECT public: explicit ComputerViewContainer(QWidget *parent = nullptr); ~ComputerViewContainer(); const virtual QString viewId() {return "Computer View";} //location const virtual QString getDirectoryUri() {return "computer:///";} //selections const virtual QStringList getSelections(); //children const virtual QStringList getAllFileUris() {return QStringList();} virtual int getSortType() {return 0;} virtual Qt::SortOrder getSortOrder() {return Qt::AscendingOrder;} //zoom virtual int currentZoomLevel() {return -1;} virtual int minimumZoomLevel() {return -1;} virtual int maximumZoomLevel() {return -1;} virtual bool supportZoom() {return false;} protected: void paintEvent(QPaintEvent *e); void keyPressEvent(QKeyEvent *e); public Q_SLOTS: virtual void bindModel(FileItemModel *model, FileItemProxyFilterSortModel *proxyModel); //location //virtual void open(const QStringList &uris, bool newWindow) {} virtual void setDirectoryUri(const QString &uri) {} virtual void beginLocationChange(); virtual void stopLocationChange(); virtual void closeDirectoryView() {} //selections virtual void setSelections(const QStringList &uris) {} virtual void invertSelections() {} virtual void scrollToSelection(const QString &uri) {} //clipboard //cut items should be drawn differently. virtual void setCutFiles(const QStringList &uris) {} virtual void setSortType(int sortType) {} virtual void setSortOrder(int sortOrder) {} virtual void editUri(const QString &uri) {} virtual void editUris(const QStringList uris) {} virtual void repaintView() {} virtual void clearIndexWidget() {} //zoom virtual void setCurrentZoomLevel(int zoomLevel) {} public: QString m_remote_uri; GMountOperation* m_op = nullptr; ConnectServerDialog* m_dlg = nullptr; private: ComputerView *m_view = nullptr; QAction *m_enterAction = nullptr; Peony::FileItemModel *m_model = nullptr; Peony::FileItemProxyFilterSortModel *m_proxyModel = nullptr; }; } #endif // COMPUTERVIEWCONTAINER_H peony-extensions/peony-extension-computer-view/peony-extension-computer-view_global.h0000644000175000017500000000221314205101224030423 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef PEONYQTEXTENSIONCOMPUTERVIEW_GLOBAL_H #define PEONYQTEXTENSIONCOMPUTERVIEW_GLOBAL_H #include #if defined(PEONYEXTENSIONCOMPUTERVIEW_LIBRARY) # define PEONYQTEXTENSIONCOMPUTERVIEW_EXPORT Q_DECL_EXPORT #else # define PEONYQTEXTENSIONCOMPUTERVIEW_EXPORT Q_DECL_IMPORT #endif #endif // PEONYEXTENSIONCOMPUTERVIEW_GLOBAL_H peony-extensions/peony-extension-computer-view/peony-extension-computer-view_cs.qm0000644000175000017500000000226614205101224027766 0ustar fengfeng. * * Authors: Yue Lan * */ #include "peony-computer-view-plugin.h" #include "computer-view-container.h" #include #include #include Peony::PeonyComputerViewPlugin::PeonyComputerViewPlugin(QObject *parent) : QObject(parent) { QTranslator *t = new QTranslator(this); t->load(":/peony-extension-computer-view_"+QLocale::system().name()); QApplication::installTranslator(t); } int Peony::PeonyComputerViewPlugin::priority(const QString &directoryUri) { if (directoryUri == "computer:///") return 1; return -1; } Peony::DirectoryViewWidget *Peony::PeonyComputerViewPlugin::create() { return new ComputerViewContainer; } peony-extensions/peony-extension-computer-view/peony-extension-computer-view_tr.qm0000644000175000017500000000531514205101224030004 0ustar fengfengy:YRS:, Q~v_UTN*Nv_U..Show drives, network and personal directories.QObject4elSx} `SQHQsNNz ^ YRS:Vh{I0PUnable to unmount it, you may need to close some programs, such as: GParted etc.QObjectSx}Y1%Unmount failedQObjectpeony-extensions/peony-extension-computer-view/peony-extension-computer-view_cs.ts0000644000175000017500000002176314205133370030011 0ustar fengfeng ComputerItemDelegate You should mount volume first Svazek je třeba nejprve připojit (mount) ComputerNetworkItem Network Neighborhood Okolní počítače ComputerRemoteVolumeItem Remote Vzdálené ComputerUserShareItem User Share ComputerVolumeItem Volume Svazek File System Souborový systém LoginRemoteFilesystem Connect to Sever server information user information tag user password protocol server directory SAMBA FTP / port 20 21 137 138 139 445 ok cancel Peony::ComputerViewContainer Connect a server Připojit k serveru sftp://, etc... sftp://, atd… Unmount Odpojit Eject format Property Vlastnost You have to mount this volume first Tento svazek je třeba nejprve připojit (mount) QObject Computer View Tento počítač Show drives, network and personal directories. Zobrazit disky, síť a osobní složky. One or more programs prevented the unmount operation. Unmount failed Error: %1 Unable to unmount it, you may need to close some programs, such as: GParted etc. %1 Eject failed peony-extensions/peony-extension-computer-view/login-remote-filesystem.ui0000644000175000017500000003440614205101224026115 0ustar fengfeng LoginRemoteFilesystem true 0 0 430 532 0 0 430 532 430 532 Noto Sans CJK SC 14 Connect to Sever .. Qt::LeftToRight width:430px; height:532px; border:0; border-radius:6px; false true 28 48 188 23 0 0 width:118px; height:23px; font-size:20px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; server information 28 260 188 23 width:143px; height:23px; font-size:20px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; user information 28 400 56 18 Noto Sans CJK SC -1 50 false width:56px; height:13px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; tag 96 312 300 30 Noto Sans CJK SC 11 width:300px; height:30px; padding:3px 5px; opacity:0.04; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; 28 318 40 14 Noto Sans CJK SC -1 50 false width:40px; height:14px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; user 96 351 300 30 Noto Sans Mono CJK SC 11 width:300px; height:30px; padding:3px 5px; opacity:0.04; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; 28 358 66 18 Noto Sans CJK SC -1 50 false width:28px; height:13px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; password 96 390 300 30 Noto Sans Mono CJK SC 11 width:300px; height:30px; padding:3px 5px; opacity:0.04; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; 28 145 60 14 Noto Sans CJK SC -1 50 false width:28px; height:13px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; protocol 28 105 42 14 42 14 999999 999999 Noto Sans CJK SC -1 50 false width:42px; height:14px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; server 28 185 60 18 Noto Sans CJK SC -1 50 false width:42px; height:14px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; directory 96 138 301 32 Noto Sans Mono CJK SC 11 width:300px; height:30px; padding:3px 5px; opacity:0.04; border-radius:4px; border:1px solid rgba(62, 108, 229, 0.3); SAMBA FTP 96 178 300 30 Noto Sans Mono CJK SC 11 width:300px; height:30px; padding:3px 5px; opacity:0.04; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; / 296 105 27 14 Noto Sans CJK SC -1 50 false width:27px; height:12px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; border:0; port 336 98 61 30 Noto Sans Mono CJK SC 11 width:60px; height:30px; padding:3px; opacity:0.04; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; true 20 21 137 138 139 445 96 98 182 30 width:182px; height:30px; padding:3px 5px; opacity:0.04; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; 316 471 80 30 Noto Sans CJK SC -1 50 false width:80px; height:30px; background:rgba(62,108,229,1); border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; color:rgba(255,255,255,1); line-height:30px; ok 228 471 80 30 Noto Sans CJK SC -1 50 false width:80px; height:30px; border:1px solid rgba(62, 108, 229, 0.3); border-radius:4px; font-size:14px; font-family:Noto Sans CJK SC; font-weight:400; line-height:30px; cancel ip_edit port_comboBox type_comboBox file_lineEdit user_lineEdit pwd_lineEdit add_lineEdit cancel_pb ok_pb cancel_pb clicked() LoginRemoteFilesystem close() 259 478 193 466 ok_pb clicked() LoginRemoteFilesystem accept() 366 490 412 443 help() peony-extensions/peony-extension-computer-view/translation.qrc0000644000175000017500000000034714205101224024035 0ustar fengfeng peony-extension-computer-view_zh_CN.qm peony-extension-computer-view_tr.qm peony-extension-computer-view_cs.qm peony-extensions/peony-extension-computer-view/computer-view/0000755000175000017500000000000014205133370023601 5ustar fengfengpeony-extensions/peony-extension-computer-view/computer-view/computer-view-style.cpp0000644000175000017500000000712714205101224030251 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: dingjing * */ #include "computer-view-style.h" #include #include #include static ComputerViewStyle *global_instance = nullptr; ComputerViewStyle::ComputerViewStyle(QStyle *style) : QProxyStyle(style) { } ComputerViewStyle *ComputerViewStyle::getStyle() { if (!global_instance) global_instance = new ComputerViewStyle; return global_instance; } void ComputerViewStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (element == PE_Frame) { return; } return QProxyStyle::drawPrimitive(element, option, painter, widget); } void ComputerViewStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (element == QStyle::CE_RubberBand) { //qDebug()<<"draw control rubber band"; if (qstyleoption_cast(option)) { auto rect = option->rect; QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight); painter->save(); QColor penColor = highlight; penColor.setAlpha(180); painter->setPen(penColor); QColor dimHighlight(qMin(highlight.red()/2 + 110, 255), qMin(highlight.green()/2 + 110, 255), qMin(highlight.blue()/2 + 110, 255)); dimHighlight.setAlpha(widget && widget->isTopLevel() ? 255 : 80); QLinearGradient gradient(rect.topLeft(), QPoint(rect.bottomLeft().x(), rect.bottomLeft().y())); gradient.setColorAt(0, dimHighlight.lighter(120)); gradient.setColorAt(1, dimHighlight); painter->setRenderHint(QPainter::Antialiasing, true); painter->translate(0.5, 0.5); painter->setBrush(dimHighlight); painter->drawRoundedRect(option->rect.adjusted(0, 0, -1, -1), 1, 1); QColor innerLine = Qt::white; innerLine.setAlpha(40); painter->setPen(innerLine); painter->drawRoundedRect(option->rect.adjusted(1, 1, -2, -2), 1, 1); painter->restore(); } return; } QProxyStyle::drawControl(element, option, painter, widget); } void ComputerViewStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const { //qDebug()<<"drawItemPixmap"; QProxyStyle::drawItemPixmap(painter, rect, alignment, pixmap); } void ComputerViewStyle::drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole) const { //qDebug()<<"drawItemText"; QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole); } peony-extensions/peony-extension-computer-view/computer-view/computer-model.h0000644000175000017500000000522314205101224026701 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERMODEL_H #define COMPUTERMODEL_H #include #include class AbstractComputerItem; class ComputerModel : public QAbstractItemModel { friend class ComputerNetworkItem; friend class ComputerVolumeItem; friend class ComputerRemoteVolumeItem; Q_OBJECT public: explicit ComputerModel(QObject *parent = nullptr); void beginInsertItem(const QModelIndex &parent, int row); void endInsterItem(); void beginRemoveItem(const QModelIndex &parent, int row); void endRemoveItem(); QModelIndex createItemIndex(int row, QObject *item); // Basic functionality: QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &index) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; // Editable: bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; Qt::ItemFlags flags(const QModelIndex& index) const override; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); QString tryGetVolumeUriFromMountRoot(const QString &mountRootUri); QString tryGetVolumeRealUriFromUri(const QString &uri); void addRealUri(const QString &realUri); void removeRealUri(const QString &realUri); void refresh(); Q_SIGNALS: void updateLocationRequest(const QString &uri); void invalidateRequest(); private: AbstractComputerItem *m_parentNode; QMap m_volumeTargetMap; QList m_volumeRealUri; }; #endif // COMPUTERMODEL_H peony-extensions/peony-extension-computer-view/computer-view/abstract-computer-item.cpp0000644000175000017500000000233514205101224030674 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "abstract-computer-item.h" #include AbstractComputerItem::AbstractComputerItem(ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent) { m_model = model; m_parentNode = parentNode; } AbstractComputerItem::~AbstractComputerItem() { for (auto child : m_children) { child->deleteLater(); } } QModelIndex AbstractComputerItem::itemIndex() { return QModelIndex(); } peony-extensions/peony-extension-computer-view/computer-view/computer-user-share-item.h0000644000175000017500000000530214205133370030620 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: dingjing * */ #ifndef COMPUTERUSERSHAREITEM_H #define COMPUTERUSERSHAREITEM_H #include #include "abstract-computer-item.h" #include #include class ComputerUserShareItem : public AbstractComputerItem { Q_OBJECT friend void query_file_info_async_callback(GFile *file, GAsyncResult *res, ComputerUserShareItem* p_this); public: explicit ComputerUserShareItem(GVolume *volume, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent = nullptr); ~ComputerUserShareItem(); void updateInfoAsync(); Type itemType() override {return Volume;} const QString uri() override {return m_uri;} const QString displayName() override {return m_displayName;}; const QIcon icon() override {return m_icon;}; bool isMount() override {return true;}; void findChildren() override {}; void updateInfo() override {updateInfoAsync();} void check() override; bool canEject() override {return false;}; void eject(GMountUnmountFlags) override {}; bool canUnmount() override {return false;}; void unmount(GMountUnmountFlags) override {}; void mount() override {}; QModelIndex itemIndex() override; qint64 usedSpace() override {return m_usedSpace;}; qint64 totalSpace() override {return m_totalSpace;} bool isHidden() override {return m_isHidden;}; protected: private: QString m_uri; QString m_vfs_uri; GFile* m_file; QString m_displayName; QIcon m_icon; qint64 m_totalSpace = 0; qint64 m_usedSpace = 0; bool m_isHidden = false; GCancellable *m_cancellable = nullptr; }; #endif // COMPUTERUSERSHAREITEM_H peony-extensions/peony-extension-computer-view/computer-view/computer-volume-item.h0000644000175000017500000001003014205133370030043 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERVOLUMEITEM_H #define COMPUTERVOLUMEITEM_H #include "abstract-computer-item.h" #include #include class ComputerVolumeItem : public AbstractComputerItem { Q_OBJECT public: explicit ComputerVolumeItem(GVolume *volume, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent = nullptr); //explicit ComputerVolumeItem(const QString uri,ComputerModel *model,AbstractComputerItem *parentNode,QObject *parent = nullptr); ~ComputerVolumeItem(); void updateInfoAsync(); Type itemType() override {return Volume;} const QString uri() override {return m_uri;} const QString displayName() override; const QIcon icon() override; bool isMount() override; void findChildren() override; void updateInfo() override {updateInfoAsync();} void check() override; bool canEject() override; void eject(GMountUnmountFlags ejectFlag) override; bool canUnmount() override; void unmount(GMountUnmountFlags unmountFlag) override; void mount() override; QModelIndex itemIndex() override; qint64 usedSpace() override {return m_usedSpace;} qint64 totalSpace() override {return m_totalSpace;} bool isHidden() override; protected: //monitor static void volume_changed_callback(GVolume *volume, ComputerVolumeItem *p_this); static void volume_removed_callback(GVolume *volume, ComputerVolumeItem *p_this); //info static void qeury_info_async_callback(GFile *file, GAsyncResult *res, ComputerVolumeItem *p_this); static void query_root_info_async_callback(GFile *file, GAsyncResult *res, ComputerVolumeItem *p_this); //mount op static void mount_async_callback(GVolume *volume, GAsyncResult *res, ComputerVolumeItem *p_this); static void unmount_async_callback(GObject *object, GAsyncResult *res, ComputerVolumeItem *p_this); static void eject_async_callback(GObject *object, GAsyncResult *res, ComputerVolumeItem *p_this); static void stop_async_callback(GDrive *drive, GAsyncResult *res, ComputerVolumeItem *p_this); //watcher //comment gparted process code to fix duplicated volume issue, bug#41623 // void collectInfoWhenGpartedOpen(QString uri); // void onFileAdded(const QString &uri); // void onFileRemoved(const QString &uri); //gparted //void findChildrenWhenGPartedOpen(); //static void enumerate_async_callback(GFile *file, GAsyncResult *res, ComputerVolumeItem *p_this); //static void find_children_async_callback(GFileEnumerator *enumerator, GAsyncResult *res, ComputerVolumeItem *p_this); friend quint64 calcVolumeCapacity(ComputerVolumeItem* pThis); private Q_SLOTS: void onVolumeAdded(const std::shared_ptr volume); void updateBlockIcons(); private: QString m_uri; QString m_vfs_uri; std::shared_ptr m_volume; std::shared_ptr m_mount; GCancellable *m_cancellable; GCancellable *m_tmpCancellable; //info QString m_displayName; QString m_unixDeviceName; QIcon m_icon; qint64 m_totalSpace = 0; qint64 m_usedSpace = 0; Peony::FileWatcher *m_watcher = nullptr; QString m_targetUri; bool m_isHidden = false; }; #endif // COMPUTERVOLUMEITEM_H peony-extensions/peony-extension-computer-view/computer-view/computer-remote-volume-item.h0000644000175000017500000000460514205133370031347 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERREMOTEVOLUMEITEM_H #define COMPUTERREMOTEVOLUMEITEM_H #include #include #include "abstract-computer-item.h" class ComputerRemoteVolumeItem : public AbstractComputerItem { Q_OBJECT public: explicit ComputerRemoteVolumeItem(const QString &uri, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent = nullptr); ~ComputerRemoteVolumeItem(); Type itemType() override {return RemoteVolume;} const QString uri() override {return m_uri;} const QString displayName() override; const QIcon icon() override; void findChildren() override; void updateInfo() override; bool canUnmount() override {return true;} void unmount(GMountUnmountFlags unmountFlag) override; QModelIndex itemIndex() override; bool isHidden() override; public: void onFileAdded(const QString &uri); void onFileRemoved(const QString &uri); void onFileChanged(const QString &uri); protected: //enumeration static void enumerate_async_callback(GFile *file, GAsyncResult *res, ComputerRemoteVolumeItem *p_this); static void find_children_async_callback(GFileEnumerator *enumerator, GAsyncResult *res, ComputerRemoteVolumeItem *p_this); //info static void query_info_async_callback(GFile *file, GAsyncResult *res, ComputerRemoteVolumeItem *p_this); //monitor private: QString m_uri; GCancellable *m_cancellable = nullptr; bool m_isUnixDevice = false; QString m_displayName; QIcon m_icon; Peony::FileWatcher *m_watcher = nullptr; }; #endif // COMPUTERREMOTEVOLUMEITEM_H peony-extensions/peony-extension-computer-view/computer-view/computer-view.h0000644000175000017500000000654614205133370026573 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERVIEW_H #define COMPUTERVIEW_H #include #include class ComputerProxyModel; class QRubberBand; class ComputerView : public QAbstractItemView { Q_OBJECT public: explicit ComputerView(QWidget *parent = nullptr); bool eventFilter(QObject *object, QEvent *event); virtual QRect visualRect(const QModelIndex &index) const; virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible); virtual QModelIndex indexAt(const QPoint &point) const; virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); virtual int horizontalOffset() const; virtual int verticalOffset() const; virtual bool isIndexHidden(const QModelIndex &index) const; virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command); virtual QRegion visualRegionForSelection(const QItemSelection &selection) const; QString tryGetVolumeUriFromMountTarget(const QString &mountTargetUri); QString tryGetVolumeRealUriFromUri(const QString &uri); void refresh(); Q_SIGNALS: void updateLocationRequest(const QString &uri); protected: void updateEditorGeometries(); void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *e); void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void dragEnterEvent(QDragEnterEvent *event); void dragMoveEvent(QDragMoveEvent *event); void dropEvent(QDropEvent *event); void layoutVolumeIndexes(const QModelIndex &volumeParentIndex); void layoutRemoteIndexes(const QModelIndex &remoteParentIndex); void layoutNetworkIndexes(const QModelIndex &networkParentIndex); void adjustLayout(); private: ComputerProxyModel *m_model; QRubberBand *m_rubberBand; QPoint m_lastPressedPoint; QPoint m_lastPressedLogicPoint; QRect m_logicRect; bool m_isLeftButtonPressed = false; QModelIndex m_hoverIndex; int m_scrollStep = 100; int m_totalHeight = 0; int m_totalWidth = 0; int m_hSpacing = 20; int m_vSpacing = 20; int m_tabPadding = 36; QSize m_volumeItemFixedSize = QSize(256, 108); QSize m_remoteItemFixedSize = QSize(108, 144); QSize m_networkItemFixedSize = QSize(108, 144); QHash m_rect_cache; }; #endif // COMPUTERVIEW_H peony-extensions/peony-extension-computer-view/computer-view/computer-proxy-model.h0000644000175000017500000000311714205101224030060 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERPROXYMODEL_H #define COMPUTERPROXYMODEL_H #include class ComputerModel; class AbstractComputerItem; class ComputerProxyModel : public QSortFilterProxyModel { Q_OBJECT public: explicit ComputerProxyModel(QObject *parent = nullptr); static ComputerProxyModel *globalInstance(); AbstractComputerItem *itemFromIndex(const QModelIndex &proxyIndex); QString tryGetVolumeUriFromMountTarget(const QString &mountTargetUri); QString tryGetVolumeRealUriFromUri(const QString &uri); void refresh(); Q_SIGNALS: void updateLocationRequest(const QString &uri); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; private: ComputerModel *m_model; }; #endif // COMPUTERPROXYMODEL_H peony-extensions/peony-extension-computer-view/computer-view/computer-remote-volume-item.cpp0000644000175000017500000002011514205133370031674 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-remote-volume-item.h" #include "computer-model.h" #include "file-utils.h" #include #include ComputerRemoteVolumeItem::ComputerRemoteVolumeItem(const QString &uri, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent) : AbstractComputerItem(model, parentNode, parent) { m_uri = uri; m_cancellable = g_cancellable_new(); updateInfo(); m_model->m_volumeTargetMap.insert(Peony::FileUtils::getTargetUri(uri), uri); m_model->addRealUri(uri); qDebug()<<"create remote volume item:"<m_volumeTargetMap.remove(m_uri); m_model->removeRealUri(m_uri); } const QString ComputerRemoteVolumeItem::displayName() { if (m_uri == "computer:///") return tr("Remote"); return m_displayName; } const QIcon ComputerRemoteVolumeItem::icon() { return m_icon; } void ComputerRemoteVolumeItem::findChildren() { if (m_uri != "computer:///") return; GFile *file = g_file_new_for_uri("computer:///"); g_file_enumerate_children_async(file, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, m_cancellable, GAsyncReadyCallback(enumerate_async_callback), this); g_object_unref(file); } void ComputerRemoteVolumeItem::updateInfo() { GFile *file = g_file_new_for_uri(m_uri.toUtf8().constData()); g_file_query_info_async(file, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, m_cancellable, GAsyncReadyCallback(query_info_async_callback), this); g_object_unref(file); } void ComputerRemoteVolumeItem::unmount(GMountUnmountFlags unmountFlag) { GFile *file = g_file_new_for_uri(m_uri.toUtf8().constData()); g_file_unmount_mountable_with_operation(file, unmountFlag, nullptr, nullptr, nullptr, nullptr); g_object_unref(file); } QModelIndex ComputerRemoteVolumeItem::itemIndex() { if (!m_parentNode) return m_model->createItemIndex(0, this); return m_model->createItemIndex(m_parentNode->m_children.indexOf(this), this); } bool ComputerRemoteVolumeItem::isHidden() { return m_isUnixDevice || m_uri == "computer:///root.link"; } void ComputerRemoteVolumeItem::onFileAdded(const QString &uri) { //not include udisk、mobile-disk、local-partition etc. QString targetUri; targetUri = Peony::FileUtils::getTargetUri(uri); m_model->m_volumeTargetMap.insert(uri, targetUri); m_model->addRealUri(uri); if(!targetUri.isEmpty() && targetUri.contains("file:///")) return; for (auto item : m_children) { //qDebug() << "ComputerRemoteVolumeItem onFileAdded uri:"<uri(); if (item->uri() == uri) return; } m_model->beginInsertItem(itemIndex(), m_children.count()); auto item = new ComputerRemoteVolumeItem(uri, m_model, this); m_children<endInsterItem(); } void ComputerRemoteVolumeItem::onFileRemoved(const QString &uri) { int row = -1; for (auto item : m_children) { //qDebug() << "ComputerRemoteVolumeItem onFileRemoved uri:"<uri(); if (item->uri() == uri) { row = m_children.indexOf(item); break; } } if (row < 0) return; m_model->beginRemoveItem(itemIndex(), row); auto item = m_children.takeAt(row); item->deleteLater(); m_model->endRemoveItem(); } void ComputerRemoteVolumeItem::onFileChanged(const QString &uri) { for (auto item : m_children) { if (item->uri() == uri) { item->updateInfo(); return; } } } void ComputerRemoteVolumeItem::enumerate_async_callback(GFile *file, GAsyncResult *res, ComputerRemoteVolumeItem *p_this) { GError *err = nullptr; auto enumerator = g_file_enumerate_children_finish(file, res, &err); if (enumerator) { g_file_enumerator_next_files_async(enumerator, 9999, 0, p_this->m_cancellable, GAsyncReadyCallback(find_children_async_callback), p_this); } if (err) { p_this->m_isUnixDevice = true; //hide computer:/// //QMessageBox::critical(0, 0, err->message); g_error_free(err); } } void ComputerRemoteVolumeItem::find_children_async_callback(GFileEnumerator *enumerator, GAsyncResult *res, ComputerRemoteVolumeItem *p_this) { GError *err = nullptr; auto infos = g_file_enumerator_next_files_finish(enumerator, res, &err); GList *l = infos; while (l) { auto info = G_FILE_INFO(l->data); l = l->next; if (!info) continue; auto file = g_file_enumerator_get_child(enumerator, info); if (!file) continue; auto uri = g_file_get_uri(file); if (!uri) continue; //not include udisk、mobile-disk、local-partition etc. QString targetUri; targetUri = Peony::FileUtils::getTargetUri(uri); p_this->m_model->m_volumeTargetMap.insert(uri, targetUri); p_this->m_model->addRealUri(uri); if(!targetUri.isEmpty() && targetUri.contains("file:///")) continue; p_this->m_model->beginInsertItem(p_this->itemIndex(), p_this->m_children.count()); auto item = new ComputerRemoteVolumeItem(uri, p_this->m_model, p_this); p_this->m_children<m_model->endInsterItem(); g_free(uri); g_object_unref(file); } if (infos) g_list_free_full(infos, g_object_unref); if (enumerator) { g_file_enumerator_close(enumerator, nullptr, nullptr); g_object_unref(enumerator); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } else { p_this->m_watcher = new Peony::FileWatcher("computer:///", p_this); connect(p_this->m_watcher, &Peony::FileWatcher::fileCreated, p_this, &ComputerRemoteVolumeItem::onFileAdded); connect(p_this->m_watcher, &Peony::FileWatcher::fileDeleted, p_this, &ComputerRemoteVolumeItem::onFileRemoved); connect(p_this->m_watcher, &Peony::FileWatcher::fileChanged, p_this, &ComputerRemoteVolumeItem::onFileChanged); p_this->m_watcher->startMonitor(); } } void ComputerRemoteVolumeItem::query_info_async_callback(GFile *file, GAsyncResult *res, ComputerRemoteVolumeItem *p_this) { GError *err = nullptr; GFileInfo *info = g_file_query_info_finish(file, res, &err); if (info) { p_this->m_isUnixDevice = g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE_FILE); p_this->m_displayName = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); GIcon *icon = g_file_info_get_icon(info); const gchar * const * names = g_themed_icon_get_names(G_THEMED_ICON(icon)); if (names) { const char *name = *names; if (name) { p_this->m_icon = QIcon::fromTheme(name); } } p_this->m_model->dataChanged(p_this->itemIndex(), p_this->itemIndex()); qDebug()<m_uri<m_isUnixDevice; g_object_unref(info); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } } peony-extensions/peony-extension-computer-view/computer-view/computer-view.cpp0000644000175000017500000003671314205133370027125 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-view.h" #include "computer-proxy-model.h" #include "abstract-computer-item.h" #include "computer-item-delegate.h" #include "computer-view-style.h" #include #include #include #include #include #include #include #include #include #include #include ComputerView::ComputerView(QWidget *parent) : QAbstractItemView(parent) { setDragDropMode(QAbstractItemView::DropOnly); setItemDelegate(new ComputerItemDelegate(this)); m_model = ComputerProxyModel::globalInstance(); setModel(m_model); setStyle(ComputerViewStyle::getStyle()); m_rubberBand = new QRubberBand(QRubberBand::Shape::Rectangle, this); connect(m_model, &ComputerProxyModel::updateLocationRequest, this, &ComputerView::updateLocationRequest); connect(this, &QAbstractItemView::doubleClicked, this, [=](const QModelIndex &index){ qDebug()<selectionModel(), &QItemSelectionModel::selectionChanged, this, [=](){ this->viewport()->update(); }); //fix #18184 auto volumeManager = Peony::VolumeManager::getInstance(); connect(volumeManager,&Peony::VolumeManager::volumeRemoved,this,[=](const std::shared_ptr volume){ this->viewport()->update(); }); if (QGSettings::isSchemaInstalled("org.ukui.style")) { adjustLayout(); //font monitor, adjust to font size to fix lauout issue, link to bug#65238 QGSettings *fontSetting = new QGSettings(FONT_SETTINGS, QByteArray(), this); connect(fontSetting, &QGSettings::changed, this, [=](const QString &key){ qDebug() << "fontSetting changed:" << key; if (key == "systemFontSize") { adjustLayout(); } }); } setSelectionMode(QAbstractItemView::ExtendedSelection); this->viewport()->setMouseTracking(true); this->viewport()->installEventFilter(this); } void ComputerView::adjustLayout() { QGSettings *fontSetting = new QGSettings(FONT_SETTINGS, QByteArray(), this); int fontSize = fontSetting->get("systemFontSize").toInt(); int width = 256 + (fontSize -11) * 64/5; int height = 108 + (fontSize -11) * 36/5; m_volumeItemFixedSize = QSize(width, height); int other_width = 108 + (fontSize -11) * 36/5; int other_height = 144 + (fontSize -11) * 48/5; m_remoteItemFixedSize = QSize(other_width, other_height); m_networkItemFixedSize = QSize(other_width, other_height); } bool ComputerView::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::MouseMove) { if (!m_isLeftButtonPressed) { auto pos = mapFromGlobal(QCursor::pos()); auto newIndex = indexAt(pos); if (newIndex != m_hoverIndex) { m_hoverIndex = newIndex; this->viewport()->update(); } } else { m_hoverIndex = QModelIndex(); } } return false; } QRect ComputerView::visualRect(const QModelIndex &index) const { return m_rect_cache.value(index); } void ComputerView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint) { //return; //FIXME: scroll to the index more accurecely. //auto y = m_rect_cache.value(index).y(); //verticalScrollBar()->setValue(y); } QModelIndex ComputerView::indexAt(const QPoint &point) const { auto pos = point + QPoint(horizontalOffset(), verticalOffset()); for (auto index : m_rect_cache.keys()) { auto rect = m_rect_cache.value(index); if (rect.contains(pos)) return index; } return QModelIndex(); } QModelIndex ComputerView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) { return QModelIndex(); } int ComputerView::horizontalOffset() const { return horizontalScrollBar()->value()*m_scrollStep; } int ComputerView::verticalOffset() const { return verticalScrollBar()->value()*m_scrollStep; } bool ComputerView::isIndexHidden(const QModelIndex &index) const { return false; } void ComputerView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) { //caculate logic rubber band rect in mouse move event. //qDebug()<<"setSelection"<isVisible()) { auto realRect = m_rubberBand->geometry(); realRect.adjust(horizontalOffset(), verticalOffset(), horizontalOffset(), verticalOffset()); for (auto index : m_rect_cache.keys()) { auto indexRect = m_rect_cache.value(index); if (realRect.contains(indexRect.center())) { selectionModel()->select(index, QItemSelectionModel::Select); } else { selectionModel()->select(index, QItemSelectionModel::Deselect); } } } else { auto pos = rect.center(); auto index = indexAt(pos); if (!index.isValid()) { clearSelection(); return; } if (!selectedIndexes().contains(index)) selectionModel()->select(index, QItemSelectionModel::SelectCurrent); } } QRegion ComputerView::visualRegionForSelection(const QItemSelection &selection) const { return QRegion(); } QString ComputerView::tryGetVolumeUriFromMountTarget(const QString &mountTargetUri) { return m_model->tryGetVolumeUriFromMountTarget(mountTargetUri); } QString ComputerView::tryGetVolumeRealUriFromUri(const QString &uri) { return m_model->tryGetVolumeRealUriFromUri(uri); } void ComputerView::refresh() { m_model->refresh(); } void ComputerView::updateEditorGeometries() { QAbstractItemView::updateEditorGeometries(); m_totalHeight = 0; m_totalWidth = this->viewport()->width(); m_rect_cache.clear(); for (int row = 0; row < m_model->rowCount(); row++) { auto index = m_model->index(row, 0); auto item = m_model->itemFromIndex(index); switch (item->itemType()) { case AbstractComputerItem::Volume: { layoutVolumeIndexes(index); break; } case AbstractComputerItem::RemoteVolume: { layoutRemoteIndexes(index); break; } case AbstractComputerItem::Network: { layoutNetworkIndexes(index); break; } default: break; } } //confirm total width for (auto rect : m_rect_cache.values()) { if (rect.right() > m_totalWidth) m_totalWidth = rect.right(); } horizontalScrollBar()->setRange(0, qMax(0, m_totalWidth - viewport()->width())); verticalScrollBar()->setRange(0, qMax(0, (m_totalHeight - viewport()->height() + 200)/m_scrollStep)); //update tab index rect width for (auto index : m_rect_cache.keys()) { if (!index.parent().isValid()) { auto rect = m_rect_cache.value(index); rect.setWidth(m_totalWidth); m_rect_cache.remove(index); m_rect_cache.insert(index, rect); } } } void ComputerView::resizeEvent(QResizeEvent *event) { QAbstractItemView::resizeEvent(event); updateEditorGeometries(); } void ComputerView::paintEvent(QPaintEvent *e) { QPainter p(this->viewport()); p.fillRect(this->rect(), palette().base()); //p.fillRect(QRect(0, 0, m_totalWidth, m_totalHeight), Qt::blue); p.save(); p.translate(-horizontalOffset(), -verticalOffset()); for (auto rect : m_rect_cache) { //qDebug()<paint(&p, opt, index); } p.restore(); } void ComputerView::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { m_isLeftButtonPressed = true; m_rubberBand->hide(); m_lastPressedPoint = event->pos(); m_lastPressedLogicPoint = event->pos() + QPoint(horizontalOffset(), verticalOffset()); } else m_rubberBand->hide(); QAbstractItemView::mousePressEvent(event); this->viewport()->update(); } void ComputerView::mouseMoveEvent(QMouseEvent *event) { QAbstractItemView::mouseMoveEvent(event); if (m_isLeftButtonPressed) { auto pos = event->pos(); auto offset = QPoint(horizontalOffset(), verticalOffset()); auto logicPos = pos + offset; QRect logicRect = QRect(logicPos, m_lastPressedLogicPoint); m_logicRect = logicRect.normalized(); int dx = -horizontalOffset(); int dy = -verticalOffset(); auto realRect = m_logicRect.adjusted(dx, dy, dx ,dy); if (!m_rubberBand->isVisible()) m_rubberBand->show(); m_rubberBand->setGeometry(realRect); } else { m_rubberBand->hide(); } } void ComputerView::mouseReleaseEvent(QMouseEvent *event) { m_rubberBand->hide(); m_isLeftButtonPressed = false; QAbstractItemView::mouseReleaseEvent(event); } void ComputerView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { QAbstractItemView::dataChanged(topLeft, bottomRight, roles); this->viewport()->update(); } void ComputerView::dragEnterEvent(QDragEnterEvent *event) { event->accept(); } void ComputerView::dragMoveEvent(QDragMoveEvent *event) { event->accept(); auto newIndex = indexAt(event->pos()); if (newIndex != m_hoverIndex) { m_hoverIndex = newIndex; this->viewport()->update(); } } void ComputerView::dropEvent(QDropEvent *event) { bool isMoveOp = event->keyboardModifiers() & Qt::ShiftModifier; auto index = indexAt(event->pos()); if (index.isValid()) { m_model->dropMimeData(event->mimeData(), isMoveOp? Qt::MoveAction: Qt::CopyAction, index.row(), index.column(), index.parent()); } } void ComputerView::layoutVolumeIndexes(const QModelIndex &volumeParentIndex) { int rowCount = m_model->rowCount(volumeParentIndex); if (rowCount <= 0) return; //add tab m_rect_cache.insert(volumeParentIndex, QRect(QPoint(0, m_totalHeight), QSize(this->viewport()->width(), m_tabPadding))); m_totalHeight += m_tabPadding + 10; //layout indexes int tmpX = 0; int maxColumnCount = 0; //if view's width is not enough, expand the m_totalWidth to ensure scroallble if (m_totalWidth < 2 * (m_hSpacing + m_volumeItemFixedSize.width())) { maxColumnCount = 1; } else { maxColumnCount = this->viewport()->width()/(m_hSpacing + m_volumeItemFixedSize.width());// - 1; } int cloumn = 0; for (int row = 0; row < rowCount; row++) { //layout next row if (cloumn > maxColumnCount - 1) { //m_totalWidth = tmpX + m_hSpacing + m_volumeItemFixedSize.width(); cloumn = 1; tmpX = m_hSpacing; m_totalHeight = m_totalHeight + m_volumeItemFixedSize.height() + m_vSpacing; } else { tmpX = m_hSpacing + cloumn*(m_hSpacing+m_volumeItemFixedSize.width()); cloumn++; } auto index = m_model->index(row, 0, volumeParentIndex); m_rect_cache.insert(index, QRect(QPoint(tmpX, m_totalHeight), m_volumeItemFixedSize)); } m_totalHeight = m_totalHeight + m_volumeItemFixedSize.height() + m_vSpacing; } void ComputerView::layoutRemoteIndexes(const QModelIndex &remoteParentIndex) { int rowCount = m_model->rowCount(remoteParentIndex); if (rowCount <= 0) return; //add tab m_rect_cache.insert(remoteParentIndex, QRect(QPoint(0, m_totalHeight), QSize(this->viewport()->width(), m_tabPadding))); m_totalHeight += m_tabPadding + 10; //layout indexes int tmpX = 0; int maxColumnCount = 0; //if view's width is not enough, expand the m_totalWidth to ensure scroallble if (m_totalWidth < 2 * (m_hSpacing + m_remoteItemFixedSize.width())) { //m_totalWidth = m_hSpacing + m_remoteItemFixedSize.width(); maxColumnCount = 1; } else { maxColumnCount = this->viewport()->width()/(m_hSpacing + m_remoteItemFixedSize.width());// - 1; } int cloumn = 0; for (int row = 0; row < rowCount; row++) { //layout next row if (cloumn > maxColumnCount - 1) { //m_totalWidth = tmpX + m_hSpacing + m_volumeItemFixedSize.width(); cloumn = 1; tmpX = m_hSpacing; m_totalHeight = m_totalHeight + m_remoteItemFixedSize.height() + m_vSpacing; } else { tmpX = m_hSpacing + cloumn*(m_hSpacing+m_remoteItemFixedSize.width()); cloumn++; } auto index = m_model->index(row, 0, remoteParentIndex); m_rect_cache.insert(index, QRect(QPoint(tmpX, m_totalHeight), m_remoteItemFixedSize)); } m_totalHeight = m_totalHeight + m_remoteItemFixedSize.height() + m_vSpacing; } void ComputerView::layoutNetworkIndexes(const QModelIndex &networkParentIndex) { int rowCount = m_model->rowCount(networkParentIndex); if (rowCount <= 0) return; //add tab m_rect_cache.insert(networkParentIndex, QRect(QPoint(0, m_totalHeight), QSize(this->viewport()->width(), m_tabPadding))); m_totalHeight += m_tabPadding + 10; //layout indexes int tmpX = 0; int maxColumnCount = 0; //if view's width is not enough, expand the m_totalWidth to ensure scroallble if (m_totalWidth < 2 * (m_hSpacing + m_networkItemFixedSize.width())) { maxColumnCount = 1; } else { maxColumnCount = this->viewport()->width()/(m_hSpacing + m_networkItemFixedSize.width());// - 1; } int cloumn = 0; for (int row = 0; row < rowCount; row++) { //layout next row if (cloumn > maxColumnCount - 1) { //m_totalWidth = tmpX + m_hSpacing + m_volumeItemFixedSize.width(); cloumn = 1; tmpX = m_hSpacing; m_totalHeight = m_totalHeight + m_networkItemFixedSize.height() + m_vSpacing; } else { tmpX = m_hSpacing + cloumn*(m_hSpacing+m_networkItemFixedSize.width()); cloumn++; } auto index = m_model->index(row, 0, networkParentIndex); m_rect_cache.insert(index, QRect(QPoint(tmpX, m_totalHeight), m_networkItemFixedSize)); } m_totalHeight = m_totalHeight + m_networkItemFixedSize.height() + m_vSpacing; } peony-extensions/peony-extension-computer-view/computer-view/computer-item-delegate.h0000644000175000017500000000366214205101224030314 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERITEMDELEGATE_H #define COMPUTERITEMDELEGATE_H #include class QListView; class AbstractComputerItem; class ComputerItemDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit ComputerItemDelegate(QObject *parent = nullptr); ~ComputerItemDelegate(); protected: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void paintVolumeItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, AbstractComputerItem *item) const; void paintRemoteItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, AbstractComputerItem *item) const; void paintNetworkItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, AbstractComputerItem *item) const; void drawTab(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void drawStyledItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; private: QListView *m_styleIconView; }; #endif // COMPUTERITEMDELEGATE_H peony-extensions/peony-extension-computer-view/computer-view/abstract-computer-item.h0000644000175000017500000000446614205101224030350 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef ABSTRACTCOMPUTERITEM_H #define ABSTRACTCOMPUTERITEM_H #include #include #include class ComputerModel; class AbstractComputerItem : public QObject { Q_OBJECT public: enum Type { Invalid, Personal, Volume, RemoteVolume, Network }; Q_ENUM(Type) explicit AbstractComputerItem(ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent = nullptr); ~AbstractComputerItem(); virtual Type itemType() {return Invalid;} virtual const QString uri() {return nullptr;} virtual const QString displayName() {return nullptr;} virtual const QIcon icon() {return QIcon::fromTheme("text-plain");} virtual bool hasChildren() {return false;} virtual void findChildren() {} virtual void clearChildren() {} virtual void updateInfo() {} virtual void check() {} virtual bool isMount () {return false;} //for volumn virtual qint64 totalSpace() {return 0;} virtual qint64 usedSpace() {return 0;} virtual bool canUnmount() {return false;} virtual void unmount(GMountUnmountFlags unmountFlag) {} virtual void mount() {} virtual bool canEject() {return false;} virtual void eject(GMountUnmountFlags ejectFlag) {} //for remote volume virtual bool isHidden() {return false;} virtual QModelIndex itemIndex(); public: ComputerModel *m_model; AbstractComputerItem *m_parentNode; QList m_children; }; #endif // ABSTRACTCOMPUTERITEM_H peony-extensions/peony-extension-computer-view/computer-view/computer-proxy-model.cpp0000644000175000017500000000455014205101224030415 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-proxy-model.h" #include "computer-model.h" #include "abstract-computer-item.h" static ComputerProxyModel *global_instance = nullptr; ComputerProxyModel::ComputerProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { setDynamicSortFilter(true); auto computerModel = new ComputerModel(this); setSourceModel(computerModel); m_model = computerModel; connect(m_model, &ComputerModel::updateLocationRequest, this, &ComputerProxyModel::updateLocationRequest); connect(m_model, &ComputerModel::invalidateRequest, this, &ComputerProxyModel::invalidateFilter); } ComputerProxyModel *ComputerProxyModel::globalInstance() { if (!global_instance) { global_instance = new ComputerProxyModel; } return global_instance; } AbstractComputerItem *ComputerProxyModel::itemFromIndex(const QModelIndex &proxyIndex) { auto index = mapToSource(proxyIndex); return static_cast(index.internalPointer()); } QString ComputerProxyModel::tryGetVolumeUriFromMountTarget(const QString &mountTargetUri) { return m_model->tryGetVolumeUriFromMountRoot(mountTargetUri); } QString ComputerProxyModel::tryGetVolumeRealUriFromUri(const QString &uri) { return m_model->tryGetVolumeRealUriFromUri(uri); } void ComputerProxyModel::refresh() { m_model->refresh(); } bool ComputerProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { auto item = static_cast(m_model->index(source_row, 0, source_parent).internalPointer()); return !item->isHidden(); } peony-extensions/peony-extension-computer-view/computer-view/computer-item-delegate.cpp0000644000175000017500000002324414205133370030654 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include #include "computer-view.h" #include "computer-proxy-model.h" #include "computer-item-delegate.h" #include "abstract-computer-item.h" #include #include #include #include #include #include ComputerItemDelegate::ComputerItemDelegate(QObject *parent) : QStyledItemDelegate(parent) { m_styleIconView = new QListView; m_styleIconView->setViewMode(QListView::IconMode); } ComputerItemDelegate::~ComputerItemDelegate() { m_styleIconView->deleteLater(); } void ComputerItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; initStyleOption(&opt, index); //use rounded rect primitive in ukui style. if (index.parent().isValid()) { opt.decorationPosition = QStyleOptionViewItem::Top; opt.decorationSize = QSize(64, 64); opt.features = QStyleOptionViewItem::WrapText; opt.displayAlignment = Qt::AlignHCenter|Qt::AlignTop; opt.rect.adjust(2, 2, -2, -2); //opt.features.setFlag(QStyleOptionViewItem::WrapText); } auto view = qobject_cast(parent()); auto model = qobject_cast(view->model()); auto item = model->itemFromIndex(index); if (!item) return; switch (item->itemType()) { case AbstractComputerItem::Volume: paintVolumeItem(painter, opt, index, item); break; case AbstractComputerItem::RemoteVolume: paintRemoteItem(painter, opt, index, item); break; case AbstractComputerItem::Network: paintNetworkItem(painter, opt, index, item); break; default: break; } } void ComputerItemDelegate::paintVolumeItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, AbstractComputerItem *item) const { auto opt = option; auto bg = opt.palette.highlight().color(); int hue = bg.hue(); //int s = bg.saturation(); int v = bg.value(); bg.setHsv(hue, 10, 127); opt.palette.setColor(QPalette::Highlight, bg); //qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, m_styleIconView); bool isHover = (option.state & QStyle::State_MouseOver) && (option.state & ~QStyle::State_Selected); bool isSelected = option.state & QStyle::State_Selected; bool enable = option.state & QStyle::State_Enabled; QColor color = option.palette.color(enable? QPalette::Active: QPalette::Disabled, QPalette::Highlight); color.setAlpha(0); if (isHover && !isSelected) { int h = color.hsvHue(); //int s = color.hsvSaturation(); auto base = option.palette.base().color(); int v = color.value(); color.setHsv(h, base.lightness(), v, 64); } if (isSelected) { color.setAlpha(127); } painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->setPen(Qt::transparent); painter->setBrush(color); painter->drawRoundedRect(option.rect, 6, 6); painter->restore(); if (index.parent().isValid()) { painter->save(); painter->setRenderHint(QPainter::Antialiasing); //draw pix map QIcon icon = option.icon; bool enable = option.state & QStyle::State_Enabled; bool selected = option.state &QStyle::State_Selected; QPixmap pix = icon.pixmap(QSize(64, 64), enable? selected? QIcon::Selected: QIcon::Normal: QIcon::Disabled); qApp->style()->drawItemPixmap(painter, option.rect.adjusted(5, 0, 0, 0), Qt::AlignVCenter|Qt::AlignLeft, pix); //draw text auto textRect = option.rect; textRect.adjust(84, 10, -5, -10); textRect.translate(0, -option.fontMetrics.ascent()); auto elideText = opt.fontMetrics.elidedText(opt.text, Qt::ElideMiddle, textRect.width()); qApp->style()->drawItemText(painter, textRect, Qt::AlignLeft|Qt::AlignVCenter, option.palette, enable, elideText, QPalette::Text); //space bool shouldDrawProgress = false; QString spaceInfo; auto total = item->totalSpace(); auto used = item->usedSpace(); if (total > 0) { char *totalFormat = g_format_size_full(total,G_FORMAT_SIZE_IEC_UNITS); char *usedFormat = g_format_size_full(used,G_FORMAT_SIZE_IEC_UNITS); QString totalFormatString(totalFormat); QString usedFormatString(usedFormat); totalFormatString.replace("iB", "B"); usedFormatString.replace("iB", "B"); spaceInfo = QString("%1/%2").arg(usedFormatString).arg(totalFormatString); g_free(totalFormat); g_free(usedFormat); shouldDrawProgress = true; } else { if (!item->isMount()) { spaceInfo = tr("You should mount volume first"); } } qApp->style()->drawItemText(painter, textRect.translated(0, 2*option.fontMetrics.ascent()), Qt::AlignLeft|Qt::AlignVCenter|Qt::TextWordWrap, option.palette, enable, spaceInfo, QPalette::Dark); if (shouldDrawProgress) { painter->save(); QPainterPath clipPath; clipPath.addRoundedRect(option.rect, 6, 6); painter->setClipPath(clipPath); qreal percent = used*1.0/total*1.0; int progressBarWidth = option.rect.width() * percent; painter->save(); QPen pen; //pen.setColor(percent < 0.8?Qt::blue:Qt::red); if (percent < 0.8) { pen.setColor(option.palette.highlight().color()); } else { pen.setColor(Qt::red); } pen.setCapStyle(Qt::PenCapStyle::RoundCap); pen.setJoinStyle(Qt::PenJoinStyle::RoundJoin); pen.setWidth(6); painter->setPen(pen); auto pos = option.rect.bottomLeft(); pos.setX(pos.x() + progressBarWidth); pos.setY(pos.y() - 5); painter->drawLine(option.rect.bottomLeft() + QPoint(5, -5), pos); painter->restore(); painter->restore(); } painter->restore(); } else { //auto textRect = qApp->style()->subElementRect(QStyle::SE_ItemViewItemText, &option, m_styleIconView); drawTab(painter, option, index); } } void ComputerItemDelegate::paintRemoteItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, AbstractComputerItem *item) const { if (index.parent().isValid()) { qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, nullptr); drawStyledItem(painter, option, index); } else { drawTab(painter, option, index); } } void ComputerItemDelegate::paintNetworkItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, AbstractComputerItem *item) const { if (index.parent().isValid()) { qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, nullptr); drawStyledItem(painter, option, index); } else { drawTab(painter, option, index); } } void ComputerItemDelegate::drawTab(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { auto opt = option; auto titleFont = opt.font; if (titleFont.pixelSize() > 0) { titleFont.setPixelSize(titleFont.pixelSize()*1.5); } else { titleFont.setPointSizeF(titleFont.pointSizeF()*1.5); } opt.icon = QIcon(); opt.decorationPosition = QStyleOptionViewItem::Right; opt.displayAlignment = Qt::AlignLeft|Qt::AlignVCenter; opt.font = titleFont; opt.fontMetrics = QFontMetrics(opt.font); qApp->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter); //auto textRect = qApp->style()->subElementRect(QStyle::SE_ItemViewItemText, &opt, m_styleIconView); //qApp->style()->drawItemText(painter, opt.rect.adjusted(5, 0, 0, 0), Qt::AlignTop|Qt::AlignVCenter, option.palette, enable, option.text, selected? QPalette::HighlightedText: QPalette::Text); } void ComputerItemDelegate::drawStyledItem(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); //draw pix map QIcon icon = option.icon; bool enable = option.state & QStyle::State_Enabled; bool selected = option.state &QStyle::State_Selected; QPixmap pix = icon.pixmap(QSize(64, 64), enable? selected? QIcon::Selected: QIcon::Normal: QIcon::Disabled); qApp->style()->drawItemPixmap(painter, option.rect.adjusted(0, 5, 0, 0), Qt::AlignTop|Qt::AlignHCenter, pix); //draw text auto textRect = option.rect.adjusted(2, 74, -2, -2); qApp->style()->drawItemText(painter, textRect, Qt::ElideRight|Qt::TextWrapAnywhere|Qt::AlignTop|Qt::AlignHCenter, option.palette, enable, option.text, selected? QPalette::HighlightedText: QPalette::Text); painter->restore(); } peony-extensions/peony-extension-computer-view/computer-view/computer-personal-item.cpp0000644000175000017500000000266314205101224030720 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-personal-item.h" #include "computer-model.h" #include ComputerPersonalItem::ComputerPersonalItem(const QString &uri, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent) : AbstractComputerItem(model, parentNode, parent) { if (!parentNode) { m_uri = "file://" + QStandardPaths::writableLocation(QStandardPaths::HomeLocation); } else { m_uri = uri; } } const QString ComputerPersonalItem::displayName() { //FIXME: return nullptr; } void ComputerPersonalItem::findChildren() { //FIXME: } void ComputerPersonalItem::clearChildren() { //FIXME: } peony-extensions/peony-extension-computer-view/computer-view/computer-network-item.cpp0000644000175000017500000001521414205101224030562 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-network-item.h" #include "computer-model.h" #include ComputerNetworkItem::ComputerNetworkItem(const QString &uri, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent) : AbstractComputerItem(model, parentNode, parent) { m_cancellable = g_cancellable_new(); m_uri = uri; updateInfo(); } ComputerNetworkItem::~ComputerNetworkItem() { g_cancellable_cancel(m_cancellable); g_object_unref(m_cancellable); } const QString ComputerNetworkItem::displayName() { if (m_uri == "network:///") return tr("Network Neighborhood"); return m_displayName; } void ComputerNetworkItem::findChildren() { if (m_uri != "network:///") return; GFile *file = g_file_new_for_uri("network:///"); g_file_enumerate_children_async(file, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, m_cancellable, GAsyncReadyCallback(enumerate_async_callback), this); g_object_unref(file); } void ComputerNetworkItem::updateInfo() { GFile *file = g_file_new_for_uri(m_uri.toUtf8().constData()); g_file_query_info_async(file, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, m_cancellable, GAsyncReadyCallback(query_info_async_callback), this); g_object_unref(file); } QModelIndex ComputerNetworkItem::itemIndex() { if (!m_parentNode) return m_model->createItemIndex(0, this); return m_model->createItemIndex(m_parentNode->m_children.indexOf(this), this); } void ComputerNetworkItem::reloadDirectory(const QString &uri) { if (m_uri != "network:///") return; m_model->beginResetModel(); for (auto item : m_children) { item->deleteLater(); } m_children.clear(); findChildren(); m_model->endResetModel(); } void ComputerNetworkItem::onFileAdded(const QString &uri) { for (auto item : m_children) { if (item->uri() == uri) return; } m_model->beginInsertItem(itemIndex(), m_children.count()); auto item = new ComputerNetworkItem(uri, m_model, this); m_children<endInsterItem(); } void ComputerNetworkItem::onFileRemoved(const QString &uri) { int row = -1; for (auto item : m_children) { if (item->uri() == uri) { row = m_children.indexOf(item); break; } } if (row < 0) return; m_model->beginRemoveItem(itemIndex(), row); auto item = m_children.takeAt(row); item->deleteLater(); m_model->endRemoveItem(); } void ComputerNetworkItem::onFileChanged(const QString &uri) { for (auto item : m_children) { if (item->uri() == uri) { item->updateInfo(); return; } } } void ComputerNetworkItem::enumerate_async_callback(GFile *file, GAsyncResult *res, ComputerNetworkItem *p_this) { GError *err = nullptr; auto enumerator = g_file_enumerate_children_finish(file, res, &err); if (enumerator) { g_file_enumerator_next_files_async(enumerator, 9999, 0, p_this->m_cancellable, GAsyncReadyCallback(find_children_async_callback), p_this); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } } void ComputerNetworkItem::find_children_async_callback(GFileEnumerator *enumerator, GAsyncResult *res, ComputerNetworkItem *p_this) { GError *err = nullptr; auto infos = g_file_enumerator_next_files_finish(enumerator, res, &err); GList *l = infos; while (l) { auto info = G_FILE_INFO(l->data); l = l->next; if (!info) continue; auto file = g_file_enumerator_get_child(enumerator, info); if (!file) continue; auto uri = g_file_get_uri(file); if (!uri) continue; p_this->m_model->beginInsertItem(p_this->itemIndex(), p_this->m_children.count()); auto item = new ComputerNetworkItem(uri, p_this->m_model, p_this); p_this->m_children<m_model->endInsterItem(); g_free(uri); g_object_unref(file); } if (infos) g_list_free_full(infos, g_object_unref); if (enumerator) { g_file_enumerator_close(enumerator, nullptr, nullptr); g_object_unref(enumerator); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } if (p_this->m_watcher) { p_this->m_watcher->deleteLater(); } p_this->m_watcher = new Peony::FileWatcher("network:///", p_this); connect(p_this->m_watcher, &Peony::FileWatcher::directoryDeleted, p_this, &ComputerNetworkItem::reloadDirectory); connect(p_this->m_watcher, &Peony::FileWatcher::fileCreated, p_this, &ComputerNetworkItem::onFileAdded); connect(p_this->m_watcher, &Peony::FileWatcher::fileDeleted, p_this, &ComputerNetworkItem::onFileRemoved); connect(p_this->m_watcher, &Peony::FileWatcher::fileChanged, p_this, &ComputerNetworkItem::onFileChanged); p_this->m_watcher->startMonitor(); } void ComputerNetworkItem::query_info_async_callback(GFile *file, GAsyncResult *res, ComputerNetworkItem *p_this) { GError *err = nullptr; GFileInfo *info = g_file_query_info_finish(file, res, &err); if (info) { p_this->m_displayName = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); GIcon *icon = g_file_info_get_icon(info); const gchar * const * names = g_themed_icon_get_names(G_THEMED_ICON(icon)); if (names) { const char *name = *names; if (name) { p_this->m_icon = QIcon::fromTheme(name); } } p_this->m_model->dataChanged(p_this->itemIndex(), p_this->itemIndex()); g_object_unref(info); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } } peony-extensions/peony-extension-computer-view/computer-view/computer-user-share-item.cpp0000644000175000017500000000460614205133370031161 0ustar fengfeng#include "computer-user-share-item.h" #include "computer-model.h" #include #include void query_file_info_async_callback(GFile *file, GAsyncResult *res, ComputerUserShareItem* p_this); ComputerUserShareItem::ComputerUserShareItem(GVolume *volume, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent) : AbstractComputerItem(model, parentNode, parent) { m_cancellable = g_cancellable_new(); m_model->beginInsertItem(parentNode->itemIndex(), parentNode->m_children.count()); parentNode->m_children<endInsterItem(); m_file = g_file_new_for_uri("file:///data/usershare/"); GFile* file = g_file_new_for_uri("file:///data"); GFileInfo* fileInfo = g_file_query_info(file, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, nullptr); if (g_file_info_get_attribute_boolean(fileInfo, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT)) { updateInfoAsync(); } if (file) g_object_unref(file); if (fileInfo) g_object_unref(fileInfo); Q_UNUSED(volume); } ComputerUserShareItem::~ComputerUserShareItem() { g_cancellable_cancel(m_cancellable); g_object_unref(m_cancellable); if (m_file) g_object_unref(m_file); } void ComputerUserShareItem::updateInfoAsync() { g_file_query_filesystem_info_async(m_file, "filesystem::*", 0, m_cancellable, GAsyncReadyCallback(query_file_info_async_callback), this); } void ComputerUserShareItem::check() { } QModelIndex ComputerUserShareItem::itemIndex() { return m_model->createItemIndex(m_parentNode->m_children.indexOf(this), this); } void query_file_info_async_callback(GFile *file, GAsyncResult *res, ComputerUserShareItem* p_this) { GError *err = nullptr; GFileInfo *info = g_file_query_info_finish(file, res, &err); if (err) { g_error_free(err); return; } if (info) { quint64 total = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); quint64 used = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_USED); p_this->m_totalSpace = total; p_this->m_usedSpace = used; auto index = p_this->itemIndex(); p_this->m_model->dataChanged(index, index); g_object_unref(info); } } peony-extensions/peony-extension-computer-view/computer-view/computer-view-style.h0000644000175000017500000000230314205133370027714 0ustar fengfeng#ifndef COMPUTERVIEWSTYLE_H #define COMPUTERVIEWSTYLE_H #include #include class ComputerViewStyle : public QProxyStyle { public: static ComputerViewStyle *getStyle(); void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override; void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override; void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override; void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override; private: explicit ComputerViewStyle(QStyle *style = nullptr); ~ComputerViewStyle() override {} }; #endif // COMPUTERVIEWSTYLE_H peony-extensions/peony-extension-computer-view/computer-view/computer-view.pri0000644000175000017500000000151614205101224027117 0ustar fengfengINCLUDEPATH += $$PWD HEADERS += \ $$PWD/abstract-computer-item.h \ $$PWD/computer-item-delegate.h \ $$PWD/computer-model.h \ $$PWD/computer-network-item.h \ $$PWD/computer-personal-item.h \ $$PWD/computer-proxy-model.h \ $$PWD/computer-remote-volume-item.h \ $$PWD/computer-view-style.h \ $$PWD/computer-view.h \ $$PWD/computer-user-share-item.h \ $$PWD/computer-volume-item.h SOURCES += \ $$PWD/abstract-computer-item.cpp \ $$PWD/computer-item-delegate.cpp \ $$PWD/computer-model.cpp \ $$PWD/computer-network-item.cpp \ $$PWD/computer-personal-item.cpp \ $$PWD/computer-proxy-model.cpp \ $$PWD/computer-remote-volume-item.cpp \ $$PWD/computer-view-style.cpp \ $$PWD/computer-view.cpp \ $$PWD/computer-user-share-item.cpp \ $$PWD/computer-volume-item.cpp peony-extensions/peony-extension-computer-view/computer-view/computer-volume-item.cpp0000644000175000017500000007025414205133370030414 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-volume-item.h" #include #include #include "computer-model.h" #include "computer-user-share-item.h" #include #include #include #include #include #include #include #include #include #ifdef signals #undef signals #endif #include ComputerVolumeItem::ComputerVolumeItem(GVolume *volume, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent) : AbstractComputerItem(model, parentNode, parent) { m_model->beginInsertItem(parentNode->itemIndex(), parentNode->m_children.count()); parentNode->m_children<itemType() != Volume) { m_displayName = tr("Volume"); m_model->endInsterItem(); return; } m_cancellable = g_cancellable_new(); if (!volume) { m_icon = QIcon::fromTheme("drive-harddisk-system"); m_uri = "file:///"; m_displayName = tr("File System"); auto file = g_file_new_for_uri("file:///"); g_file_query_filesystem_info_async(file, "*", 0, m_cancellable, GAsyncReadyCallback(query_root_info_async_callback), this); m_model->endInsterItem(); return; } m_volume = std::make_shared(volume, true); updateInfoAsync(); g_signal_connect(volume, "changed", G_CALLBACK(volume_changed_callback), this); g_signal_connect(volume, "removed", G_CALLBACK(volume_removed_callback), this); m_model->endInsterItem(); } //ComputerVolumeItem::ComputerVolumeItem(const QString uri,ComputerModel *model,AbstractComputerItem *parentNode,QObject *parent) : AbstractComputerItem(model,parentNode,parent){ // if(uri.isNull() || uri.isEmpty()) // return; // //collectInfoWhenGpartedOpen(uri); //} ComputerVolumeItem::~ComputerVolumeItem() { g_cancellable_cancel(m_cancellable); g_object_unref(m_cancellable); if(m_watcher){ m_watcher->stopMonitor(); delete m_watcher; } } void ComputerVolumeItem::updateInfoAsync() { if (!m_volume) { m_icon = QIcon::fromTheme("drive-harddisk-system"); m_uri = "file:///"; m_displayName = tr("File System"); auto file = g_file_new_for_uri("file:///"); g_file_query_filesystem_info_async(file, "*", 0, m_cancellable, GAsyncReadyCallback(query_root_info_async_callback), this); return; } char *deviceName; m_displayName = m_volume->name(); //Handle the Chinese name of fat32 udisk. deviceName = g_volume_get_identifier(m_volume->getGVolume(),G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); if(deviceName){ m_unixDeviceName = QString(deviceName); qDebug()<<"unix Device Name"<< m_unixDeviceName; Peony::FileUtils::handleVolumeLabelForFat32(m_displayName, m_unixDeviceName); g_free(deviceName); } //fix u-disk show as hard-disk icon issue, task#25343 updateBlockIcons(); //qDebug()<getGVolume()); if (mount) { m_mount = std::make_shared(mount, true); auto active_root = g_mount_get_root(mount); if (active_root) { auto uri = g_file_get_uri(active_root); if (uri) { m_uri = uri; g_free(uri); } if (m_uri == "file:///data") { if (Peony::FileUtils::isFileExsit("file:///data/usershare")) { m_isHidden = true; } } g_file_query_filesystem_info_async(active_root, "*", 0, m_cancellable, GAsyncReadyCallback(qeury_info_async_callback), this); g_object_unref(active_root); } } else { //m_mount = nullptr; //mount first //FIXME: check auto mount // this->mount(); } auto index = this->itemIndex(); m_model->dataChanged(index, index); m_model->invalidateRequest(); } const QString ComputerVolumeItem::displayName() { return m_displayName; } const QIcon ComputerVolumeItem::icon() { return m_icon.isNull()? AbstractComputerItem::icon(): m_icon; } bool ComputerVolumeItem::isMount() { return Peony::FileUtils::isMountPoint(m_uri); } void ComputerVolumeItem::findChildren() { //add root auto root = new ComputerVolumeItem(nullptr, m_model, this); //enumerate auto volume_monitor = g_volume_monitor_get(); auto current_volumes = g_volume_monitor_get_volumes(volume_monitor); GList *l = current_volumes; while (l) { auto volume = G_VOLUME(l->data); auto item = new ComputerVolumeItem(volume, m_model, this); l = l->next; } //comment gparted process code to fix duplicated volume issue, bug#41623 // if(!current_volumes) // findChildrenWhenGPartedOpen(); //monitor auto volumeManager = Peony::VolumeManager::getInstance(); connect(volumeManager, &Peony::VolumeManager::volumeAdded, this, &ComputerVolumeItem::onVolumeAdded); //watcher // m_watcher = new Peony::FileWatcher("computer:///",this); // connect(m_watcher, &Peony::FileWatcher::fileCreated, this, &ComputerVolumeItem::onFileAdded); // connect(m_watcher, &Peony::FileWatcher::fileDeleted, this, &ComputerVolumeItem::onFileRemoved); // m_watcher->startMonitor(); if (Peony::FileUtils::isFileExsit("file:///data/usershare")) { new ComputerUserShareItem(nullptr, m_model, this); } } void ComputerVolumeItem::check() { if (!m_volume) return; auto active_root = g_volume_get_activation_root(m_volume->getGVolume()); if (active_root) { auto uri = g_file_get_uri(active_root); auto path = g_file_get_path(active_root); if (QString(uri) == "file:///data") { if (Peony::FileUtils::isFileExsit("file:///data/usershare")) { m_isHidden = true; } } //QMessageBox::information(0, 0, QString("%1 has active root %2").arg(m_displayName).arg(uri)); if (uri) { /*! \bug when a volume added, it could have active root represond with a uri, such as mtp://, etc... however it could not get the local path of active root correctly at the time. that makes some volumes location changement meet troubles. */ m_uri = uri; g_free(uri); } if (path) { m_uri = QString("file://%1").arg(path); g_free(path); } g_object_unref(active_root); } if (m_uri.isNull()) { GFile* file = nullptr; GMount* mount = g_volume_get_mount(m_volume->getGVolume()); if (nullptr != mount) { file = g_mount_get_root (mount); if (nullptr != file) { m_uri = g_file_get_uri(file); } } if (nullptr != file) { g_object_unref(file); } if (nullptr != mount) { g_object_unref (mount); } } } bool ComputerVolumeItem::canEject() { GVolume *gvolume; GDrive *gdrive; bool ejectAble = false; if("file:///" == m_uri || m_volume == nullptr) /*The root File System cannot eject*/ return false; if(NULL != m_volume->getGVolume()){ gvolume = (GVolume*)g_object_ref(m_volume->getGVolume()); gdrive = g_volume_get_drive(gvolume); if(gdrive){ ejectAble = g_drive_can_eject(gdrive) || g_drive_can_stop(gdrive) || g_drive_is_removable(gdrive); g_object_unref(gdrive); } g_object_unref(gvolume); } return ejectAble; } void ComputerVolumeItem::eject(GMountUnmountFlags ejectFlag) { GVolume *g_volume; GMount *g_mount; /*If udisk device is mounted,eject it from here*/ if (m_mount && (g_mount = m_mount->getGMount())) { if (g_mount_can_eject(g_mount)) { g_mount_eject_with_operation(g_mount, ejectFlag, nullptr, m_cancellable, GAsyncReadyCallback(eject_async_callback), this); } else { auto g_drive = g_mount_get_drive(g_mount); if (!g_drive) return; if (g_drive_can_stop(g_drive) || g_drive_is_removable(g_drive)) g_drive_stop(g_mount_get_drive(g_mount), ejectFlag, nullptr, m_cancellable, GAsyncReadyCallback(stop_async_callback), this); g_object_unref(g_drive); } return; } /*If udisk device is unmounted,eject it from here*/ if (m_volume && (g_volume = m_volume->getGVolume())) { if (g_volume_can_eject(g_volume)) { g_volume_eject_with_operation(g_volume, ejectFlag, nullptr, m_cancellable, GAsyncReadyCallback(eject_async_callback), this); } else { auto g_drive = g_mount_get_drive(g_mount); if (!g_drive) return; if (g_drive_can_stop(g_drive)) g_drive_stop(g_mount_get_drive(g_mount), ejectFlag, nullptr, m_cancellable, GAsyncReadyCallback(stop_async_callback), this); g_object_unref(g_drive); } } } bool ComputerVolumeItem::canUnmount() { if(m_uri.endsWith(".mount") || m_uri.endsWith(".volume")) return true; return m_mount != nullptr; } void ComputerVolumeItem::unmount(GMountUnmountFlags unmountFlag) { GMount *g_mount = nullptr; GFile *file = nullptr; m_vfs_uri = m_model->m_volumeTargetMap.key(m_uri); if (!m_vfs_uri.isEmpty()) { file = g_file_new_for_uri(m_vfs_uri.toUtf8().constData()); if(file) g_file_unmount_mountable_with_operation(file,unmountFlag, nullptr,nullptr, GAsyncReadyCallback(unmount_async_callback), this); g_object_unref(file); } else if (m_mount) { if (g_mount = m_mount->getGMount()) g_mount_unmount_with_operation(g_mount, unmountFlag, nullptr, m_cancellable, GAsyncReadyCallback(unmount_async_callback), this); } else if (!m_uri.isEmpty()) { file = g_file_new_for_uri(m_uri.toUtf8().constData()); if(file) g_file_unmount_mountable_with_operation(file,unmountFlag, nullptr,nullptr, GAsyncReadyCallback(unmount_async_callback), this); g_object_unref(file); } } void ComputerVolumeItem::mount() { if (m_uri == "file:///") { return; } if (m_mount) { auto root = g_mount_get_root(m_mount->getGMount()); if (root) { auto uri = g_file_get_uri(root); if (uri) { m_uri = uri; g_free(uri); } g_file_query_filesystem_info_async(root, "*", 0, m_cancellable, GAsyncReadyCallback(qeury_info_async_callback), this); g_object_unref(root); } } else { g_volume_mount(m_volume->getGVolume(), G_MOUNT_MOUNT_NONE, nullptr, m_cancellable, GAsyncReadyCallback(mount_async_callback), this); } } QModelIndex ComputerVolumeItem::itemIndex() { if (!m_parentNode) { return m_model->createItemIndex(0, this); } else { return m_model->createItemIndex(m_parentNode->m_children.indexOf(this), this); } } bool ComputerVolumeItem::isHidden() { return m_isHidden; } void ComputerVolumeItem::volume_changed_callback(GVolume *volume, ComputerVolumeItem *p_this) { //QMessageBox::information(0, 0, tr("Volume Changed")); p_this->m_mount = nullptr; p_this->m_uri = nullptr; p_this->m_icon = QIcon(); p_this->m_displayName = nullptr; p_this->m_usedSpace = 0; p_this->m_totalSpace = 0; p_this->updateInfo(); } void ComputerVolumeItem::volume_removed_callback(GVolume *volume, ComputerVolumeItem *p_this) { auto parentNode = p_this->m_parentNode; if (!parentNode) return; auto row = parentNode->m_children.indexOf(p_this); parentNode->m_model->beginRemoveItem(parentNode->itemIndex(), row); parentNode->m_children.removeAt(row); p_this->deleteLater(); parentNode->m_model->endRemoveItem(); } QString iconFileFromMountpoint(const QString& mountpoint){ bool isReadOnly; QDir mountDir; QString iconPath; GUnixMountEntry* entry; if(mountpoint.isEmpty()) return iconPath; entry = g_unix_mount_for(mountpoint.mid(7).toUtf8().constData(),NULL); if(entry){ isReadOnly = g_unix_mount_is_readonly(entry); g_unix_mount_free(entry); if(!isReadOnly)//is not a boot disk return iconPath; } mountDir.setPath(mountpoint.mid(7));//remove 'file://' if(mountDir.exists()){ QStringList filters; filters << "*.ico"; mountDir.setNameFilters(filters); QFileInfoList list = mountDir.entryInfoList(); if(0 != list.length()) iconPath = list.at(0).absoluteFilePath(); } return iconPath; } void ComputerVolumeItem::qeury_info_async_callback(GFile *file, GAsyncResult *res, ComputerVolumeItem *p_this) { GError *err = nullptr; auto info = g_file_query_filesystem_info_finish(file, res, &err); if (info) { /* *由于对DVD+RW或者是DVD-RW类型的光盘,无法通过cdromdata类获取到使用的容量,所以使用的容量统一使用gio函数获取 */ quint64 used = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_USED); bool bNotDisk = true; if (p_this->m_unixDeviceName.startsWith("/dev/sr")) { Peony::DataCDROM *cdrom = new Peony::DataCDROM(p_this->m_unixDeviceName); if (cdrom) { cdrom->getCDROMInfo(); p_this->m_usedSpace = used; p_this->m_totalSpace = cdrom->getCDROMCapacity(); delete cdrom; cdrom = nullptr; bNotDisk = false; } } //fix block not update volume issue, link to bug#63326 if (bNotDisk || 0 == p_this->m_totalSpace) { quint64 total = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); quint64 free = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); if (total > 0 && (used > 0 || free > 0)) { if (used > 0 && used <= total) { p_this->m_usedSpace = used; p_this->m_totalSpace = total; } else if(free > 0 && free <= total) { p_this->m_usedSpace = total - free; p_this->m_totalSpace = total; } p_this->updateBlockIcons(); } } qWarning()<<"udisk name"<m_volume->name(); qWarning()<<"udisk used space"<m_usedSpace; qWarning()<<"udisk total space"<m_totalSpace; /***************************collect info when gparted open*************************/ // if(p_this->m_icon.name().isEmpty()){ // QString iconName = Peony::FileUtils::getFileIconName(p_this->m_uri); // if(iconName.isNull()) /*Some startup disks cannot get the icon*/ // iconName = "drive-harddisk-usb"; // p_this->m_icon = QIcon::fromTheme(iconName); // } // if(p_this->m_displayName.isEmpty()){ // p_this->m_displayName = Peony::FileUtils::getFileDisplayName(p_this->m_uri); // if(!p_this->m_targetUri.isEmpty()){ // char *realMountPoint = g_filename_from_uri(p_this->m_targetUri.toUtf8().constData(),NULL,NULL); // const char *unixDev = Peony::VolumeManager::getUnixDeviceFileFromMountPoint(realMountPoint); // QString unixDeviceName = unixDev; // Peony::FileUtils::handleVolumeLabelForFat32(p_this->m_displayName,unixDeviceName); // g_free(realMountPoint); // } // } /**********************************************************************************/ auto index = p_this->itemIndex(); p_this->m_model->dataChanged(index, index); //p_this->m_model->dataChanged(p_this->itemIndex(), p_this->itemIndex()); g_object_unref(info); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } } void ComputerVolumeItem::query_root_info_async_callback(GFile *file, GAsyncResult *res, ComputerVolumeItem *p_this) { GError *err = nullptr; GFileInfo *info = g_file_query_info_finish(file, res, &err); if (info) { quint64 total = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); quint64 used = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_USED); p_this->m_totalSpace = total; p_this->m_usedSpace = used; auto index = p_this->itemIndex(); p_this->m_model->dataChanged(index, index); //p_this->m_model->dataChanged(p_this->itemIndex(), p_this->itemIndex()); g_object_unref(info); } if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } } void ComputerVolumeItem::mount_async_callback(GVolume *volume, GAsyncResult *res, ComputerVolumeItem *p_this) { GError *err = nullptr; bool successed = g_volume_mount_finish(volume, res, &err); if (err) { //QMessageBox::critical(0, 0, err->message); g_error_free(err); } if (successed) { p_this->updateInfoAsync(); } } void ComputerVolumeItem::unmount_async_callback(GObject* object,GAsyncResult *res,ComputerVolumeItem *p_this) { GError *err = nullptr; QString errorMsg; bool successed; if(G_IS_MOUNT(object)){ successed = g_mount_unmount_with_operation_finish(G_MOUNT(object),res,&err); if(successed) p_this->m_mount = nullptr; }else if(G_IS_FILE(object)){ g_file_unmount_mountable_with_operation_finish(G_FILE(object),res,&err); } if(err){ errorMsg = err->message; if(strstr(err->message,"target is busy")){ errorMsg = QObject::tr("One or more programs prevented the unmount operation."); QMessageBox::warning(nullptr, QObject::tr("Unmount failed"), QObject::tr("Error: %1\n").arg(errorMsg), QMessageBox::Yes); }else if(strstr(err->message,"umount: /media/")){ //chinese name need to be converted,this may be a error that from glib2/gio2. errorMsg = QObject::tr("Unable to unmount it, you may need to close some programs, such as: GParted etc."); QMessageBox::warning(nullptr, QObject::tr("Unmount failed"), QObject::tr("%1").arg(errorMsg), QMessageBox::Yes); } else if (err->code == G_IO_ERROR_PERMISSION_DENIED || errorMsg.contains("authorized", Qt::CaseInsensitive)) { // do nothing because we have requested polkit dialog yet. } else { QMessageBox::warning(nullptr, QObject::tr("Unmount failed"), QObject::tr("Error: %1\n").arg(err->message), QMessageBox::Yes); } g_error_free(err); } } void ComputerVolumeItem::eject_async_callback(GObject *object, GAsyncResult *res, ComputerVolumeItem *p_this) { GError *err = nullptr; bool successed; if(G_IS_MOUNT(object)) successed = g_mount_eject_with_operation_finish(G_MOUNT(object), res, &err); else if(G_IS_VOLUME(object)) successed = g_volume_eject_with_operation_finish(G_VOLUME(object), res, &err); if (successed) { //QMessageBox::information(0, 0, "Volume Ejected"); } if (err) { QString errMsg = err->message; if (!errMsg.contains("authorized", Qt::CaseInsensitive)) { QMessageBox warningBox(QMessageBox::Warning,QObject::tr("Eject failed"),QString(err->message), QMessageBox::Ok); warningBox.exec(); } g_error_free(err); } } void ComputerVolumeItem::stop_async_callback(GDrive *drive, GAsyncResult *res, ComputerVolumeItem *p_this) { GError *err = nullptr; bool successed; successed = g_drive_stop_finish(drive, res, &err); if (!successed) { QMessageBox warningBox(QMessageBox::Warning,QObject::tr("Eject failed"),QString(err->message), QMessageBox::Ok); warningBox.exec(); g_error_free(err); } } void ComputerVolumeItem::onVolumeAdded(const std::shared_ptr volume) { auto g_volume = volume->getGVolume(); auto item = new ComputerVolumeItem(g_volume, m_model, this); } void ComputerVolumeItem::updateBlockIcons() { if (m_volume->iconName() != "drive-harddisk-usb") { m_icon = QIcon::fromTheme(m_volume->iconName()); return; } //用设备容量区分U盘和移动硬盘,大于128GiB为移动硬盘 //FIXME with a better solution, fix bug#57660, #70014 if (m_totalSpace/(1024 * 1024 *1024) > 128) m_icon = QIcon::fromTheme("drive-harddisk-usb"); else m_icon = QIcon::fromTheme("drive-removable-media-usb"); } /* Usage scenarios: * -> open Peony first,then open Gparted. * -> when computer:///xxx.mount or computer:///xxx.volume is generated, * it will query their information from here. */ //comment gparted process code to fix duplicated volume issue, bug#41623 //void ComputerVolumeItem::collectInfoWhenGpartedOpen(QString uri) //{ // GFile *file = NULL; // m_uri = uri; // m_displayName = ""; // m_icon = QIcon(); // m_cancellable = g_cancellable_new(); // m_targetUri = Peony::FileUtils::getTargetUri(m_uri); // file = g_file_new_for_uri(m_targetUri.toUtf8().constData()); // g_file_query_filesystem_info_async(file,"*",0, // m_cancellable, // GAsyncReadyCallback(qeury_info_async_callback),this); // g_object_unref(file); //} /* monitor file generation for computer:///xxx.mount or computer:///xxx.volume */ //void ComputerVolumeItem::onFileAdded(const QString &uri) //{ // QString targetUri = Peony::FileUtils::getTargetUri(uri); // if(!targetUri.contains("file:///") || targetUri.isEmpty()) // return; // for (auto item : m_children) { // qDebug() << "ComputerVolumeItem onFileAdded uri:"<uri(); // if (item->uri() == uri) // return; // } // m_model->beginInsertItem(itemIndex(), m_children.count()); // auto item = new ComputerVolumeItem(uri, m_model, this); // m_children<endInsterItem(); //} //void ComputerVolumeItem::onFileRemoved(const QString &uri) //{ // int row = -1; // for (auto item : m_children) { // qDebug() << "ComputerVolumeItem onFileRemoved uri:"<uri(); // if (item->uri() == uri) { // row = m_children.indexOf(item); // break; // } // } // if (row < 0) // return; // m_model->beginRemoveItem(itemIndex(), row); // auto item = m_children.takeAt(row); // item->deleteLater(); // m_model->endRemoveItem(); //} /* Usage scenarios: * -> open Gparted first,then open Peony. * -> when Gparted is open,it is used to find all partition devices * except the root partition. */ //void ComputerVolumeItem::findChildrenWhenGPartedOpen() //{ // GFile *file; // file = g_file_new_for_uri("computer:///"); // m_tmpCancellable = g_cancellable_new(); // g_file_enumerate_children_async(file, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, // m_tmpCancellable, GAsyncReadyCallback(enumerate_async_callback), this); // //g_object_unref(file); //} //void ComputerVolumeItem::enumerate_async_callback(GFile *file, GAsyncResult *res, ComputerVolumeItem *p_this) //{ // GError *err = nullptr; // auto enumerator = g_file_enumerate_children_finish(file, res, &err); // if (enumerator) { // g_file_enumerator_next_files_async(enumerator, 9999, 0, p_this->m_tmpCancellable, // GAsyncReadyCallback(find_children_async_callback), p_this); // } // if (err) // g_error_free(err); //} //void ComputerVolumeItem::find_children_async_callback(GFileEnumerator *enumerator, GAsyncResult *res, ComputerVolumeItem *p_this) //{ // GError *err = nullptr; // auto infos = g_file_enumerator_next_files_finish(enumerator, res, &err); // GList *l = infos; // while (l) { // auto info = G_FILE_INFO(l->data); // l = l->next; // if (!info) // continue; // auto file = g_file_enumerator_get_child(enumerator, info); // if (!file) // continue; // auto uri = g_file_get_uri(file); // if (!uri) // continue; // //not include ftp://xxx etc. // QString targetUri; // targetUri = Peony::FileUtils::getTargetUri(uri); // if(targetUri.isEmpty()) // continue; // if("file:///" == targetUri) // continue; // if(!targetUri.contains("file:///")) // continue; // p_this->m_model->beginInsertItem(p_this->itemIndex(), p_this->m_children.count()); // auto item = new ComputerVolumeItem(uri, p_this->m_model, p_this); // qDebug() << "find_children_async_callback uri:" <m_children<m_model->endInsterItem(); // g_free(uri); // g_object_unref(file); // } // if (infos) // g_list_free_full(infos, g_object_unref); // if (enumerator) { // g_file_enumerator_close(enumerator, nullptr, nullptr); // g_object_unref(enumerator); // } // if(p_this->m_tmpCancellable){ // g_cancellable_cancel(p_this->m_tmpCancellable); // g_object_unref(p_this->m_tmpCancellable); // } // if (err) { // g_error_free(err); // } //} quint64 calcVolumeCapacity(ComputerVolumeItem* pThis) { char* tmpDevice; GVolume* gVolume; quint64 capacityBytes; QString unixDevice,dbusPath; if(!pThis->m_mount && pThis->m_targetUri.isEmpty()) return 0; if(pThis->m_mount){ if(gVolume = pThis->m_volume->getGVolume()){ tmpDevice = g_volume_get_identifier(gVolume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); if (tmpDevice) { unixDevice = QString(tmpDevice+5); //fix crash issue if (tmpDevice) g_free(tmpDevice); } else { unixDevice = Peony::FileUtils::getUnixDevice(pThis->m_uri); unixDevice = unixDevice.section('/',-1); } } }else{ unixDevice = Peony::FileUtils::getUnixDevice(pThis->m_uri); unixDevice = unixDevice.section('/',-1); } if (unixDevice.isEmpty()) { return 0; } dbusPath = "/org/freedesktop/UDisks2/block_devices/" + unixDevice; QDBusInterface blockInterface("org.freedesktop.UDisks2", dbusPath, "org.freedesktop.UDisks2.Block", QDBusConnection::systemBus()); capacityBytes = 0; if(blockInterface.isValid()) capacityBytes = blockInterface.property("Size").toULongLong(); return capacityBytes; } peony-extensions/peony-extension-computer-view/computer-view/computer-model.cpp0000644000175000017500000001623114205133370027244 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "computer-model.h" #include "abstract-computer-item.h" #include "computer-volume-item.h" #include "computer-remote-volume-item.h" #include "computer-network-item.h" #include "file-info.h" #include "file-utils.h" #include "file-operation-utils.h" #include "file-operation-manager.h" #include #include ComputerModel::ComputerModel(QObject *parent) : QAbstractItemModel(parent) { beginResetModel(); m_parentNode = new AbstractComputerItem(this, nullptr, this); auto computerItem = new ComputerVolumeItem(nullptr, this, m_parentNode); computerItem->findChildren(); auto remoteItem = new ComputerRemoteVolumeItem("computer:///", this, m_parentNode); m_parentNode->m_children<findChildren(); auto networkItem = new ComputerNetworkItem("network:///", this, m_parentNode); m_parentNode->m_children<findChildren(); connect(Peony::FileOperationManager::getInstance(), &Peony::FileOperationManager::operationFinished, this, &ComputerModel::refresh); endResetModel(); } void ComputerModel::beginInsertItem(const QModelIndex &parent, int row) { beginInsertRows(parent, row, row); } void ComputerModel::endInsterItem() { endInsertRows(); } void ComputerModel::beginRemoveItem(const QModelIndex &parent, int row) { beginRemoveRows(parent, row, row); } void ComputerModel::endRemoveItem() { endRemoveRows(); } QModelIndex ComputerModel::createItemIndex(int row, QObject *item) { return createIndex(row, 0, item); } QModelIndex ComputerModel::index(int row, int column, const QModelIndex &parent) const { if (!parent.isValid()) { auto item = m_parentNode->m_children.at(row); return createIndex(row, column, item); } auto parentNode = static_cast(parent.internalPointer()); if (parentNode->m_children.count() < row) return QModelIndex(); return createIndex(row, column, parentNode->m_children.at(row)); } QModelIndex ComputerModel::parent(const QModelIndex &index) const { auto item = static_cast(index.internalPointer()); if (item->m_parentNode) { return item->m_parentNode->itemIndex(); } return QModelIndex(); } int ComputerModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) return m_parentNode->m_children.count(); auto item = static_cast(parent.internalPointer()); return item->m_children.count(); } int ComputerModel::columnCount(const QModelIndex &parent) const { return 1; } QVariant ComputerModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); auto item = static_cast(index.internalPointer()); switch (role) { case Qt::DisplayRole: return item->displayName(); case Qt::DecorationRole: { if (item->m_parentNode == m_parentNode) return QVariant(); return item->icon(); } case Qt::ToolTipRole: return item->displayName(); default: return QVariant(); } } bool ComputerModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (data(index, role) != value) { // FIXME: Implement me! Q_EMIT dataChanged(index, index, QVector() << role); return true; } return false; } Qt::ItemFlags ComputerModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; return QAbstractItemModel::flags(index); // FIXME: Implement me! } bool ComputerModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { if (data->urls().isEmpty()) return false; auto i = index(row, column, parent); if (i.isValid()) { auto item = static_cast(i.internalPointer()); if (!item->uri().isEmpty()) { if (item->canUnmount()) { QStringList sourcesUris; for (auto url : data->urls()) { sourcesUris<uri(), true, action == Qt::CopyAction); connect(operation, &Peony::FileOperation::operationFinished, item, [=](){ if (!operation->hasError()) { Q_EMIT updateLocationRequest(item->uri()); } }); } } } return false; } QString ComputerModel::tryGetVolumeUriFromMountRoot(const QString &mountRootUri) { auto value = m_volumeTargetMap.key(mountRootUri); return value; } QString ComputerModel::tryGetVolumeRealUriFromUri(const QString &uri) { QString realUri = ""; if (uri.isEmpty()) { return realUri; } QList::iterator iter; for(iter = m_volumeRealUri.begin(); iter != m_volumeRealUri.end(); iter++) { realUri = *iter; auto info = Peony::FileInfo::fromUri(realUri); QString targetUri = info->targetUri(); qDebug()<<"real uri"<::iterator iter; for(iter = m_volumeRealUri.begin(); iter != m_volumeRealUri.end(); iter++){ if (*iter == realUri) { return; } } m_volumeRealUri.append(realUri); return; } void ComputerModel::removeRealUri(const QString &realUri) { qDebug()<<"remove volume real uri"<::iterator iter; int index = 0; for(iter = m_volumeRealUri.begin(); iter != m_volumeRealUri.end(); iter++){ if (*iter == realUri) { m_volumeRealUri.removeAt(index); return; } index++; } return; } void ComputerModel::refresh() { for (auto child : m_parentNode->m_children) { for (auto child2 : child->m_children) { if (auto item = qobject_cast(child2)) { item->updateInfo(); } } } } peony-extensions/peony-extension-computer-view/computer-view/computer-network-item.h0000644000175000017500000000432714205101224030232 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERNETWORKITEM_H #define COMPUTERNETWORKITEM_H #include "abstract-computer-item.h" #include #include class ComputerNetworkItem : public AbstractComputerItem { Q_OBJECT public: explicit ComputerNetworkItem(const QString &uri, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent = nullptr); ~ComputerNetworkItem(); Type itemType() override {return Network;} const QString uri() override {return m_uri;} const QString displayName() override; const QIcon icon() override {return m_icon;} void findChildren() override; void updateInfo() override; QModelIndex itemIndex() override; public Q_SLOTS: void reloadDirectory(const QString &uri); void onFileAdded(const QString &uri); void onFileRemoved(const QString &uri); void onFileChanged(const QString &uri); protected: //enumeration static void enumerate_async_callback(GFile *file, GAsyncResult *res, ComputerNetworkItem *p_this); static void find_children_async_callback(GFileEnumerator *enumerator, GAsyncResult *res, ComputerNetworkItem *p_this); //info static void query_info_async_callback(GFile *file, GAsyncResult *res, ComputerNetworkItem *p_this); private: QString m_uri; QString m_displayName; QIcon m_icon; GCancellable *m_cancellable; Peony::FileWatcher *m_watcher = nullptr; }; #endif // COMPUTERNETWORKITEM_H peony-extensions/peony-extension-computer-view/computer-view/computer-personal-item.h0000644000175000017500000000266614205101224030370 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef COMPUTERPERSONALITEM_H #define COMPUTERPERSONALITEM_H #include "abstract-computer-item.h" class ComputerPersonalItem : public AbstractComputerItem { Q_OBJECT public: explicit ComputerPersonalItem(const QString &uri, ComputerModel *model, AbstractComputerItem *parentNode, QObject *parent = nullptr); Type itemType() override {return Personal;} const QString uri() override {return m_uri;} const QString displayName() override; bool hasChildren() override {return !m_parentNode;} void findChildren() override; void clearChildren() override; private: QString m_uri; }; #endif // COMPUTERPERSONALITEM_H peony-extensions/peony-extension-computer-view/login-remote-filesystem.h0000644000175000017500000000234314205101224025722 0ustar fengfeng/* * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef LOGINREMOTEFILESYSTEM_H #define LOGINREMOTEFILESYSTEM_H #include namespace Ui { class LoginRemoteFilesystem; } class LoginRemoteFilesystem : public QDialog { Q_OBJECT public: explicit LoginRemoteFilesystem(QWidget *parent = nullptr); ~LoginRemoteFilesystem(); QString user(); QString password(); QString domain(); QString uri(); private: Ui::LoginRemoteFilesystem *ui; }; #endif // LOGINREMOTEFILESYSTEM_H peony-extensions/peony-set-wallpaper/0000755000175000017500000000000014205101224016724 5ustar fengfengpeony-extensions/peony-set-wallpaper/set-wallpaper-plugin.h0000644000175000017500000000417314205101224023156 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Meihong * */ #ifndef SETWALLPAPERPLUGIN_H #define SETWALLPAPERPLUGIN_H #include "peony-set-wallpaper_global.h" #include #include namespace Peony { class PEONYQTSETWALLPAPERSHARED_EXPORT SetWallPaperPlugin: public QObject, public MenuPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID MenuPluginInterface_iid FILE "common.json") Q_INTERFACES(Peony::MenuPluginInterface) public: explicit SetWallPaperPlugin(QObject *parent = nullptr); PluginInterface::PluginType pluginType() override {return PluginInterface::MenuPlugin;} const QString name() override {return tr("Peony-Qt set wallpaper Extension");} const QString description() override {return tr("set wallpaper Extension.");} const QIcon icon() override {return QIcon::fromTheme("");} void setEnable(bool enable) override {m_enable = enable;} bool isEnable() override {return m_enable;} QString testPlugin() override {return "test set wallpaper";} QList menuActions(Types types, const QString &uri, const QStringList &selectionUris) override; bool is_picture_file(QString file_name); private: bool m_enable; QStringList m_picture_type_list = {"png", "jpg", "jpeg", "bmp", "dib", "jfif", "jpe", "gif", "tif", "tiff", "wdp"}; QGSettings *m_bg_settings = nullptr; }; } #endif // SETWALLPAPERPLUGIN_H peony-extensions/peony-set-wallpaper/peony-set-wallpaper_global.h0000644000175000017500000000214614205101224024330 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Meihong * */ #ifndef PEONYQTSETWALLPAPER_GLOBAL_H #define PEONYQTSETWALLPAPER_GLOBAL_H #include #if defined(PEONYSETWALLPAPER_LIBRARY) # define PEONYQTSETWALLPAPERSHARED_EXPORT Q_DECL_EXPORT #else # define PEONYQTSETWALLPAPERSHARED_EXPORT Q_DECL_IMPORT #endif #endif // PEONYQTSETWALLPAPER_GLOBAL_H peony-extensions/peony-set-wallpaper/peony-set-wallpaper.qrc0000644000175000017500000000031014205101224023335 0ustar fengfeng translations/peony-set-wallpaper-extension_zh_CN.qm translations/peony-set-wallpaper-extension_tr.qm peony-extensions/peony-set-wallpaper/peony-set-wallpaper.pro0000644000175000017500000000257614205101224023370 0ustar fengfeng#------------------------------------------------- # # Project created by QtCreator 2020-06-11T13:45:26 # #------------------------------------------------- QT += widgets TARGET = peony-set-wallpaper TEMPLATE = lib DEFINES += PEONYSETWALLPAPER_LIBRARY include(../common.pri) # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 CONFIG += debug link_pkgconfig plugin PKGCONFIG += peony gsettings-qt TRANSLATIONS = translations/peony-set-wallpaper-extension_zh_CN.ts \ translations/peony-set-wallpaper-extension_tr.ts #DESTDIR += ../testdir SOURCES += \ set-wallpaper-plugin.cpp HEADERS += \ set-wallpaper-plugin.h \ peony-set-wallpaper_global.h unix { target.path = $$[QT_INSTALL_LIBS]/peony-extensions INSTALLS += target } RESOURCES += \ peony-set-wallpaper.qrc peony-extensions/peony-set-wallpaper/set-wallpaper-plugin.cpp0000644000175000017500000000546014205101224023511 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Meihong * */ #include "set-wallpaper-plugin.h" #include #include #include #include #include #include #include #include #include #include #define BACKGROUND_SETTINGS "org.mate.background" #define PICTRUE "picture-filename" using namespace Peony; SetWallPaperPlugin::SetWallPaperPlugin(QObject *parent) : QObject (parent) { QTranslator *t = new QTranslator(this); QString path = ":/translations/peony-set-wallpaper-extension_"+QLocale::system().name(); qDebug()<<"system().name and path:"<load(path); QApplication::installTranslator(t); } QList SetWallPaperPlugin::menuActions(Types types, const QString &uri, const QStringList &selectionUris) { QList actions; if (types == MenuPluginInterface::DirectoryView || types == MenuPluginInterface::DesktopWindow) { if (selectionUris.count() == 1 && is_picture_file(selectionUris.first())) { if (selectionUris.first().contains("trash:///")) return actions; QAction *set_action = new QAction(tr("Set as wallpaper"), nullptr); actions<trySet("pictureFilename", url.path()); qDebug() << "set as wallpaper result:" < Peony::SetWallPaperPlugin Peony-Qt set wallpaper Extension Peony-Qt duvar kağıdı ayarlama eklentisi set wallpaper Extension. Duvarkağıdı eklentisi ayarla. Set as wallpaper Duvar kağıdı olarak ayarla peony-extensions/peony-set-wallpaper/translations/peony-set-wallpaper-extension_tr.qm0000644000175000017500000000070214205101224030432 0ustar fengfeng Peony::SetWallPaperPlugin Peony-Qt set wallpaper Extension 文件管理器设置壁纸插件 set wallpaper Extension. 设置壁纸插件。 Set as wallpaper 设为壁纸 peony-extensions/peony-set-wallpaper/translations/peony-set-wallpaper-extension_zh_CN.qm0000644000175000017500000000046014205101224031007 0ustar fengfeng. * * Authors: Meihong * */ #ifndef PEONYQTENGRAMPAMENUPLUGIN_GLOBAL_H #define PEONYQTENGRAMPAMENUPLUGIN_GLOBAL_H #include #if defined(PEONYENGRAMPAMENUPLUGIN_LIBRARY) # define PEONYQTENGRAMPAMENUPLUGINSHARED_EXPORT Q_DECL_EXPORT #else # define PEONYQTENGRAMPAMENUPLUGINSHARED_EXPORT Q_DECL_IMPORT #endif #endif // PEONYQTENGRAMPAMENUPLUGIN_GLOBAL_H peony-extensions/peony-engrampa-menu-plugin/engrampa-menu-plugin.h0000644000175000017500000000441214205101224024376 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Meihong * */ #ifndef ENGRAMPAMENUPLUGIN_H #define ENGRAMPAMENUPLUGIN_H #include "peony-engrampa-menu-plugin_global.h" #include namespace Peony { class PEONYQTENGRAMPAMENUPLUGINSHARED_EXPORT EngrampaMenuPlugin: public QObject, public MenuPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID MenuPluginInterface_iid FILE "common.json") Q_INTERFACES(Peony::MenuPluginInterface) public: explicit EngrampaMenuPlugin(QObject *parent = nullptr); PluginInterface::PluginType pluginType() override {return PluginInterface::MenuPlugin;} const QString name() override {return tr("Peony-Qt engrampa Extension");} const QString description() override {return tr("engrampa Menu Extension.");} const QIcon icon() override {return QIcon::fromTheme("application-zip");} void setEnable(bool enable) override {m_enable = enable;} bool isEnable() override {return m_enable;} QString testPlugin() override {return "test compress";} QList menuActions(Types types, const QString &uri, const QStringList &selectionUris) override; bool is_compressed_file(QString file_name); private: bool m_enable; QStringList m_file_type_list = {"7z","ar","bz","bz2","cbz","deb", "ear","exe","gz","jar","tar","tar.7z", "tar.bz2","tar.gz","tar.lzma","rar","tar.xz","war","zip","lzma","xz","tgz", "odp", "ods", "otp", "ott", "ots", "odt", "iso"}; }; } #endif // ENGRAMPAMENUPLUGIN_H peony-extensions/peony-engrampa-menu-plugin/engrampa-menu-plugin.cpp0000644000175000017500000001063014205133370024737 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Meihong * */ #include "engrampa-menu-plugin.h" #include #include #include #include #include #include #include #include #include using namespace Peony; EngrampaMenuPlugin::EngrampaMenuPlugin(QObject *parent) : QObject (parent) { QTranslator *t = new QTranslator(this); qDebug()<<"system().name:"<load(":/translations/peony-engrampa-menu_"+QLocale::system().name()); QApplication::installTranslator(t); } QList EngrampaMenuPlugin::menuActions(Types types, const QString &uri, const QStringList &selectionUris) { QList actions; if (types == MenuPluginInterface::DirectoryView || types == MenuPluginInterface::DesktopWindow) { if (! selectionUris.isEmpty()) { auto info = FileInfo::fromUri(selectionUris.first()); //special type mountable, return qDebug()<<"info isVirtual:"<isVirtual()<mimeType(); if (selectionUris.first().startsWith("computer:///") || selectionUris.first().startsWith("trash:///") || selectionUris.first().startsWith("recent:///") || selectionUris.first().startsWith("filesafe:///") || info->isVirtual()) return actions; QFileInfo file(selectionUris.first()); QAction *compress = new QAction(QIcon::fromTheme("application-zip"), tr("compress..."), nullptr); actions< translations/peony-engrampa-menu_zh_CN.qm translations/peony-engrampa-menu_tr.qm translations/peony-engrampa-menu_cs.qm peony-extensions/peony-engrampa-menu-plugin/translations/0000755000175000017500000000000014205133370022724 5ustar fengfengpeony-extensions/peony-engrampa-menu-plugin/translations/peony-engrampa-menu_zh_CN.qm0000644000175000017500000000073014205101224030221 0ustar fengfengFNiS)cNPeony-Qt engrampa ExtensionPeony::EngrampaMenuPlugin S)... compress...Peony::EngrampaMenuPlugin_RhcSUbi\U0engrampa Menu Extension.Peony::EngrampaMenuPlugin S)R0kdYuncompress to current pathPeony::EngrampaMenuPluginS)R0...uncompress to specific path...Peony::EngrampaMenuPluginpeony-extensions/peony-engrampa-menu-plugin/translations/peony-engrampa-menu_tr.ts0000644000175000017500000000315714205133370027673 0ustar fengfeng Peony::EngrampaMenuPlugin compress... Arşivle... uncompress to current path Buraya ayıkla uncompress to specific path... Arşivle... uncompress to specific path Buraya ayıkla... Peony-Qt KArchive Menu Extension Peony-Qt KArchive Menü Uzantısı. KArchive Menu Extension. KArchive Menü Uzantısı. Peony-Qt engrampa Extension Peony-Qt engrampa Menü Uzantısı engrampa Menu Extension. Engrampa Menü Uzantısı peony-extensions/peony-engrampa-menu-plugin/translations/peony-engrampa-menu_zh_CN.ts0000644000175000017500000000310614205133370030241 0ustar fengfeng Peony::EngrampaMenuPlugin compress... 压缩... uncompress to current path 解压缩到此处 uncompress to specific path... 解压缩到... uncompress to specific path 解压缩到... Peony-Qt KArchive Menu Extension 文件压缩插件 KArchive Menu Extension. 压缩菜单扩展。 Peony-Qt engrampa Extension 压缩插件 engrampa Menu Extension. 归档菜单扩展。 peony-extensions/peony-engrampa-menu-plugin/translations/peony-engrampa-menu_tr.qm0000644000175000017500000000111214205101224027640 0ustar fengfengFNi>Peony-Qt engrampa Men Uzant1s1Peony-Qt engrampa ExtensionPeony::EngrampaMenuPluginAr_ivle... compress...Peony::EngrampaMenuPlugin,Engrampa Men Uzant1s1engrampa Menu Extension.Peony::EngrampaMenuPluginBuraya ay1klauncompress to current pathPeony::EngrampaMenuPluginAr_ivle...uncompress to specific path...Peony::EngrampaMenuPluginpeony-extensions/peony-engrampa-menu-plugin/translations/peony-engrampa-menu_cs.ts0000644000175000017500000000333014205133370027644 0ustar fengfeng Peony::EngrampaMenuPlugin compress... zkomprimovat… uncompress to current path rozbalit do stávajícího umístění uncompress to specific path... rozbalit do zadaného umístění… uncompress to specific path rozbalit do zadaného umístění Peony-Qt KArchive Menu Extension Rozšíření do Peony-Qt pro nabídku KArchive. KArchive Menu Extension. Rozšíření s nabídkou KArchive. Peony-Qt engrampa Extension Rozšíření do Peony-Qt pro engrampa engrampa Menu Extension. Rozšíření s nabídkou engrampa. peony-extensions/peony-engrampa-menu-plugin/translations/peony-engrampa-menu_cs.qm0000644000175000017500000000127714205101224027634 0ustar fengfengFNirDRozaYen do Peony-Qt pro engrampaPeony-Qt engrampa ExtensionPeony::EngrampaMenuPluginzkomprimovat & compress...Peony::EngrampaMenuPlugin<RozaYen s nabdkou engrampa.engrampa Menu Extension.Peony::EngrampaMenuPlugin@rozbalit do stvajcho umstnuncompress to current pathPeony::EngrampaMenuPlugin<rozbalit do zadanho umstn &uncompress to specific path...Peony::EngrampaMenuPluginpeony-extensions/peony-share/0000755000175000017500000000000014205133370015255 5ustar fengfengpeony-extensions/peony-share/share-page.h0000644000175000017500000000450214205133370017443 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef SHAREPAGE_H #define SHAREPAGE_H #include #include #include #include #include #include #include #include #include #include #include //#include "libpeony-qt/usershare-manager.h" using namespace Peony; class SharePage : public Peony::PropertiesWindowTabIface { Q_OBJECT public: explicit SharePage(const QString &uri, QWidget *parent = nullptr); void addSeparate() { QFrame * separate = new QFrame(this); separate->setFrameShape(QFrame::HLine); m_layout->addWidget(separate); } void init(); void initFloorOne(); void initFloorTwo(); void initFloorThree(); /*! * 响应确定按钮 * \brief */ void saveAllChange() override; private: QFutureWatcher *m_theFutureWatcher = nullptr; Peony::ShareInfo m_shareInfo; QVBoxLayout* m_layout = nullptr; std::shared_ptr m_fileInfo = nullptr; //floor1 QPushButton *m_iconButton = nullptr; QLabel *m_folderName = nullptr; QLabel *m_sharedState = nullptr; //floor2 QCheckBox *m_shareCheckBox = nullptr; //floor3 QFrame *m_floor3 = nullptr; QLineEdit *m_shareNameEdit = nullptr; QLineEdit *m_commentEdit = nullptr; QCheckBox *m_shareReadOnlyCheckBox = nullptr; QCheckBox *m_shareAllowGuestCheckBox = nullptr; }; #endif // SHAREPAGE_H peony-extensions/peony-share/peony-share.pro0000644000175000017500000000151614205133370020234 0ustar fengfengQT += core gui widgets concurrent TARGET = peony-share TEMPLATE = lib DEFINES += PEONYSHARE_LIBRARY include(../common.pri) PKGCONFIG += peony CONFIG += link_pkgconfig \ c++11 \ plugin \ debug #DESTDIR += ../testdir SOURCES += share-page.cpp \ share-properties-page-plugin.cpp HEADERS += share-page.h \ share-properties-page-plugin.h TRANSLATIONS += translations/peony-share-extension_cs.ts \ translations/peony-share-extension_tr.ts \ translations/peony-share-extension_zh_CN.ts RESOURCES += resources.qrc target.path = $$[QT_INSTALL_LIBS]/peony-extensions polkit1.files = $$PWD/org.freedesktop.peony-share.policy polkit1.path = /usr/share/polkit-1/actions/ polkitbin.files = $$PWD/peony-share polkitbin.path = /usr/share/peony-extensions/ INSTALLS += target polkit1 polkitbin peony-extensions/peony-share/resources.qrc0000644000175000017500000000036614205101224017774 0ustar fengfeng translations/peony-share-extension_zh_CN.qm translations/peony-share-extension_tr.qm translations/peony-share-extension_cs.qm peony-extensions/peony-share/org.freedesktop.peony-share.policy0000644000175000017500000000232514205133370024032 0ustar fengfeng Peony share https://github.com/ukui/peony-extensions Peony Share peony 文件共享 Authentication Peony share peony share 身份验证 system-file-manager yes yes yes /usr/share/peony-extensions/peony-share true peony-extensions/peony-share/share-properties-page-plugin.cpp0000644000175000017500000000546014205101224023461 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * Authors: Meihong * */ #include "share-properties-page-plugin.h" #include "share-page.h" #include #include #include #include #include #include #include using namespace Peony; SharePropertiesPagePlugin *global_instance = nullptr; SharePropertiesPagePlugin *SharePropertiesPagePlugin::getInstance() { return global_instance; } SharePropertiesPagePlugin::SharePropertiesPagePlugin(QObject *parent) : QObject(parent) { qDebug()<<"init"; QTranslator *t = new QTranslator(this); qDebug()<<"\n\n\n\n\n\n\n SharePropertiesPagePlugin translate:"<load(":/translations/peony-share-extension_"+QLocale::system().name()); QFile file(":/translations/peony-share-extension_"+QLocale::system().name()+".ts"); qDebug()<<"file:"<displayName().isNull()) { FileInfoJob j(info); j.querySync(); } if (!info->isDir() || info->isVirtual() || !info->uri().startsWith("file:///")) { return false; } // don't share user's home directory file:///home/xxx/ QStringList file = info->uri().split('/', QString::SkipEmptyParts); if ((3 == file.size ()) && (file.at(1) == "home")) { return false; } // don't share directory that has no permission if (!info->canRead() || !info->canWrite() || !info->canExecute()) { return false; } return true; } PropertiesWindowTabIface * SharePropertiesPagePlugin::createTabPage(const QStringList &uris) { return new SharePage(uris.first()); } peony-extensions/peony-share/share-properties-page-plugin.h0000644000175000017500000000410214205101224023116 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #ifndef SHAREMENUPLUGIN_H #define SHAREMENUPLUGIN_H #include #include #include "usershare-manager.h" namespace Peony { class SharePropertiesPagePlugin : public QObject, public PropertiesWindowTabPagePluginIface { Q_OBJECT Q_PLUGIN_METADATA(IID PropertiesWindowTabPagePluginIface_iid FILE "common.json") Q_INTERFACES(Peony::PropertiesWindowTabPagePluginIface) public: explicit SharePropertiesPagePlugin(QObject *parent = nullptr); static SharePropertiesPagePlugin *getInstance(); PluginInterface::PluginType pluginType() override {return PluginInterface::PropertiesWindowPlugin;} const QString name() override {return tr("Peony Qt Share Extension");} const QString description() override {return tr("Allow user share folders");} const QIcon icon() override {return QIcon::fromTheme("emblem-shared");} void setEnable(bool enable) override {m_enable = enable;} bool isEnable() override {return m_enable;} int tabOrder() override {return 99;} bool supportUris(const QStringList &uris) override; PropertiesWindowTabIface * createTabPage(const QStringList &uris) override; void closeFactory() {deleteLater();} private: bool m_enable; }; } #endif // SHAREMENUPLUGIN_H peony-extensions/peony-share/share-page.cpp0000644000175000017500000001571014205133370020001 0ustar fengfeng/* * Peony-Qt's Library * * Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library. If not, see . * * Authors: Yue Lan * */ #include "share-page.h" #include "share-properties-page-plugin.h" #include #include #include #include #include #include #include #include #include #include SharePage::SharePage(const QString &uri, QWidget *parent) : PropertiesWindowTabIface(parent) { QFuture initFileInfoJob = QtConcurrent::run([=]() { m_fileInfo = Peony::FileInfo::fromUri(uri); Peony::FileInfoJob *fileInfoJob = new Peony::FileInfoJob(m_fileInfo); fileInfoJob->setAutoDelete(true); fileInfoJob->querySync(); }); m_theFutureWatcher = new QFutureWatcher(); m_theFutureWatcher->setFuture(initFileInfoJob); connect(m_theFutureWatcher, &QFutureWatcher::finished, this, &SharePage::init); } void SharePage::init() { if (m_theFutureWatcher) delete m_theFutureWatcher; m_shareInfo.name = m_fileInfo->displayName(); m_shareInfo.originalPath = m_fileInfo->filePath(); const ShareInfo* stmp = UserShareInfoManager::getInstance()->getShareInfo(m_shareInfo.name); if (nullptr != stmp) { m_shareInfo = stmp; m_shareInfo.isShared = true; } m_layout = new QVBoxLayout(this); m_layout->setMargin(0); this->initFloorOne(); this->addSeparate(); this->initFloorTwo(); this->initFloorThree(); m_layout->addStretch(1); } void SharePage::saveAllChange() { if (!m_thisPageChanged) return; bool checked = m_shareCheckBox->isChecked(); if (checked) { //FIXME:暂时不支持自定义共享名 - Currently does not support custom shared name m_shareInfo.name = m_fileInfo->displayName(); m_shareInfo.readOnly = m_shareReadOnlyCheckBox->isChecked(); m_shareInfo.allowGuest = m_shareAllowGuestCheckBox->isChecked(); m_shareInfo.isShared = true; UserShareInfoManager::getInstance()->updateShareInfo(m_shareInfo); } else { //FIXME:需要先判断存在共享吗 - Need to determine whether there is sharing first UserShareInfoManager::getInstance()->removeShareInfo(m_shareInfo.name); } } void SharePage::initFloorOne() { QFrame * floor1 = new QFrame(this); floor1->setMinimumHeight(90); QHBoxLayout * layout1 = new QHBoxLayout(floor1); layout1->setContentsMargins(22, 14, 22, 0); layout1->setAlignment(Qt::AlignTop | Qt::AlignLeft); floor1->setLayout(layout1); m_iconButton = new QPushButton(floor1); m_iconButton->setIcon(QIcon::fromTheme(m_fileInfo.get()->iconName())); m_iconButton->setFixedSize(QSize(60,60)); m_iconButton->setIconSize(QSize(48, 48)); layout1->addWidget(m_iconButton); QVBoxLayout * vBoxLayout = new QVBoxLayout(floor1); m_folderName = new QLabel(floor1); m_sharedState = new QLabel(floor1); m_folderName->setText(m_fileInfo.get()->displayName()); m_sharedState->setText(m_shareInfo.isShared ? tr("share this folder") : tr("don`t share this folder")); vBoxLayout->addStretch(1); vBoxLayout->addWidget(m_folderName); vBoxLayout->addWidget(m_sharedState); vBoxLayout->addStretch(1); layout1->addLayout(vBoxLayout); layout1->addStretch(1); m_layout->addWidget(floor1); } void SharePage::initFloorTwo() { QFrame * floor2 = new QFrame(this); floor2->setMinimumHeight(64); QVBoxLayout * layout2 = new QVBoxLayout(floor2); layout2->setContentsMargins(22, 0, 22, 0); floor2->setLayout(layout2); bool shared = m_shareInfo.isShared; m_shareCheckBox = new QCheckBox(tr("Share folder"), floor2); m_shareCheckBox->setChecked(shared); layout2->addWidget(m_shareCheckBox); m_layout->addWidget(floor2); connect(m_shareCheckBox, &QCheckBox::clicked, this, [=](bool checked) { this->thisPageChanged(); if (checked) { //FIXME:暂时不支持自定义共享名 - Currently does not support custom shared name m_shareInfo.name = m_fileInfo->displayName(); m_shareInfo.readOnly = m_shareReadOnlyCheckBox->isChecked(); m_shareInfo.allowGuest = m_shareAllowGuestCheckBox->isChecked(); if (m_floor3) m_floor3->setVisible(true); m_sharedState->setText(tr("share this folder")); m_shareInfo.isShared = true; } else { if (m_floor3) m_floor3->setVisible(false); m_sharedState->setText(tr("don`t share this folder")); m_shareInfo.isShared = false; } }); } void SharePage::initFloorThree() { m_floor3 = new QFrame(this); QVBoxLayout * layout3 = new QVBoxLayout(m_floor3); layout3->setContentsMargins(22, 0, 22, 0); m_floor3->setLayout(layout3); QFormLayout *formLayout = new QFormLayout(m_floor3); m_shareNameEdit = new QLineEdit(m_floor3); m_shareNameEdit->setMaxLength(32); m_shareNameEdit->setEnabled(false); m_shareNameEdit->setText(m_shareInfo.name); m_commentEdit = new QLineEdit(m_floor3); m_commentEdit->setMaxLength(64); m_commentEdit->setText(m_shareInfo.comment); formLayout->addRow(tr("Share name:"), m_shareNameEdit); formLayout->addRow(tr("Comment:"), m_commentEdit); layout3->addLayout(formLayout); m_shareReadOnlyCheckBox = new QCheckBox(tr("Read Only"), this); m_shareReadOnlyCheckBox->setChecked(m_shareInfo.readOnly); m_shareAllowGuestCheckBox = new QCheckBox(tr("Allow Anonymous")); m_shareAllowGuestCheckBox->setChecked(m_shareInfo.allowGuest); layout3->addWidget(m_shareReadOnlyCheckBox); layout3->addWidget(m_shareAllowGuestCheckBox); m_floor3->setVisible(m_shareInfo.isShared); m_layout->addWidget(m_floor3); connect(m_commentEdit, &QLineEdit::textChanged, this, [=]() { m_shareInfo.comment = m_commentEdit->text(); this->thisPageChanged(); }); connect(m_shareReadOnlyCheckBox, &QCheckBox::clicked, this, [=](bool checked) { m_shareInfo.readOnly = checked; this->thisPageChanged(); }); connect(m_shareAllowGuestCheckBox, &QCheckBox::clicked, this, [=](bool checked) { m_shareInfo.allowGuest = checked; this->thisPageChanged(); }); } peony-extensions/peony-share/translations/0000755000175000017500000000000014205133370017776 5ustar fengfengpeony-extensions/peony-share/translations/peony-share-extension_tr.qm0000644000175000017500000000126214205133305025305 0ustar fengfeng NetUsershareHelper Peony-Qt-Share-Extension Peony-Qt-Share-Extension Peony::SharePropertiesPagePlugin Peony Qt Share Extension Rozšíření do Peony Qt pro správu sdílení Allow user share folders Umožnit uživateli sdílet složku SharePage Share folder Sdílet složku Share: Zdroj: share this folder don`t share this folder Share name: Read Only Pouze pro čtení Allow Anonymous Umožnit anonymní Comment: Komentář: peony-extensions/peony-share/translations/peony-share-extension_zh_CN.qm0000644000175000017500000000175314205133370025670 0ustar fengfengUmo~nit u~ivateli sdlet slo~kuAllow user share folders Peony::SharePropertiesPagePluginPRozaYen do Peony Qt pro sprvu sdlenPeony Qt Share Extension Peony::SharePropertiesPagePlugin Umo~nit anonymnAllow Anonymous SharePageKomentY:Comment: SharePagePouze pro  ten Read Only SharePageSdlet slo~ku Share folder SharePage Zdroj:Share: SharePagepeony-extensions/peony-share/translations/peony-share-extension_zh_CN.ts0000644000175000017500000000440014205133370025671 0ustar fengfeng NetUsershareHelper Peony-Qt-Share-Extension 共享 Peony::SharePropertiesPagePlugin Peony Qt Share Extension 共享 Allow user share folders 允许共享文件夹 SharePage Share folder 共享文件夹 Share: 共享: share this folder 共享此文件夹 don`t share this folder 不共享此文件夹 Share name: 共享名: Read Only 只读 Allow Anonymous 允许游客访问 Comment: 注释: peony-extensions/peony-share/translations/peony-share-extension_tr.ts0000644000175000017500000000451214205133370025321 0ustar fengfeng NetUsershareHelper Peony-Qt-Share-Extension Peony-Qt-Share-Eklentisi Peony::SharePropertiesPagePlugin Peony Qt Share Extension Peony Qt Share Eklentisi Allow user share folders Kullanıcı paylaşım klasörlerine izin ver SharePage Share folder Klasör paylaş Share: Paylaş: share this folder don`t share this folder Share name: Read Only Sadece Okunabilir Allow Anonymous Herkese İzin Ver Comment: Yorum yap: peony-extensions/peony-share/peony-share0000755000175000017500000000052214205133370017434 0ustar fengfeng#!/bin/bash if [ "$#" -ge 1 ]; then if [[ $(groups $1 | grep "sambashare") == "" ]]; then usermod -a -G sambashare "$1" fi fi if [ "$#" -ge 2 ]; then if [[ $(echo "$2" | grep "/home/$1") != "" ]]; then umsk=$(umask) set umask 0 chmod o+x "/home/$1" set umask umsk fi fi peony-extensions/README.md0000644000175000017500000000434514205101224014301 0ustar fengfeng# peony-extensions ## Getting Start - Make sure all build dependencies have been installed in your machine. You can reference debian/control for building depends. * Create *build* directory and change to it, then build with cmake. The follow commands will auto build extensions as library. ``` sh #cmake .. qmake .. make ``` - Put the generated libraries into &&[QT_INSTALL_LIBS]/peony-extensions. - Test the extension with peony. ## Current extensions - **terminal**, open terminal with right click menu. - **shared**, a share properties page in properties window. - ~~**admin**, open a directory or a file as root with menu.~~ - **parchives**, compress/uncompress files with menu. - **computer view**, a special view for displaying computer:///. - **send-to-device**, provides a directory menu action for sending selected files to mounted device. - **bluetooth**, provides a directory menu action for sneding selected files by bluetooth, depending on ukui-bluetooth. - **set-wallparper**, privides a directory menu action for set desktop background. ## binary compatibility Peony-Extensions strongly relies on Peony library, that means the binary files of those plugins might not compat with Peony when the library updated and some API changed. Sometimes the old plugins will not be loaded, or will make Peony crashed due to call an unmatch method. To avoid the binary compatibility problems, we add a version checkment in latest version both in this project and Peony. The plugins' version infomation are loaded from [common.json](common.json), this must match to the Peony VERSION marco. When peony extensions doesn't work or can't be build correctly, please consider using latest Peony library built locally, and rebuild this project again. ## Translations Unlike Peony, Peony Extensions translations job is relatively primitive and crude. The main idea is every plugin translates itself, and compile translations resources with code (qrc). When you are going to translate peony extensions (I created), here are the mainly steps. - use lupdate to generate .ts file for your language, the naming rules reference existing files. - use lrelease to publish .ts file to .qm file. - modify the project's .qrc file, add your .qm file into recources to be compiled. peony-extensions/.gitattributes0000644000175000017500000000012514205101224015705 0ustar fengfengdebian/changelog merge=ours debian/compat merge=ours debian/source/format merge=ours peony-extensions/common.pri0000644000175000017500000000006414205133370015027 0ustar fengfengINCLUDEPATH += $$PWD DISTFILES += $$PWD/common.json