*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
# include "config.h"
#endif
-#ifdef HAVE_IO_H
-#include <io.h> /* open/close on win32 */
-#endif
-
-#ifdef HAVE_LIBPCAP
-#include <pcap.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
#endif
+#include <string.h>
+#include <stdio.h>
#include <gtk/gtk.h>
-#include "globals.h"
+#include <epan/prefs.h>
-#include "gtkglobals.h"
-#include "util.h"
-#include "file_dlg.h"
-#include "../menu.h"
-#include "compat_macros.h"
-#include "file.h"
-#include "simple_dialog.h"
-#include "main.h"
+#include "../globals.h"
+#include "../util.h"
+#include "../file.h"
+#include "../simple_dialog.h"
#ifdef HAVE_LIBPCAP
-#include "capture.h"
+#include "../capture.h"
#endif
-#include <epan/prefs.h>
-#include <string.h>
-#include <stdio.h>
+#include "gtk/gtkglobals.h"
+#include "gtk/capture_file_dlg.h"
+#include "gtk/drag_and_drop.h"
+#include "gtk/main.h"
+#include "gtk/menus.h"
+#ifdef HAVE_LIBPCAP
+#include "gtk/capture_globals.h"
+#endif
enum { DND_TARGET_STRING, DND_TARGET_ROOTWIN, DND_TARGET_URL };
*
* On UNIX (at least GNOME Nautilus 2.8.2), this prefix looks like:
* file:///dir1/dir2/capture-file.cap
- */
+ */
if (strncmp("file:", cf_name, 5) == 0) {
/* now becoming: /dir1/dir2/capture-file.cap or ///dir1/dir2/capture-file.cap */
cf_name += 5;
}
#endif
- /*
+ /*
* unescape the escaped URI characters (spaces, ...)
*
- * we have to replace escaped chars to their equivalents,
+ * we have to replace escaped chars to their equivalents,
* e.g. %20 (always a two digit hexstring) -> ' '
* the percent character '%' is escaped be a double one "%%"
*
- * we do this conversation "in place" as the result is always
+ * we do this conversation "in place" as the result is always
* equal or smaller in size.
*/
src = cf_name;
dnd_merge_files(int in_file_count, char **in_filenames)
{
char *tmpname;
- gboolean merge_ok;
+ cf_status_t merge_status;
int err;
/* merge the files in chonological order */
tmpname = NULL;
- merge_ok = cf_merge_files(&tmpname, in_file_count, in_filenames,
+ merge_status = cf_merge_files(&tmpname, in_file_count, in_filenames,
WTAP_FILE_PCAP, FALSE);
- if (!merge_ok) {
+ if (merge_status != CF_OK) {
/* merge failed */
g_free(tmpname);
return;
/* open/merge the dnd file */
void
-dnd_open_file_cmd(GtkSelectionData *selection_data)
+dnd_open_file_cmd(gchar *cf_names_freeme)
{
int err;
- gchar *cf_name, *cf_name_freeme;
+ gchar *cf_name;
int in_files;
gpointer dialog;
GString *dialog_text;
int files_work;
char **in_filenames;
-
+
/* DND_TARGET_URL on Win32:
- * The selection_data->data is a single string, containing one or more URI's,
- * seperated by CR/NL chars. The length of the whole field can be found
+ * The cf_name_freeme is a single string, containing one or more URI's,
+ * seperated by CR/NL chars. The length of the whole field can be found
* in the selection_data->length field. If it contains one file, simply open it,
* If it contains more than one file, ask to merge these files. */
- /* the data string is not zero terminated -> make a zero terminated "copy" of it */
- cf_name_freeme = g_malloc(selection_data->length + 1);
- memcpy(cf_name_freeme, selection_data->data, selection_data->length);
- cf_name_freeme[selection_data->length] = '\0';
-
/* count the number of input files */
- cf_name = cf_name_freeme;
+ cf_name = cf_names_freeme;
for(in_files = 0; (cf_name = strstr(cf_name, "\r\n")) != NULL; ) {
cf_name += 2;
in_files++;
in_filenames = g_malloc(sizeof(char*) * in_files);
/* store the starts of the file entries in a gchar array */
- cf_name = cf_name_freeme;
+ cf_name = cf_names_freeme;
in_filenames[0] = cf_name;
for(files_work = 1; (cf_name = strstr(cf_name, "\r\n")) != NULL && files_work < in_files; ) {
cf_name += 2;
}
/* replace trailing CR NL simply with zeroes (in place), so we get valid terminated strings */
- cf_name = cf_name_freeme;
+ cf_name = cf_names_freeme;
g_strdelimit(cf_name, "\r\n", '\0');
/* convert all filenames from URI to local filename (in place) */
default:
/* build and show the info dialog */
dialog_text = g_string_sized_new(200);
- g_string_append(dialog_text, PRIMARY_TEXT_START
- "Merging the following files:" PRIMARY_TEXT_END "\n\n");
+ 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, in_filenames[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,
+ ESD_BTN_OK, "%s",
dialog_text->str);
g_string_free(dialog_text, TRUE);
}
g_free(in_filenames);
- g_free(cf_name_freeme);
+ g_free(cf_names_freeme);
}
/* ask the user to save current unsaved file, before opening the dnd file */
-static void
-dnd_save_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
+static void
+dnd_save_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
{
switch(btn) {
case(ESD_BTN_SAVE):
/* we have received some drag and drop 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_,
+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_)
{
gpointer dialog;
+ gchar *cf_names_freeme;
if (info == DND_TARGET_URL) {
- /* Usually we block incoming events by disabling the corresponding menu/toolbar items.
- * This is the only place where an incoming event won't be blocked in such a way,
- * so we have to take care of NOT loading a new file while a different process
+ /* Usually we block incoming events by disabling the corresponding menu/toolbar items.
+ * This is the only place where an incoming event won't be blocked in such a way,
+ * so we have to take care of NOT loading a new file while a different process
* (e.g. capture/load/...) is still in progress. */
#ifdef HAVE_LIBPCAP
/* if a capture is running, do nothing but warn the user */
- if((capture_opts->state != CAPTURE_STOPPED)) {
+ if((global_capture_opts.state != CAPTURE_STOPPED)) {
dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
ESD_BTN_OK,
- PRIMARY_TEXT_START "Drag and Drop currently not possible!" PRIMARY_TEXT_END "\n\n"
- "Dropping a file isn't possible while a capture is in progress.");
+ "%sDrag and Drop currently not possible!%s\n\n"
+ "Dropping a file isn't possible while a capture is in progress.",
+ simple_dialog_primary_start(), simple_dialog_primary_end());
return;
}
#endif
if((cfile.state == FILE_READ_IN_PROGRESS)) {
dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
ESD_BTN_OK,
- PRIMARY_TEXT_START "Drag and Drop currently not possible!" PRIMARY_TEXT_END "\n\n"
- "Dropping a file isn't possible while loading another capture file.");
+ "%sDrag and Drop currently not possible!%s\n\n"
+ "Dropping a file isn't possible while loading another capture file.",
+ simple_dialog_primary_start(), simple_dialog_primary_end());
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';
+
/* ask the user to save it's current capture file first */
if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
/* user didn't saved his current file, ask him */
dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
ESD_BTNS_SAVE_DONTSAVE_CANCEL,
- PRIMARY_TEXT_START "Save capture file before opening a new one?" PRIMARY_TEXT_END "\n\n"
- "If you open a new capture file without saving, your current capture data will be discarded.");
- simple_dialog_set_cb(dialog, dnd_save_file_answered_cb, selection_data);
+ "%sSave capture file before opening a new one?%s\n\n"
+ "If you open a new capture file without saving, your current capture data will be discarded.",
+ simple_dialog_primary_start(), simple_dialog_primary_end());
+ simple_dialog_set_cb(dialog, dnd_save_file_answered_cb, cf_names_freeme );
} else {
/* unchanged file */
- dnd_open_file_cmd(selection_data);
+ dnd_open_file_cmd( cf_names_freeme );
}
}
}
/* init the drag and drop functionality */
-void
+void
dnd_init(GtkWidget *w)
{
/* we are only interested in the URI list containing filenames */
(GdkDragAction)(GDK_ACTION_MOVE | GDK_ACTION_COPY) );
/* get notified, if some dnd coming in */
- gtk_signal_connect(GTK_OBJECT(w), "drag_data_received",
- GTK_SIGNAL_FUNC(dnd_data_received), NULL);
+ g_signal_connect(w, "drag_data_received", G_CALLBACK(dnd_data_received), NULL);
}