mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
plasma: use KonqOperations::emptyTrash() to empty the trashcan
folderview applet also uses it Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
667f189b3c
commit
11d9c173dc
3 changed files with 73 additions and 114 deletions
|
@ -1,10 +1,28 @@
|
||||||
project(plasma-applet-trash)
|
project(plasma-applet-trash)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${CMAKE_SOURCE_DIR}/libs/konq
|
||||||
|
${CMAKE_BINARY_DIR}/libs/konq
|
||||||
|
)
|
||||||
|
|
||||||
set(trash_SRCS
|
set(trash_SRCS
|
||||||
trash.cpp)
|
trash.cpp
|
||||||
|
)
|
||||||
|
|
||||||
kde4_add_plugin(plasma_applet_trash ${trash_SRCS})
|
kde4_add_plugin(plasma_applet_trash ${trash_SRCS})
|
||||||
target_link_libraries(plasma_applet_trash KDE4::plasma KDE4::solid KDE4::kio KDE4::kcmutils)
|
target_link_libraries(plasma_applet_trash
|
||||||
|
KDE4::plasma
|
||||||
|
KDE4::solid
|
||||||
|
KDE4::kio
|
||||||
|
KDE4::kcmutils
|
||||||
|
konq
|
||||||
|
)
|
||||||
|
|
||||||
install(TARGETS plasma_applet_trash DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
install(
|
||||||
install(FILES plasma-applet-trash.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})
|
TARGETS plasma_applet_trash
|
||||||
|
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
FILES plasma-applet-trash.desktop
|
||||||
|
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
#include "trash.h"
|
#include "trash.h"
|
||||||
|
|
||||||
//QT
|
// Katie
|
||||||
#include <QtGui/qgraphicssceneevent.h>
|
#include <QGraphicsSceneDragDropEvent>
|
||||||
#include <QGraphicsLinearLayout>
|
#include <QGraphicsLinearLayout>
|
||||||
|
|
||||||
//KDE
|
// KDE
|
||||||
#include <KCModuleProxy>
|
#include <KCModuleProxy>
|
||||||
#include <KConfigDialog>
|
#include <KConfigDialog>
|
||||||
#include <KDebug>
|
#include <KDebug>
|
||||||
|
@ -33,20 +33,16 @@
|
||||||
#include <KMessageBox>
|
#include <KMessageBox>
|
||||||
#include <KLocale>
|
#include <KLocale>
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
#include <QProcess>
|
|
||||||
#include <KToolInvocation>
|
#include <KToolInvocation>
|
||||||
#include <KSharedConfig>
|
#include <KSharedConfig>
|
||||||
#include <KStandardDirs>
|
#include <KStandardDirs>
|
||||||
#include <KUrl>
|
#include <KUrl>
|
||||||
#include <KWindowSystem>
|
|
||||||
|
|
||||||
#include <KIO/CopyJob>
|
#include <KIO/CopyJob>
|
||||||
#include <KIO/JobUiDelegate>
|
#include <KIO/JobUiDelegate>
|
||||||
|
|
||||||
//Plasma
|
|
||||||
#include <Plasma/IconWidget>
|
#include <Plasma/IconWidget>
|
||||||
#include <Plasma/Containment>
|
#include <Plasma/Containment>
|
||||||
#include <Plasma/ToolTipManager>
|
#include <Plasma/ToolTipManager>
|
||||||
|
#include <konq_operations.h>
|
||||||
|
|
||||||
//Solid
|
//Solid
|
||||||
#include <solid/devicenotifier.h>
|
#include <solid/devicenotifier.h>
|
||||||
|
@ -60,14 +56,13 @@
|
||||||
|
|
||||||
Trash::Trash(QObject *parent, const QVariantList &args)
|
Trash::Trash(QObject *parent, const QVariantList &args)
|
||||||
: Plasma::Applet(parent, args),
|
: Plasma::Applet(parent, args),
|
||||||
m_icon(0),
|
m_icon(0),
|
||||||
m_dirLister(0),
|
m_dirLister(0),
|
||||||
m_emptyAction(0),
|
m_emptyAction(0),
|
||||||
m_count(0),
|
m_count(0),
|
||||||
m_showText(false),
|
m_showText(false),
|
||||||
m_places(0),
|
m_places(0),
|
||||||
m_proxy(0),
|
m_proxy(0)
|
||||||
m_emptyProcess(0)
|
|
||||||
{
|
{
|
||||||
setHasConfigurationInterface(true);
|
setHasConfigurationInterface(true);
|
||||||
setAspectRatioMode(Plasma::ConstrainedSquare);
|
setAspectRatioMode(Plasma::ConstrainedSquare);
|
||||||
|
@ -106,8 +101,10 @@ void Trash::init()
|
||||||
m_dirLister->openUrl(KUrl("trash:/"));
|
m_dirLister->openUrl(KUrl("trash:/"));
|
||||||
|
|
||||||
connect(m_icon, SIGNAL(activated()), this, SLOT(open()));
|
connect(m_icon, SIGNAL(activated()), this, SLOT(open()));
|
||||||
connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
|
connect(
|
||||||
this, SLOT(iconSizeChanged(int)));
|
KGlobalSettings::self(), SIGNAL(iconChanged(int)),
|
||||||
|
this, SLOT(iconSizeChanged(int))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trash::createConfigurationInterface(KConfigDialog *parent)
|
void Trash::createConfigurationInterface(KConfigDialog *parent)
|
||||||
|
@ -191,55 +188,9 @@ void Trash::open()
|
||||||
|
|
||||||
void Trash::empty()
|
void Trash::empty()
|
||||||
{
|
{
|
||||||
if (m_emptyProcess) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_confirmEmptyDialog) {
|
|
||||||
KWindowSystem::forceActiveWindow(m_confirmEmptyDialog.data()->winId());
|
|
||||||
} else {
|
|
||||||
const QString text(i18nc("@info", "Do you really want to empty the trash? All items will be deleted."));
|
|
||||||
KDialog *dialog = new KDialog;
|
|
||||||
dialog->setWindowTitle(i18nc("@title:window", "Empty Trash"));
|
|
||||||
dialog->setButtons(KDialog::Yes|KDialog::No);
|
|
||||||
dialog->setButtonText(KDialog::Yes, i18n("Empty Trash"));
|
|
||||||
dialog->setButtonText(KDialog::No, i18n("Cancel"));
|
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
connect(dialog, SIGNAL(yesClicked()), this, SLOT(emptyTrash()));
|
|
||||||
|
|
||||||
KMessageBox::createKMessageBox(dialog, KIcon("user-trash"), text, QStringList(), QString(), 0, KMessageBox::NoExec);
|
|
||||||
|
|
||||||
dialog->setModal(false);
|
|
||||||
m_confirmEmptyDialog = dialog;
|
|
||||||
dialog->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trash::emptyTrash()
|
|
||||||
{
|
|
||||||
// We can't use KonqOperations here. To avoid duplicating its code (small, though),
|
|
||||||
// we can simply call ktrash.
|
|
||||||
//KonqOperations::emptyTrash(&m_menu);
|
|
||||||
m_emptyAction->setEnabled(false);
|
m_emptyAction->setEnabled(false);
|
||||||
m_emptyAction->setText(i18n("Emptying Trashcan..."));
|
m_emptyAction->setText(i18n("Emptying Trashcan..."));
|
||||||
m_emptyProcess = new QProcess(this);
|
KonqOperations::emptyTrash(&m_menu);
|
||||||
connect(m_emptyProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
|
|
||||||
this, SLOT(emptyFinished(int,QProcess::ExitStatus)));
|
|
||||||
QString ktrash = KStandardDirs::findExe("ktrash");
|
|
||||||
m_emptyProcess->start(ktrash, QStringList() << "--empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trash::emptyFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|
||||||
{
|
|
||||||
Q_UNUSED(exitCode)
|
|
||||||
Q_UNUSED(exitStatus)
|
|
||||||
|
|
||||||
KNotification::event("kde/TrashEmptied");
|
|
||||||
|
|
||||||
//TODO: check the exit status and let the user know if it fails
|
|
||||||
delete m_emptyProcess;
|
|
||||||
m_emptyProcess = 0;
|
|
||||||
m_emptyAction->setEnabled(false);
|
|
||||||
m_emptyAction->setText(i18n("&Empty Trashcan"));
|
m_emptyAction->setText(i18n("&Empty Trashcan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,19 +21,13 @@
|
||||||
#ifndef TRASH_H
|
#ifndef TRASH_H
|
||||||
#define TRASH_H
|
#define TRASH_H
|
||||||
|
|
||||||
#include <QtGui/qaction.h>
|
#include <QAction>
|
||||||
#include <QtCore/qprocess.h>
|
|
||||||
#include <QtGui/qgraphicsview.h>
|
|
||||||
#include <KMenu>
|
#include <KMenu>
|
||||||
#include <KFileItem>
|
#include <KFileItem>
|
||||||
#include <KDirLister>
|
#include <KDirLister>
|
||||||
|
|
||||||
#include <Plasma/Applet>
|
#include <Plasma/Applet>
|
||||||
|
|
||||||
#include <QAction>
|
|
||||||
|
|
||||||
class KCModuleProxy;
|
class KCModuleProxy;
|
||||||
class KDialog;
|
|
||||||
class KFilePlacesModel;
|
class KFilePlacesModel;
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
|
@ -44,49 +38,45 @@ namespace Plasma
|
||||||
class Trash : public Plasma::Applet
|
class Trash : public Plasma::Applet
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Trash(QObject *parent, const QVariantList &args);
|
Trash(QObject *parent, const QVariantList &args);
|
||||||
virtual QList<QAction*> contextualActions();
|
~Trash();
|
||||||
~Trash();
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void constraintsEvent(Plasma::Constraints constraints);
|
void constraintsEvent(Plasma::Constraints constraints);
|
||||||
|
QList<QAction*> contextualActions();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
||||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
|
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
|
||||||
void dropEvent(QGraphicsSceneDragDropEvent *event);
|
void dropEvent(QGraphicsSceneDragDropEvent *event);
|
||||||
void createConfigurationInterface(KConfigDialog *parent);
|
void createConfigurationInterface(KConfigDialog *parent);
|
||||||
void createMenu();
|
void createMenu();
|
||||||
void updateIcon();
|
void updateIcon();
|
||||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void popup();
|
void popup();
|
||||||
void open();
|
void open();
|
||||||
void empty();
|
void empty();
|
||||||
void clear();
|
void clear();
|
||||||
void completed();
|
void completed();
|
||||||
void itemsDeleted(const KFileItemList &items);
|
void itemsDeleted(const KFileItemList &items);
|
||||||
void applyConfig();
|
void applyConfig();
|
||||||
void emptyTrash();
|
|
||||||
void emptyFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void iconSizeChanged(int group);
|
void iconSizeChanged(int group);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Plasma::IconWidget* m_icon;
|
Plasma::IconWidget* m_icon;
|
||||||
QList<QAction*> actions;
|
QList<QAction*> actions;
|
||||||
KDirLister *m_dirLister;
|
KDirLister *m_dirLister;
|
||||||
KMenu m_menu;
|
KMenu m_menu;
|
||||||
QAction *m_emptyAction;
|
QAction *m_emptyAction;
|
||||||
QWeakPointer<KDialog> m_confirmEmptyDialog;
|
int m_count;
|
||||||
int m_count;
|
bool m_showText;
|
||||||
bool m_showText;
|
KFilePlacesModel *m_places;
|
||||||
KFilePlacesModel *m_places;
|
KCModuleProxy *m_proxy;
|
||||||
KCModuleProxy *m_proxy;
|
|
||||||
QProcess *m_emptyProcess;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
K_EXPORT_PLASMA_APPLET(trash, Trash)
|
K_EXPORT_PLASMA_APPLET(trash, Trash)
|
||||||
|
|
Loading…
Add table
Reference in a new issue