[evolution-patches] Patch for #ifdef'ed GtkFileChooser support
- From: Carlos Garnacho <garnacho tuxerver net>
- To: Patches <evolution-patches ximian com>
- Subject: [evolution-patches] Patch for #ifdef'ed GtkFileChooser support
- Date: Wed, 21 Jul 2004 11:19:38 +0200
Hi,
I've attached a patch for using GtkFileChooser if the Gtk+ version that
evo has been compiled against is >= 2.4.0, if not, it will use
GtkFileSelection. Seems OK to you?
Carlos
Index: addressbook/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1795
diff -u -r1.1795 ChangeLog
--- addressbook/ChangeLog 20 Jul 2004 16:36:18 -0000 1.1795
+++ addressbook/ChangeLog 20 Jul 2004 20:34:16 -0000
@@ -1,3 +1,8 @@
+2004-07-20 Carlos Garnacho Parro <carlosg gnome org>
+
+ * gui/widgets/eab-gui-util.c: Optionally use GtkFileChooser if
+ compiled against Gtk+ >= 2.4.0
+
2004-07-20 JP Rosevear <jpr novell com>
* gui/component/autocompletion-config.c
Index: addressbook/gui/widgets/eab-gui-util.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/eab-gui-util.c,v
retrieving revision 1.24
diff -u -r1.24 eab-gui-util.c
--- addressbook/gui/widgets/eab-gui-util.c 23 Jun 2004 22:59:21 -0000 1.24
+++ addressbook/gui/widgets/eab-gui-util.c 20 Jul 2004 20:34:19 -0000
@@ -289,12 +289,12 @@
static gint
-file_exists(GtkFileSelection *filesel, const char *filename)
+file_exists(GtkWindow *window, const char *filename)
{
GtkWidget *dialog;
gint response;
- dialog = gtk_message_dialog_new (GTK_WINDOW (filesel),
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
0,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
@@ -311,7 +311,7 @@
}
typedef struct {
- GtkFileSelection *filesel;
+ GtkWidget *filesel;
char *vcard;
} SaveAsInfo;
@@ -320,13 +320,17 @@
{
gint error = 0;
gint response = 0;
-
- const char *filename = gtk_file_selection_get_filename (info->filesel);
+
+#if GTK_CHECK_VERSION(2,4,0)
+ const char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (info->filesel));
+#else
+ const char *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (info->filesel));
+#endif
error = e_write_file (filename, info->vcard, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC);
if (error == EEXIST) {
- response = file_exists(info->filesel, filename);
+ response = file_exists(GTK_WINDOW (info->filesel), filename);
switch (response) {
case GTK_RESPONSE_ACCEPT : /* Overwrite */
e_write_file(filename, info->vcard, O_WRONLY | O_CREAT | O_TRUNC);
@@ -356,25 +360,33 @@
g_free (info);
}
+#if GTK_CHECK_VERSION(2,4,0)
+static void
+filechooser_response (GtkWidget *widget, gint response_id, SaveAsInfo *info)
+{
+ if (response_id == GTK_RESPONSE_ACCEPT)
+ save_it (widget, info);
+ else
+ close_it (widget, info);
+}
+#endif
+
static char *
-make_safe_filename (const char *prefix, char *name)
+make_safe_filename (char *name)
{
- char *safe, *p;
+ char *safe;
if (!name) {
/* This is a filename. Translators take note. */
name = _("card.vcf");
}
- p = strrchr (name, '/');
- if (p)
- safe = g_strdup_printf ("%s%s%s", prefix, p, ".vcf");
+ if (!g_strrstr (name, ".vcf"))
+ safe = g_strdup_printf ("%s%s", name, ".vcf");
else
- safe = g_strdup_printf ("%s/%s%s", prefix, name, ".vcf");
-
- p = strrchr (safe, '/') + 1;
- if (p)
- e_filename_make_safe (p);
+ safe = g_strdup (name);
+
+ e_filename_make_safe (safe);
return safe;
}
@@ -447,26 +459,48 @@
void
eab_contact_save (char *title, EContact *contact, GtkWindow *parent_window)
{
- GtkFileSelection *filesel;
- char *file;
+ GtkWidget *filesel;
+ char *file, *full_filename;
char *name;
SaveAsInfo *info = g_new(SaveAsInfo, 1);
- filesel = GTK_FILE_SELECTION(gtk_file_selection_new(title));
-
name = e_contact_get (contact, E_CONTACT_FILE_AS);
- file = make_safe_filename (g_get_home_dir(), name);
- gtk_file_selection_set_filename (filesel, file);
- g_free (file);
+ file = make_safe_filename (name);
+
+#if GTK_CHECK_VERSION(2,4,0)
+ filesel = gtk_file_chooser_dialog_new (title,
+ parent_window,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_ACCEPT);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filesel), g_get_home_dir ());
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filesel), file);
+
info->filesel = filesel;
info->vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
- g_signal_connect(filesel->ok_button, "clicked",
+ g_signal_connect (G_OBJECT (filesel), "response",
+ G_CALLBACK (filechooser_response), info);
+ g_object_weak_ref (G_OBJECT (filesel), destroy_it, info);
+#else
+ filesel = gtk_file_selection_new (title);
+
+ full_filename = g_strdup_printf ("%s/%s", g_get_home_dir (), file);
+ gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), full_filename);
+ g_free (full_filename);
+
+ info->filesel = filesel;
+ info->vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
+
+ g_signal_connect(G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button), "clicked",
G_CALLBACK (save_it), info);
- g_signal_connect(filesel->cancel_button, "clicked",
+ g_signal_connect(G_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button), "clicked",
G_CALLBACK (close_it), info);
g_object_weak_ref (G_OBJECT (filesel), destroy_it, info);
+#endif
if (parent_window) {
gtk_window_set_transient_for (GTK_WINDOW (filesel),
@@ -475,41 +509,63 @@
}
gtk_widget_show(GTK_WIDGET(filesel));
+ g_free (file);
}
void
eab_contact_list_save (char *title, GList *list, GtkWindow *parent_window)
{
- GtkFileSelection *filesel;
+ GtkWidget *filesel;
SaveAsInfo *info = g_new(SaveAsInfo, 1);
+ char *file, *full_filename;
- filesel = GTK_FILE_SELECTION(gtk_file_selection_new(title));
+#if GTK_CHECK_VERSION(2,4,0)
+ filesel = gtk_file_chooser_dialog_new (title,
+ parent_window,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_ACCEPT);
+#else
+ filesel = gtk_file_selection_new(title);
+#endif
/* This is a filename. Translators take note. */
if (list && list->data && list->next == NULL) {
- char *name, *file;
+ char *name;
name = e_contact_get (E_CONTACT (list->data), E_CONTACT_FILE_AS);
if (!name)
name = e_contact_get (E_CONTACT (list->data), E_CONTACT_FULL_NAME);
- file = make_safe_filename (g_get_home_dir(), name);
- gtk_file_selection_set_filename (filesel, file);
- g_free (file);
+ file = make_safe_filename (name);
} else {
- char *file;
- file = make_safe_filename (g_get_home_dir(), _("list"));
- gtk_file_selection_set_filename (filesel, file);
- g_free (file);
+ file = make_safe_filename (_("list"));
}
+#if GTK_CHECK_VERSION(2,4,0)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filesel), g_get_home_dir ());
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filesel), file);
+#else
+ full_filename = g_strdup_printf ("%s/%s", g_get_home_dir (), file);
+ gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), full_filename);
+ g_free (full_filename);
+#endif
+
info->filesel = filesel;
info->vcard = eab_contact_list_to_string (list);
-
- g_signal_connect(filesel->ok_button, "clicked",
+
+#if GTK_CHECK_VERSION(2,4,0)
+ g_signal_connect (G_OBJECT (filesel), "response",
+ G_CALLBACK (filechooser_response), info);
+ g_object_weak_ref (G_OBJECT (filesel), destroy_it, info);
+#else
+ g_signal_connect(G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button), "clicked",
G_CALLBACK (save_it), info);
- g_signal_connect(filesel->cancel_button, "clicked",
+ g_signal_connect(G_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button), "clicked",
G_CALLBACK (close_it), info);
g_object_weak_ref (G_OBJECT (filesel), destroy_it, info);
+#endif
if (parent_window) {
gtk_window_set_transient_for (GTK_WINDOW (filesel),
@@ -518,6 +574,7 @@
}
gtk_widget_show(GTK_WIDGET(filesel));
+ g_free (file);
}
typedef struct ContactCopyProcess_ ContactCopyProcess;
Index: composer/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/composer/ChangeLog,v
retrieving revision 1.651
diff -u -r1.651 ChangeLog
--- composer/ChangeLog 18 Jun 2004 05:59:16 -0000 1.651
+++ composer/ChangeLog 20 Jul 2004 20:34:26 -0000
@@ -1,3 +1,12 @@
+2004-07-20 Carlos Garnacho Parro <carlosg gnome org>
+
+ * e-msg-composer-select-file.[ch]: Optionally use GtkFileChooser if
+ compiled against Gtk+ >= 2.4.0. (e_msg_composer_select_file): added
+ save_mode parameter
+
+ * e-msg-composer: use the modified e_msg_composer_select_file()
+ function
+
2004-06-18 Not Zed <NotZed Ximian com>
** Fix for #60387.
Index: composer/e-msg-composer-select-file.c
===================================================================
RCS file: /cvs/gnome/evolution/composer/e-msg-composer-select-file.c,v
retrieving revision 1.27
diff -u -r1.27 e-msg-composer-select-file.c
--- composer/e-msg-composer-select-file.c 19 Apr 2004 15:20:26 -0000 1.27
+++ composer/e-msg-composer-select-file.c 20 Jul 2004 20:34:26 -0000
@@ -29,57 +29,108 @@
#include <gtk/gtkbox.h>
#include <gtk/gtkcheckbutton.h>
-#include <gtk/gtkfilesel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
+#include <gtk/gtkversion.h>
+
+#if GTK_CHECK_VERSION(2,4,0)
+#include <gtk/gtkfilechooser.h>
+#include <gtk/gtkfilechooserdialog.h>
+#include <gtk/gtkstock.h>
+#else
+#include <gtk/gtkfilesel.h>
+#endif
#include <libgnomeui/gnome-uidefs.h>
#include "e-msg-composer-select-file.h"
#include <e-util/e-icon-factory.h>
-static GtkFileSelection *
-run_selector(EMsgComposer *composer, const char *title, int multi, gboolean *showinline_p)
+static GtkWidget*
+run_selector(EMsgComposer *composer, const char *title, int multi, gboolean *showinline_p, gboolean save_mode)
{
- GtkFileSelection *selection;
+ GtkWidget *selection;
GtkWidget *showinline = NULL;
char *path;
GList *icon_list;
+ path = g_object_get_data((GObject *)composer, "attach_path");
+
+#if GTK_CHECK_VERSION(2,4,0)
+ if (save_mode)
+ selection = gtk_file_chooser_dialog_new (title,
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+ NULL);
+ else
+ selection = gtk_file_chooser_dialog_new (title,
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (selection), GTK_RESPONSE_OK);
+
+ if (!save_mode)
+ gtk_file_chooser_set_select_multiple((GtkFileChooser *) selection, multi);
+
+ /* restore last path used */
+ if (!path)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (selection), g_get_home_dir ());
+ else
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (selection), path);
+
+ if (showinline_p) {
+ showinline = gtk_check_button_new_with_label (_("Suggest automatic display of attachment"));
+ gtk_widget_show (showinline);
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (selection), showinline);
+ }
+#else
selection = (GtkFileSelection *)gtk_file_selection_new(title);
- gtk_window_set_transient_for((GtkWindow *)selection, (GtkWindow *)composer);
- gtk_window_set_wmclass((GtkWindow *)selection, "fileselection", "Evolution:composer");
- gtk_window_set_modal((GtkWindow *)selection, TRUE);
-
- icon_list = e_icon_factory_get_icon_list ("stock_mail-compose");
- if (icon_list) {
- gtk_window_set_icon_list (GTK_WINDOW (selection), icon_list);
- g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
- g_list_free (icon_list);
- }
-
+
gtk_file_selection_set_select_multiple((GtkFileSelection *)selection, multi);
/* restore last path used */
- path = g_object_get_data((GObject *)composer, "attach_path");
- if (path == NULL) {
+ if (!path) {
path = g_strdup_printf("%s/", g_get_home_dir());
- gtk_file_selection_set_filename(selection, path);
- g_free(path);
+ gtk_file_selection_set_filename(GTK_FILE_SELECTION (selection), path);
+ g_free (path);
} else {
- gtk_file_selection_set_filename(selection, path);
+ gtk_file_selection_set_filename(GTK_FILE_SELECTION (selection), path);
}
if (showinline_p) {
showinline = gtk_check_button_new_with_label (_("Suggest automatic display of attachment"));
gtk_widget_show (showinline);
- gtk_box_pack_end (GTK_BOX (selection->main_vbox), showinline, FALSE, FALSE, 4);
+ gtk_box_pack_end (GTK_BOX (GTK_FILE_SELECTION (selection)->main_vbox), showinline, FALSE, FALSE, 4);
}
+#endif
+
+ gtk_window_set_transient_for((GtkWindow *)selection, (GtkWindow *)composer);
+ gtk_window_set_wmclass((GtkWindow *)selection, "fileselection", "Evolution:composer");
+ gtk_window_set_modal((GtkWindow *)selection, TRUE);
+
+ icon_list = e_icon_factory_get_icon_list ("stock_mail-compose");
+ if (icon_list) {
+ gtk_window_set_icon_list (GTK_WINDOW (selection), icon_list);
+ g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
+ g_list_free (icon_list);
+ }
+
if (gtk_dialog_run((GtkDialog *)selection) == GTK_RESPONSE_OK) {
if (showinline_p)
*showinline_p = gtk_toggle_button_get_active((GtkToggleButton *)showinline);
- path = g_path_get_dirname(gtk_file_selection_get_filename(selection));
+
+#if GTK_CHECK_VERSION(2,4,0)
+ path = g_path_get_dirname(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selection)));
+#else
+ path = g_path_get_dirname(gtk_file_selection_get_filename(GTK_FILE_SELECTION (selection)));
+#endif
+
g_object_set_data_full((GObject *)composer, "attach_path", g_strdup_printf("%s/", path), g_free);
g_free(path);
} else {
@@ -94,6 +145,7 @@
* e_msg_composer_select_file:
* @composer: a composer
* @title: the title for the file selection dialog box
+ * @save_mode: whether the file selection box should be shown in save mode or not
*
* This pops up a file selection dialog box with the given title
* and allows the user to select a file.
@@ -102,14 +154,18 @@
* cancelled.
**/
char *
-e_msg_composer_select_file (EMsgComposer *composer, const char *title)
+e_msg_composer_select_file (EMsgComposer *composer, const char *title, gboolean save_mode)
{
- GtkFileSelection *selection;
+ GtkWidget *selection;
char *name = NULL;
- selection = run_selector (composer, title, TRUE, NULL);
+ selection = run_selector (composer, title, TRUE, FALSE, save_mode);
if (selection) {
- name = g_strdup(gtk_file_selection_get_filename(selection));
+#if GTK_CHECK_VERSION(2,4,0)
+ name = g_strdup (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selection)));
+#else
+ name = g_strdup (gtk_file_selection_get_filename(GTK_FILE_SELECTION (selection)));
+#endif
gtk_widget_destroy((GtkWidget *)selection);
}
@@ -119,22 +175,42 @@
GPtrArray *
e_msg_composer_select_file_attachments (EMsgComposer *composer, gboolean *showinline_p)
{
- GtkFileSelection *selection;
+ GtkWidget *selection;
GPtrArray *list = NULL;
- char **files;
- int i;
- selection = run_selector(composer, _("Attach file(s)"), TRUE, showinline_p);
+ selection = run_selector(composer, _("Attach file(s)"), TRUE, showinline_p, FALSE);
+
if (selection) {
- files = gtk_file_selection_get_selections(selection);
+#if GTK_CHECK_VERSION(2,4,0)
+ GSList *files, *l;
+
+ files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (selection));
+
+ if (files) {
+ list = g_ptr_array_new ();
+ l = files;
+
+ while (l) {
+ g_ptr_array_add (list, l->data);
+ l = l->next;
+ }
+
+ g_slist_free (files);
+ }
+#else
+ char **files;
+ int i;
+
+ files = gtk_file_selection_get_selections(GTK_FILE_SELECTION (selection));
- if (files != NULL) {
+ if (files) {
list = g_ptr_array_new ();
for (i = 0; files[i]; i++)
g_ptr_array_add (list, g_strdup (files[i]));
g_strfreev (files);
}
+#endif
gtk_widget_destroy((GtkWidget *)selection);
}
Index: composer/e-msg-composer-select-file.h
===================================================================
RCS file: /cvs/gnome/evolution/composer/e-msg-composer-select-file.h,v
retrieving revision 1.5
diff -u -r1.5 e-msg-composer-select-file.h
--- composer/e-msg-composer-select-file.h 11 Dec 2001 01:01:05 -0000 1.5
+++ composer/e-msg-composer-select-file.h 20 Jul 2004 20:34:26 -0000
@@ -27,7 +27,8 @@
#include "e-msg-composer.h"
char *e_msg_composer_select_file (EMsgComposer *composer,
- const char *title);
+ const char *title,
+ gboolean save_mode);
GPtrArray *e_msg_composer_select_file_attachments (EMsgComposer *composer,
gboolean *inline_p);
Index: composer/e-msg-composer.c
===================================================================
RCS file: /cvs/gnome/evolution/composer/e-msg-composer.c,v
retrieving revision 1.474
diff -u -r1.474 e-msg-composer.c
--- composer/e-msg-composer.c 18 Jun 2004 05:59:16 -0000 1.474
+++ composer/e-msg-composer.c 20 Jul 2004 20:34:38 -0000
@@ -1190,7 +1190,7 @@
if (default_filename != NULL)
filename = g_strdup (default_filename);
else
- filename = e_msg_composer_select_file (composer, _("Save as..."));
+ filename = e_msg_composer_select_file (composer, _("Save as..."), TRUE);
if (filename == NULL)
return;
@@ -1588,7 +1588,7 @@
composer = E_MSG_COMPOSER (data);
- file_name = e_msg_composer_select_file (composer, _("Open file"));
+ file_name = e_msg_composer_select_file (composer, _("Open file"), FALSE);
if (file_name == NULL)
return;
Index: e-util/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/e-util/ChangeLog,v
retrieving revision 1.471
diff -u -r1.471 ChangeLog
--- e-util/ChangeLog 14 Jul 2004 15:19:58 -0000 1.471
+++ e-util/ChangeLog 20 Jul 2004 20:34:41 -0000
@@ -1,3 +1,8 @@
+2004-07-20 Carlos Garnacho Parro <carlosg gnome org>
+
+ * e-dialog-utils.c: Optionally use GtkFileChooser if compiled
+ against Gtk+ >= 2.4.0
+
2004-07-12 Dan Winship <danw novell com>
* e-mktemp.c (e_mktemp, e_mkdtemp): un-const the return values,
Index: e-util/e-dialog-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-dialog-utils.c,v
retrieving revision 1.18
diff -u -r1.18 e-dialog-utils.c
--- e-util/e-dialog-utils.c 9 Mar 2004 21:10:42 -0000 1.18
+++ e-util/e-dialog-utils.c 20 Jul 2004 20:34:41 -0000
@@ -26,9 +26,17 @@
#include <gdk/gdkx.h>
-#include <gtk/gtkfilesel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkplug.h>
+#include <gtk/gtkversion.h>
+
+#if GTK_CHECK_VERSION(2,4,0)
+#include <gtk/gtkfilechooser.h>
+#include <gtk/gtkfilechooserdialog.h>
+#include <gtk/gtkstock.h>
+#else
+#include <gtk/gtkfilesel.h>
+#endif
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
@@ -238,7 +246,11 @@
int btn = GTK_RESPONSE_YES;
fs = gtk_widget_get_toplevel (widget);
+#if GTK_CHECK_VERSION(2,4,0)
+ path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs));
+#else
path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
+#endif
if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
GtkWidget *dlg;
@@ -261,25 +273,49 @@
gtk_main_quit ();
}
+#if GTK_CHECK_VERSION(2,4,0)
+static void
+filechooser_response (GtkWidget *fc, gint response_id, gpointer data)
+{
+ if (response_id == GTK_RESPONSE_ACCEPT)
+ save_ok (fc, data);
+ else
+ gtk_widget_destroy (fc);
+}
+#endif
+
char *
e_file_dialog_save (const char *title)
{
- GtkFileSelection *fs;
+ GtkWidget *selection;
char *path, *filename = NULL;
-
- fs = GTK_FILE_SELECTION (gtk_file_selection_new (title));
+
+#if GTK_CHECK_VERSION(2,4,0)
+ selection = gtk_file_chooser_dialog_new (title,
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (selection), GTK_RESPONSE_ACCEPT);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (selection), g_get_home_dir ());
+
+ g_signal_connect (G_OBJECT (selection), "response", G_CALLBACK (filechooser_response), &filename);
+#else
+ selection = gtk_file_selection_new (title);
path = g_strdup_printf ("%s/", g_get_home_dir ());
- gtk_file_selection_set_filename (fs, path);
+ gtk_file_selection_set_filename (GTK_FILE_SELECTION (selection), path);
g_free (path);
+
+ g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (selection)->ok_button), "clicked", G_CALLBACK (save_ok), &filename);
+ g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (selection)->cancel_button), "clicked", G_CALLBACK (gtk_main_quit), NULL);
+#endif
- g_signal_connect (fs->ok_button, "clicked", G_CALLBACK (save_ok), &filename);
- g_signal_connect (fs->cancel_button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
-
- gtk_widget_show (GTK_WIDGET (fs));
- gtk_grab_add (GTK_WIDGET (fs));
+ gtk_widget_show (GTK_WIDGET (selection));
+ gtk_grab_add (GTK_WIDGET (selection));
gtk_main ();
- gtk_widget_destroy (GTK_WIDGET (fs));
+ gtk_widget_destroy (GTK_WIDGET (selection));
return filename;
}
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3416
diff -u -r1.3416 ChangeLog
--- mail/ChangeLog 16 Jul 2004 16:03:44 -0000 1.3416
+++ mail/ChangeLog 20 Jul 2004 20:35:03 -0000
@@ -1,3 +1,8 @@
+2004-07-20 Carlos Garnacho Parro <carlosg gnome org>
+
+ * em-utils.c: Optionally use GtkFileChooser if compiled against
+ Gtk+ >= 2.4.0
+
2004-07-13 Jeffrey Stedfast <fejj novell com>
* em-folder-view.c (emfv_message_reply): Chck that the selection
Index: mail/em-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-utils.c,v
retrieving revision 1.44
diff -u -r1.44 em-utils.c
--- mail/em-utils.c 14 Jul 2004 15:20:19 -0000 1.44
+++ mail/em-utils.c 20 Jul 2004 20:35:07 -0000
@@ -297,36 +297,53 @@
/* Saving messages... */
-static GtkFileSelection *
+static GtkWidget *
emu_get_save_filesel (GtkWidget *parent, const char *title, const char *name)
{
- GtkFileSelection *filesel;
- char *gdir, *mname = NULL, *filename;
- const char *realname, *dir;
+ GtkWidget *filesel;
+ const char *dir;
+ char *realname, *filename;
GConfClient *gconf;
- filesel = (GtkFileSelection *)gtk_file_selection_new(title);
+#if GTK_CHECK_VERSION(2,4,0)
+ filesel = gtk_file_chooser_dialog_new (title,
+ GTK_WINDOW (parent),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
+#else
+ filesel = gtk_file_selection_new(title);
+#endif
+
if (parent)
e_dialog_set_transient_for((GtkWindow *)filesel, parent);
gconf = gconf_client_get_default();
- dir = gdir = gconf_client_get_string(gconf, "/apps/evolution/mail/save_dir", NULL);
+ dir = gconf_client_get_string(gconf, "/apps/evolution/mail/save_dir", NULL);
g_object_unref(gconf);
+
if (dir == NULL)
dir = g_get_home_dir();
if (name && name[0]) {
- realname = mname = g_strdup(name);
- e_filename_make_safe(mname);
+ realname = g_strdup(name);
+ e_filename_make_safe(realname);
} else {
- realname = "/";
+ realname = NULL;
}
- filename = g_build_filename(dir, realname, NULL);
- gtk_file_selection_set_filename(filesel, filename);
+#if GTK_CHECK_VERSION(2,4,0)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filesel), dir);
+
+ if (realname)
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filesel), realname);
+#else
+ filename = g_build_filename(dir, G_DIR_SEPARATOR_S, realname, NULL);
+ gtk_file_selection_set_filename(GTK_FILE_SELECTION (filesel), filename);
g_free(filename);
- g_free(mname);
- g_free (gdir);
+#endif
return filesel;
}
@@ -367,10 +384,17 @@
}
static void
-emu_save_part_response(GtkFileSelection *filesel, int response, CamelMimePart *part)
+emu_save_part_response(GtkWidget *filesel, int response, CamelMimePart *part)
{
+ const char *path;
+
if (response == GTK_RESPONSE_OK) {
- const char *path = gtk_file_selection_get_filename(filesel);
+
+#if GTK_CHECK_VERSION(2,4,0)
+ path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filesel));
+#else
+ path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#endif
if (!emu_can_save((GtkWindow *)filesel, path))
return;
@@ -396,7 +420,7 @@
em_utils_save_part(GtkWidget *parent, const char *prompt, CamelMimePart *part)
{
const char *name;
- GtkFileSelection *filesel;
+ GtkWidget *filesel;
name = camel_mime_part_get_filename(part);
if (name == NULL) {
@@ -411,8 +435,8 @@
filesel = emu_get_save_filesel(parent, prompt, name);
camel_object_ref(part);
- g_signal_connect(filesel, "response", G_CALLBACK(emu_save_part_response), part);
- gtk_widget_show((GtkWidget *)filesel);
+ g_signal_connect(G_OBJECT (filesel), "response", G_CALLBACK(emu_save_part_response), part);
+ gtk_widget_show(filesel);
}
/**
@@ -468,10 +492,16 @@
};
static void
-emu_save_messages_response(GtkFileSelection *filesel, int response, struct _save_messages_data *data)
+emu_save_messages_response(GtkWidget *filesel, int response, struct _save_messages_data *data)
{
+ const char *path;
+
if (response == GTK_RESPONSE_OK) {
- const char *path = gtk_file_selection_get_filename(filesel);
+#if GTK_CHECK_VERSION(2,4,0)
+ path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filesel));
+#else
+ path = gtk_file_selection_get_filename(GTK_FILE_SELECTION (filesel));
+#endif
if (!emu_can_save((GtkWindow *)filesel, path))
return;
@@ -501,7 +531,7 @@
em_utils_save_messages (GtkWidget *parent, CamelFolder *folder, GPtrArray *uids)
{
struct _save_messages_data *data;
- GtkFileSelection *filesel;
+ GtkWidget *filesel;
g_return_if_fail (CAMEL_IS_FOLDER (folder));
g_return_if_fail (uids != NULL);
Index: smime/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/smime/ChangeLog,v
retrieving revision 1.37
diff -u -r1.37 ChangeLog
--- smime/ChangeLog 19 Jul 2004 19:01:52 -0000 1.37
+++ smime/ChangeLog 20 Jul 2004 20:35:09 -0000
@@ -1,3 +1,8 @@
+2004-07-20 Carlos Garnacho Parro <carlosg gnome org>
+
+ * gui/certificate-manager.c: Optionally use GtkFileChooser if
+ compiled against Gtk+ >= 2.4.0
+
2004-07-16 Chris Toshok <toshok ximian com>
[ fixes #61490 ]
Index: smime/gui/certificate-manager.c
===================================================================
RCS file: /cvs/gnome/evolution/smime/gui/certificate-manager.c,v
retrieving revision 1.13
diff -u -r1.13 certificate-manager.c
--- smime/gui/certificate-manager.c 28 May 2004 09:27:06 -0000 1.13
+++ smime/gui/certificate-manager.c 20 Jul 2004 20:35:12 -0000
@@ -127,10 +127,28 @@
static void
import_your (GtkWidget *widget, CertificateManagerData *cfm)
{
- GtkWidget *filesel = gtk_file_selection_new (_("Select a cert to import..."));
+ GtkWidget *filesel;
+ const char *filename;
+
+#if GTK_CHECK_VERSION(2,4,0)
+ filesel = gtk_file_chooser_dialog_new (_("Select a cert to import..."),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
+#else
+ filesel = gtk_file_selection_new (_("Select a cert to import..."));
+#endif
if (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (filesel))) {
- const char *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#if GTK_CHECK_VERSION(2,4,0)
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filesel));
+#else
+ filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#endif
+
if (e_cert_db_import_pkcs12_file (e_cert_db_peek (),
filename, NULL /* XXX */)) {
/* there's no telling how many certificates were added during the import,
@@ -350,10 +368,27 @@
static void
import_contact (GtkWidget *widget, CertificateManagerData *cfm)
{
- GtkWidget *filesel = gtk_file_selection_new (_("Select a cert to import..."));
+ GtkWidget *filesel;
+ const char *filename;
+
+#if GTK_CHECK_VERSION(2,4,0)
+ filesel = gtk_file_chooser_dialog_new (_("Select a cert to import..."),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
+#else
+ filesel = gtk_file_selection_new (_("Select a cert to import..."));
+#endif
if (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (filesel))) {
- const char *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#if GTK_CHECK_VERSION(2,4,0)
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filesel));
+#else
+ filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#endif
if (e_cert_db_import_certs_from_file (e_cert_db_peek (),
filename,
@@ -553,10 +588,27 @@
static void
import_ca (GtkWidget *widget, CertificateManagerData *cfm)
{
- GtkWidget *filesel = gtk_file_selection_new (_("Select a cert to import..."));
+ GtkWidget *filesel;
+ const char *filename;
+
+#if GTK_CHECK_VERSION(2,4,0)
+ filesel = gtk_file_chooser_dialog_new (_("Select a cert to import..."),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
+#else
+ filesel = gtk_file_selection_new (_("Select a cert to import..."));
+#endif
if (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (filesel))) {
- const char *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#if GTK_CHECK_VERSION(2,4,0)
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filesel));
+#else
+ filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+#endif
if (e_cert_db_import_certs_from_file (e_cert_db_peek (),
filename,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]