summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-06-20 00:42:02 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-06-20 00:42:02 -0400
commitcab99c4e92eea53d1e42bc7ce42899d368bbe7cd (patch)
treedf42826f0715a1bdc2a90ab850923b5754ec392b
parentf95f8fa32ec5cb2ecf4d2aaf7499dc1756090e8a (diff)
Better error reporting
-rw-r--r--siv.c65
-rw-r--r--siv.desktop2
-rw-r--r--siv.h4
-rw-r--r--window.c16
4 files changed, 65 insertions, 22 deletions
diff --git a/siv.c b/siv.c
index 5353dfe..b0294e2 100644
--- a/siv.c
+++ b/siv.c
@@ -17,6 +17,7 @@ struct App
void
app_show_warning (GtkWidget *parent_window,
+ const gchar *secondary,
const gchar *format,
...)
{
@@ -28,10 +29,18 @@ app_show_warning (GtkWidget *parent_window,
g_vasprintf (&message, format, args);
va_end (args);
- dialog = gtk_message_dialog_new (parent_window ? GTK_WINDOW (parent_window) : NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK, message);
+ dialog = gtk_message_dialog_new_with_markup (
+ parent_window ? GTK_WINDOW (parent_window) : NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK, message);
+
+ if (secondary)
+ {
+ gtk_message_dialog_format_secondary_markup (
+ dialog, "%s", secondary);
+ }
+
g_free (message);
gtk_window_set_title (GTK_WINDOW (dialog), APPLICATION_NAME " Warning");
@@ -41,6 +50,38 @@ app_show_warning (GtkWidget *parent_window,
}
void
+app_show_could_not_open (GtkWidget *parent_window,
+ int n_files,
+ gchar **files)
+{
+ const char *header = NULL;
+ GString *text;
+ int i;
+
+ if (n_files == 0)
+ {
+ return;
+ }
+ else if (n_files == 1)
+ {
+ header = "<b>Could not open this file:</b>";
+ }
+ else
+ {
+ header = "<b>Could not open these files:</b>";
+ }
+
+ text = g_string_new (header);
+
+ for (i = 0; i < n_files; ++i)
+ g_string_append_printf (text, "\n%s", files[i]);
+
+ app_show_warning (NULL, NULL, "%s", text->str);
+
+ g_string_free (text, TRUE);
+}
+
+void
app_register_window (App *app, SivWindow *window)
{
++app->n_windows;
@@ -255,6 +296,7 @@ app_new (int argc, char **argv)
GList *list;
App *app;
int i;
+ GPtrArray *err_files = g_ptr_array_new ();
for (i = 1; i < argc; ++i)
{
@@ -317,7 +359,9 @@ app_new (int argc, char **argv)
if (!window_load_file (window, list->data, &err))
{
- g_print ("Could not open %s: %s\n", filename, err->message);
+ g_ptr_array_add (err_files, g_strdup (filename));
+ g_error_free (err);
+
window_free (window);
}
else
@@ -336,6 +380,11 @@ app_new (int argc, char **argv)
window_show (window_new (app), GDK_CURRENT_TIME);
}
+ app_show_could_not_open (NULL, err_files->len, (char **)err_files->pdata);
+
+ g_ptr_array_foreach (err_files, (GFunc)g_free, NULL);
+ g_ptr_array_free (err_files, TRUE);
+
if (app->n_windows == 1)
exit (1);
else
@@ -366,9 +415,9 @@ main (int argc,
{
app_show_warning (
NULL,
- APPLICATION_NAME " was not compiled or installed correctly.\n"
- "\n"
- "Running \"make install\" may solve this problem.\n");
+ "<i>Running \"make install\" may solve this problem.</i>",
+ "<b>"APPLICATION_NAME
+ " was not compiled or installed correctly.</b>");
return FALSE;
}
diff --git a/siv.desktop b/siv.desktop
index d72a6af..5724212 100644
--- a/siv.desktop
+++ b/siv.desktop
@@ -2,7 +2,7 @@
Name=Simple Image Viewer
Comment=Display images
TryExec=siv
-Exec=siv %U
+Exec=siv %F
Icon=siv
StartupNotify=true
Terminal=false
diff --git a/siv.h b/siv.h
index 4f9753f..1fcc595 100644
--- a/siv.h
+++ b/siv.h
@@ -55,8 +55,12 @@ void app_set_meta_data (App *data,
/* Doesn't really belong in the app namespace */
void app_show_warning (GtkWidget *parent_window,
+ const gchar *secondary,
const gchar *format,
...);
+void app_show_could_not_open (GtkWidget *parent_window,
+ int n_files,
+ gchar **files);
/* SivWindow */
SivWindow * window_new (App *app);
diff --git a/window.c b/window.c
index f1fd7f2..b2c4e37 100644
--- a/window.c
+++ b/window.c
@@ -729,17 +729,6 @@ set_busy (GtkWidget *widget,
}
static void
-show_could_not_open (SivWindow *window,
- const char *filename,
- GError *err)
-{
- app_show_warning (get_widget (window, "main_window"),
- "Could not open %s: %s",
- filename,
- err->message);
-}
-
-static void
on_open (GtkWidget *widget, gpointer data)
{
SivWindow *window = data;
@@ -784,8 +773,9 @@ retry:
}
else
{
- show_could_not_open (window, filename, err);
-
+ app_show_could_not_open (
+ get_widget (window, "main_window"), 1, &filename);
+
g_error_free (err);
if (window != target)