From c8f673afcb50c6b81b0f43bfa22fb10ed3870ada Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 25 Jun 2008 17:48:13 +0200 Subject: [PATCH] Split MMApplication into MMSoApplication and a base implementation. This will help the progress to make MMDBusApplication. --- src/Makefile.am | 4 ++- src/mm-application.c | 38 +++++++++++--------------- src/mm-application.h | 9 ++++--- src/mm-so-application.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ src/mm-so-application.h | 57 +++++++++++++++++++++++++++++++++++++++ src/mm.h | 1 + 6 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 src/mm-so-application.c create mode 100644 src/mm-so-application.h diff --git a/src/Makefile.am b/src/Makefile.am index e4afb39..4b44d3f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,7 @@ libmmanager_includedir=$(includedir)/libmmanager libmmanager_headers = \ mm.h \ mm-application.h \ + mm-so-application.h \ mm-application-provider.h \ mm-category.h \ mm-category-provider.h \ @@ -61,7 +62,8 @@ libmmanager_include_HEADERS = \ mm-type-builtins.h libmmanager_la_SOURCES = \ - mm-application.c\ + mm-application.c \ + mm-so-application.c \ mm-application-provider.c \ mm-category.c \ mm-category-provider.c \ diff --git a/src/mm-application.c b/src/mm-application.c index 4e52eae..befa581 100644 --- a/src/mm-application.c +++ b/src/mm-application.c @@ -119,20 +119,18 @@ mm_application_init (MMApplication *a) /* public methods */ -MMApplication * -mm_application_new (const char *desktop_id, - MMApplicationType supported_type, - const char *id) +void +mm_application_set_attributes (MMApplication *application, + const char *desktop_id, + MMApplicationType supported_type, + const char *id) { - MMApplication *application; + g_object_set (application, + "supported-type", supported_type, + NULL); - application = g_object_new (MM_TYPE_APPLICATION, - "supported-type", supported_type, - NULL); application->details->info = g_desktop_app_info_new (desktop_id); application->details->id = g_strdup (id); - - return application; } GDesktopAppInfo * @@ -144,26 +142,22 @@ mm_application_get_app_info (MMApplication *a) return a->details->info; } -GList * -mm_application_get_categories (MMApplication *a) +const char * +mm_application_get_id (MMApplication *a) { - MMCategoryProvider *cat_provider; - MMManager *manager; - g_return_val_if_fail (a != NULL, NULL); g_return_val_if_fail (MM_IS_APPLICATION (a), NULL); - manager = mm_manager_get (); - cat_provider = mm_module_manager_get_category_provider_for_application (mm_manager_get_module_manager (manager), - a->details->id); - return mm_category_provider_get_categories (cat_provider, a); + return a->details->id; } -const char * -mm_application_get_id (MMApplication *a) +GList * +mm_application_get_categories (MMApplication *a) { g_return_val_if_fail (a != NULL, NULL); g_return_val_if_fail (MM_IS_APPLICATION (a), NULL); - return a->details->id; + /* return NULL if we can't find the method in the subclass */ + return (MM_APPLICATION_CLASS (G_OBJECT_GET_CLASS (a))->get_categories == NULL) ? + NULL : ((* MM_APPLICATION_CLASS (G_OBJECT_GET_CLASS (a))->get_categories) (a)); } diff --git a/src/mm-application.h b/src/mm-application.h index a4a5e4c..6c890ab 100644 --- a/src/mm-application.h +++ b/src/mm-application.h @@ -48,15 +48,18 @@ struct _MMApplication { struct _MMApplicationClass { GObjectClass parent_class; + + GList * (* get_categories) (MMApplication *application); }; GType mm_application_get_type (void); -MMApplication* mm_application_new (const char *desktop_id, - MMApplicationType supported_types, - const char *id); GDesktopAppInfo* mm_application_get_app_info (MMApplication *application); const char * mm_application_get_id (MMApplication *application); +void mm_application_set_attributes (MMApplication *application, + const char *desktop_id, + MMApplicationType supported_type, + const char *id); /* return the list of the categories inside the application */ GList* mm_application_get_categories (MMApplication *application); diff --git a/src/mm-so-application.c b/src/mm-so-application.c new file mode 100644 index 0000000..ea3d07d --- /dev/null +++ b/src/mm-so-application.c @@ -0,0 +1,72 @@ +/* MManager - a Desktop wide manager for multimedia applications. + * + * Copyright (C) 2008 Cosimo Cecchi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "mm-application.h" +#include "mm-so-application.h" +#include "mm-manager.h" +#include "mm-category-provider.h" +#include +#include + +G_DEFINE_TYPE (MMSoApplication, mm_so_application, MM_TYPE_APPLICATION); + +static GList * +mm_so_application_get_categories (MMApplication *a) +{ + MMManager *manager; + MMCategoryProvider *cat_provider; + + g_return_val_if_fail (a != NULL, NULL); + g_return_val_if_fail (MM_IS_APPLICATION (a), NULL); + + manager = mm_manager_get (); + cat_provider = mm_module_manager_get_category_provider_for_application (mm_manager_get_module_manager (manager), + mm_application_get_id (a)); + return mm_category_provider_get_categories (cat_provider, a); +} + +static void +mm_so_application_class_init (MMSoApplicationClass *klass) +{ + MMApplicationClass *app_class = MM_APPLICATION_CLASS (klass); + + app_class->get_categories = mm_so_application_get_categories; +} + +static void +mm_so_application_init (MMSoApplication *app) +{ + /* empty */ +} + +/* public methods */ + +MMApplication * +mm_so_application_new (const char *desktop_id, + MMApplicationType supported_type, + const char *id) +{ + MMApplication *app; + + app = MM_APPLICATION (g_object_new (MM_TYPE_SO_APPLICATION, NULL)); + mm_application_set_attributes (app, desktop_id, supported_type, id); + + return app; +} diff --git a/src/mm-so-application.h b/src/mm-so-application.h new file mode 100644 index 0000000..a636461 --- /dev/null +++ b/src/mm-so-application.h @@ -0,0 +1,57 @@ +/* MManager - a Desktop wide manager for multimedia applications. + * + * Copyright (C) 2008 Cosimo Cecchi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __MM_SO_APPLICATION_H__ +#define __MM_SO_APPLICATION_H__ + +#include +#include +#include "mm-application.h" + +#define MM_TYPE_SO_APPLICATION (mm_so_application_get_type()) +#define MM_SO_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ + MM_TYPE_SO_APPLICATION, MMSoApplication)) +#define MM_SO_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ + MM_TYPE_SO_APPLICATION, MMSoApplicationClass)) +#define MM_IS_SO_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ + MM_TYPE_SO_APPLICATION)) +#define MM_IS_SO_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj),\ + MM_TYPE_SO_APPLICATION)) +#define MM_SO_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),\ + MM_TYPE_SO_APPLICATION, MMSoApplicationClass)) + +typedef struct _MMSoApplication MMSoApplication; +typedef struct _MMSoApplicationClass MMSoApplicationClass; + +struct _MMSoApplication { + MMApplication parent; +}; + +struct _MMSoApplicationClass { + MMApplicationClass parent_class; +}; + +/* public methods */ +GType mm_so_application_get_type (void); +MMApplication * mm_so_application_new (const char *desktop_id, + MMApplicationType supported_type, + const char *id); + +#endif /* __MM_SO_APPLICATION_H__ */ diff --git a/src/mm.h b/src/mm.h index 373e7f8..1cad53c 100644 --- a/src/mm.h +++ b/src/mm.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include -- 2.11.4.GIT