-/* dnd.c
+/* drag_and_drop.c
* Drag and Drop
*
* $Id$
#include <epan/prefs.h>
-#include "../globals.h"
#include "../util.h"
#include "../file.h"
#include "../simple_dialog.h"
#include "gtk/capture_file_dlg.h"
#include "gtk/drag_and_drop.h"
#include "gtk/main.h"
-#include "gtk/main_menu.h"
+#include "gtk/menus.h"
#ifdef HAVE_LIBPCAP
#include "gtk/capture_globals.h"
#endif
+#include "gtk/old-gtk-compat.h"
+
+#ifdef HAVE_GTKOSXAPPLICATION
+#include <igemacintegration/gtkosxapplication.h>
+#endif
enum { DND_TARGET_STRING, DND_TARGET_ROOTWIN, DND_TARGET_URL };
}
g_free(tmpname);
- switch (cf_read(&cfile)) {
+ switch (cf_read(&cfile, FALSE)) {
case CF_READ_OK:
case CF_READ_ERROR:
directory). */
return;
}
-
- gtk_widget_grab_focus(packet_list);
}
/* open/merge the dnd file */
int err;
gchar *cf_name;
int in_files;
- gpointer dialog;
GString *dialog_text;
int files_work;
char **in_filenames;
/* open and read the capture file (this will close an existing file) */
if (cf_open(&cfile, in_filenames[0], FALSE, &err) == CF_OK) {
/* XXX - add this to the menu if the read fails? */
- cf_read(&cfile);
+ cf_read(&cfile, FALSE);
add_menu_recent_capture_file(in_filenames[0]);
} else {
/* the capture file couldn't be read (doesn't exist, file format unknown, ...) */
default:
/* build and show the info dialog */
dialog_text = g_string_sized_new(200);
- g_string_printf(dialog_text,
+ g_string_printf(dialog_text,
"%sMerging the following files:%s\n\n",
simple_dialog_primary_start(), simple_dialog_primary_end());
for(files_work = 0; files_work < in_files; files_work++) {
g_string_append(dialog_text, "\n");
}
g_string_append(dialog_text, "\nThe packets in these files will be merged chronologically into a new temporary file.");
- dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
- ESD_BTN_OK, "%s",
+ simple_dialog(ESD_TYPE_CONFIRMATION,
+ ESD_BTN_OK, "%s",
dialog_text->str);
g_string_free(dialog_text, TRUE);
/* (as we only registered to "text/uri-list", we will only get a file list here) */
static void
dnd_data_received(GtkWidget *widget _U_, GdkDragContext *dc _U_, gint x _U_, gint y _U_,
-GtkSelectionData *selection_data, guint info, guint t _U_, gpointer data _U_)
+ GtkSelectionData *selection_data, guint info, guint t _U_, gpointer data _U_)
{
gpointer dialog;
gchar *cf_names_freeme;
+ const guchar *sel_data_data;
+ gint sel_data_len;
if (info == DND_TARGET_URL) {
/* Usually we block incoming events by disabling the corresponding menu/toolbar items.
#ifdef HAVE_LIBPCAP
/* if a capture is running, do nothing but warn the user */
if((global_capture_opts.state != CAPTURE_STOPPED)) {
- dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
+ simple_dialog(ESD_TYPE_CONFIRMATION,
ESD_BTN_OK,
"%sDrag and Drop currently not possible!%s\n\n"
"Dropping a file isn't possible while a capture is in progress.",
#endif
/* if another file read is still in progress, do nothing but warn the user */
- if((cfile.state == FILE_READ_IN_PROGRESS)) {
- dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
+ if(cfile.state == FILE_READ_IN_PROGRESS) {
+ simple_dialog(ESD_TYPE_CONFIRMATION,
ESD_BTN_OK,
"%sDrag and Drop currently not possible!%s\n\n"
"Dropping a file isn't possible while loading another capture file.",
return;
}
- /* the selection_data will soon be gone, make a copy first */
- /* the data string is not zero terminated -> make a zero terminated "copy" of it */
- cf_names_freeme = g_malloc(selection_data->length + 1);
- memcpy(cf_names_freeme, selection_data->data, selection_data->length);
- cf_names_freeme[selection_data->length] = '\0';
+ /* the selection_data will soon be gone, make a copy first */
+ /* the data string is not zero terminated -> make a zero terminated "copy" of it */
+ sel_data_len = gtk_selection_data_get_length(selection_data);
+ sel_data_data = gtk_selection_data_get_data(selection_data);
+ cf_names_freeme = g_malloc(sel_data_len + 1);
+ memcpy(cf_names_freeme, sel_data_data, sel_data_len);
+ cf_names_freeme[sel_data_len] = '\0';
/* ask the user to save it's current capture file first */
if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
}
}
+#ifdef HAVE_GTKOSXAPPLICATION
+gboolean
+gtk_osx_openFile (GtkOSXApplication *app _U_, gchar *path, gpointer user_data _U_)
+{
+ GtkSelectionData selection_data;
+ int length = strlen(path);
+
+ selection_data.length = length + 3;
+ selection_data.data = g_malloc(length + 3);
+ memcpy(selection_data.data, path, length);
+
+ selection_data.data[length] = '\r';
+ selection_data.data[length + 1] = '\n';
+ selection_data.data[length + 2] = '\0';
+
+ dnd_data_received(NULL, NULL, 0, 0, &selection_data, DND_TARGET_URL, 0, 0);
+
+ g_free(selection_data.data);
+
+ return TRUE;
+}
+#endif
+
/* init the drag and drop functionality */
void
dnd_init(GtkWidget *w)
/* get notified, if some dnd coming in */
g_signal_connect(w, "drag_data_received", G_CALLBACK(dnd_data_received), NULL);
+#ifdef HAVE_GTKOSXAPPLICATION
+ g_signal_connect(g_object_new(GTK_TYPE_OSX_APPLICATION, NULL), "NSApplicationOpenFile", G_CALLBACK(gtk_osx_openFile), NULL);
+#endif
}