summaryrefslogtreecommitdiff
path: root/src/plugins/typing/typing-config.c
blob: 6b2b79b980404488276723dbb2102b6682bdab67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * typing-config.c - typing configuration options (file typing.conf)
 *
 * Copyright (C) 2021-2023 Sébastien Helleu <flashcode@flashtux.org>
 *
 * This file is part of WeeChat, the extensible chat client.
 *
 * WeeChat is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * WeeChat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WeeChat.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>

#include "../weechat-plugin.h"
#include "typing.h"
#include "typing-config.h"
#include "typing-bar-item.h"


struct t_config_file *typing_config_file = NULL;

/* sections */

struct t_config_section *typing_config_section_look = NULL;

/* typing config, look section */

struct t_config_option *typing_config_look_delay_purge_paused = NULL;
struct t_config_option *typing_config_look_delay_purge_typing = NULL;
struct t_config_option *typing_config_look_delay_set_paused = NULL;
struct t_config_option *typing_config_look_enabled_nicks = NULL;
struct t_config_option *typing_config_look_enabled_self = NULL;
struct t_config_option *typing_config_look_input_min_chars = NULL;
struct t_config_option *typing_config_look_item_max_length = NULL;


/*
 * Reloads typing configuration file.
 */

int
typing_config_reload (const void *pointer, void *data,
                      struct t_config_file *config_file)
{
    int rc;

    /* make C compiler happy */
    (void) pointer;
    (void) data;

    rc = weechat_config_reload (config_file);

    typing_setup_hooks ();

    return rc;
}

/*
 * Callback for changes on options "typing.look.enabled_*".
 */

void
typing_config_change_enabled (const void *pointer, void *data,
                              struct t_config_option *option)
{
    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) option;

    typing_setup_hooks ();
    weechat_bar_item_update (TYPING_BAR_ITEM_NAME);
}

/*
 * Callback for changes on options "typing.look.item_max_length".
 */

void
typing_config_change_item_max_length (const void *pointer, void *data,
                                      struct t_config_option *option)
{
    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) option;

    weechat_bar_item_update (TYPING_BAR_ITEM_NAME);
}

/*
 * Initializes typing configuration file.
 *
 * Returns:
 *   1: OK
 *   0: error
 */

int
typing_config_init ()
{
    typing_config_file = weechat_config_new (
        TYPING_CONFIG_PRIO_NAME,
        &typing_config_reload, NULL, NULL);
    if (!typing_config_file)
        return 0;

    /* look */
    typing_config_section_look = weechat_config_new_section (
        typing_config_file, "look",
        0, 0,
        NULL, NULL, NULL,
        NULL, NULL, NULL,
        NULL, NULL, NULL,
        NULL, NULL, NULL,
        NULL, NULL, NULL);
    if (typing_config_section_look)
    {
        typing_config_look_delay_purge_paused = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "delay_purge_paused", "integer",
            N_("number of seconds after paused status has been set: if reached, "
               "the typing status is removed"),
            NULL, 1, INT_MAX, "30", NULL, 0,
            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        typing_config_look_delay_purge_typing = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "delay_purge_typing", "integer",
            N_("number of seconds after typing status has been set: if reached, "
               "the typing status is removed"),
            NULL, 1, INT_MAX, "6", NULL, 0,
            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        typing_config_look_delay_set_paused = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "delay_set_paused", "integer",
            N_("number of seconds after typing last char: if reached, the "
               "typing status becomes \"paused\" and no more typing signals "
               "are sent"),
            NULL, 1, INT_MAX, "10", NULL, 0,
            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        typing_config_look_enabled_nicks = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "enabled_nicks", "boolean",
            N_("typing enabled for other nicks (display typing info for nicks "
               "typing in the current buffer)"),
            NULL, 0, 0, "off", NULL, 0,
            NULL, NULL, NULL,
            &typing_config_change_enabled, NULL, NULL,
            NULL, NULL, NULL);
        typing_config_look_enabled_self = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "enabled_self", "boolean",
            N_("typing enabled for self messages (send typing info to other "
               "users)"),
            NULL, 0, 0, "off", NULL, 0,
            NULL, NULL, NULL,
            &typing_config_change_enabled, NULL, NULL,
            NULL, NULL, NULL);
        typing_config_look_input_min_chars = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "input_min_chars", "integer",
            N_("min number of chars in message to trigger send of typing "
               "signals"),
            NULL, 1, INT_MAX, "4", NULL, 0,
            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        typing_config_look_item_max_length = weechat_config_new_option (
            typing_config_file, typing_config_section_look,
            "item_max_length", "integer",
            N_("max number of chars displayed in the bar item \"typing\" "
               "(0 = do not truncate content)"),
            NULL, 0, INT_MAX, "0", NULL, 0,
            NULL, NULL, NULL,
            &typing_config_change_item_max_length, NULL, NULL,
            NULL, NULL, NULL);
    }

    return 1;
}

/*
 * Reads typing configuration file.
 */

int
typing_config_read ()
{
    return weechat_config_read (typing_config_file);
}

/*
 * Writes typing configuration file.
 */

int
typing_config_write ()
{
    return weechat_config_write (typing_config_file);
}

/*
 * Frees typing configuration.
 */

void
typing_config_free ()
{
    weechat_config_free (typing_config_file);
}