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