[Xfce4-commits] [xfce/xfce4-session] 07/08: Add a "delete session" button to the session list
noreply at xfce.org
noreply at xfce.org
Mon May 13 22:10:46 CEST 2019
This is an automated email from the git hooks/post-receive script.
o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/xfce4-session.
commit 7404fedb1c98b3e0d6a9959bf4ac9f9a859c1e2d
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Mon May 13 00:00:53 2019 +0200
Add a "delete session" button to the session list
---
libxfsm/xfsm-util.c | 47 ++++++++++++++++++++++++++++++++++++++
libxfsm/xfsm-util.h | 40 +++++++++++++++++---------------
settings/main.c | 6 +++++
settings/xfce4-session-settings.ui | 19 +++++++++++++++
xfce4-session/xfsm-chooser.c | 44 +++--------------------------------
5 files changed, 97 insertions(+), 59 deletions(-)
diff --git a/libxfsm/xfsm-util.c b/libxfsm/xfsm-util.c
index c418920..691753b 100644
--- a/libxfsm/xfsm-util.c
+++ b/libxfsm/xfsm-util.c
@@ -382,3 +382,50 @@ settings_list_sessions_populate (GtkTreeModel *model,
g_free (title);
}
}
+
+void
+settings_list_sessions_delete_session (GtkButton *button,
+ GtkTreeView *treeview)
+{
+ XfceRc *rc;
+ gchar *session_file;
+ gchar *display_name;
+ gchar *resource_name;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+ GValue value;
+ gchar *session;
+
+ display_name = xfsm_gdk_display_get_fullname (gdk_display_get_default ());
+ resource_name = g_strconcat ("sessions/xfce4-session-", display_name, NULL);
+ session_file = xfce_resource_save_location (XFCE_RESOURCE_CACHE, resource_name, TRUE);
+
+ if (!g_file_test (session_file, G_FILE_TEST_IS_REGULAR))
+ {
+ g_warning ("xfsm_manager_load_session: Something wrong with %s, Does it exist? Permissions issue?", session_file);
+ return;
+ }
+
+ /* Remove the session from session file */
+ bzero (&value, sizeof (value));
+ selection = gtk_tree_view_get_selection (treeview);
+ if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+ {
+ g_warning ("xfsm_chooser_get_session: !gtk_tree_selection_get_selected");
+ return;
+ }
+ gtk_tree_model_get_value (model, &iter, NAME_COLUMN, &value);
+ session = g_strdup_printf ("Session: %s", g_value_get_string (&value));
+ g_value_unset (&value);
+ rc = xfce_rc_simple_open (session_file, FALSE);
+ xfce_rc_delete_group (rc, session, FALSE);
+ xfce_rc_close (rc);
+ g_free (session);
+
+ /* Remove the session from the treeview */
+ model = gtk_tree_view_get_model (treeview);
+ selection = gtk_tree_view_get_selection (treeview);
+ gtk_tree_selection_get_selected (selection, &model, &iter);
+ gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
diff --git a/libxfsm/xfsm-util.h b/libxfsm/xfsm-util.h
index 86d7668..0d3eb03 100644
--- a/libxfsm/xfsm-util.h
+++ b/libxfsm/xfsm-util.h
@@ -53,34 +53,38 @@ enum
};
-gboolean xfsm_start_application (gchar **command,
- gchar **environment,
- GdkScreen *screen,
- const gchar *current_directory,
- const gchar *client_machine,
- const gchar *user_id);
+gboolean xfsm_start_application (gchar **command,
+ gchar **environment,
+ GdkScreen *screen,
+ const gchar *current_directory,
+ const gchar *client_machine,
+ const gchar *user_id);
-void xfsm_place_trash_window (GtkWindow *window,
- GdkScreen *screen,
- gint monitor);
+void xfsm_place_trash_window (GtkWindow *window,
+ GdkScreen *screen,
+ gint monitor);
/* XXX - move to libxfce4util? */
-gboolean xfsm_strv_equal (gchar **a, gchar **b);
+gboolean xfsm_strv_equal (gchar **a,
+ gchar **b);
-XfconfChannel *xfsm_open_config (void);
+XfconfChannel *xfsm_open_config (void);
-gchar *xfsm_gdk_display_get_fullname (GdkDisplay *display);
+gchar *xfsm_gdk_display_get_fullname (GdkDisplay *display);
-GdkPixbuf *xfsm_load_session_preview (const gchar *name);
+GdkPixbuf *xfsm_load_session_preview (const gchar *name);
-XfceRc *settings_list_sessions_open_rc (void);
+XfceRc *settings_list_sessions_open_rc (void);
-GList *settings_list_sessions (XfceRc *rc);
+GList *settings_list_sessions (XfceRc *rc);
-void settings_list_sessions_treeview_init (GtkTreeView *treeview);
+void settings_list_sessions_treeview_init (GtkTreeView *treeview);
-void settings_list_sessions_populate (GtkTreeModel *model,
- GList *sessions);
+void settings_list_sessions_populate (GtkTreeModel *model,
+ GList *sessions);
+
+void settings_list_sessions_delete_session (GtkButton *button,
+ GtkTreeView *treeview);
G_END_DECLS;
diff --git a/settings/main.c b/settings/main.c
index 61879f5..7a0459a 100644
--- a/settings/main.c
+++ b/settings/main.c
@@ -80,6 +80,8 @@ main(int argc,
GtkWidget *xfae_page;
GtkWidget *lbl;
GtkWidget *label_active_session;
+ GObject *delete_button;
+ GObject *treeview;
GError *error = NULL;
XfconfChannel *channel;
XfceRc *rc;
@@ -172,6 +174,10 @@ main(int argc,
gtk_label_set_markup (GTK_LABEL (label_active_session), markup);
g_free (markup);
+ delete_button = gtk_builder_get_object (builder, "btn_delete_session");
+ treeview = gtk_builder_get_object (builder, "saved-sessions-list");
+ g_signal_connect (delete_button, "clicked", G_CALLBACK (settings_list_sessions_delete_session), GTK_TREE_VIEW (treeview));
+
/* Check if there are saved sessions and if so, show the "Saved Sessions" tab */
rc = settings_list_sessions_open_rc ();
if (rc)
diff --git a/settings/xfce4-session-settings.ui b/settings/xfce4-session-settings.ui
index 31be44b..f84930c 100644
--- a/settings/xfce4-session-settings.ui
+++ b/settings/xfce4-session-settings.ui
@@ -18,6 +18,11 @@
<property name="can_focus">False</property>
<property name="icon_name">window-close-symbolic</property>
</object>
+ <object class="GtkImage" id="image4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">list-remove-symbolic</property>
+ </object>
<object class="XfceTitledDialog" id="xfce4_session_settings_dialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Session and Startup</property>
@@ -459,6 +464,20 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
+ <object class="GtkButton" id="btn_delete_session">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Delete the selected session</property>
+ <property name="image">image4</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkButton" id="btn_clear_sessions">
<property name="label" translatable="yes">Clear Save_d Sessions</property>
<property name="visible">True</property>
diff --git a/xfce4-session/xfsm-chooser.c b/xfce4-session/xfsm-chooser.c
index 636a957..e1e1fdf 100644
--- a/xfce4-session/xfsm-chooser.c
+++ b/xfce4-session/xfsm-chooser.c
@@ -94,44 +94,6 @@ xfsm_chooser_start_session (GtkButton *button,
}
-static void
-xfsm_chooser_delete_session (GtkButton *button,
- XfsmChooser *chooser)
-{
- XfceRc *rc;
- gchar *session_file;
- gchar *display_name;
- gchar *resource_name;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
- gchar *session;
-
- display_name = xfsm_gdk_display_get_fullname (gdk_display_get_default ());
- resource_name = g_strconcat ("sessions/xfce4-session-", display_name, NULL);
- session_file = xfce_resource_save_location (XFCE_RESOURCE_CACHE, resource_name, TRUE);
-
- if (!g_file_test (session_file, G_FILE_TEST_IS_REGULAR))
- {
- g_warning ("xfsm_manager_load_session: Something wrong with %s, Does it exist? Permissions issue?", session_file);
- return;
- }
-
- /* Remove the session from the treeview */
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (chooser->tree));
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chooser->tree));
- gtk_tree_selection_get_selected (selection, &model, &iter);
- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-
- /* Remove the session from session file */
- session = g_strdup_printf ("Session: %s", xfsm_chooser_get_session (chooser));
- rc = xfce_rc_simple_open (session_file, FALSE);
- xfce_rc_delete_group (rc, session, FALSE);
- xfce_rc_close (rc);
- g_free (session);
-}
-
-
gchar*
xfsm_chooser_get_session (const XfsmChooser *chooser)
{
@@ -218,17 +180,17 @@ xfsm_chooser_init (XfsmChooser *chooser)
gtk_style_context_add_class (gtk_widget_get_style_context (hbox), "inline-toolbar");
/* "New" button */
- button = gtk_button_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_BUTTON);//xfce_gtk_button_new_mixed ("document-new", _("Create New Session"));
+ button = gtk_button_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_widget_set_tooltip_text (button, _("Create a new session."));
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (xfsm_chooser_new_session), chooser);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
/* "Delete" button */
- button = gtk_button_new_from_icon_name ("list-remove-symbolic", GTK_ICON_SIZE_BUTTON); //xfce_gtk_button_new_mixed ("document-new", _("Delete Session"));
+ button = gtk_button_new_from_icon_name ("list-remove-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_widget_set_tooltip_text (button, _("Delete a saved session."));
g_signal_connect (G_OBJECT (button), "clicked",
- G_CALLBACK (xfsm_chooser_delete_session), chooser);
+ G_CALLBACK (settings_list_sessions_delete_session), GTK_TREE_VIEW (chooser->tree));
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
/* Button box */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list