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 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,