2010-05-19 11:11:26 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, 2010 Intel, Inc.
|
|
|
|
* Copyright (c) 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* The Control Center is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* The Control Center is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with the Control Center; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* Author: Thomas Wood <thos@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-12-13 17:16:57 +01:00
|
|
|
#include <gio/gdesktopappinfo.h>
|
|
|
|
|
2013-01-15 11:37:24 +01:00
|
|
|
#include "cc-shell-model.h"
|
|
|
|
#include "cc-util.h"
|
|
|
|
|
2010-06-03 11:47:36 +01:00
|
|
|
#define GNOME_SETTINGS_PANEL_ID_KEY "X-GNOME-Settings-Panel"
|
2010-09-30 13:29:23 +01:00
|
|
|
#define GNOME_SETTINGS_PANEL_CATEGORY GNOME_SETTINGS_PANEL_ID_KEY
|
2011-12-19 14:55:53 +01:00
|
|
|
#define GNOME_SETTINGS_PANEL_ID_KEYWORDS "Keywords"
|
2010-06-03 11:47:36 +01:00
|
|
|
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
G_DEFINE_TYPE (CcShellModel, cc_shell_model, GTK_TYPE_LIST_STORE)
|
|
|
|
|
2011-01-14 17:03:21 +00:00
|
|
|
static void
|
|
|
|
cc_shell_model_class_init (CcShellModelClass *klass)
|
|
|
|
{
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cc_shell_model_init (CcShellModel *self)
|
|
|
|
{
|
2013-01-15 11:37:24 +01:00
|
|
|
GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_APP_INFO, G_TYPE_STRING,
|
|
|
|
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ICON, G_TYPE_STRV};
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
gtk_list_store_set_column_types (GTK_LIST_STORE (self),
|
|
|
|
N_COLS, types);
|
2011-01-14 17:03:21 +00:00
|
|
|
|
2011-02-12 19:21:43 +00:00
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self), COL_NAME,
|
|
|
|
GTK_SORT_ASCENDING);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CcShellModel *
|
|
|
|
cc_shell_model_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CC_TYPE_SHELL_MODEL, NULL);
|
|
|
|
}
|
|
|
|
|
2013-01-15 11:37:24 +01:00
|
|
|
static char **
|
|
|
|
get_casefolded_keywords (GAppInfo *appinfo)
|
|
|
|
{
|
|
|
|
const char * const * keywords;
|
|
|
|
char **casefolded_keywords;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
keywords = g_desktop_app_info_get_keywords (G_DESKTOP_APP_INFO (appinfo));
|
|
|
|
n = keywords ? g_strv_length ((char**) keywords) : 0;
|
|
|
|
casefolded_keywords = g_new (char*, n+1);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
casefolded_keywords[i] = cc_util_normalize_casefold_and_unaccent (keywords[i]);
|
|
|
|
casefolded_keywords[n] = NULL;
|
|
|
|
|
|
|
|
return casefolded_keywords;
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
void
|
2012-12-13 17:16:57 +01:00
|
|
|
cc_shell_model_add_item (CcShellModel *model,
|
|
|
|
CcPanelCategory category,
|
|
|
|
GAppInfo *appinfo,
|
|
|
|
const char *id)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2011-07-22 13:05:01 +02:00
|
|
|
GIcon *icon = g_app_info_get_icon (appinfo);
|
|
|
|
const gchar *name = g_app_info_get_name (appinfo);
|
|
|
|
const gchar *comment = g_app_info_get_description (appinfo);
|
2013-01-15 11:37:24 +01:00
|
|
|
char **keywords;
|
|
|
|
char *casefolded_name, *casefolded_description;
|
2010-06-03 11:47:36 +01:00
|
|
|
|
2013-01-15 11:37:24 +01:00
|
|
|
casefolded_name = cc_util_normalize_casefold_and_unaccent (name);
|
|
|
|
casefolded_description = cc_util_normalize_casefold_and_unaccent (comment);
|
|
|
|
keywords = get_casefolded_keywords (appinfo);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, 0,
|
|
|
|
COL_NAME, name,
|
2013-01-15 11:37:24 +01:00
|
|
|
COL_CASEFOLDED_NAME, casefolded_name,
|
|
|
|
COL_APP, appinfo,
|
2010-05-19 11:11:26 +01:00
|
|
|
COL_ID, id,
|
2012-12-13 17:16:57 +01:00
|
|
|
COL_CATEGORY, category,
|
2011-08-26 13:59:23 +01:00
|
|
|
COL_DESCRIPTION, comment,
|
2013-01-15 11:37:24 +01:00
|
|
|
COL_CASEFOLDED_DESCRIPTION, casefolded_description,
|
2011-07-22 13:05:01 +02:00
|
|
|
COL_GICON, icon,
|
2010-11-15 13:16:25 -05:00
|
|
|
COL_KEYWORDS, keywords,
|
2010-05-19 11:11:26 +01:00
|
|
|
-1);
|
2013-01-15 11:37:24 +01:00
|
|
|
|
|
|
|
g_free (casefolded_name);
|
|
|
|
g_free (casefolded_description);
|
|
|
|
g_strfreev (keywords);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cc_shell_model_iter_matches_search (CcShellModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
const char *term)
|
|
|
|
{
|
|
|
|
gchar *name, *description;
|
|
|
|
gboolean result;
|
|
|
|
gchar **keywords;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (model), iter,
|
|
|
|
COL_CASEFOLDED_NAME, &name,
|
|
|
|
COL_CASEFOLDED_DESCRIPTION, &description,
|
|
|
|
COL_KEYWORDS, &keywords,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
result = (strstr (name, term) != NULL);
|
|
|
|
|
|
|
|
if (!result && description)
|
|
|
|
result = (strstr (description, term) != NULL);
|
|
|
|
|
|
|
|
if (!result && keywords)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; !result && keywords[i]; i++)
|
|
|
|
result = (strstr (keywords[i], term) == keywords[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
g_free (description);
|
|
|
|
g_strfreev (keywords);
|
|
|
|
|
|
|
|
return result;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|