summaryrefslogtreecommitdiff
path: root/helper-utilities
diff options
context:
space:
mode:
authorRamiro Estrugo <ramiro@src.gnome.org>2000-11-04 00:52:02 +0000
committerRamiro Estrugo <ramiro@src.gnome.org>2000-11-04 00:52:02 +0000
commit1541f5092f7cc65c1e301b8ce4b6984e824f645a (patch)
tree6f892f58824cf518ac9c8c8cf4bae5c69ab68ac5 /helper-utilities
parent8c6d734e728dbfc0ea1ebce676ba6d4057853c9d (diff)
downloadnautilus-1541f5092f7cc65c1e301b8ce4b6984e824f645a.tar.gz
Add a place to put helper-scripts.
* Makefile.am: * configure.in: * helper-scripts/.cvsignore: * helper-scripts/Makefile.am: * helper-scripts/nautilus-verify-rpm.sh: Add a place to put helper-scripts. * helper-utilities/error-dialog/Makefile.am: Dont link in with Nautilus libraries and dependencies. * helper-utilities/error-dialog/nautilus-error-dialog.c: (find_message_label), (find_message_label_callback), (show_message_box), (show_ok_box), (nautilus_error_dialog), (nautilus_yes_no_dialog), (main): Add support for specifying button labels on the command line. * src/run-nautilus: Call the nautilus rpm verification script and bail if it fails.
Diffstat (limited to 'helper-utilities')
-rw-r--r--helper-utilities/error-dialog/Makefile.am5
-rw-r--r--helper-utilities/error-dialog/nautilus-error-dialog.c180
2 files changed, 163 insertions, 22 deletions
diff --git a/helper-utilities/error-dialog/Makefile.am b/helper-utilities/error-dialog/Makefile.am
index d11a3a7c2..183552e38 100644
--- a/helper-utilities/error-dialog/Makefile.am
+++ b/helper-utilities/error-dialog/Makefile.am
@@ -14,10 +14,5 @@ nautilus_error_dialog_SOURCES =\
$(NULL)
nautilus_error_dialog_LDADD = \
- $(top_builddir)/libnautilus-extensions/libnautilus-extensions.la \
$(GNOMEUI_LIBS) \
- $(GCONF_LIBS) \
- $(PAM_LIBS) \
- $(top_builddir)/libnautilus/libnautilus.la \
- $(BONOBO_LIBS) \
$(NULL)
diff --git a/helper-utilities/error-dialog/nautilus-error-dialog.c b/helper-utilities/error-dialog/nautilus-error-dialog.c
index 9677e9d1b..9c168428f 100644
--- a/helper-utilities/error-dialog/nautilus-error-dialog.c
+++ b/helper-utilities/error-dialog/nautilus-error-dialog.c
@@ -21,32 +21,172 @@
*/
/* nautilus-error-dialog.c - A very simple program used to post an
- * error dialog.
+ * error dialog or a question dialog.
+ *
+ * To post a error dialog:
+ *
+ * nautilus-error-dialog --message "My message" --title "My Title"
+ *
+ * Posts a error dialog (error icon) with an OK button.
+ *
+ *
+ * To post a warning dialog:
+ *
+ * nautilus-error-dialog --button-one "No" --button-two "Yes" \
+ * --message "My Question" --title "My Question"
+ *
+ * Posts a question dialog (question icon) with two buttons ordered
+ * left to right such that "No" is left and "Yes" is right. "Yes"
+ * is the default button.
+ *
+ * The result value of the script is the number of the clicked button
+ * starting at 0. In the question example above, "Yes" would return
+ * "1" and "No" would return "0".
+ *
*/
#include <config.h>
-#include <libnautilus-extensions/nautilus-stock-dialogs.h>
#include <gnome.h>
#include <popt.h>
+#include <gtk/gtkbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkmain.h>
+#include <gtk/gtksignal.h>
+#include <libgnome/gnome-i18n.h>
+#include <libgnomeui/gnome-messagebox.h>
+#include <libgnomeui/gnome-stock.h>
+#include <libgnomeui/gnome-uidefs.h>
+
+/*
+ * The following dialog widgetry code cut-n-pasted from libnautilus-extension.
+ * The reason why we dont use libnautilus-extensions is that we dont want to
+ * incur its dependencies, especially libnautilus and thus libbonobo.
+ */
+static void find_message_label_callback (GtkWidget *widget,
+ gpointer callback_data);
+
+static void
+find_message_label (GtkWidget *widget, const char *message)
+{
+ char *text;
+
+ /* Turn on the flag if we find a label with the message
+ * in it.
+ */
+ if (GTK_IS_LABEL (widget)) {
+ gtk_label_get (GTK_LABEL (widget), &text);
+ if (strcmp (text, message) == 0) {
+ gtk_object_set_data (GTK_OBJECT (gtk_widget_get_toplevel (widget)),
+ "message label", widget);
+ }
+ }
+
+ /* Recurse for children. */
+ if (GTK_IS_CONTAINER (widget)) {
+ gtk_container_foreach (GTK_CONTAINER (widget),
+ find_message_label_callback,
+ (char *) message);
+ }
+}
+
+static void
+find_message_label_callback (GtkWidget *widget, gpointer callback_data)
+{
+ find_message_label (widget, callback_data);
+}
+
+static GnomeDialog *
+show_message_box (const char *message,
+ const char *dialog_title,
+ const char *type,
+ const char *button_one,
+ const char *button_two,
+ GtkWindow *parent)
+{
+ GtkWidget *box;
+ GtkLabel *message_label;
+
+ g_assert (dialog_title != NULL);
+
+ box = gnome_message_box_new (message, type, button_one, button_two, NULL);
+ gtk_window_set_title (GTK_WINDOW (box), dialog_title);
+
+ /* A bit of a hack. We want to use gnome_message_box_new,
+ * but we want the message to be wrapped. So, we search
+ * for the label with this message so we can mark it.
+ */
+ find_message_label (box, message);
+ message_label = GTK_LABEL (gtk_object_get_data (GTK_OBJECT (box), "message label"));
+ gtk_label_set_line_wrap (message_label, TRUE);
+
+ if (parent != NULL) {
+ gnome_dialog_set_parent (GNOME_DIALOG (box), parent);
+ }
+ gtk_widget_show (box);
+ return GNOME_DIALOG (box);
+}
+
+static GnomeDialog *
+show_ok_box (const char *message,
+ const char *dialog_title,
+ const char *type,
+ GtkWindow *parent)
+{
+ return show_message_box (message, dialog_title, type, GNOME_STOCK_BUTTON_OK, NULL, parent);
+}
+
+static GnomeDialog *
+nautilus_error_dialog (const char *error,
+ const char *dialog_title,
+ GtkWindow *parent)
+{
+ return show_ok_box (error,
+ dialog_title == NULL ? _("Error") : dialog_title,
+ GNOME_MESSAGE_BOX_ERROR, parent);
+}
+
+/**
+ * nautilus_yes_no_dialog:
+ *
+ * Create a dialog asking a question with two choices.
+ * The caller needs to set up any necessary callbacks
+ * for the buttons.
+ * @question: The text of the question.
+ * @yes_label: The label of the "yes" button.
+ * @no_label: The label of the "no" button.
+ * @parent: The parent window for this dialog.
+ */
+static GnomeDialog *
+nautilus_yes_no_dialog (const char *question,
+ const char *dialog_title,
+ const char *yes_label,
+ const char *no_label,
+ GtkWindow *parent)
+{
+ return show_message_box (question,
+ dialog_title == NULL ? _("Question") : dialog_title,
+ GNOME_MESSAGE_BOX_QUESTION,
+ yes_label,
+ no_label,
+ parent);
+}
+
int main (int argc, char *argv[])
{
- GnomeDialog *error_dialog;
+ GnomeDialog *dialog;
poptContext popt_context;
-
char *title = NULL;
char *message = NULL;
+ char *button_one_label = NULL;
+ char *button_two_label = NULL;
- const char *default_title = "Default Title";
- const char *default_message = "Default Message";
-
- const char *the_title = NULL;
- const char *the_message = NULL;
-
struct poptOption options[] = {
{ "message", '\0', POPT_ARG_STRING, &message, 0, N_("Message."), NULL },
{ "title", '\0', POPT_ARG_STRING, &title, 0, N_("Title."), NULL },
+ { "button-one", '\0', POPT_ARG_STRING, &button_one_label, 0, N_("Button one label."), NULL },
+ { "button-two", '\0', POPT_ARG_STRING, &button_two_label, 0, N_("Button two label."), NULL },
POPT_AUTOHELP
{ NULL, '\0', 0, NULL, 0, NULL, NULL }
};
@@ -61,12 +201,18 @@ int main (int argc, char *argv[])
0,
&popt_context);
- the_title = title ? title : default_title;
- the_message = message ? message : default_message;
-
- error_dialog = nautilus_error_dialog (the_message, the_title, NULL);
-
- gnome_dialog_run_and_close (GNOME_DIALOG (error_dialog));
+ if (button_two_label) {
+ dialog = nautilus_yes_no_dialog (message ? message : _("Question"),
+ title ? title : _("Question"),
+ button_one_label ? button_one_label : _("Ok"),
+ button_two_label,
+ NULL);
+ }
+ else {
+ dialog = nautilus_error_dialog (message ? message : _("Question"),
+ title ? title : _("Question"),
+ NULL);
+ }
- return 0;
+ return gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
}