[Gnucash-changes] r11997 - gnucash/trunk - Convert the "file
locked" message to a GtkMessageDialog. Add a
David Hampton
hampton at cvs.gnucash.org
Sun Nov 20 19:41:44 EST 2005
Author: hampton
Date: 2005-11-20 19:41:43 -0500 (Sun, 20 Nov 2005)
New Revision: 11997
Trac: http://svn.gnucash.org/trac/changeset/11997
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/gnome-utils/dialog-utils.c
gnucash/trunk/src/gnome-utils/dialog-utils.h
gnucash/trunk/src/gnome-utils/gnc-file.c
Log:
Convert the "file locked" message to a GtkMessageDialog. Add a
utility function for creating buttons with images attached.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2005-11-21 00:39:22 UTC (rev 11996)
+++ gnucash/trunk/ChangeLog 2005-11-21 00:41:43 UTC (rev 11997)
@@ -1,5 +1,10 @@
2005-11-20 David Hampton <hampton at employees.org>
+ * src/gnome-utils/gnc-file.c:
+ * src/gnome-utils/dialog-utils.[ch]: Convert the "file locked"
+ message to a GtkMessageDialog. Add a utility function for
+ creating buttons with images attached.
+
* src/gnome-utils/gnc-main-window.c: Use the new GtkAboutDialog
when compiling with gtk2.6.
Modified: gnucash/trunk/src/gnome-utils/dialog-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.c 2005-11-21 00:39:22 UTC (rev 11996)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.c 2005-11-21 00:41:43 UTC (rev 11997)
@@ -963,3 +963,23 @@
g_signal_connect(signal_object, signal_name, func, user_data);
}
}
+
+void
+gnc_gtk_dialog_add_button (GtkWidget *dialog, const gchar *label, const gchar *stock_id, guint response)
+{
+ GtkWidget *button;
+
+ button = gtk_button_new_with_label(label);
+#ifdef HAVE_GLIB26
+ if (stock_id) {
+ GtkWidget *image;
+
+ image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image(GTK_BUTTON(button), image);
+ }
+#else
+ gtk_button_set_use_underline(GTK_BUTTON(button), TRUE);
+#endif
+ gtk_widget_show_all(button);
+ gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button, response);
+}
Modified: gnucash/trunk/src/gnome-utils/dialog-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.h 2005-11-21 00:39:22 UTC (rev 11996)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.h 2005-11-21 00:41:43 UTC (rev 11997)
@@ -136,5 +136,22 @@
gboolean after,
gpointer user_data);
+/** This function generates a button with icon and adds it to a
+ * GtkDialog. This is similar to just adding a stock button to the
+ * dialog, only you can add an arbitrary pairing of button and label,
+ * which the stock system doesn't provide.
+ *
+ * @param dialog The dialog where the button should be added.
+ *
+ * @param label The text of the button.
+ *
+ * @param stock_id The name of the stock button to use.
+ *
+ * @param response The response id to return if this button is
+ * clicked.*/
+void gnc_gtk_dialog_add_button (GtkWidget *dialog,
+ const gchar *label,
+ const gchar *stock_id,
+ guint response);
#endif
Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c 2005-11-21 00:39:22 UTC (rev 11996)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c 2005-11-21 00:41:43 UTC (rev 11997)
@@ -28,6 +28,7 @@
#include <string.h>
#include <g-wrap-wct.h>
+#include "dialog-utils.h"
#include "gnc-commodity.h"
#include "gnc-component-manager.h"
#include "gnc-engine.h"
@@ -517,6 +518,10 @@
/* private utilities for file open; done in two stages */
+#define RESPONSE_NEW 1
+#define RESPONSE_OPEN 2
+#define RESPONSE_QUIT 3
+
static gboolean
gnc_post_file_open (const char * filename)
{
@@ -560,37 +565,63 @@
/* if file appears to be locked, ask the user ... */
if (ERR_BACKEND_LOCKED == io_err || ERR_BACKEND_READONLY == io_err)
{
- const char *buttons[] = { GTK_STOCK_QUIT, GTK_STOCK_OPEN,
- GTK_STOCK_NEW, NULL };
- char *fmt = ((ERR_BACKEND_LOCKED == io_err) ?
- _("GnuCash could not obtain the lock for\n"
- " %s.\n"
- "That database may be in use by another user,\n"
- "in which case you should not open the database.\n"
- "\nWhat would you like to do?") :
- _("WARNING!!! GnuCash could not obtain the lock for\n"
- " %s.\n"
- "That database may be on a read-only file system,\n"
- "or you may not have write permission for the directory.\n"
- "If you proceed you may not be able to save any changes.\n"
- "\nWhat would you like to do?")
+ GtkWidget *dialog;
+ char *fmt1 = _("GnuCash could not obtain the lock for %s.");
+ char *fmt2 = ((ERR_BACKEND_LOCKED == io_err) ?
+ _("That database may be in use by another user, "
+ "in which case you should not open the database. "
+ "What would you like to do?") :
+ _("That database may be on a read-only file system, "
+ "or you may not have write permission for the directory. "
+ "If you proceed you may not be able to save any changes. "
+ "What would you like to do?")
);
int rc;
gnc_destroy_splash_screen(); /* Just in case */
- if (shutdown_cb) {
- rc = gnc_generic_question_dialog (NULL, buttons, fmt, newfile);
- } else {
- rc = gnc_generic_question_dialog (NULL, buttons+1, fmt, newfile)+1;
+
+#ifdef HAVE_GLIB26
+ dialog = gtk_message_dialog_new(NULL,
+ 0,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ fmt1, newfile);
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), fmt2);
+#else
+ {
+ gchar *tmp;
+
+ tmp = g_strdup_printf("<b>%s</b>\n\n%s", fmt1, fmt2);
+ dialog = gtk_message_dialog_new_with_markup(NULL,
+ 0,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ tmp, newfile);
+ g_free(tmp);
}
+#endif
- if (rc == 0)
+ gnc_gtk_dialog_add_button(dialog, _("_Open Anyway"),
+ GTK_STOCK_OPEN, RESPONSE_OPEN);
+ gnc_gtk_dialog_add_button(dialog, _("_Create New File"),
+ GTK_STOCK_NEW, RESPONSE_NEW);
+ if (shutdown_cb)
+ gtk_dialog_add_button(GTK_DIALOG(dialog),
+ GTK_STOCK_QUIT, RESPONSE_QUIT);
+ rc = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+
+ if (rc == GTK_RESPONSE_DELETE_EVENT)
{
+ rc = shutdown_cb ? RESPONSE_QUIT : RESPONSE_NEW;
+ }
+ if (rc == RESPONSE_QUIT)
+ {
if (shutdown_cb)
shutdown_cb(0);
g_assert(1);
}
- else if (rc == 1)
+ else if (rc == RESPONSE_OPEN)
{
/* user told us to ignore locks. So ignore them. */
qof_session_begin (new_session, newfile, TRUE, FALSE);
More information about the gnucash-changes
mailing list