summaryrefslogtreecommitdiff
path: root/ui/qt/main_window.cpp
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/main_window.cpp
parent05fbb4826bcb182cc3895874a15585a96703ce1f (diff)
downloadwireshark-a5fe96e50a2e9602855f1b7f7507edff8aa381e6.tar.gz
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/main_window.cpp')
-rw-r--r--ui/qt/main_window.cpp43
1 files changed, 38 insertions, 5 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.