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