|
ali@9
|
1 |
/*
|
|
ali@9
|
2 |
* Copyright (C) 2010 J. Ali Harlow <ali@juiblex.co.uk>
|
|
ali@9
|
3 |
*
|
|
ali@9
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
ali@9
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
ali@9
|
6 |
* the Free Software Foundation; either version 2 of the License, or
|
|
ali@9
|
7 |
* (at your option) any later version.
|
|
ali@9
|
8 |
*
|
|
ali@9
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
ali@9
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
ali@9
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
ali@9
|
12 |
* GNU General Public License for more details.
|
|
ali@9
|
13 |
*
|
|
ali@9
|
14 |
* You should have received a copy of the GNU General Public License along
|
|
ali@9
|
15 |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
ali@9
|
16 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
ali@9
|
17 |
*/
|
|
ali@9
|
18 |
|
|
ali@9
|
19 |
#include "config.h"
|
|
ali@9
|
20 |
#include <stdlib.h>
|
|
ali@9
|
21 |
#include <string.h>
|
|
ali@10
|
22 |
#ifdef WIN32
|
|
ali@10
|
23 |
#include <windows.h>
|
|
ali@10
|
24 |
#endif
|
|
ali@9
|
25 |
#include <glib.h>
|
|
ali@9
|
26 |
#include <gtk/gtk.h>
|
|
ali@9
|
27 |
#include <plover-gtk/packagestore.h>
|
|
ali@24
|
28 |
#include <plover-gtk/packagefilestore.h>
|
|
ali@9
|
29 |
#include "app-manager.h"
|
|
ali@9
|
30 |
|
|
ali@10
|
31 |
#ifdef WIN32
|
|
ali@10
|
32 |
static BOOL CALLBACK plover_applications_visible_callback(HMODULE module,
|
|
ali@99
|
33 |
const char *type,char *name,LONG_PTR param)
|
|
ali@10
|
34 |
{
|
|
ali@10
|
35 |
gboolean *visible=(void *)param;
|
|
ali@10
|
36 |
if (!IS_INTRESOURCE(name) && !strcmp(name,"MAINICON"))
|
|
ali@10
|
37 |
*visible=TRUE;
|
|
ali@10
|
38 |
return !*visible;
|
|
ali@10
|
39 |
}
|
|
ali@10
|
40 |
#endif
|
|
ali@10
|
41 |
|
|
ali@9
|
42 |
static gboolean plover_applications_visible_func(GtkTreeModel *model,
|
|
ali@9
|
43 |
GtkTreeIter *iter,gpointer data)
|
|
ali@9
|
44 |
{
|
|
ali@9
|
45 |
/* Visible if row is non-empty and package contains a .desktop file
|
|
ali@10
|
46 |
* in /usr/share/applications (UNIX) or package contains a .exe file
|
|
ali@10
|
47 |
* which has a default application icon (MS-Windows).
|
|
ali@9
|
48 |
*/
|
|
ali@9
|
49 |
PloverPackage *package;
|
|
ali@9
|
50 |
GtkTreeModel *file_store;
|
|
ali@9
|
51 |
GtkTreeIter fi;
|
|
ali@10
|
52 |
gchar *name;
|
|
ali@10
|
53 |
#ifdef WIN32
|
|
ali@10
|
54 |
HMODULE module;
|
|
ali@10
|
55 |
DWORD flags=
|
|
ali@10
|
56 |
#ifdef LOAD_LIBRARY_AS_IMAGE_RESOURCE
|
|
ali@10
|
57 |
LOAD_LIBRARY_AS_IMAGE_RESOURCE|
|
|
ali@10
|
58 |
#endif
|
|
ali@10
|
59 |
LOAD_LIBRARY_AS_DATAFILE;
|
|
ali@10
|
60 |
#else
|
|
ali@10
|
61 |
gchar *dir;
|
|
ali@10
|
62 |
#endif
|
|
ali@9
|
63 |
gboolean visible=FALSE;
|
|
ali@9
|
64 |
gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1);
|
|
ali@9
|
65 |
if (package)
|
|
ali@9
|
66 |
{
|
|
ali@24
|
67 |
file_store=
|
|
ali@24
|
68 |
GTK_TREE_MODEL(plover_package_file_store_new_from_package(package));
|
|
ali@9
|
69 |
if (gtk_tree_model_get_iter_first(file_store,&fi))
|
|
ali@9
|
70 |
{
|
|
ali@9
|
71 |
do
|
|
ali@9
|
72 |
{
|
|
ali@9
|
73 |
gtk_tree_model_get(file_store,&fi,
|
|
ali@9
|
74 |
PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1);
|
|
ali@10
|
75 |
#ifdef WIN32
|
|
ali@10
|
76 |
if (g_str_has_suffix(name,".exe"))
|
|
ali@10
|
77 |
{
|
|
ali@10
|
78 |
module=LoadLibraryExA(name,NULL,flags);
|
|
ali@10
|
79 |
if (module)
|
|
ali@10
|
80 |
{
|
|
ali@10
|
81 |
(void)EnumResourceNamesA(module,RT_ICON,
|
|
ali@99
|
82 |
plover_applications_visible_callback,
|
|
ali@99
|
83 |
(LONG_PTR)&visible);
|
|
ali@10
|
84 |
if (!visible)
|
|
ali@10
|
85 |
(void)EnumResourceNamesA(module,RT_GROUP_ICON,
|
|
ali@99
|
86 |
plover_applications_visible_callback,
|
|
ali@99
|
87 |
(LONG_PTR)&visible);
|
|
ali@10
|
88 |
FreeLibrary(module);
|
|
ali@10
|
89 |
}
|
|
ali@10
|
90 |
}
|
|
ali@10
|
91 |
#else
|
|
ali@9
|
92 |
dir=g_path_get_dirname(name);
|
|
ali@9
|
93 |
if (!strcmp(dir,"/usr/share/applications") &&
|
|
ali@9
|
94 |
g_str_has_suffix(name,".desktop"))
|
|
ali@9
|
95 |
visible=TRUE;
|
|
ali@9
|
96 |
g_free(dir);
|
|
ali@10
|
97 |
#endif
|
|
ali@9
|
98 |
g_free(name);
|
|
ali@9
|
99 |
} while(!visible && gtk_tree_model_iter_next(file_store,&fi));
|
|
ali@9
|
100 |
}
|
|
ali@24
|
101 |
g_object_unref(file_store);
|
|
ali@9
|
102 |
}
|
|
ali@9
|
103 |
g_object_unref(package);
|
|
ali@9
|
104 |
return visible;
|
|
ali@9
|
105 |
}
|
|
ali@9
|
106 |
|
|
ali@9
|
107 |
GtkTreeModel *plover_applications_model_new(GtkTreeModel *installed)
|
|
ali@9
|
108 |
{
|
|
ali@9
|
109 |
GtkTreeModel *model;
|
|
ali@9
|
110 |
model=gtk_tree_model_filter_new(installed,NULL);
|
|
ali@10
|
111 |
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
|
|
ali@9
|
112 |
plover_applications_visible_func,NULL,NULL);
|
|
ali@9
|
113 |
return model;
|
|
ali@9
|
114 |
}
|