~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/rb-dialog.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  arch-tag: Implementation of Rhythmbox dialog wrapper functions
3
 
 *
4
 
 *  Copyright (C) 2002 Jorn Baayen
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2, or (at your option)
9
 
 *  any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 
 *
20
 
 */
21
 
 
22
 
#include <config.h>
23
 
#include <libgnome/gnome-i18n.h>
24
 
#include <gtk/gtk.h>
25
 
#include <glib.h>
26
 
#include <stdio.h>
27
 
#include <string.h>
28
 
#include <stdarg.h>
29
 
 
30
 
#include "rb-dialog.h"
31
 
#include "rb-stock-icons.h"
32
 
 
33
 
static void rb_dialog (const char *format, va_list args, GtkMessageType type);
34
 
 
35
 
void
36
 
rb_error_dialog (const char *format, ...)
37
 
{
38
 
        va_list args;
39
 
 
40
 
        va_start (args, format);
41
 
 
42
 
        rb_dialog (format, args, GTK_MESSAGE_ERROR);
43
 
 
44
 
        va_end (args);
45
 
}
46
 
 
47
 
void
48
 
rb_warning_dialog (const char *format, ...)
49
 
{
50
 
        va_list args;
51
 
 
52
 
        va_start (args, format);
53
 
 
54
 
        rb_dialog (format, args, GTK_MESSAGE_WARNING);
55
 
 
56
 
        va_end (args);
57
 
}
58
 
 
59
 
void
60
 
rb_message_dialog (const char *format, ...)
61
 
{
62
 
        va_list args;
63
 
 
64
 
        va_start (args, format);
65
 
 
66
 
        rb_dialog (format, args, GTK_MESSAGE_INFO);
67
 
 
68
 
        va_end (args);
69
 
}
70
 
 
71
 
static void
72
 
rb_dialog (const char *format, va_list args, GtkMessageType type)
73
 
{
74
 
        GtkWidget *dialog;
75
 
        char buffer[1025];
76
 
 
77
 
        g_vsnprintf (buffer, 1024, format, args);
78
 
 
79
 
        dialog = gtk_message_dialog_new (NULL,
80
 
                                         GTK_DIALOG_MODAL,
81
 
                                         type,
82
 
                                         GTK_BUTTONS_OK,
83
 
                                         "%s",
84
 
                                         buffer);
85
 
 
86
 
        g_signal_connect_swapped (GTK_OBJECT (dialog), "response",
87
 
                                  G_CALLBACK (gtk_widget_destroy),
88
 
                                  GTK_OBJECT (dialog));
89
 
 
90
 
        gtk_widget_show (GTK_WIDGET (dialog));
91
 
}
92
 
 
93
 
static GtkWidget *
94
 
rb_ask_file_internal (const char *title,
95
 
                      const char *default_file,
96
 
                      GtkWindow *parent,
97
 
                      gboolean multiple,
98
 
                      gboolean want_dir)
99
 
{
100
 
        GtkWidget *filesel;
101
 
 
102
 
#ifndef HAVE_GTK_2_3
103
 
        filesel = gtk_file_selection_new (title);
104
 
        if (default_file != NULL)
105
 
                gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), default_file);
106
 
 
107
 
        gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (filesel));
108
 
#else
109
 
        {
110
 
                GtkFileChooserAction mode;
111
 
                if (want_dir) {
112
 
                        mode = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
113
 
                } else {
114
 
                        mode = GTK_FILE_CHOOSER_ACTION_OPEN;
115
 
                }
116
 
                
117
 
                filesel = gtk_file_chooser_dialog_new (title, 
118
 
                                                       parent, 
119
 
                                                       mode,
120
 
                                                       GTK_STOCK_CANCEL, 
121
 
                                                       GTK_RESPONSE_CANCEL,
122
 
                                                       GTK_STOCK_OPEN, 
123
 
                                                       GTK_RESPONSE_OK,
124
 
                                                       NULL);
125
 
                gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (filesel),
126
 
                                                 FALSE);
127
 
        }
128
 
 
129
 
        if (default_file != NULL)
130
 
                gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (filesel),
131
 
                                                         default_file);
132
 
 
133
 
        gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (filesel), multiple);
134
 
 
135
 
        gtk_dialog_set_default_response (GTK_DIALOG (filesel),
136
 
                                         GTK_RESPONSE_OK);
137
 
#endif
138
 
        gtk_window_set_transient_for (GTK_WINDOW (filesel),
139
 
                                      parent);
140
 
        gtk_window_set_modal (GTK_WINDOW (filesel),
141
 
                              FALSE);
142
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (filesel),
143
 
                                            TRUE);
144
 
        
145
 
        gtk_widget_show_all (filesel);
146
 
 
147
 
        return filesel;
148
 
}
149
 
 
150
 
GtkWidget *
151
 
rb_ask_file (const char *title,
152
 
             const char *default_file,
153
 
             GtkWindow *parent)
154
 
{
155
 
        return rb_ask_file_internal (title, default_file, parent, FALSE, FALSE);
156
 
}
157
 
 
158
 
GtkWidget *
159
 
rb_ask_file_save (const char *title,
160
 
                  const char *default_file,
161
 
                  GtkWindow *parent)
162
 
{
163
 
#ifndef HAVE_GTK_2_3
164
 
        return rb_ask_file_internal (title, default_file, parent, FALSE, FALSE);
165
 
#else
166
 
        GtkWidget *filesel;
167
 
        filesel = gtk_file_chooser_dialog_new (title, 
168
 
                                               parent, 
169
 
                                               GTK_FILE_CHOOSER_ACTION_SAVE,
170
 
                                               GTK_STOCK_CANCEL, 
171
 
                                               GTK_RESPONSE_CANCEL,
172
 
                                               GTK_STOCK_SAVE, 
173
 
                                               GTK_RESPONSE_OK,
174
 
                                               NULL);
175
 
        if (default_file != NULL)
176
 
                gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (filesel),
177
 
                                                         default_file);
178
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (filesel), TRUE);
179
 
        
180
 
        gtk_widget_show_all (filesel);
181
 
        return filesel;
182
 
#endif
183
 
}
184
 
 
185
 
GtkWidget *
186
 
rb_ask_file_multiple (const char *title,
187
 
                      const char *default_file,
188
 
                      GtkWindow *parent)
189
 
{
190
 
        return rb_ask_file_internal (title, default_file, parent, TRUE, FALSE);
191
 
}
192
 
 
193
 
GtkWidget *
194
 
rb_ask_dir (const char *title,
195
 
            const char *default_file,
196
 
            GtkWindow *parent)
197
 
{
198
 
        return rb_ask_file_internal (title, default_file, parent, FALSE, TRUE);
199
 
}
200
 
 
201
 
GtkWidget *
202
 
rb_ask_dir_multiple (const char *title,
203
 
                     const char *default_file,
204
 
                     GtkWindow *parent)
205
 
{
206
 
        return rb_ask_file_internal (title, default_file, parent, TRUE, TRUE);
207
 
}
208
 
 
209
 
GtkWidget *
210
 
rb_ask_string (const char *question,
211
 
               const char *accept_button_text,
212
 
               const char *default_text,
213
 
               GtkWindow *parent)
214
 
{
215
 
        GtkWidget *dialog, *hbox, *image, *entry, *label, *vbox;
216
 
        char *tmp;
217
 
 
218
 
        dialog = gtk_dialog_new_with_buttons ("",
219
 
                                              NULL,
220
 
                                              0,
221
 
                                              GTK_STOCK_CANCEL,
222
 
                                              GTK_RESPONSE_CANCEL,
223
 
                                              accept_button_text,
224
 
                                              GTK_RESPONSE_OK,
225
 
                                              NULL);
226
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
227
 
                                         GTK_RESPONSE_OK);
228
 
        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
229
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
230
 
        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 12);
231
 
 
232
 
        gtk_window_set_transient_for (GTK_WINDOW (dialog),
233
 
                                      parent);
234
 
        gtk_window_set_modal (GTK_WINDOW (dialog),
235
 
                              FALSE);
236
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog),
237
 
                                            TRUE);
238
 
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
239
 
 
240
 
        hbox = gtk_hbox_new (FALSE, 12);
241
 
        gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
242
 
        image = gtk_image_new_from_stock (RB_STOCK_PLAYLIST,
243
 
                                          GTK_ICON_SIZE_DIALOG);
244
 
        gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
245
 
 
246
 
        vbox = gtk_vbox_new (FALSE, 0);
247
 
 
248
 
        tmp = g_strdup_printf ("%s\n", question);
249
 
        label = gtk_label_new (tmp);
250
 
        g_free (tmp);
251
 
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
252
 
        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
253
 
 
254
 
        entry = gtk_entry_new ();
255
 
        gtk_entry_set_text (GTK_ENTRY (entry), default_text);
256
 
        gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
257
 
        gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, TRUE, 0);
258
 
 
259
 
        gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
260
 
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox);
261
 
        gtk_widget_show_all (hbox);
262
 
 
263
 
        gtk_widget_grab_focus (entry);
264
 
 
265
 
        g_object_set_data (G_OBJECT (dialog), "entry", entry);
266
 
 
267
 
        gtk_widget_show_all (dialog);
268
 
 
269
 
        return dialog;
270
 
}