diff options
Diffstat (limited to 'capplet')
-rw-r--r-- | capplet/Makefile.am | 2 | ||||
-rw-r--r-- | capplet/gsm-properties-dialog.c | 43 | ||||
-rw-r--r-- | capplet/gsp-app-manager.c | 1 | ||||
-rw-r--r-- | capplet/gsp-app.c | 5 | ||||
-rw-r--r-- | capplet/gsp-keyfile.c | 33 | ||||
-rw-r--r-- | capplet/gsp-keyfile.h | 4 | ||||
-rw-r--r-- | capplet/msm-desktop-app-dialog.c | 315 | ||||
-rw-r--r-- | capplet/msm-desktop-app-dialog.h | 20 |
8 files changed, 377 insertions, 46 deletions
diff --git a/capplet/Makefile.am b/capplet/Makefile.am index d2ccfdd..a680ea4 100644 --- a/capplet/Makefile.am +++ b/capplet/Makefile.am @@ -15,6 +15,8 @@ mate_session_properties_SOURCES = \ gsm-properties-dialog.c \ gsm-app-dialog.h \ gsm-app-dialog.c \ + msm-desktop-app-dialog.h \ + msm-desktop-app-dialog.c \ gsp-app.h \ gsp-app.c \ gsp-app-manager.h \ diff --git a/capplet/gsm-properties-dialog.c b/capplet/gsm-properties-dialog.c index a67d81a..d05d564 100644 --- a/capplet/gsm-properties-dialog.c +++ b/capplet/gsm-properties-dialog.c @@ -32,6 +32,7 @@ #include "gsm-properties-dialog.h" #include "gsm-app-dialog.h" +#include "msm-desktop-app-dialog.h" #include "gsm-util.h" #include "gsp-app.h" #include "gsp-app-manager.h" @@ -40,6 +41,7 @@ #define CAPPLET_TREEVIEW_WIDGET_NAME "session_properties_treeview" #define CAPPLET_ADD_WIDGET_NAME "session_properties_add_button" +#define CAPPLET_DESKTOP_ADD_WIDGET_NAME "session_properties_desktop_add_button" #define CAPPLET_DELETE_WIDGET_NAME "session_properties_delete_button" #define CAPPLET_EDIT_WIDGET_NAME "session_properties_edit_button" #define CAPPLET_SAVE_WIDGET_NAME "session_properties_save_button" @@ -61,6 +63,7 @@ struct _GsmPropertiesDialog GtkTreeView *treeview; GtkWidget *add_button; + GtkWidget *desktop_add_button; GtkWidget *delete_button; GtkWidget *edit_button; @@ -388,6 +391,33 @@ on_add_app_clicked (GtkWidget *widget, } static void +on_desktop_add_app_clicked (GtkWidget *widget, + GsmPropertiesDialog *dialog) +{ + GtkWidget *desktop_add_dialog; + gint response; + const char *filename; + + desktop_add_dialog = msm_desktop_app_dialog_new (dialog->manager); + gtk_window_set_transient_for (GTK_WINDOW (desktop_add_dialog), + GTK_WINDOW (dialog)); + + gtk_widget_show_all (desktop_add_dialog); + response = gtk_dialog_run (GTK_DIALOG (desktop_add_dialog)); + + if (response == GTK_RESPONSE_OK) + { + filename = msm_dektop_app_dialog_get_selected (MSM_DESKTOP_APP_DIALOG (desktop_add_dialog)); + if (filename != NULL) + { + gsp_app_copy_desktop_file (g_filename_to_uri (filename, NULL, NULL)); + } + } + + gtk_widget_destroy (desktop_add_dialog); +} + +static void on_delete_app_clicked (GtkWidget *widget, GsmPropertiesDialog *dialog) { @@ -671,7 +701,6 @@ setup_dialog (GsmPropertiesDialog *dialog) NULL); gtk_tree_view_append_column (treeview, column); - gtk_tree_view_column_set_sort_column_id (column, STORE_COL_DESCRIPTION); gtk_tree_view_set_search_column (treeview, STORE_COL_SEARCH); @@ -716,7 +745,6 @@ setup_dialog (GsmPropertiesDialog *dialog) STORE_COL_DESCRIPTION, GTK_SORT_ASCENDING); - button = GTK_WIDGET (gtk_builder_get_object (dialog->xml, CAPPLET_ADD_WIDGET_NAME)); dialog->add_button = button; @@ -726,6 +754,14 @@ setup_dialog (GsmPropertiesDialog *dialog) dialog); button = GTK_WIDGET (gtk_builder_get_object (dialog->xml, + CAPPLET_DESKTOP_ADD_WIDGET_NAME)); + dialog->desktop_add_button = button; + g_signal_connect (button, + "clicked", + G_CALLBACK (on_desktop_add_app_clicked), + dialog); + + button = GTK_WIDGET (gtk_builder_get_object (dialog->xml, CAPPLET_DELETE_WIDGET_NAME)); dialog->delete_button = button; g_signal_connect (button, @@ -741,7 +777,6 @@ setup_dialog (GsmPropertiesDialog *dialog) G_CALLBACK (on_edit_app_clicked), dialog); - button = GTK_WIDGET (gtk_builder_get_object (dialog->xml, CAPPLET_REMEMBER_WIDGET_NAME)); @@ -859,7 +894,7 @@ gsm_properties_dialog_init (GsmPropertiesDialog *dialog) gtk_box_pack_start (GTK_BOX (content_area), widget, TRUE, TRUE, 0); gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_box_set_spacing (GTK_BOX (content_area), 2); gtk_window_set_icon_name (GTK_WINDOW (dialog), "mate-session-properties"); gtk_window_set_title (GTK_WINDOW (dialog), _("Startup Applications Preferences")); diff --git a/capplet/gsp-app-manager.c b/capplet/gsp-app-manager.c index 3f663ad..6d3b0f5 100644 --- a/capplet/gsp-app-manager.c +++ b/capplet/gsp-app-manager.c @@ -48,7 +48,6 @@ enum { static guint gsp_app_manager_signals[LAST_SIGNAL] = { 0 }; - G_DEFINE_TYPE_WITH_PRIVATE (GspAppManager, gsp_app_manager, G_TYPE_OBJECT) static void gsp_app_manager_dispose (GObject *object); diff --git a/capplet/gsp-app.c b/capplet/gsp-app.c index bd55353..6c2250a 100644 --- a/capplet/gsp-app.c +++ b/capplet/gsp-app.c @@ -89,14 +89,12 @@ enum { static guint gsp_app_signals[LAST_SIGNAL] = { 0 }; - G_DEFINE_TYPE_WITH_PRIVATE (GspApp, gsp_app, G_TYPE_OBJECT) static void gsp_app_dispose (GObject *object); static void gsp_app_finalize (GObject *object); static gboolean _gsp_app_save (gpointer data); - static gboolean _gsp_str_equal (const char *a, const char *b) @@ -116,7 +114,6 @@ _gsp_str_equal (const char *a, return FALSE; } - static void gsp_app_class_init (GspAppClass *class) { @@ -493,7 +490,7 @@ _gsp_app_save (gpointer data) } _gsp_ensure_user_autostart_dir (); - if (gsp_key_file_to_file (keyfile, priv->path, NULL)) { + if (g_key_file_save_to_file (keyfile, priv->path, NULL)) { priv->skip_next_monitor_event = TRUE; _gsp_app_save_done_success (app); } else { diff --git a/capplet/gsp-keyfile.c b/capplet/gsp-keyfile.c index 434ec97..260c1de 100644 --- a/capplet/gsp-keyfile.c +++ b/capplet/gsp-keyfile.c @@ -43,39 +43,6 @@ gsp_key_file_populate (GKeyFile *keyfile) "/bin/false"); } -//FIXME: kill this when bug #309224 is fixed -gboolean -gsp_key_file_to_file (GKeyFile *keyfile, - const gchar *path, - GError **error) -{ - GError *write_error; - gchar *data; - gsize length; - gboolean res; - - g_return_val_if_fail (keyfile != NULL, FALSE); - g_return_val_if_fail (path != NULL, FALSE); - - write_error = NULL; - data = g_key_file_to_data (keyfile, &length, &write_error); - - if (write_error) { - g_propagate_error (error, write_error); - return FALSE; - } - - res = g_file_set_contents (path, data, length, &write_error); - g_free (data); - - if (write_error) { - g_propagate_error (error, write_error); - return FALSE; - } - - return res; -} - gboolean gsp_key_file_get_boolean (GKeyFile *keyfile, const gchar *key, diff --git a/capplet/gsp-keyfile.h b/capplet/gsp-keyfile.h index 7838017..ed7a0c9 100644 --- a/capplet/gsp-keyfile.h +++ b/capplet/gsp-keyfile.h @@ -38,10 +38,6 @@ extern "C" { void gsp_key_file_populate (GKeyFile *keyfile); -gboolean gsp_key_file_to_file (GKeyFile *keyfile, - const gchar *path, - GError **error); - gboolean gsp_key_file_get_boolean (GKeyFile *keyfile, const gchar *key, gboolean default_value); diff --git a/capplet/msm-desktop-app-dialog.c b/capplet/msm-desktop-app-dialog.c new file mode 100644 index 0000000..cb0c3dd --- /dev/null +++ b/capplet/msm-desktop-app-dialog.c @@ -0,0 +1,315 @@ +#include "config.h" +#include <glib.h> +#include <glib/gi18n.h> + +#include "msm-desktop-app-dialog.h" + +struct _MsmDesktopAppDialog +{ + GtkDialog parent; + + GtkWidget *entry; + GtkWidget *listbox; +}; + +G_DEFINE_TYPE (MsmDesktopAppDialog, msm_desktop_app_dialog, GTK_TYPE_DIALOG) + +static void +on_search_entry_changed (GtkSearchEntry *entry, + MsmDesktopAppDialog *dialog) +{ + GtkListBoxRow *selected; + + gtk_list_box_invalidate_filter (GTK_LIST_BOX (dialog->listbox)); + selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (dialog->listbox)); + + if (selected != NULL && gtk_widget_get_mapped (GTK_WIDGET (selected))) + { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE); + } + else + { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE); + } +} + +static gint +list_sort_app_func (GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer user_data) +{ + GAppInfo *app1, *app2; + + app1 = g_object_get_data (G_OBJECT (row1), "appinfo"); + app2 = g_object_get_data (G_OBJECT (row2), "appinfo"); + + return g_utf8_collate (g_app_info_get_name (app1), g_app_info_get_name (app2)); +} + +static void +list_header_app_func (GtkListBoxRow *row, GtkListBoxRow *before, gpointer user_data) +{ + + if (before != NULL && (gtk_list_box_row_get_header (row) == NULL)) + { + gtk_list_box_row_set_header (row, + gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)); + } +} + +static gboolean +list_filter_app_func (GtkListBoxRow *row, + gpointer user_data) +{ + MsmDesktopAppDialog *dialog = MSM_DESKTOP_APP_DIALOG (user_data); + GAppInfo *app; + GString *s1, *s2; + + app = g_object_get_data (G_OBJECT (row), "appinfo"); + + s1 = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->entry))); + s2 = g_string_new (g_app_info_get_name (app)); + + g_string_ascii_up (s1); + g_string_ascii_up (s2); + + if (strstr (s2->str, s1->str) != NULL) + return TRUE; + + return FALSE; +} + +static void +on_row_selected (GtkListBox *box, + GtkListBoxRow *row, + MsmDesktopAppDialog *dialog) +{ + if (row != NULL && gtk_widget_get_mapped (GTK_WIDGET (row))) + { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE); + } + else + { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE); + } +} + +static void +setup_dialog (MsmDesktopAppDialog *dialog) +{ + GtkStyleContext *context; + GtkWidget *content_area; + GtkWidget *searchbar; + GtkWidget *searchbutton; + GtkWidget *searchimage; + GtkWidget *headerbar; + GtkWidget *sw; + + content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + gtk_container_set_border_width (GTK_CONTAINER (content_area), 6); + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request (GTK_WIDGET (dialog), 600, 400); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + dialog->entry = gtk_search_entry_new (); + g_signal_connect (dialog->entry, + "search-changed", + G_CALLBACK (on_search_entry_changed), + dialog); + + gtk_entry_set_placeholder_text (GTK_ENTRY (dialog->entry), _("Search Applications…")); + gtk_entry_set_width_chars (GTK_ENTRY (dialog->entry), 30); + gtk_entry_set_activates_default (GTK_ENTRY (dialog->entry), TRUE); + gtk_entry_set_input_hints (GTK_ENTRY (dialog->entry), GTK_INPUT_HINT_NO_EMOJI); + + searchbar = gtk_search_bar_new (); + gtk_container_add (GTK_CONTAINER (searchbar), dialog->entry); + gtk_widget_set_hexpand (searchbar, TRUE); + gtk_box_pack_start (GTK_BOX (content_area), searchbar, FALSE, FALSE, 0); + + dialog->listbox = gtk_list_box_new (); + gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (dialog->listbox), FALSE); + gtk_list_box_set_sort_func (GTK_LIST_BOX (dialog->listbox), list_sort_app_func, dialog, NULL); + gtk_list_box_set_header_func (GTK_LIST_BOX (dialog->listbox), list_header_app_func, dialog, NULL); + gtk_list_box_set_filter_func (GTK_LIST_BOX (dialog->listbox), list_filter_app_func, dialog, NULL); + g_signal_connect (dialog->listbox, + "row-selected", + G_CALLBACK (on_row_selected), + dialog); + + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Close"), GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Add"), GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE); + + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (sw), dialog->listbox); + gtk_box_pack_start (GTK_BOX (content_area), sw, TRUE, TRUE, 0); + + searchbutton = gtk_toggle_button_new (); + gtk_widget_set_valign (searchbutton, GTK_ALIGN_CENTER); + searchimage = gtk_image_new_from_icon_name ("edit-find", GTK_ICON_SIZE_MENU); + gtk_container_add (GTK_CONTAINER (searchbutton), searchimage); + + context = gtk_widget_get_style_context (searchbutton); + gtk_style_context_add_class (context, "image-button"); + gtk_style_context_remove_class (context, "text-button"); + + headerbar = gtk_dialog_get_header_bar (GTK_DIALOG (dialog)); + gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), searchbutton); + g_object_bind_property (searchbutton, "active", searchbar, "search-mode-enabled", G_BINDING_BIDIRECTIONAL); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbutton), TRUE); +} + +static GObject * +msm_desktop_app_dialog_constructor (GType type, + guint n_construct_app, + GObjectConstructParam *construct_app) +{ + MsmDesktopAppDialog *dialog; + + dialog = MSM_DESKTOP_APP_DIALOG (G_OBJECT_CLASS (msm_desktop_app_dialog_parent_class)->constructor (type, + n_construct_app, + construct_app)); + + setup_dialog (dialog); + + return G_OBJECT (dialog); +} + +static void +msm_desktop_app_dialog_dispose (GObject *object) +{ + g_return_if_fail (object != NULL); + g_return_if_fail (MSM_IS_DESKTOP_APP_DIALOG (object)); + + G_OBJECT_CLASS (msm_desktop_app_dialog_parent_class)->dispose (object); +} + +static void +msm_desktop_app_dialog_class_init (MsmDesktopAppDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructor = msm_desktop_app_dialog_constructor; + object_class->dispose = msm_desktop_app_dialog_dispose; +} + +static void +msm_desktop_app_dialog_init (MsmDesktopAppDialog *dialog) +{ + +} + +static GtkWidget * +create_app_info_row (GAppInfo *app) +{ + GtkWidget *row; + GtkWidget *grid; + GtkWidget *image = NULL; + GtkWidget *label, *label2; + gint height; + const char *app_name; + const char *app_summary; + GIcon *app_icon; + + row = gtk_list_box_row_new (); + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + gtk_grid_set_row_spacing (GTK_GRID (grid), 6); + + app_name = g_app_info_get_name (app); + app_icon = g_app_info_get_icon (app); + app_summary = g_app_info_get_description (app); + + if (app_name == NULL) + return NULL; + + if (app_icon != NULL) + { + image = gtk_image_new_from_gicon (app_icon, GTK_ICON_SIZE_DIALOG); + gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, NULL, &height); + gtk_image_set_pixel_size (GTK_IMAGE (image), height); + gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 2, 2); + gtk_widget_set_hexpand (image, FALSE); + } + + label = gtk_label_new (app_name); + gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); + gtk_label_set_max_width_chars (GTK_LABEL (label), 50); + gtk_widget_set_hexpand (label, TRUE); + gtk_widget_set_halign (label, GTK_ALIGN_START); + gtk_widget_set_vexpand (label, FALSE); + gtk_widget_set_valign (label, GTK_ALIGN_CENTER); + gtk_grid_attach_next_to (GTK_GRID (grid), label, image, GTK_POS_RIGHT, 1, 1); + + label2 = gtk_label_new (app_summary); + gtk_label_set_ellipsize (GTK_LABEL (label2), PANGO_ELLIPSIZE_END); + gtk_label_set_max_width_chars (GTK_LABEL (label2), 50); + gtk_widget_set_hexpand (label2, TRUE); + gtk_widget_set_halign (label2, GTK_ALIGN_START); + gtk_widget_set_vexpand (label2, FALSE); + gtk_widget_set_valign (label2, GTK_ALIGN_CENTER); + gtk_grid_attach_next_to (GTK_GRID (grid), label2, label, GTK_POS_BOTTOM, 1, 1); + + gtk_container_add (GTK_CONTAINER (row), grid); + g_object_set_data (G_OBJECT (row), "appinfo", app); + + return row; +} + +GtkWidget * +msm_desktop_app_dialog_new (GspAppManager *manager) +{ + MsmDesktopAppDialog *dialog; + gboolean use_header; + GList *apps, *l; + + g_object_get (gtk_settings_get_default (), + "gtk-dialogs-use-header", &use_header, + NULL); + + dialog = g_object_new (MSM_TYPE_DESKTOP_APP_DIALOG, + "use-header-bar", use_header, + NULL); + + apps = g_app_info_get_all (); + for (l = apps; l != NULL; l = l->next) + { + GAppInfo *info = l->data; + GtkWidget *row; + const char *id; + + id = g_app_info_get_id (info); + if (id != NULL && gsp_app_manager_find_app_with_basename (manager, id) == NULL) + { + if (g_app_info_should_show (info)) + { + row = create_app_info_row (info); + if (row != NULL) + { + gtk_list_box_prepend (GTK_LIST_BOX (dialog->listbox), row); + } + } + } + } + + return GTK_WIDGET (dialog); +} + +const char * +msm_dektop_app_dialog_get_selected (MsmDesktopAppDialog *dialog) +{ + GtkListBoxRow *selected = NULL; + GAppInfo *app; + + selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (dialog->listbox)); + if (selected != NULL) + { + app = g_object_get_data (G_OBJECT (selected), "appinfo"); + return g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (app)); + } + + return NULL; +} diff --git a/capplet/msm-desktop-app-dialog.h b/capplet/msm-desktop-app-dialog.h new file mode 100644 index 0000000..ac7cf25 --- /dev/null +++ b/capplet/msm-desktop-app-dialog.h @@ -0,0 +1,20 @@ +#ifndef __MSM_DESKTOP_APP_DIALOG_H +#define __MSM_DESKTOP_APP_DIALOG_H + +#include <glib-object.h> +#include <gtk/gtk.h> +#include <gio/gdesktopappinfo.h> +#include "gsp-app-manager.h" + +G_BEGIN_DECLS + +#define MSM_TYPE_DESKTOP_APP_DIALOG (msm_desktop_app_dialog_get_type ()) +G_DECLARE_FINAL_TYPE (MsmDesktopAppDialog, msm_desktop_app_dialog, MSM, DESKTOP_APP_DIALOG, GtkDialog) + +GtkWidget *msm_desktop_app_dialog_new (GspAppManager *manager); + +const char *msm_dektop_app_dialog_get_selected (MsmDesktopAppDialog *dialog); + +G_END_DECLS + +#endif /* __GSM_APP_DIALOG_H */ |