|
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@9
|
22 |
#include <glib.h>
|
|
ali@9
|
23 |
#include <gtk/gtk.h>
|
|
ali@9
|
24 |
#include <plover-gtk/packagestore.h>
|
|
ali@9
|
25 |
#include "app-manager.h"
|
|
ali@9
|
26 |
|
|
ali@9
|
27 |
static gboolean plover_applications_visible_func(GtkTreeModel *model,
|
|
ali@9
|
28 |
GtkTreeIter *iter,gpointer data)
|
|
ali@9
|
29 |
{
|
|
ali@9
|
30 |
/* Visible if row is non-empty and package contains a .desktop file
|
|
ali@9
|
31 |
* in /usr/share/applications
|
|
ali@9
|
32 |
*/
|
|
ali@9
|
33 |
PloverPackage *package;
|
|
ali@9
|
34 |
GtkTreeModel *file_store;
|
|
ali@9
|
35 |
GtkTreeIter fi;
|
|
ali@9
|
36 |
gchar *name,*dir;
|
|
ali@9
|
37 |
gboolean visible=FALSE;
|
|
ali@9
|
38 |
gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1);
|
|
ali@9
|
39 |
if (package)
|
|
ali@9
|
40 |
{
|
|
ali@9
|
41 |
file_store=GTK_TREE_MODEL(plover_package_get_file_store(package));
|
|
ali@9
|
42 |
if (gtk_tree_model_get_iter_first(file_store,&fi))
|
|
ali@9
|
43 |
{
|
|
ali@9
|
44 |
do
|
|
ali@9
|
45 |
{
|
|
ali@9
|
46 |
gtk_tree_model_get(file_store,&fi,
|
|
ali@9
|
47 |
PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1);
|
|
ali@9
|
48 |
dir=g_path_get_dirname(name);
|
|
ali@9
|
49 |
if (!strcmp(dir,"/usr/share/applications") &&
|
|
ali@9
|
50 |
g_str_has_suffix(name,".desktop"))
|
|
ali@9
|
51 |
visible=TRUE;
|
|
ali@9
|
52 |
g_free(dir);
|
|
ali@9
|
53 |
g_free(name);
|
|
ali@9
|
54 |
} while(!visible && gtk_tree_model_iter_next(file_store,&fi));
|
|
ali@9
|
55 |
}
|
|
ali@9
|
56 |
}
|
|
ali@9
|
57 |
g_object_unref(package);
|
|
ali@9
|
58 |
return visible;
|
|
ali@9
|
59 |
}
|
|
ali@9
|
60 |
|
|
ali@9
|
61 |
GtkTreeModel *plover_applications_model_new(GtkTreeModel *installed)
|
|
ali@9
|
62 |
{
|
|
ali@9
|
63 |
GtkTreeModel *model;
|
|
ali@9
|
64 |
model=gtk_tree_model_filter_new(installed,NULL);
|
|
ali@9
|
65 |
gtk_tree_model_filter_set_visible_func(model,
|
|
ali@9
|
66 |
plover_applications_visible_func,NULL,NULL);
|
|
ali@9
|
67 |
return model;
|
|
ali@9
|
68 |
}
|