00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "jobuidelegate.h"
00023
00024 #include <kdebug.h>
00025 #include <kjob.h>
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028 #include <ksharedconfig.h>
00029
00030 #include <QPointer>
00031 #include <QWidget>
00032
00033 #include "kio/scheduler.h"
00034
00035 #if defined Q_WS_X11
00036 #include <QX11Info>
00037 #include <netwm.h>
00038 #endif
00039
00040 class KIO::JobUiDelegate::Private
00041 {
00042 public:
00043 };
00044
00045 KIO::JobUiDelegate::JobUiDelegate()
00046 : d(new Private())
00047 {
00048 }
00049
00050 KIO::JobUiDelegate::~JobUiDelegate()
00051 {
00052 delete d;
00053 }
00054
00055 void KIO::JobUiDelegate::setWindow(QWidget *window)
00056 {
00057 KDialogJobUiDelegate::setWindow(window);
00058 KIO::Scheduler::registerWindow(window);
00059 }
00060
00061 KIO::RenameDialog_Result KIO::JobUiDelegate::askFileRename(KJob * job,
00062 const QString & caption,
00063 const QString& src,
00064 const QString & dest,
00065 KIO::RenameDialog_Mode mode,
00066 QString& newDest,
00067 KIO::filesize_t sizeSrc,
00068 KIO::filesize_t sizeDest,
00069 time_t ctimeSrc,
00070 time_t ctimeDest,
00071 time_t mtimeSrc,
00072 time_t mtimeDest)
00073 {
00074 Q_UNUSED(job);
00075
00076
00077
00078 KIO::RenameDialog dlg( window(), caption, src, dest, mode,
00079 sizeSrc, sizeDest,
00080 ctimeSrc, ctimeDest, mtimeSrc,
00081 mtimeDest);
00082 KIO::RenameDialog_Result res = static_cast<RenameDialog_Result>(dlg.exec());
00083 newDest = dlg.newDestUrl().path();
00084 return res;
00085 }
00086
00087 KIO::SkipDialog_Result KIO::JobUiDelegate::askSkip(KJob *,
00088 bool multi,
00089 const QString & error_text)
00090 {
00091
00092 KIO::SkipDialog dlg( window(), multi, error_text );
00093 return static_cast<KIO::SkipDialog_Result>(dlg.exec());
00094 }
00095
00096 bool KIO::JobUiDelegate::askDeleteConfirmation(const KUrl::List& urls,
00097 DeletionType deletionType,
00098 ConfirmationType confirmationType)
00099 {
00100 QString keyName;
00101 bool ask = ( confirmationType == ForceConfirmation );
00102 if (!ask) {
00103 KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
00104 keyName = (deletionType == Delete ? "ConfirmDelete" : "ConfirmTrash");
00105
00106
00107 const bool defaultValue = true;
00108 ask = kioConfig->group("Confirmations").readEntry(keyName, defaultValue);
00109 }
00110 if (ask) {
00111 QStringList prettyList;
00112 Q_FOREACH(const KUrl& url, urls) {
00113 if ( url.protocol() == "trash" ) {
00114 QString path = url.path();
00115
00116
00117 path.remove(QRegExp("^/[0-9]*-"));
00118 prettyList.append(path);
00119 } else {
00120 prettyList.append(url.pathOrUrl());
00121 }
00122 }
00123
00124 QWidget* widget = window();
00125 int result;
00126 switch(deletionType) {
00127 case Delete:
00128 result = KMessageBox::warningContinueCancelList(
00129 widget,
00130 i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList.count()),
00131 prettyList,
00132 i18n("Delete Files"),
00133 KStandardGuiItem::del(),
00134 KStandardGuiItem::cancel(),
00135 keyName, KMessageBox::Notify);
00136 break;
00137
00138 case Trash:
00139 default:
00140 result = KMessageBox::warningContinueCancelList(
00141 widget,
00142 i18np("Do you really want to move this item to the trash?", "Do you really want to move these %1 items to the trash?", prettyList.count()),
00143 prettyList,
00144 i18n("Move to Trash"),
00145 KGuiItem(i18nc("Verb", "&Trash"), "user-trash"),
00146 KStandardGuiItem::cancel(),
00147 keyName, KMessageBox::Notify);
00148 }
00149 if (!keyName.isEmpty()) {
00150
00151 KSharedConfig::Ptr config = KGlobal::config();
00152 KConfigGroup notificationGroup(config, "Notification Messages");
00153 if (!notificationGroup.readEntry(keyName, true)) {
00154 notificationGroup.writeEntry(keyName, true);
00155 notificationGroup.sync();
00156
00157 KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
00158 kioConfig->group("Confirmations").writeEntry(keyName, false);
00159 }
00160 }
00161 return (result == KMessageBox::Continue);
00162 }
00163 return true;
00164 }
00165
00166 #include "jobuidelegate.moc"