Added some config options.
This commit is contained in:
parent
a437931e41
commit
e6e4fd568e
@ -31,6 +31,7 @@
|
|||||||
#include "twc-group-invite.h"
|
#include "twc-group-invite.h"
|
||||||
#include "twc-bootstrap.h"
|
#include "twc-bootstrap.h"
|
||||||
#include "twc-sqlite.h"
|
#include "twc-sqlite.h"
|
||||||
|
#include "twc-config.h"
|
||||||
#include "twc-utils.h"
|
#include "twc-utils.h"
|
||||||
|
|
||||||
#include "twc-commands.h"
|
#include "twc-commands.h"
|
||||||
@ -267,8 +268,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!message)
|
if (!message)
|
||||||
// TODO: default message as option
|
message = weechat_config_string(twc_config_friend_request_message);
|
||||||
message = "Hi! Please add me on Tox!";
|
|
||||||
|
|
||||||
if (strlen(hex_id) != TOX_FRIEND_ADDRESS_SIZE * 2)
|
if (strlen(hex_id) != TOX_FRIEND_ADDRESS_SIZE * 2)
|
||||||
{
|
{
|
||||||
@ -455,10 +455,10 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||||||
struct t_twc_list_item *item;
|
struct t_twc_list_item *item;
|
||||||
twc_list_foreach(friend_requests, index, item)
|
twc_list_foreach(friend_requests, index, item)
|
||||||
{
|
{
|
||||||
// TODO: load short form address length from config
|
size_t short_id_length = weechat_config_integer(twc_config_short_id_size);
|
||||||
char hex_address[12 + 1];
|
char hex_address[short_id_length + 1];
|
||||||
twc_bin2hex(item->friend_request->tox_id,
|
twc_bin2hex(item->friend_request->tox_id,
|
||||||
6,
|
short_id_length / 2,
|
||||||
hex_address);
|
hex_address);
|
||||||
|
|
||||||
weechat_printf(profile->buffer,
|
weechat_printf(profile->buffer,
|
||||||
|
@ -31,9 +31,13 @@
|
|||||||
#include "twc-config.h"
|
#include "twc-config.h"
|
||||||
|
|
||||||
struct t_config_file *twc_config_file = NULL;
|
struct t_config_file *twc_config_file = NULL;
|
||||||
|
struct t_config_section *twc_config_section_look = NULL;
|
||||||
struct t_config_section *twc_config_section_profile = NULL;
|
struct t_config_section *twc_config_section_profile = NULL;
|
||||||
struct t_config_section *twc_config_section_profile_default = NULL;
|
struct t_config_section *twc_config_section_profile_default = NULL;
|
||||||
|
|
||||||
|
struct t_config_option *twc_config_friend_request_message;
|
||||||
|
struct t_config_option *twc_config_short_id_size;
|
||||||
|
|
||||||
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
|
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
|
||||||
{
|
{
|
||||||
"save_file",
|
"save_file",
|
||||||
@ -175,6 +179,23 @@ twc_config_profile_write_callback(void *data,
|
|||||||
return WEECHAT_CONFIG_WRITE_OK;
|
return WEECHAT_CONFIG_WRITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for checking an option value being set.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
twc_config_check_value_callback(void *data,
|
||||||
|
struct t_config_option *option,
|
||||||
|
const char *value)
|
||||||
|
{
|
||||||
|
int int_value = atoi(value);
|
||||||
|
|
||||||
|
// must be multiple of two
|
||||||
|
if (option == twc_config_short_id_size && int_value % 2)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for checking an option value being set for a profile.
|
* Callback for checking an option value being set for a profile.
|
||||||
*/
|
*/
|
||||||
@ -307,6 +328,32 @@ twc_config_init()
|
|||||||
twc_config_init_option(twc_config_section_profile_default,
|
twc_config_init_option(twc_config_section_profile_default,
|
||||||
i, twc_profile_option_names[i], true);
|
i, twc_profile_option_names[i], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
twc_config_section_look =
|
||||||
|
weechat_config_new_section(twc_config_file, "look",
|
||||||
|
0, 0,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
twc_config_friend_request_message = weechat_config_new_option(
|
||||||
|
twc_config_file, twc_config_section_look,
|
||||||
|
"friend_request_message", "string",
|
||||||
|
"message sent with friend requests if no other message is specified",
|
||||||
|
NULL, 0, 0,
|
||||||
|
"Hi! Please add me on Tox!", NULL, 0,
|
||||||
|
twc_config_check_value_callback, NULL,
|
||||||
|
NULL, NULL, NULL, NULL);
|
||||||
|
twc_config_short_id_size = weechat_config_new_option(
|
||||||
|
twc_config_file, twc_config_section_look,
|
||||||
|
"short_id_size", "integer",
|
||||||
|
"length of Tox IDs shown in short format; must be a multiple of two",
|
||||||
|
NULL, 2, TOX_CLIENT_ID_SIZE * 2,
|
||||||
|
"8", NULL, 0,
|
||||||
|
twc_config_check_value_callback, NULL,
|
||||||
|
NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,11 @@
|
|||||||
#ifndef TOX_WEECHAT_CONFIG_H
|
#ifndef TOX_WEECHAT_CONFIG_H
|
||||||
#define TOX_WEECHAT_CONFIG_H
|
#define TOX_WEECHAT_CONFIG_H
|
||||||
|
|
||||||
|
struct t_twc_profile;
|
||||||
|
|
||||||
|
extern struct t_config_option *twc_config_friend_request_message;
|
||||||
|
extern struct t_config_option *twc_config_short_id_size;
|
||||||
|
|
||||||
void
|
void
|
||||||
twc_config_init();
|
twc_config_init();
|
||||||
|
|
||||||
|
@ -34,9 +34,6 @@
|
|||||||
sqlite3 *twc_sqlite_db = NULL;
|
sqlite3 *twc_sqlite_db = NULL;
|
||||||
struct t_twc_list *twc_sqlite_statements = NULL;
|
struct t_twc_list *twc_sqlite_statements = NULL;
|
||||||
|
|
||||||
// TODO: move to config
|
|
||||||
#define TWC_SQLITE_PATH "%h/tox/data.db"
|
|
||||||
|
|
||||||
#define TWC_SQLITE_DEBUG_RC(rc, expected_rc) \
|
#define TWC_SQLITE_DEBUG_RC(rc, expected_rc) \
|
||||||
if (rc != expected_rc) \
|
if (rc != expected_rc) \
|
||||||
weechat_printf(NULL, \
|
weechat_printf(NULL, \
|
||||||
@ -74,7 +71,7 @@ char *
|
|||||||
twc_sqlite_db_path()
|
twc_sqlite_db_path()
|
||||||
{
|
{
|
||||||
const char *weechat_dir = weechat_info_get("weechat_dir", NULL);
|
const char *weechat_dir = weechat_info_get("weechat_dir", NULL);
|
||||||
return weechat_string_replace(TWC_SQLITE_PATH, "%h", weechat_dir);
|
return weechat_string_replace("%h/tox/data.db", "%h", weechat_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
#include <weechat/weechat-plugin.h>
|
#include <weechat/weechat-plugin.h>
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
|
#include "twc.h"
|
||||||
|
#include "twc-config.h"
|
||||||
|
|
||||||
#include "twc-utils.h"
|
#include "twc-utils.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,8 +143,7 @@ twc_get_friend_id_short(Tox *tox, int32_t friend_number)
|
|||||||
uint8_t client_id[TOX_CLIENT_ID_SIZE];
|
uint8_t client_id[TOX_CLIENT_ID_SIZE];
|
||||||
tox_get_client_id(tox, friend_number, client_id);
|
tox_get_client_id(tox, friend_number, client_id);
|
||||||
|
|
||||||
// TODO: config
|
size_t short_id_length = weechat_config_integer(twc_config_short_id_size);
|
||||||
size_t short_id_length = 8;
|
|
||||||
|
|
||||||
char *hex_address = malloc(short_id_length + 1);
|
char *hex_address = malloc(short_id_length + 1);
|
||||||
twc_bin2hex(client_id,
|
twc_bin2hex(client_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user