aboutsummaryrefslogtreecommitdiffstats
path: root/trace-dialog.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-06-14 20:51:50 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-06-14 20:51:50 -0400
commitad15344e398191ae63bde380b865c57c286e2732 (patch)
treef79c661d8db7d2ff283f4f51713c7a409f8b6585 /trace-dialog.c
parenta06b4a35cf29205d4c17da6c8f6fbc63b503b68f (diff)
kernelshark: Have file dialog ask if we want to overwrite
If someone selects a file that already exists and the command will be used to overwrite the file. Ask the user if they want to overwrite it instead of just doing so. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'trace-dialog.c')
-rw-r--r--trace-dialog.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/trace-dialog.c b/trace-dialog.c
index 4fab040..4bddd08 100644
--- a/trace-dialog.c
+++ b/trace-dialog.c
@@ -250,13 +250,15 @@ void trace_show_help(GtkWidget *window, const gchar *link, GError **error)
250#endif 250#endif
251} 251}
252 252
253void trace_dialog(GtkWindow *parent, enum trace_dialog_type type, 253GtkResponseType trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
254 gchar *message, ...) 254 gchar *message, ...)
255{ 255{
256 GtkWidget *dialog; 256 GtkWidget *dialog;
257 GtkMessageType mtype; 257 GtkMessageType mtype;
258 GtkButtonsType btype = GTK_BUTTONS_CLOSE;
258 gchar *str; 259 gchar *str;
259 va_list ap; 260 va_list ap;
261 int result;
260 262
261 switch (type) { 263 switch (type) {
262 case TRACE_GUI_INFO: 264 case TRACE_GUI_INFO:
@@ -268,6 +270,10 @@ void trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
268 case TRACE_GUI_ERROR: 270 case TRACE_GUI_ERROR:
269 mtype = GTK_MESSAGE_ERROR; 271 mtype = GTK_MESSAGE_ERROR;
270 break; 272 break;
273 case TRACE_GUI_ASK:
274 mtype = GTK_MESSAGE_WARNING;
275 btype = GTK_BUTTONS_YES_NO;
276 break;
271 } 277 }
272 278
273 va_start(ap, message); 279 va_start(ap, message);
@@ -277,26 +283,56 @@ void trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
277 dialog = gtk_message_dialog_new(parent, 283 dialog = gtk_message_dialog_new(parent,
278 GTK_DIALOG_DESTROY_WITH_PARENT, 284 GTK_DIALOG_DESTROY_WITH_PARENT,
279 mtype, 285 mtype,
280 GTK_BUTTONS_CLOSE, 286 btype,
281 "%s", str); 287 "%s", str);
282 g_free(str); 288 g_free(str);
283 gtk_dialog_run(GTK_DIALOG(dialog)); 289 result = gtk_dialog_run(GTK_DIALOG(dialog));
284 gtk_widget_destroy(dialog); 290 gtk_widget_destroy(dialog);
291
292 return result;
285} 293}
286 294
287gchar *trace_get_file_dialog(const gchar *title) 295/**
296 * trace_get_file_dialog - pop up a file dialog to get a file
297 * @title: the title of the dialog
298 * @open: the text for the "open" button (NULL for default)
299 * @warn: if the file exists, warn and let them choose again.
300 *
301 * Returns: the filename if it should be used. NULL otherwise.
302 * The filename needs to be freed with g_free().
303 */
304gchar *trace_get_file_dialog(const gchar *title, const char *open,
305 gboolean warn)
288{ 306{
289 GtkWidget *dialog; 307 GtkWidget *dialog;
308 GtkResponseType ret;
290 gchar *filename = NULL; 309 gchar *filename = NULL;
291 310
311 if (!open)
312 open = GTK_STOCK_OPEN;
313
292 dialog = gtk_file_chooser_dialog_new(title, 314 dialog = gtk_file_chooser_dialog_new(title,
293 NULL, 315 NULL,
294 GTK_FILE_CHOOSER_ACTION_OPEN, 316 GTK_FILE_CHOOSER_ACTION_OPEN,
295 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 317 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
296 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 318 open, GTK_RESPONSE_ACCEPT,
297 NULL); 319 NULL);
298 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) 320
321 again:
322 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
299 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 323 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
324 if (warn) {
325 ret = trace_dialog(GTK_WINDOW(dialog), TRACE_GUI_ASK,
326 "The file '%s' already exists.\n"
327 "Are you sure you want to replace it",
328 filename);
329 if (ret == GTK_RESPONSE_NO) {
330 g_free(filename);
331 filename = NULL;
332 goto again;
333 }
334 }
335 }
300 336
301 gtk_widget_destroy(dialog); 337 gtk_widget_destroy(dialog);
302 338