merge_all_tap_menus() has been moved to menus.c.
[obnox/wireshark/wip.git] / gtk / drag_and_drop.c
index 8353232c45a2e7a8b58e476bc7a0a727922b5681..7c0e334cb6bd9501e7af9525b8be0818caa6ecc9 100644 (file)
@@ -1,4 +1,4 @@
-/* dnd.c
+/* drag_and_drop.c
  * Drag and Drop
  *
  * $Id$
@@ -36,7 +36,6 @@
 
 #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 };
 
@@ -177,7 +181,7 @@ dnd_merge_files(int in_file_count, char **in_filenames)
     }
     g_free(tmpname);
 
-    switch (cf_read(&cfile)) {
+    switch (cf_read(&cfile, FALSE)) {
 
     case CF_READ_OK:
     case CF_READ_ERROR:
@@ -193,8 +197,6 @@ dnd_merge_files(int in_file_count, char **in_filenames)
           directory). */
        return;
     }
-
-    gtk_widget_grab_focus(packet_list);
 }
 
 /* open/merge the dnd file */
@@ -204,7 +206,6 @@ dnd_open_file_cmd(gchar *cf_names_freeme)
     int       err;
     gchar     *cf_name;
     int       in_files;
-    gpointer  dialog;
     GString   *dialog_text;
     int       files_work;
     char      **in_filenames;
@@ -251,7 +252,7 @@ dnd_open_file_cmd(gchar *cf_names_freeme)
         /* 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, ...) */
@@ -260,7 +261,7 @@ dnd_open_file_cmd(gchar *cf_names_freeme)
     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++) {
@@ -268,8 +269,8 @@ dnd_open_file_cmd(gchar *cf_names_freeme)
             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);
 
@@ -306,10 +307,12 @@ dnd_save_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
 /* (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.
@@ -320,7 +323,7 @@ GtkSelectionData *selection_data, guint info, guint t _U_, gpointer data _U_)
 #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.",
@@ -330,8 +333,8 @@ GtkSelectionData *selection_data, guint info, guint t _U_, gpointer data _U_)
 #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.",
@@ -339,11 +342,13 @@ GtkSelectionData *selection_data, guint info, guint t _U_, gpointer data _U_)
             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) {
@@ -361,6 +366,29 @@ GtkSelectionData *selection_data, guint info, guint t _U_, gpointer data _U_)
     }
 }
 
+#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)
@@ -380,6 +408,9 @@ 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
 }