aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2004-01-31 18:32:37 +0000
committerUlf Lamping <ulf.lamping@web.de>2004-01-31 18:32:37 +0000
commit5b38a022e4dba17251d79ef205d5e37a660b741d (patch)
tree6bd53b8475b35641890c253fb6cfe05f18cb137b
parent3c763c4fb6f1a892bdb8736d1dd760d61bd837f1 (diff)
Implemented rudimentary Drag and Drop support.
svn path=/trunk/; revision=9926
-rw-r--r--gtk/file_dlg.c5
-rw-r--r--gtk/file_dlg.h3
-rw-r--r--gtk/main.c116
-rw-r--r--gtk/main.h3
4 files changed, 123 insertions, 4 deletions
diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c
index b8b80e176c..be6dfb29e2 100644
--- a/gtk/file_dlg.c
+++ b/gtk/file_dlg.c
@@ -1,7 +1,7 @@
/* file_dlg.c
* Dialog boxes for handling files
*
- * $Id: file_dlg.c,v 1.89 2004/01/31 14:16:43 ulfl Exp $
+ * $Id: file_dlg.c,v 1.90 2004/01/31 18:32:36 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1085,6 +1085,9 @@ file_save_as_ok_cb(GtkWidget *w _U_, GtkFileSelection *fs) {
case(after_save_open_recent_file):
menu_open_recent_file_cmd(action_after_save_data_g);
break;
+ case(after_save_open_dnd_file):
+ dnd_open_file_cmd(action_after_save_data_g);
+ break;
#ifdef HAVE_LIBPCAP
case(after_save_capture_dialog):
capture_prep();
diff --git a/gtk/file_dlg.h b/gtk/file_dlg.h
index 9a103a3532..e14c8d24c9 100644
--- a/gtk/file_dlg.h
+++ b/gtk/file_dlg.h
@@ -1,7 +1,7 @@
/* file_dlg.h
* Definitions for dialog boxes for handling files
*
- * $Id: file_dlg.h,v 1.8 2004/01/29 23:11:37 ulfl Exp $
+ * $Id: file_dlg.h,v 1.9 2004/01/31 18:32:36 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -30,6 +30,7 @@ typedef enum {
after_save_close_file,
after_save_open_dialog,
after_save_open_recent_file,
+ after_save_open_dnd_file,
after_save_capture_dialog,
after_save_exit
} action_after_save_e;
diff --git a/gtk/main.c b/gtk/main.c
index 8c90c366c9..bc0e5248f4 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.382 2004/01/31 12:13:23 ulfl Exp $
+ * $Id: main.c,v 1.383 2004/01/31 18:32:36 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1539,6 +1539,118 @@ register_ethereal_tap(char *cmd, void (*func)(char *arg))
}
+
+enum { DND_TARGET_STRING, DND_TARGET_ROOTWIN, DND_TARGET_URL };
+
+void
+dnd_open_file_cmd(gpointer cf_name)
+{
+ int err;
+
+
+ /* open and read the capture file (this will close an existing file) */
+ if ((err = cf_open(cf_name, FALSE, &cfile)) == 0) {
+ cf_read(&cfile);
+ add_menu_recent_capture_file(cf_name);
+ } else {
+ /* the capture file couldn't be read (doesn't exist, file format unknown, ...) */
+ }
+
+ g_free(cf_name);
+}
+
+static void
+dnd_open_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
+{
+ switch(btn) {
+ case(ESD_BTN_YES):
+ /* save file first */
+ file_save_as_cmd(after_save_open_dnd_file, data);
+ break;
+ case(ESD_BTN_NO):
+ dnd_open_file_cmd(data);
+ break;
+ case(ESD_BTN_CANCEL):
+ g_free(data);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+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_)
+{
+ gchar *cf_name, *cf_name_ori;
+ gpointer dialog;
+
+
+ if (info == DND_TARGET_URL) {
+ /* 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
+ * in the selection_data->length field. As we can't handle more than one
+ * capture file at a time, we only try to load the first one. */
+
+ /* XXX: how does this string look like on other platforms? */
+
+ /* XXX: if more than one file is in the string, we might want to have
+ * a dialog box asking to merge these files together? */
+
+ /* the name might not be zero terminated -> make a copy of it */
+ cf_name_ori = g_strndup(selection_data->data, selection_data->length);
+ cf_name = cf_name_ori;
+
+ /* replace trailing CR NL simply with zeroes */
+ g_strdelimit(cf_name, "\r\n", '\0');
+
+ /* remove uri header */
+ if (strncmp("file:///", cf_name, 8) == 0) {
+ cf_name += 8;
+ };
+
+ /* we need a clean name for later call to g_free() */
+ cf_name = strdup(cf_name);
+ g_free(cf_name_ori);
+
+ /* ask the user to save it's current capture file first */
+ if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+ /* user didn't saved his current file, ask him */
+ dialog = simple_dialog(ESD_TYPE_WARN | ESD_TYPE_MODAL,
+ ESD_BTN_YES | ESD_BTN_NO | ESD_BTN_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_open_file_answered_cb, cf_name);
+ } else {
+ /* unchanged file */
+ dnd_open_file_cmd(cf_name);
+ }
+ }
+}
+
+static void
+dnd_init(GtkWidget *w)
+{
+ /* we are only interested in the URI list containing filenames */
+ static GtkTargetEntry target_entry[] = {
+ /*{"STRING", 0, DND_TARGET_STRING},*/
+ /*{"text/plain", 0, DND_TARGET_STRING},*/
+ {"text/uri-list", 0, DND_TARGET_URL}
+ };
+
+ /* set this window as a dnd destination */
+ gtk_drag_dest_set(
+ w, GTK_DEST_DEFAULT_ALL, target_entry,
+ sizeof(target_entry) / sizeof(GtkTargetEntry),
+ (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);
+}
+
+
/* And now our feature presentation... [ fade to music ] */
int
main(int argc, char *argv[])
@@ -2387,6 +2499,8 @@ main(int argc, char *argv[])
we were told to. */
create_main_window(pl_size, tv_size, bv_size, prefs);
+ dnd_init(top_level);
+
/* Read the recent file, as we have the gui now ready for it. */
read_recent(&rf_path, &rf_open_errno);
diff --git a/gtk/main.h b/gtk/main.h
index c9a81b38b5..4a6f87cb37 100644
--- a/gtk/main.h
+++ b/gtk/main.h
@@ -1,7 +1,7 @@
/* main.h
* Global defines, etc.
*
- * $Id: main.h,v 1.40 2004/01/29 23:11:37 ulfl Exp $
+ * $Id: main.h,v 1.41 2004/01/31 18:32:37 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -108,6 +108,7 @@ extern void dfilter_recent_combo_write_all(FILE *rf);
extern gboolean main_do_quit(void);
extern void main_widgets_rearrange(void);
extern int main_filter_packets(capture_file *cf, const gchar *dftext);
+extern void dnd_open_file_cmd(gpointer cf_name);
typedef enum {
FA_SUCCESS,