From d7aa34cc6c8b34fafae74f45e67dc7838c3e483a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 22 Oct 2013 11:20:42 +0200 Subject: [PATCH] implement uninstall() --- src/plasma/package.cpp | 2 + src/shell/widgetexplorer/widgetexplorer.cpp | 90 +++------------------ src/shell/widgetexplorer/widgetexplorer.h | 10 +-- 3 files changed, 18 insertions(+), 84 deletions(-) diff --git a/src/plasma/package.cpp b/src/plasma/package.cpp index 405053693..532382669 100644 --- a/src/plasma/package.cpp +++ b/src/plasma/package.cpp @@ -709,6 +709,8 @@ KJob* Package::install(const QString &sourcePackage, const QString &packageRoot) KJob* Package::uninstall(const QString &packageName, const QString &packageRoot) { + //FIXME:packageName unused, name taken from metadata().pluginName() ? + //can this become either just uninstall() otherwise maintain parameters and be static? const QString pname = metadata().pluginName(); diff --git a/src/shell/widgetexplorer/widgetexplorer.cpp b/src/shell/widgetexplorer/widgetexplorer.cpp index 767db4f9e..17a8c7a76 100644 --- a/src/shell/widgetexplorer/widgetexplorer.cpp +++ b/src/shell/widgetexplorer/widgetexplorer.cpp @@ -66,7 +66,6 @@ public: } void initFilters(); - void init(Plasma::Types::Location loc); void initRunningApplets(); void containmentDestroyed(); void setLocation(Plasma::Types::Location loc); @@ -149,47 +148,6 @@ void WidgetExplorerPrivate::initFilters() } -void WidgetExplorerPrivate::init(Plasma::Types::Location loc) -{ -// q->setFocusPolicy(Qt::StrongFocus); - - //init widgets - location = loc; - orientation = ((location == Plasma::Types::LeftEdge || location == Plasma::Types::RightEdge)?Qt::Vertical:Qt::Horizontal); -// mainLayout = new QGraphicsLinearLayout(Qt::Vertical); -// mainLayout->setContentsMargins(0, 0, 0, 0); -// mainLayout->setSpacing(0); - - //connect - //QObject::connect(filteringWidget, SIGNAL(closeClicked()), q, SIGNAL(closeClicked())); - - initRunningApplets(); - - filterItemModel.setSortCaseSensitivity(Qt::CaseInsensitive); - filterItemModel.setDynamicSortFilter(true); - filterItemModel.setSourceModel(&itemModel); - filterItemModel.sort(0); -// Plasma::PackageStructure::Ptr structure = Plasma::PackageStructure::load("Plasma/Generic"); -// package = new Plasma::Package(QString(), "org.kde.desktop.widgetexplorer", structure); -// -// declarativeWidget = new Plasma::DeclarativeWidget(q); -// declarativeWidget->setInitializationDelayed(true); -// declarativeWidget->setQmlPath(package->filePath("mainscript")); -// mainLayout->addItem(declarativeWidget); -// -// if (declarativeWidget->engine()) { -// QDeclarativeContext *ctxt = declarativeWidget->engine()->rootContext(); -// if (ctxt) { -// filterItemModel.setSortCaseSensitivity(Qt::CaseInsensitive); -// filterItemModel.setDynamicSortFilter(true); -// filterItemModel.setSourceModel(&itemModel); -// filterItemModel.sort(0); -// ctxt->setContextProperty("widgetExplorer", q); -// } -// } -// -// q->setLayout(mainLayout); -} void WidgetExplorerPrivate::setLocation(const Plasma::Types::Location loc) { @@ -344,20 +302,17 @@ void WidgetExplorerPrivate::appletRemoved(Plasma::Applet *applet) //WidgetExplorer -WidgetExplorer::WidgetExplorer(Plasma::Types::Location loc, QObject *parent) - :QObject(parent), - d(new WidgetExplorerPrivate(this)) -{ - d->init(loc); - populateWidgetList(); -} - WidgetExplorer::WidgetExplorer(QObject *parent) :QObject(parent), d(new WidgetExplorerPrivate(this)) { - d->init(Plasma::Types::LeftEdge); + setLocation(Plasma::Types::LeftEdge); populateWidgetList(); + d->initRunningApplets(); + d->filterItemModel.setSortCaseSensitivity(Qt::CaseInsensitive); + d->filterItemModel.setDynamicSortFilter(true); + d->filterItemModel.setSourceModel(&d->itemModel); + d->filterItemModel.sort(0); } WidgetExplorer::~WidgetExplorer() @@ -475,27 +430,7 @@ void WidgetExplorer::immutabilityChanged(Plasma::Types::ImmutabilityType type) } } -bool WidgetExplorer::event(QEvent *event) -{ - switch (event->type()) { - case QEvent::ActionAdded: - case QEvent::ActionChanged: - case QEvent::ActionRemoved: - //if (d->declarativeWidget->rootObject()) { - emit widgetsMenuActionsChanged(); - //} - break; - default: - break; - } - return QObject::event(event); -} - -void WidgetExplorer::focusInEvent(QFocusEvent* event) -{ - Q_UNUSED(event); -} void WidgetExplorer::downloadWidgets(const QString &type) { @@ -523,7 +458,6 @@ void WidgetExplorer::downloadWidgets(const QString &type) } } - emit closeClicked(); if (installer) { //installer->createNewWidgetBrowser(); } else { @@ -543,11 +477,11 @@ void WidgetExplorer::downloadWidgets(const QString &type) knsDialog->raise(); */ } + close(); } void WidgetExplorer::openWidgetFile() { - emit closeClicked(); /* Plasma::OpenWidgetAssistant *assistant = d->openAssistant.data(); if (!assistant) { @@ -561,14 +495,16 @@ void WidgetExplorer::openWidgetFile() assistant->raise(); assistant->setFocus(); */ + close(); } void WidgetExplorer::uninstall(const QString &pluginName) { - Plasma::PackageStructure installer; - qWarning() << "FIXME: uninstall needs reimplementation"; - //installer.uninstallPackage(pluginName, - // QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "plasma/plasmoids/"); + const QString packageRoot = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/plasma/plasmoids/"; + + Plasma::Package pkg; + pkg.setPath(packageRoot); + pkg.uninstall(pluginName, packageRoot); //FIXME: moreefficient way rather a linear scan? for (int i = 0; i < d->itemModel.rowCount(); ++i) { diff --git a/src/shell/widgetexplorer/widgetexplorer.h b/src/shell/widgetexplorer/widgetexplorer.h index 7b4b7aec0..47e80de84 100644 --- a/src/shell/widgetexplorer/widgetexplorer.h +++ b/src/shell/widgetexplorer/widgetexplorer.h @@ -102,7 +102,6 @@ public: RightEdge /**< Along the right side of the screen */ }; - explicit WidgetExplorer(Plasma::Types::Location loc, QObject *parent = 0); explicit WidgetExplorer(QObject *parent = 0); ~WidgetExplorer(); @@ -159,6 +158,9 @@ public: QList widgetsMenuActions(); QList extraActions() const; + /** + * Uninstall a plasmoid with a given plugin name. only user-installed ones are uninstallable + */ Q_INVOKABLE void uninstall(const QString &pluginName); Q_INVOKABLE void close(); @@ -167,7 +169,6 @@ public: Q_SIGNALS: void locationChanged(Plasma::Types::Location loc); void orientationChanged(); - void closeClicked(); void widgetsMenuActionsChanged(); void extraActionsChanged(); @@ -182,11 +183,6 @@ public Q_SLOTS: protected Q_SLOTS: void immutabilityChanged(Plasma::Types::ImmutabilityType); -protected: - void keyPressEvent(QKeyEvent *e); - bool event(QEvent *e); - void focusInEvent(QFocusEvent * event); - private: Q_PRIVATE_SLOT(d, void appletAdded(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void appletRemoved(Plasma::Applet*))