[gnome-power-manager] Remove the single use abstract GpmRefcount and use a local timer
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-power-manager] Remove the single use abstract GpmRefcount and use a local timer
- Date: Wed, 6 May 2009 11:36:46 -0400 (EDT)
commit 5b108b8352c878322933700789669efd86a0bb08
Author: Richard Hughes <richard hughsie com>
Date: Wed May 6 15:33:00 2009 +0100
Remove the single use abstract GpmRefcount and use a local timer
---
src/Makefile.am | 2 -
src/gpm-feedback-widget.c | 37 ++++----
src/gpm-refcount.c | 229 ---------------------------------------------
src/gpm-refcount.h | 61 ------------
4 files changed, 17 insertions(+), 312 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index a18cc0b..2d1370c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -165,8 +165,6 @@ gnome_power_manager_SOURCES = \
gpm-load.c \
gpm-control.h \
gpm-control.c \
- gpm-refcount.h \
- gpm-refcount.c \
gpm-button.h \
gpm-button.c \
gpm-brightness.h \
diff --git a/src/gpm-feedback-widget.c b/src/gpm-feedback-widget.c
index f71ad91..abaf567 100644
--- a/src/gpm-feedback-widget.c
+++ b/src/gpm-feedback-widget.c
@@ -29,7 +29,6 @@
#include "gpm-feedback-widget.h"
#include "gpm-stock-icons.h"
-#include "gpm-refcount.h"
#include "egg-debug.h"
static void gpm_feedback_finalize (GObject *object);
@@ -44,7 +43,7 @@ struct GpmFeedbackPrivate
GladeXML *xml;
GtkWidget *main_window;
GtkWidget *progress;
- GpmRefcount *refcount;
+ guint timer_id;
gchar *icon_name;
};
@@ -119,16 +118,18 @@ gpm_feedback_show (GtkWidget *widget)
/**
* gpm_feedback_close_window:
- * @data: gpointer to this class instance
**/
static void
-gpm_feedback_close_window (GpmRefcount *refcount,
- GpmFeedback *feedback)
+gpm_feedback_close_window (GpmFeedback *feedback)
{
+ g_return_if_fail (GPM_IS_FEEDBACK (feedback));
egg_debug ("Closing feedback widget");
gtk_widget_hide (feedback->priv->main_window);
}
+/**
+ * gpm_feedback_display_value:
+ **/
gboolean
gpm_feedback_display_value (GpmFeedback *feedback, gfloat value)
{
@@ -139,12 +140,16 @@ gpm_feedback_display_value (GpmFeedback *feedback, gfloat value)
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (feedback->priv->progress), value);
gpm_feedback_show (feedback->priv->main_window);
- /* set up the window auto-close */
- gpm_refcount_add (feedback->priv->refcount);
+ if (feedback->priv->timer_id != 0)
+ g_source_remove (feedback->priv->timer_id);
+ feedback->priv->timer_id = g_timeout_add_seconds (GPM_FEEDBACK_TIMOUT, (GSourceFunc) gpm_feedback_close_window, feedback);
return TRUE;
}
+/**
+ * gpm_feedback_set_icon_name:
+ **/
gboolean
gpm_feedback_set_icon_name (GpmFeedback *feedback, const gchar *icon_name)
{
@@ -155,17 +160,14 @@ gpm_feedback_set_icon_name (GpmFeedback *feedback, const gchar *icon_name)
g_return_val_if_fail (icon_name != NULL, FALSE);
/* if name already set then free */
- if (feedback->priv->icon_name != NULL) {
+ if (feedback->priv->icon_name != NULL)
g_free (feedback->priv->icon_name);
- }
egg_debug ("Using icon name '%s'", icon_name);
feedback->priv->icon_name = g_strdup (icon_name);
image = glade_xml_get_widget (feedback->priv->xml, "image");
- gtk_image_set_from_icon_name (GTK_IMAGE (image),
- feedback->priv->icon_name,
- GTK_ICON_SIZE_DIALOG);
+ gtk_image_set_from_icon_name (GTK_IMAGE (image), feedback->priv->icon_name, GTK_ICON_SIZE_DIALOG);
return TRUE;
}
@@ -178,14 +180,9 @@ static void
gpm_feedback_init (GpmFeedback *feedback)
{
feedback->priv = GPM_FEEDBACK_GET_PRIVATE (feedback);
- feedback->priv->refcount = 0;
+ feedback->priv->timer_id = 0;
feedback->priv->icon_name = NULL;
- feedback->priv->refcount = gpm_refcount_new ();
- g_signal_connect (feedback->priv->refcount, "refcount-zero",
- G_CALLBACK (gpm_feedback_close_window), feedback);
- gpm_refcount_set_timeout (feedback->priv->refcount, GPM_FEEDBACK_TIMOUT);
-
/* initialise the window */
feedback->priv->xml = glade_xml_new (GPM_DATA "/gpm-feedback-widget.glade", NULL, NULL);
if (feedback->priv->xml == NULL)
@@ -215,8 +212,8 @@ gpm_feedback_finalize (GObject *object)
feedback->priv = GPM_FEEDBACK_GET_PRIVATE (feedback);
g_free (feedback->priv->icon_name);
- if (feedback->priv->refcount != NULL)
- g_object_unref (feedback->priv->refcount);
+ if (feedback->priv->timer_id != 0)
+ g_source_remove (feedback->priv->timer_id);
G_OBJECT_CLASS (gpm_feedback_parent_class)->finalize (object);
}
diff --git a/src/gpm-refcount.c b/src/gpm-refcount.c
deleted file mode 100644
index ccb1928..0000000
--- a/src/gpm-refcount.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2006-2007 Richard Hughes <richard hughsie com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include "gpm-refcount.h"
-#include "egg-debug.h"
-
-static void gpm_refcount_finalize (GObject *object);
-
-#define GPM_REFCOUNT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_REFCOUNT, GpmRefcountPrivate))
-
-/* this is a managed refcounter */
-
-struct GpmRefcountPrivate
-{
- guint timeout; /* s */
- guint refcount;
-};
-
-enum {
- REFCOUNT_ADDED,
- REFCOUNT_ZERO,
- LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (GpmRefcount, gpm_refcount, G_TYPE_OBJECT)
-
-/**
- * gpm_refcount_auto_decrement:
- * @data: gpointer to this class instance
- *
- * Called automatically to clear one of the refcounts
- **/
-static gboolean
-gpm_refcount_auto_decrement (gpointer data)
-{
- GpmRefcount *refcount = (GpmRefcount*) data;
-
- if (refcount->priv->refcount == 0) {
- egg_warning ("no refcount to remove");
- return FALSE;
- }
-
- refcount->priv->refcount--;
-
- if (refcount->priv->refcount == 0) {
- egg_debug ("zero, so sending REFCOUNT_ZERO");
- g_signal_emit (refcount, signals [REFCOUNT_ZERO], 0);
- } else {
- egg_debug ("refcount now: %i", refcount->priv->refcount);
- }
-
- return FALSE;
-}
-
-/**
- * gpm_refcount_add:
- * @refcount: This class instance
- * Return value: success
- **/
-gboolean
-gpm_refcount_add (GpmRefcount *refcount)
-{
- g_return_val_if_fail (refcount != NULL, FALSE);
- g_return_val_if_fail (GPM_IS_REFCOUNT (refcount), FALSE);
-
- if (refcount->priv->timeout == 0) {
- egg_warning ("no timeout has been set");
- return FALSE;
- }
-
- refcount->priv->refcount++;
- egg_debug ("refcount now: %i", refcount->priv->refcount);
- egg_debug ("non zero, so sending REFCOUNT_ADDED");
- g_signal_emit (refcount, signals [REFCOUNT_ADDED], 0);
-
- /* remove the last timeout */
- g_idle_remove_by_data (refcount);
-
- /* add ONE automatic timeout */
- g_timeout_add_seconds (refcount->priv->timeout, gpm_refcount_auto_decrement, refcount);
-
- return TRUE;
-}
-
-/**
- * gpm_refcount_remove:
- * @refcount: This class instance
- * Return value: success
- *
- * Not normally required, but removes a refcount manually.
- **/
-gboolean
-gpm_refcount_remove (GpmRefcount *refcount)
-{
- g_return_val_if_fail (refcount != NULL, FALSE);
- g_return_val_if_fail (GPM_IS_REFCOUNT (refcount), FALSE);
-
- if (refcount->priv->refcount == 0) {
- egg_warning ("no refcount to remove");
- return FALSE;
- }
-
- /* BUG? we should clear the timeout also */
- return gpm_refcount_auto_decrement (refcount);
-}
-
-/**
- * gpm_refcount_set_timeout:
- * @refcount: This class instance
- * @timeout: seconds
- * Return value: success
- **/
-gboolean
-gpm_refcount_set_timeout (GpmRefcount *refcount, guint timeout)
-{
- g_return_val_if_fail (refcount != NULL, FALSE);
- g_return_val_if_fail (GPM_IS_REFCOUNT (refcount), FALSE);
-
- if (timeout > 1000) {
- egg_warning ("refcount is not designed for long timeouts");
- return FALSE;
- }
- if (timeout == 0) {
- egg_warning ("refcount cannot be zero");
- timeout = 1; /* seconds */
- }
-
- refcount->priv->timeout = timeout;
- return TRUE;
-}
-
-/**
- * gpm_refcount_class_init:
- * @refcount: This class instance
- **/
-static void
-gpm_refcount_class_init (GpmRefcountClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gpm_refcount_finalize;
- g_type_class_add_private (klass, sizeof (GpmRefcountPrivate));
-
- signals [REFCOUNT_ADDED] =
- g_signal_new ("refcount-added",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmRefcountClass, refcount_added),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals [REFCOUNT_ZERO] =
- g_signal_new ("refcount-zero",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmRefcountClass, refcount_zero),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-}
-
-/**
- * gpm_refcount_init:
- * @refcount: This class instance
- **/
-static void
-gpm_refcount_init (GpmRefcount *refcount)
-{
- refcount->priv = GPM_REFCOUNT_GET_PRIVATE (refcount);
-
- refcount->priv->refcount = 0;
- refcount->priv->timeout = 0;
-}
-
-/**
- * gpm_refcount_finalize:
- * @object: This class instance
- **/
-static void
-gpm_refcount_finalize (GObject *object)
-{
- GpmRefcount *refcount;
- g_return_if_fail (object != NULL);
- g_return_if_fail (GPM_IS_REFCOUNT (object));
-
- refcount = GPM_REFCOUNT (object);
- refcount->priv = GPM_REFCOUNT_GET_PRIVATE (refcount);
- /* emit signal ? */
- G_OBJECT_CLASS (gpm_refcount_parent_class)->finalize (object);
-}
-
-/**
- * gpm_refcount_new:
- * Return value: new class instance.
- **/
-GpmRefcount *
-gpm_refcount_new (void)
-{
- GpmRefcount *refcount;
- refcount = g_object_new (GPM_TYPE_REFCOUNT, NULL);
- return GPM_REFCOUNT (refcount);
-}
diff --git a/src/gpm-refcount.h b/src/gpm-refcount.h
deleted file mode 100644
index 409964a..0000000
--- a/src/gpm-refcount.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2006-2007 Richard Hughes <richard hughsie com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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 __GPMREFCOUNT_H
-#define __GPMREFCOUNT_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define GPM_TYPE_REFCOUNT (gpm_refcount_get_type ())
-#define GPM_REFCOUNT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_REFCOUNT, GpmRefcount))
-#define GPM_REFCOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_REFCOUNT, GpmRefcountClass))
-#define GPM_IS_REFCOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_REFCOUNT))
-#define GPM_IS_REFCOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_REFCOUNT))
-#define GPM_REFCOUNT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_REFCOUNT, GpmRefcountClass))
-
-typedef struct GpmRefcountPrivate GpmRefcountPrivate;
-
-typedef struct
-{
- GObject parent;
- GpmRefcountPrivate *priv;
-} GpmRefcount;
-
-typedef struct
-{
- GObjectClass parent_class;
- void (* refcount_zero) (GpmRefcount *refcount);
- void (* refcount_added) (GpmRefcount *refcount);
-} GpmRefcountClass;
-
-GType gpm_refcount_get_type (void);
-GpmRefcount *gpm_refcount_new (void);
-
-gboolean gpm_refcount_add (GpmRefcount *refcount);
-gboolean gpm_refcount_remove (GpmRefcount *refcount);
-gboolean gpm_refcount_set_timeout (GpmRefcount *refcount,
- guint timeout);
-
-G_END_DECLS
-
-#endif /* __GPMREFCOUNT_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]