Move handling of supported types to the MMManager.
[mmediamanager.git] / src / mm-module-manager.c
blobfbd32fb9e119de5543ba7edfc066ba2391c02cae
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.h>
22 #include <glib-object.h>
24 #include "mm-module-manager.h"
25 #include "mm-application-provider.h"
26 #include "mm-category-provider.h"
27 #include "mm-hit-collection-provider.h"
28 #include "mm-module.h"
30 #define MM_MODULE_MANAGER_GET_PRIVATE(o) \
31 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODULE_MANAGER, MMModuleManagerDetails))
33 G_DEFINE_TYPE (MMModuleManager, mm_module_manager, G_TYPE_OBJECT);
35 struct _MMModuleManagerDetails {
36 GList *modules;
37 char *path;
40 static void
41 load_modules (MMModuleManager *manager)
43 MMModuleManagerDetails *details = manager->details;
44 GDir *dir;
45 GError *error = NULL;
47 dir = g_dir_open (path, 0, &error);
48 if (!dir) {
49 g_warning ("Unable to load modules from %s: %s",
50 details->path, error->message);
51 } else {
52 const char *name;
54 while ((name = g_dir_read_name (dir))) {
55 if (g_str_has_suffix (name, "." G_MODULE_SUFFIX)) {
56 char *filename;
57 MMModule *module;
59 filename = g_build_filename (details->path, name, NULL);
60 module = mm_module_load_file (filename);
61 g_free (filename);
63 if (module) {
64 g_list_prepend (details->modules, module);
68 g_dir_close (dir);
70 g_error_free (error);
73 static void
74 mm_module_managet_finalize (GObject *o)
76 MMModuleManager *manager = MM_MODULE_MANAGER (o);
78 g_free (manager->details->path);
79 g_list_free (manager->details->modules);
81 G_OBJECT_CLASS (mm_module_manager_parent_class)->finalize (o);
84 static void
85 mm_module_manager_init (MMModuleManager *manager)
87 MMModuleManagerDetails *details = manager->details =
88 MM_MODULE_MANAGER_GET_PRIVATE (manager);
90 details->modules_path = g_strdup ("/path/to/the/modules");
91 details->modules = NULL;
92 load_modules (manager);
95 static void
96 mm_module_manager_class_init (MMModuleManagerClass *klass)
98 G_OBJECT_CLASS (klass)->finalize = mm_module_manager_finalize;
100 g_type_class_add_private (klass, sizeof (MMModuleManagerDetails));
103 /* public methods */
105 GList *
106 mm_module_manager_get_all_application_providers (MMModuleManager *manager)
108 GList *l;
109 GList *application_providers = NULL;
111 for (l = manager->details->modules; l; l = l->next) {
112 application_providers = g_list_prepend (application_providers,
113 mm_module_get_application_provider (MM_MODULE (l->data)));
116 return application_providers;
119 MMCategoryProvider *
120 mm_module_manager_get_category_provider_for_application (MMModuleManager *manager,
121 MMApplicationProvider *application)
123 GList *l;
124 MMCategoryProvider *provider = NULL;
126 for (l = manager->details->modules; l; l = l->next) {
127 if (mm_module_get_application_provider (MM_MODULE (l->data)) == application) {
128 provider = mm_module_get_category_provider (MM_MODULE (l->data));
129 break;
133 return provider;
136 MMHitCollectionProvider *
137 mm_module_manager_get_hit_collection_provider_for_application (MMModuleManager *manager,
138 MMApplicationProvider *application)
140 GList *l;
141 MMHitCollectionProvider *provider = NULL;
143 for (l = manager->details->modules; l; l = l->next) {
144 if (mm_module_get_application_provider (MM_MODULE (l->data)) == application) {
145 provider = mm_module_get_hit_collection_provider (MM_MODULE (l->data));
146 break;
150 return provider;