An application can now support only one type.
[mmediamanager.git] / src / mm-application.c
blobcf0e568209ad9d0616952dfd8f32c714b2463afe
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>
22 #include <glib.h>
24 #include "mm-application.h"
25 #include "mm-application-provider.h"
26 #include "mm-category-provider.h"
27 #include "mm-module-manager.h"
28 #include "mm-manager.h"
29 #include "mm-type-builtins.h"
31 #define MM_APPLICATION_GET_PRIVATE(o) \
32 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_APPLICATION, MMApplicationDetails))
34 G_DEFINE_TYPE (MMApplication, mm_application, G_TYPE_OBJECT);
36 enum {
37 PROP_0,
38 PROP_SUPPORTED_TYPE
41 struct _MMApplicationDetails {
42 GDesktopAppInfo *info;
43 MMApplicationType supported_type;
46 static void
47 mm_application_finalize (GObject *o)
49 g_object_unref (MM_APPLICATION (o)->details->info);
51 G_OBJECT_CLASS (mm_application_parent_class)->finalize (o);
54 static void
55 mm_application_get_property (GObject *o,
56 guint prop_id,
57 GValue *value,
58 GParamSpec *pspec)
60 MMApplicationDetails *details = MM_APPLICATION (o)->details;
62 switch (prop_id) {
63 case PROP_SUPPORTED_TYPE:
64 g_value_set_enum (value, details->supported_type);
65 break;
66 default:
67 break;
71 static void
72 mm_application_set_property (GObject *o,
73 guint prop_id,
74 const GValue *value,
75 GParamSpec *pspec)
77 MMApplicationDetails *details = MM_APPLICATION (o)->details;
79 switch (prop_id) {
80 case PROP_SUPPORTED_TYPE:
81 details->supported_type = g_value_get_enum (value);
82 break;
83 default:
84 break;
88 static void
89 mm_application_class_init (MMApplicationClass *klass)
91 GObjectClass *oclass = G_OBJECT_CLASS (klass);
93 oclass->get_property = mm_application_get_property;
94 oclass->set_property = mm_application_set_property;
95 oclass->finalize = mm_application_finalize;
97 g_object_class_install_property (oclass,
98 PROP_SUPPORTED_TYPE,
99 g_param_spec_enum ("supported-type",
100 "Supported Type",
101 "Media type supported by the application",
102 MM_TYPE_MAPPLICATION_TYPES,
103 MM_APPLICATION_NONE,
104 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
106 g_type_class_add_private (klass, sizeof (MMApplicationDetails));
109 static void
110 mm_application_init (MMApplication *a)
112 MMApplicationDetails *details = a->details = MM_APPLICATION_GET_PRIVATE (a);
114 details->info = NULL;
115 details->supported_type = MM_APPLICATION_NONE;
118 /* public methods */
120 MMApplication *
121 mm_application_new (const char *desktop_id,
122 MMApplicationType supported_type)
124 MMApplication *application;
126 application = g_object_new (MM_TYPE_APPLICATION,
127 "supported-type", supported_type,
128 NULL);
129 application->details->info = g_desktop_app_info_new (desktop_id);
131 return application;
134 GDesktopAppInfo *
135 mm_application_get_app_info (MMApplication *a)
137 g_return_val_if_fail (a != NULL, NULL);
138 g_return_val_if_fail (MM_IS_APPLICATION (a), NULL);
140 return a->details->info;
143 GList *
144 mm_application_get_categories (MMApplication *a)
146 MMCategoryProvider *cat_provider;
147 MMApplicationProvider *app_provider;
148 MMManager *manager;
150 g_return_val_if_fail (a != NULL, NULL);
151 g_return_val_if_fail (MM_IS_APPLICATION (a), NULL);
153 manager = mm_manager_get ();
154 app_provider = mm_manager_get_application_provider_for_application (manager, a);
155 cat_provider = mm_module_manager_get_category_provider_for_application (mm_manager_get_module_manager (manager),
156 app_provider);
157 return mm_category_provider_get_categories (cat_provider, a);