mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +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)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/libs/konq
|
||||
${CMAKE_BINARY_DIR}/libs/konq
|
||||
)
|
||||
|
||||
set(trash_SRCS
|
||||
trash.cpp)
|
||||
trash.cpp
|
||||
)
|
||||
|
||||
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(FILES plasma-applet-trash.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})
|
||||
install(
|
||||
TARGETS plasma_applet_trash
|
||||
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
|
||||
)
|
||||
install(
|
||||
FILES plasma-applet-trash.desktop
|
||||
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
|
||||
)
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
#include "trash.h"
|
||||
|
||||
//QT
|
||||
#include <QtGui/qgraphicssceneevent.h>
|
||||
// Katie
|
||||
#include <QGraphicsSceneDragDropEvent>
|
||||
#include <QGraphicsLinearLayout>
|
||||
|
||||
// KDE
|
||||
|
@ -33,20 +33,16 @@
|
|||
#include <KMessageBox>
|
||||
#include <KLocale>
|
||||
#include <KNotification>
|
||||
#include <QProcess>
|
||||
#include <KToolInvocation>
|
||||
#include <KSharedConfig>
|
||||
#include <KStandardDirs>
|
||||
#include <KUrl>
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include <KIO/CopyJob>
|
||||
#include <KIO/JobUiDelegate>
|
||||
|
||||
//Plasma
|
||||
#include <Plasma/IconWidget>
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/ToolTipManager>
|
||||
#include <konq_operations.h>
|
||||
|
||||
//Solid
|
||||
#include <solid/devicenotifier.h>
|
||||
|
@ -66,8 +62,7 @@ Trash::Trash(QObject *parent, const QVariantList &args)
|
|||
m_count(0),
|
||||
m_showText(false),
|
||||
m_places(0),
|
||||
m_proxy(0),
|
||||
m_emptyProcess(0)
|
||||
m_proxy(0)
|
||||
{
|
||||
setHasConfigurationInterface(true);
|
||||
setAspectRatioMode(Plasma::ConstrainedSquare);
|
||||
|
@ -106,8 +101,10 @@ void Trash::init()
|
|||
m_dirLister->openUrl(KUrl("trash:/"));
|
||||
|
||||
connect(m_icon, SIGNAL(activated()), this, SLOT(open()));
|
||||
connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
|
||||
this, SLOT(iconSizeChanged(int)));
|
||||
connect(
|
||||
KGlobalSettings::self(), SIGNAL(iconChanged(int)),
|
||||
this, SLOT(iconSizeChanged(int))
|
||||
);
|
||||
}
|
||||
|
||||
void Trash::createConfigurationInterface(KConfigDialog *parent)
|
||||
|
@ -191,55 +188,9 @@ void Trash::open()
|
|||
|
||||
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->setText(i18n("Emptying Trashcan..."));
|
||||
m_emptyProcess = new QProcess(this);
|
||||
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);
|
||||
KonqOperations::emptyTrash(&m_menu);
|
||||
m_emptyAction->setText(i18n("&Empty Trashcan"));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,19 +21,13 @@
|
|||
#ifndef TRASH_H
|
||||
#define TRASH_H
|
||||
|
||||
#include <QtGui/qaction.h>
|
||||
#include <QtCore/qprocess.h>
|
||||
#include <QtGui/qgraphicsview.h>
|
||||
#include <QAction>
|
||||
#include <KMenu>
|
||||
#include <KFileItem>
|
||||
#include <KDirLister>
|
||||
|
||||
#include <Plasma/Applet>
|
||||
|
||||
#include <QAction>
|
||||
|
||||
class KCModuleProxy;
|
||||
class KDialog;
|
||||
class KFilePlacesModel;
|
||||
|
||||
namespace Plasma
|
||||
|
@ -46,11 +40,11 @@ class Trash : public Plasma::Applet
|
|||
Q_OBJECT
|
||||
public:
|
||||
Trash(QObject *parent, const QVariantList &args);
|
||||
virtual QList<QAction*> contextualActions();
|
||||
~Trash();
|
||||
|
||||
void init();
|
||||
void constraintsEvent(Plasma::Constraints constraints);
|
||||
QList<QAction*> contextualActions();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
@ -69,8 +63,6 @@ class Trash : public Plasma::Applet
|
|||
void completed();
|
||||
void itemsDeleted(const KFileItemList &items);
|
||||
void applyConfig();
|
||||
void emptyTrash();
|
||||
void emptyFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
private slots:
|
||||
void iconSizeChanged(int group);
|
||||
|
@ -81,12 +73,10 @@ class Trash : public Plasma::Applet
|
|||
KDirLister *m_dirLister;
|
||||
KMenu m_menu;
|
||||
QAction *m_emptyAction;
|
||||
QWeakPointer<KDialog> m_confirmEmptyDialog;
|
||||
int m_count;
|
||||
bool m_showText;
|
||||
KFilePlacesModel *m_places;
|
||||
KCModuleProxy *m_proxy;
|
||||
QProcess *m_emptyProcess;
|
||||
};
|
||||
|
||||
K_EXPORT_PLASMA_APPLET(trash, Trash)
|
||||
|
|
Loading…
Add table
Reference in a new issue