app-manager/applications.c
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Feb 20 12:11:02 2010 +0000 (2010-02-20)
changeset 9 8d3b1ddf789c
child 10 8b50be3e2998
permissions -rw-r--r--
First cut at an applications manager
     1 /*
     2  * Copyright (C) 2010  J. Ali Harlow <ali@juiblex.co.uk>
     3  *
     4  * This program is free software; you can redistribute it and/or modify
     5  * it under the terms of the GNU General Public License as published by
     6  * the Free Software Foundation; either version 2 of the License, or
     7  * (at your option) any later version.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License along
    15  * with this program; if not, write to the Free Software Foundation, Inc.,
    16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    17  */
    18 
    19 #include "config.h"
    20 #include <stdlib.h>
    21 #include <string.h>
    22 #include <glib.h>
    23 #include <gtk/gtk.h>
    24 #include <plover-gtk/packagestore.h>
    25 #include "app-manager.h"
    26 
    27 static gboolean plover_applications_visible_func(GtkTreeModel *model,
    28   GtkTreeIter *iter,gpointer data)
    29 {
    30     /* Visible if row is non-empty and package contains a .desktop file
    31      * in /usr/share/applications
    32      */
    33     PloverPackage *package;
    34     GtkTreeModel *file_store;
    35     GtkTreeIter fi;
    36     gchar *name,*dir;
    37     gboolean visible=FALSE;
    38     gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1);
    39     if (package)
    40     {
    41 	file_store=GTK_TREE_MODEL(plover_package_get_file_store(package));
    42 	if (gtk_tree_model_get_iter_first(file_store,&fi))
    43 	{
    44 	    do
    45 	    {
    46 		gtk_tree_model_get(file_store,&fi,
    47 		  PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1);
    48 		dir=g_path_get_dirname(name);
    49 		if (!strcmp(dir,"/usr/share/applications") &&
    50 		  g_str_has_suffix(name,".desktop"))
    51 		    visible=TRUE;
    52 		g_free(dir);
    53 		g_free(name);
    54 	    } while(!visible && gtk_tree_model_iter_next(file_store,&fi));
    55 	}
    56     }
    57     g_object_unref(package);
    58     return visible;
    59 }
    60 
    61 GtkTreeModel *plover_applications_model_new(GtkTreeModel *installed)
    62 {
    63     GtkTreeModel *model;
    64     model=gtk_tree_model_filter_new(installed,NULL);
    65     gtk_tree_model_filter_set_visible_func(model,
    66       plover_applications_visible_func,NULL,NULL);
    67     return model;
    68 }