aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2017-01-20 12:26:32 -0800
committerAnders Broman <a.broman58@gmail.com>2017-01-21 06:50:56 +0000
commita5fe96e50a2e9602855f1b7f7507edff8aa381e6 (patch)
treeae40db6c6ee0efed77c2e63bafa7812d5679cb6b /ui/qt
parent05fbb4826bcb182cc3895874a15585a96703ce1f (diff)
Qt: Fixup drag and drop merging.
Make the behavior of MainWindow::dropEvent match the documentation and dnd_open_file_cmd. If we've been passed a single file, open it. If we've been passed multiple files, merge them first. Add an is_tempfile parameter to openCaptureFile. Add a note about setting the drop description on Windows. Bug: 12129 Change-Id: I325a4da5a29e940b4efa7654627d8bcafba15b57 Reviewed-on: https://code.wireshark.org/review/19717 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/main_window.cpp43
-rw-r--r--ui/qt/main_window.h2
-rw-r--r--ui/qt/main_window_slots.cpp4
3 files changed, 41 insertions, 8 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 588353cd91..3efbaf198f 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -868,6 +868,9 @@ void MainWindow::closeEvent(QCloseEvent *event) {
wsApp->quit();
}
+// XXX On windows the drag description is "Copy". It should be "Open" or
+// "Merge" as appropriate. It looks like we need access to IDataObject in
+// order to set DROPDESCRIPTION.
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
bool accept = false;
@@ -882,14 +885,44 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
void MainWindow::dropEvent(QDropEvent *event)
{
+ QList<QByteArray> local_files;
+
foreach (QUrl drop_url, event->mimeData()->urls()) {
- QString local_file = drop_url.toLocalFile();
- if (!local_file.isEmpty()) {
- event->acceptProposedAction();
- openCaptureFile(local_file);
- break;
+ QString drop_file = drop_url.toLocalFile();
+ if (!drop_file.isEmpty()) {
+ local_files << drop_file.toUtf8();
}
}
+
+ if (local_files.size() < 1) {
+ return;
+ }
+ event->acceptProposedAction();
+
+
+ if (local_files.size() == 1) {
+ openCaptureFile(local_files.at(0));
+ return;
+ }
+
+ char **in_filenames = (char **)g_malloc(sizeof(char*) * local_files.size());
+ char *tmpname = NULL;
+
+ for (int i = 0; i < local_files.size(); i++) {
+ in_filenames[i] = (char *) local_files.at(i).constData();
+ }
+
+ /* merge the files in chronological order */
+ if (cf_merge_files_to_tempfile(&tmpname, local_files.size(), in_filenames,
+ WTAP_FILE_TYPE_SUBTYPE_PCAPNG, FALSE) == CF_OK) {
+ /* Merge succeeded; close the currently-open file and try
+ to open the merged capture file. */
+ openCaptureFile(tmpname, QString(), WTAP_TYPE_AUTO, TRUE);
+ }
+
+ g_free(tmpname);
+ g_free(in_filenames);
+
}
// Apply recent settings to the main window geometry.
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index ffbd8a3cf9..987da8e6f6 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -254,7 +254,7 @@ public slots:
* @return True on success, false on failure.
*/
// XXX We might want to return a cf_read_status_t or a CaptureFile.
- bool openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
+ bool openCaptureFile(QString cf_path, QString display_filter, unsigned int type, gboolean is_tempfile = FALSE);
bool openCaptureFile(QString cf_path = QString(), QString display_filter = QString()) { return openCaptureFile(cf_path, display_filter, WTAP_TYPE_AUTO); }
void filterPackets(QString new_filter = QString(), bool force = false);
void updateForUnsavedChanges();
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index 083eb5fd43..c16e474856 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -178,7 +178,7 @@
static const char *dfe_property_ = "display filter expression"; //TODO : Fix Translate
-bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned int type)
+bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned int type, gboolean is_tempfile)
{
QString file_name = "";
dfilter_t *rfcode = NULL;
@@ -232,7 +232,7 @@ bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned
/* Try to open the capture file. This closes the current file if it succeeds. */
CaptureFile::globalCapFile()->window = this;
- if (cf_open(CaptureFile::globalCapFile(), cf_path.toUtf8().constData(), type, FALSE, &err) != CF_OK) {
+ if (cf_open(CaptureFile::globalCapFile(), cf_path.toUtf8().constData(), type, is_tempfile, &err) != CF_OK) {
/* We couldn't open it; don't dismiss the open dialog box,
just leave it around so that the user can, after they
dismiss the alert box popped up for the open error,