Files
evolution/e-util/e-dialog-utils.c
Matthew Barnes 86fdd3a1cb Merge branch 'master' into kill-bonobo
This was a particularly messy merge.  Watch out for regressions!

Conflicts:
	ChangeLog
	NEWS
	a11y/ChangeLog
	a11y/widgets/ea-combo-button.c
	a11y/widgets/ea-combo-button.h
	a11y/widgets/ea-widgets.c
	addressbook/ChangeLog
	addressbook/gui/component/GNOME_Evolution_Addressbook.server.in.in
	addressbook/gui/component/addressbook-component.c
	addressbook/gui/component/addressbook-component.h
	addressbook/gui/component/addressbook-config.c
	addressbook/gui/component/addressbook-migrate.h
	addressbook/gui/component/addressbook-view.c
	addressbook/gui/component/addressbook-view.h
	addressbook/gui/component/addressbook.h
	addressbook/gui/component/autocompletion-config.c
	addressbook/gui/component/autocompletion-config.h
	addressbook/gui/component/component-factory.c
	addressbook/gui/component/e-book-shell-module-migrate.c
	addressbook/gui/component/ldap-config.glade
	addressbook/gui/contact-editor/Makefile.am
	addressbook/gui/contact-editor/contact-editor.glade
	addressbook/gui/contact-editor/e-contact-editor-address.c
	addressbook/gui/contact-editor/e-contact-editor-address.h
	addressbook/gui/contact-editor/e-contact-editor-im.c
	addressbook/gui/contact-editor/e-contact-editor-im.h
	addressbook/gui/contact-editor/e-contact-editor.c
	addressbook/gui/contact-editor/e-contact-editor.h
	addressbook/gui/contact-editor/eab-editor.c
	addressbook/gui/contact-editor/eab-editor.h
	addressbook/gui/contact-editor/test-editor.c
	addressbook/gui/contact-list-editor/Makefile.am
	addressbook/gui/widgets/Makefile.am
	addressbook/gui/widgets/e-addressbook-model.c
	addressbook/gui/widgets/e-addressbook-model.h
	addressbook/gui/widgets/e-addressbook-reflow-adapter.c
	addressbook/gui/widgets/e-addressbook-view.c
	addressbook/gui/widgets/e-addressbook-view.h
	addressbook/gui/widgets/e-minicard-view.c
	addressbook/gui/widgets/eab-contact-display.c
	addressbook/gui/widgets/eab-gui-util.c
	addressbook/gui/widgets/eab-menu.c
	addressbook/gui/widgets/eab-menu.h
	addressbook/gui/widgets/eab-popup-control.c
	addressbook/gui/widgets/eab-popup-control.h
	addressbook/gui/widgets/eab-popup.c
	addressbook/gui/widgets/eab-popup.h
	addressbook/gui/widgets/eab-vcard-control.c
	addressbook/gui/widgets/eab-vcard-control.h
	addressbook/gui/widgets/gal-view-minicard.c
	addressbook/gui/widgets/gal-view-minicard.h
	addressbook/printing/e-contact-print-style-editor.c
	addressbook/printing/e-contact-print-style-editor.h
	addressbook/printing/e-contact-print.glade
	addressbook/printing/test-contact-print-style-editor.c
	addressbook/tools/evolution-addressbook-export.c
	addressbook/util/Makefile.am
	calendar/ChangeLog
	calendar/gui/Makefile.am
	calendar/gui/apps_evolution_calendar.schemas.in
	calendar/gui/calendar-component.c
	calendar/gui/calendar-component.h
	calendar/gui/calendar-config.c
	calendar/gui/comp-editor-factory.c
	calendar/gui/comp-editor-factory.h
	calendar/gui/comp-util.c
	calendar/gui/comp-util.h
	calendar/gui/control-factory.c
	calendar/gui/control-factory.h
	calendar/gui/dialogs/alarm-dialog.c
	calendar/gui/dialogs/cal-prefs-dialog.c
	calendar/gui/dialogs/cal-prefs-dialog.glade
	calendar/gui/dialogs/cal-prefs-dialog.h
	calendar/gui/dialogs/comp-editor.c
	calendar/gui/dialogs/comp-editor.h
	calendar/gui/dialogs/event-editor.c
	calendar/gui/dialogs/event-page.c
	calendar/gui/dialogs/memo-editor.c
	calendar/gui/dialogs/memo-page.c
	calendar/gui/dialogs/recurrence-page.c
	calendar/gui/dialogs/task-details-page.c
	calendar/gui/dialogs/task-details-page.glade
	calendar/gui/dialogs/task-editor.c
	calendar/gui/dialogs/task-page.c
	calendar/gui/e-cal-component-memo-preview.c
	calendar/gui/e-cal-component-memo-preview.h
	calendar/gui/e-cal-component-preview.c
	calendar/gui/e-cal-component-preview.h
	calendar/gui/e-cal-event.h
	calendar/gui/e-cal-model.c
	calendar/gui/e-cal-popup.c
	calendar/gui/e-calendar-table.c
	calendar/gui/e-calendar-view.c
	calendar/gui/e-day-view.c
	calendar/gui/e-itip-control.c
	calendar/gui/e-memo-table.c
	calendar/gui/e-memos.c
	calendar/gui/e-memos.h
	calendar/gui/e-tasks.c
	calendar/gui/e-tasks.h
	calendar/gui/e-week-view.c
	calendar/gui/gnome-cal.c
	calendar/gui/goto.c
	calendar/gui/itip-bonobo-control.c
	calendar/gui/itip-bonobo-control.h
	calendar/gui/itip-utils.c
	calendar/gui/itip-utils.h
	calendar/gui/main.c
	calendar/gui/memos-component.c
	calendar/gui/memos-control.c
	calendar/gui/memos-control.h
	calendar/gui/migration.c
	calendar/gui/migration.h
	calendar/gui/tasks-component.c
	calendar/gui/tasks-control.c
	calendar/importers/main.c
	composer/ChangeLog
	composer/e-composer-actions.c
	composer/e-composer-private.c
	composer/e-msg-composer.c
	composer/e-msg-composer.h
	composer/evolution-composer.ui
	configure.in
	doc/reference/shell/eshell-overrides.txt
	e-util/ChangeLog
	e-util/Makefile.am
	e-util/e-corba-utils.c
	e-util/e-corba-utils.h
	e-util/e-gui-utils.c
	e-util/e-gui-utils.h
	e-util/e-logger.c
	e-util/e-non-intrusive-error-dialog.c
	e-util/e-non-intrusive-error-dialog.h
	e-util/e-plugin-ui.c
	e-util/e-util-labels.c
	e-util/e-util-labels.h
	e-util/e-util.c
	e-util/e-util.h
	filter/ChangeLog
	filter/filter-option.c
	help/C/evolution.xml
	help/ChangeLog
	help/Makefile.am
	help/cs/cs.po
	help/de/de.po
	help/es/es.po
	help/eu/figures/Screenshot-Free-Busy.png
	help/eu/figures/evo_blink.png
	help/eu/figures/evo_dialog-info.png
	help/eu/figures/evo_dialog-warning.png
	help/eu/figures/evo_email_a.png
	help/eu/figures/evo_flag_follow_up_a.png
	help/eu/figures/evo_proxyadd_a.png
	help/eu/figures/evo_shd_memo_a.png
	help/eu/figures/exchange-delegation.png
	help/eu/figures/exchange-identity.png
	help/eu/figures/exchange-receive-options.png
	help/eu/figures/exchange-receive.png
	help/eu/figures/exchg-identity.png
	help/eu/figures/exchng-identity.png
	help/eu/figures/exchng-rec-mail.png
	help/eu/figures/exchng-rec-option.png
	help/eu/figures/exchng-rec-options.png
	help/eu/figures/free_busy.png
	help/eu/figures/full-1.png
	help/eu/figures/full-2.png
	help/eu/figures/full-3.png
	help/eu/figures/full-4.png
	help/eu/figures/full-5.png
	help/eu/figures/full-6.png
	help/eu/figures/full-7.png
	help/eu/figures/mail-druid-pic.png
	help/eu/figures/mail-inbox.png
	help/eu/figures/mail-threaded.png
	help/eu/figures/mainwindow-pic.png
	help/eu/figures/minus.png
	help/eu/figures/plus.png
	help/eu/figures/proxy-cal.png
	help/eu/figures/proxy-login.png
	help/eu/figures/schedule.png
	help/eu/figures/stock_search.png
	help/eu/figures/sub-others-folder.png
	help/eu/figures/sub-pub-fold.png
	help/eu/figures/vfolder-createrule-fig.png
	help/quickref/Makefile.am
	mail/ChangeLog
	mail/Makefile.am
	mail/default/Makefile.am
	mail/e-mail-shell-module-migrate.c
	mail/e-searching-tokenizer.c
	mail/em-account-editor.c
	mail/em-account-prefs.h
	mail/em-composer-prefs.c
	mail/em-composer-prefs.h
	mail/em-composer-utils.c
	mail/em-filter-folder-element.c
	mail/em-folder-browser.c
	mail/em-folder-selection-button.h
	mail/em-folder-selector.c
	mail/em-folder-tree-model.c
	mail/em-folder-tree-model.h
	mail/em-folder-tree.c
	mail/em-folder-tree.h
	mail/em-folder-utils.c
	mail/em-folder-utils.h
	mail/em-folder-view.c
	mail/em-format-html-display.c
	mail/em-format-html-print.c
	mail/em-format-html-print.h
	mail/em-format-html.c
	mail/em-format-quote.h
	mail/em-format.c
	mail/em-format.h
	mail/em-html-stream.h
	mail/em-mailer-prefs.c
	mail/em-mailer-prefs.h
	mail/em-message-browser.c
	mail/em-message-browser.h
	mail/em-migrate.h
	mail/em-network-prefs.h
	mail/em-popup.c
	mail/em-search-context.h
	mail/em-subscribe-editor.c
	mail/em-utils.c
	mail/em-utils.h
	mail/filtertypes.xml
	mail/mail-component-factory.c
	mail/mail-component.c
	mail/mail-config-factory.c
	mail/mail-config-factory.h
	mail/mail-config.c
	mail/mail-config.glade
	mail/mail-crypto.c
	mail/mail-crypto.h
	mail/mail-dialogs.glade
	mail/mail-folder-cache.c
	mail/mail-mt.c
	mail/mail-send-recv.c
	mail/mail-send-recv.h
	mail/mail-session.c
	mail/mail-session.h
	mail/mail-types.h
	mail/mail-vfolder.c
	mail/message-list.c
	mail/message-tag-followup.c
	mail/searchtypes.xml
	mail/vfoldertypes.xml
	plugins/attachment-reminder/Makefile.am
	plugins/audio-inline/org-gnome-audio-inline.eplug.xml
	plugins/caldav/ChangeLog
	plugins/caldav/caldav-source.c
	plugins/calendar-http/ChangeLog
	plugins/calendar-weather/ChangeLog
	plugins/calendar-weather/calendar-weather.c
	plugins/email-custom-header/ChangeLog
	plugins/email-custom-header/email-custom-header.c
	plugins/exchange-operations/ChangeLog
	plugins/google-account-setup/ChangeLog
	plugins/google-account-setup/Makefile.am
	plugins/google-account-setup/google-contacts-source.c
	plugins/google-account-setup/google-source.c
	plugins/import-ics-attachments/ChangeLog
	plugins/import-ics-attachments/Makefile.am
	plugins/import-ics-attachments/icsimporter.c
	plugins/itip-formatter/ChangeLog
	plugins/itip-formatter/itip-view.c
	plugins/mail-account-disable/ChangeLog
	plugins/mail-account-disable/mail-account-disable.c
	plugins/mail-notification/ChangeLog
	plugins/mail-notification/mail-notification.c
	plugins/mail-to-meeting/ChangeLog
	plugins/mail-to-task/ChangeLog
	plugins/mark-all-read/mark-all-read.c
	plugins/publish-calendar/ChangeLog
	plugins/publish-calendar/publish-format-fb.c
	plugins/publish-calendar/publish-format-ical.c
	plugins/save-attachments/ChangeLog
	plugins/save-attachments/Makefile.am
	plugins/save-attachments/save-attachments.c
	plugins/select-one-source/ChangeLog
	plugins/select-one-source/Makefile.am
	plugins/select-one-source/select-one-source.c
	plugins/startup-wizard/ChangeLog
	plugins/startup-wizard/startup-wizard.c
	plugins/webdav-account-setup/ChangeLog
	plugins/webdav-account-setup/Makefile.am
	plugins/webdav-account-setup/webdav-contacts-source.c
	po/ChangeLog
	po/POTFILES.in
	po/ar.po
	po/bg.po
	po/bn_IN.po
	po/ca.po
	po/cs.po
	po/da.po
	po/de.po
	po/el.po
	po/en_GB.po
	po/es.po
	po/et.po
	po/fr.po
	po/gl.po
	po/gu.po
	po/hi.po
	po/hu.po
	po/it.po
	po/ja.po
	po/kn.po
	po/ko.po
	po/lt.po
	po/ml.po
	po/mr.po
	po/nb.po
	po/nl.po
	po/pa.po
	po/pl.po
	po/pt.po
	po/ru.po
	po/sl.po
	po/sr.po
	po/sr@latin.po
	po/sv.po
	po/ta.po
	po/te.po
	po/th.po
	po/tr.po
	po/zh_HK.po
	po/zh_TW.po
	shell/ChangeLog
	shell/Evolution-Component.idl
	shell/Makefile.am
	shell/apps_evolution_shell.schemas.in
	shell/e-component-registry.c
	shell/e-component-registry.h
	shell/e-component-view.c
	shell/e-component-view.h
	shell/e-corba-config-page.c
	shell/e-corba-config-page.h
	shell/e-shell-constants.h
	shell/e-shell-importer.c
	shell/e-shell-importer.h
	shell/e-shell-nm.c
	shell/e-shell-settings-dialog.c
	shell/e-shell-settings-dialog.h
	shell/e-shell-view.c
	shell/e-shell-view.h
	shell/e-shell-window-commands.c
	shell/e-shell-window-commands.h
	shell/e-shell-window.c
	shell/e-shell-window.h
	shell/e-shell.c
	shell/e-shell.h
	shell/e-sidebar.c
	shell/e-sidebar.h
	shell/e-user-creatable-items-handler.c
	shell/e-user-creatable-items-handler.h
	shell/es-menu.c
	shell/es-menu.h
	shell/evolution-component.c
	shell/evolution-component.h
	shell/evolution-config-control.c
	shell/evolution-config-control.h
	shell/evolution-listener.c
	shell/evolution-listener.h
	shell/evolution-shell-component-utils.c
	shell/evolution-shell-component-utils.h
	shell/importer/evolution-importer-client.c
	shell/importer/evolution-importer-client.h
	shell/importer/evolution-importer-listener.c
	shell/importer/evolution-importer-listener.h
	shell/importer/evolution-importer.c
	shell/importer/evolution-importer.h
	shell/importer/evolution-intelligent-importer.c
	shell/importer/evolution-intelligent-importer.h
	shell/importer/import.glade
	shell/importer/intelligent.c
	shell/importer/intelligent.h
	shell/main.c
	shell/shell.error.xml
	shell/test/evolution-test-component.c
	shell/test/evolution-test-component.h
	smime/ChangeLog
	smime/lib/Makefile.am
	ui/Makefile.am
	ui/evolution-addressbook.xml
	ui/evolution-calendar.xml
	widgets/ChangeLog
	widgets/menus/gal-view-menus.c
	widgets/menus/gal-view-menus.h
	widgets/misc/ChangeLog
	widgets/misc/Makefile.am
	widgets/misc/e-activity-handler.c
	widgets/misc/e-activity-handler.h
	widgets/misc/e-attachment-bar.c
	widgets/misc/e-attachment-bar.h
	widgets/misc/e-attachment.c
	widgets/misc/e-attachment.h
	widgets/misc/e-calendar-item.c
	widgets/misc/e-charset-picker.c
	widgets/misc/e-combo-button.c
	widgets/misc/e-combo-button.h
	widgets/misc/e-config-page.c
	widgets/misc/e-config-page.h
	widgets/misc/e-dropdown-button.c
	widgets/misc/e-dropdown-button.h
	widgets/misc/e-filter-bar.h
	widgets/misc/e-info-label.c
	widgets/misc/e-info-label.h
	widgets/misc/e-multi-config-dialog.c
	widgets/misc/e-multi-config-dialog.h
	widgets/misc/e-online-button.c
	widgets/misc/e-search-bar.c
	widgets/misc/e-search-bar.h
	widgets/misc/e-signature-combo-box.c
	widgets/misc/e-signature-combo-box.h
	widgets/misc/e-signature-editor.c
	widgets/misc/e-signature-editor.h
	widgets/misc/e-task-bar.c
	widgets/misc/e-task-bar.h
	widgets/misc/e-task-widget.c
	widgets/misc/e-task-widget.h
	widgets/misc/test-dropdown-button.c
	widgets/misc/test-info-label.c
	widgets/misc/test-multi-config-dialog.c
	widgets/table/ChangeLog
	widgets/table/e-cell-date.c
	widgets/table/e-table-group-container.c
	widgets/table/e-table-group-leaf.c
	widgets/table/e-table-group.c
	widgets/table/e-table-group.h
	widgets/table/e-table.c
	widgets/table/e-table.h
2009-04-25 10:07:44 -04:00

436 lines
10 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
* Authors:
* Michael Meeks <michael@ximian.com>
* Ettore Perazzoli <ettore@ximian.com>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-dialog-utils.h"
#include <errno.h>
#include <unistd.h>
#include <glib/gstdio.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#include <gconf/gconf-client.h>
#include <glib/gi18n.h>
#include "e-util/e-util.h"
#include "e-util/e-error.h"
/**
* e_notice:
* @parent: the dialog's parent window, or %NULL
* @type: the type of dialog (%GTK_MESSAGE_INFO, %GTK_MESSAGE_WARNING,
* or %GTK_MESSAGE_ERROR)
* @format: printf-style format string, followed by arguments
*
* Convenience function to show a dialog with a message and an "OK"
* button.
**/
void
e_notice (gpointer parent, GtkMessageType type, const char *format, ...)
{
GtkWidget *dialog;
va_list args;
char *str;
va_start (args, format);
str = g_strdup_vprintf (format, args);
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
type,
GTK_BUTTONS_OK,
"%s",
str);
va_end (args);
g_free (str);
if (parent)
e_dialog_set_transient_for (GTK_WINDOW (dialog), parent);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
/**
* e_notice_with_xid:
* @parent: the dialog's parent window, or %NULL
* @type: the type of dialog (%GTK_MESSAGE_INFO, %GTK_MESSAGE_WARNING,
* or %GTK_MESSAGE_ERROR)
* @format: printf-style format string, followed by arguments
*
* Like e_notice(), but takes a GdkNativeWindow for the parent
* window argument.
**/
void
e_notice_with_xid (GdkNativeWindow parent, GtkMessageType type, const char *format, ...)
{
GtkWidget *dialog;
va_list args;
char *str;
va_start (args, format);
str = g_strdup_vprintf (format, args);
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
type,
GTK_BUTTONS_OK,
"%s",
str);
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
va_end (args);
g_free (str);
if (parent)
e_dialog_set_transient_for_xid (GTK_WINDOW (dialog), parent);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
#ifdef GDK_WINDOWING_X11
/* Tests whether or not an X Window is being managed by the
* window manager.
*/
static gboolean
window_is_wm_toplevel (Display *display, Window window)
{
static Atom WM_STATE = None;
unsigned long nitems, after;
unsigned char *data = NULL;
Atom type = None;
int format;
if (!WM_STATE)
WM_STATE = XInternAtom (display, "WM_STATE", False);
if (XGetWindowProperty (display, window, WM_STATE, 0, 0, False,
AnyPropertyType, &type, &format,
&nitems, &after, &data) == Success) {
if (data)
XFree((char*)data);
if (type)
return TRUE;
}
return FALSE;
}
#endif
/**
* e_dialog_set_transient_for:
* @dialog: a dialog window
* @parent_widget: the parent for @dialog
*
* This sets the parent for @dialog to be @parent_widget. Unlike
* gtk_window_set_transient_for(), this doesn't need @parent_widget to
* be the actual toplevel, and also works if @parent_widget is
* embedded as a Bonobo control by an out-of-process container.
* @parent_widget must already be realized before calling this
* function, but @dialog does not need to be.
**/
void
e_dialog_set_transient_for (GtkWindow *dialog,
GtkWidget *parent_widget)
{
GtkWidget *toplevel;
#ifdef GDK_WINDOWING_X11
Window parent, root_ret, *children;
unsigned int numchildren;
Display *display;
Status status;
#endif
g_return_if_fail (GTK_IS_WINDOW (dialog));
g_return_if_fail (GTK_IS_WIDGET (parent_widget));
toplevel = gtk_widget_get_toplevel (parent_widget);
if (toplevel == NULL)
return;
if (!GTK_IS_PLUG (toplevel)) {
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (toplevel));
return;
}
#ifdef GDK_WINDOWING_X11
/* Find the top-level windowmanager-managed X Window */
display = GDK_WINDOW_XDISPLAY (gtk_widget_get_window (parent_widget));
parent = GDK_WINDOW_XID (gtk_widget_get_window (parent_widget));
while (parent && !window_is_wm_toplevel (display, parent)) {
status = XQueryTree (display, parent, &root_ret,
&parent, &children, &numchildren);
if (status != 0)
XFree (children);
}
e_dialog_set_transient_for_xid (dialog, parent);
#endif
#ifdef GDK_WINDOWING_WIN32
g_warning ("Not implemented on Win32: e_dialog_set_transient_for() for plug windows");
#endif
}
static void
dialog_realized (GtkWindow *dialog, gpointer xid)
{
e_dialog_set_transient_for_xid (dialog, (GdkNativeWindow)GPOINTER_TO_INT(xid));
}
/**
* e_dialog_set_transient_for_xid:
* @dialog: a dialog window
* @xid: the X Window parent
*
* Like e_dialog_set_transient_for(), but use an XID to specify the
* parent window.
**/
void
e_dialog_set_transient_for_xid (GtkWindow *dialog,
GdkNativeWindow xid)
{
#ifdef GDK_MULTIHEAD_SAFE
GdkDisplay *display;
#endif
GdkWindow *parent;
g_return_if_fail (GTK_IS_WINDOW (dialog));
if (!GTK_WIDGET_REALIZED (dialog)) {
g_signal_connect (dialog, "realize",
G_CALLBACK (dialog_realized),
GINT_TO_POINTER(xid));
return;
}
#ifdef GDK_MULTIHEAD_SAFE
display = gdk_drawable_get_display (GDK_DRAWABLE (gtk_widget_get_window (GTK_WIDGET (dialog))));
parent = gdk_window_lookup_for_display (display, xid);
if (!parent)
parent = gdk_window_foreign_new_for_display (display, xid);
#else
parent = gdk_window_lookup (xid);
if (!parent)
parent = gdk_window_foreign_new (xid);
#endif
g_return_if_fail (parent != NULL);
gdk_window_set_transient_for (gtk_widget_get_window (GTK_WIDGET (dialog)), parent);
}
static void
save_ok (GtkWidget *widget, gpointer data)
{
GtkWidget *fs;
char **filename = data;
char *uri;
fs = gtk_widget_get_toplevel (widget);
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fs));
if (e_file_can_save((GtkWindow *)widget, uri)) {
e_file_update_save_path(gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(fs)), TRUE);
*filename = uri;
}
gtk_main_quit ();
}
static void
filechooser_response (GtkWidget *fc, gint response_id, gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
save_ok (fc, data);
else
gtk_widget_destroy (fc);
}
char *
e_file_dialog_save (const char *title, const char *fname)
{
GtkWidget *selection;
char *filename = NULL;
selection = e_file_get_save_filesel(NULL, title, fname, GTK_FILE_CHOOSER_ACTION_SAVE);
g_signal_connect (G_OBJECT (selection), "response", G_CALLBACK (filechooser_response), &filename);
gtk_widget_show (GTK_WIDGET (selection));
gtk_grab_add (GTK_WIDGET (selection));
gtk_main ();
gtk_widget_destroy (GTK_WIDGET (selection));
return filename;
}
static void
save_folder_ok (GtkWidget *widget, gpointer data)
{
GtkWidget *fs;
char **filename = data;
char *uri;
fs = gtk_widget_get_toplevel (widget);
uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (fs));
e_file_update_save_path(uri, FALSE);
*filename = uri;
gtk_main_quit ();
}
static void
folderchooser_response (GtkWidget *fc, gint response_id, gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
save_folder_ok (fc, data);
else
gtk_widget_destroy (fc);
}
char *
e_file_dialog_save_folder (const char *title)
{
GtkWidget *selection;
char *filename = NULL;
selection = e_file_get_save_filesel(NULL, title, NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
g_signal_connect (G_OBJECT (selection), "response", G_CALLBACK (folderchooser_response), &filename);
gtk_widget_show (GTK_WIDGET (selection));
gtk_grab_add (GTK_WIDGET (selection));
gtk_main ();
gtk_widget_destroy (GTK_WIDGET (selection));
return filename;
}
/**
* e_file_get_save_filesel:
* @parent: parent window
* @title: dialog title
* @name: filename; already in a proper form (suitable for file system)
* @action: action for dialog
*
* Creates a save dialog, using the saved directory from gconf. The dialog has
* no signals connected and is not shown.
**/
GtkWidget *
e_file_get_save_filesel (GtkWindow *parent, const char *title, const char *name, GtkFileChooserAction action)
{
GtkWidget *filesel;
char *uri;
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
filesel = gtk_file_chooser_dialog_new (
title, parent, action,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
(action == GTK_FILE_CHOOSER_ACTION_OPEN) ?
GTK_STOCK_OPEN : GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (filesel), FALSE);
uri = e_file_get_save_path ();
gtk_file_chooser_set_current_folder_uri (
GTK_FILE_CHOOSER (filesel), uri);
if (name && name[0])
gtk_file_chooser_set_current_name (
GTK_FILE_CHOOSER (filesel), name);
g_free (uri);
return filesel;
}
/**
* e_file_can_save:
*
* Return TRUE if the URI can be saved to, FALSE otherwise. It checks local
* files to see if they're regular and can be accessed. If the file exists and
* is writable, it pops up a dialog asking the user if they want to overwrite
* it. Returns the users choice.
**/
gboolean
e_file_can_save(GtkWindow *parent, const char *uri)
{
struct stat st;
char *path;
gboolean res;
if (!uri || uri[0] == 0)
return FALSE;
/* Assume remote files are writable; too costly to check */
if (!e_file_check_local(uri))
return TRUE;
path = e_util_uri_to_filename (uri);
if (!path)
return FALSE;
/* make sure we can actually save to it... */
if (g_stat (path, &st) != -1 && !S_ISREG (st.st_mode)) {
g_free(path);
return FALSE;
}
res = TRUE;
if (g_access (path, F_OK) == 0) {
if (g_access (path, W_OK) != 0) { e_error_run(parent, "mail:no-save-path", path, g_strerror(errno), NULL);
g_free(path);
return FALSE;
}
res = e_error_run(parent, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, path, NULL) == GTK_RESPONSE_OK;
}
g_free(path);
return res;
}
gboolean
e_file_check_local (const char *name)
{
char *uri;
uri = e_util_uri_to_filename (name);
if (uri) {
g_free(uri);
return TRUE;
}
return FALSE;
}