Author: kelnos
Date: 2008-09-14 10:20:06 +0000 (Sun, 14 Sep 2008)
New Revision: 27862

Modified:
   xfwm4/trunk/settings-dialogs/Makefile.am
   xfwm4/trunk/settings-dialogs/workspace-settings.c
   xfwm4/trunk/settings-dialogs/xfwm4-workspace-dialog.glade
Log:
implement workspace name changing

Modified: xfwm4/trunk/settings-dialogs/Makefile.am
===================================================================
--- xfwm4/trunk/settings-dialogs/Makefile.am    2008-09-14 10:19:53 UTC (rev 
27861)
+++ xfwm4/trunk/settings-dialogs/Makefile.am    2008-09-14 10:20:06 UTC (rev 
27862)
@@ -15,9 +15,11 @@
        $(LIBXFCE4UTIL_CFLAGS) \
        $(LIBXFCEGUI4_CFLAGS) \
        $(LIBXFCONF_CFLAGS) \
+       $(LIBWNCK_CFLAGS) \
        -DDATADIR=\"$(datadir)\" \
        -DSRCDIR=\"$(top_srcdir)\" \
-       -DLOCALEDIR=\"$(localedir)\"
+       -DLOCALEDIR=\"$(localedir)\" \
+       -DWNCK_I_KNOW_THIS_IS_UNSTABLE
 
 xfwm4_workspace_settings_LDADD = \
        $(GTK_LIBS) \
@@ -26,7 +28,8 @@
        $(DBUS_GLIB_LIBS) \
        $(LIBXFCE4UTIL_LIBS) \
        $(LIBXFCEGUI4_LIBS) \
-       $(LIBXFCONF_LIBS)
+       $(LIBXFCONF_LIBS) \
+       $(LIBWNCK_LIBS)
 
 xfwm4_settings_SOURCES = \
        xfwm4-settings.c \

Modified: xfwm4/trunk/settings-dialogs/workspace-settings.c
===================================================================
--- xfwm4/trunk/settings-dialogs/workspace-settings.c   2008-09-14 10:19:53 UTC 
(rev 27861)
+++ xfwm4/trunk/settings-dialogs/workspace-settings.c   2008-09-14 10:20:06 UTC 
(rev 27862)
@@ -1,4 +1,5 @@
 /*
+ *  Copyright (c) 2008 Brian Tarricone <[EMAIL PROTECTED]>
  *  Copyright (c) 2008 Stephan Arts <[EMAIL PROTECTED]>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -21,32 +22,300 @@
 #include <string.h>
 
 #include <glib.h>
-
 #include <gtk/gtk.h>
 #include <glade/glade.h>
+#include <dbus/dbus-glib.h>
+#include <libwnck/libwnck.h>
 
 #include <libxfce4util/libxfce4util.h>
 #include <libxfcegui4/libxfcegui4.h>
 #include <xfconf/xfconf.h>
 #include "xfwm4-workspace-dialog_glade.h"
 
+#define WORKSPACES_CHANNEL         "xfwm4"
+
+#define WORKSPACE_NAMES_PROP       "/general/workspace_names"
+
 static gboolean version = FALSE;
 
+
+enum
+{
+    COL_NUMBER = 0,
+    COL_NAME,
+    N_COLS,
+};
+
+static void
+workspace_names_update_xfconf(gint workspace,
+                              const gchar *new_name)
+{
+    WnckScreen *screen = wnck_screen_get_default();
+    XfconfChannel *channel;
+    gchar **names;
+    gboolean do_update_xfconf = TRUE;
+
+    channel = xfconf_channel_new(WORKSPACES_CHANNEL);
+    names = xfconf_channel_get_string_list(channel, WORKSPACE_NAMES_PROP);
+
+    if(!names) {
+        /* the property doesn't exist; let's build one from scratch */
+        gint i, n_workspaces = wnck_screen_get_workspace_count(screen);
+
+        names = g_new(gchar *, n_workspaces + 1);
+        for(i = 0; i < n_workspaces; ++i) {
+            if(G_LIKELY(i != workspace))
+                names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
+            else
+                names[i] = g_strdup(new_name);
+        }
+        names[n_workspaces] = NULL;
+    } else {
+        gint i, prop_len = g_strv_length(names);
+        gint n_workspaces = wnck_screen_get_workspace_count(screen);
+
+        if(prop_len < n_workspaces) {
+            /* the property exists, but it's smaller than the current
+             * actual number of workspaces */
+            names = g_realloc(names, sizeof(gchar *) * (n_workspaces + 1));
+            for(i = prop_len; i < n_workspaces; ++i) {
+                if(i != workspace)
+                    names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
+                else
+                    names[i] = g_strdup(new_name);
+            }
+            names[n_workspaces] = NULL;
+        } else {
+            /* here we may have a |names| array longer than the actual
+             * number of workspaces, but that's fine.  the user might
+             * want to re-add a workspace or whatever, and may appreciate
+             * that we remember the old name. */
+            if(strcmp(names[workspace], new_name)) {
+                g_free(names[workspace]);
+                names[workspace] = g_strdup(new_name);
+            } else {
+                /* nothing's actually changed, so don't update the xfconf
+                 * property.  this saves us some trouble later. */
+                do_update_xfconf = FALSE;
+            }
+        }
+    }
+
+    if(do_update_xfconf)
+        xfconf_channel_set_string_list(channel, WORKSPACE_NAMES_PROP, names);
+
+    g_strfreev(names);
+    g_object_unref(G_OBJECT(channel));
+}
+
+static void
+treeview_ws_names_row_activated(GtkTreeView *treeview,
+                                GtkTreePath *path,
+                                GtkTreeViewColumn *column,
+                                gpointer user_data)
+{
+    GtkWidget *dialog = user_data, *entry;
+    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
+    GtkTreeIter iter;
+    gint ws_num = 1;
+    gchar *subtitle, *old_name = NULL;
+
+    if(!gtk_tree_model_get_iter(model, &iter, path))
+        return;
+
+    gtk_tree_model_get(model, &iter,
+                       COL_NUMBER, &ws_num,
+                       -1);
+
+    subtitle = g_strdup_printf(_("Change the name of workspace %d"), ws_num);
+    xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(dialog), subtitle);
+    g_free(subtitle);
+
+    entry = g_object_get_data(G_OBJECT(dialog), "name-entry");
+    gtk_tree_model_get(model, &iter,
+                       COL_NAME, &old_name,
+                       -1);
+    gtk_entry_set_text(GTK_ENTRY(entry), old_name);
+    gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
+
+    if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+        gchar *new_name;
+
+        new_name = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+        if(!*new_name) {
+            g_free(new_name);
+            new_name = g_strdup_printf(_("Workspace %d"), ws_num);
+        }
+
+        /* only update it if the name's actually different */
+        if(strcmp(old_name, new_name)) {
+            gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+                               COL_NAME, &new_name,
+                               -1);
+            workspace_names_update_xfconf(ws_num - 1, new_name);
+        }
+
+        g_free(new_name);
+    }
+
+    g_free(old_name);
+    gtk_widget_hide(dialog);
+}
+
+
+static void
+xfconf_workspace_names_changed(XfconfChannel *channel,
+                               const gchar *property,
+                               const GValue *value,
+                               gpointer user_data)
+{
+    GtkTreeView *treeview = user_data;
+    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
+    WnckScreen *screen = wnck_screen_get_default();
+    gint i, n_workspaces;
+    GPtrArray *names;
+    GtkTreePath *path;
+    GtkTreeIter iter;
+
+    if(G_VALUE_TYPE(value) !=  dbus_g_type_get_collection("GPtrArray",
+                                                          G_TYPE_VALUE))
+    {
+        g_warning("(workspace names) Expected boxed GPtrArray property, got 
%s",
+                  G_VALUE_TYPE_NAME(value));
+        return;
+    }
+
+    names = g_value_get_boxed(value);
+    if(!names)
+        return;
+
+    wnck_screen_force_update(screen);
+    n_workspaces = wnck_screen_get_workspace_count(screen);
+    for(i = 0; i < n_workspaces && i < names->len; ++i) {
+        GValue *val = g_ptr_array_index(names, i);
+        const gchar *new_name;
+
+        if(!G_VALUE_HOLDS_STRING(val)) {
+            g_warning("(workspace names) Expected string but got %s for item 
%d",
+                      G_VALUE_TYPE_NAME(val), i);
+            continue;
+        }
+
+        new_name = g_value_get_string(val);
+
+        path = gtk_tree_path_new_from_indices(i, -1);
+        if(gtk_tree_model_get_iter(model, &iter, path)) {
+            gchar *old_name = NULL;
+
+            gtk_tree_model_get(model, &iter,
+                               COL_NAME, &old_name,
+                               -1);
+            /* only update the names that have actually changed */
+            if(strcmp(old_name, new_name)) {
+                gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+                                   COL_NAME, new_name,
+                                   -1);
+            }
+            g_free(old_name);
+        } else {
+            /* must be a new workspace */
+            gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+            gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+                               COL_NUMBER, i + 1,
+                               COL_NAME, new_name,
+                               -1);
+        }
+
+        gtk_tree_path_free(path);
+    }
+
+    /* if workspaces got destroyed, we need to remove them from the treeview */
+    path = gtk_tree_path_new_from_indices(n_workspaces, -1);
+    while(gtk_tree_model_get_iter(model, &iter, path))
+        gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
+    gtk_tree_path_free(path);
+}
+
+static void
+workspace_dialog_setup_names_treeview(GladeXML *gxml,
+                                      XfconfChannel *channel)
+{
+    GtkWidget *treeview, *dialog;
+    GtkListStore *ls;
+    GtkCellRenderer *render;
+    GtkTreeViewColumn *col;
+    WnckScreen *screen;
+    gint n_workspaces, i;
+    GtkTreeIter iter;
+
+    dialog = glade_xml_get_widget(gxml, "change_name_dialog");
+    g_object_set_data(G_OBJECT(dialog), "name-entry",
+                      glade_xml_get_widget(gxml, "entry_name"));
+    g_signal_connect(G_OBJECT(dialog), "delete-event",
+                     G_CALLBACK(gtk_true), NULL);
+
+    treeview = glade_xml_get_widget(gxml, "treeview_ws_names");
+    g_signal_connect(G_OBJECT(treeview), "row-activated",
+                     G_CALLBACK(treeview_ws_names_row_activated), dialog);
+
+    ls = gtk_list_store_new(N_COLS, G_TYPE_INT, G_TYPE_STRING);
+
+    render = gtk_cell_renderer_text_new();
+    col = gtk_tree_view_column_new_with_attributes("", render,
+                                                   "text", COL_NUMBER,
+                                                   NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
+
+    render = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(render),
+                 "ellipsize", PANGO_ELLIPSIZE_END,
+                 "ellipsize-set", TRUE,
+                 NULL);
+    col = gtk_tree_view_column_new_with_attributes(_("Workspace Name"),
+                                                   render,
+                                                   "text", COL_NAME,
+                                                   NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
+
+    screen = wnck_screen_get_default();
+    wnck_screen_force_update(screen);
+
+    n_workspaces = wnck_screen_get_workspace_count(screen);
+    for(i = 0; i < n_workspaces; ++i) {
+        WnckWorkspace *space = wnck_screen_get_workspace(screen, i);
+        const char *name = wnck_workspace_get_name(space);
+
+        gtk_list_store_append(ls, &iter);
+        gtk_list_store_set(ls, &iter,
+                           COL_NUMBER, i + 1,
+                           COL_NAME, name,
+                           -1);
+    }
+
+    gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(ls));
+
+    g_signal_connect(G_OBJECT(channel),
+                     "property-changed::" WORKSPACE_NAMES_PROP,
+                     G_CALLBACK(xfconf_workspace_names_changed), treeview);
+}
+
 static GtkWidget *
-workspace_dialog_new_from_xml (GladeXML *gxml)
+workspace_dialog_new_from_xml (GladeXML *gxml,
+                               XfconfChannel *channel)
 {
     GtkWidget *dialog;
     GtkWidget *vbox;
-    XfconfChannel *xfwm4_channel = xfconf_channel_new("xfwm4");
 
     GtkWidget *workspace_count_spinbutton = glade_xml_get_widget (gxml, 
"workspace_count_spinbutton");
 
     /* Bind easy properties */
-    xfconf_g_property_bind (xfwm4_channel, 
+    xfconf_g_property_bind (channel, 
                             "/general/workspace_count",
                             G_TYPE_INT,
-                            (GObject *)workspace_count_spinbutton, "value"); 
+                            (GObject *)workspace_count_spinbutton, "value");
 
+    workspace_dialog_setup_names_treeview(gxml, channel);
+
     vbox = glade_xml_get_widget (gxml, "main-vbox");
     dialog = glade_xml_get_widget (gxml, "main-dialog");
 
@@ -71,6 +340,7 @@
 {
     GladeXML *gxml;
     GtkWidget *dialog;
+    XfconfChannel *channel;
     GError *cli_error = NULL;
 
     xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
@@ -101,10 +371,15 @@
                                       workspace_dialog_glade_length,
                                       NULL, NULL);
 
-    dialog = workspace_dialog_new_from_xml (gxml);
+    channel = xfconf_channel_new(WORKSPACES_CHANNEL);
 
-    gtk_dialog_run(GTK_DIALOG(dialog));
+    dialog = workspace_dialog_new_from_xml (gxml, channel);
 
+    while(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_HELP) {
+        /* FIXME: launch help */
+    }
+
+    g_object_unref(G_OBJECT(channel));
     xfconf_shutdown();
 
     return 0;

Modified: xfwm4/trunk/settings-dialogs/xfwm4-workspace-dialog.glade
===================================================================
--- xfwm4/trunk/settings-dialogs/xfwm4-workspace-dialog.glade   2008-09-14 
10:19:53 UTC (rev 27861)
+++ xfwm4/trunk/settings-dialogs/xfwm4-workspace-dialog.glade   2008-09-14 
10:20:06 UTC (rev 27862)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Sun Aug 24 22:43:54 2008 -->
+<!--Generated with glade3 3.4.5 on Fri Sep 12 00:31:15 2008 -->
 <glade-interface>
   <requires lib="xfce4"/>
   <widget class="XfceTitledDialog" id="main-dialog">
@@ -55,10 +55,20 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkTreeView" id="treeview1">
+              <widget class="GtkScrolledWindow" id="scrolledwindow1">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="headers_clickable">True</property>
+                <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+                <property 
name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
+                <child>
+                  <widget class="GtkTreeView" id="treeview_ws_names">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="headers_clickable">True</property>
+                    <property name="rules_hint">True</property>
+                  </widget>
+                </child>
               </widget>
               <packing>
                 <property name="position">1</property>
@@ -72,7 +82,6 @@
         <child internal-child="action_area">
           <widget class="GtkHButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>
-            <property name="layout_style">GTK_BUTTONBOX_EDGE</property>
             <child>
               <widget class="GtkButton" id="button2">
                 <property name="visible">True</property>
@@ -80,7 +89,7 @@
                 <property name="receives_default">True</property>
                 <property name="label" translatable="yes">gtk-help</property>
                 <property name="use_stock">True</property>
-                <property name="response_id">0</property>
+                <property name="response_id">-11</property>
               </widget>
             </child>
             <child>
@@ -105,4 +114,92 @@
       </widget>
     </child>
   </widget>
+  <widget class="XfceTitledDialog" id="change_name_dialog">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Change Workspace Name</property>
+    <property name="resizable">False</property>
+    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="icon_name">xfce4-workspaces</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="transient_for">main-dialog</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkHBox" id="hbox1">
+            <property name="visible">True</property>
+            <property name="border_width">6</property>
+            <property name="spacing">12</property>
+            <child>
+              <widget class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Name:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">entry_name</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkEntry" id="entry_name">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="activates_default">True</property>
+                <property name="width_chars">16</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <child>
+              <widget class="GtkButton" id="button3">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">-6</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkButton" id="button4">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-save</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">-3</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </glade-interface>

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to