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>
This commit is contained in:
Gerald Combs 2017-01-20 12:26:32 -08:00 committed by Anders Broman
parent 05fbb4826b
commit a5fe96e50a
3 changed files with 41 additions and 8 deletions

View File

@ -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.

View File

@ -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();

View File

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