Move most of file_open_cmd to gtk_open_file. Make gtk_open_file
[metze/wireshark/wip.git] / ui / gtk / file_dlg.h
1 /* file_dlg.h
2  * Declarations of utilities to use when constructing file selection dialogs
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 /** @defgroup filesel_dialog_group File Selection Dialogs
26  *
27  * Dialogs are specially created windows and are related to their parent windows (usually the main window). 
28  * See: @ref howto_window_page for details.
29  *
30  * File selection dialogs are created using file_selection_new().
31  *
32  * - "Browse" file_selection_browse()
33  * - "Open Capture File" file_open_cmd()
34  * - "Save Capture File As" file_save_as_cmd()
35  * - "Import Color Filters" file_color_import_cmd_cb()
36  * - "Export Color Filters" file_color_export_cmd_cb()
37  * - "Save TCP Follow Stream As" follow_save_as_cmd_cb()
38  * - "Export Selected Packet Bytes" savehex_cb()
39  * - "Save Data As CSV" save_csv_as_cb()
40  * - "Save Payload As ..." on_save_bt_clicked()
41  * - "Save selected stream in rtpdump" rtpstream_on_save()
42  * 
43  */
44
45 /** @file
46  * Utilities for file selection dialog boxes. Depending on the window
47  * functions in gui_utils.h, see: @ref howto_window_page for details.
48  * @ingroup filesel_dialog_group
49  */
50
51 #ifndef __FILE_DLG_H__
52 #define __FILE_DLG_H__
53
54 /** the action a file selection is designed for */
55 typedef enum {
56         FILE_SELECTION_OPEN,            /**< open a file */
57         FILE_SELECTION_READ_BROWSE,     /**< browse for a file to read */
58         FILE_SELECTION_SAVE,            /**< save/export a file */
59         FILE_SELECTION_WRITE_BROWSE,    /**< browse for a file to write to */
60         FILE_SELECTION_CREATE_FOLDER    /**< browse for a dir. to save in */  
61 } file_selection_action_t;
62
63 /** Create a file selection dialog box window that belongs to Wireshark's
64  *  main window. See window_new() for usage.
65  *
66  * @param title the title for the new file selection dialog
67  * @param action the desired action
68  * @return the newly created file selection dialog
69  */
70 extern GtkWidget *file_selection_new(const gchar *title, file_selection_action_t action);
71
72 /** Set the current folder for a file selection dialog.
73  *
74  * @param fs the file selection dialog from file_selection_new()
75  * @param filename the folder to set
76  * @return TRUE if the folder could be changed successfully
77  */
78 extern gboolean file_selection_set_current_folder(GtkWidget *fs, const gchar *filename);
79
80 /** Set the current file for a file selection dialog.
81  *
82  * @param fs the file selection dialog from file_selection_new()
83  * @param filename the folder to set
84  * @return TRUE if the folder could be changed successfully
85  */
86 #define file_selection_set_current_file(chooser, filename) \
87         gtk_file_chooser_set_filename(chooser, filename)
88
89 /** Set the "extra" widget for a file selection dialog. This is needed to support 
90  *  user-supplied options.
91  *
92  * @param fs the file selection dialog from file_selection_new()
93  * @param extra the widget to set
94  */
95 extern void file_selection_set_extra_widget(GtkWidget *fs, GtkWidget *extra);
96
97 /** Run the dialog, and handle some common operations, such as, if the
98  *  user selects a directory, browsing that directory, and handling
99  *  shortcuts on Windows.
100  * @param fs the file selection dialog from file_selection_new()
101  * @return the pathname of the selected file if the user selected a
102  * file, NULL if they cancelled or closed the dialog.
103  */
104 extern gchar *file_selection_run(GtkWidget *fs);
105
106 #ifndef _WIN32
107 /** If the specified file doesn't exist, return TRUE.
108  *  If it exists and is neither user-immutable nor not writable, return
109  *  TRUE.
110  *  Otherwise, as the user whether they want to overwrite it anyway, and
111  *  return TRUE if the file should be overwritten and FALSE otherwise.
112  *
113  * @param chooser_w the GtkFileChooser used to select the file in question
114  * @param cf_name the current name chosen
115  */
116 extern gboolean file_target_unwritable_ui(GtkWidget *chooser_w, char *cf_name);
117 #endif
118
119 /** The function file_selection_browse() will g_object_set_data() itself on it's parent window.
120  *  When destroying the parent window, it can close the corresponding file selection. */
121 #define E_FILE_SEL_DIALOG_PTR_KEY "file_sel_dialog_ptr"
122
123 /** Browse the files and fill in the associated text entry.
124  *
125  * @param file_bt the button that called us (to get the toplevel widget)
126  * @param file_te the GtkEntry the dialog will have to fill in the filename
127  * @param title the title for the file selection dialog
128  * @param action the desired action
129  */
130 extern void
131 file_selection_browse(GtkWidget *file_bt, GtkWidget *file_te, const char *title, file_selection_action_t action);
132
133 /** Set the latest opened directory.
134  *  Will already be done when using file_selection_new().
135  *
136  * @param dirname the dirname
137  */
138 extern void set_last_open_dir(const char *dirname);
139
140 #endif