summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Aurich <darkrain42@pidgin.im>2009-04-12 23:47:43 +0000
committerPaul Aurich <darkrain42@pidgin.im>2009-04-12 23:47:43 +0000
commit72cbcc93e3b7da059d14044b7b242d45f5281692 (patch)
treef11137956a80a4aca6ce061e6a47de0cdf90c1cb
parentc91961a2b9bcf2746826ae14bbf6906899b7ef0a (diff)
parentb66b7bb765ae120d8460d87202efb9dda997db68 (diff)
downloadpidgin-72cbcc93e3b7da059d14044b7b242d45f5281692.tar.gz
merge of 'a4411d5d13d1ac4e203c795bc44f2b34f945c48e'
and '921e0fd19a7d2004b46a639c1024bc75d96b5ffc'
-rw-r--r--ChangeLog.API4
-rw-r--r--finch/libgnt/Makefile.am2
-rw-r--r--finch/libgnt/gntprogressbar.c253
-rw-r--r--finch/libgnt/gntprogressbar.h132
4 files changed, 391 insertions, 0 deletions
diff --git a/ChangeLog.API b/ChangeLog.API
index 155160ada4..62b65a4dc4 100644
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -78,6 +78,10 @@ version 2.6.0 (??/??/2009):
* pidgin_utils_init, pidgin_utils_uninit
* pidgin_notify_pounce_add
+ libgnt:
+ Added:
+ * GntProgressBar and functions (Saleem Abdulrasool)
+
perl:
Changed:
* Made a bunch of functions act more perl-like. Call the new()
diff --git a/finch/libgnt/Makefile.am b/finch/libgnt/Makefile.am
index 99b6d4566b..65ce3cb65f 100644
--- a/finch/libgnt/Makefile.am
+++ b/finch/libgnt/Makefile.am
@@ -28,6 +28,7 @@ libgnt_la_SOURCES = \
gntmenu.c \
gntmenuitem.c \
gntmenuitemcheck.c \
+ gntprogressbar.c \
gntslider.c \
gntstyle.c \
gnttextview.c \
@@ -56,6 +57,7 @@ libgnt_la_headers = \
gntmenu.h \
gntmenuitem.h \
gntmenuitemcheck.h \
+ gntprogressbar.h \
gntslider.h \
gntstyle.h \
gnttextview.h \
diff --git a/finch/libgnt/gntprogressbar.c b/finch/libgnt/gntprogressbar.c
new file mode 100644
index 0000000000..0032fabbe2
--- /dev/null
+++ b/finch/libgnt/gntprogressbar.c
@@ -0,0 +1,253 @@
+/**
+ * GNT - The GLib Ncurses Toolkit
+ *
+ * GNT is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ **/
+
+#include "gntprogressbar.h"
+#include "gntutils.h"
+
+#include <string.h>
+
+typedef struct _GntProgressBarPrivate
+{
+ gdouble fraction;
+ gboolean show_value;
+ GntProgressBarOrientation orientation;
+} GntProgressBarPrivate;
+
+struct _GntProgressBar
+{
+ GntWidget parent;
+#if !GLIB_CHECK_VERSION(2,4,0)
+ GntProgressBarPrivate priv;
+#endif
+};
+
+#if GLIB_CHECK_VERSION(2,4,0)
+#define GNT_PROGRESS_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNT_TYPE_PROGRESS_BAR, GntProgressBarPrivate))
+#else
+#define GNT_PROGRESS_BAR_GET_PRIVATE(o) &(GNT_PROGRESS_BAR(o)->priv)
+#endif
+
+static GntWidgetClass *parent_class = NULL;
+
+
+static void
+gnt_progress_bar_draw (GntWidget *widget)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (GNT_PROGRESS_BAR (widget));
+ gchar progress[8];
+ gint start, end, i, pos;
+ int color;
+
+ g_snprintf (progress, sizeof (progress), "%.1f%%", priv->fraction * 100);
+ color = gnt_color_pair(GNT_COLOR_NORMAL);
+
+ switch (priv->orientation) {
+ case GNT_PROGRESS_LEFT_TO_RIGHT:
+ case GNT_PROGRESS_RIGHT_TO_LEFT:
+ start = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT ? 0 : (1.0 - priv->fraction) * widget->priv.width);
+ end = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT ? widget->priv.width * priv->fraction : widget->priv.width);
+
+ /* background */
+ for (i = 0; i < widget->priv.height; i++)
+ mvwhline (widget->window, i, 0, ' ' | color, widget->priv.width);
+
+ /* foreground */
+ for (i = 0; i < widget->priv.height; i++)
+ mvwhline (widget->window, i, start, ACS_CKBOARD | color | A_REVERSE, end);
+
+ /* text */
+ if (priv->show_value) {
+ pos = widget->priv.width / 2 - strlen (progress) / 2;
+ for (i = 0; i < progress[i]; i++, pos++) {
+ wattrset (widget->window, color | ((pos < start || pos > end) ? A_NORMAL : A_REVERSE));
+ mvwprintw (widget->window, widget->priv.height / 2, pos, "%c", progress[i]);
+ }
+ wattrset (widget->window, color);
+ }
+
+ break;
+ case GNT_PROGRESS_TOP_TO_BOTTOM:
+ case GNT_PROGRESS_BOTTOM_TO_TOP:
+ start = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM ? 0 : (1.0 - priv->fraction) * widget->priv.height);
+ end = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM ? widget->priv.height * priv->fraction : widget->priv.height);
+
+ /* background */
+ for (i = 0; i < widget->priv.width; i++)
+ mvwvline (widget->window, 0, i, ' ' | color, widget->priv.height);
+
+ /* foreground */
+ for (i = 0; i < widget->priv.width; i++)
+ mvwvline (widget->window, start, i, ACS_CKBOARD | color | A_REVERSE, end);
+
+ /* text */
+ if (priv->show_value) {
+ pos = widget->priv.height / 2 - strlen (progress) / 2;
+ for (i = 0; i < progress[i]; i++, pos++) {
+ wattrset (widget->window, color | ((pos < start || pos > end) ? A_NORMAL : A_REVERSE));
+ mvwprintw (widget->window, pos, widget->priv.width / 2, "%c\n", progress[i]);
+ }
+ wattrset (widget->window, color);
+ }
+
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+gnt_progress_bar_size_request (GntWidget *widget)
+{
+ gnt_widget_set_size (widget, widget->priv.minw, widget->priv.minh);
+}
+
+static void
+gnt_progress_bar_class_init (gpointer klass, gpointer class_data)
+{
+ GObjectClass *g_class = G_OBJECT_CLASS (klass);
+
+ parent_class = GNT_WIDGET_CLASS (klass);
+
+#if GLIB_CHECK_VERSION(2,4,0)
+ g_type_class_add_private (g_class, sizeof (GntProgressBarPrivate));
+#endif
+
+ parent_class->draw = gnt_progress_bar_draw;
+ parent_class->size_request = gnt_progress_bar_size_request;
+}
+
+static void
+gnt_progress_bar_init (GTypeInstance *instance, gpointer g_class)
+{
+ GntWidget *widget = GNT_WIDGET (instance);
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (GNT_PROGRESS_BAR (widget));
+
+ gnt_widget_set_take_focus (widget, FALSE);
+ GNT_WIDGET_SET_FLAGS (widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW | GNT_WIDGET_GROW_X);
+
+ widget->priv.minw = 8;
+ widget->priv.minh = 1;
+
+ priv->show_value = TRUE;
+}
+
+GType
+gnt_progress_bar_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (GntProgressBarClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ gnt_progress_bar_class_init, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GntProgressBar),
+ 0, /* n_preallocs */
+ gnt_progress_bar_init, /* instance_init */
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (GNT_TYPE_WIDGET, "GntProgressBar", &info, 0);
+ }
+
+ return type;
+}
+
+GntWidget *
+gnt_progress_bar_new (void)
+{
+ GntWidget *widget = g_object_new (GNT_TYPE_PROGRESS_BAR, NULL);
+ return widget;
+}
+
+void
+gnt_progress_bar_set_fraction (GntProgressBar *pbar, gdouble fraction)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
+
+ if (fraction > 1.0)
+ priv->fraction = 1.0;
+ else if (fraction < 0.0)
+ priv->fraction = 0.0;
+ else
+ priv->fraction = fraction;
+
+ if ((GNT_WIDGET_FLAGS(pbar) & GNT_WIDGET_MAPPED))
+ gnt_widget_draw(GNT_WIDGET(pbar));
+}
+
+void
+gnt_progress_bar_set_orientation (GntProgressBar *pbar,
+ GntProgressBarOrientation orientation)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
+ GntWidget *widget = GNT_WIDGET(pbar);
+
+ priv->orientation = orientation;
+ if (orientation == GNT_PROGRESS_LEFT_TO_RIGHT ||
+ orientation == GNT_PROGRESS_RIGHT_TO_LEFT) {
+ GNT_WIDGET_SET_FLAGS(pbar, GNT_WIDGET_GROW_X);
+ GNT_WIDGET_UNSET_FLAGS(pbar, GNT_WIDGET_GROW_Y);
+ widget->priv.minw = 8;
+ widget->priv.minh = 1;
+ } else {
+ GNT_WIDGET_UNSET_FLAGS(pbar, GNT_WIDGET_GROW_X);
+ GNT_WIDGET_SET_FLAGS(pbar, GNT_WIDGET_GROW_Y);
+ widget->priv.minw = 1;
+ widget->priv.minh = 8;
+ }
+
+ if ((GNT_WIDGET_FLAGS(pbar) & GNT_WIDGET_MAPPED))
+ gnt_widget_draw(GNT_WIDGET(pbar));
+}
+
+void
+gnt_progress_bar_set_show_progress (GntProgressBar *pbar, gboolean show)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
+ priv->show_value = show;
+}
+
+gdouble
+gnt_progress_bar_get_fraction (GntProgressBar *pbar)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
+ return priv->fraction;
+}
+
+GntProgressBarOrientation
+gnt_progress_bar_get_orientation (GntProgressBar *pbar)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
+ return priv->orientation;
+}
+
+gboolean
+gnt_progress_bar_get_show_progress (GntProgressBar *pbar)
+{
+ GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
+ return priv->show_value;
+}
+
diff --git a/finch/libgnt/gntprogressbar.h b/finch/libgnt/gntprogressbar.h
new file mode 100644
index 0000000000..fbfd788992
--- /dev/null
+++ b/finch/libgnt/gntprogressbar.h
@@ -0,0 +1,132 @@
+/**
+ * @file gntprogressbar.h Progress Bar API
+ * @ingroup gnt
+ */
+/*
+ * GNT - The GLib Ncurses Toolkit
+ *
+ * GNT is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#ifndef GNT_PROGRESS_BAR_H
+#define GNT_PROGRESS_BAR_H
+
+#include "gnt.h"
+#include "gntwidget.h"
+
+#define GNT_TYPE_PROGRESS_BAR (gnt_progress_bar_get_type ())
+#define GNT_PROGRESS_BAR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNT_TYPE_PROGRESS_BAR, GntProgressBar))
+#define GNT_PROGRESS_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNT_TYPE_PROGRESS_BAR, GntProgressBarClass))
+#define GNT_IS_PROGRESS_BAR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNT_TYPE_PROGRESS_BAR))
+#define GNT_IS_PROGRESS_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNT_TYPE_PROGRESS_BAR))
+#define GNT_PROGRESS_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNT_TYPE_PROGRESS_BAR, GntProgressBarClass))
+
+typedef enum _GntProgressBarOrientation
+{
+ GNT_PROGRESS_LEFT_TO_RIGHT,
+ GNT_PROGRESS_RIGHT_TO_LEFT,
+ GNT_PROGRESS_BOTTOM_TO_TOP,
+ GNT_PROGRESS_TOP_TO_BOTTOM,
+} GntProgressBarOrientation;
+
+typedef struct _GntProgressBar GntProgressBar;
+
+typedef struct _GntProgressBarClass
+{
+ GntWidgetClass parent;
+
+ void (*gnt_reserved1)(void);
+ void (*gnt_reserved2)(void);
+ void (*gnt_reserved3)(void);
+ void (*gnt_reserved4)(void);
+} GntProgressBarClass;
+
+G_BEGIN_DECLS
+
+/**
+ * Get the GType for GntProgressBar
+ * @return The GType for GntProrgressBar
+ **/
+GType
+gnt_progress_bar_get_type (void);
+
+/**
+ * Create a new GntProgressBar
+ * @return The new GntProgressBar
+ **/
+GntWidget *
+gnt_progress_bar_new (void);
+
+/**
+ * Set the progress for a progress bar
+ *
+ * @param pbar The GntProgressBar
+ * @param fraction The value between 0 and 1 to display
+ **/
+void
+gnt_progress_bar_set_fraction (GntProgressBar *pbar, gdouble fraction);
+
+/**
+ * Set the orientation for a progress bar
+ *
+ * @param pbar The GntProgressBar
+ * @param orientation The orientation to use
+ **/
+void
+gnt_progress_bar_set_orientation (GntProgressBar *pbar, GntProgressBarOrientation orientation);
+
+/**
+ * Controls whether the progress value is shown
+ *
+ * @param pbar The GntProgressBar
+ * @param show A boolean indicating if the value is shown
+ **/
+void
+gnt_progress_bar_set_show_progress (GntProgressBar *pbar, gboolean show);
+
+/**
+ * Get the progress that is displayed
+ *
+ * @param pbar The GntProgressBar
+ * @return The progress displayed as a value between 0 and 1
+ **/
+gdouble
+gnt_progress_bar_get_fraction (GntProgressBar *pbar);
+
+/**
+ * Get the orientation for the progress bar
+ *
+ * @param pbar The GntProgressBar
+ * @return The current orientation of the progress bar
+ **/
+GntProgressBarOrientation
+gnt_progress_bar_get_orientation (GntProgressBar *pbar);
+
+/**
+ * Get a boolean describing if the progress value is shown
+ *
+ * @param pbar The GntProgressBar
+ * @return A boolean @c true if the progress value is shown, @c false otherwise.
+ **/
+gboolean
+gnt_progress_bar_get_show_progress (GntProgressBar *pbar);
+
+G_END_DECLS
+
+#endif /* GNT_PROGRESS_BAR_H */