summaryrefslogtreecommitdiff
path: root/lib/ephy-search-engine-manager.c
diff options
context:
space:
mode:
authorvanadiae <vanadiae35@gmail.com>2020-06-24 19:19:51 +0200
committerJan-Michael Brummer <jan.brummer@tabos.org>2020-09-28 17:47:55 +0000
commit87fbb71e3e7dd04137447b240e6292b7efe2056f (patch)
treece134b0c90e344901c0e02eae67dbe945b4363a9 /lib/ephy-search-engine-manager.c
parentcc9535c7cb59eaaf1003e4cdd254fc082ccdb752 (diff)
downloadepiphany-87fbb71e3e7dd04137447b240e6292b7efe2056f.tar.gz
prefs-search-engines: replace dialog with inline list box
The old search engines dialog had a terrible look so this commit replaces it with a list box with expandable rows, that let see and edit the various informations (name, address, etc.). It also allows to select the default search engine, used when no engine is selected when doing a search in the search bar. Fixes #631 Fixes #441
Diffstat (limited to 'lib/ephy-search-engine-manager.c')
-rw-r--r--lib/ephy-search-engine-manager.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/ephy-search-engine-manager.c b/lib/ephy-search-engine-manager.c
index a5872db8d..7f9c5eb49 100644
--- a/lib/ephy-search-engine-manager.c
+++ b/lib/ephy-search-engine-manager.c
@@ -213,6 +213,23 @@ ephy_search_engine_manager_get_names (EphySearchEngineManager *manager)
return search_engine_names;
}
+/**
+ * ephy_search_engine_manager_engine_exists:
+ *
+ * Checks if search engine @name exists in @manager.
+ *
+ * @manager: the #EphySearchEngineManager
+ * @name: the name of the search engine
+ *
+ * Returns: %TRUE if the search engine was found, %FALSE otherwise.
+ */
+gboolean
+ephy_search_engine_manager_engine_exists (EphySearchEngineManager *manager,
+ const char *name)
+{
+ return !!g_hash_table_lookup (manager->search_engines, name);
+}
+
char **
ephy_search_engine_manager_get_bangs (EphySearchEngineManager *manager)
{
@@ -275,6 +292,43 @@ ephy_search_engine_manager_delete_engine (EphySearchEngineManager *manager,
ephy_search_engine_manager_apply_settings (manager);
}
+/**
+ * ephy_search_engine_manager_rename:
+ *
+ * Renames search engine @old_name to @new_name, taking care of setting it back
+ * as default search engine if needed.
+ *
+ * @manager: a #EphySearchEngineManager
+ * @old_name: the current name of the search engine
+ * @new_name: the new name for search engine @old_name
+ *
+ * Returns: %FALSE if there wasn't any renaming to do (if both old and new names
+ * were the same), %TRUE if the search engine was renamed.
+ */
+gboolean
+ephy_search_engine_manager_rename (EphySearchEngineManager *manager,
+ const char *old_name,
+ const char *new_name)
+{
+ EphySearchEngineInfo *info, *info_copy;
+
+ if (g_strcmp0 (old_name, new_name) == 0)
+ return FALSE;
+
+ info = g_hash_table_lookup (manager->search_engines, old_name);
+ g_assert_nonnull (info);
+
+ info_copy = ephy_search_engine_info_new (info->address, info->bang);
+ g_hash_table_remove (manager->search_engines, old_name);
+ g_hash_table_insert (manager->search_engines, g_strdup (new_name), info_copy);
+ /* Set the search engine back as default engine if it was the default one. */
+ if (g_strcmp0 (ephy_search_engine_manager_get_default_engine (manager), old_name) == 0)
+ ephy_search_engine_manager_set_default_engine (manager, new_name);
+ ephy_search_engine_manager_apply_settings (manager);
+
+ return TRUE;
+}
+
void
ephy_search_engine_manager_modify_engine (EphySearchEngineManager *manager,
const char *name,
@@ -283,6 +337,9 @@ ephy_search_engine_manager_modify_engine (EphySearchEngineManager *manager,
{
EphySearchEngineInfo *info;
+ /* You can't modify a non-existant search engine. */
+ g_assert (g_hash_table_contains (manager->search_engines, name));
+
info = ephy_search_engine_info_new (address, bang);
g_hash_table_replace (manager->search_engines,
g_strdup (name),