[Goodies-commits] r3788 - in xfce4-places-plugin/trunk: . panel-plugin

Diego Ongaro ongardie at xfce.org
Tue Jan 8 06:07:52 CET 2008


Author: ongardie
Date: 2008-01-08 05:07:51 +0000 (Tue, 08 Jan 2008)
New Revision: 3788

Modified:
   xfce4-places-plugin/trunk/ChangeLog
   xfce4-places-plugin/trunk/configure.in.in
   xfce4-places-plugin/trunk/panel-plugin/Makefile.am
   xfce4-places-plugin/trunk/panel-plugin/cfg.c
   xfce4-places-plugin/trunk/panel-plugin/cfg.h
   xfce4-places-plugin/trunk/panel-plugin/view.c
   xfce4-places-plugin/trunk/panel-plugin/view.h
Log:
2008-01-07	Diego Ongaro <ongardie at gmail.com>

* button.{c,h}: Created a button widget to modularize view code
* cfg.{c,h}: Made the interface between the view and cfg saner
* view.{c,h}: Moved stuff out of this file (see above)
Sorry about the huge commit - I was playing with git :)



Modified: xfce4-places-plugin/trunk/ChangeLog
===================================================================
--- xfce4-places-plugin/trunk/ChangeLog	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/ChangeLog	2008-01-08 05:07:51 UTC (rev 3788)
@@ -1,3 +1,9 @@
+2008-01-07	Diego Ongaro <ongardie at gmail.com>
+
+	* button.{c,h}: Created a button widget to modularize view code
+	* cfg.{c,h}: Made the interface between the view and cfg saner
+	* view.{c,h}: Moved stuff out of this file (see above)
+
 2007-12-13	Diego Ongaro <ongardie at gmail.com>
 
 	* model.h, model_volumes.c, view.c: Provide visual feedback on

Modified: xfce4-places-plugin/trunk/configure.in.in
===================================================================
--- xfce4-places-plugin/trunk/configure.in.in	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/configure.in.in	2008-01-08 05:07:51 UTC (rev 3788)
@@ -4,7 +4,7 @@
 m4_define([places_version], [1.0.0])
 
 dnl initialize autoconf
-AC_COPYRIGHT([Copyright (c) 2007 Diego Ongaro <ongardie at gmail.com>])
+AC_COPYRIGHT([Copyright (c) 2007-2008 Diego Ongaro <ongardie at gmail.com>])
 AC_INIT([xfce4-places-plugin], [places_version], [ongardie at gmail.com])
 AC_PREREQ([2.50])
 

Modified: xfce4-places-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/Makefile.am	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/panel-plugin/Makefile.am	2008-01-08 05:07:51 UTC (rev 3788)
@@ -36,7 +36,9 @@
 	model_user.c							\
 	model_user.h							\
 	model_volumes.c							\
-	model_volumes.h
+	model_volumes.h							\
+	button.c							\
+	button.h
 
 
 

Modified: xfce4-places-plugin/trunk/panel-plugin/cfg.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/cfg.c	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/panel-plugin/cfg.c	2008-01-08 05:07:51 UTC (rev 3788)
@@ -2,7 +2,7 @@
  *
  *  This file provides a means of configuring the plugin.
  *
- *  Copyright (c) 2007 Diego Ongaro <ongardie at gmail.com>
+ *  Copyright (c) 2007-2008 Diego Ongaro <ongardie at gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -35,39 +35,8 @@
 #include "cfg.h"
 #include "view.h"
 
-/********** PlacesCfgViewIface helpers **********/
 
-inline PlacesCfg*
-places_cfg_view_iface_get_cfg(PlacesCfgViewIface *iface)
-{
-    return iface->cfg;
-}
 
-inline void
-places_cfg_view_iface_open_dialog(PlacesCfgViewIface *iface)
-{
-    iface->open_dialog(iface->cfg);
-}
-
-inline void
-places_cfg_view_iface_load(PlacesCfgViewIface *iface)
-{
-    iface->load(iface->cfg);
-}
-
-inline void
-places_cfg_view_iface_save(PlacesCfgViewIface *iface)
-{
-    iface->save(iface->cfg);
-}
-
-inline void
-places_cfg_view_iface_finalize(PlacesCfgViewIface *iface)
-{
-    iface->finalize(iface);
-}
-
-
 /********** Configuration File **********/
 
 static void
@@ -154,11 +123,11 @@
     xfce_rc_close(rcfile);
 }
 
-static void
-pcfg_save(PlacesCfg *cfg)
+void
+places_cfg_save(PlacesCfg *cfg)
 {
     XfceRc *rcfile;
-    
+
     g_assert(cfg != NULL);
 
     if(cfg->write_path == NULL)
@@ -201,7 +170,7 @@
 pcfg_button_show_cb(GtkComboBox *combo, PlacesCfg *cfg)
 {
     gint option = gtk_combo_box_get_active(combo);
-    
+
     g_assert(cfg != NULL);
     g_assert(option >= 0 && option <= 2);
 
@@ -227,7 +196,7 @@
 
         if(old_text != NULL)
             g_free(old_text);
-    
+
         places_view_cfg_iface_update_button(cfg->view_iface);
 
     }else{ /* we prefer the old/default text */
@@ -260,10 +229,10 @@
 
     if(old_text == NULL || strcmp(old_text, new_text)){
         cfg->search_cmd = new_text;
-        
+
         if(old_text != NULL)
             g_free(old_text);
-        
+
         places_view_cfg_iface_update_menu(cfg->view_iface);
 
     }else /* we prefer the old text */
@@ -312,7 +281,7 @@
     GtkWidget *transient;
 
     g_assert(cfg != NULL);
-    
+
     opt = g_object_get_data(G_OBJECT(toggle), "cfg_opt");
     g_assert(opt != NULL);
 
@@ -326,8 +295,36 @@
 }
 
 static void
-pcfg_open_dialog(PlacesCfg *cfg)
+pcfg_dialog_close_cb(GtkDialog *dialog, gint response, PlacesCfg *cfg)
 {
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+    xfce_panel_plugin_unblock_menu(cfg->plugin);
+}
+
+static GtkWidget*
+pcfg_make_empty_dialog(PlacesCfg *cfg)
+{
+    GtkWidget *dlg; /* we'll return this */
+
+    xfce_panel_plugin_block_menu(cfg->plugin);
+
+    dlg = xfce_titled_dialog_new_with_buttons(_("Places"),
+              GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(cfg->plugin))),
+              GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
+              GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+
+    gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
+    gtk_window_set_icon_name(GTK_WINDOW(dlg), "xfce4-settings");
+
+    g_signal_connect(dlg, "response",
+                     G_CALLBACK(pcfg_dialog_close_cb), cfg);
+
+    return dlg;
+}
+
+void
+places_cfg_open_dialog(PlacesCfg *cfg)
+{
     DBG("configure plugin");
 
     GtkWidget *dlg;
@@ -340,13 +337,13 @@
 
     GtkWidget *tmp_box, *tmp_label, *tmp_widget;
     gint active;
-    
-    dlg = places_view_cfg_iface_make_empty_cfg_dialog(cfg->view_iface);
 
+    dlg = pcfg_make_empty_dialog(cfg);
+
     /* BUTTON: frame, vbox */
     vbox_button = gtk_vbox_new(FALSE, 4);
     gtk_widget_show(vbox_button);
-    
+
     frame_button = xfce_create_framebox_with_content(_("Button"), vbox_button);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame_button, FALSE, FALSE, 0);
 
@@ -355,7 +352,7 @@
     tmp_box = gtk_hbox_new(FALSE, 15);
     gtk_widget_show(tmp_box);
     gtk_box_pack_start(GTK_BOX(vbox_button), tmp_box, FALSE, FALSE, 0);
-    
+
     tmp_label = gtk_label_new_with_mnemonic(_("_Show"));
     gtk_widget_show(tmp_label);
     gtk_box_pack_start(GTK_BOX(tmp_box), tmp_label, FALSE, FALSE, 0);
@@ -374,7 +371,7 @@
     else
         active = 0;
     gtk_combo_box_set_active(GTK_COMBO_BOX(tmp_widget), active);
-    
+
     g_signal_connect(G_OBJECT(tmp_widget), "changed",
                      G_CALLBACK(pcfg_button_show_cb), cfg);
 
@@ -385,7 +382,7 @@
     tmp_box = gtk_hbox_new(FALSE, 15);
     gtk_widget_show(tmp_box);
     gtk_box_pack_start(GTK_BOX(vbox_button), tmp_box, FALSE, FALSE, 0);
-    
+
     tmp_label = gtk_label_new_with_mnemonic(_("_Label"));
     gtk_widget_show(tmp_label);
     gtk_box_pack_start(GTK_BOX(tmp_box), tmp_label, FALSE, FALSE, 0);
@@ -403,7 +400,7 @@
     /* MENU: frame, vbox */
     vbox_menu = gtk_vbox_new(FALSE, 4);
     gtk_widget_show(vbox_menu);
-    
+
     frame_menu = xfce_create_framebox_with_content(_("Menu"), vbox_menu);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame_menu, FALSE, FALSE, 0);
 
@@ -428,7 +425,7 @@
                      G_CALLBACK(pcfg_model_cb), cfg);
 
     gtk_widget_show(tmp_widget);
-    gtk_box_pack_start(GTK_BOX(vbox_menu), tmp_widget, FALSE, FALSE, 0);   
+    gtk_box_pack_start(GTK_BOX(vbox_menu), tmp_widget, FALSE, FALSE, 0);
 
     /* MENU: - Mount and Open (indented) */
     tmp_box = gtk_hbox_new(FALSE, 15);
@@ -450,7 +447,7 @@
 
     gtk_widget_show(tmp_widget);
     gtk_box_pack_start(GTK_BOX(tmp_box), tmp_widget, FALSE, FALSE, 0);
-    
+
     gtk_widget_show(tmp_box);
     gtk_box_pack_start(GTK_BOX(vbox_menu), tmp_box, FALSE, FALSE, 0);
 
@@ -481,7 +478,7 @@
     /* RECENT DOCUMENTS: frame, vbox */
     vbox_recent = gtk_vbox_new(FALSE, 4);
     gtk_widget_show(vbox_recent);
-    
+
     /* Gray out this box when "Show recent documents" is off */
     gtk_widget_set_sensitive(vbox_recent, cfg->show_recent);
     g_object_set_data(G_OBJECT(tmp_widget), "cfg_transient", vbox_recent);
@@ -504,7 +501,7 @@
     tmp_box = gtk_hbox_new(FALSE, 15);
     gtk_widget_show(tmp_box);
     gtk_box_pack_start(GTK_BOX(vbox_recent), tmp_box, FALSE, FALSE, 0);
-    
+
     tmp_label = gtk_label_new_with_mnemonic(_("_Number to display"));
     gtk_widget_show(tmp_label);
     gtk_box_pack_start(GTK_BOX(tmp_box), tmp_label, FALSE, FALSE, 0);
@@ -524,7 +521,7 @@
     /* Search: frame, vbox */
     vbox_search = gtk_vbox_new(FALSE, 4);
     gtk_widget_show(vbox_search);
-    
+
     frame_search = xfce_create_framebox_with_content(_("Search"), vbox_search);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame_search, FALSE, FALSE, 0);
 
@@ -532,7 +529,7 @@
     tmp_box = gtk_hbox_new(FALSE, 15);
     gtk_widget_show(tmp_box);
     gtk_box_pack_start(GTK_BOX(vbox_search), tmp_box, FALSE, FALSE, 0);
-    
+
     tmp_label = gtk_label_new_with_mnemonic(_("Co_mmand"));
     gtk_widget_show(tmp_label);
     gtk_box_pack_start(GTK_BOX(tmp_box), tmp_label, FALSE, FALSE, 0);
@@ -552,14 +549,9 @@
 
 /********** Initialization & Finalization **********/
 
-static void 
-pcfg_finalize(PlacesCfgViewIface *cfg_iface)
+void
+places_cfg_finalize(PlacesCfg *cfg)
 {
-    PlacesCfg *cfg;
-
-    g_assert(cfg_iface != NULL);
-
-    cfg = cfg_iface->cfg;
     g_assert(cfg != NULL);
 
     if(cfg->label != NULL)
@@ -573,32 +565,31 @@
         g_free(cfg->write_path);
 
     g_free(cfg);
-    g_free(cfg_iface);
 }
 
-/* cfg takes ownership of {read,write}_path */
-PlacesCfgViewIface*
-places_cfg_new(PlacesViewCfgIface *view_iface, gchar *read_path, gchar *write_path)
+PlacesCfg*
+places_cfg_new(XfcePanelPlugin *plugin, PlacesViewCfgIface *view_iface)
 {
-    PlacesCfgViewIface *cfg_iface;
     PlacesCfg *cfg;
 
     g_assert(view_iface != NULL);
 
-    cfg                     = g_new0(PlacesCfg, 1);
-    cfg->read_path          = read_path;
-    cfg->write_path         = write_path;
-    cfg->view_iface         = view_iface;
+    cfg             = g_new0(PlacesCfg, 1);
+    cfg->plugin     = plugin;
+    cfg->view_iface = view_iface;
 
+    cfg->read_path  = xfce_panel_plugin_lookup_rc_file(plugin);
+    cfg->write_path = xfce_panel_plugin_save_location(plugin, TRUE);
+
     pcfg_load(cfg);
-    
-    cfg_iface               = g_new0(PlacesCfgViewIface, 1);
-    cfg_iface->cfg          = cfg;
-    cfg_iface->open_dialog  = pcfg_open_dialog;
-    cfg_iface->save         = pcfg_save;
-    cfg_iface->finalize     = pcfg_finalize;
 
-    return cfg_iface;
+    g_signal_connect_swapped(G_OBJECT(plugin), "configure-plugin",
+                             G_CALLBACK(places_cfg_open_dialog), cfg);
+    g_signal_connect_swapped(G_OBJECT(plugin), "save",
+                             G_CALLBACK(places_cfg_save), cfg);
+    xfce_panel_plugin_menu_show_configure(plugin);
+
+    return cfg;
 }
 
 /* vim: set ai et tabstop=4: */

Modified: xfce4-places-plugin/trunk/panel-plugin/cfg.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/cfg.h	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/panel-plugin/cfg.h	2008-01-08 05:07:51 UTC (rev 3788)
@@ -1,9 +1,8 @@
 /*  xfce4-places-plugin
  *
  *  Defines the struct holding configuration data.
- *  Defines the interface by which view communicates with cfg.
  *
- *  Copyright (c) 2007 Diego Ongaro <ongardie at gmail.com>
+ *  Copyright (c) 2007-2008 Diego Ongaro <ongardie at gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -24,11 +23,13 @@
 #define _XFCE_PANEL_PLACES_CFG_H
 
 #include <glib.h>
+#include <libxfce4panel/xfce-panel-plugin.h>
 #include "view.h"
 
 typedef struct
 {
     /* "private" */
+    XfcePanelPlugin     *plugin;
     PlacesViewCfgIface  *view_iface;
     gchar               *read_path;
     gchar               *write_path;
@@ -50,38 +51,20 @@
 
 } PlacesCfg;
 
-typedef struct _PlacesCfgViewIface PlacesCfgViewIface;
-struct _PlacesCfgViewIface {
-    
-    PlacesCfg           *cfg;
+void
+places_cfg_open_dialog(PlacesCfg*);
 
-    void                (*open_dialog)         (PlacesCfg*);
-    void                (*load)                (PlacesCfg*);
-    void                (*save)                (PlacesCfg*);
-    void                (*finalize)            (PlacesCfgViewIface*);
-    
-};
+void
+places_cfg_load(PlacesCfg*);
 
-inline PlacesCfg*
-places_cfg_view_iface_get_cfg(PlacesCfgViewIface*);
+void
+places_cfg_save(PlacesCfg*);
 
-inline void
-places_cfg_view_iface_open_dialog(PlacesCfgViewIface*);
+void
+places_cfg_finalize(PlacesCfg*);
 
-inline void
-places_cfg_view_iface_load(PlacesCfgViewIface*);
+PlacesCfg*
+places_cfg_new(XfcePanelPlugin*, PlacesViewCfgIface*);
 
-inline void
-places_cfg_view_iface_save(PlacesCfgViewIface*);
-
-inline void
-places_cfg_view_iface_finalize(PlacesCfgViewIface*);
-
-
-/* PlacesCfg will take ownership of the paths */
-PlacesCfgViewIface*
-places_cfg_new(PlacesViewCfgIface*,
-               gchar *read_path, gchar *write_path);
-
 #endif
 /* vim: set ai et tabstop=4: */

Modified: xfce4-places-plugin/trunk/panel-plugin/view.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/view.c	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/panel-plugin/view.c	2008-01-08 05:07:51 UTC (rev 3788)
@@ -2,7 +2,7 @@
  *
  *  This file handles the GUI. It "owns" the model and cfg.
  *
- *  Copyright (c) 2007 Diego Ongaro <ongardie at gmail.com>
+ *  Copyright (c) 2007-2008 Diego Ongaro <ongardie at gmail.com>
  *
  *  Largely based on:
  *
@@ -67,7 +67,17 @@
 #include "model_volumes.h"
 #include "model_user.h"
 #include "xfce4-popup-places.h"
+#include "button.h"
 
+struct _PlacesViewCfgIface
+{
+    PlacesView          *places_view;
+
+    void                (*update_menu)              (PlacesView*);
+    void                (*update_button)            (PlacesView*);
+    void                (*reconfigure_model)        (PlacesView*);
+};
+
 struct _PlacesView
 {
     /* plugin */
@@ -75,27 +85,19 @@
     
     /* configuration */
     PlacesCfg                 *cfg;
-    PlacesCfgViewIface        *cfg_iface;
     PlacesViewCfgIface        *view_cfg_iface;
     
     /* view */
     GtkWidget                 *button;
-    GtkWidget                 *button_image;
-    GtkWidget                 *button_label;
     GtkWidget                 *menu;
+
 #if !USE_GTK_TOOLTIP_API
     GtkTooltips               *tooltips;
 #endif
-    gboolean                  needs_separator;
-    guint                     menu_timeout_id;
-    
-    GtkOrientation            orientation;
-    gint                      size;
-    gboolean                  show_button_icon;
-    gboolean                  show_button_label;
-    gchar                     *label_text;
-    gboolean                  force_update_theme;
 
+    gboolean                   needs_separator;
+    guint                      menu_timeout_id;
+    
     /* model */
     GList                     *bookmark_groups;
 };
@@ -153,12 +155,6 @@
     iface->reconfigure_model(iface->places_view);
 }
 
-inline GtkWidget*
-places_view_cfg_iface_make_empty_cfg_dialog(PlacesViewCfgIface *iface)
-{
-    return iface->make_empty_cfg_dialog(iface->places_view);
-}
-
 /********** Model Management **********/
 static void
 pview_destroy_model(PlacesView *view)
@@ -251,36 +247,6 @@
 
 /* Panel callbacks */
 
-static gboolean
-pview_cb_size_changed(PlacesView *pd)
-{
-    g_assert(pd != NULL);
-    g_assert(pd->button != NULL);
-
-    if(GTK_WIDGET_REALIZED(pd->button))
-        pview_button_update(pd);
-
-    return TRUE;
-}
-
-static void
-pview_cb_theme_changed(PlacesView *view)
-{
-    g_assert(view != NULL);
-    g_assert(view->button != NULL);
-
-    DBG("theme changed");
-
-    /* update the button */
-    if(GTK_WIDGET_REALIZED(view->button)){
-        view->force_update_theme = TRUE;
-        pview_button_update(view);
-    }
-    
-    /* force a menu update */
-    pview_destroy_menu(view);
-}
-
 /* Menu callbacks */
 static gboolean /* return false to stop calling it */
 pview_cb_menu_timeout(PlacesView *pd){
@@ -771,208 +737,41 @@
     }
 }
 
+static GdkPixbuf*
+pview_pixbuf_factory(gint size)
+{
+    return xfce_themed_icon_load_category(2, size);
+}
+
 static void
 pview_button_update(PlacesView *view)
 {
-    
     PlacesCfg *cfg = view->cfg;
-    gboolean orientation_changed, size_changed, 
-             icon_presence_changed, label_presence_changed, 
-             label_changed, theme_changed;
-    static gboolean first_run = TRUE;
+    PlacesButton *button = (PlacesButton*) view->button;
 
-    DBG("button_update (first run: %1x)", first_run);
+    static guint tooltip_text_hash = 0;
+    guint new_tooltip_text_hash;
 
-    if(first_run){
-        first_run = FALSE;
-        
-        orientation_changed = TRUE;
-        view->orientation = xfce_panel_plugin_get_orientation(view->plugin);
-        
-        size_changed = TRUE;
-        view->size = xfce_panel_plugin_get_size(view->plugin);
-        
-        icon_presence_changed = TRUE;
-        view->show_button_icon = cfg->show_button_icon;
-        
-        label_presence_changed = TRUE;
-        view->show_button_label = cfg->show_button_label;
-        
-        label_changed = TRUE;
-        view->label_text = g_strdup(cfg->label);
+    places_button_set_label(button,
+                  cfg->show_button_label ? cfg->label : NULL);
 
-        theme_changed = TRUE;
-        view->force_update_theme = FALSE;
+    places_button_set_pixbuf_factory(button,
+                  cfg->show_button_icon  ? pview_pixbuf_factory : NULL);
 
-    }else{
-        orientation_changed    = (view->orientation != xfce_panel_plugin_get_orientation(view->plugin));
-        size_changed           = (view->size != xfce_panel_plugin_get_size(view->plugin));
-        icon_presence_changed  = (view->show_button_icon != cfg->show_button_icon);
-        label_presence_changed = (view->show_button_label != cfg->show_button_label);
-        label_changed          = (strcmp(view->label_text, cfg->label) != 0);
-        theme_changed          = view->force_update_theme;
-    }
+    /* tooltips */
+    new_tooltip_text_hash = g_str_hash(cfg->label);
+    if (new_tooltip_text_hash != tooltip_text_hash) {
 
-    DBG("orientation: %1x, size: %1x, icon_pr: %1x, label_pr: %1x, label_text: %1x",
-        orientation_changed, size_changed, 
-        icon_presence_changed, label_presence_changed, 
-        label_changed);
-
-    if(orientation_changed){
-        GtkWidget *button_box = gtk_bin_get_child(GTK_BIN(view->button));
-        
-        view->orientation = xfce_panel_plugin_get_orientation(view->plugin);
-        xfce_hvbox_set_orientation(XFCE_HVBOX(button_box), view->orientation);
-
-        size_changed = TRUE;
-    }
-    
-    if(label_changed){
-        g_free(view->label_text);
-        view->label_text = g_strdup(cfg->label);
-    }
-
-    if(theme_changed)
-        view->force_update_theme = FALSE;
-
-    if(size_changed || icon_presence_changed || label_presence_changed || label_changed || theme_changed){
-        view->size              = xfce_panel_plugin_get_size(view->plugin);
-        DBG("Panel size: %d", view->size);
-        view->show_button_icon  = cfg->show_button_icon;
-        view->show_button_label = cfg->show_button_label;
-        
-        GdkPixbuf *icon;
-        gint width, height;
-        gint button_overhead_size, box_overhead_size;
-        GtkWidget *button_box = gtk_bin_get_child(GTK_BIN(view->button));
-        
-        button_overhead_size = 2 + 2 *  MAX(view->button->style->xthickness,
-                                            view->button->style->ythickness);
-        box_overhead_size = 0;
-        width = 0;
-        height = 0;
-
-        if(view->show_button_icon){
-            icon = xfce_themed_icon_load_category(2, view->size - button_overhead_size);
-            if(G_LIKELY(icon != NULL)){
-                
-                width  = MAX(gdk_pixbuf_get_width(icon),  view->size - button_overhead_size);
-                height = MAX(gdk_pixbuf_get_height(icon), view->size - button_overhead_size);
-             
-                if(view->button_image == NULL){
-                    view->button_image = g_object_ref(gtk_image_new_from_pixbuf(icon));
-                    gtk_box_pack_start_defaults(GTK_BOX(button_box),
-                                                view->button_image);
-                    gtk_widget_show(view->button_image);
-                }else{
-                    g_assert(GTK_IS_WIDGET(view->button_image));
-                    gtk_image_set_from_pixbuf(GTK_IMAGE(view->button_image), icon);
-                }
-
-                g_object_unref(G_OBJECT(icon));
-            }else{
-                DBG("Could not load icon for button");
-            }
-
-        }else if(view->button_image != NULL){
-            g_assert(GTK_IS_WIDGET(view->button_image));
-            gtk_widget_destroy(view->button_image);
-            g_object_unref(view->button_image);
-            view->button_image = NULL;
-        }
-
-        if(view->show_button_label){
-            GtkRequisition req;
-            
-            if(view->button_label == NULL){
-                view->button_label = g_object_ref(gtk_label_new(view->label_text));
-                gtk_box_pack_end_defaults(GTK_BOX(button_box), 
-                                          view->button_label);
-                gtk_widget_show(view->button_label);
-            }else{
-                g_assert(GTK_IS_WIDGET(view->button_label));
-                if(label_changed)
-                    gtk_label_set_text(GTK_LABEL(view->button_label), view->label_text);
-            }
-
-            gtk_widget_size_request(view->button_label, &req);
-            if(view->orientation == GTK_ORIENTATION_HORIZONTAL){
-                width += req.width;
-                height = MAX(height, req.height);
-            }else{
-                width = MAX(width, req.width);
-                height += req.height;
-            }
-
-        }else if(view->button_label != NULL){
-            g_assert(GTK_IS_WIDGET(view->button_label));
-            gtk_widget_destroy(view->button_label);
-            g_object_unref(view->button_label);
-            view->button_label = NULL;
-        }
-
-        width += button_overhead_size;
-        height += button_overhead_size;
-
-        if(view->button_image != NULL && view->button_label != NULL){
-
-            box_overhead_size = gtk_box_get_spacing(GTK_BOX(button_box));
-
-            if(view->orientation == GTK_ORIENTATION_HORIZONTAL)
-                width += box_overhead_size;
-            else
-                height += box_overhead_size;
-        }
-
-        if(view->orientation == GTK_ORIENTATION_HORIZONTAL)
-            height = MAX(height, view->size);
-        else
-            width = MAX(width, view->size);
-
-        gtk_widget_show_all(view->button);
-
-        DBG("width=%d, height=%d", width, height);
-        gtk_widget_set_size_request(view->button, width, height);
-    }
-
-    if(label_changed){
 #if USE_GTK_TOOLTIP_API
-        gtk_widget_set_tooltip_text(view->button, view->label_text);
+        gtk_widget_set_tooltip_text(view->button, cfg->label);
 #else
-        gtk_tooltips_set_tip(view->tooltips, view->button, view->label_text, NULL);
+        gtk_tooltips_set_tip(view->tooltips, view->button, cfg->label, NULL);
 #endif
+
     }
-}
+    tooltip_text_hash = new_tooltip_text_hash;
 
-static void
-pview_cfg_dialog_close_cb(GtkDialog *dialog, gint response, PlacesView *view)
-{
-    gtk_widget_destroy(GTK_WIDGET(dialog));
-    xfce_panel_plugin_unblock_menu(view->plugin);
-    places_cfg_view_iface_save(view->cfg_iface);
 }
-
-static GtkWidget*
-pview_make_empty_cfg_dialog(PlacesView *view)
-{
-    GtkWidget *dlg; /* we'll return this */
-
-    xfce_panel_plugin_block_menu(view->plugin);
-    
-    dlg = xfce_titled_dialog_new_with_buttons(_("Places"),
-              GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(view->plugin))),
-              GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
-              GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
-
-    gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
-    gtk_window_set_icon_name(GTK_WINDOW(dlg), "xfce4-settings");
-
-    g_signal_connect(dlg, "response",
-                     G_CALLBACK(pview_cfg_dialog_close_cb), view);
-
-    return dlg;
-}
-
 /********** Handle user message **********/
 static gboolean
 pview_popup_command_message_received(GtkWidget *widget,
@@ -1026,7 +825,6 @@
 PlacesView*
 places_view_init(XfcePanelPlugin *plugin)
 {
-    GtkWidget *button_box;
     PlacesView *view;                   /* internal use in this file */
     PlacesViewCfgIface *view_cfg_iface; /* given to cfg */
 
@@ -1041,14 +839,10 @@
     view_cfg_iface->update_menu             = pview_update_menu;
     view_cfg_iface->update_button           = pview_button_update;
     view_cfg_iface->reconfigure_model       = pview_reconfigure_model;
-    view_cfg_iface->make_empty_cfg_dialog   = pview_make_empty_cfg_dialog;
-    
     view->view_cfg_iface = view_cfg_iface;
-    view->cfg_iface      = places_cfg_new(view_cfg_iface, 
-                                          xfce_panel_plugin_lookup_rc_file(view->plugin),
-                                          xfce_panel_plugin_save_location(view->plugin, TRUE));
-    view->cfg            = places_cfg_view_iface_get_cfg(view->cfg_iface);
 
+    view->cfg      = places_cfg_new(view->plugin, view_cfg_iface);
+
     pview_reconfigure_model(view);
     
 #if USE_GTK_TOOLTIP_API
@@ -1063,43 +857,25 @@
     DBG("init GUI");
 
     /* create the button */
-    view->button = g_object_ref(xfce_create_panel_toggle_button());
+    view->button = g_object_ref(places_button_new(view->plugin));
     xfce_panel_plugin_add_action_widget(view->plugin, view->button);
     gtk_container_add(GTK_CONTAINER(view->plugin), view->button);
     gtk_widget_show(view->button);
 
-    /* create the box */
-    button_box = xfce_hvbox_new(xfce_panel_plugin_get_orientation(view->plugin),
-                                FALSE, 4);
-    gtk_container_set_border_width(GTK_CONTAINER(button_box), 0);
-    gtk_container_add(GTK_CONTAINER(view->button), button_box);
-    gtk_widget_show(button_box);
-
     pview_button_update(view);
 
     /* signals for icon theme/screen changes */
     g_signal_connect_swapped(view->button, "style-set",
-                             G_CALLBACK(pview_cb_theme_changed), view);
+                             G_CALLBACK(pview_destroy_menu), view);
     g_signal_connect_swapped(view->button, "screen-changed",
-                             G_CALLBACK(pview_cb_theme_changed), view);
+                             G_CALLBACK(pview_destroy_menu), view);
     
-    /* plugin signals */
-    g_signal_connect_swapped(G_OBJECT(view->plugin), "size-changed",
-                             G_CALLBACK(pview_cb_size_changed), view);
-    g_signal_connect_swapped(G_OBJECT(view->plugin), "orientation-changed",
-                             G_CALLBACK(pview_button_update), view);
-
     /* button signal */
     g_signal_connect_swapped(view->button, "button-press-event",
                              G_CALLBACK(pview_cb_button_pressed), view);
 
-    /* cfg-related signals */
-    g_signal_connect_swapped(G_OBJECT(view->plugin), "configure-plugin",
-                             G_CALLBACK(places_cfg_view_iface_open_dialog), view->cfg_iface);
-    g_signal_connect_swapped(G_OBJECT(view->plugin), "save",
-                             G_CALLBACK(places_cfg_view_iface_save), view->cfg_iface);
-    xfce_panel_plugin_menu_show_configure(view->plugin);
 
+
     /* set selection for xfce4-popup-places */
     pview_popup_command_set_selection(view);
 
@@ -1114,20 +890,14 @@
     pview_destroy_menu(view);
     pview_destroy_model(view);
     
-    if(view->button_image != NULL)
-        g_object_unref(view->button_image);
-    if(view->button_label != NULL)
-        g_object_unref(view->button_label);
     if(view->button != NULL)
         g_object_unref(view->button);
-    if(view->label_text != NULL)
-        g_free(view->label_text);
 
 #if !USE_GTK_TOOLTIP_API
     g_object_unref(view->tooltips);
 #endif
 
-    places_cfg_view_iface_finalize(view->cfg_iface);
+    places_cfg_finalize(view->cfg);
     
     g_free(view->view_cfg_iface);
     g_free(view);

Modified: xfce4-places-plugin/trunk/panel-plugin/view.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/view.h	2008-01-07 00:16:31 UTC (rev 3787)
+++ xfce4-places-plugin/trunk/panel-plugin/view.h	2008-01-08 05:07:51 UTC (rev 3788)
@@ -3,7 +3,7 @@
  *  Defines the interface by which cfg can communicate with view.
  *  Headers for interface by which places.c creates/destroys view.
  *
- *  Copyright (c) 2007 Diego Ongaro <ongardie at gmail.com>
+ *  Copyright (c) 2007-2008 Diego Ongaro <ongardie at gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -31,17 +31,9 @@
 
 typedef struct _PlacesView PlacesView;
 
-typedef struct {
-    
-    PlacesView          *places_view;
+/* Interface for cfg */
+typedef struct _PlacesViewCfgIface PlacesViewCfgIface;
 
-    void                (*update_menu)              (PlacesView*);
-    void                (*update_button)            (PlacesView*);
-    void                (*reconfigure_model)        (PlacesView*);
-    GtkWidget*          (*make_empty_cfg_dialog)    (PlacesView*);
-    
-} PlacesViewCfgIface;
-
 inline void
 places_view_cfg_iface_update_menu(PlacesViewCfgIface*);
 
@@ -51,11 +43,7 @@
 inline void
 places_view_cfg_iface_reconfigure_model(PlacesViewCfgIface*);
 
-inline GtkWidget*
-places_view_cfg_iface_make_empty_cfg_dialog(PlacesViewCfgIface*);
 
-#include "cfg.h"
-
 /* Init & Finalize */
 PlacesView*
 places_view_init(XfcePanelPlugin*);




More information about the Goodies-commits mailing list