1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <glib-object.h>
24 #include "mm-manager.h"
26 G_DEFINE_TYPE (MMManager
, mm_manager
, G_TYPE_OBJECT
);
28 #define MM_MANAGER_GET_PRIVATE(o) \
29 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MANAGER, MMManagerDetails))
31 MMManager
* mm_manager_singleton
= NULL
;
33 struct _MMManagerDetails
{
34 MMModuleManager
*module_manager
;
35 GHashTable
*applications
;
39 mm_manager_finalize (GObject
*o
)
41 MMManager
*manager
= MM_MANAGER (o
);
43 g_hash_table_destroy (manager
->details
->applications
);
45 G_OBJECT_CLASS (mm_manager_parent_class
)->finalize (o
);
49 mm_manager_class_init (MMManagerClass
*klass
)
51 G_OBJECT_CLASS (klass
)->finalize
= mm_manager_finalize
;
53 g_type_class_add_private (klass
, sizeof (MMManagerDetails
));
57 populate_applications_table (MMManager
*manager
)
59 GHashTable
*applications
= manager
->details
->applications
;
60 GList
*app_providers
, *l
;
61 MMApplication
*application
;
62 MMApplicationProvider
*provider
;
65 app_providers
= mm_module_manager_get_all_application_providers (manager
->details
->module_manager
);
66 for (l
= app_providers
; l
; l
= l
->next
) {
67 provider
= MM_APPLICATION_PROVIDER (l
->data
);
68 application
= mm_application_provider_get_application (provider
);
69 id
= mm_application_get_id (application
);
70 g_hash_table_insert (applications
,
71 g_strdup (id
), /* key */
72 application
); /* value */
77 mm_manager_init (MMManager
*manager
)
79 MMManagerDetails
*details
= manager
->details
= MM_MANAGER_GET_PRIVATE (manager
);
81 details
->module_manager
= MM_MODULE_MANAGER (g_object_new (MM_TYPE_MODULE_MANAGER
, NULL
));
82 details
->applications
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
83 (GDestroyNotify
) g_free
,
86 populate_applications_table (manager
);
94 if (!mm_manager_singleton
) {
95 mm_manager_singleton
= MM_MANAGER (g_object_new (MM_TYPE_MANAGER
, NULL
));
98 return mm_manager_singleton
;
102 mm_manager_get_application_list_for_type (MMManager
*m
,
103 MMApplicationType type
)
106 GList
*app_list
= NULL
;
107 MMApplicationType supported_type
;
110 g_return_val_if_fail (m
!= NULL
, NULL
);
111 g_return_val_if_fail (MM_IS_MANAGER (m
), NULL
);
113 /* this should be fine anyway, as the hash table is created only when
114 * initializing the manager.
116 all_apps
= g_hash_table_get_values (m
->details
->applications
);
117 for (l
= all_apps
; l
; l
= l
->next
) {
120 "supported-type", &supported_type
,
122 if (supported_type
== type
) {
123 app_list
= g_list_prepend (app_list
, app
);
127 g_list_free (all_apps
);
133 mm_manager_get_application_list (MMManager
*m
)
135 g_return_val_if_fail (m
!= NULL
, NULL
);
136 g_return_val_if_fail (MM_IS_MANAGER (m
), NULL
);
138 /* see the comment in _get_application_list_for_type () */
139 return g_hash_table_get_values (m
->details
->applications
);
143 mm_manager_get_module_manager (MMManager
*m
)
145 g_return_val_if_fail (m
!= NULL
, NULL
);
146 g_return_val_if_fail (MM_IS_MANAGER (m
), NULL
);
148 return m
->details
->module_manager
;