Add simple config UI.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Tue, 10 Oct 2006 10:01:35 +0000 (10:01 +0000)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Tue, 10 Oct 2006 10:01:35 +0000 (10:01 +0000)
12 files changed:
src/configurator.c
src/misc.c
src/plugins/cpu/cpu.c
src/plugins/dclock.c
src/plugins/deskno.c
src/plugins/deskno2.c
src/plugins/netstatus/netstatus.c
src/plugins/pager.c
src/plugins/space.c
src/plugins/taskbar.c
src/plugins/volume/volume.c
src/systray/tray.c

index 579f8b5..c59b54b 100644 (file)
@@ -453,12 +453,35 @@ dialog_delete_event( GtkWidget *widget, GdkEvent  *event, gpointer   data )
 }
 
 static void
-on_sel_plugin_changed( GtkTreeSelection* tree_sel, gpointer user_data )
+on_sel_plugin_changed( GtkTreeSelection* tree_sel, GtkWidget* bin )
 {
+    GtkTreeIter it;
+    GtkTreeModel* model;
+    plugin* pl;
 
+    if( gtk_tree_selection_get_selected( tree_sel, &model, &it ) )
+    {
+        GtkWidget *label = NULL, *config = NULL;
+        gtk_tree_model_get( model, &it, 1, &pl, -1 );
+        label = (GtkLabel*)g_object_get_data( bin, "desc" );
+        gtk_label_set_text( label, _(pl->class->description) );
+        config = gtk_bin_get_child( bin );
+        if( config )
+            gtk_widget_destroy( config );
+
+        if( pl->class->config )
+            config = pl->class->config( pl );
+        else
+            config = NULL;
+        if( ! config )
+            config = gtk_label_new( _("Configuration page of this plugin is not available") );
+
+        gtk_container_add( GTK_CONTAINER(bin), config );
+        gtk_widget_show( config );
+    }
 }
 
-static void init_plugin_list( GtkTreeView* view )
+static void init_plugin_list( GtkTreeView* view, GtkWidget* bin )
 {
     /* extern panel *p; */
     GtkListStore* list;
@@ -466,6 +489,7 @@ static void init_plugin_list( GtkTreeView* view )
     GtkCellRenderer* render;
     GtkTreeSelection* tree_sel;
     GList* l;
+    GtkTreeIter it;
 
     render = gtk_cell_renderer_text_new();
     col = gtk_tree_view_column_new_with_attributes(
@@ -487,7 +511,9 @@ static void init_plugin_list( GtkTreeView* view )
 
     tree_sel = gtk_tree_view_get_selection( view );
     g_signal_connect( tree_sel, "changed",
-                      G_CALLBACK(on_sel_plugin_changed), NULL);
+                      G_CALLBACK(on_sel_plugin_changed), bin);
+    if( gtk_tree_model_get_iter_first( GTK_TREE_MODEL(list), &it ) )
+        gtk_tree_selection_select_iter( tree_sel, &it );
 }
 
 static void on_add_plugin( GtkButton* btn, GtkTreeView* view )
@@ -497,7 +523,26 @@ static void on_add_plugin( GtkButton* btn, GtkTreeView* view )
 
 static void on_remove_plugin(  GtkButton* btn, GtkTreeView* view )
 {
+    GtkTreeIter it;
+    GtkTreePath* tree_path;
+    GtkTreeModel* model;
+    GtkTreeSelection* tree_sel = gtk_tree_view_get_selection( view );
+    plugin* pl;
 
+    if( gtk_tree_selection_get_selected( tree_sel, &model, &it ) )
+    {
+        tree_path = gtk_tree_model_get_path( model, &it );
+        gtk_tree_model_get( model, &it, 1, &pl, -1 );
+        if( gtk_tree_path_get_indices(tree_path)[0] >= gtk_tree_model_iter_n_children( model, NULL ) )
+            gtk_tree_path_prev( tree_path );
+        gtk_list_store_remove( GTK_LIST_STORE(model), &it );
+        p->plugins = g_list_remove( p->plugins, pl );
+        plugin_stop( pl ); /* free the plugin widget & its data */
+        plugin_put( pl ); /* free th lib if necessary */
+
+        gtk_tree_selection_select_path( tree_sel, tree_path );
+        gtk_tree_path_free( tree_path );
+    }
 }
 
 static int get_widget_index( plugin* pl )
@@ -593,12 +638,13 @@ static void on_movedown_plugin(  GtkButton* btn, GtkTreeView* view )
 static GtkWidget *
 mk_tab_plugins()
 {
-    GtkWidget *sw, *paned, *hbox, *vbox, *rvbox, *label;
+    GtkWidget *sw, *paned, *hbox, *vbox, *rvbox, *label, *bin;
     GtkWidget *scroll, *plugin_list, *button, *image;
 
-    paned = gtk_hpaned_new();
+    paned = gtk_hbox_new( FALSE, 2 ); // gtk_hpaned_new();
     vbox = gtk_vbox_new( FALSE, 2 );
-    gtk_paned_pack1(GTK_PANED(paned), vbox, TRUE, FALSE);
+    //gtk_paned_pack1(GTK_PANED(paned), vbox, TRUE, FALSE);
+    gtk_box_pack_start(paned, vbox, FALSE, FALSE, 2);
 
     /* Left pane */
     plugin_list = gtk_tree_view_new();
@@ -608,8 +654,6 @@ mk_tab_plugins()
     gtk_container_add( GTK_CONTAINER(scroll), plugin_list );
     gtk_box_pack_start( GTK_BOX( vbox ), scroll, TRUE, TRUE, 4 );
 
-    init_plugin_list( GTK_TREE_VIEW( plugin_list ) );
-
     /* buttons used to edit plugin list */
     hbox = gtk_hbox_new( FALSE, 2 );
     gtk_box_pack_start( GTK_BOX( vbox ), hbox, FALSE, FALSE, 4 );
@@ -633,12 +677,18 @@ mk_tab_plugins()
 
     /* Right pane */
     vbox = gtk_vbox_new( FALSE, 2 );
-    gtk_paned_add2(GTK_PANED(paned), vbox);
+    // gtk_paned_pack2(GTK_PANED(paned), vbox, TRUE, FALSE);
+    gtk_box_pack_start(paned, vbox, TRUE, TRUE, 2);
 
     /* Label displaying plugin descriptions */
     label = gtk_label_new("");
     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-    gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 4);
+    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 4);
+
+    bin = gtk_frame_new("");
+    gtk_box_pack_start(GTK_BOX(vbox), bin, TRUE, TRUE, 4);
+    g_object_set_data( bin, "desc", label );
+    init_plugin_list( GTK_TREE_VIEW( plugin_list ), bin );
 
     RET(paned);
 }
index dbc4b3d..6391836 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdarg.h>
 
 #include "misc.h"
 #include "panel.h"
@@ -1043,3 +1044,53 @@ char* translate_exec_to_cmd( const char* exec, const char* icon,
     return g_string_free( cmd, FALSE );
 }
 
+/* Parameters: const char* name, gpointer ret_value, GType type, ....NULL */
+GtkWidget* create_generic_config_page( const char* name, ... )
+{
+    va_list args;
+    GtkWidget* config = gtk_vbox_new( FALSE, 4 );
+    va_start( args, name );
+    while( name )
+    {
+        GtkWidget* label = gtk_label_new( name );
+        GtkWidget* entry = NULL;
+        gpointer val = va_arg( args, gpointer );
+        GType type = va_arg( args, GType );
+        switch( type )
+        {
+            case G_TYPE_STRING:
+                entry = gtk_entry_new();
+                gtk_entry_set_text( entry, *(char**)val );
+                break;
+            case G_TYPE_INT:
+            {
+                /* FIXME: the range shouldn't be hardcoded */
+                entry = gtk_spin_button_new_with_range( 0, 100, 1 );
+                gtk_spin_button_set_value( entry, *(int*)val );
+                break;
+            }
+            case G_TYPE_BOOLEAN:
+                entry = gtk_check_button_new();
+                gtk_container_add( entry, label );
+                gtk_toggle_button_set_active( entry, *(gboolean*)val );
+                break;
+        }
+        if( entry )
+        {
+            if( type == G_TYPE_BOOLEAN )
+                gtk_box_pack_start( config, entry, FALSE, FALSE, 2 );
+            else
+            {
+                GtkWidget* hbox = gtk_hbox_new( FALSE, 2 );
+                gtk_box_pack_start( hbox, label, FALSE, FALSE, 2 );
+                gtk_box_pack_start( hbox, entry, TRUE, TRUE, 2 );
+                gtk_box_pack_start( config, hbox, FALSE, FALSE, 2 );
+            }
+        }
+        name = va_arg( args, const char* );
+    }
+    va_end( args );
+    gtk_widget_show_all( config );
+    return config;
+}
+
index d5bf5d8..a04fc9b 100644 (file)
@@ -31,7 +31,7 @@
 #include "plugin.h"
 #include "panel.h"
 #include "gtkbgbox.h"
-
+#include "misc.h"
 
 #define KILOBYTE 1024
 #define MAX_WGSIZE 100
@@ -211,4 +211,5 @@ plugin_class cpu_plugin_class = {
 
     constructor : cpu_constructor,
     destructor  : cpu_destructor,
+    config : NULL
 };
index ebc9d43..1d57df5 100644 (file)
@@ -83,14 +83,12 @@ dclock_constructor(plugin *p)
     line s;
     dclock *dc;
     char output [40] ;
-    time_t now ;
-    struct tm * detail ;
-    
+
     ENTER;
     dc = g_new0(dclock, 1);
     g_return_val_if_fail(dc != NULL, 0);
     p->priv = dc;
-    
+
     s.len = 256;
     dc->cfmt = dc->tfmt = dc->action = 0;
     while (get_line(p->fp, &s) != LINE_BLOCK_END) {
@@ -125,10 +123,7 @@ dclock_constructor(plugin *p)
     if (dc->action)
         g_signal_connect (G_OBJECT (dc->main), "button_press_event",
               G_CALLBACK (clicked), (gpointer) dc);
-    time(&now);
-    detail = localtime(&now);
-    strftime(output, sizeof(output), dc->cfmt, detail) ;
-    dc->clockw = gtk_label_new(output);
+    dc->clockw = gtk_label_new("");
     gtk_misc_set_alignment(GTK_MISC(dc->clockw), 0.5, 0.5);
     gtk_misc_set_padding(GTK_MISC(dc->clockw), 4, 0);
     //gtk_widget_show(dc->clockw);
@@ -137,6 +132,8 @@ dclock_constructor(plugin *p)
     dc->tip = gtk_tooltips_new();
     dc->timer = g_timeout_add(1000, (GSourceFunc) clock_update, (gpointer)dc);
     gtk_container_add(GTK_CONTAINER(p->pwid), dc->main);
+
+    clock_update( dc );
     RET(1);
 
  error:
@@ -165,6 +162,15 @@ dclock_destructor(plugin *p)
   RET();
 }
 
+static GtkWidget* dclock_config( plugin *p )
+{
+    dclock *dc = (dclock *)p->priv;
+    return create_generic_config_page( _("Clock Format"), &dc->cfmt, G_TYPE_STRING,
+                                       _("Tooltip Format"), &dc->tfmt, G_TYPE_STRING,
+                                       _("Action"), &dc->action, G_TYPE_STRING,
+                                       NULL );
+}
+
 plugin_class dclock_plugin_class = {
     fname: NULL,
     count: 0,
@@ -176,4 +182,5 @@ plugin_class dclock_plugin_class = {
 
     constructor : dclock_constructor,
     destructor  : dclock_destructor,
+    config : dclock_config
 };
index 52873e4..f1ebc09 100644 (file)
@@ -103,4 +103,5 @@ plugin_class deskno_plugin_class = {
 
     constructor : deskno_constructor,
     destructor  : deskno_destructor,
+    config : NULL
 };
index ce81e84..4c80d30 100644 (file)
@@ -133,4 +133,5 @@ plugin_class deskno2_plugin_class = {
 
     constructor : deskno_constructor,
     destructor  : deskno_destructor,
+    config : NULL
 };
index e2d9588..9c5ef29 100644 (file)
@@ -115,6 +115,14 @@ netstatus_constructor(plugin *p)
     RET(0);
 }
 
+static GtkWidget* netstatus_config( plugin* p )
+{
+    netstatus *ns = (netstatus*)p->priv;
+    return create_generic_config_page(
+                _("Interface to monitor"), &ns->iface, G_TYPE_STRING,
+                _("Config tool"), &ns->config_tool, G_TYPE_STRING,
+                NULL );
+}
 
 plugin_class netstatus_plugin_class = {
     fname: NULL,
@@ -127,4 +135,5 @@ plugin_class netstatus_plugin_class = {
 
     constructor : netstatus_constructor,
     destructor  : netstatus_destructor,
+    config : netstatus_config
 };
index 9825f4c..1464e5f 100644 (file)
@@ -701,4 +701,5 @@ plugin_class pager_plugin_class = {
 
     constructor : pager_constructor,
     destructor  : pager_destructor,
+    config : NULL
 };
index d4a55b2..d729e79 100644 (file)
@@ -85,6 +85,11 @@ space_constructor(plugin *p)
     RET(0);
 }
 
+static GtkWidget* space_config(plugin* p)
+{
+    space *sp = (space *)p->priv;
+    return create_generic_config_page( _("Size"), &sp->size, G_TYPE_INT,  NULL );
+}
 
 plugin_class space_plugin_class = {
     fname: NULL,
@@ -97,4 +102,5 @@ plugin_class space_plugin_class = {
 
     constructor : space_constructor,
     destructor  : space_destructor,
+    config : space_config
 };
index 91bf357..0dd549c 100644 (file)
@@ -86,14 +86,14 @@ typedef struct _taskbar{
     
     unsigned int iconsize;
     unsigned int task_width_max;
-    unsigned int accept_skip_pager : 1;
-    unsigned int show_iconified : 1;
-    unsigned int show_mapped : 1;
-    unsigned int show_all_desks : 1;
-    unsigned int tooltips : 1;
-    unsigned int icons_only : 1;
-    unsigned int use_mouse_wheel : 1;
-    unsigned int use_urgency_hint : 1;
+    unsigned int accept_skip_pager;// : 1;
+    unsigned int show_iconified;// : 1;
+    unsigned int show_mapped;// : 1;
+    unsigned int show_all_desks;// : 1;
+    unsigned int tooltips;// : 1;
+    unsigned int icons_only;// : 1;
+    unsigned int use_mouse_wheel;// : 1;
+    unsigned int use_urgency_hint;// : 1;
 } taskbar;
 
 
@@ -1400,6 +1400,24 @@ taskbar_destructor(plugin *p)
     RET();
 }
 
+static GtkWidget* taskbar_config( plugin* p )
+{
+    taskbar *tb = (taskbar *)p->priv;
+
+    return create_generic_config_page(
+            _("Show tooltips"), &tb->tooltips, G_TYPE_BOOLEAN,
+            _("Icons only"), &tb->icons_only, G_TYPE_BOOLEAN,
+            _("Accept SkipPager"), &tb->accept_skip_pager, G_TYPE_BOOLEAN,
+            _("Show Iconified windows"), &tb->show_iconified, G_TYPE_BOOLEAN,
+            _("Show mapped windows"), &tb->show_mapped, G_TYPE_BOOLEAN,
+            _("Show windows from all desktops"), &tb->show_all_desks, G_TYPE_BOOLEAN,
+            _("Use mouse wheel"), &tb->use_mouse_wheel, G_TYPE_BOOLEAN,
+            _("Flash when there is any window requiring attention"), &tb->use_urgency_hint, G_TYPE_BOOLEAN,
+            _("Max width of task button"), &tb->task_width_max, G_TYPE_INT,
+            _("Spacing"), &tb->spacing, G_TYPE_INT,
+                NULL );
+}
+
 plugin_class taskbar_plugin_class = {
     fname: NULL,
     count: 0,
@@ -1411,5 +1429,6 @@ plugin_class taskbar_plugin_class = {
     
     constructor : taskbar_constructor,
     destructor  : taskbar_destructor,
+    config : taskbar_config
 };
 
index 411783f..5bbc0c6 100644 (file)
@@ -128,4 +128,5 @@ plugin_class volume_plugin_class = {
 
        constructor : volume_constructor,
        destructor  : volume_destructor,
+    config : NULL
 };
index 109b2dd..0ae2cf5 100644 (file)
@@ -159,4 +159,5 @@ plugin_class tray_plugin_class = {
 
     constructor : tray_constructor,
     destructor  : tray_destructor,
+    config : NULL
 };