gnome-panel r11404 - in trunk/gnome-panel: . libpanel-util



Author: vuntz
Date: Wed Dec 10 02:33:39 2008
New Revision: 11404
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11404&view=rev

Log:
2008-12-10  Vincent Untz  <vuntz gnome org>

	* panel-util.[ch]: move all panel_g_(s)list functions to...
	* libpanel-util/panel-list.[ch]: ... here (new files)
	* libpanel-util/Makefile.am: add new file
	* panel-profile.c:
	* panel-widget.c: include panel-list.h


Added:
   trunk/gnome-panel/libpanel-util/panel-list.c
   trunk/gnome-panel/libpanel-util/panel-list.h
Modified:
   trunk/gnome-panel/ChangeLog
   trunk/gnome-panel/libpanel-util/Makefile.am
   trunk/gnome-panel/panel-profile.c
   trunk/gnome-panel/panel-util.c
   trunk/gnome-panel/panel-util.h
   trunk/gnome-panel/panel-widget.c

Modified: trunk/gnome-panel/libpanel-util/Makefile.am
==============================================================================
--- trunk/gnome-panel/libpanel-util/Makefile.am	(original)
+++ trunk/gnome-panel/libpanel-util/Makefile.am	Wed Dec 10 02:33:39 2008
@@ -30,6 +30,8 @@
 	panel-glib.h			\
 	panel-keyfile.c			\
 	panel-keyfile.h			\
+	panel-list.c			\
+	panel-list.h			\
 	panel-power-manager.c		\
 	panel-power-manager.h		\
 	panel-session-manager.c		\

Added: trunk/gnome-panel/libpanel-util/panel-list.c
==============================================================================
--- (empty file)
+++ trunk/gnome-panel/libpanel-util/panel-list.c	Wed Dec 10 02:33:39 2008
@@ -0,0 +1,203 @@
+/*
+ * panel-list.c: GList & GSList extensions
+ *
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * Originally based on code from panel-util.c (there was no relevant copyright
+ * header at the time), but the code was:
+ * Copyright (C) Mark McLoughlin <mark skynet ie>
+ *
+ * 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.
+ *
+ * Authors:
+ *	Vincent Untz <vuntz gnome org>
+ */
+
+#include <glib.h>
+
+#include "panel-list.h"
+
+GList *
+panel_g_list_insert_before (GList *list,
+			    GList *sibling,
+			    GList *link)
+{
+	if (!list) {
+		g_return_val_if_fail (sibling == NULL, list);
+		return link;
+	} else if (sibling) {
+		if (sibling->prev) {
+			link->prev = sibling->prev;
+			link->prev->next = link;
+			link->next = sibling;
+			sibling->prev = link;
+			return list;
+		} else {
+			link->next = sibling;
+			sibling->prev = link;
+			g_return_val_if_fail (sibling == list, link);
+			return link;
+		}
+	} else {
+		GList *last;
+
+		last = list;
+		while (last->next)
+			last = last->next;
+
+		last->next = link;
+		link->prev = last;
+		return list;
+	}
+}
+
+GList *
+panel_g_list_insert_after (GList *list,
+			   GList *sibling,
+			   GList *link)
+{
+	if (!list) {
+		g_return_val_if_fail (sibling == NULL, link);
+		return link;
+	} else if (sibling) {
+		if (sibling->next) {
+			link->next = sibling->next;
+			link->next->prev = link;
+			link->prev = sibling;
+			sibling->next = link;
+			return list;
+		} else {
+			sibling->next = link;
+			link->prev = sibling;
+			return list;
+		}
+			
+	} else {
+		link->next = list;
+		list->prev = link;
+		return link;
+	}
+}
+
+GList *
+panel_g_list_swap_next (GList *list,
+			GList *dl)
+{
+	GList *t;
+
+	if (!dl->next)
+		return list;
+
+	if (dl->prev)
+		dl->prev->next = dl->next;
+	t = dl->prev;
+	dl->prev = dl->next;
+	dl->next->prev = t;
+	if (dl->next->next)
+		dl->next->next->prev = dl;
+	t = dl->next->next;
+	dl->next->next = dl;
+	dl->next = t;
+
+	if (list == dl)
+		return dl->prev;
+
+	return list;
+}
+
+GList *
+panel_g_list_swap_prev (GList *list,
+			GList *dl)
+{
+	GList *t;
+
+	if (!dl->prev)
+		return list;
+
+	if (dl->next)
+		dl->next->prev = dl->prev;
+	t = dl->next;
+	dl->next = dl->prev;
+	dl->prev->next = t;
+	if (dl->prev->prev)
+		dl->prev->prev->next = dl;
+	t = dl->prev->prev;
+	dl->prev->prev = dl;
+	dl->prev = t;
+
+	if (list == dl->next)
+		return dl;
+
+	return list;
+}
+
+/*maybe this should be a glib function?
+ it resorts a single item in the list*/
+GList *
+panel_g_list_resort_item (GList        *list,
+			  gpointer      data,
+			  GCompareFunc  func)
+{
+	GList *dl;
+
+	if (!list)
+		return NULL;
+
+	dl = g_list_find (list,data);
+
+	g_return_val_if_fail (dl != NULL, list);
+
+	while (dl->next &&
+	       (*func)(dl->data, dl->next->data) > 0)
+		list = panel_g_list_swap_next (list, dl);
+	while (dl->prev &&
+	       (*func) (dl->data, dl->prev->data) < 0)
+		list = panel_g_list_swap_prev (list, dl);
+
+	return list;
+}
+
+GSList *
+panel_g_slist_make_unique (GSList       *list,
+			   GCompareFunc  compare,
+			   gboolean      free_data)
+{
+	GSList *sorted, *l;
+
+	g_assert (compare != NULL);
+
+	if (!list)
+		return NULL;
+
+	sorted = g_slist_copy (list);
+	sorted = g_slist_sort (sorted, compare);
+
+	for (l = sorted; l; l = l->next) {
+		GSList *next;
+
+		next = l->next;
+		if (l->data && next && next->data)
+			if (!compare (l->data, next->data)) {
+				list = g_slist_remove (list, l->data);
+				if (free_data)
+					g_free (l->data);
+			}
+	}
+
+	g_slist_free (sorted);
+
+	return list;
+}

Added: trunk/gnome-panel/libpanel-util/panel-list.h
==============================================================================
--- (empty file)
+++ trunk/gnome-panel/libpanel-util/panel-list.h	Wed Dec 10 02:33:39 2008
@@ -0,0 +1,52 @@
+/*
+ * panel-list.h: GList & GSList extensions
+ *
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ *	Vincent Untz <vuntz gnome org>
+ */
+
+#ifndef PANEL_LIST_H
+#define PANEL_LIST_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+GList *panel_g_list_insert_before (GList        *list,
+				   GList        *sibling,
+				   GList        *link);
+GList *panel_g_list_insert_after  (GList        *list,
+				   GList        *sibling,
+				   GList        *link);
+GList *panel_g_list_swap_next     (GList        *list,
+				   GList        *dl);
+GList *panel_g_list_swap_prev     (GList        *list,
+				   GList        *dl);
+GList *panel_g_list_resort_item   (GList        *list,
+				   gpointer      data,
+				   GCompareFunc  func);
+
+GSList *panel_g_slist_make_unique (GSList       *list,
+				   GCompareFunc  compare,
+				   gboolean      free_data);
+
+G_END_DECLS
+
+#endif /* PANEL_LIST_H */

Modified: trunk/gnome-panel/panel-profile.c
==============================================================================
--- trunk/gnome-panel/panel-profile.c	(original)
+++ trunk/gnome-panel/panel-profile.c	Wed Dec 10 02:33:39 2008
@@ -29,6 +29,8 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
+#include <libpanel-util/panel-list.h>
+
 #include "applet.h"
 #include "panel-compatibility.h"
 #include "panel-gconf.h"

Modified: trunk/gnome-panel/panel-util.c
==============================================================================
--- trunk/gnome-panel/panel-util.c	(original)
+++ trunk/gnome-panel/panel-util.c	Wed Dec 10 02:33:39 2008
@@ -196,169 +196,6 @@
 	}
 }
 
-GList *
-panel_g_list_insert_before (GList *list,
-			    GList *sibling,
-			    GList *link)
-{
-	if (!list) {
-		g_return_val_if_fail (sibling == NULL, list);
-		return link;
-	} else if (sibling) {
-		if (sibling->prev) {
-			link->prev = sibling->prev;
-			link->prev->next = link;
-			link->next = sibling;
-			sibling->prev = link;
-			return list;
-		} else {
-			link->next = sibling;
-			sibling->prev = link;
-			g_return_val_if_fail (sibling == list, link);
-			return link;
-		}
-	} else {
-		GList *last;
-
-		last = list;
-		while (last->next)
-			last = last->next;
-
-		last->next = link;
-		link->prev = last;
-		return list;
-	}
-}
-
-GList *
-panel_g_list_insert_after (GList *list,
-			   GList *sibling,
-			   GList *link)
-{
-	if (!list) {
-		g_return_val_if_fail (sibling == NULL, link);
-		return link;
-	} else if (sibling) {
-		if (sibling->next) {
-			link->next = sibling->next;
-			link->next->prev = link;
-			link->prev = sibling;
-			sibling->next = link;
-			return list;
-		} else {
-			sibling->next = link;
-			link->prev = sibling;
-			return list;
-		}
-			
-	} else {
-		link->next = list;
-		list->prev = link;
-		return link;
-	}
-}
-
-GList *
-panel_g_list_swap_next (GList *list, GList *dl)
-{
-	GList *t;
-
-	if(!dl->next)
-		return list;
-	if(dl->prev)
-		dl->prev->next = dl->next;
-	t = dl->prev;
-	dl->prev = dl->next;
-	dl->next->prev = t;
-	if(dl->next->next)
-		dl->next->next->prev = dl;
-	t = dl->next->next;
-	dl->next->next = dl;
-	dl->next = t;
-
-	if(list == dl)
-		return dl->prev;
-	return list;
-}
-
-GList *
-panel_g_list_swap_prev (GList *list, GList *dl)
-{
-	GList *t;
-
-	if(!dl->prev)
-		return list;
-	if(dl->next)
-		dl->next->prev = dl->prev;
-	t = dl->next;
-	dl->next = dl->prev;
-	dl->prev->next = t;
-	if(dl->prev->prev)
-		dl->prev->prev->next = dl;
-	t = dl->prev->prev;
-	dl->prev->prev = dl;
-	dl->prev = t;
-
-	if(list == dl->next)
-		return dl;
-	return list;
-}
-
-/*maybe this should be a glib function?
- it resorts a single item in the list*/
-GList *
-panel_g_list_resort_item(GList *list, gpointer data, GCompareFunc func)
-{
-	GList *dl;
-
-	if(!list)
-		return NULL;
-
-	dl = g_list_find(list,data);
-
-	g_return_val_if_fail(dl!=NULL,list);
-
-	while(dl->next &&
-	      (*func)(dl->data,dl->next->data)>0)
-		list = panel_g_list_swap_next (list, dl);
-	while(dl->prev &&
-	      (*func)(dl->data,dl->prev->data)<0)
-		list = panel_g_list_swap_prev (list, dl);
-	return list;
-}
-
-GSList *
-panel_g_slist_make_unique (GSList       *list,
-			   GCompareFunc  compare,
-			   gboolean      free_data)
-{
-	GSList *sorted, *l;
-
-	g_assert (compare != NULL);
-
-	if (!list)
-		return NULL;
-
-	sorted = g_slist_copy (list);
-	sorted = g_slist_sort (sorted, compare);
-
-	for (l = sorted; l; l = l->next) {
-		GSList *next;
-
-		next = l->next;
-		if (l->data && next && next->data)
-			if (!compare (l->data, next->data)) {
-				list = g_slist_remove (list, l->data);
-				if (free_data)
-					g_free (l->data);
-			}
-	}
-
-	g_slist_free (sorted);
-
-	return list;
-}
-
 int
 panel_find_applet_index (GtkWidget *widget)
 {

Modified: trunk/gnome-panel/panel-util.h
==============================================================================
--- trunk/gnome-panel/panel-util.h	(original)
+++ trunk/gnome-panel/panel-util.h	Wed Dec 10 02:33:39 2008
@@ -23,24 +23,6 @@
 					 const char *path,
 					 const char *linkid);
 
-GList *panel_g_list_insert_before (GList        *list,
-				   GList        *sibling,
-				   GList        *link);
-GList *panel_g_list_insert_after  (GList        *list,
-				   GList        *sibling,
-				   GList        *link);
-GList *panel_g_list_swap_next     (GList        *list,
-				   GList        *dl);
-GList *panel_g_list_swap_prev     (GList        *list,
-				   GList        *dl);
-GList *panel_g_list_resort_item   (GList        *list,
-				   gpointer      data,
-				   GCompareFunc  func);
-
-GSList *panel_g_slist_make_unique (GSList       *list,
-				   GCompareFunc  compare,
-				   gboolean      free_data);
-
 int		panel_find_applet_index	(GtkWidget *widget);
 
 void		panel_push_window_busy	(GtkWidget *window);

Modified: trunk/gnome-panel/panel-widget.c
==============================================================================
--- trunk/gnome-panel/panel-widget.c	(original)
+++ trunk/gnome-panel/panel-widget.c	Wed Dec 10 02:33:39 2008
@@ -12,6 +12,8 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 
+#include <libpanel-util/panel-list.h>
+
 #include "applet.h"
 #include "panel-widget.h"
 #include "button-widget.h"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]