summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2024-07-07 22:22:18 +0300
committerMavridis Philippe <mavridisf@gmail.com>2024-07-07 22:22:18 +0300
commitc7b0c7b88c1bebb038bd70f4995fc35771fa83c0 (patch)
tree0e6b9580cb88a3a538ed56016c0e9502aab9b7ea
parentb8f8ce418e3b2bb00b6a5b4c75aebfb6e99147ef (diff)
downloadxdg-desktop-portal-tde-c7b0c7b88c1bebb038bd70f4995fc35771fa83c0.tar.gz
xdg-desktop-portal-tde-c7b0c7b88c1bebb038bd70f4995fc35771fa83c0.zip
Implement TDEFileChooserPortal::SaveFiles
Allows selecting a directory to save multiple files while checking for existing files with similar filenames. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--src/file_chooser_portal.cpp80
1 files changed, 79 insertions, 1 deletions
diff --git a/src/file_chooser_portal.cpp b/src/file_chooser_portal.cpp
index 0a7b340..ee8b0f6 100644
--- a/src/file_chooser_portal.cpp
+++ b/src/file_chooser_portal.cpp
@@ -24,6 +24,7 @@
#include <tqdbusobjectpath.h>
// TDE
+#include <tdeio/renamedlg.h>
#include <tdefiledialog.h>
#include <kpushbutton.h>
#include <twin.h>
@@ -126,7 +127,84 @@ bool TDEFileChooserPortal::SaveFiles(const TQT_DBusObjectPath& handle,
TQMap<TQString, TQT_DBusVariant> &results,
TQT_DBusError& error)
{
- return false;
+ // Get list of files to save
+ if (!OPTION_VALID("files", "aay"))
+ {
+ kdWarning() << "TDEFileChooserPortal::SaveFiles: "
+ << "Invalid or misssing files option" << endl;
+ return false;
+ }
+
+ TQValueList<TQT_DBusData> filelist = options["files"].value.toTQValueList();
+ TQValueList<TQT_DBusData>::iterator fi;
+ TQStringList files;
+ for (fi = filelist.begin(); fi != filelist.end(); ++fi)
+ {
+ files << bytelist_to_string((*fi).toList().toByteList());
+ }
+
+ // Parse options
+ FileDialogOpts opts;
+ opts.caption = title;
+
+ if (OPTION_VALID("accept_label", "s"))
+ opts.okButtonText = options["accept_label"].value.toString();
+
+ if (OPTION_VALID("modal", "b"))
+ opts.modal = options["modal"].value.toBool();
+
+ if (OPTION_VALID("current_folder", "ay"))
+ opts.startDir = bytelist_to_string(options["current_folder"].value.toList().toByteList());
+
+ // We can't just use execFileDialog because we need to do some special processing
+ KFileDialog *dialog = new KFileDialog(opts.startDir, TQString::null,
+ nullptr, "xdg-tde-file-chooser",
+ opts.modal);
+
+ dialog->setMode(KFile::LocalOnly | KFile::Directory);
+
+ if (!opts.caption.isNull())
+ dialog->setPlainCaption(opts.caption);
+
+ if (!opts.okButtonText.isNull())
+ dialog->okButton()->setText(opts.okButtonText);
+
+ if (opts.windowId > 0) KWin::setMainWindow(dialog, opts.windowId);
+
+ if (dialog->exec() == TQDialog::Accepted)
+ {
+ TQDir d(dialog->selectedURL().path());
+ KURL::List urllist;
+ for (TQStringList::Iterator it = files.begin(); it != files.end(); ++it)
+ {
+ TQString filename = (*it);
+ TQFileInfo fi(d, filename);
+ KURL url(fi.absFilePath());
+ if (fi.exists())
+ {
+ TDEIO::RenameDlg rename(dialog, opts.caption, TQString::null,
+ fi.absFilePath(), TDEIO::M_OVERWRITE);
+ int result = rename.exec();
+ switch (result)
+ {
+ case TDEIO::R_RENAME:
+ url = rename.newDestURL();
+ break;
+ case TDEIO::R_CANCEL:
+ url = KURL();
+ break;
+ }
+ }
+ urllist << url.url();
+ }
+
+ response = 0;
+ TQT_DBusDataList urls = kurl_list_to_datalist(urllist);
+ TQT_DBusVariant var = TQT_DBusData::fromList(urls).getAsVariantData().toVariant();
+ results.insert("uris", var);
+ }
+ else response = 1;
+ return true;
}
void TDEFileChooserPortal::handleMethodReply(const TQT_DBusMessage &reply)