about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-08-02 10:23:13 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-08-02 10:23:13 +0200
commit658e36a06618dd48798133983c4a234e747834ad (patch)
tree6355ffa39185e5b17c9f5dee1f720636d2016cef
parentd4150eb7d15c3a8674eaf78a212209381ed95ee9 (diff)
downloadprofani-tty-658e36a06618dd48798133983c4a234e747834ad.tar.gz
Add 'save' command to save preferences
Most applications have an 'apply changes' button. This makes testing
easier too.

Implement https://github.com/profanity-im/profanity/issues/1164
-rw-r--r--src/command/cmd_defs.c13
-rw-r--r--src/command/cmd_defs.h1
-rw-r--r--src/command/cmd_funcs.c10
-rw-r--r--src/command/cmd_funcs.h2
-rw-r--r--src/config/preferences.c52
-rw-r--r--src/config/preferences.h2
6 files changed, 34 insertions, 46 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index efe2bad0..358b3472 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2393,6 +2393,19 @@ static struct cmd_t command_defs[] =
             "/omemo untrust buddy@buddychat.org c4f9c875-144d7a3b-0c4a05b6-ca3be51a-a037f329-0bd3ae62-07f99719-55559d2a",
             "/omemo char *")
     },
+
+    { "/save",
+        parse_args, 0, 0, NULL,
+        CMD_NOSUBFUNCS
+        CMD_MAINFUNC(cmd_save)
+        CMD_NOTAGS
+        CMD_SYN(
+            "/save")
+        CMD_DESC(
+            "Save preferences to configuration file.")
+        CMD_NOARGS
+        CMD_NOEXAMPLES
+    },
 };
 
 static GHashTable *search_index;
diff --git a/src/command/cmd_defs.h b/src/command/cmd_defs.h
index e6ce1053..fb3a12c4 100644
--- a/src/command/cmd_defs.h
+++ b/src/command/cmd_defs.h
@@ -2,6 +2,7 @@
  * cmd_defs.h
  *
  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
+ * Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
  *
  * This file is part of Profanity.
  *
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index b2893633..a64e70b2 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -2,6 +2,7 @@
  * cmd_funcs.c
  *
  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
+ * Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
  *
  * This file is part of Profanity.
  *
@@ -8535,3 +8536,12 @@ cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args)
     return TRUE;
 #endif
 }
+
+gboolean
+cmd_save(ProfWin *window, const char *const command, gchar **args)
+{
+    log_info("Saving preferences to configuration file");
+    cons_show("Saving preferences.");
+    prefs_save();
+    return TRUE;
+}
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 8f8d60a9..c623ca83 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -2,6 +2,7 @@
  * cmd_funcs.h
  *
  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
+ * Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
  *
  * This file is part of Profanity.
  *
@@ -225,4 +226,5 @@ gboolean cmd_omemo_untrust(ProfWin *window, const char *const command, gchar **a
 gboolean cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_clear_device_list(ProfWin *window, const char *const command, gchar **args);
 
+gboolean cmd_save(ProfWin *window, const char *const command, gchar **args);
 #endif
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 68ebdc0c..80b6cc15 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -176,6 +176,12 @@ prefs_load(void)
 }
 
 void
+prefs_save(void)
+{
+    _save_prefs();
+}
+
+void
 prefs_close(void)
 {
     autocomplete_free(boolean_choice_ac);
@@ -334,21 +340,18 @@ void
 prefs_set_room_notify(const char *const roomjid, gboolean value)
 {
     g_key_file_set_boolean(prefs, roomjid, "notify", value);
-    _save_prefs();
 }
 
 void
 prefs_set_room_notify_mention(const char *const roomjid, gboolean value)
 {
     g_key_file_set_boolean(prefs, roomjid, "notify.mention", value);
-    _save_prefs();
 }
 
 void
 prefs_set_room_notify_trigger(const char *const roomjid, gboolean value)
 {
     g_key_file_set_boolean(prefs, roomjid, "notify.trigger", value);
-    _save_prefs();
 }
 
 gboolean
@@ -392,7 +395,6 @@ prefs_reset_room_notify(const char *const roomjid)
 {
     if (g_key_file_has_group(prefs, roomjid)) {
         g_key_file_remove_group(prefs, roomjid, NULL);
-        _save_prefs();
         return TRUE;
     }
 
@@ -419,7 +421,6 @@ prefs_set_boolean(preference_t pref, gboolean value)
     const char *group = _get_group(pref);
     const char *key = _get_key(pref);
     g_key_file_set_boolean(prefs, group, key, value);
-    _save_prefs();
 }
 
 char*
@@ -460,7 +461,6 @@ prefs_set_string(preference_t pref, char *value)
     } else {
         g_key_file_set_string(prefs, group, key, value);
     }
-    _save_prefs();
 }
 
 char*
@@ -512,7 +512,6 @@ void
 prefs_set_gone(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_CHATSTATES, "gone", value);
-    _save_prefs();
 }
 
 gint
@@ -525,7 +524,6 @@ void
 prefs_set_notify_remind(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "remind", value);
-    _save_prefs();
 }
 
 gint
@@ -542,7 +540,6 @@ prefs_set_max_log_size(gint value)
 {
     log_maxsize = value;
     g_key_file_set_integer(prefs, PREF_GROUP_LOGGING, "maxsize", value);
-    _save_prefs();
 }
 
 gint
@@ -560,7 +557,6 @@ void
 prefs_set_inpblock(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "inpblock", value);
-    _save_prefs();
 }
 
 gint
@@ -577,7 +573,6 @@ void
 prefs_set_reconnect(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "reconnect", value);
-    _save_prefs();
 }
 
 gint
@@ -594,7 +589,6 @@ void
 prefs_set_autoping(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "autoping", value);
-    _save_prefs();
 }
 
 gint
@@ -611,7 +605,6 @@ void
 prefs_set_autoping_timeout(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "autoping.timeout", value);
-    _save_prefs();
 }
 
 gint
@@ -636,21 +629,18 @@ void
 prefs_set_autoaway_time(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.awaytime", value);
-    _save_prefs();
 }
 
 void
 prefs_set_autoxa_time(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.xatime", value);
-    _save_prefs();
 }
 
 void
 prefs_set_tray_timer(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "tray.timer", value);
-    _save_prefs();
 }
 
 gint
@@ -679,7 +669,6 @@ void
 prefs_set_statusbartabs(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "statusbar.tabs", value);
-    _save_prefs();
 }
 
 gint
@@ -696,7 +685,6 @@ void
 prefs_set_statusbartablen(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "statusbar.tablen", value);
-    _save_prefs();
 }
 
 gchar**
@@ -736,7 +724,6 @@ void
 prefs_set_occupants_size(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "occupants.size", value);
-    _save_prefs();
 }
 
 gint
@@ -775,14 +762,12 @@ prefs_set_occupants_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "occupants.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_occupants_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "occupants.char", NULL);
-    _save_prefs();
 }
 
 gint
@@ -804,7 +789,6 @@ void
 prefs_set_occupants_indent(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "occupants.indent", value);
-    _save_prefs();
 }
 
 char
@@ -831,21 +815,18 @@ prefs_set_occupants_header_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "occupants.header.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_occupants_header_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "occupants.header.char", NULL);
-    _save_prefs();
 }
 
 void
 prefs_set_roster_size(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.size", value);
-    _save_prefs();
 }
 
 gint
@@ -884,7 +865,6 @@ prefs_set_otr_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_OTR, "otr.char", str);
-    _save_prefs();
 }
 
 char
@@ -911,7 +891,6 @@ prefs_set_pgp_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_PGP, "pgp.char", str);
-    _save_prefs();
 }
 
 char
@@ -938,7 +917,6 @@ prefs_set_omemo_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_OMEMO, "omemo.char", str);
-    _save_prefs();
 }
 
 char
@@ -965,14 +943,12 @@ prefs_set_roster_header_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.header.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_roster_header_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.header.char", NULL);
-    _save_prefs();
 }
 
 char
@@ -999,14 +975,12 @@ prefs_set_roster_contact_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.contact.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_roster_contact_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.contact.char", NULL);
-    _save_prefs();
 }
 
 char
@@ -1033,14 +1007,12 @@ prefs_set_roster_resource_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.resource.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_roster_resource_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.resource.char", NULL);
-    _save_prefs();
 }
 
 char
@@ -1067,14 +1039,12 @@ prefs_set_roster_private_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.private.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_roster_private_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.private.char", NULL);
-    _save_prefs();
 }
 
 char
@@ -1101,14 +1071,12 @@ prefs_set_roster_room_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.rooms.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_roster_room_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.rooms.char", NULL);
-    _save_prefs();
 }
 
 char
@@ -1135,14 +1103,12 @@ prefs_set_roster_room_private_char(char ch)
     str[1] = '\0';
 
     g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.rooms.private.char", str);
-    _save_prefs();
 }
 
 void
 prefs_clear_roster_room_private_char(void)
 {
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.rooms.pruvate.char", NULL);
-    _save_prefs();
 }
 
 gint
@@ -1164,7 +1130,6 @@ void
 prefs_set_roster_contact_indent(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.contact.indent", value);
-    _save_prefs();
 }
 
 gint
@@ -1186,7 +1151,6 @@ void
 prefs_set_roster_resource_indent(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.resource.indent", value);
-    _save_prefs();
 }
 
 gint
@@ -1208,14 +1172,12 @@ void
 prefs_set_roster_presence_indent(gint value)
 {
     g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", value);
-    _save_prefs();
 }
 
 gboolean
 prefs_add_room_notify_trigger(const char * const text)
 {
     gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text);
-    _save_prefs();
 
     if (res) {
         autocomplete_add(room_trigger_ac, text);
@@ -1563,7 +1525,6 @@ prefs_add_alias(const char *const name, const char *const value)
         return FALSE;
     } else {
         g_key_file_set_string(prefs, PREF_GROUP_ALIAS, name, value);
-        _save_prefs();
         return TRUE;
     }
 }
@@ -1582,7 +1543,6 @@ prefs_remove_alias(const char *const name)
         return FALSE;
     } else {
         g_key_file_remove_key(prefs, PREF_GROUP_ALIAS, name, NULL);
-        _save_prefs();
         return TRUE;
     }
 }
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 108111c8..d5ba4bb2 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -2,6 +2,7 @@
  * preferences.h
  *
  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
+ * Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
  *
  * This file is part of Profanity.
  *
@@ -166,6 +167,7 @@ typedef struct prof_winplacement_t {
 } ProfWinPlacement;
 
 void prefs_load(void);
+void prefs_save(void);
 void prefs_close(void);
 
 char* prefs_find_login(char *prefix);