app-manager/applications.c
changeset 22 5cbb66c24fc6
parent 9 8d3b1ddf789c
child 24 2b9f54d14cc2
     1.1 --- a/app-manager/applications.c	Sat Feb 20 12:11:02 2010 +0000
     1.2 +++ b/app-manager/applications.c	Fri Mar 23 20:29:50 2012 +0000
     1.3 @@ -19,21 +19,46 @@
     1.4  #include "config.h"
     1.5  #include <stdlib.h>
     1.6  #include <string.h>
     1.7 +#ifdef WIN32
     1.8 +#include <windows.h>
     1.9 +#endif
    1.10  #include <glib.h>
    1.11  #include <gtk/gtk.h>
    1.12  #include <plover-gtk/packagestore.h>
    1.13  #include "app-manager.h"
    1.14  
    1.15 +#ifdef WIN32
    1.16 +static BOOL CALLBACK plover_applications_visible_callback(HMODULE module,
    1.17 +  const char *type,char *name,long *param)
    1.18 +{
    1.19 +    gboolean *visible=(void *)param;
    1.20 +    if (!IS_INTRESOURCE(name) && !strcmp(name,"MAINICON"))
    1.21 +	*visible=TRUE;
    1.22 +    return !*visible;
    1.23 +}
    1.24 +#endif
    1.25 +
    1.26  static gboolean plover_applications_visible_func(GtkTreeModel *model,
    1.27    GtkTreeIter *iter,gpointer data)
    1.28  {
    1.29      /* Visible if row is non-empty and package contains a .desktop file
    1.30 -     * in /usr/share/applications
    1.31 +     * in /usr/share/applications (UNIX) or package contains a .exe file
    1.32 +     * which has a default application icon (MS-Windows).
    1.33       */
    1.34      PloverPackage *package;
    1.35      GtkTreeModel *file_store;
    1.36      GtkTreeIter fi;
    1.37 -    gchar *name,*dir;
    1.38 +    gchar *name;
    1.39 +#ifdef WIN32
    1.40 +    HMODULE module;
    1.41 +    DWORD flags=
    1.42 +#ifdef LOAD_LIBRARY_AS_IMAGE_RESOURCE
    1.43 +      LOAD_LIBRARY_AS_IMAGE_RESOURCE|
    1.44 +#endif
    1.45 +      LOAD_LIBRARY_AS_DATAFILE;
    1.46 +#else
    1.47 +    gchar *dir;
    1.48 +#endif
    1.49      gboolean visible=FALSE;
    1.50      gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1);
    1.51      if (package)
    1.52 @@ -45,11 +70,27 @@
    1.53  	    {
    1.54  		gtk_tree_model_get(file_store,&fi,
    1.55  		  PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1);
    1.56 +#ifdef WIN32
    1.57 +		if (g_str_has_suffix(name,".exe"))
    1.58 +		{
    1.59 +		    module=LoadLibraryExA(name,NULL,flags);
    1.60 +		    if (module)
    1.61 +		    {
    1.62 +			(void)EnumResourceNamesA(module,RT_ICON,
    1.63 +			  plover_applications_visible_callback,&visible);
    1.64 +			if (!visible)
    1.65 +			    (void)EnumResourceNamesA(module,RT_GROUP_ICON,
    1.66 +			      plover_applications_visible_callback,&visible);
    1.67 +			FreeLibrary(module);
    1.68 +		    }
    1.69 +		}
    1.70 +#else
    1.71  		dir=g_path_get_dirname(name);
    1.72  		if (!strcmp(dir,"/usr/share/applications") &&
    1.73  		  g_str_has_suffix(name,".desktop"))
    1.74  		    visible=TRUE;
    1.75  		g_free(dir);
    1.76 +#endif
    1.77  		g_free(name);
    1.78  	    } while(!visible && gtk_tree_model_iter_next(file_store,&fi));
    1.79  	}
    1.80 @@ -62,7 +103,7 @@
    1.81  {
    1.82      GtkTreeModel *model;
    1.83      model=gtk_tree_model_filter_new(installed,NULL);
    1.84 -    gtk_tree_model_filter_set_visible_func(model,
    1.85 +    gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
    1.86        plover_applications_visible_func,NULL,NULL);
    1.87      return model;
    1.88  }