aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-03-17 11:45:43 -0700
committerGuy Harris <guy@alum.mit.edu>2015-03-17 18:47:30 +0000
commit6637f4d144c96a4bb467540c46bb47779d2be573 (patch)
tree7c8326877b9dfeaee43d4d589bb6eb9dd21d9d37 /ui
parentf59ad07a0a8b3d79c74bd2ebc6c3e04c5ef4e70f (diff)
Fix "Save All" for Export Objects.
Fix the loop that goes through all the objects to be saved so that it looks at all the objects to be saved rather than repeatedly looking at the first object. When letting the user select a directory in which to save, restrict them to looking at directories. QDir doesn't do what we actually want here - QDir.setCurrent() might do a chdir() but it doesn't appear to set the QDir's path, so when we use it to construct pathnames it constructs them based on wsApp->lastOpenDir() rather than the directory the user selected. Use Boring Old GLib's g_build_filename(), as we do in the GTK+ version, for now. (It also does something we *don't* want, namely, at least as the documentation implies, a chdir().) Bug: 11062 Change-Id: I705292dc2713b9dba615b0d59a4cf8313f357d82 Reviewed-on: https://code.wireshark.org/review/7720 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/export_object_dialog.cpp45
1 files changed, 29 insertions, 16 deletions
diff --git a/ui/qt/export_object_dialog.cpp b/ui/qt/export_object_dialog.cpp
index 35b56e45e4..4300d4998d 100644
--- a/ui/qt/export_object_dialog.cpp
+++ b/ui/qt/export_object_dialog.cpp
@@ -270,19 +270,29 @@ void ExportObjectDialog::saveAllEntries()
{
int i;
QTreeWidgetItem *item;
- QDir path(wsApp->lastOpenDir());
- QString file_path;
+ QDir save_in_dir(wsApp->lastOpenDir());
+ QString save_in_path;
bool all_saved = true;
- file_path = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save All Objects In" UTF8_HORIZONTAL_ELLIPSIS)),
- path.canonicalPath(), QString(), NULL,
- QFileDialog::ShowDirsOnly);
-
- if (file_path.length() < 1 || file_path.length() > MAXFILELEN) return;
-
- for (i = 0, item = eo_ui_->objectTree->topLevelItem(i); item != NULL; i++) {
+ //
+ // We want the user to be able to specify a directory in which
+ // to drop files for all the objects, not a file name.
+ //
+ // XXX - what we *really* want is something that asks the user
+ // for an existing directory *but* lets them create a new
+ // directory in the process. That's what we get on OS X,
+ // as the native dialog is used, and it supports that; does
+ // that also work on Windows and with Qt's own dialog?
+ //
+ save_in_path = QFileDialog::getExistingDirectory(this, wsApp->windowTitleString(tr("Save All Objects In" UTF8_HORIZONTAL_ELLIPSIS)),
+ save_in_dir.canonicalPath(),
+ QFileDialog::ShowDirsOnly);
+
+ if (save_in_path.length() < 1 || save_in_path.length() > MAXFILELEN) return;
+
+ for (i = 0; (item = eo_ui_->objectTree->topLevelItem(i)) != NULL; i++) {
int count = 0;
- QString file_name;
+ gchar *save_as_fullpath = NULL;
export_object_entry_t *entry = item->data(0, Qt::UserRole).value<export_object_entry_t *>();
if (!entry) continue;
@@ -290,10 +300,10 @@ void ExportObjectDialog::saveAllEntries()
do {
GString *safe_filename;
- path.setCurrent(file_path);
+ g_free(save_as_fullpath);
if (entry->filename)
safe_filename = eo_massage_str(entry->filename,
- MAXFILELEN - file_path.length(), count);
+ MAXFILELEN - save_in_path.length(), count);
else {
char generic_name[256];
const char *ext;
@@ -302,13 +312,16 @@ void ExportObjectDialog::saveAllEntries()
"object%u%s%s", entry->pkt_num, ext ? "." : "",
ext ? ext : "");
safe_filename = eo_massage_str(generic_name,
- MAXFILELEN - file_path.length(), count);
+ MAXFILELEN - save_in_path.length(), count);
}
- file_name = path.filePath(safe_filename->str);
+ save_as_fullpath = g_build_filename(save_in_path.toUtf8().constData(),
+ safe_filename->str, NULL);
g_string_free(safe_filename, TRUE);
- } while (g_file_test(file_path.toUtf8().constData(), G_FILE_TEST_EXISTS) && ++count < 1000);
- if (!eo_save_entry(file_path.toUtf8().constData(), entry, FALSE))
+ } while (g_file_test(save_as_fullpath, G_FILE_TEST_EXISTS) && ++count < 1000);
+ if (!eo_save_entry(save_as_fullpath, entry, FALSE))
all_saved = false;
+ g_free(save_as_fullpath);
+ save_as_fullpath = NULL;
}
if (!all_saved) {
QMessageBox::warning(