[Xfce4-commits] [apps/xfdashboard] 01/01: Rewrote view manager to use IDs.

noreply at xfce.org noreply at xfce.org
Thu Oct 15 08:49:20 CEST 2015


This is an automated email from the git hooks/post-receive script.

nomad pushed a commit to branch master
in repository apps/xfdashboard.

commit 1a7972f7b409b70f918c268906133799ce6c781c
Author: Stephan Haller <nomad at froevel.de>
Date:   Thu Oct 15 08:43:13 2015 +0200

    Rewrote view manager to use IDs.
    
    Views do not specify their internal names by themselve but are now registered with an ID directly and the GType of this view is registered with this ID. Doing it this way makes it possible to define multi-purpose views of the same type. This is not interesting for views but for search providers.
    
    Multi-purpose views (and later search providers) can reuse the same type but behave different depending on the ID. Thinking of one Gnome shell search provider object that will be registered several time but with different ID whereby the ID specifies with search provider to call via DBUS. This is just an example.
---
 .../xfdashboard-auber/xfdashboard-secondary.xml    |    1 +
 .../xfdashboard-blue/xfdashboard-secondary.xml     |    1 +
 .../xfdashboard-dark/xfdashboard-secondary.xml     |    1 +
 .../xfdashboard-mint/xfdashboard-secondary.xml     |    1 +
 .../xfdashboard-moranga/xfdashboard-secondary.xml  |    1 +
 .../xfdashboard-wine/xfdashboard-secondary.xml     |    1 +
 data/themes/xfdashboard/xfdashboard-secondary.xml  |    1 +
 xfdashboard/application.c                          |    6 +-
 xfdashboard/applications-view.c                    |    1 -
 xfdashboard/search-view.c                          |    1 -
 xfdashboard/stage.c                                |    6 +-
 xfdashboard/view-manager.c                         |  222 +++++++++++++++++---
 xfdashboard/view-manager.h                         |   10 +-
 xfdashboard/view.c                                 |   76 ++++---
 xfdashboard/view.h                                 |    4 +-
 xfdashboard/viewpad.c                              |   41 ++--
 xfdashboard/viewpad.h                              |    2 +-
 xfdashboard/windows-view.c                         |    1 -
 18 files changed, 283 insertions(+), 94 deletions(-)

diff --git a/data/themes/xfdashboard-auber/xfdashboard-secondary.xml b/data/themes/xfdashboard-auber/xfdashboard-secondary.xml
index 9c8656b..8bb264a 100644
--- a/data/themes/xfdashboard-auber/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard-auber/xfdashboard-secondary.xml
@@ -43,6 +43,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/data/themes/xfdashboard-blue/xfdashboard-secondary.xml b/data/themes/xfdashboard-blue/xfdashboard-secondary.xml
index 9c8656b..8bb264a 100644
--- a/data/themes/xfdashboard-blue/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard-blue/xfdashboard-secondary.xml
@@ -43,6 +43,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/data/themes/xfdashboard-dark/xfdashboard-secondary.xml b/data/themes/xfdashboard-dark/xfdashboard-secondary.xml
index 9c8656b..8bb264a 100644
--- a/data/themes/xfdashboard-dark/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard-dark/xfdashboard-secondary.xml
@@ -43,6 +43,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/data/themes/xfdashboard-mint/xfdashboard-secondary.xml b/data/themes/xfdashboard-mint/xfdashboard-secondary.xml
index 9c8656b..8bb264a 100644
--- a/data/themes/xfdashboard-mint/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard-mint/xfdashboard-secondary.xml
@@ -43,6 +43,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/data/themes/xfdashboard-moranga/xfdashboard-secondary.xml b/data/themes/xfdashboard-moranga/xfdashboard-secondary.xml
index 9c8656b..8bb264a 100644
--- a/data/themes/xfdashboard-moranga/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard-moranga/xfdashboard-secondary.xml
@@ -43,6 +43,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/data/themes/xfdashboard-wine/xfdashboard-secondary.xml b/data/themes/xfdashboard-wine/xfdashboard-secondary.xml
index 9c8656b..8bb264a 100644
--- a/data/themes/xfdashboard-wine/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard-wine/xfdashboard-secondary.xml
@@ -43,6 +43,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/data/themes/xfdashboard/xfdashboard-secondary.xml b/data/themes/xfdashboard/xfdashboard-secondary.xml
index 8af32e5..8ff3e50 100644
--- a/data/themes/xfdashboard/xfdashboard-secondary.xml
+++ b/data/themes/xfdashboard/xfdashboard-secondary.xml
@@ -51,6 +51,7 @@
 
 				<child>
 					<object class="XfdashboardWindowsView">
+						<property name="view-id">windows</property>
 						<property name="x-expand">true</property>
 						<property name="y-expand">true</property>
 					</object>
diff --git a/xfdashboard/application.c b/xfdashboard/application.c
index 970358c..30a828f 100644
--- a/xfdashboard/application.c
+++ b/xfdashboard/application.c
@@ -410,9 +410,9 @@ static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication
 	/* Register built-in views (order of registration is important) */
 	priv->viewManager=xfdashboard_view_manager_get_default();
 
-	xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_WINDOWS_VIEW);
-	xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_APPLICATIONS_VIEW);
-	xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_SEARCH_VIEW);
+	xfdashboard_view_manager_register(priv->viewManager, "windows", XFDASHBOARD_TYPE_WINDOWS_VIEW);
+	xfdashboard_view_manager_register(priv->viewManager, "applications", XFDASHBOARD_TYPE_APPLICATIONS_VIEW);
+	xfdashboard_view_manager_register(priv->viewManager, "search", XFDASHBOARD_TYPE_SEARCH_VIEW);
 
 	/* Register built-in search providers */
 	priv->searchManager=xfdashboard_search_manager_get_default();
diff --git a/xfdashboard/applications-view.c b/xfdashboard/applications-view.c
index b767454..c34ad26 100644
--- a/xfdashboard/applications-view.c
+++ b/xfdashboard/applications-view.c
@@ -1373,7 +1373,6 @@ static void xfdashboard_applications_view_init(XfdashboardApplicationsView *self
 	priv->xfconfShowAllAppsMenuBindingID=0;
 
 	/* Set up view */
-	xfdashboard_view_set_internal_name(XFDASHBOARD_VIEW(self), "applications");
 	xfdashboard_view_set_name(XFDASHBOARD_VIEW(self), _("Applications"));
 	xfdashboard_view_set_icon(XFDASHBOARD_VIEW(self), "start-here");
 
diff --git a/xfdashboard/search-view.c b/xfdashboard/search-view.c
index 75dff01..fd202ea 100644
--- a/xfdashboard/search-view.c
+++ b/xfdashboard/search-view.c
@@ -1724,7 +1724,6 @@ static void xfdashboard_search_view_init(XfdashboardSearchView *self)
 	priv->xfconfChannel=xfdashboard_application_get_xfconf_channel();
 
 	/* Set up view (Note: Search view is disabled by default!) */
-	xfdashboard_view_set_internal_name(XFDASHBOARD_VIEW(self), "search");
 	xfdashboard_view_set_name(XFDASHBOARD_VIEW(self), _("Search"));
 	xfdashboard_view_set_icon(XFDASHBOARD_VIEW(self), "edit-find");
 	xfdashboard_view_set_enabled(XFDASHBOARD_VIEW(self), FALSE);
diff --git a/xfdashboard/stage.c b/xfdashboard/stage.c
index 051647e..26f4a13 100644
--- a/xfdashboard/stage.c
+++ b/xfdashboard/stage.c
@@ -663,7 +663,7 @@ static void _xfdashboard_stage_on_application_resume(XfdashboardStage *self, gpo
 			/* First lookup view we should switch to by its internal name */
 			if(priv->switchToView)
 			{
-				resumeView=xfdashboard_viewpad_find_view_by_name(XFDASHBOARD_VIEWPAD(priv->viewpad), priv->switchToView);
+				resumeView=xfdashboard_viewpad_find_view_by_id(XFDASHBOARD_VIEWPAD(priv->viewpad), priv->switchToView);
 				if(!resumeView) g_warning(_("Will not switch to unknown view '%s'"), priv->switchToView);
 
 				/* Regardless if we could find view by its internal name or not
@@ -681,7 +681,7 @@ static void _xfdashboard_stage_on_application_resume(XfdashboardStage *self, gpo
 			 */
 			if(!resumeView)
 			{
-				resumeView=xfdashboard_viewpad_find_view_by_name(XFDASHBOARD_VIEWPAD(priv->viewpad), resumeViewInternalName);
+				resumeView=xfdashboard_viewpad_find_view_by_id(XFDASHBOARD_VIEWPAD(priv->viewpad), resumeViewInternalName);
 				if(!resumeView) g_warning(_("Cannot switch to unknown view '%s'"), resumeViewInternalName);
 			}
 
@@ -1315,7 +1315,7 @@ static void _xfdashboard_stage_show(ClutterActor *inActor)
 	if(priv->switchToView)
 	{
 		/* Look up view and switch to it if found */
-		switchView=xfdashboard_viewpad_find_view_by_name(XFDASHBOARD_VIEWPAD(priv->viewpad), priv->switchToView);
+		switchView=xfdashboard_viewpad_find_view_by_id(XFDASHBOARD_VIEWPAD(priv->viewpad), priv->switchToView);
 		if(switchView)
 		{
 			xfdashboard_viewpad_set_active_view(XFDASHBOARD_VIEWPAD(priv->viewpad), switchView);
diff --git a/xfdashboard/view-manager.c b/xfdashboard/view-manager.c
index d5d4cb7..059d2ce 100644
--- a/xfdashboard/view-manager.c
+++ b/xfdashboard/view-manager.c
@@ -59,18 +59,105 @@ enum
 static guint XfdashboardViewManagerSignals[SIGNAL_LAST]={ 0, };
 
 /* IMPLEMENTATION: Private variables and methods */
+typedef struct _XfdashboardViewManagerData		XfdashboardViewManagerData;
+struct _XfdashboardViewManagerData
+{
+	gchar		*ID;
+	GType		gtype;
+};
 
 /* Single instance of view manager */
 static XfdashboardViewManager*		_xfdashboard_view_manager=NULL;
 
+/* Free an registered view entry */
+static void _xfdashboard_view_manager_entry_free(XfdashboardViewManagerData *inData)
+{
+	g_return_if_fail(inData);
+
+	/* Release allocated resources */
+	if(inData->ID) g_free(inData->ID);
+	g_free(inData);
+}
+
+/* Create an entry for a registered view */
+static XfdashboardViewManagerData* _xfdashboard_view_manager_entry_new(const gchar *inID, GType inType)
+{
+	XfdashboardViewManagerData		*data;
+
+	g_return_val_if_fail(inID && *inID, NULL);
+
+	/* Create new entry */
+	data=g_new0(XfdashboardViewManagerData, 1);
+	if(!data) return(NULL);
+
+	data->ID=g_strdup(inID);
+	data->gtype=inType;
+
+	/* Return newly created entry */
+	return(data);
+}
+
+/* Find entry for a registered view by ID */
+static GList* _xfdashboard_view_manager_entry_find_list_entry_by_id(XfdashboardViewManager *self,
+																	const gchar *inID)
+{
+	XfdashboardViewManagerPrivate	*priv;
+	GList							*iter;
+	XfdashboardViewManagerData		*data;
+
+	g_return_val_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self), NULL);
+	g_return_val_if_fail(inID && *inID, NULL);
+
+	priv=self->priv;
+
+	/* Iterate through list and lookup list entry whose data has requested ID */
+	for(iter=priv->registeredViews; iter; iter=g_list_next(iter))
+	{
+		/* Get data of currently iterated list entry */
+		data=(XfdashboardViewManagerData*)(iter->data);
+		if(!data) continue;
+
+		/* Check if ID of data matches requested one and
+		 * return list entry if it does.
+		 */
+		if(g_strcmp0(data->ID, inID)==0) return(iter);
+	}
+
+	/* If we get here we did not find a matching list entry */
+	return(NULL);
+}
+
+static XfdashboardViewManagerData* _xfdashboard_view_manager_entry_find_data_by_id(XfdashboardViewManager *self,
+																					const gchar *inID)
+{
+	GList							*iter;
+	XfdashboardViewManagerData		*data;
+
+	g_return_val_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self), NULL);
+	g_return_val_if_fail(inID && *inID, NULL);
+
+	/* Find list entry matching requested ID */
+	iter=_xfdashboard_view_manager_entry_find_list_entry_by_id(self, inID);
+	if(!iter) return(NULL);
+
+	/* We found a matching list entry so return its data */
+	data=(XfdashboardViewManagerData*)(iter->data);
+
+	/* Return data of matching list entry */
+	return(data);
+}
+
 /* IMPLEMENTATION: GObject */
 
 /* Dispose this object */
 static void _xfdashboard_view_manager_dispose_unregister_view(gpointer inData, gpointer inUserData)
 {
+	XfdashboardViewManagerData		*data;
+
 	g_return_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(inUserData));
 
-	xfdashboard_view_manager_unregister(XFDASHBOARD_VIEW_MANAGER(inUserData), GPOINTER_TO_GTYPE(inData));
+	data=(XfdashboardViewManagerData*)inData;
+	xfdashboard_view_manager_unregister(XFDASHBOARD_VIEW_MANAGER(inUserData), data->ID);
 }
 
 static void _xfdashboard_view_manager_dispose(GObject *inObject)
@@ -161,11 +248,13 @@ XfdashboardViewManager* xfdashboard_view_manager_get_default(void)
 }
 
 /* Register a view */
-void xfdashboard_view_manager_register(XfdashboardViewManager *self, GType inViewType)
+gboolean xfdashboard_view_manager_register(XfdashboardViewManager *self, const gchar *inID, GType inViewType)
 {
-	XfdashboardViewManagerPrivate	*priv;
+	XfdashboardViewManagerPrivate		*priv;
+	XfdashboardViewManagerData			*data;
 
-	g_return_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self));
+	g_return_val_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self), FALSE);
+	g_return_val_if_fail(inID && *inID, FALSE);
 
 	priv=self->priv;
 
@@ -173,59 +262,128 @@ void xfdashboard_view_manager_register(XfdashboardViewManager *self, GType inVie
 	if(inViewType==XFDASHBOARD_TYPE_VIEW ||
 		g_type_is_a(inViewType, XFDASHBOARD_TYPE_VIEW)!=TRUE)
 	{
-		g_warning(_("View %s is not a %s and cannot be registered"),
+		g_warning(_("View %s of type %s is not a %s and cannot be registered"),
+					inID,
 					g_type_name(inViewType),
 					g_type_name(XFDASHBOARD_TYPE_VIEW));
-		return;
+		return(FALSE);
 	}
 
-	/* Register type if not already registered */
-	if(g_list_find(priv->registeredViews, GTYPE_TO_POINTER(inViewType))==NULL)
+	/* Check if view is registered already */
+	if(_xfdashboard_view_manager_entry_find_list_entry_by_id(self, inID))
+	{
+		g_warning(_("View %s of type %s is registered already"),
+					inID,
+					g_type_name(inViewType));
+		return(FALSE);
+	}
+
+	/* Register view */
+	g_debug("Registering view %s of type %s",
+			inID,
+			g_type_name(inViewType));
+
+	data=_xfdashboard_view_manager_entry_new(inID, inViewType);
+	if(!data)
 	{
-		g_debug("Registering view %s", g_type_name(inViewType));
-		priv->registeredViews=g_list_append(priv->registeredViews, GTYPE_TO_POINTER(inViewType));
-		g_signal_emit(self, XfdashboardViewManagerSignals[SIGNAL_REGISTERED], 0, inViewType);
+		g_warning(_("Failed to register view %s of type %s"),
+					inID,
+					g_type_name(inViewType));
+		return(FALSE);
 	}
+
+	priv->registeredViews=g_list_append(priv->registeredViews, data);
+	g_signal_emit(self, XfdashboardViewManagerSignals[SIGNAL_REGISTERED], 0, data->ID);
+
+	/* View was registered successfully so return TRUE here */
+	return(TRUE);
 }
 
 /* Unregister a view */
-void xfdashboard_view_manager_unregister(XfdashboardViewManager *self, GType inViewType)
+gboolean xfdashboard_view_manager_unregister(XfdashboardViewManager *self, const gchar *inID)
 {
-	XfdashboardViewManagerPrivate	*priv;
+	XfdashboardViewManagerPrivate		*priv;
+	GList								*iter;
+	XfdashboardViewManagerData			*data;
 
-	g_return_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self));
+	g_return_val_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self), FALSE);
+	g_return_val_if_fail(inID && *inID, FALSE);
 
 	priv=self->priv;
 
-	/* Check if given type is not a XfdashboardView but a derived type from it */
-	if(inViewType==XFDASHBOARD_TYPE_VIEW ||
-		g_type_is_a(inViewType, XFDASHBOARD_TYPE_VIEW)!=TRUE)
+	/* Check if view is registered  */
+	iter=_xfdashboard_view_manager_entry_find_list_entry_by_id(self, inID);
+	if(!iter)
 	{
-		g_warning(_("View %s is not a %s and cannot be unregistered"),
-					g_type_name(inViewType),
-					g_type_name(XFDASHBOARD_TYPE_VIEW));
-		return;
+		g_warning(_("View %s is not registered and cannot be unregistered"), inID);
+		return(FALSE);
 	}
 
-	/* Unregister type if registered */
-	if(g_list_find(priv->registeredViews, GTYPE_TO_POINTER(inViewType))!=NULL)
-	{
-		g_debug("Unregistering view %s", g_type_name(inViewType));
-		priv->registeredViews=g_list_remove(priv->registeredViews, GTYPE_TO_POINTER(inViewType));
-		g_signal_emit(self, XfdashboardViewManagerSignals[SIGNAL_UNREGISTERED], 0, inViewType);
-	}
+	/* Get data from found list entry */
+	data=(XfdashboardViewManagerData*)(iter->data);
+
+	/* Remove from list of registered views */
+	g_debug("Unregistering view %s of type %s",
+			data->ID,
+			g_type_name(data->gtype));
+
+	priv->registeredViews=g_list_remove(priv->registeredViews, iter);
+	g_signal_emit(self, XfdashboardViewManagerSignals[SIGNAL_UNREGISTERED], 0, data->ID);
+
+	/* Free data entry */
+	_xfdashboard_view_manager_entry_free(data);
+
+	/* View was unregistered successfully so return TRUE here */
+	return(TRUE);
 }
 
 /* Get list of registered views types.
- * Returned GList must be freed with g_list_free() by caller.
+ * Returned GList must be freed with g_list_free_full(result, g_free) by caller.
  */
 GList* xfdashboard_view_manager_get_registered(XfdashboardViewManager *self)
 {
-	GList		*copy;
+	GList						*copy;
+	GList						*iter;
+	XfdashboardViewManagerData	*data;
 
 	g_return_val_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self), NULL);
 
-	/* Return a copy of list of registered view types */
-	copy=g_list_copy(self->priv->registeredViews);
+	/* Return a copy of all IDs stored in list of registered view types */
+	copy=NULL;
+	for(iter=self->priv->registeredViews; iter; iter=g_list_next(iter))
+	{
+		data=(XfdashboardViewManagerData*)(iter->data);
+
+		copy=g_list_prepend(copy, g_strdup(data->ID));
+	}
+
+	/* Restore order in copied list to match origin */
+	copy=g_list_reverse(copy);
+
+	/* Return copied list of IDs of registered views */
 	return(copy);
 }
+
+/* Create view for requested ID */
+GObject* xfdashboard_view_manager_create_view(XfdashboardViewManager *self, const gchar *inID)
+{
+	XfdashboardViewManagerData			*data;
+	GObject								*view;
+
+	g_return_val_if_fail(XFDASHBOARD_IS_VIEW_MANAGER(self), NULL);
+	g_return_val_if_fail(inID && *inID, NULL);
+
+	/* Check if view is registered and get its data */
+	data=_xfdashboard_view_manager_entry_find_data_by_id(self, inID);
+	if(!data)
+	{
+		g_warning(_("Cannot create view %s because it is not registered"), inID);
+		return(NULL);
+	}
+
+	/* Create view */
+	view=g_object_new(data->gtype, "view-id", data->ID, NULL);
+
+	/* Return newly created view */
+	return(view);
+}
diff --git a/xfdashboard/view-manager.h b/xfdashboard/view-manager.h
index aa8f646..90c12a7 100644
--- a/xfdashboard/view-manager.h
+++ b/xfdashboard/view-manager.h
@@ -56,8 +56,8 @@ struct _XfdashboardViewManagerClass
 
 	/*< public >*/
 	/* Virtual functions */
-	void (*registered)(XfdashboardViewManager *self, GType inViewType);
-	void (*unregistered)(XfdashboardViewManager *self, GType inViewType);
+	void (*registered)(XfdashboardViewManager *self, const gchar *inID);
+	void (*unregistered)(XfdashboardViewManager *self, const gchar *inID);
 };
 
 /* Public API */
@@ -65,10 +65,12 @@ GType xfdashboard_view_manager_get_type(void) G_GNUC_CONST;
 
 XfdashboardViewManager* xfdashboard_view_manager_get_default(void);
 
-void xfdashboard_view_manager_register(XfdashboardViewManager *self, GType inViewType);
-void xfdashboard_view_manager_unregister(XfdashboardViewManager *self, GType inViewType);
+gboolean xfdashboard_view_manager_register(XfdashboardViewManager *self, const gchar *inID, GType inViewType);
+gboolean xfdashboard_view_manager_unregister(XfdashboardViewManager *self, const gchar *inID);
 GList* xfdashboard_view_manager_get_registered(XfdashboardViewManager *self);
 
+GObject* xfdashboard_view_manager_create_view(XfdashboardViewManager *self, const gchar *inID);
+
 G_END_DECLS
 
 #endif	/* __XFDASHBOARD_VIEW_MANAGER__ */
diff --git a/xfdashboard/view.c b/xfdashboard/view.c
index ddc1bb1..1e7d07c 100644
--- a/xfdashboard/view.c
+++ b/xfdashboard/view.c
@@ -49,14 +49,14 @@ G_DEFINE_ABSTRACT_TYPE(XfdashboardView,
 struct _XfdashboardViewPrivate
 {
 	/* Properties related */
-	gchar					*viewInternalName;
+	gchar					*viewID;
 
 	gchar					*viewName;
 
 	gchar					*viewIcon;
 	ClutterContent			*viewIconImage;
 
-	XfdashboardViewFitMode		fitMode;
+	XfdashboardViewFitMode	fitMode;
 
 	gboolean				isEnabled;
 
@@ -69,7 +69,7 @@ enum
 {
 	PROP_0,
 
-	PROP_VIEW_INTERNAL_NAME,
+	PROP_VIEW_ID,
 	PROP_VIEW_NAME,
 	PROP_VIEW_ICON,
 
@@ -212,6 +212,27 @@ static void _xfdashboard_view_disabled(XfdashboardView *self)
 	}
 }
 
+/* Set view ID */
+static void _xfdashboard_view_set_id(XfdashboardView *self, const gchar *inID)
+{
+	XfdashboardViewPrivate	*priv;
+
+	g_return_if_fail(XFDASHBOARD_IS_VIEW(self));
+	g_return_if_fail(inID && *inID);
+
+	priv=self->priv;
+
+	/* Set value if changed */
+	if(g_strcmp0(priv->viewID, inID)!=0)
+	{
+		if(priv->viewID) g_free(priv->viewID);
+		priv->viewID=g_strdup(inID);
+
+		/* Notify about property change */
+		g_object_notify_by_pspec(G_OBJECT(self), XfdashboardViewProperties[PROP_VIEW_ID]);
+	}
+}
+
 /* IMPLEMENTATION: GObject */
 
 /* Dispose this object */
@@ -221,10 +242,10 @@ static void _xfdashboard_view_dispose(GObject *inObject)
 	XfdashboardViewPrivate	*priv=self->priv;
 
 	/* Release allocated resources */
-	if(priv->viewInternalName)
+	if(priv->viewID)
 	{
-		g_free(priv->viewInternalName);
-		priv->viewInternalName=NULL;
+		g_free(priv->viewID);
+		priv->viewID=NULL;
 	}
 
 	if(priv->viewName)
@@ -259,8 +280,8 @@ static void _xfdashboard_view_set_property(GObject *inObject,
 	
 	switch(inPropID)
 	{
-		case PROP_VIEW_INTERNAL_NAME:
-			xfdashboard_view_set_internal_name(self, g_value_get_string(inValue));
+		case PROP_VIEW_ID:
+			_xfdashboard_view_set_id(self, g_value_get_string(inValue));
 			break;
 
 		case PROP_VIEW_NAME:
@@ -294,8 +315,8 @@ static void _xfdashboard_view_get_property(GObject *inObject,
 
 	switch(inPropID)
 	{
-		case PROP_VIEW_INTERNAL_NAME:
-			g_value_set_string(outValue, self->priv->viewInternalName);
+		case PROP_VIEW_ID:
+			g_value_set_string(outValue, self->priv->viewID);
 			break;
 
 		case PROP_VIEW_NAME:
@@ -342,12 +363,12 @@ static void xfdashboard_view_class_init(XfdashboardViewClass *klass)
 	g_type_class_add_private(klass, sizeof(XfdashboardViewPrivate));
 
 	/* Define properties */
-	XfdashboardViewProperties[PROP_VIEW_INTERNAL_NAME]=
-		g_param_spec_string("view-internal-name",
-							_("View internal name"),
-							_("Internal and untranslated name of view used in application"),
+	XfdashboardViewProperties[PROP_VIEW_ID]=
+		g_param_spec_string("view-id",
+							_("View ID"),
+							_("The internal ID used to register this type of view"),
 							NULL,
-							G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+							G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
 
 	XfdashboardViewProperties[PROP_VIEW_NAME]=
 		g_param_spec_string("view-name",
@@ -572,32 +593,29 @@ static void xfdashboard_view_init(XfdashboardView *self)
 
 /* IMPLEMENTATION: Public API */
 
-/* Get/set internal name of view */
-const gchar* xfdashboard_view_get_internal_name(XfdashboardView *self)
+/* Get view ID */
+const gchar* xfdashboard_view_get_id(XfdashboardView *self)
 {
 	g_return_val_if_fail(XFDASHBOARD_IS_VIEW(self), NULL);
 
-	return(self->priv->viewInternalName);
+	return(self->priv->viewID);
 }
 
-void xfdashboard_view_set_internal_name(XfdashboardView *self, const gchar *inInternalName)
+/* Check if view has requested ID */
+gboolean xfdashboard_view_has_id(XfdashboardView *self, const gchar *inID)
 {
 	XfdashboardViewPrivate	*priv;
 
-	g_return_if_fail(XFDASHBOARD_IS_VIEW(self));
-	g_return_if_fail(inInternalName!=NULL);
+	g_return_val_if_fail(XFDASHBOARD_IS_VIEW(self), FALSE);
+	g_return_val_if_fail(inID && *inID, FALSE);
 
 	priv=self->priv;
 
-	/* Set value if changed */
-	if(g_strcmp0(priv->viewInternalName, inInternalName)!=0)
-	{
-		if(priv->viewInternalName) g_free(priv->viewInternalName);
-		priv->viewInternalName=g_strdup(inInternalName);
+	/* Check if requested ID matches the ID of this view */
+	if(g_strcmp0(priv->viewID, inID)!=0) return(FALSE);
 
-		/* Notify about property change */
-		g_object_notify_by_pspec(G_OBJECT(self), XfdashboardViewProperties[PROP_VIEW_INTERNAL_NAME]);
-	}
+	/* If we get here the requested ID matches view's ID */
+	return(TRUE);
 }
 
 /* Get/set name of view */
diff --git a/xfdashboard/view.h b/xfdashboard/view.h
index 2ef3bd5..8ba7060 100644
--- a/xfdashboard/view.h
+++ b/xfdashboard/view.h
@@ -110,8 +110,8 @@ struct _XfdashboardViewClass
 /* Public API */
 GType xfdashboard_view_get_type(void) G_GNUC_CONST;
 
-const gchar* xfdashboard_view_get_internal_name(XfdashboardView *self);
-void xfdashboard_view_set_internal_name(XfdashboardView *self, const gchar *inInternalName);
+const gchar* xfdashboard_view_get_id(XfdashboardView *self);
+gboolean xfdashboard_view_has_id(XfdashboardView *self, const gchar *inID);
 
 const gchar* xfdashboard_view_get_name(XfdashboardView *self);
 void xfdashboard_view_set_name(XfdashboardView *self, const gchar *inName);
diff --git a/xfdashboard/viewpad.c b/xfdashboard/viewpad.c
index 8e083a5..39889f7 100644
--- a/xfdashboard/viewpad.c
+++ b/xfdashboard/viewpad.c
@@ -647,29 +647,33 @@ static void _xfdashboard_viewpad_on_view_child_ensure_visible(XfdashboardViewpad
 }
 
 /* Create view of given type and add to this actor */
-static void _xfdashboard_viewpad_add_view(XfdashboardViewpad *self, GType inViewType)
+static void _xfdashboard_viewpad_add_view(XfdashboardViewpad *self, const gchar *inID)
 {
 	XfdashboardViewpadPrivate	*priv;
 	GObject						*view;
 
 	g_return_if_fail(XFDASHBOARD_IS_VIEWPAD(self));
+	g_return_if_fail(inID && *inID);
 
 	priv=self->priv;
 
 	/* Create instance and check if it is a view */
-	g_debug("Creating view %s for viewpad", g_type_name(inViewType));
+	g_debug("Creating view %s for viewpad", inID);
 
-	view=g_object_new(inViewType, NULL);
+	view=xfdashboard_view_manager_create_view(priv->viewManager, inID);
 	if(view==NULL)
 	{
-		g_critical(_("Failed to create view instance of %s"), g_type_name(inViewType));
+		g_critical(_("Failed to create view %s for viewpad"), inID);
 		return;
 	}
 
 	if(XFDASHBOARD_IS_VIEW(view)!=TRUE)
 	{
-		g_critical(_("Instance %s is not a %s and cannot be added to %s"),
-					g_type_name(inViewType), g_type_name(XFDASHBOARD_TYPE_VIEW), G_OBJECT_TYPE_NAME(self));
+		g_critical(_("View %s of type %s is not a %s and cannot be added to %s"),
+					inID,
+					G_OBJECT_TYPE_NAME(view),
+					g_type_name(XFDASHBOARD_TYPE_VIEW),
+					G_OBJECT_TYPE_NAME(self));
 		return;
 	}
 
@@ -707,17 +711,18 @@ static void _xfdashboard_viewpad_add_view(XfdashboardViewpad *self, GType inView
 
 /* Called when a new view type was registered */
 static void _xfdashboard_viewpad_on_view_registered(XfdashboardViewpad *self,
-													GType inViewType,
+													const gchar *inID,
 													gpointer inUserData)
 {
 	g_return_if_fail(XFDASHBOARD_IS_VIEWPAD(self));
+	g_return_if_fail(inID && *inID);
 
-	_xfdashboard_viewpad_add_view(self, inViewType);
+	_xfdashboard_viewpad_add_view(self, inID);
 }
 
 /* Called when a view type was unregistered */
 static void _xfdashboard_viewpad_on_view_unregistered(XfdashboardViewpad *self,
-														GType inViewType,
+														const gchar *inID,
 														gpointer inUserData)
 {
 	XfdashboardViewpadPrivate	*priv;
@@ -726,6 +731,7 @@ static void _xfdashboard_viewpad_on_view_unregistered(XfdashboardViewpad *self,
 	ClutterActor				*firstActivatableView;
 
 	g_return_if_fail(XFDASHBOARD_IS_VIEWPAD(self));
+	g_return_if_fail(inID && *inID);
 
 	priv=self->priv;
 	firstActivatableView=NULL;
@@ -740,7 +746,7 @@ static void _xfdashboard_viewpad_on_view_unregistered(XfdashboardViewpad *self,
 		/* If child is not of type being unregistered it will get
 		 * the first activatable view after we destroyed all views found.
 		 */
-		if(G_OBJECT_TYPE(child)!=inViewType)
+		if(xfdashboard_view_has_id(XFDASHBOARD_VIEW(child), inID)==FALSE)
 		{
 			if(xfdashboard_view_get_enabled(XFDASHBOARD_VIEW(child))) firstActivatableView=child;
 		}
@@ -1329,12 +1335,12 @@ static void xfdashboard_viewpad_init(XfdashboardViewpad *self)
 	views=viewEntry=xfdashboard_view_manager_get_registered(priv->viewManager);
 	for(; viewEntry; viewEntry=g_list_next(viewEntry))
 	{
-		GType					viewType;
+		const gchar				*viewID;
 
-		viewType=(GType)GPOINTER_TO_GTYPE(viewEntry->data);
-		_xfdashboard_viewpad_add_view(self, viewType);
+		viewID=(const gchar*)viewEntry->data;
+		_xfdashboard_viewpad_add_view(self, viewID);
 	}
-	g_list_free(views);
+	g_list_free_full(views, g_free);
 
 	g_signal_connect_swapped(priv->viewManager, "registered", G_CALLBACK(_xfdashboard_viewpad_on_view_registered), self);
 	g_signal_connect_swapped(priv->viewManager, "unregistered", G_CALLBACK(_xfdashboard_viewpad_on_view_unregistered), self);
@@ -1457,14 +1463,15 @@ XfdashboardView* xfdashboard_viewpad_find_view_by_type(XfdashboardViewpad *self,
 	return(view);
 }
 
-/* Find view by internal name */
-XfdashboardView* xfdashboard_viewpad_find_view_by_name(XfdashboardViewpad *self, const gchar *inInternalName)
+/* Find view by ID */
+XfdashboardView* xfdashboard_viewpad_find_view_by_id(XfdashboardViewpad *self, const gchar *inID)
 {
 	ClutterActorIter			iter;
 	ClutterActor				*child;
 	XfdashboardView				*view;
 
 	g_return_val_if_fail(XFDASHBOARD_IS_VIEWPAD(self), NULL);
+	g_return_val_if_fail(inID && *inID, NULL);
 
 	view=NULL;
 
@@ -1474,7 +1481,7 @@ XfdashboardView* xfdashboard_viewpad_find_view_by_name(XfdashboardViewpad *self,
 	{
 		/* Check if child is a view and its internal name matches requested name */
 		if(XFDASHBOARD_IS_VIEW(child)==TRUE &&
-			g_strcmp0(xfdashboard_view_get_internal_name(XFDASHBOARD_VIEW(child)), inInternalName)==0)
+			xfdashboard_view_has_id(XFDASHBOARD_VIEW(child), inID)==0)
 		{
 			view=XFDASHBOARD_VIEW(child);
 		}
diff --git a/xfdashboard/viewpad.h b/xfdashboard/viewpad.h
index 955f31c..0946c12 100644
--- a/xfdashboard/viewpad.h
+++ b/xfdashboard/viewpad.h
@@ -80,7 +80,7 @@ void xfdashboard_viewpad_set_spacing(XfdashboardViewpad *self, gfloat inSpacing)
 GList* xfdashboard_viewpad_get_views(XfdashboardViewpad *self);
 gboolean xfdashboard_viewpad_has_view(XfdashboardViewpad *self, XfdashboardView *inView);
 XfdashboardView* xfdashboard_viewpad_find_view_by_type(XfdashboardViewpad *self, GType inType);
-XfdashboardView* xfdashboard_viewpad_find_view_by_name(XfdashboardViewpad *self, const gchar *inInternalName);
+XfdashboardView* xfdashboard_viewpad_find_view_by_id(XfdashboardViewpad *self, const gchar *inID);
 
 XfdashboardView* xfdashboard_viewpad_get_active_view(XfdashboardViewpad *self);
 void xfdashboard_viewpad_set_active_view(XfdashboardViewpad *self, XfdashboardView *inView);
diff --git a/xfdashboard/windows-view.c b/xfdashboard/windows-view.c
index b811c73..2458286 100644
--- a/xfdashboard/windows-view.c
+++ b/xfdashboard/windows-view.c
@@ -1938,7 +1938,6 @@ static void xfdashboard_windows_view_init(XfdashboardWindowsView *self)
 	priv->currentStageMonitorBindingID=0;
 
 	/* Set up view */
-	xfdashboard_view_set_internal_name(XFDASHBOARD_VIEW(self), "windows");
 	xfdashboard_view_set_name(XFDASHBOARD_VIEW(self), _("Windows"));
 	xfdashboard_view_set_icon(XFDASHBOARD_VIEW(self), DEFAULT_VIEW_ICON);
 	xfdashboard_view_set_view_fit_mode(XFDASHBOARD_VIEW(self), XFDASHBOARD_VIEW_FIT_MODE_BOTH);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list