1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/app-manager/applications.c Sat Feb 20 12:11:02 2010 +0000
1.3 @@ -0,0 +1,68 @@
1.4 +/*
1.5 + * Copyright (C) 2010 J. Ali Harlow <ali@juiblex.co.uk>
1.6 + *
1.7 + * This program is free software; you can redistribute it and/or modify
1.8 + * it under the terms of the GNU General Public License as published by
1.9 + * the Free Software Foundation; either version 2 of the License, or
1.10 + * (at your option) any later version.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License along
1.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
1.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.20 + */
1.21 +
1.22 +#include "config.h"
1.23 +#include <stdlib.h>
1.24 +#include <string.h>
1.25 +#include <glib.h>
1.26 +#include <gtk/gtk.h>
1.27 +#include <plover-gtk/packagestore.h>
1.28 +#include "app-manager.h"
1.29 +
1.30 +static gboolean plover_applications_visible_func(GtkTreeModel *model,
1.31 + GtkTreeIter *iter,gpointer data)
1.32 +{
1.33 + /* Visible if row is non-empty and package contains a .desktop file
1.34 + * in /usr/share/applications
1.35 + */
1.36 + PloverPackage *package;
1.37 + GtkTreeModel *file_store;
1.38 + GtkTreeIter fi;
1.39 + gchar *name,*dir;
1.40 + gboolean visible=FALSE;
1.41 + gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1);
1.42 + if (package)
1.43 + {
1.44 + file_store=GTK_TREE_MODEL(plover_package_get_file_store(package));
1.45 + if (gtk_tree_model_get_iter_first(file_store,&fi))
1.46 + {
1.47 + do
1.48 + {
1.49 + gtk_tree_model_get(file_store,&fi,
1.50 + PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1);
1.51 + dir=g_path_get_dirname(name);
1.52 + if (!strcmp(dir,"/usr/share/applications") &&
1.53 + g_str_has_suffix(name,".desktop"))
1.54 + visible=TRUE;
1.55 + g_free(dir);
1.56 + g_free(name);
1.57 + } while(!visible && gtk_tree_model_iter_next(file_store,&fi));
1.58 + }
1.59 + }
1.60 + g_object_unref(package);
1.61 + return visible;
1.62 +}
1.63 +
1.64 +GtkTreeModel *plover_applications_model_new(GtkTreeModel *installed)
1.65 +{
1.66 + GtkTreeModel *model;
1.67 + model=gtk_tree_model_filter_new(installed,NULL);
1.68 + gtk_tree_model_filter_set_visible_func(model,
1.69 + plover_applications_visible_func,NULL,NULL);
1.70 + return model;
1.71 +}