From 6fc93d1f7a03a14fe299190a6afebad145026e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Tue, 7 Oct 2014 04:02:06 +0200 Subject: [PATCH] Save Tox profile data on /save. --- src/twc-commands.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/twc-commands.c b/src/twc-commands.c index 132a66e..225cd4b 100644 --- a/src/twc-commands.c +++ b/src/twc-commands.c @@ -707,6 +707,32 @@ twc_cmd_nospam(void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } +int +twc_cmd_save(void *data, struct t_gui_buffer *buffer, const char *command) +{ + size_t index; + struct t_twc_list_item *item; + twc_list_foreach(twc_profiles, index, item) + { + if (!(item->profile->tox)) continue; + + int rc = twc_profile_save_data_file(item->profile); + if (rc == -1) + { + weechat_printf(NULL, + "%s%s: failed to save data for profile %s", + weechat_prefix("error"), weechat_plugin->name, + item->profile->name); + } + } + + weechat_printf(NULL, + "%s: profile data saved", + weechat_plugin->name); + + return WEECHAT_RC_OK; +} + /** * Command /status callback. */ @@ -988,6 +1014,8 @@ twc_commands_init() "Tox ID!", NULL, twc_cmd_nospam, NULL); + weechat_hook_command_run("/save", twc_cmd_save, NULL); + weechat_hook_command("status", "change your Tox status", "online|busy|away",