/** * xfce_dialog_show_error: * @parent : (allow-none): transient parent of the dialog, or %NULL. * @error : (allow-none): a #GError, which gives a more precise description of the problem or %NULL. * @primary_format : the printf()-style format for the primary problem description. * @... : argument list for the @primary_format. * * Displays an error dialog on @parent using the @primary_format as primary message and optionally * displaying @error as secondary error text. */ void xfce_dialog_show_error (GtkWindow *parent, const GError *error, const gchar *primary_format, ...) { va_list args; gchar *primary_text; g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent)); va_start (args, primary_format); primary_text = g_strdup_vprintf (primary_format, args); va_end (args); xfce_message_dialog (parent, _("Error"), #if !GTK_CHECK_VERSION (3, 10, 0) GTK_STOCK_DIALOG_ERROR, #else "dialog-error", #endif primary_text, error ? error->message : NULL, #if !GTK_CHECK_VERSION (3, 10, 0) GTK_STOCK_CLOSE, #else XFCE_BUTTON_TYPE_MIXED, "window-close", _("Close"), #endif GTK_RESPONSE_CLOSE, NULL); g_free (primary_text); }
/** * xfce_dialog_show_warning: * @parent : (allow-none): transient parent of the dialog, or %NULL. * @secondary_text : (allow-none): secondary text of the dialog or %NULL. * @primary_format : the printf()-style format for the primary problem description. * @... : argument list for the @format. * * Displays a warning dialog on @parent using the @primary_format as message. */ void xfce_dialog_show_warning (GtkWindow *parent, const gchar *secondary_text, const gchar *primary_format, ...) { va_list args; gchar *primary_text; g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent)); va_start (args, primary_format); primary_text = g_strdup_vprintf (primary_format, args); va_end (args); xfce_message_dialog (parent, _("Warning"), #if !GTK_CHECK_VERSION (3, 10, 0) GTK_STOCK_DIALOG_WARNING, #else "dialog-warning", #endif primary_text, secondary_text, #if !GTK_CHECK_VERSION (3, 10, 0) GTK_STOCK_CLOSE, #else XFCE_BUTTON_TYPE_MIXED, "window-close", _("Close"), #endif GTK_RESPONSE_CLOSE, NULL); g_free (primary_text); }
gboolean xfce_volstatus_remove_drive(GHalDrive *drive) { GList *volumes, *l; gboolean ret = TRUE; GError *error = NULL; gint exit_status = 0; g_return_val_if_fail(GHAL_IS_DRIVE(drive), FALSE); volumes = ghal_drive_list_volumes(drive); for(l = volumes; l; l = l->next) { GHalVolume *volume = l->data; if(ghal_volume_is_mounted(volume)) { gchar *udi_quoted = g_shell_quote(ghal_device_peek_udi(GHAL_DEVICE(volume))); gchar *cmd = g_strdup_printf("exo-unmount -n -u -h %s", udi_quoted); ret = g_spawn_command_line_sync(cmd, NULL, NULL, &exit_status, &error); g_free(udi_quoted); g_free(cmd); if(!ret || exit_status) break; } } g_list_foreach(volumes, (GFunc)g_object_unref, NULL); g_list_free(volumes); if(ghal_drive_requires_eject(drive)) { gchar *udi_quoted = g_shell_quote(ghal_device_peek_udi(GHAL_DEVICE(drive))); gchar *cmd = g_strdup_printf("exo-eject -n -e -h %s", udi_quoted); ret = g_spawn_command_line_sync(cmd, NULL, NULL, &exit_status, &error); g_free(udi_quoted); g_free(cmd); } if(!ret) { gchar *name = ghal_drive_get_display_name(drive); gchar *primary = g_strdup_printf(_("Unable to remove \"%s\""), name); xfce_message_dialog(NULL, _("Removal Failure"), GTK_STOCK_DIALOG_WARNING, primary, error ? error->message : _("Unknown error"), GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); g_free(name); g_free(primary); if(error) g_error_free(error); } return ret; }
static gboolean mailwatch_create(Control *c) { XfceMailwatchPlugin *mwp = g_new0(XfceMailwatchPlugin, 1); c->data = mwp; mwp->mailwatch = xfce_mailwatch_new(); if(G_UNLIKELY(!mwp->mailwatch)) { xfce_message_dialog(NULL, _("Xfce Mailwatch"), GTK_STOCK_DIALOG_ERROR, _("The mailwatch applet cannot be added to the panel."), _("It is possible that your version of GLib does not have threads support."), GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); g_free(mwp); return FALSE; } mwp->tooltip = gtk_tooltips_new(); mwp->button = gtk_button_new(); gtk_button_set_relief(GTK_BUTTON(mwp->button), GTK_RELIEF_NONE); gtk_widget_show(mwp->button); gtk_container_add(GTK_CONTAINER(c->base), mwp->button); g_signal_connect(mwp->button, "button-press-event", G_CALLBACK(mailwatch_button_press_cb), mwp); g_signal_connect(mwp->button, "button-release-event", G_CALLBACK(mailwatch_button_release_cb), mwp); gtk_tooltips_set_tip(mwp->tooltip, mwp->button, _("No new mail"), NULL); mwp->image = xfce_scaled_image_new(); gtk_widget_show(mwp->image); gtk_container_add(GTK_CONTAINER(mwp->button), mwp->image); mwp->loglist = gtk_list_store_new(LOGLIST_N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING ); xfce_mailwatch_signal_connect(mwp->mailwatch, XFCE_MAILWATCH_SIGNAL_NEW_MESSAGE_COUNT_CHANGED, mailwatch_new_messages_changed_cb, mwp); xfce_mailwatch_signal_connect( mwp->mailwatch, XFCE_MAILWATCH_SIGNAL_LOG_MESSAGE, mailwatch_log_message_cb, mwp); xfce_mailwatch_force_update(mwp->mailwatch); return TRUE; }
static void xfdesktop_volume_icon_unmount_finish(GObject *object, GAsyncResult *result, gpointer user_data) { XfdesktopVolumeIcon *icon = XFDESKTOP_VOLUME_ICON(user_data); GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon)); GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view); GMount *mount = G_MOUNT(object); GError *error = NULL; gboolean unmount_successful; g_return_if_fail(G_IS_MOUNT(object)); g_return_if_fail(G_IS_ASYNC_RESULT(result)); g_return_if_fail(XFDESKTOP_IS_VOLUME_ICON(icon)); unmount_successful = g_mount_unmount_with_operation_finish(mount, result, &error); if(!unmount_successful) { /* ignore GIO errors handled internally */ if(error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) { gchar *mount_name = g_mount_get_name(mount); gchar *primary = g_markup_printf_escaped(_("Failed to eject \"%s\""), mount_name); /* display an error dialog to inform the user */ xfce_message_dialog(toplevel ? GTK_WINDOW(toplevel) : NULL, _("Eject Failed"), GTK_STOCK_DIALOG_ERROR, primary, error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); g_free(primary); g_free(mount_name); } g_error_free(error); } #ifdef HAVE_LIBNOTIFY xfdesktop_notify_unmount_finish(mount, unmount_successful); #endif g_object_unref(icon); }
gint xfce_shortcut_conflict_dialog (GtkWindow *parent, const gchar *owner, const gchar *other, const gchar *shortcut, const gchar *owner_action, const gchar *other_action, gboolean ignore_same_provider) { GdkModifierType modifiers; gboolean handled; gchar *other_action_name; gchar *other_button_text; gchar *owner_action_name; gchar *owner_button_text; gchar *secondary_text; gchar *shortcut_label; gchar *title; guint keyval; gint response; gint i; /* Default values */ response = GTK_RESPONSE_ACCEPT; handled = FALSE; /* Make sure to use the translations from libxfce4ui */ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); if (g_utf8_collate (owner, other) == 0 && ignore_same_provider) return GTK_RESPONSE_ACCEPT; /* Get the shortcut label */ gtk_accelerator_parse (shortcut, &keyval, &modifiers); shortcut_label = gtk_accelerator_get_label (keyval, modifiers); if (g_utf8_collate (owner, other) == 0 && g_utf8_collate (owner_action, other_action) == 0) { /* This shortcut already exists in the provider, we don't want it twice */ /* Warn the user */ xfce_dialog_show_warning (parent, _("Please use another key combination."), _("%s already triggers this action."), shortcut_label); return GTK_RESPONSE_REJECT; } title = g_strdup_printf (_("Conflicting actions for %s"), shortcut_label); for (i = 0; conflict_messages[i].message != NULL; ++i) if (g_utf8_collate (conflict_messages[i].owner_name, owner) == 0 && g_utf8_collate (conflict_messages[i].other_name, other) == 0) { if (owner_action == NULL) owner_action_name = NULL; else if (g_utf8_collate (owner, "xfwm4") == 0) { DBG ("Owner action %s is an xfwm4 action, get the string", owner_action); /* We need to get the human readable string of the action name */ owner_action_name = g_strdup (xfce_shortcuts_xfwm4_get_feature_name (owner_action)); } else owner_action_name = g_strdup(owner_action); DBG ("Owner action name: %s", owner_action_name); if (other_action == NULL) other_action_name = NULL; else if (g_utf8_collate (other, "xfwm4") == 0) { /* We need to get the human readable string of the action name */ other_action_name = g_strdup (xfce_shortcuts_xfwm4_get_feature_name (other_action)); } else other_action_name = g_strdup (other_action); secondary_text = g_strdup_printf (_(conflict_messages[i].message), other_action_name); owner_button_text = g_strdup_printf (_(conflict_messages[i].owner_button_text), owner_action_name); other_button_text = g_strdup_printf (_(conflict_messages[i].other_button_text), other_action_name); response = xfce_message_dialog (parent, title, GTK_STOCK_DIALOG_QUESTION, title, secondary_text, XFCE_BUTTON_TYPE_MIXED, NULL, owner_button_text, GTK_RESPONSE_ACCEPT, XFCE_BUTTON_TYPE_MIXED, NULL, other_button_text, GTK_RESPONSE_REJECT, NULL); g_free (other_button_text); g_free (owner_button_text); g_free (secondary_text); g_free (other_action_name); g_free (owner_action_name); g_free (shortcut_label); handled = TRUE; break; } if (G_UNLIKELY (!handled)) { xfce_message_dialog (parent, title, GTK_STOCK_DIALOG_ERROR, title, _("This shortcut is already being used for something else."), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); response = GTK_RESPONSE_REJECT; } g_free (title); return response; }
static void xfdesktop_volume_icon_mount_finish(GObject *object, GAsyncResult *result, gpointer user_data) { XfdesktopVolumeIcon *icon = XFDESKTOP_VOLUME_ICON(user_data); GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon)); GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view); GVolume *volume = G_VOLUME(object); GError *error = NULL; if(!g_volume_mount_finish(volume, result, &error)) { if(error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) { gchar *volume_name = g_volume_get_name(volume); gchar *primary = g_markup_printf_escaped(_("Failed to mount \"%s\""), volume_name); xfce_message_dialog(toplevel ? GTK_WINDOW(toplevel) : NULL, _("Mount Failed"), GTK_STOCK_DIALOG_ERROR, primary, error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); g_free(primary); g_free(volume_name); } g_error_free(error); } else { GMount *mount = g_volume_get_mount(volume); GFile *file = NULL; GFileInfo *info = NULL; if(mount) { file = g_mount_get_root(mount); info = g_file_query_info(file, XFDESKTOP_FILE_INFO_NAMESPACE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref(mount); } if(file && info) { gboolean activated = FALSE; if(icon->priv->file) g_object_unref(icon->priv->file); icon->priv->file = g_object_ref(file); xfdesktop_file_icon_update_file_info(XFDESKTOP_FILE_ICON(icon), info); activated = GPOINTER_TO_UINT(g_object_get_qdata(G_OBJECT(icon), xfdesktop_volume_icon_activated_quark)); if(activated) { XfdesktopIcon *icon_p = XFDESKTOP_ICON(icon); XFDESKTOP_ICON_CLASS(xfdesktop_volume_icon_parent_class)->activated(icon_p); } g_object_set_qdata(G_OBJECT(icon), xfdesktop_volume_icon_activated_quark, NULL); } else { if(icon->priv->file) g_object_unref(icon->priv->file); icon->priv->file = NULL; xfdesktop_file_icon_update_file_info(XFDESKTOP_FILE_ICON(icon), NULL); } if(file) g_object_unref(file); if(info) g_object_unref(info); } }
/** * xfce_dialog_confirm: * @parent : (allow-none): transient parent of the dialog, or %NULL. * @stock_id : the stock name of the confirm button, for example #GTK_STOCK_YES or #GTK_STOCK_CLEAR. * @confirm_label : (allow-none): if non-%NULL, this text is used on the confirm button together with the @stock_id icon. * @secondary_text : (allow-none): secondary text in the dialog. * @primary_format : (allow-none): the printf()-style format for the dialog question. * @... : (allow-none): argument list for the @primary_format. * * Runs a questions dialog, that has a 'Cancel' and a 'Confirm' button. The 'Confirm' * button text can be set by @action if given. * * If @stock_id is equal to #GTK_STOCK_YES, the 'Cancel' button becomes a 'No' button. * * Return value: TRUE if the user confirms, else FALSE. */ gboolean xfce_dialog_confirm (GtkWindow *parent, const gchar *stock_id, const gchar *confirm_label, const gchar *secondary_text, const gchar *primary_format, ...) { va_list args; gchar *primary_text; const gchar *no_stock_id; gint response_id; g_return_val_if_fail (stock_id != NULL || confirm_label != NULL, FALSE); g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), FALSE); va_start (args, primary_format); primary_text = g_strdup_vprintf (primary_format, args); va_end (args); /* whether this will be a yes/no dialog */ if (stock_id != NULL && (strcmp (stock_id, "gtk-yes") == 0 || strcmp (stock_id, "yes") == 0)) { #if GTK_CHECK_VERSION (3, 10, 0) no_stock_id = _("No"); if (confirm_label == NULL) confirm_label = _("Yes"); #else no_stock_id = GTK_STOCK_NO; #endif } else { #if GTK_CHECK_VERSION (3, 10, 0) no_stock_id = _("Cancel"); #else no_stock_id = GTK_STOCK_CANCEL; #endif } #if GTK_CHECK_VERSION (3, 0, 0) response_id = xfce_message_dialog (parent, _("Question"), "dialog-question", primary_text, secondary_text, no_stock_id, GTK_RESPONSE_NO, XFCE_BUTTON_TYPE_MIXED, stock_id, confirm_label, GTK_RESPONSE_YES, NULL); #else response_id = xfce_message_dialog (parent, _("Question"), GTK_STOCK_DIALOG_QUESTION, primary_text, secondary_text, no_stock_id, GTK_RESPONSE_NO, XFCE_BUTTON_TYPE_MIXED, stock_id, confirm_label, GTK_RESPONSE_YES, NULL); #endif g_free (primary_text); return (response_id == GTK_RESPONSE_YES); }