[Xfce4-commits] r25390 - in squeeze/trunk: libsqueeze src
Stephan Arts
stephan at xfce.org
Thu Apr 5 17:35:40 CEST 2007
Author: stephan
Date: 2007-04-05 15:35:40 +0000 (Thu, 05 Apr 2007)
New Revision: 25390
Added:
squeeze/trunk/src/throbber-fallback.h
squeeze/trunk/src/throbber-fallback.png
squeeze/trunk/src/throbber.c
squeeze/trunk/src/throbber.h
Modified:
squeeze/trunk/libsqueeze/archive-iter.c
squeeze/trunk/src/Makefile.am
squeeze/trunk/src/archive_store.c
squeeze/trunk/src/main_window.c
squeeze/trunk/src/main_window.h
Log:
Added throbber to squeeze (borrowed it from thunar)
Modified: squeeze/trunk/libsqueeze/archive-iter.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-iter.c 2007-04-05 13:41:23 UTC (rev 25389)
+++ squeeze/trunk/libsqueeze/archive-iter.c 2007-04-05 15:35:40 UTC (rev 25390)
@@ -495,7 +495,7 @@
GSList *back_stack = NULL;
GSList *back_iter;
const LSQArchiveIter *parent = iter;
- while(parent)
+ while(parent != NULL)
{
back_stack = g_slist_prepend(back_stack, (gpointer)parent);
parent = parent->parent;
Modified: squeeze/trunk/src/Makefile.am
===================================================================
--- squeeze/trunk/src/Makefile.am 2007-04-05 13:41:23 UTC (rev 25389)
+++ squeeze/trunk/src/Makefile.am 2007-04-05 15:35:40 UTC (rev 25390)
@@ -24,6 +24,8 @@
settings.c settings.h \
archive_store.c archive_store.h \
message_dialog.c message_dialog.h \
+ throbber-fallback.c throbber-fallback.h \
+ throbber.c throbber.h \
new_dialog.c new_dialog.h \
add_dialog.c add_dialog.h \
extract_dialog.c extract_dialog.h \
@@ -47,8 +49,11 @@
@DBUS_LIBS@ \
@THUNAR_VFS_LIBS@
-# squeeze_LDFLAGS = -static
+squeeze_LDFLAGS = -static
INCLUDES = \
-I${top_srcdir}
+
+throbber-fallback.c: $(srcdir)/throbber-fallback.png Makefile
+ (echo "#include \"throbber-fallback.h\"" && gdk-pixbuf-csource --extern --raw --stream --name=sq_throbber_fallback $(srcdir)/throbber-fallback.png) > throbber-fallback.c
Modified: squeeze/trunk/src/archive_store.c
===================================================================
--- squeeze/trunk/src/archive_store.c 2007-04-05 13:41:23 UTC (rev 25389)
+++ squeeze/trunk/src/archive_store.c 2007-04-05 15:35:40 UTC (rev 25390)
@@ -1574,14 +1574,8 @@
SQArchiveStore *store = SQ_ARCHIVE_STORE(object);
if(store->archive)
{
- GList *list_iter;
- for(list_iter = store->navigation.history; list_iter; list_iter = list_iter->next)
- lsq_archive_iter_unref(list_iter->data);
+ g_signal_handlers_disconnect_by_func(store->archive, cb_sq_archive_store_archive_refreshed, store);
- g_list_free(store->navigation.history);
- if(store->navigation.trailing)
- lsq_archive_iter_unref(store->navigation.trailing);
-
g_object_unref(store->archive);
store->archive = NULL;
}
Modified: squeeze/trunk/src/main_window.c
===================================================================
--- squeeze/trunk/src/main_window.c 2007-04-05 13:41:23 UTC (rev 25389)
+++ squeeze/trunk/src/main_window.c 2007-04-05 15:35:40 UTC (rev 25390)
@@ -56,6 +56,7 @@
#include "notebook.h"
#include "application.h"
#include "main_window.h"
+#include "throbber.h"
#include "new_dialog.h"
#include "extract_dialog.h"
@@ -387,6 +388,17 @@
gtk_menu_bar_append(GTK_MENU_BAR(window->menu_bar), window->menubar.menu_item_action);
gtk_menu_bar_append(GTK_MENU_BAR(window->menu_bar), window->menubar.menu_item_view);
gtk_menu_bar_append(GTK_MENU_BAR(window->menu_bar), window->menubar.menu_item_help);
+
+ GtkMenuItem *item = gtk_menu_item_new ();
+ gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
+ gtk_menu_item_set_right_justified (GTK_MENU_ITEM (item), TRUE);
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->menu_bar), item);
+ gtk_widget_show (item);
+
+ window->throbber = sq_throbber_new ();
+ gtk_container_add (GTK_CONTAINER (item), window->throbber);
+ gtk_widget_show (window->throbber);
+
}
show_toolbar = sq_settings_read_bool_entry(window->settings, "ToolBar", TRUE);
@@ -1238,6 +1250,7 @@
const gchar *message = lsq_archive_get_status(archive);
if(!message)
{
+ sq_throbber_set_animated(window->throbber, FALSE);
message = _("Done");
if(window->menu_bar)
{
@@ -1261,6 +1274,7 @@
if(window->menu_bar)
{
+ sq_throbber_set_animated(window->throbber, TRUE);
gtk_widget_set_sensitive(window->menubar.menu_item_add, FALSE);
gtk_widget_set_sensitive(window->menubar.menu_item_extract, FALSE);
gtk_widget_set_sensitive(window->menubar.menu_item_remove, FALSE);
Modified: squeeze/trunk/src/main_window.h
===================================================================
--- squeeze/trunk/src/main_window.h 2007-04-05 13:41:23 UTC (rev 25389)
+++ squeeze/trunk/src/main_window.h 2007-04-05 15:35:40 UTC (rev 25390)
@@ -72,6 +72,7 @@
GtkWidget *tool_bar;
GtkWidget *main_vbox;
SQWidgetFactory *widget_factory;
+ GtkWidget *throbber;
struct {
/* 'file' menu */
GtkWidget *menu_item_file;
Added: squeeze/trunk/src/throbber-fallback.h
===================================================================
--- squeeze/trunk/src/throbber-fallback.h (rev 0)
+++ squeeze/trunk/src/throbber-fallback.h 2007-04-05 15:35:40 UTC (rev 25390)
@@ -0,0 +1,32 @@
+/*-
+ * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>
+ *
+ * Modified by Stephan Arts <stephan at xfce.org>
+ *
+ * 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 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __THUNAR_THROBBER_FALLBACK_H__
+#define __THUNAR_THROBBER_FALLBACK_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS;
+
+extern const guint8 sq_throbber_fallback[];
+
+G_END_DECLS;
+
+#endif /* !__THUNAR_THROBBER_FALLBACK_H__ */
Added: squeeze/trunk/src/throbber-fallback.png
===================================================================
(Binary files differ)
Property changes on: squeeze/trunk/src/throbber-fallback.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: squeeze/trunk/src/throbber.c
===================================================================
--- squeeze/trunk/src/throbber.c (rev 0)
+++ squeeze/trunk/src/throbber.c 2007-04-05 15:35:40 UTC (rev 25390)
@@ -0,0 +1,404 @@
+/*-
+ * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ *
+ * Modified by Stephan Arts <stephan at xfce.org>
+ *
+ * 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 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <exo/exo.h>
+
+#include "throbber.h"
+#include "throbber-fallback.h"
+
+
+
+/* Property identifiers */
+enum
+{
+ PROP_0,
+ PROP_ANIMATED,
+};
+
+
+
+static void sq_throbber_class_init (SQThrobberClass *klass);
+static void sq_throbber_init (SQThrobber *throbber);
+static void sq_throbber_dispose (GObject *object);
+static void sq_throbber_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void sq_throbber_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void sq_throbber_realize (GtkWidget *widget);
+static void sq_throbber_unrealize (GtkWidget *widget);
+static void sq_throbber_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static gboolean sq_throbber_expose_event (GtkWidget *widget,
+ GdkEventExpose *event);
+static gboolean sq_throbber_timer (gpointer user_data);
+static void sq_throbber_timer_destroy (gpointer user_data);
+
+
+
+struct _SQThrobberClass
+{
+ GtkWidgetClass __parent__;
+};
+
+struct _SQThrobber
+{
+ GtkWidget __parent__;
+
+ GdkPixbuf *icon;
+
+ gboolean animated;
+ gint index;
+ gint timer_id;
+};
+
+
+
+static GObjectClass *sq_throbber_parent_class;
+
+
+
+GType
+sq_throbber_get_type (void)
+{
+ static GType type = G_TYPE_INVALID;
+
+ if (G_UNLIKELY (type == G_TYPE_INVALID))
+ {
+ static const GTypeInfo info =
+ {
+ sizeof (SQThrobberClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) sq_throbber_class_init,
+ NULL,
+ NULL,
+ sizeof (SQThrobber),
+ 0,
+ (GInstanceInitFunc) sq_throbber_init,
+ NULL,
+ };
+
+ type = g_type_register_static (GTK_TYPE_WIDGET, I_("SQThrobber"), &info, 0);
+ }
+
+ return type;
+}
+
+
+
+static void
+sq_throbber_class_init (SQThrobberClass *klass)
+{
+ GtkWidgetClass *gtkwidget_class;
+ GObjectClass *gobject_class;
+ GdkPixbuf *icon;
+
+ /* determine the parent type class */
+ sq_throbber_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->dispose = sq_throbber_dispose;
+ gobject_class->get_property = sq_throbber_get_property;
+ gobject_class->set_property = sq_throbber_set_property;
+
+ gtkwidget_class = GTK_WIDGET_CLASS (klass);
+ gtkwidget_class->realize = sq_throbber_realize;
+ gtkwidget_class->unrealize = sq_throbber_unrealize;
+ gtkwidget_class->size_request = sq_throbber_size_request;
+ gtkwidget_class->expose_event = sq_throbber_expose_event;
+
+ /**
+ * SQThrobber:animated:
+ *
+ * Whether the throbber should display an animation.
+ **/
+ g_object_class_install_property (gobject_class,
+ PROP_ANIMATED,
+ g_param_spec_boolean ("animated",
+ "animated",
+ "animated",
+ FALSE,
+ EXO_PARAM_READWRITE));
+
+ /* register the "process-working" fallback icon */
+ icon = gdk_pixbuf_new_from_inline (-1, sq_throbber_fallback, FALSE, NULL);
+ gtk_icon_theme_add_builtin_icon ("process-working", 16, icon);
+ g_object_unref (G_OBJECT (icon));
+}
+
+
+
+static void
+sq_throbber_init (SQThrobber *throbber)
+{
+ GTK_WIDGET_SET_FLAGS (throbber, GTK_NO_WINDOW);
+ throbber->timer_id = -1;
+}
+
+
+
+static void
+sq_throbber_dispose (GObject *object)
+{
+ SQThrobber *throbber = SQ_THROBBER (object);
+
+ /* stop any running animation */
+ if (G_UNLIKELY (throbber->timer_id >= 0))
+ g_source_remove (throbber->timer_id);
+
+ (*G_OBJECT_CLASS (sq_throbber_parent_class)->dispose) (object);
+}
+
+
+
+static void
+sq_throbber_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ SQThrobber *throbber = SQ_THROBBER (object);
+
+ switch (prop_id)
+ {
+ case PROP_ANIMATED:
+ g_value_set_boolean (value, sq_throbber_get_animated (throbber));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+sq_throbber_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ SQThrobber *throbber = SQ_THROBBER (object);
+
+ switch (prop_id)
+ {
+ case PROP_ANIMATED:
+ sq_throbber_set_animated (throbber, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+sq_throbber_realize (GtkWidget *widget)
+{
+ SQThrobber *throbber = SQ_THROBBER (widget);
+ GtkIconTheme *icon_theme;
+
+ /* let Gtk+ realize the widget */
+ (*GTK_WIDGET_CLASS (sq_throbber_parent_class)->realize) (widget);
+
+ /* determine the icon theme for our screen */
+ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
+
+ /* try to lookup the "process-working" icon */
+ throbber->icon = gtk_icon_theme_load_icon (icon_theme, "process-working", 16, GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_NO_SVG, NULL);
+}
+
+
+
+static void
+sq_throbber_unrealize (GtkWidget *widget)
+{
+ SQThrobber *throbber = SQ_THROBBER (widget);
+
+ /* release the icon if any */
+ if (G_LIKELY (throbber->icon != NULL))
+ {
+ g_object_unref (G_OBJECT (throbber->icon));
+ throbber->icon = NULL;
+ }
+
+ /* let Gtk+ unrealize the widget */
+ (*GTK_WIDGET_CLASS (sq_throbber_parent_class)->unrealize) (widget);
+}
+
+
+
+static void
+sq_throbber_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ requisition->width = 16;
+ requisition->height = 16;
+}
+
+
+
+static gboolean
+sq_throbber_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ SQThrobber *throbber = SQ_THROBBER (widget);
+ gint icon_index;
+ gint icon_cols;
+ gint icon_rows;
+ gint icon_x;
+ gint icon_y;
+
+ /* verify that we have a valid icon */
+ if (G_LIKELY (throbber->icon != NULL))
+ {
+ /* determine the icon columns and icon rows */
+ icon_cols = gdk_pixbuf_get_width (throbber->icon) / 16;
+ icon_rows = gdk_pixbuf_get_height (throbber->icon) / 16;
+
+ /* verify that the icon is usable */
+ if (G_LIKELY (icon_cols > 0 && icon_rows > 0))
+ {
+ /* determine the icon index */
+ icon_index = throbber->index % (icon_cols * icon_rows);
+
+ /* make sure, we don't display the "empty state" while animated */
+ if (G_LIKELY (throbber->timer_id >= 0))
+ icon_index = MAX (icon_index, 1);
+
+ /* determine the icon x/y offset for the icon index */
+ icon_x = (icon_index % icon_cols) * 16;
+ icon_y = (icon_index / icon_cols) * 16;
+
+ /* render the given part of the icon */
+ gdk_draw_pixbuf (event->window, NULL, throbber->icon, icon_x, icon_y,
+ widget->allocation.x, widget->allocation.y,
+ 16, 16, GDK_RGB_DITHER_NONE, 0, 0);
+ }
+ }
+
+ return TRUE;
+}
+
+
+
+static gboolean
+sq_throbber_timer (gpointer user_data)
+{
+ SQThrobber *throbber = SQ_THROBBER (user_data);
+
+ GDK_THREADS_ENTER ();
+ throbber->index += 1;
+ gtk_widget_queue_draw (GTK_WIDGET (throbber));
+ GDK_THREADS_LEAVE ();
+
+ return throbber->animated;
+}
+
+
+
+static void
+sq_throbber_timer_destroy (gpointer user_data)
+{
+ SQ_THROBBER (user_data)->index = 0;
+ SQ_THROBBER (user_data)->timer_id = -1;
+}
+
+
+
+/**
+ * sq_throbber_new:
+ *
+ * Allocates a new #SQThrobber instance.
+ *
+ * Return value: the newly allocated #SQThrobber.
+ **/
+GtkWidget*
+sq_throbber_new (void)
+{
+ return g_object_new (SQ_TYPE_THROBBER, NULL);
+}
+
+
+
+/**
+ * sq_throbber_get_animated:
+ * @throbber : a #SQThrobber.
+ *
+ * Returns whether @throbber is currently animated.
+ *
+ * Return value: %TRUE if @throbber is animated.
+ **/
+gboolean
+sq_throbber_get_animated (const SQThrobber *throbber)
+{
+ g_return_val_if_fail (SQ_IS_THROBBER (throbber), FALSE);
+ return throbber->animated;
+}
+
+
+
+/**
+ * sq_throbber_set_animated:
+ * @throbber : a #SQThrobber.
+ * @animated : whether to animate @throbber.
+ *
+ * If @animated is %TRUE, @throbber will display an animation.
+ **/
+void
+sq_throbber_set_animated (SQThrobber *throbber,
+ gboolean animated)
+{
+ g_return_if_fail (SQ_IS_THROBBER (throbber));
+
+ /* check if we're already in the requested state */
+ if (G_UNLIKELY (throbber->animated == animated))
+ return;
+
+ /* pick up the new state */
+ throbber->animated = animated;
+
+ /* start the timer if animated and not already running */
+ if (animated && (throbber->timer_id < 0))
+ {
+ /* start the animation */
+ throbber->timer_id = g_timeout_add_full (G_PRIORITY_LOW, 25, sq_throbber_timer,
+ throbber, sq_throbber_timer_destroy);
+ }
+
+ /* schedule a redraw with the new animation state */
+ gtk_widget_queue_draw (GTK_WIDGET (throbber));
+
+ /* notify listeners */
+ g_object_notify (G_OBJECT (throbber), "animated");
+}
+
+
Added: squeeze/trunk/src/throbber.h
===================================================================
--- squeeze/trunk/src/throbber.h (rev 0)
+++ squeeze/trunk/src/throbber.h 2007-04-05 15:35:40 UTC (rev 25390)
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ *
+ * Modified by Stephan Arts <stephan at xfce.org>
+ *
+ * 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 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __SQ_THROBBER_H__
+#define __SQ_THROBBER_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS;
+
+typedef struct _SQThrobberClass SQThrobberClass;
+typedef struct _SQThrobber SQThrobber;
+
+#define SQ_TYPE_THROBBER (sq_throbber_get_type ())
+#define SQ_THROBBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SQ_TYPE_THROBBER, SQThrobber))
+#define SQ_THROBBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SQ_TYPE_THROBBER, SQThrobberClass))
+#define SQ_IS_THROBBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQ_TYPE_THROBBER))
+#define SQ_IS_THROBBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SQ_TYPE_THROBBER))
+#define SQ_THROBBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SQ_TYPE_THROBBER, SQThrobberClass))
+
+GType sq_throbber_get_type (void) G_GNUC_CONST;
+
+GtkWidget *sq_throbber_new (void) G_GNUC_MALLOC;
+
+gboolean sq_throbber_get_animated (const SQThrobber *throbber);
+void sq_throbber_set_animated (SQThrobber *throbber,
+ gboolean animated);
+
+G_END_DECLS;
+
+#endif /* !__SQ_THROBBER_H__ */
More information about the Xfce4-commits
mailing list