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 connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject()));
00083 KIO::RenameDialog_Result res = static_cast<RenameDialog_Result>(dlg.exec());
00084 newDest = dlg.newDestUrl().path();
00085 return res;
00086 }
00087
00088 KIO::SkipDialog_Result KIO::JobUiDelegate::askSkip(KJob *job,
00089 bool multi,
00090 const QString & error_text)
00091 {
00092
00093 KIO::SkipDialog dlg( window(), multi, error_text );
00094 connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject()));
00095 return static_cast<KIO::SkipDialog_Result>(dlg.exec());
00096 }
00097
00098 bool KIO::JobUiDelegate::askDeleteConfirmation(const KUrl::List& urls,
00099 DeletionType deletionType,
00100 ConfirmationType confirmationType)
00101 {
00102 QString keyName;
00103 bool ask = ( confirmationType == ForceConfirmation );
00104 if (!ask) {
00105 KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
00106 keyName = (deletionType == Delete ? "ConfirmDelete" : "ConfirmTrash");
00107
00108
00109 const bool defaultValue = true;
00110 ask = kioConfig->group("Confirmations").readEntry(keyName, defaultValue);
00111 }
00112 if (ask) {
00113 QStringList prettyList;
00114 Q_FOREACH(const KUrl& url, urls) {
00115 if ( url.protocol() == "trash" ) {
00116 QString path = url.path();
00117
00118
00119 path.remove(QRegExp("^/[0-9]*-"));
00120 prettyList.append(path);
00121 } else {
00122 prettyList.append(url.pathOrUrl());
00123 }
00124 }
00125
00126 QWidget* widget = window();
00127 int result;
00128 switch(deletionType) {
00129 case Delete:
00130 result = KMessageBox::warningContinueCancelList(
00131 widget,
00132 i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList.count()),
00133 prettyList,
00134 i18n("Delete Files"),
00135 KStandardGuiItem::del(),
00136 KStandardGuiItem::cancel(),
00137 keyName, KMessageBox::Notify);
00138 break;
00139
00140 case Trash:
00141 default:
00142 result = KMessageBox::warningContinueCancelList(
00143 widget,
00144 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()),
00145 prettyList,
00146 i18n("Move to Trash"),
00147 KGuiItem(i18nc("Verb", "&Trash"), "user-trash"),
00148 KStandardGuiItem::cancel(),
00149 keyName, KMessageBox::Notify);
00150 }
00151 if (!keyName.isEmpty()) {
00152
00153 KSharedConfig::Ptr config = KGlobal::config();
00154 KConfigGroup notificationGroup(config, "Notification Messages");
00155 if (!notificationGroup.readEntry(keyName, true)) {
00156 notificationGroup.writeEntry(keyName, true);
00157 notificationGroup.sync();
00158
00159 KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
00160 kioConfig->group("Confirmations").writeEntry(keyName, false);
00161 }
00162 }
00163 return (result == KMessageBox::Continue);
00164 }
00165 return true;
00166 }
00167
00168 #include "jobuidelegate.moc"