コード例 #1
0
ファイル: gui-hotlist.c プロジェクト: Georgiy-Tugai/weechat
void
gui_hotlist_remove_buffer (struct t_gui_buffer *buffer)
{
    int hotlist_changed;
    struct t_gui_hotlist *ptr_hotlist, *next_hotlist;

    if (!buffer || weechat_upgrading)
        return;

    hotlist_changed = 0;

    ptr_hotlist = gui_hotlist;
    while (ptr_hotlist)
    {
        next_hotlist = ptr_hotlist->next_hotlist;

        if ((ptr_hotlist->buffer->number == buffer->number)
            && (!ptr_hotlist->buffer->zoomed
                || (ptr_hotlist->buffer->active == 2)))
        {
            gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
            hotlist_changed = 1;
        }

        ptr_hotlist = next_hotlist;
    }

    if (hotlist_changed)
        gui_hotlist_changed_signal ();
}
コード例 #2
0
ファイル: gui-hotlist.c プロジェクト: Georgiy-Tugai/weechat
void
gui_hotlist_free_all (struct t_gui_hotlist **hotlist,
                      struct t_gui_hotlist **last_hotlist)
{
    /* remove all hotlists */
    while (*hotlist)
    {
        gui_hotlist_free (hotlist, last_hotlist, *hotlist);
    }
}
コード例 #3
0
ファイル: gui-hotlist.c プロジェクト: Evalle/weechat
void
gui_hotlist_remove_buffer (struct t_gui_buffer *buffer,
                           int force_remove_buffer)
{
    int hotlist_changed, hotlist_remove, buffer_to_remove;
    struct t_gui_hotlist *ptr_hotlist, *next_hotlist;

    if (!buffer || weechat_upgrading)
        return;

    hotlist_changed = 0;

    hotlist_remove = CONFIG_INTEGER(config_look_hotlist_remove);

    ptr_hotlist = gui_hotlist;
    while (ptr_hotlist)
    {
        next_hotlist = ptr_hotlist->next_hotlist;

        buffer_to_remove = (force_remove_buffer) ?
            (ptr_hotlist->buffer == buffer) : 0;

        switch (hotlist_remove)
        {
            case CONFIG_LOOK_HOTLIST_REMOVE_BUFFER:
                buffer_to_remove |= (ptr_hotlist->buffer == buffer);
                break;
            case CONFIG_LOOK_HOTLIST_REMOVE_MERGED:
                buffer_to_remove |=
                    ((ptr_hotlist->buffer->number == buffer->number)
                     && (!ptr_hotlist->buffer->zoomed
                         || (ptr_hotlist->buffer->active == 2)));
                break;
        }

        if (buffer_to_remove)
        {
            gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
            hotlist_changed = 1;
        }

        ptr_hotlist = next_hotlist;
    }

    if (hotlist_changed)
        gui_hotlist_changed_signal ();
}
コード例 #4
0
ファイル: gui-hotlist.c プロジェクト: Evalle/weechat
void
gui_hotlist_clear (int level_mask)
{
    struct t_gui_hotlist *ptr_hotlist, *ptr_next_hotlist;
    int hotlist_changed;

    hotlist_changed = 0;

    ptr_hotlist = gui_hotlist;
    while (ptr_hotlist)
    {
        ptr_next_hotlist = ptr_hotlist->next_hotlist;
        if (level_mask & (1 << ptr_hotlist->priority))
        {
            gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
            hotlist_changed = 1;
        }
        ptr_hotlist = ptr_next_hotlist;
    }

    if (hotlist_changed)
        gui_hotlist_changed_signal ();
}
コード例 #5
0
ファイル: gui-hotlist.c プロジェクト: Georgiy-Tugai/weechat
struct t_gui_hotlist *
gui_hotlist_add (struct t_gui_buffer *buffer,
                 enum t_gui_hotlist_priority priority,
                 struct timeval *creation_time)
{
    struct t_gui_hotlist *new_hotlist, *ptr_hotlist;
    int i, count[GUI_HOTLIST_NUM_PRIORITIES], rc;
    char *value, str_value[32];

    if (!buffer || !gui_add_hotlist)
        return NULL;

    /* do not add core buffer if upgrading */
    if (weechat_upgrading && (buffer == gui_buffer_search_main ()))
        return NULL;

    if (priority > GUI_HOTLIST_MAX)
        priority = GUI_HOTLIST_MAX;

    /* check if priority is OK according to buffer notify level value */
    if (!gui_hotlist_check_buffer_notify (buffer, priority))
        return NULL;

    /* create hashtable if needed (to evaluate conditions) */
    if (!gui_hotlist_hashtable_add_conditions_pointers)
    {
        gui_hotlist_hashtable_add_conditions_pointers = hashtable_new (
            32,
            WEECHAT_HASHTABLE_STRING,
            WEECHAT_HASHTABLE_POINTER,
            NULL,
            NULL);
        if (!gui_hotlist_hashtable_add_conditions_pointers)
            return NULL;
    }
    if (!gui_hotlist_hashtable_add_conditions_vars)
    {
        gui_hotlist_hashtable_add_conditions_vars = hashtable_new (
            32,
            WEECHAT_HASHTABLE_STRING,
            WEECHAT_HASHTABLE_STRING,
            NULL,
            NULL);
        if (!gui_hotlist_hashtable_add_conditions_vars)
            return NULL;
    }
    if (!gui_hotlist_hashtable_add_conditions_options)
    {
        gui_hotlist_hashtable_add_conditions_options = hashtable_new (
            32,
            WEECHAT_HASHTABLE_STRING,
            WEECHAT_HASHTABLE_STRING,
            NULL,
            NULL);
        if (!gui_hotlist_hashtable_add_conditions_options)
            return NULL;
        hashtable_set (gui_hotlist_hashtable_add_conditions_options,
                       "type", "condition");
    }

    /* set data in hashtables */
    hashtable_set (gui_hotlist_hashtable_add_conditions_pointers,
                   "window", gui_current_window);
    hashtable_set (gui_hotlist_hashtable_add_conditions_pointers,
                   "buffer", buffer);
    snprintf (str_value, sizeof (str_value), "%d", priority);
    hashtable_set (gui_hotlist_hashtable_add_conditions_vars,
                   "priority", str_value);

    /* check if conditions are true */
    value = eval_expression (CONFIG_STRING(config_look_hotlist_add_conditions),
                             gui_hotlist_hashtable_add_conditions_pointers,
                             gui_hotlist_hashtable_add_conditions_vars,
                             gui_hotlist_hashtable_add_conditions_options);
    rc = (value && (strcmp (value, "1") == 0));
    if (value)
        free (value);
    if (!rc)
        return NULL;

    /* init count */
    for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++)
    {
        count[i] = 0;
    }

    ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer);
    if (ptr_hotlist)
    {
        /* return if priority is greater or equal than the one to add */
        if (ptr_hotlist->priority >= priority)
        {
            ptr_hotlist->count[priority]++;
            gui_hotlist_changed_signal ();
            return ptr_hotlist;
        }

        /*
         * if buffer is present with lower priority: save counts, remove it
         * and go on
         */
        memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count));
        gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
    }

    new_hotlist = malloc (sizeof (*new_hotlist));
    if (!new_hotlist)
        return NULL;

    new_hotlist->priority = priority;
    if (creation_time)
    {
        memcpy (&(new_hotlist->creation_time),
                creation_time, sizeof (*creation_time));
    }
    else
        gettimeofday (&(new_hotlist->creation_time), NULL);
    new_hotlist->buffer = buffer;
    memcpy (new_hotlist->count, count, sizeof (new_hotlist->count));
    new_hotlist->count[priority]++;
    new_hotlist->next_hotlist = NULL;
    new_hotlist->prev_hotlist = NULL;

    gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, new_hotlist);

    gui_hotlist_changed_signal ();

    return new_hotlist;
}
コード例 #6
0
ファイル: gui-hotlist.c プロジェクト: richo/weechat
struct t_gui_hotlist *
gui_hotlist_add (struct t_gui_buffer *buffer,
                 enum t_gui_hotlist_priority priority,
                 struct timeval *creation_time)
{
    struct t_gui_hotlist *new_hotlist, *ptr_hotlist;
    int i, count[GUI_HOTLIST_NUM_PRIORITIES];
    const char *away;

    if (!buffer || !gui_add_hotlist)
        return NULL;

    /* do not add core buffer if upgrading */
    if (weechat_upgrading && (buffer == gui_buffer_search_main ()))
        return NULL;

    /* do not add buffer if it is displayed and away is not set */
    away = hashtable_get (buffer->local_variables, "away");
    if ((buffer->num_displayed > 0)
        && ((!away || !away[0])
            || !CONFIG_BOOLEAN(config_look_hotlist_add_buffer_if_away)))
        return NULL;

    if (priority > GUI_HOTLIST_MAX)
        priority = GUI_HOTLIST_MAX;

    /* check if priority is OK according to buffer notify level value */
    if (!gui_hotlist_check_buffer_notify (buffer, priority))
        return NULL;

    /* init count */
    for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++)
    {
        count[i] = 0;
    }

    ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer);
    if (ptr_hotlist)
    {
        /* return if priority is greater or equal than the one to add */
        if (ptr_hotlist->priority >= priority)
        {
            ptr_hotlist->count[priority]++;
            gui_hotlist_changed_signal ();
            return ptr_hotlist;
        }

        /*
         * if buffer is present with lower priority: save counts, remove it
         * and go on
         */
        memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count));
        gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
    }

    new_hotlist = malloc (sizeof (*new_hotlist));
    if (!new_hotlist)
    {
        log_printf (_("Error: not enough memory to add a buffer to "
                      "hotlist"));
        return NULL;
    }

    new_hotlist->priority = priority;
    if (creation_time)
    {
        memcpy (&(new_hotlist->creation_time),
                creation_time, sizeof (*creation_time));
    }
    else
        gettimeofday (&(new_hotlist->creation_time), NULL);
    new_hotlist->buffer = buffer;
    memcpy (new_hotlist->count, count, sizeof (new_hotlist->count));
    new_hotlist->count[priority]++;
    new_hotlist->next_hotlist = NULL;
    new_hotlist->prev_hotlist = NULL;

    gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, new_hotlist);

    gui_hotlist_changed_signal ();

    return new_hotlist;
}