[Xfce4-commits] [apps/xfdashboard] 01/01: Consider desktop files in sub-directories if not found via the application name directly

noreply at xfce.org noreply at xfce.org
Mon Sep 28 16:42:39 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 e2d0b150510d275edc08ba2433d3c6b3c629aa43
Author: Stephan Haller <nomad at froevel.de>
Date:   Mon Sep 28 16:38:55 2015 +0200

    Consider desktop files in sub-directories if not found via the application name directly
    
    If we cannot find an matching application from any window name (instance name, class name etc.) directly in application database consider it may located in a sub-directory, e.g. kile in kde4 resulting in a desktop file called 'kde4-kile.desktop'. Then create a glob pattern '*-<<NAME>>' and iterate through all registered applications in application database collecting all matching the glob pattern. If the resulting list contains exactly one application it should be the one we're looking for.
    
    This commit hopefully fixes GH #99
---
 xfdashboard/application-tracker.c |  118 ++++++++++++++++++++++++++-----------
 1 file changed, 82 insertions(+), 36 deletions(-)

diff --git a/xfdashboard/application-tracker.c b/xfdashboard/application-tracker.c
index 717d1f2..904d4a0 100644
--- a/xfdashboard/application-tracker.c
+++ b/xfdashboard/application-tracker.c
@@ -471,6 +471,7 @@ static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_nam
 	GAppInfo								*foundAppInfo;
 	gchar									**names;
 	gchar									**iter;
+	GList									*apps;
 
 	g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION_TRACKER(self), NULL);
 	g_return_val_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WINDOW(inWindow), NULL);
@@ -478,6 +479,9 @@ static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_nam
 	priv=self->priv;
 	foundAppInfo=NULL;
 
+	/* Get list of applications */
+	apps=xfdashboard_application_database_get_all_applications(priv->appDatabase);
+
 	/* Get window's names */
 	names=xfdashboard_window_tracker_window_get_instance_names(inWindow);
 
@@ -486,59 +490,95 @@ static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_nam
 	while(iter && *iter)
 	{
 		GAppInfo							*appInfo;
+		gchar								*iterName;
+		gchar								*iterNameLowerCase;
 
-		/* Lookup application from unmodified name */
-		if(g_str_has_suffix(*iter, ".desktop"))
-		{
-			appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, *iter);
-		}
-			else
-			{
-				gchar						*desktopID;
+		/* Build desktop ID from iterated name */
+		if(!g_str_has_suffix(*iter, ".desktop")) iterName=g_strconcat(*iter, ".desktop", NULL);
+			else iterName=g_strdup(*iter);
 
-				desktopID=g_strconcat(*iter, ".desktop", NULL);
-				appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, desktopID);
-				g_free(desktopID);
-			}
+		iterNameLowerCase=g_utf8_strdown(iterName, -1);
+
+		/* Lookup application from unmodified name */
+		appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, iterName);
 
 		/* Lookup application from to-lower-case converted name if previous
 		 * lookup with unmodified name failed.
 		 */
 		if(!appInfo)
 		{
-			gchar							*lowerDesktopID;
-
-			/* Convert name to lower case */
-			lowerDesktopID=g_utf8_strdown(*iter, -1);
+			/* Lookup application from lower-case name */
+			appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, iterNameLowerCase);
+		}
 
-			/* Lookup application from lower-case name. No need to add '.desktop'
-			 * as suffix as it was done before.
+		/* If no application was found for the name it may be an application
+		 * located in a subdirectory. Then the desktop ID is prefixed with
+		 * the subdirectory's name followed by a dash. So iterate through all
+		 * applications and lookup with glob pattern '*-' followed by name
+		 * and suffix '.desktop'.
+		 */
+		if(!appInfo)
+		{
+			GList							*iterApps;
+			GList							*foundSubdirApps;
+			gchar							*globName;
+			GPatternSpec					*globPattern;
+			GAppInfo						*globAppInfo;
+
+			/* Build glob pattern */
+			globName=g_strconcat("*-", iterNameLowerCase, NULL);
+			globPattern=g_pattern_spec_new(globName);
+
+			/* Iterate through application and collect applications matching
+			 * glob pattern.
 			 */
-			if(g_str_has_suffix(lowerDesktopID, ".desktop"))
+			foundSubdirApps=NULL;
+			for(iterApps=apps; iterApps; iterApps=g_list_next(iterApps))
 			{
-				appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, lowerDesktopID);
-			}
-				else
-				{
-					gchar					*desktopID;
+				if(!G_IS_APP_INFO(iterApps->data)) continue;
+				globAppInfo=G_APP_INFO(iterApps->data);
 
-					desktopID=g_strconcat(lowerDesktopID, ".desktop", NULL);
-					appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, desktopID);
-					g_free(desktopID);
+				if(g_pattern_match_string(globPattern, g_app_info_get_id(globAppInfo)))
+				{
+					foundSubdirApps=g_list_prepend(foundSubdirApps, globAppInfo);
+					g_debug("Found possible application '%s' for window '%s' using pattern '%s'",
+							g_app_info_get_id(globAppInfo),
+							xfdashboard_window_tracker_window_get_title(inWindow),
+							globName);
 				}
+			}
 
-			/* Free lower case of name */
-			g_free(lowerDesktopID);
-
-			/* If we still did not find an application continue with next
-			 * name in list.
+			/* If exactly one application was collected because it matched
+			 * the glob pattern then we found the application.
 			 */
-			if(!appInfo)
+			if(g_list_length(foundSubdirApps)==1)
 			{
-				/* Continue with next name in list */
-				iter++;
-				continue;
+				appInfo=G_APP_INFO(g_object_ref(G_OBJECT(foundSubdirApps->data)));
+
+				g_debug("Found exactly one application named '%s' for window '%s' using pattern '%s'",
+						g_app_info_get_id(globAppInfo),
+						xfdashboard_window_tracker_window_get_title(inWindow),
+						globName);
 			}
+
+			/* Release allocated resources */
+			if(foundSubdirApps) g_list_free(foundSubdirApps);
+			if(globPattern) g_pattern_spec_free(globPattern);
+			if(globName) g_free(globName);
+		}
+
+		/* If we still did not find an application continue with next
+		 * name in list.
+		 */
+		if(!appInfo)
+		{
+			/* Release allocated resources */
+			if(iterName) g_free(iterName);
+			if(iterNameLowerCase) g_free(iterNameLowerCase);
+
+			/* Continue with next name in list */
+			iter++;
+			continue;
 		}
 
 		/* Check if found application info matches previous one. If it does not match
@@ -553,9 +593,12 @@ static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_nam
 						g_app_info_get_id(appInfo));
 
 			/* Release allocated resources */
+			if(iterName) g_free(iterName);
+			if(iterNameLowerCase) g_free(iterNameLowerCase);
 			if(foundAppInfo) g_object_unref(foundAppInfo);
 			if(appInfo) g_object_unref(appInfo);
 			if(names) g_strfreev(names);
+			if(apps) g_list_free_full(apps, g_object_unref);
 
 			return(NULL);
 		}
@@ -564,6 +607,8 @@ static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_nam
 		if(!foundAppInfo) foundAppInfo=g_object_ref(appInfo);
 
 		/* Release allocated resources */
+		if(iterName) g_free(iterName);
+		if(iterNameLowerCase) g_free(iterNameLowerCase);
 		if(appInfo) g_object_unref(appInfo);
 
 		/* Continue with next name in list */
@@ -572,6 +617,7 @@ static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_nam
 
 	/* Release allocated resources */
 	if(names) g_strfreev(names);
+	if(apps) g_list_free_full(apps, g_object_unref);
 
 	/* Return found application info */
 	g_debug("Resolved window names of '%s' to desktop ID '%s'",

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


More information about the Xfce4-commits mailing list