[tracker-miners: 1/4] tracker-miner-rss: split the main function for readability
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners: 1/4] tracker-miner-rss: split the main function for readability
- Date: Sun, 7 Aug 2022 13:15:47 +0000 (UTC)
commit b64102feab3678f0414bf59772120d11cc2f9043
Author: Éloi Rivard <eloi rivard aquilenet fr>
Date: Mon Jun 20 18:42:53 2022 +0200
tracker-miner-rss: split the main function for readability
src/miners/rss/tracker-main.c | 177 +++++++++++++++++++++++-------------------
1 file changed, 97 insertions(+), 80 deletions(-)
---
diff --git a/src/miners/rss/tracker-main.c b/src/miners/rss/tracker-main.c
index 87a8dc605..25531fb13 100644
--- a/src/miners/rss/tracker-main.c
+++ b/src/miners/rss/tracker-main.c
@@ -119,34 +119,11 @@ setup_connection_and_endpoint (TrackerDomainOntology *domain,
}
int
-main (int argc, char **argv)
+handle_add_feed_option(GOptionContext *context)
{
- GMainLoop *loop;
- GOptionContext *context;
- TrackerMinerRSS *miner;
GError *error = NULL;
- GDBusConnection *connection;
- TrackerSparqlConnection *sparql_conn;
- TrackerEndpointDBus *endpoint;
- TrackerMinerProxy *proxy;
- TrackerDomainOntology *domain_ontology;
- gchar *domain_name, *dbus_name;
-
- setlocale (LC_ALL, "");
-
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
- tzset ();
-
- /* Translators: this messagge will apper immediately after the
- * usage string - Usage: COMMAND <THIS_MESSAGE>
- */
- context = g_option_context_new (_("— start the feeds indexer"));
- g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
- if (title && !add_feed) {
+ if (!add_feed) {
gchar *help;
help = g_option_context_get_help (context, TRUE, NULL);
@@ -157,64 +134,73 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
- g_option_context_free (context);
-
/* Command line stuff doesn't use logging, so we're using g_print*() */
- if (add_feed) {
- TrackerSparqlConnection *connection;
- GString *query;
-
- g_print ("Adding feed:\n"
- " title:'%s'\n"
- " url:'%s'\n",
- title,
- add_feed);
-
- connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.RSS",
- NULL, NULL, &error);
-
- if (!connection) {
- g_printerr ("%s: %s\n",
- _("Could not establish a connection to Tracker"),
- error ? error->message : _("No error given"));
- g_clear_error (&error);
- return EXIT_FAILURE;
- }
-
- /* FIXME: Make interval configurable */
- query = g_string_new ("INSERT {"
- " _:FeedSettings a mfo:FeedSettings ;"
- " mfo:updateInterval 20 ."
- " _:Feed a nie:DataObject, mfo:FeedChannel ;"
- " mfo:feedSettings _:FeedSettings ;");
-
- if (title) {
- g_string_append_printf (query, "nie:title \"%s\";", title);
- }
-
- g_string_append_printf (query, " nie:url \"%s\" }", add_feed);
-
- tracker_sparql_connection_update (connection,
- query->str,
- NULL,
- &error);
- g_string_free (query, TRUE);
-
- if (error) {
- g_printerr ("%s, %s\n",
- _("Could not add feed"),
- error->message);
- g_error_free (error);
- g_object_unref (connection);
-
- return EXIT_FAILURE;
- }
-
- g_print ("Done\n");
-
- return EXIT_SUCCESS;
+ TrackerSparqlConnection *connection;
+ GString *query;
+
+ g_print ("Adding feed:\n"
+ " title:'%s'\n"
+ " url:'%s'\n",
+ title,
+ add_feed);
+
+ connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.RSS",
+ NULL, NULL, &error);
+
+ if (!connection) {
+ g_printerr ("%s: %s\n",
+ _("Could not establish a connection to Tracker"),
+ error ? error->message : _("No error given"));
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ /* FIXME: Make interval configurable */
+ query = g_string_new ("INSERT {"
+ " _:FeedSettings a mfo:FeedSettings ;"
+ " mfo:updateInterval 20 ."
+ " _:Feed a nie:DataObject, mfo:FeedChannel ;"
+ " mfo:feedSettings _:FeedSettings ;");
+
+ if (title)
+ g_string_append_printf (query, "nie:title \"%s\";", title);
+
+ g_string_append_printf (query, " nie:url \"%s\" }", add_feed);
+
+ tracker_sparql_connection_update (connection,
+ query->str,
+ NULL,
+ &error);
+ g_string_free (query, TRUE);
+
+ if (error) {
+ g_printerr ("%s, %s\n",
+ _("Could not add feed"),
+ error->message);
+ g_error_free (error);
+ g_object_unref (connection);
+
+ return EXIT_FAILURE;
}
+ g_print ("Done\n");
+
+ return EXIT_SUCCESS;
+}
+
+int
+handle_default()
+{
+ GMainLoop *loop;
+ TrackerMinerRSS *miner;
+ GError *error = NULL;
+ GDBusConnection *connection;
+ TrackerSparqlConnection *sparql_conn;
+ TrackerEndpointDBus *endpoint;
+ TrackerMinerProxy *proxy;
+ TrackerDomainOntology *domain_ontology;
+ gchar *domain_name, *dbus_name;
+
domain_ontology = tracker_domain_ontology_new (domain_ontology_name, NULL, &error);
if (error) {
g_critical ("Could not load domain ontology '%s': %s",
@@ -300,3 +286,34 @@ main (int argc, char **argv)
return EXIT_SUCCESS;
}
+
+void
+setup_locale() {
+ setlocale (LC_ALL, "");
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+ tzset ();
+}
+
+int
+main (int argc, char **argv)
+{
+ GOptionContext *context;
+
+ setup_locale();
+
+ /* Translators: this messagge will apper immediately after the
+ * usage string - Usage: COMMAND <THIS_MESSAGE>
+ */
+ context = g_option_context_new (_("— start the feeds indexer"));
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+
+ g_option_context_free (context);
+
+ if (add_feed)
+ return handle_add_feed_option(context);
+
+ return handle_default();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]