Back to index

indicator-appmenu  12.10.0
hudsourcelist.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2012 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Author: Ryan Lortie <desrt@desrt.ca>
00017  */
00018 
00019 #include "hudsourcelist.h"
00020 
00043 struct _HudSourceList
00044 {
00045   GObject parent_instance;
00046 
00047   GSList *list;
00048 };
00049 
00050 typedef GObjectClass HudSourceListClass;
00051 
00052 static void hud_source_list_iface_init (HudSourceInterface *iface);
00053 G_DEFINE_TYPE_WITH_CODE (HudSourceList, hud_source_list, G_TYPE_OBJECT,
00054                          G_IMPLEMENT_INTERFACE (HUD_TYPE_SOURCE, hud_source_list_iface_init))
00055 
00056 static void
00057 hud_source_list_source_changed (HudSource *source,
00058                                 gpointer   user_data)
00059 {
00060   HudSourceList *list = user_data;
00061 
00062   hud_source_changed (HUD_SOURCE (list));
00063 }
00064 
00065 static void
00066 hud_source_list_use (HudSource *source)
00067 {
00068   HudSourceList *list = HUD_SOURCE_LIST (source);
00069   GSList *node;
00070 
00071   for (node = list->list; node; node = node->next)
00072     hud_source_use (node->data);
00073 }
00074 
00075 static void
00076 hud_source_list_unuse (HudSource *source)
00077 {
00078   HudSourceList *list = HUD_SOURCE_LIST (source);
00079   GSList *node;
00080 
00081   for (node = list->list; node; node = node->next)
00082     hud_source_unuse (node->data);
00083 }
00084 
00085 static void
00086 hud_source_list_search (HudSource    *source,
00087                         GPtrArray    *results_array,
00088                         HudTokenList *search_string)
00089 {
00090   HudSourceList *list = HUD_SOURCE_LIST (source);
00091   GSList *node;
00092 
00093   for (node = list->list; node; node = node->next)
00094     hud_source_search (node->data, results_array, search_string);
00095 }
00096 
00097 static void
00098 hud_source_list_finalize (GObject *object)
00099 {
00100   HudSourceList *list = HUD_SOURCE_LIST (object);
00101 
00102   /* signals have already been disconnected in dispose */
00103   g_slist_free_full (list->list, g_object_unref);
00104 
00105   G_OBJECT_CLASS (hud_source_list_parent_class)
00106     ->finalize (object);
00107 }
00108 
00109 static void
00110 hud_source_list_init (HudSourceList *list)
00111 {
00112 }
00113 
00114 static void
00115 hud_source_list_iface_init (HudSourceInterface *iface)
00116 {
00117   iface->use = hud_source_list_use;
00118   iface->unuse = hud_source_list_unuse;
00119   iface->search = hud_source_list_search;
00120 }
00121 
00122 static void
00123 hud_source_list_class_init (HudSourceListClass *class)
00124 {
00125   class->finalize = hud_source_list_finalize;
00126 }
00127 
00138 HudSourceList *
00139 hud_source_list_new (void)
00140 {
00141   return g_object_new (HUD_TYPE_SOURCE_LIST, NULL);
00142 }
00143 
00154 void
00155 hud_source_list_add (HudSourceList *list,
00156                      HudSource     *source)
00157 {
00158   g_return_if_fail (HUD_IS_SOURCE_LIST (list));
00159   g_return_if_fail (HUD_IS_SOURCE (source));
00160 
00161   g_signal_connect_object (source, "changed", G_CALLBACK (hud_source_list_source_changed), list, 0);
00162   list->list = g_slist_prepend (list->list, g_object_ref (source));
00163 
00164   hud_source_changed (HUD_SOURCE (source));
00165 }