/* * Copyright (C) 2010 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #ifdef WIN32 #include #endif #include #include #include #include "app-manager.h" #ifdef WIN32 static BOOL CALLBACK plover_applications_visible_callback(HMODULE module, const char *type,char *name,long *param) { gboolean *visible=(void *)param; if (!IS_INTRESOURCE(name) && !strcmp(name,"MAINICON")) *visible=TRUE; return !*visible; } #endif static gboolean plover_applications_visible_func(GtkTreeModel *model, GtkTreeIter *iter,gpointer data) { /* Visible if row is non-empty and package contains a .desktop file * in /usr/share/applications (UNIX) or package contains a .exe file * which has a default application icon (MS-Windows). */ PloverPackage *package; GtkTreeModel *file_store; GtkTreeIter fi; gchar *name; #ifdef WIN32 HMODULE module; DWORD flags= #ifdef LOAD_LIBRARY_AS_IMAGE_RESOURCE LOAD_LIBRARY_AS_IMAGE_RESOURCE| #endif LOAD_LIBRARY_AS_DATAFILE; #else gchar *dir; #endif gboolean visible=FALSE; gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1); if (package) { file_store=GTK_TREE_MODEL(plover_package_get_file_store(package)); if (gtk_tree_model_get_iter_first(file_store,&fi)) { do { gtk_tree_model_get(file_store,&fi, PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1); #ifdef WIN32 if (g_str_has_suffix(name,".exe")) { module=LoadLibraryExA(name,NULL,flags); if (module) { (void)EnumResourceNamesA(module,RT_ICON, plover_applications_visible_callback,&visible); if (!visible) (void)EnumResourceNamesA(module,RT_GROUP_ICON, plover_applications_visible_callback,&visible); FreeLibrary(module); } } #else dir=g_path_get_dirname(name); if (!strcmp(dir,"/usr/share/applications") && g_str_has_suffix(name,".desktop")) visible=TRUE; g_free(dir); #endif g_free(name); } while(!visible && gtk_tree_model_iter_next(file_store,&fi)); } } g_object_unref(package); return visible; } GtkTreeModel *plover_applications_model_new(GtkTreeModel *installed) { GtkTreeModel *model; model=gtk_tree_model_filter_new(installed,NULL); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model), plover_applications_visible_func,NULL,NULL); return model; }