Exemple #1
0
void
alias_run_command (struct t_gui_buffer **buffer, const char *command)
{
    char *string;
    struct t_gui_buffer *old_current_buffer, *new_current_buffer;

    /* save current buffer pointer */
    old_current_buffer = weechat_current_buffer();

    /* execute command */
    string = weechat_buffer_string_replace_local_var (*buffer, command);
    weechat_command (*buffer,
                     (string) ? string : command);
    if (string)
        free (string);

    /* get new current buffer */
    new_current_buffer = weechat_current_buffer();

    /*
     * if current buffer was changed by command, then we'll use this one for
     * next commands in alias
     */
    if (old_current_buffer != new_current_buffer)
        *buffer = new_current_buffer;
}
struct t_gui_buffer *
irc_msgbuffer_get_target_buffer (struct t_irc_server *server, const char *nick,
                                 const char *message, const char *alias,
                                 struct t_gui_buffer *default_buffer)
{
    struct t_config_option *ptr_option;
    int target;
    struct t_gui_buffer *ptr_buffer;
    struct t_irc_channel *ptr_channel;
    struct t_weechat_plugin *buffer_plugin;

    ptr_option = NULL;

    if (message && message[0])
        ptr_option = irc_msgbuffer_get_option (server, message);
    if (!ptr_option && alias && alias[0])
        ptr_option = irc_msgbuffer_get_option (server, alias);

    if (!ptr_option)
    {
        if (default_buffer)
            return default_buffer;
        return (server) ? server->buffer : NULL;
    }

    target = weechat_config_integer (ptr_option);
    switch (target)
    {
        case IRC_MSGBUFFER_TARGET_WEECHAT:
            return NULL;
            break;
        case IRC_MSGBUFFER_TARGET_SERVER:
            return (server) ? server->buffer : NULL;
            break;
        case IRC_MSGBUFFER_TARGET_CURRENT:
            break;
        case IRC_MSGBUFFER_TARGET_PRIVATE:
            ptr_channel = irc_channel_search (server, nick);
            if (ptr_channel)
                return ptr_channel->buffer;
            if (weechat_config_integer (irc_config_look_msgbuffer_fallback) ==
                IRC_CONFIG_LOOK_MSGBUFFER_FALLBACK_SERVER)
            {
                return (server) ? server->buffer : NULL;
            }
            break;
        default:
            return (server) ? server->buffer : NULL;
            break;
    }

    ptr_buffer = weechat_current_buffer ();
    buffer_plugin = weechat_buffer_get_pointer (ptr_buffer, "plugin");
    if (buffer_plugin == weechat_irc_plugin)
        return ptr_buffer;

    return (server) ? server->buffer : NULL;
}
void
weechat_aspell_config_dict_change (void *data,
                                   struct t_config_option *option)
{
    /* make C compiler happy */
    (void) data;
    (void) option;
    
    weechat_aspell_create_spellers (weechat_current_buffer ());
}
Exemple #4
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    /* make C compiler happy */
    (void) argc;
    (void) argv;
    
    weechat_plugin = plugin;
    
    if (!weechat_aspell_config_init ())
        return WEECHAT_RC_ERROR;
    
    if (weechat_aspell_config_read () < 0)
        return WEECHAT_RC_ERROR;
    
    /* command /aspell */
    weechat_hook_command ("aspell",
                          N_("aspell plugin configuration"),
                          N_("dictlist | enable lang | disable | "
                             "addword [lang] word"),
                          N_("dictlist: show installed dictionaries\n"
                             "  enable: enable aspell on current buffer\n"
                             " disable: disable aspell on current buffer\n"
                             " addword: add a word in your personal aspell "
                             "dictionary\n"
                             "\n"
                             "Input line beginning with a '/' is not checked, "
                             "except for some commands."),
                          "dictlist"
                          " || enable %(aspell_langs)"
                          " || disable"
                          " || addword",
                          &weechat_aspell_command_cb, NULL);
    weechat_hook_completion ("aspell_langs",
                             N_("list of supported langs for aspell"),
                             &weechat_aspell_completion_langs_cb, NULL);
    
    /* callback for buffer_switch */
    weechat_hook_signal ("buffer_switch",
                         &weechat_aspell_buffer_switch_cb, NULL);
    
    /* callback for spell checking input text */
    weechat_hook_modifier ("input_text_display",
                           &weechat_aspell_modifier_cb, NULL);
    
    weechat_aspell_create_spellers (weechat_current_buffer ());
    
    return WEECHAT_RC_OK;
}
int
weechat_aspell_config_dict_delete_option (void *data,
                                          struct t_config_file *config_file,
                                          struct t_config_section *section,
                                          struct t_config_option *option)
{
    /* make C compiler happy */
    (void) data;
    (void) config_file;
    (void) section;
    
    weechat_config_option_free (option);
    weechat_aspell_create_spellers (weechat_current_buffer ());
    
    return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
}
int
weechat_aspell_config_dict_create_option (void *data,
                                          struct t_config_file *config_file,
                                          struct t_config_section *section,
                                          const char *option_name,
                                          const char *value)
{
    struct t_config_option *ptr_option;
    int rc;
    
    /* make C compiler happy */
    (void) data;
    
    rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
    
    if (value && value[0])
        weechat_aspell_speller_check_dictionaries (value);
    
    if (option_name)
    {
        ptr_option = weechat_config_search_option (config_file, section,
                                                   option_name);
        if (ptr_option)
        {
            if (value && value[0])
                rc = weechat_config_option_set (ptr_option, value, 1);
            else
            {
                weechat_config_option_free (ptr_option);
                rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
            }
        }
        else
        {
            if (value && value[0])
            {
                ptr_option = weechat_config_new_option (
                    config_file, section,
                    option_name, "string",
                    _("comma separated list of dictionaries to use on this buffer"),
                    NULL, 0, 0, "", value, 0,
                    NULL, NULL,
                    &weechat_aspell_config_dict_change, NULL,
                    NULL, NULL);
                rc = (ptr_option) ?
                    WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
            }
            else
                rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
        }
    }
    
    if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR)
    {
        weechat_printf (NULL,
                        _("%s%s: error creating aspell dictionary \"%s\" => \"%s\""),
                        weechat_prefix ("error"), ASPELL_PLUGIN_NAME,
                        option_name, value);
    }
    else
        weechat_aspell_create_spellers (weechat_current_buffer ());
    
    return rc;
}
Exemple #7
0
static gint
_wec_print_callback(gconstpointer user_data, gpointer data, struct t_gui_buffer *buffer, time_t date, gint tags_count, const gchar **tags, gint displayed, gint highlight, const gchar *prefix, const gchar *message)
{
    if ( ( ! displayed ) || ( buffer == NULL ) )
        return WEECHAT_RC_OK;

    const gchar *plugin = weechat_buffer_get_string(buffer, "plugin");
    if ( g_strcmp0(plugin, "irc") != 0 )
        return WEECHAT_RC_OK;

    if ( _wec_config_boolean(restrictions, ignore_current_buffer) && ( buffer == weechat_current_buffer() ) )
        return WEECHAT_RC_OK;

    gint error = 0;
    if ( ! eventc_light_connection_is_connected(_wec_context.client, &error) )
        return WEECHAT_RC_OK;

    const gchar *category = NULL;
    const gchar *name = NULL;

    const gchar *channel = NULL;

    const gchar *buffer_type = weechat_buffer_get_string(buffer, "localvar_type");
    if ( g_strcmp0(buffer_type, "channel") == 0 )
    {
        category = "chat";
        channel = weechat_buffer_get_string(buffer, "localvar_channel");
    }
    else if ( g_strcmp0(buffer_type, "private") == 0 )
        category = "im";

    const gchar *nick = NULL;
    gchar *msg = NULL;

    gint i;
    for ( i = 0 ; i < tags_count  ; ++i )
    {
        const gchar *tag = tags[i];
        if ( g_str_has_prefix(tag, "log") || g_str_has_prefix(tag, "no_") )
            continue;

        if ( ( g_strcmp0(tag, "away_info") == 0 ) || ( g_strcmp0(tag, "notify_none") == 0 ) )
            goto cleanup;

        if ( g_str_has_prefix(tag, "irc_") )
        {
            tag += strlen("irc_");

            if ( g_strcmp0(tag, "privmsg") == 0 )
            {
                if ( highlight && _wec_config_boolean(events, highlight) )
                {
                    name = "highlight";
                    continue;
                }
                if ( ( channel != NULL ) && ( ! _wec_config_boolean(events, chat) ) )
                    break;

                if ( ! _wec_config_boolean(events, im) )
                    break;

                name = "received";
            }
            else if ( g_strcmp0(tag, "notice") == 0 )
            {
                category = "im";
                if ( highlight && _wec_config_boolean(events, highlight) )
                {
                    name = "highlight";
                    continue;
                }

                if ( ! _wec_config_boolean(events, notice) )
                    break;

                name = "received";
            }
            else if ( g_str_has_prefix(tag, "notify_") )
            {
                if ( ! _wec_config_boolean(events, notify) )
                    break;

                tag += strlen("notify_");

                category = "presence";
                if ( g_strcmp0(tag, "join") == 0 )
                    name = "signed-on";
                else if ( g_strcmp0(tag, "quit") == 0 )
                    name = "signed-off";
                else if ( g_strcmp0(tag, "back") == 0 )
                    name = "back";
                else if ( g_strcmp0(tag, "away") == 0 )
                {
                    name = "away";
                    msg = _wec_split_message(message);
                }
                else if ( g_strcmp0(tag, "still_away") == 0 )
                {
                    name = "message";
                    msg = _wec_split_message(message);
                }
            }
            else if ( g_strcmp0(tag, "join") == 0 )
            {
                if ( ! _wec_config_boolean(events, join) )
                    break;

                category = "presence";
                name = "join";
            }
            else if ( g_strcmp0(tag, "leave") == 0 )
            {
                if ( ! _wec_config_boolean(events, leave) )
                    break;

                category = "presence";
                name = "leave";
            }
            else if ( g_strcmp0(tag, "quit") == 0 )
            {
                if ( ! _wec_config_boolean(events, quit) )
                    break;

                category = "presence";
                name = "signed-off";
            }
        }
        else if ( g_str_has_prefix(tag, "nick_") )
            nick = tag + strlen("nick_");
    }

    if ( ( category == NULL ) || ( name == NULL ) )
        goto cleanup;

    if ( g_hash_table_contains(_wec_context.blacklist, nick) )
        goto cleanup;

    EventdEvent *event;

    event = eventd_event_new(category, name);

    if ( nick != NULL )
        eventd_event_add_data_string(event, g_strdup("buddy-name"), g_strdup(nick));

    if ( channel != NULL )
        eventd_event_add_data_string(event, g_strdup("channel"), g_strdup(channel));

    eventd_event_add_data_string(event, g_strdup("message"), ( msg != NULL ) ? msg : g_strdup(message));
    msg = NULL;

    eventc_light_connection_event(_wec_context.client, event);
    eventd_event_unref(event);

cleanup:
    g_free(msg);
    return WEECHAT_RC_OK;
}