static void mex_search_plugin_update_history (MexSearchPlugin *self, const gchar *term) { gint i; gsize length; gchar *contents, *current; MexSearchPluginPrivate *priv = self->priv; const gchar *base_dir = mex_settings_get_config_dir (mex_settings_get_default ()); gchar *history_file = g_build_filename (base_dir, "search", "history", NULL); /* Read the history file contents */ /* TODO: Make this less rubbish? */ g_file_get_contents (history_file, &contents, &length, NULL); /* Prepend new search-term if appropriate */ if (term) { gint terms; gchar *path; gsize new_length; gsize term_len = strlen (term); gchar *new_contents = g_malloc (length + term_len + 1); memcpy (new_contents, term, term_len); new_contents[term_len] = '\n'; new_length = term_len + 1; /* Truncate list to 10 terms and remove duplicates */ if (contents) { i = 0; terms = 1; do { gint cur_len; char *eos = strchr (contents + i, '\n'); if (!eos) cur_len = strlen (contents + i); else cur_len = eos - (contents + i); if ((cur_len != term_len) || (strncmp (contents + i, term, term_len) != 0)) { memcpy (new_contents + new_length, contents + i, cur_len + 1); new_length += cur_len + 1; if (++terms >= 10) break; } if (!eos) break; i += cur_len + 1; } while (i < length); } new_contents[new_length++] = '\0'; /* Save new list */ path = g_path_get_dirname (history_file); g_mkdir_with_parents (path, 0755); g_free (path); g_file_set_contents (history_file, new_contents, new_length, NULL); /* Replace content with new content */ g_free (contents); contents = new_contents; length = new_length; } /* Empty current list */ mex_model_clear (MEX_MODEL (priv->history_model)); /* Populate with search history */ if (contents) { current = contents; while (current < contents + length) { MexContent *content = MEX_CONTENT (mex_program_new (priv->history_model)); gchar *end = g_utf8_strchr (current, -1, '\n'); if (end) *end = '\0'; if (*current) { mex_content_set_metadata (content, MEX_CONTENT_METADATA_TITLE, current); mex_content_set_metadata (content, MEX_CONTENT_METADATA_MIMETYPE, "x-mex/search"); mex_model_add_content (MEX_MODEL (priv->history_model), content); } if (end) current = end + 1; else break; } g_free (contents); } else { /* Add a default search so the column isn't hidden. * TODO: Have a way of inserting 'stock' content rather than doing * this, I suppose. */ MexContent *content = MEX_CONTENT (mex_program_new (priv->history_model)); mex_content_set_metadata (content, MEX_CONTENT_METADATA_TITLE, "MeeGo"); mex_content_set_metadata (content, MEX_CONTENT_METADATA_MIMETYPE, "x-mex/search"); mex_model_add_content (MEX_MODEL (priv->history_model), content); } }
/** * mex_init_load_plugins: * * Load the Grilo plugins. */ static void mex_init_load_grilo_plugins (void) { GrlPluginRegistry *registry; GError *error = NULL; gchar *settings; registry = grl_plugin_registry_get_default (); settings = mex_settings_find_config_file (mex_settings_get_default (), "grilo-system.conf"); if (settings) grl_plugin_registry_add_config_from_file (registry, settings, NULL); g_free (settings); settings = mex_settings_find_config_file (mex_settings_get_default (), "mex.conf"); /* Load plugins */ if (settings) { GKeyFile *mex_conf; gchar **enabled_plugins; mex_conf = g_key_file_new (); g_key_file_load_from_file (mex_conf, settings, G_KEY_FILE_NONE, NULL); enabled_plugins = g_key_file_get_string_list (mex_conf, "grilo-plugins", "enabled", NULL, NULL); g_key_file_free (mex_conf); if (enabled_plugins) { gint i; for (i=0; enabled_plugins[i]; i++) { if (!grl_plugin_registry_load_by_id (registry, enabled_plugins[i], &error)) { g_warning ("Tried to load specified grilo plugin: %s but failed: %s", enabled_plugins[i], (error) ? error->message : ""); if (error) g_clear_error (&error); } else { MEX_DEBUG ("Loaded grilo plugin: %s plugin", enabled_plugins[i]); } } g_strfreev (enabled_plugins); } else { MEX_DEBUG ("No enabled plugins in mex.conf, loading default plugins"); grilo_load_default_plugins (registry); } g_free (settings); } else { MEX_DEBUG ("No mex.conf found, loading default plugins"); grilo_load_default_plugins (registry); } }