[Xfce4-commits] <xfce4-session:master> Add a way to delete sessions (Bug #5730)

Jérôme Guelfucci noreply at xfce.org
Tue Apr 5 07:48:01 CEST 2011


Updating branch refs/heads/master
         to a72907b0d2ad473042e029e91637ddffca2ff78a (commit)
       from 34edc29ec92a8e355f35cb0738bf21b15fd034e5 (commit)

commit a72907b0d2ad473042e029e91637ddffca2ff78a
Author: Lionel Le Folgoc <lionel at lefolgoc.net>
Date:   Thu Mar 31 12:34:07 2011 +0200

    Add a way to delete sessions (Bug #5730)
    
    This adds a "Clear saved sessions" button in xfce4-session-settings
    ("Session" tab), which lets the user delete Xfce-related cache items
    from $XDG_CACHE_HOME/sessions/.

 settings/session-editor.c             |   57 ++++++++++++++++++++++++++++++++-
 settings/xfce4-session-settings.glade |   40 +++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletions(-)

diff --git a/settings/session-editor.c b/settings/session-editor.c
index 1e7d23a..6ce3749 100644
--- a/settings/session-editor.c
+++ b/settings/session-editor.c
@@ -160,6 +160,57 @@ session_editor_sel_changed_btn(GtkTreeSelection *sel,
 }
 
 static void
+session_editor_clear_sessions(GtkWidget *btn,
+                              GtkWidget *treeview)
+{
+    gtk_widget_set_sensitive(btn, FALSE);
+
+    if(xfce_message_dialog(GTK_WINDOW(gtk_widget_get_toplevel(treeview)),
+                           _("Clear sessions"), GTK_STOCK_DIALOG_QUESTION,
+                           _("Are you sure you want to empty the session cache?"),
+                           _("The saved states of your applications will not be restored during your next login."),
+                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                           XFCE_BUTTON_TYPE_MIXED, GTK_STOCK_DELETE, _("_Proceed"), GTK_RESPONSE_ACCEPT,
+                           NULL) == GTK_RESPONSE_ACCEPT)
+    {
+        const gchar *item_name;
+        gchar       *cache_dir_path, *item_path;
+        GDir        *cache_dir;
+        GError      *error = NULL;
+
+        cache_dir_path = g_build_path(G_DIR_SEPARATOR_S, g_get_user_cache_dir(), "sessions", NULL);
+        cache_dir = g_dir_open(cache_dir_path, 0, &error);
+        if(!cache_dir) {
+            g_critical("Failed to open the session cache's directory: %s", error->message);
+            g_error_free(error);
+            g_free(cache_dir_path);
+            gtk_widget_set_sensitive(btn, TRUE);
+            return;
+        }
+
+        while((item_name = g_dir_read_name(cache_dir))) {
+            /* only clean Xfce related items */
+            if(!g_str_has_prefix(item_name, "xfce4-session-") &&
+               !g_str_has_prefix(item_name, "Thunar-") &&
+               !g_str_has_prefix(item_name, "xfwm4-")) {
+                continue;
+            }
+
+            item_path = g_build_filename(cache_dir_path, item_name, NULL);
+            if(G_UNLIKELY(g_unlink(item_path) == -1)) {
+                g_warning("Failed to delete \"%s\" from the session cache.", item_path);
+            }
+            g_free(item_path);
+        }
+        g_dir_close(cache_dir);
+        g_free(cache_dir_path);
+    }
+    else {
+        gtk_widget_set_sensitive(btn, TRUE);
+    }
+}
+
+static void
 session_editor_quit_client(GtkWidget *btn,
                            GtkWidget *treeview)
 {
@@ -699,7 +750,7 @@ session_editor_populate_treeview(GtkTreeView *treeview)
 void
 session_editor_init(GtkBuilder *builder)
 {
-    GObject *btn_save, *btn_quit, *dlg_saving;
+    GObject *btn_save, *btn_clear, *btn_quit, *dlg_saving;
     GtkTreeView *treeview;
     GtkTreeSelection *sel;
 
@@ -725,6 +776,10 @@ session_editor_init(GtkBuilder *builder)
     g_signal_connect(btn_save, "clicked",
                      G_CALLBACK(session_editor_save_session), GTK_WIDGET(dlg_saving));
 
+    btn_clear = gtk_builder_get_object(builder, "btn_clear_sessions");
+    g_signal_connect(btn_clear, "clicked",
+                     G_CALLBACK(session_editor_clear_sessions), treeview);
+
     btn_quit = gtk_builder_get_object(builder, "btn_quit_client");
     g_signal_connect(btn_quit, "clicked",
                      G_CALLBACK(session_editor_quit_client), treeview);
diff --git a/settings/xfce4-session-settings.glade b/settings/xfce4-session-settings.glade
index c815bc5..367022f 100644
--- a/settings/xfce4-session-settings.glade
+++ b/settings/xfce4-session-settings.glade
@@ -527,6 +527,46 @@
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkButton" id="btn_clear_sessions">
+                        <property name="visible">True</property>
+                        <property name="sensitive">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="tooltip_text" translatable="yes">Empty the session cache</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox9">
+                            <property name="visible">True</property>
+                            <property name="spacing">4</property>
+                            <child>
+                              <object class="GtkImage" id="image7">
+                                <property name="visible">True</property>
+                                <property name="xalign">1</property>
+                                <property name="stock">gtk-clear</property>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label24">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">_Clear saved sessions</property>
+                                <property name="use_underline">True</property>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkButton" id="btn_quit_client">
                         <property name="visible">True</property>
                         <property name="sensitive">False</property>



More information about the Xfce4-commits mailing list