diff options
author | L. Pereira <l@tia.mat.br> | 2023-08-14 22:33:51 -0700 |
---|---|---|
committer | L. Pereira <l@tia.mat.br> | 2023-08-14 22:33:51 -0700 |
commit | 8d6c28b8ce4d9959f907c0a48c5032241654fbc8 (patch) | |
tree | ab41a708ea34e636e7252dacdd5e15c56f77e092 /shell | |
parent | a2ac044128305c426235de1b9d3f83ba27c36407 (diff) |
Add option to synchronize during startup
Diffstat (limited to 'shell')
-rw-r--r-- | shell/callbacks.c | 18 | ||||
-rw-r--r-- | shell/menu.c | 4 | ||||
-rw-r--r-- | shell/shell.c | 25 | ||||
-rw-r--r-- | shell/syncmanager.c | 59 |
4 files changed, 98 insertions, 8 deletions
diff --git a/shell/callbacks.c b/shell/callbacks.c index c6f7997f..9c281eaa 100644 --- a/shell/callbacks.c +++ b/shell/callbacks.c @@ -37,6 +37,24 @@ void cb_sync_manager() sync_manager_show(shell->window); } +void cb_sync_on_startup() +{ + gboolean setting = shell_action_get_active("SyncOnStartupAction"); + GKeyFile *key_file = g_key_file_new(); + + gchar *conf_path = g_build_filename(g_get_user_config_dir(), "hardinfo", + "settings.ini", NULL); + + g_key_file_load_from_file( + key_file, conf_path, + G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); + g_key_file_set_boolean(key_file, "Sync", "OnStartup", setting); + g_key_file_save_to_file(key_file, conf_path, NULL); + + g_free(conf_path); + g_key_file_free(key_file); +} + void cb_open_web_page() { uri_open("http://www.hardinfo.org"); diff --git a/shell/menu.c b/shell/menu.c index dee3aa4f..ed6a6078 100644 --- a/shell/menu.c +++ b/shell/menu.c @@ -102,6 +102,10 @@ static GtkToggleActionEntry toggle_entries[] = { N_("_Toolbar"), NULL, NULL, G_CALLBACK(cb_toolbar)}, + {"SyncOnStartupAction", NULL, + N_("Synchronize on startup"), NULL, + NULL, + G_CALLBACK(cb_sync_on_startup)}, }; /* Implement a handler for GtkUIManager's "add_widget" signal. The UI manager diff --git a/shell/shell.c b/shell/shell.c index 0993f8f7..0d08161f 100644 --- a/shell/shell.c +++ b/shell/shell.c @@ -722,6 +722,29 @@ select_first_tree_item(gpointer data) return FALSE; } +static void +check_for_updates(void) +{ + GKeyFile *key_file = g_key_file_new(); + + gchar *conf_path = g_build_filename(g_get_user_config_dir(), "hardinfo", + "settings.ini", NULL); + + g_key_file_load_from_file( + key_file, conf_path, + G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); + + gboolean setting = g_key_file_get_boolean(key_file, "Sync", "OnStartup", NULL); + shell_action_set_active("SyncOnStartupAction", setting); + + g_free(conf_path); + g_key_file_free(key_file); + + if (setting) { + sync_manager_update_on_startup(); + } +} + gboolean hardinfo_link(const gchar *uri) { /* Clicked link events pass through here on their * way to the default handler (xdg-open). @@ -792,6 +815,8 @@ void shell_init(GSList * modules) shell->tree->modules = modules ? modules : modules_load_all(); + check_for_updates(); + g_slist_foreach(shell->tree->modules, shell_add_modules_to_gui, shell->tree); gtk_tree_view_expand_all(GTK_TREE_VIEW(shell->tree->view)); diff --git a/shell/syncmanager.c b/shell/syncmanager.c index c5f0b986..396bce92 100644 --- a/shell/syncmanager.c +++ b/shell/syncmanager.c @@ -200,22 +200,24 @@ static SoupURI *sync_manager_get_proxy(void) return soup_uri_new(conf); } -static void sync_dialog_start_sync(SyncDialog *sd) +static void ensure_soup_session(void) { - gint nactions; - SyncNetAction *actions; - if (!session) { SoupURI *proxy = sync_manager_get_proxy(); session = soup_session_new_with_options( SOUP_SESSION_TIMEOUT, 10, SOUP_SESSION_PROXY_URI, proxy, NULL); - /* Crashes if we unref the proxy? O_o */ - /*if (proxy) - g_object_unref(proxy); */ } +} + +static void sync_dialog_start_sync(SyncDialog *sd) +{ + gint nactions; + SyncNetAction *actions; + + ensure_soup_session(); - loop = g_main_loop_new(NULL, TRUE); + loop = g_main_loop_new(NULL, FALSE); gtk_widget_hide(sd->button_sync); gtk_widget_hide(sd->button_priv_policy); @@ -647,4 +649,45 @@ static void sync_dialog_destroy(SyncDialog *sd) sync_dialog_netarea_destroy(sd->sna); g_free(sd); } + +static gboolean sync_one(gpointer data) +{ + SyncNetAction *sna = data; + + if (sna->entry->generate_contents_for_upload) + goto out; + + DEBUG("Syncronizing: %s", sna->entry->name); + + gchar *msg = g_strdup_printf(_("Synchronizing: %s"), _(sna->entry->name)); + shell_status_update(msg); + shell_status_pulse(); + g_free(msg); + + send_request_for_net_action(sna); + +out: + g_main_loop_unref(loop); + idle_free(sna); + + return FALSE; +} + +void sync_manager_update_on_startup(void) +{ + GSList *entry; + + ensure_soup_session(); + + loop = g_main_loop_new(NULL, FALSE); + + for (entry = entries; entry; entry = entry->next) { + SyncNetAction *action = g_new0(SyncNetAction, 1); + + action->entry = entry->data; + loop = g_main_loop_ref(loop); + + g_idle_add(sync_one, action); + } +} #endif /* HAS_LIBSOUP */ |