Use real Gtk TreeView progress bars, finally!
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 14 Oct 2007 22:53:30 +0000 (00:53 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 14 Oct 2007 22:53:30 +0000 (00:53 +0200)
clients/gtk2/Makefile.am
clients/gtk2/dolcon.c
clients/gtk2/mainwnd.desc
clients/gtk2/progressbar.c [deleted file]
clients/gtk2/progressbar.h [deleted file]
common/makegdesc
configure.in
doc/INSTALL

index 298ec86..813c8fe 100644 (file)
@@ -7,9 +7,7 @@ dolcon_SOURCES= dolcon.c \
                hublist.c \
                hublist.h \
                hublist-xml.c \
-               hublist-old.c \
-               progressbar.c \
-               progressbar.h
+               hublist-old.c
 
 EXTRA_DIST=mainwnd.desc inpdialog.desc pref.desc reslist.desc
 
index c71b9a1..c96498f 100644 (file)
@@ -47,7 +47,6 @@
 #endif
 #include "dolcon.h"
 #include "hublist.h"
-#include "progressbar.h"
 
 #define TRHISTSIZE 10
 
@@ -292,6 +291,27 @@ char *bytes2si(long long bytes)
     return(ret);
 }
 
+void progressfunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+    int totalc, curc;
+    int total, cur;
+    char buf[64];
+    
+    totalc = (GPOINTER_TO_INT(data) & 0xff00) >> 8;
+    curc = GPOINTER_TO_INT(data) & 0xff;
+    gtk_tree_model_get(model, iter, totalc, &total, curc, &cur, -1);
+    if(total < 1)
+       g_object_set(rend, "value", GINT_TO_POINTER(0), NULL);
+    else
+       g_object_set(rend, "value", GINT_TO_POINTER((int)(((double)cur / (double)total) * 100)), NULL);
+    if(cur < 0) {
+       g_object_set(rend, "text", "", NULL);
+    } else {
+       snprintf(buf, 64, "%'i", cur);
+       g_object_set(rend, "text", buf, NULL);
+    }
+}
+
 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
     int colnum;
index d0ca65f..9bb2220 100644 (file)
@@ -149,12 +149,7 @@ end
                                                                $textrend func: transnicebytefunc funcdata: "GINT_TO_POINTER(6)"
                                                        end
                                                        :tvcol title: "Position"
-#ifdef ENABLE_GTK2PBAR
-                                                               $custrend newfunc: custom_cell_renderer_progress_new attr(percentage): 9
-#else
-                                                               $textrend func: percentagefunc funcdata: "GINT_TO_POINTER(9)" expand: FALSE
-#endif
-                                                               $textrend func: transnicebytefunc funcdata: "GINT_TO_POINTER(7)"
+                                                               $progrend func: progressfunc funcdata: "GINT_TO_POINTER((6 << 8) | 7)" expand: TRUE
                                                        end
                                                        :tvcol title: "Speed"
                                                                $textrend func: transspeedinfo
@@ -179,12 +174,7 @@ end
                                                                $textrend func: transnicebytefunc funcdata: "GINT_TO_POINTER(6)"
                                                        end
                                                        :tvcol title: "Position"
-#ifdef ENABLE_GTK2PBAR
-                                                               $custrend newfunc: custom_cell_renderer_progress_new attr(percentage): 9
-#else
-                                                               $textrend func: percentagefunc funcdata: "GINT_TO_POINTER(9)" expand: FALSE
-#endif
-                                                               $textrend func: transnicebytefunc funcdata: "GINT_TO_POINTER(7)"
+                                                               $progrend func: progressfunc funcdata: "GINT_TO_POINTER((6 << 8) | 7)" expand: TRUE
                                                        end
                                                        :tvcol title: "Speed"
                                                                $textrend func: transspeedinfo
diff --git a/clients/gtk2/progressbar.c b/clients/gtk2/progressbar.c
deleted file mode 100644 (file)
index 2dff9b2..0000000
+++ /dev/null
@@ -1,344 +0,0 @@
-/* Taken from the GTK TreeView tutorial on gtk.org.
- * Slightly modified.
- */
-
-#include "progressbar.h"
-
-/* This is based mainly on GtkCellRendererProgress
- *  in GAIM, written and (c) 2002 by Sean Egan
- *  (Licensed under the GPL), which in turn is
- *  based on Gtk's GtkCellRenderer[Text|Toggle|Pixbuf]
- *  implementation by Jonathan Blandford */
-
-/* Some boring function declarations: GObject type system stuff */
-
-static void     custom_cell_renderer_progress_init       (CustomCellRendererProgress      *cellprogress);
-
-static void     custom_cell_renderer_progress_class_init (CustomCellRendererProgressClass *klass);
-
-static void     custom_cell_renderer_progress_get_property  (GObject                    *object,
-                                                             guint                       param_id,
-                                                             GValue                     *value,
-                                                             GParamSpec                 *pspec);
-
-static void     custom_cell_renderer_progress_set_property  (GObject                    *object,
-                                                             guint                       param_id,
-                                                             const GValue               *value,
-                                                             GParamSpec                 *pspec);
-
-static void     custom_cell_renderer_progress_finalize (GObject *gobject);
-
-
-/* These functions are the heart of our custom cell renderer: */
-
-static void     custom_cell_renderer_progress_get_size   (GtkCellRenderer            *cell,
-                                                          GtkWidget                  *widget,
-                                                          GdkRectangle               *cell_area,
-                                                          gint                       *x_offset,
-                                                          gint                       *y_offset,
-                                                          gint                       *width,
-                                                          gint                       *height);
-
-static void     custom_cell_renderer_progress_render     (GtkCellRenderer            *cell,
-                                                          GdkWindow                  *window,
-                                                          GtkWidget                  *widget,
-                                                          GdkRectangle               *background_area,
-                                                          GdkRectangle               *cell_area,
-                                                          GdkRectangle               *expose_area,
-                                                          guint                       flags);
-
-
-enum
-{
-  PROP_PERCENTAGE = 1,
-};
-
-static   gpointer parent_class;
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_get_type: here we register our type with
- *                                          the GObject type system if we
- *                                          haven't done so yet. Everything
- *                                          else is done in the callbacks.
- *
- ***************************************************************************/
-
-GType
-custom_cell_renderer_progress_get_type (void)
-{
-    static GType cell_progress_type = 0;
-
-    if (cell_progress_type)
-       return cell_progress_type;
-
-    if (1)
-    {
-       static const GTypeInfo cell_progress_info =
-           {
-               sizeof (CustomCellRendererProgressClass),
-               NULL,                                                     /* base_init */
-               NULL,                                                     /* base_finalize */
-               (GClassInitFunc) custom_cell_renderer_progress_class_init,
-               NULL,                                                     /* class_finalize */
-               NULL,                                                     /* class_data */
-               sizeof (CustomCellRendererProgress),
-               0,                                                        /* n_preallocs */
-               (GInstanceInitFunc) custom_cell_renderer_progress_init,
-           };
-
-       /* Derive from GtkCellRenderer */
-       cell_progress_type = g_type_register_static (GTK_TYPE_CELL_RENDERER,
-                                                    "CustomCellRendererProgress",
-                                                    &cell_progress_info,
-                                                    0);
-    }
-
-    return cell_progress_type;
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_init: set some default properties of the
- *                                      parent (GtkCellRenderer).
- *
- ***************************************************************************/
-
-static void
-custom_cell_renderer_progress_init (CustomCellRendererProgress *cellrendererprogress)
-{
-    GTK_CELL_RENDERER(cellrendererprogress)->mode = GTK_CELL_RENDERER_MODE_INERT;
-    GTK_CELL_RENDERER(cellrendererprogress)->xpad = 2;
-    GTK_CELL_RENDERER(cellrendererprogress)->ypad = 2;
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_class_init:
- *
- *  set up our own get_property and set_property functions, and
- *  override the parent's functions that we need to implement.
- *  And make our new "percentage" property known to the type system.
- *  If you want cells that can be activated on their own (ie. not
- *  just the whole row selected) or cells that are editable, you
- *  will need to override 'activate' and 'start_editing' as well.
- *
- ***************************************************************************/
-
-static void
-custom_cell_renderer_progress_class_init (CustomCellRendererProgressClass *klass)
-{
-    GtkCellRendererClass *cell_class   = GTK_CELL_RENDERER_CLASS(klass);
-    GObjectClass         *object_class = G_OBJECT_CLASS(klass);
-
-    parent_class           = g_type_class_peek_parent (klass);
-    object_class->finalize = custom_cell_renderer_progress_finalize;
-
-    /* Hook up functions to set and get our
-     *   custom cell renderer properties */
-    object_class->get_property = custom_cell_renderer_progress_get_property;
-    object_class->set_property = custom_cell_renderer_progress_set_property;
-
-    /* Override the two crucial functions that are the heart
-     *   of a cell renderer in the parent class */
-    cell_class->get_size = custom_cell_renderer_progress_get_size;
-    cell_class->render   = custom_cell_renderer_progress_render;
-
-    /* Install our very own properties */
-    g_object_class_install_property (object_class,
-                                    PROP_PERCENTAGE,
-                                    g_param_spec_double ("percentage",
-                                                         "Percentage",
-                                                         "The fractional progress to display",
-                                                         0, 1, 0,
-                                                         G_PARAM_READWRITE));
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_finalize: free any resources here
- *
- ***************************************************************************/
-
-static void
-custom_cell_renderer_progress_finalize (GObject *object)
-{
-/*
-  CustomCellRendererProgress *cellrendererprogress = CUSTOM_CELL_RENDERER_PROGRESS(object);
-*/
-
-    /* Free any dynamically allocated resources here */
-
-    (* G_OBJECT_CLASS (parent_class)->finalize) (object);
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_get_property: as it says
- *
- ***************************************************************************/
-
-static void
-custom_cell_renderer_progress_get_property (GObject    *object,
-                                            guint       param_id,
-                                            GValue     *value,
-                                            GParamSpec *psec)
-{
-  CustomCellRendererProgress  *cellprogress = CUSTOM_CELL_RENDERER_PROGRESS(object);
-
-  switch (param_id)
-  {
-    case PROP_PERCENTAGE:
-      g_value_set_double(value, cellprogress->progress);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
-      break;
-  }
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_set_property: as it says
- *
- ***************************************************************************/
-
-static void
-custom_cell_renderer_progress_set_property (GObject      *object,
-                                            guint         param_id,
-                                            const GValue *value,
-                                            GParamSpec   *pspec)
-{
-    CustomCellRendererProgress *cellprogress = CUSTOM_CELL_RENDERER_PROGRESS (object);
-
-    switch (param_id)
-    {
-    case PROP_PERCENTAGE:
-       cellprogress->progress = g_value_get_double(value);
-       break;
-
-    default:
-       G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
-       break;
-    }
-}
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_new: return a new cell renderer instance
- *
- ***************************************************************************/
-
-GtkCellRenderer *
-custom_cell_renderer_progress_new (void)
-{
-    return g_object_new(CUSTOM_TYPE_CELL_RENDERER_PROGRESS, NULL);
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_get_size: crucial - calculate the size
- *                                          of our cell, taking into account
- *                                          padding and alignment properties
- *                                          of parent.
- *
- ***************************************************************************/
-
-#define FIXED_WIDTH   100
-#define FIXED_HEIGHT  12
-
-static void
-custom_cell_renderer_progress_get_size (GtkCellRenderer *cell,
-                                        GtkWidget       *widget,
-                                        GdkRectangle    *cell_area,
-                                        gint            *x_offset,
-                                        gint            *y_offset,
-                                        gint            *width,
-                                        gint            *height)
-{
-    gint calc_width;
-    gint calc_height;
-
-    calc_width  = (gint) cell->xpad * 2 + FIXED_WIDTH;
-    calc_height = (gint) cell->ypad * 2 + FIXED_HEIGHT;
-
-    if (width)
-       *width = calc_width;
-
-    if (height)
-       *height = calc_height;
-
-    if (cell_area)
-    {
-       if (x_offset)
-       {
-           *x_offset = cell->xalign * (cell_area->width - calc_width);
-           *x_offset = MAX (*x_offset, 0);
-       }
-
-       if (y_offset)
-       {
-           *y_offset = cell->yalign * (cell_area->height - calc_height);
-           *y_offset = MAX (*y_offset, 0);
-       }
-    }
-}
-
-
-/***************************************************************************
- *
- *  custom_cell_renderer_progress_render: crucial - do the rendering.
- *
- ***************************************************************************/
-
-static void
-custom_cell_renderer_progress_render (GtkCellRenderer *cell,
-                                      GdkWindow       *window,
-                                      GtkWidget       *widget,
-                                      GdkRectangle    *background_area,
-                                      GdkRectangle    *cell_area,
-                                      GdkRectangle    *expose_area,
-                                      guint            flags)
-{
-    CustomCellRendererProgress *cellprogress = CUSTOM_CELL_RENDERER_PROGRESS (cell);
-    GtkStateType                state;
-    gint                        width, height;
-    gint                        x_offset, y_offset;
-
-    custom_cell_renderer_progress_get_size (cell, widget, cell_area,
-                                           &x_offset, &y_offset,
-                                           &width, &height);
-
-    if (GTK_WIDGET_HAS_FOCUS (widget))
-       state = GTK_STATE_ACTIVE;
-    else
-       state = GTK_STATE_NORMAL;
-
-    width  -= cell->xpad*2;
-    height -= cell->ypad*2;
-
-    gtk_paint_box (widget->style,
-                  window,
-                  GTK_STATE_NORMAL, GTK_SHADOW_IN,
-                  NULL, widget, "trough",
-                  cell_area->x + x_offset + cell->xpad,
-                  cell_area->y + y_offset + cell->ypad,
-                  width - 1, height - 1);
-
-    gtk_paint_box (widget->style,
-                  window,
-                  state, GTK_SHADOW_OUT,
-                  NULL, widget, "bar",
-                  cell_area->x + x_offset + cell->xpad,
-                  cell_area->y + y_offset + cell->ypad,
-                  width * cellprogress->progress,
-                  height - 1);
-}
diff --git a/clients/gtk2/progressbar.h b/clients/gtk2/progressbar.h
deleted file mode 100644 (file)
index 4b773f3..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Taken from the GTK TreeView tutorial on gtk.org. */
-
-#ifndef _custom_cell_renderer_progressbar_included_
-#define _custom_cell_renderer_progressbar_included_
-
-#include <gtk/gtk.h>
-
-/* Some boilerplate GObject type check and type cast macros.
- *  'klass' is used here instead of 'class', because 'class'
- *  is a c++ keyword */
-
-#define CUSTOM_TYPE_CELL_RENDERER_PROGRESS             (custom_cell_renderer_progress_get_type())
-#define CUSTOM_CELL_RENDERER_PROGRESS(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),  CUSTOM_TYPE_CELL_RENDERER_PROGRESS, CustomCellRendererProgress))
-#define CUSTOM_CELL_RENDERER_PROGRESS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass),  CUSTOM_TYPE_CELL_RENDERER_PROGRESS, CustomCellRendererProgressClass))
-#define CUSTOM_IS_CELL_PROGRESS_PROGRESS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUSTOM_TYPE_CELL_RENDERER_PROGRESS))
-#define CUSTOM_IS_CELL_PROGRESS_PROGRESS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass),  CUSTOM_TYPE_CELL_RENDERER_PROGRESS))
-#define CUSTOM_CELL_RENDERER_PROGRESS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj),  CUSTOM_TYPE_CELL_RENDERER_PROGRESS, CustomCellRendererProgressClass))
-
-typedef struct _CustomCellRendererProgress CustomCellRendererProgress;
-typedef struct _CustomCellRendererProgressClass CustomCellRendererProgressClass;
-
-/* CustomCellRendererProgress: Our custom cell renderer
- *   structure. Extend according to need */
-
-struct _CustomCellRendererProgress
-{
-    GtkCellRenderer   parent;
-    gdouble           progress;
-};
-
-
-struct _CustomCellRendererProgressClass
-{
-    GtkCellRendererClass  parent_class;
-};
-
-
-GType                custom_cell_renderer_progress_get_type (void);
-
-GtkCellRenderer     *custom_cell_renderer_progress_new (void);
-
-
-#endif /* _custom_cell_renderer_progressbar_included_ */
-
index 3adbee2..b61ed75 100755 (executable)
@@ -331,6 +331,16 @@ sub printwidgets
                print "${p}gtk_tree_view_column_set_cell_data_func(column, renderer, " . $widget->{"func"} . ", " . ($widget->{"funcdata"} || "NULL") . ", NULL);\n";
            }
            $widget->{"noshow"} = 1;
+       } elsif($widget->{"type"} eq "progrend") {
+           print "${p}renderer = gtk_cell_renderer_progress_new();\n";
+           print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"FALSE") . ");\n";
+           if(defined($widget->{"value"})) {
+               print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"value\", " . $widget->{"value"} . ");\n";
+           }
+           if(defined($widget->{"func"})) {
+               print "${p}gtk_tree_view_column_set_cell_data_func(column, renderer, " . $widget->{"func"} . ", " . ($widget->{"funcdata"} || "NULL") . ", NULL);\n";
+           }
+           $widget->{"noshow"} = 1;
        } elsif($widget->{"type"} eq "custrend") {
            print "${p}renderer = GTK_CELL_RENDERER(" . $widget->{"newfunc"} . "());\n";
            print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"FALSE") . ");\n";
index daf5d05..b7466ca 100644 (file)
@@ -109,15 +109,6 @@ DOLDA_ENABLE(guishell, [  --enable-guishell       Build the GUI shell programs],
                       [HAS_GTK2])
 AM_CONDITIONAL(GUISHELL, test "$enable_guishell" = yes)
 
-# Gtk progress bar check
-AH_TEMPLATE(ENABLE_GTK2PBAR, [define to compile GTK2 progress bars (experimental)])
-DOLDA_ENABLE(gtk2pbar, [  --enable-gtk2pbar       Enable GTK2 progress bars (experimental)], no,
-                      [HAS_GTK2 enable_gtk2ui])
-if test "$enable_gtk2pbar" = yes; then
-       experimental=yes
-       AC_DEFINE(ENABLE_GTK2PBAR)
-fi
-
 # Gnome applet check
 DOLDA_ENABLE(gnomeapplet, [  --enable-gnomeapplet    Enable GNOME transfer applet (experimental)], no,
                          [HAS_LIBPANELAPPLET])
@@ -294,7 +285,6 @@ echo "    Daemon:                  $enable_daemon"
 echo "    PAM support:             $pam_msg"
 echo "    Kerberos 5 support:      $krb_msg"
 echo "    GTK2 user interface:     $enable_gtk2ui"
-echo "    GTK2 progress bars:      $enable_gtk2pbar"
 echo "    Dolconf configurator:    $enable_dolconf"
 echo "    GUI shell:               $enable_guishell"
 echo "    Guile extension library: $guile_msg"
index 00f66f9..73df535 100644 (file)
@@ -46,11 +46,6 @@ use of command-line parameters:
 
  * --with-guile enables the Guile extension library, necessary for any
    clients written in Scheme (such as the automatic downloader).
- * --enable-gtk2pbar enables graphical progress bars in the Gtk2 GUI
-   client, instead of textual percent indicators. However, these
-   progress bars have proven to be unstable with certain Gtk2 themes,
-   so if the GUI crashes with them enabled, try turning them off
-   before reporting a bug.
  * --enable-gnomeapplet selects the GNOME panel applet for
    compilation.
  * --enable-gaimplugin selects the Gaim chat plugin for compilation.