media: port to GtkAppChooserButton
Use the new GTK+ widget instead of our homebrew comboboxes.
This commit is contained in:
parent
5b7132bacf
commit
0b4c4e05bf
2 changed files with 196 additions and 479 deletions
|
@ -27,8 +27,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
#include "nautilus-open-with-dialog.h"
|
|
||||||
|
|
||||||
G_DEFINE_DYNAMIC_TYPE (CcMediaPanel, cc_media_panel, CC_TYPE_PANEL)
|
G_DEFINE_DYNAMIC_TYPE (CcMediaPanel, cc_media_panel, CC_TYPE_PANEL)
|
||||||
|
|
||||||
#define MEDIA_PANEL_PRIVATE(o) \
|
#define MEDIA_PANEL_PRIVATE(o) \
|
||||||
|
@ -40,49 +38,17 @@ G_DEFINE_DYNAMIC_TYPE (CcMediaPanel, cc_media_panel, CC_TYPE_PANEL)
|
||||||
#define PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE "autorun-x-content-ignore"
|
#define PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE "autorun-x-content-ignore"
|
||||||
#define PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER "autorun-x-content-open-folder"
|
#define PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER "autorun-x-content-open-folder"
|
||||||
|
|
||||||
enum {
|
#define CUSTOM_ITEM_ASK "cc-item-ask"
|
||||||
AUTORUN_ASK,
|
#define CUSTOM_ITEM_DO_NOTHING "cc-item-do-nothing"
|
||||||
AUTORUN_IGNORE,
|
#define CUSTOM_ITEM_OPEN_FOLDER "cc-item-open-folder"
|
||||||
AUTORUN_APP,
|
|
||||||
AUTORUN_OPEN_FOLDER,
|
|
||||||
AUTORUN_SEP,
|
|
||||||
AUTORUN_OTHER_APP,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
COLUMN_AUTORUN_GICON,
|
|
||||||
COLUMN_AUTORUN_NAME,
|
|
||||||
COLUMN_AUTORUN_APP_INFO,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
COMBO_ITEM_ASK_OR_LABEL = 0,
|
|
||||||
COMBO_ITEM_DO_NOTHING,
|
|
||||||
COMBO_ITEM_OPEN_FOLDER
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _CcMediaPanelPrivate {
|
struct _CcMediaPanelPrivate {
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GSettings *preferences;
|
GSettings *preferences;
|
||||||
|
|
||||||
|
GtkWidget *other_application_combo;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
guint changed_signal_id;
|
|
||||||
GtkWidget *combo_box;
|
|
||||||
|
|
||||||
char *x_content_type;
|
|
||||||
|
|
||||||
gboolean other_application_selected;
|
|
||||||
CcMediaPanel *self;
|
|
||||||
} AutorunComboBoxData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
prepare_combo_box (CcMediaPanel *self,
|
|
||||||
GtkWidget *combo_box,
|
|
||||||
const char *x_content_type);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cc_media_panel_dispose (GObject *object)
|
cc_media_panel_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
|
@ -168,213 +134,6 @@ add_elem_to_str_array (char **v,
|
||||||
return (char **) g_ptr_array_free (array, FALSE);
|
return (char **) g_ptr_array_free (array, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_media_sensitivity (CcMediaPanel *self)
|
|
||||||
{
|
|
||||||
gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "media_handling_vbox")),
|
|
||||||
! g_settings_get_boolean (self->priv->preferences, PREF_MEDIA_AUTORUN_NEVER));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
autorun_set_preferences (CcMediaPanel *self,
|
|
||||||
const char *x_content_type,
|
|
||||||
gboolean pref_start_app,
|
|
||||||
gboolean pref_ignore,
|
|
||||||
gboolean pref_open_folder)
|
|
||||||
{
|
|
||||||
char **x_content_start_app;
|
|
||||||
char **x_content_ignore;
|
|
||||||
char **x_content_open_folder;
|
|
||||||
|
|
||||||
g_assert (x_content_type != NULL);
|
|
||||||
|
|
||||||
x_content_start_app = g_settings_get_strv (self->priv->preferences,
|
|
||||||
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP);
|
|
||||||
x_content_ignore = g_settings_get_strv (self->priv->preferences,
|
|
||||||
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE);
|
|
||||||
x_content_open_folder = g_settings_get_strv (self->priv->preferences,
|
|
||||||
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER);
|
|
||||||
|
|
||||||
x_content_start_app = remove_elem_from_str_array (x_content_start_app, x_content_type);
|
|
||||||
if (pref_start_app) {
|
|
||||||
x_content_start_app = add_elem_to_str_array (x_content_start_app, x_content_type);
|
|
||||||
}
|
|
||||||
g_settings_set_strv (self->priv->preferences,
|
|
||||||
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP, (const gchar * const*) x_content_start_app);
|
|
||||||
|
|
||||||
x_content_ignore = remove_elem_from_str_array (x_content_ignore, x_content_type);
|
|
||||||
if (pref_ignore) {
|
|
||||||
x_content_ignore = add_elem_to_str_array (x_content_ignore, x_content_type);
|
|
||||||
}
|
|
||||||
g_settings_set_strv (self->priv->preferences,
|
|
||||||
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE, (const gchar * const*) x_content_ignore);
|
|
||||||
|
|
||||||
x_content_open_folder = remove_elem_from_str_array (x_content_open_folder, x_content_type);
|
|
||||||
if (pref_open_folder) {
|
|
||||||
x_content_open_folder = add_elem_to_str_array (x_content_open_folder, x_content_type);
|
|
||||||
}
|
|
||||||
g_settings_set_strv (self->priv->preferences,
|
|
||||||
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder);
|
|
||||||
|
|
||||||
g_strfreev (x_content_open_folder);
|
|
||||||
g_strfreev (x_content_ignore);
|
|
||||||
g_strfreev (x_content_start_app);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
autorun_rebuild_combo_box (AutorunComboBoxData *data)
|
|
||||||
{
|
|
||||||
char *x_content_type;
|
|
||||||
|
|
||||||
x_content_type = g_strdup (data->x_content_type);
|
|
||||||
prepare_combo_box (data->self,
|
|
||||||
data->combo_box,
|
|
||||||
x_content_type);
|
|
||||||
|
|
||||||
g_free (x_content_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
other_application_selected (NautilusOpenWithDialog *dialog,
|
|
||||||
GAppInfo *app_info,
|
|
||||||
AutorunComboBoxData *data)
|
|
||||||
{
|
|
||||||
autorun_set_preferences (data->self, data->x_content_type, TRUE, FALSE, FALSE);
|
|
||||||
g_app_info_set_as_default_for_type (app_info,
|
|
||||||
data->x_content_type,
|
|
||||||
NULL);
|
|
||||||
data->other_application_selected = TRUE;
|
|
||||||
|
|
||||||
/* rebuild so we include and select the new application in the list */
|
|
||||||
autorun_rebuild_combo_box (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_dialog_closure (AutorunComboBoxData *data)
|
|
||||||
{
|
|
||||||
if (!data->other_application_selected) {
|
|
||||||
/* reset combo box so we don't linger on "Open with other Application..." */
|
|
||||||
autorun_rebuild_combo_box (data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
combo_box_changed (GtkComboBox *combo_box,
|
|
||||||
AutorunComboBoxData *data)
|
|
||||||
{
|
|
||||||
GtkTreeIter iter;
|
|
||||||
GtkTreeModel *model;
|
|
||||||
GAppInfo *app_info;
|
|
||||||
char *x_content_type;
|
|
||||||
int type;
|
|
||||||
CcMediaPanel *self = data->self;
|
|
||||||
|
|
||||||
model = NULL;
|
|
||||||
app_info = NULL;
|
|
||||||
x_content_type = NULL;
|
|
||||||
|
|
||||||
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
model = gtk_combo_box_get_model (combo_box);
|
|
||||||
if (model == NULL) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_tree_model_get (model, &iter,
|
|
||||||
COLUMN_AUTORUN_APP_INFO, &app_info,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, &x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, &type,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case AUTORUN_ASK:
|
|
||||||
autorun_set_preferences (self, x_content_type,
|
|
||||||
FALSE, FALSE, FALSE);
|
|
||||||
break;
|
|
||||||
case AUTORUN_IGNORE:
|
|
||||||
autorun_set_preferences (self, x_content_type,
|
|
||||||
FALSE, TRUE, FALSE);
|
|
||||||
break;
|
|
||||||
case AUTORUN_OPEN_FOLDER:
|
|
||||||
autorun_set_preferences (self, x_content_type,
|
|
||||||
FALSE, FALSE, TRUE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUTORUN_APP:
|
|
||||||
autorun_set_preferences (self, x_content_type,
|
|
||||||
TRUE, FALSE, FALSE);
|
|
||||||
g_app_info_set_as_default_for_type (app_info,
|
|
||||||
x_content_type,
|
|
||||||
NULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AUTORUN_OTHER_APP:
|
|
||||||
{
|
|
||||||
GtkWidget *dialog;
|
|
||||||
|
|
||||||
data->other_application_selected = FALSE;
|
|
||||||
|
|
||||||
dialog = nautilus_add_application_dialog_new (NULL, x_content_type);
|
|
||||||
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
|
||||||
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (data->self))));
|
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
||||||
g_signal_connect (dialog, "application_selected",
|
|
||||||
G_CALLBACK (other_application_selected),
|
|
||||||
data);
|
|
||||||
g_signal_connect_swapped (dialog, "response",
|
|
||||||
G_CALLBACK (handle_dialog_closure), data);
|
|
||||||
g_signal_connect_swapped (dialog, "destroy",
|
|
||||||
G_CALLBACK (handle_dialog_closure), data);
|
|
||||||
gtk_widget_show (GTK_WIDGET (dialog));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (app_info != NULL) {
|
|
||||||
g_object_unref (app_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (x_content_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
other_type_combo_box_changed (GtkComboBox *combo_box,
|
|
||||||
CcMediaPanel *self)
|
|
||||||
{
|
|
||||||
GtkTreeIter iter;
|
|
||||||
GtkTreeModel *model;
|
|
||||||
char *x_content_type;
|
|
||||||
GtkWidget *action_combo_box;
|
|
||||||
|
|
||||||
x_content_type = NULL;
|
|
||||||
|
|
||||||
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
model = gtk_combo_box_get_model (combo_box);
|
|
||||||
if (model == NULL) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_tree_model_get (model, &iter,
|
|
||||||
2, &x_content_type,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
action_combo_box = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
|
|
||||||
"media_other_action_combobox"));
|
|
||||||
|
|
||||||
prepare_combo_box (self, action_combo_box,
|
|
||||||
x_content_type);
|
|
||||||
out:
|
|
||||||
g_free (x_content_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
media_panel_g_strv_find (char **strv,
|
media_panel_g_strv_find (char **strv,
|
||||||
const char *find_me)
|
const char *find_me)
|
||||||
|
@ -430,254 +189,206 @@ autorun_get_preferences (CcMediaPanel *self,
|
||||||
g_strfreev (x_content_open_folder);
|
g_strfreev (x_content_open_folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
combo_box_separator_func (GtkTreeModel *model,
|
autorun_set_preferences (CcMediaPanel *self,
|
||||||
GtkTreeIter *iter,
|
const char *x_content_type,
|
||||||
gpointer data)
|
gboolean pref_start_app,
|
||||||
|
gboolean pref_ignore,
|
||||||
|
gboolean pref_open_folder)
|
||||||
{
|
{
|
||||||
char *str;
|
char **x_content_start_app;
|
||||||
|
char **x_content_ignore;
|
||||||
|
char **x_content_open_folder;
|
||||||
|
|
||||||
gtk_tree_model_get (model, iter,
|
g_assert (x_content_type != NULL);
|
||||||
1, &str,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
if (str != NULL) {
|
x_content_start_app = g_settings_get_strv (self->priv->preferences,
|
||||||
g_free (str);
|
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP);
|
||||||
return FALSE;
|
x_content_ignore = g_settings_get_strv (self->priv->preferences,
|
||||||
|
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE);
|
||||||
|
x_content_open_folder = g_settings_get_strv (self->priv->preferences,
|
||||||
|
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER);
|
||||||
|
|
||||||
|
x_content_start_app = remove_elem_from_str_array (x_content_start_app, x_content_type);
|
||||||
|
if (pref_start_app) {
|
||||||
|
x_content_start_app = add_elem_to_str_array (x_content_start_app, x_content_type);
|
||||||
|
}
|
||||||
|
g_settings_set_strv (self->priv->preferences,
|
||||||
|
PREF_MEDIA_AUTORUN_X_CONTENT_START_APP, (const gchar * const*) x_content_start_app);
|
||||||
|
|
||||||
|
x_content_ignore = remove_elem_from_str_array (x_content_ignore, x_content_type);
|
||||||
|
if (pref_ignore) {
|
||||||
|
x_content_ignore = add_elem_to_str_array (x_content_ignore, x_content_type);
|
||||||
|
}
|
||||||
|
g_settings_set_strv (self->priv->preferences,
|
||||||
|
PREF_MEDIA_AUTORUN_X_CONTENT_IGNORE, (const gchar * const*) x_content_ignore);
|
||||||
|
|
||||||
|
x_content_open_folder = remove_elem_from_str_array (x_content_open_folder, x_content_type);
|
||||||
|
if (pref_open_folder) {
|
||||||
|
x_content_open_folder = add_elem_to_str_array (x_content_open_folder, x_content_type);
|
||||||
|
}
|
||||||
|
g_settings_set_strv (self->priv->preferences,
|
||||||
|
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder);
|
||||||
|
|
||||||
|
g_strfreev (x_content_open_folder);
|
||||||
|
g_strfreev (x_content_ignore);
|
||||||
|
g_strfreev (x_content_start_app);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_media_sensitivity (CcMediaPanel *self)
|
||||||
|
{
|
||||||
|
gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "media_handling_vbox")),
|
||||||
|
! g_settings_get_boolean (self->priv->preferences, PREF_MEDIA_AUTORUN_NEVER));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
custom_item_activated_cb (GtkAppChooserButton *button,
|
||||||
|
const gchar *item,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
CcMediaPanel *self = user_data;
|
||||||
|
gchar *content_type;
|
||||||
|
|
||||||
|
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button));
|
||||||
|
|
||||||
|
if (g_strcmp0 (item, CUSTOM_ITEM_ASK) == 0) {
|
||||||
|
autorun_set_preferences (self, content_type,
|
||||||
|
FALSE, FALSE, FALSE);
|
||||||
|
} else if (g_strcmp0 (item, CUSTOM_ITEM_OPEN_FOLDER) == 0) {
|
||||||
|
autorun_set_preferences (self, content_type,
|
||||||
|
FALSE, FALSE, TRUE);
|
||||||
|
} else if (g_strcmp0 (item, CUSTOM_ITEM_DO_NOTHING) == 0) {
|
||||||
|
autorun_set_preferences (self, content_type,
|
||||||
|
FALSE, TRUE, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
g_free (content_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
autorun_combobox_data_destroy (AutorunComboBoxData *data)
|
combo_box_changed_cb (GtkComboBox *combo_box,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
/* signal handler may be automatically disconnected by destroying the widget */
|
CcMediaPanel *self = user_data;
|
||||||
if (g_signal_handler_is_connected (data->combo_box, data->changed_signal_id)) {
|
GAppInfo *info;
|
||||||
g_signal_handler_disconnect (data->combo_box, data->changed_signal_id);
|
gchar *content_type;
|
||||||
}
|
|
||||||
g_free (data->x_content_type);
|
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
|
||||||
g_free (data);
|
|
||||||
|
if (info == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (combo_box));
|
||||||
|
autorun_set_preferences (self, content_type,
|
||||||
|
TRUE, FALSE, FALSE);
|
||||||
|
g_app_info_set_as_default_for_type (info, content_type, NULL);
|
||||||
|
|
||||||
|
g_object_unref (info);
|
||||||
|
g_free (content_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prepare_combo_box (CcMediaPanel *self,
|
prepare_combo_box (CcMediaPanel *self,
|
||||||
GtkWidget *combo_box,
|
GtkWidget *combo_box)
|
||||||
const char *x_content_type)
|
|
||||||
{
|
{
|
||||||
GList *l;
|
GtkAppChooserButton *app_chooser = GTK_APP_CHOOSER_BUTTON (combo_box);
|
||||||
GList *app_info_list;
|
|
||||||
GAppInfo *default_app_info;
|
|
||||||
GtkListStore *list_store;
|
|
||||||
GtkTreeIter iter;
|
|
||||||
GIcon *icon;
|
GIcon *icon;
|
||||||
int set_active;
|
|
||||||
int n;
|
|
||||||
int num_apps;
|
|
||||||
gboolean pref_ask;
|
gboolean pref_ask;
|
||||||
gboolean pref_start_app;
|
gboolean pref_start_app;
|
||||||
gboolean pref_ignore;
|
gboolean pref_ignore;
|
||||||
gboolean pref_open_folder;
|
gboolean pref_open_folder;
|
||||||
AutorunComboBoxData *data;
|
GAppInfo *info;
|
||||||
GtkCellRenderer *renderer;
|
gchar *content_type;
|
||||||
gboolean new_data;
|
|
||||||
|
|
||||||
autorun_get_preferences (self, x_content_type,
|
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser));
|
||||||
|
|
||||||
|
/* fetch preferences for this content type */
|
||||||
|
autorun_get_preferences (self, content_type,
|
||||||
&pref_start_app, &pref_ignore, &pref_open_folder);
|
&pref_start_app, &pref_ignore, &pref_open_folder);
|
||||||
pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;
|
pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;
|
||||||
|
|
||||||
set_active = -1;
|
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
|
||||||
data = NULL;
|
|
||||||
new_data = TRUE;
|
|
||||||
|
|
||||||
app_info_list = g_app_info_get_all_for_type (x_content_type);
|
/* append the separator only if we have >= 1 apps in the chooser */
|
||||||
default_app_info = g_app_info_get_default_for_type (x_content_type, FALSE);
|
if (info != NULL) {
|
||||||
num_apps = g_list_length (app_info_list);
|
gtk_app_chooser_button_append_separator (app_chooser);
|
||||||
|
g_object_unref (info);
|
||||||
list_store = gtk_list_store_new (5,
|
|
||||||
G_TYPE_ICON,
|
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_APP_INFO,
|
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_INT);
|
|
||||||
|
|
||||||
/* no apps installed */
|
|
||||||
if (num_apps == 0) {
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
icon = g_themed_icon_new (GTK_STOCK_DIALOG_ERROR);
|
|
||||||
|
|
||||||
/* TODO: integrate with PackageKit-gnome to find applications */
|
|
||||||
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, icon,
|
|
||||||
COLUMN_AUTORUN_NAME, _("No applications found"),
|
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
|
|
||||||
-1);
|
|
||||||
g_object_unref (icon);
|
|
||||||
} else {
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
icon = g_themed_icon_new (GTK_STOCK_DIALOG_QUESTION);
|
|
||||||
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, icon,
|
|
||||||
COLUMN_AUTORUN_NAME, _("Ask what to do"),
|
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
|
|
||||||
-1);
|
|
||||||
g_object_unref (icon);
|
|
||||||
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
icon = g_themed_icon_new (GTK_STOCK_CLOSE);
|
|
||||||
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, icon,
|
|
||||||
COLUMN_AUTORUN_NAME, _("Do Nothing"),
|
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE,
|
|
||||||
-1);
|
|
||||||
g_object_unref (icon);
|
|
||||||
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
icon = g_themed_icon_new ("folder-open");
|
|
||||||
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, icon,
|
|
||||||
COLUMN_AUTORUN_NAME, _("Open Folder"),
|
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER,
|
|
||||||
-1);
|
|
||||||
g_object_unref (icon);
|
|
||||||
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, NULL,
|
|
||||||
COLUMN_AUTORUN_NAME, NULL,
|
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
for (l = app_info_list, n = 4; l != NULL; l = l->next, n++) {
|
|
||||||
char *open_string;
|
|
||||||
GAppInfo *app_info = l->data;
|
|
||||||
|
|
||||||
/* we deliberately ignore should_show because some apps might want
|
|
||||||
* to install special handlers that should be hidden in the regular
|
|
||||||
* application launcher menus
|
|
||||||
*/
|
|
||||||
|
|
||||||
icon = g_app_info_get_icon (app_info);
|
|
||||||
open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info));
|
|
||||||
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, icon,
|
|
||||||
COLUMN_AUTORUN_NAME, open_string,
|
|
||||||
COLUMN_AUTORUN_APP_INFO, app_info,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
g_free (open_string);
|
|
||||||
|
|
||||||
if (g_app_info_equal (app_info, default_app_info)) {
|
|
||||||
set_active = n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
icon = g_themed_icon_new (GTK_STOCK_DIALOG_QUESTION);
|
||||||
gtk_list_store_set (list_store, &iter,
|
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK,
|
||||||
COLUMN_AUTORUN_GICON, NULL,
|
_("Ask what to do"),
|
||||||
COLUMN_AUTORUN_NAME, NULL,
|
icon);
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
gtk_list_store_append (list_store, &iter);
|
|
||||||
icon = g_themed_icon_new ("application-x-executable");
|
|
||||||
|
|
||||||
gtk_list_store_set (list_store, &iter,
|
|
||||||
COLUMN_AUTORUN_GICON, icon,
|
|
||||||
COLUMN_AUTORUN_NAME, _("Open with other Application..."),
|
|
||||||
COLUMN_AUTORUN_APP_INFO, NULL,
|
|
||||||
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
|
|
||||||
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP,
|
|
||||||
-1);
|
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
|
|
||||||
if (default_app_info != NULL) {
|
icon = g_themed_icon_new (GTK_STOCK_CLOSE);
|
||||||
g_object_unref (default_app_info);
|
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING,
|
||||||
}
|
_("Do Nothing"),
|
||||||
g_list_free_full (app_info_list, g_object_unref);
|
icon);
|
||||||
|
g_object_unref (icon);
|
||||||
|
|
||||||
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (list_store));
|
icon = g_themed_icon_new ("folder-open");
|
||||||
g_object_unref (list_store);
|
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER,
|
||||||
|
_("Open Folder"),
|
||||||
|
icon);
|
||||||
|
g_object_unref (icon);
|
||||||
|
|
||||||
gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box));
|
gtk_app_chooser_button_set_show_dialog_item (app_chooser, TRUE);
|
||||||
|
|
||||||
renderer = gtk_cell_renderer_pixbuf_new ();
|
if (pref_ask) {
|
||||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
|
gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_ASK);
|
||||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
|
} else if (pref_ignore) {
|
||||||
"gicon", COLUMN_AUTORUN_GICON,
|
gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING);
|
||||||
NULL);
|
} else if (pref_open_folder) {
|
||||||
renderer = gtk_cell_renderer_text_new ();
|
gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER);
|
||||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
|
|
||||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
|
|
||||||
"text", COLUMN_AUTORUN_NAME,
|
|
||||||
NULL);
|
|
||||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box), combo_box_separator_func, NULL, NULL);
|
|
||||||
|
|
||||||
if (num_apps == 0) {
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COMBO_ITEM_ASK_OR_LABEL);
|
|
||||||
gtk_widget_set_sensitive (combo_box, FALSE);
|
|
||||||
} else {
|
|
||||||
gtk_widget_set_sensitive (combo_box, TRUE);
|
|
||||||
if (pref_ask) {
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COMBO_ITEM_ASK_OR_LABEL);
|
|
||||||
} else if (pref_ignore) {
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COMBO_ITEM_DO_NOTHING);
|
|
||||||
} else if (pref_open_folder) {
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COMBO_ITEM_OPEN_FOLDER);
|
|
||||||
} else if (set_active != -1) {
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), set_active);
|
|
||||||
} else {
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COMBO_ITEM_DO_NOTHING);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See if we have an old data around */
|
|
||||||
data = g_object_get_data (G_OBJECT (combo_box), "autorun_combobox_data");
|
|
||||||
if (data) {
|
|
||||||
new_data = FALSE;
|
|
||||||
g_free (data->x_content_type);
|
|
||||||
} else {
|
|
||||||
data = g_new0 (AutorunComboBoxData, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
data->x_content_type = g_strdup (x_content_type);
|
|
||||||
data->combo_box = combo_box;
|
|
||||||
data->self = self;
|
|
||||||
|
|
||||||
if (data->changed_signal_id == 0) {
|
|
||||||
data->changed_signal_id = g_signal_connect (combo_box,
|
|
||||||
"changed",
|
|
||||||
G_CALLBACK (combo_box_changed),
|
|
||||||
data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_data) {
|
g_signal_connect (app_chooser, "changed",
|
||||||
g_object_set_data_full (G_OBJECT (combo_box),
|
G_CALLBACK (combo_box_changed_cb), self);
|
||||||
"autorun_combobox_data",
|
g_signal_connect (app_chooser, "custom-item-activated",
|
||||||
data,
|
G_CALLBACK (custom_item_activated_cb), self);
|
||||||
(GDestroyNotify) autorun_combobox_data_destroy);
|
|
||||||
|
g_free (content_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
other_type_combo_box_changed (GtkComboBox *combo_box,
|
||||||
|
CcMediaPanel *self)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
GtkTreeModel *model;
|
||||||
|
char *x_content_type;
|
||||||
|
GtkWidget *action_container;
|
||||||
|
|
||||||
|
x_content_type = NULL;
|
||||||
|
|
||||||
|
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model = gtk_combo_box_get_model (combo_box);
|
||||||
|
if (model == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_tree_model_get (model, &iter,
|
||||||
|
2, &x_content_type,
|
||||||
|
-1);
|
||||||
|
|
||||||
|
action_container = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
|
||||||
|
"media_other_action_container"));
|
||||||
|
if (self->priv->other_application_combo != NULL) {
|
||||||
|
gtk_widget_destroy (self->priv->other_application_combo);
|
||||||
|
}
|
||||||
|
|
||||||
|
self->priv->other_application_combo = gtk_app_chooser_button_new (x_content_type);
|
||||||
|
gtk_box_pack_start (GTK_BOX (action_container), self->priv->other_application_combo, TRUE, TRUE, 0);
|
||||||
|
prepare_combo_box (self, self->priv->other_application_combo);
|
||||||
|
gtk_widget_show (self->priv->other_application_combo);
|
||||||
|
|
||||||
|
g_free (x_content_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -686,6 +397,11 @@ on_extra_options_dialog_response (GtkWidget *dialog,
|
||||||
CcMediaPanel *self)
|
CcMediaPanel *self)
|
||||||
{
|
{
|
||||||
gtk_widget_hide (dialog);
|
gtk_widget_hide (dialog);
|
||||||
|
|
||||||
|
if (self->priv->other_application_combo != NULL) {
|
||||||
|
gtk_widget_destroy (self->priv->other_application_combo);
|
||||||
|
self->priv->other_application_combo = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -701,7 +417,7 @@ on_extra_options_button_clicked (GtkWidget *button,
|
||||||
g_signal_connect (dialog,
|
g_signal_connect (dialog,
|
||||||
"response",
|
"response",
|
||||||
G_CALLBACK (on_extra_options_dialog_response),
|
G_CALLBACK (on_extra_options_dialog_response),
|
||||||
NULL);
|
self);
|
||||||
gtk_window_present (GTK_WINDOW (dialog));
|
gtk_window_present (GTK_WINDOW (dialog));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,21 +433,17 @@ media_panel_setup (CcMediaPanel *self)
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkBuilder *builder = self->priv->builder;
|
GtkBuilder *builder = self->priv->builder;
|
||||||
|
|
||||||
struct {
|
const gchar *widget_names[] = {
|
||||||
const gchar *widget_name;
|
"media_audio_cdda_combobox",
|
||||||
const gchar *content_type;
|
"media_video_dvd_combobox",
|
||||||
} const defs[] = {
|
"media_music_player_combobox",
|
||||||
{ "media_audio_cdda_combobox", "x-content/audio-cdda" },
|
"media_dcf_combobox",
|
||||||
{ "media_video_dvd_combobox", "x-content/video-dvd" },
|
"media_software_combobox",
|
||||||
{ "media_music_player_combobox", "x-content/audio-player" },
|
|
||||||
{ "media_dcf_combobox", "x-content/image-dcf" },
|
|
||||||
{ "media_software_combobox", "x-content/software" },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (n = 0; n < G_N_ELEMENTS (defs); n++) {
|
for (n = 0; n < G_N_ELEMENTS (defs); n++) {
|
||||||
prepare_combo_box (self,
|
prepare_combo_box (self,
|
||||||
GTK_WIDGET (gtk_builder_get_object (builder, defs[n].widget_name)),
|
GTK_WIDGET (gtk_builder_get_object (builder, defs[n].widget_name)));
|
||||||
defs[n].content_type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
other_type_combo_box = GTK_WIDGET (gtk_builder_get_object (builder, "media_other_type_combobox"));
|
other_type_combo_box = GTK_WIDGET (gtk_builder_get_object (builder, "media_other_type_combobox"));
|
||||||
|
|
|
@ -94,8 +94,9 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="media_audio_cdda_combobox">
|
<object class="GtkAppChooserButton" id="media_audio_cdda_combobox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="content-type">x-content/audio-cdda</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="left_attach">1</property>
|
||||||
|
@ -104,8 +105,9 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="media_video_dvd_combobox">
|
<object class="GtkAppChooserButton" id="media_video_dvd_combobox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="content-type">x-content/video-dvd</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="left_attach">1</property>
|
||||||
|
@ -132,8 +134,9 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="media_music_player_combobox">
|
<object class="GtkAppChooserButton" id="media_music_player_combobox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="content-type">"x-content/audio-player"</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="left_attach">1</property>
|
||||||
|
@ -160,8 +163,9 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="media_dcf_combobox">
|
<object class="GtkAppChooserButton" id="media_dcf_combobox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="content-type">x-content/image-dcf</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="left_attach">1</property>
|
||||||
|
@ -188,8 +192,9 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="media_software_combobox">
|
<object class="GtkAppChooserButton" id="media_software_combobox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="content-type">x-content/software</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="left_attach">1</property>
|
||||||
|
@ -357,7 +362,7 @@
|
||||||
<property name="xalign">0</property>
|
<property name="xalign">0</property>
|
||||||
<property name="label" translatable="yes">Acti_on:</property>
|
<property name="label" translatable="yes">Acti_on:</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="mnemonic_widget">media_other_action_combobox</property>
|
<property name="mnemonic_widget">media_other_action_container</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="top_attach">1</property>
|
<property name="top_attach">1</property>
|
||||||
|
@ -367,7 +372,7 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="media_other_action_combobox">
|
<object class="GtkBox" id="media_other_action_container">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue