This looks much nicer. ACK. On Fri, 2015-03-20 at 10:35 +0100, Pavel Grunt wrote: > Since the error is propagated to the main, report the error there. > To make it work GError VIRT_VIEWER_ERROR_FAILED is set for all > failing states and it is reported using virt_viewer_app_simple_message_dialog(). > --- > Depends on https://www.redhat.com/archives/virt-tools-list/2015-March/msg00120.html > --- > src/remote-viewer-main.c | 3 +++ > src/remote-viewer.c | 25 +++++++++++++------------ > src/virt-viewer-main.c | 3 +++ > src/virt-viewer.c | 21 ++++----------------- > 4 files changed, 23 insertions(+), 29 deletions(-) > > diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c > index 1bb61c7..749fac1 100644 > --- a/src/remote-viewer-main.c > +++ b/src/remote-viewer-main.c > @@ -176,6 +176,9 @@ main(int argc, char **argv) > if (!virt_viewer_app_start(app, &error)) { > if (g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) > ret = 0; > + else if (error) { > + virt_viewer_app_simple_message_dialog(app, error->message); > + } > goto cleanup; > } > > diff --git a/src/remote-viewer.c b/src/remote-viewer.c > index a9de5e7..ae227ae 100644 > --- a/src/remote-viewer.c > +++ b/src/remote-viewer.c > @@ -1282,30 +1282,30 @@ retry_dialog: > vvfile = virt_viewer_file_new(path, &error); > g_free(path); > if (error) { > - virt_viewer_app_simple_message_dialog(app, _("Invalid file %s"), guri); > + g_prefix_error(&error, _("Invalid file %s: "), guri); > g_warning("%s", error->message); > goto cleanup; > } > g_object_get(G_OBJECT(vvfile), "type", &type, NULL); > } else if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0 || type == NULL) { > - virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI")); > + g_set_error_literal(&error, > + VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED, > + _("Cannot determine the connection type from URI")); > goto cleanup; > } > #ifdef HAVE_OVIRT > if (g_strcmp0(type, "ovirt") == 0) { > if (!create_ovirt_session(app, guri, &error)) { > - if (error && !g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) { > - virt_viewer_app_simple_message_dialog(app, > - _("Couldn't open oVirt session: %s"), > - error->message); > - } > + g_prefix_error(&error, _("Couldn't open oVirt session: ")); > goto cleanup; > } > } else > #endif > { > if (virt_viewer_app_create_session(app, type) < 0) { > - virt_viewer_app_simple_message_dialog(app, _("Couldn't create a session for this type: %s"), type); > + g_set_error(&error, > + VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED, > + _("Couldn't create a session for this type: %s"), type); > goto cleanup; > } > } > @@ -1322,10 +1322,11 @@ retry_dialog: > #endif > > if (!virt_viewer_app_initial_connect(app, &error)) { > - const gchar *msg = error ? error->message : > - _("Failed to initiate connection"); > - > - virt_viewer_app_simple_message_dialog(app, msg); > + if (error == NULL) { > + g_set_error_literal(&error, > + VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED, > + _("Failed to initiate connection")); > + } > goto cleanup; > } > #ifdef HAVE_SPICE_GTK > diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c > index f3d6b35..291af42 100644 > --- a/src/virt-viewer-main.c > +++ b/src/virt-viewer-main.c > @@ -115,6 +115,9 @@ int main(int argc, char **argv) > if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer), &error)) { > if (g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) > ret = 0; > + else if (error) { > + virt_viewer_app_simple_message_dialog(VIRT_VIEWER_APP(viewer), error->message); > + } > goto cleanup; > } > > diff --git a/src/virt-viewer.c b/src/virt-viewer.c > index c36a17c..e83898b 100644 > --- a/src/virt-viewer.c > +++ b/src/virt-viewer.c > @@ -746,7 +746,9 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error) > > virt_viewer_app_show_status(app, _("Checking guest domain status")); > if (virDomainGetInfo(dom, &info) < 0) { > - g_debug("Cannot get guest state"); > + g_set_error_literal(&err, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED, > + _("Cannot get guest state")); > + g_debug("%s", err->message); > goto cleanup; > } > > @@ -911,7 +913,6 @@ virt_viewer_connect(VirtViewerApp *app, GError **err) > g_set_error_literal(&error, > VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED, > error_message); > - virt_viewer_app_simple_message_dialog(app, error_message); > > g_free(error_message); > } else { > @@ -924,21 +925,7 @@ virt_viewer_connect(VirtViewerApp *app, GError **err) > } > > if (!virt_viewer_app_initial_connect(app, &error)) { > - if (error != NULL) { > - if (!g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) { > - VirtViewerWindow *main_window = virt_viewer_app_get_main_window(app); > - > - GtkWidget *dialog = gtk_message_dialog_new(virt_viewer_window_get_window(main_window), > - GTK_DIALOG_DESTROY_WITH_PARENT, > - GTK_MESSAGE_ERROR, > - GTK_BUTTONS_CLOSE, > - "Failed to connect: %s", > - error->message); > - gtk_dialog_run(GTK_DIALOG(dialog)); > - gtk_widget_destroy(GTK_WIDGET(dialog)); > - } > - g_propagate_error(err, error); > - } > + g_propagate_prefixed_error(err, error, _("Failed to connect: ")); > return -1; > } > _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list