コード例 #1
0
ファイル: script-buffer.c プロジェクト: anders/weechat
void
script_buffer_refresh (int clear)
{
    struct t_script_repo *ptr_script;
    int line;
    char str_title[1024];

    if (!script_buffer)
        return;

    if (clear)
    {
        weechat_buffer_clear (script_buffer);
        script_buffer_selected_line = (script_repo_count_displayed > 0) ? 0 : -1;
    }

    if (script_buffer_detail_script)
    {
        snprintf (str_title, sizeof (str_title),
                  "%s",
                  _("Alt+key/input: v=back to list d=jump to diff"));
    }
    else
    {
        snprintf (str_title, sizeof (str_title),
                  _("%d/%d scripts (filter: %s) | Sort: %s | "
                    "Alt+key/input: i=install, r=remove, l=load, L=reload, "
                    "u=unload, A=autoload, h=(un)hold, v=view script | "
                    "Input: q=close, $=refresh, s:x,y=sort, words=filter, "
                    "*=reset filter | Mouse: left=select, right=install/remove"),
                  script_repo_count_displayed,
                  script_repo_count,
                  (script_repo_filter) ? script_repo_filter : "*",
                  weechat_config_string (script_config_look_sort));
    }
    weechat_buffer_set (script_buffer, "title", str_title);

    if (script_buffer_detail_script)
    {
        /* detail on a script */
        script_buffer_display_detail_script (script_buffer_detail_script);
    }
    else
    {
        /* list of scripts */
        line = 0;
        for (ptr_script = scripts_repo; ptr_script;
             ptr_script = ptr_script->next_script)
        {
            if (ptr_script->displayed)
            {
                script_buffer_display_line_script (line, ptr_script);
                line++;
            }
        }
    }
}
コード例 #2
0
ファイル: exec-buffer.c プロジェクト: Evalle/weechat
struct t_gui_buffer *
exec_buffer_new (const char *name, int free_content, int clear_buffer,
                 int switch_to_buffer)
{
    struct t_gui_buffer *new_buffer;
    int buffer_type;

    new_buffer = weechat_buffer_search (EXEC_PLUGIN_NAME, name);
    if (new_buffer)
    {
        buffer_type = weechat_buffer_get_integer (new_buffer, "type");
        if (((buffer_type == 0) && free_content)
            || ((buffer_type == 1) && !free_content))
        {
            /* change the type of buffer */
            weechat_buffer_set (new_buffer,
                                "type",
                                (free_content) ? "free" : "formatted");
        }
        goto end;
    }

    new_buffer = weechat_buffer_new (name,
                                     &exec_buffer_input_cb, NULL, NULL,
                                     &exec_buffer_close_cb, NULL, NULL);

    /* failed to create buffer ? then return */
    if (!new_buffer)
        return NULL;

    if (free_content)
        weechat_buffer_set (new_buffer, "type", "free");
    weechat_buffer_set (new_buffer, "clear", "1");
    weechat_buffer_set (new_buffer, "title", _("Executed commands"));
    weechat_buffer_set (new_buffer, "localvar_set_type", "exec");
    weechat_buffer_set (new_buffer, "localvar_set_no_log", "1");
    weechat_buffer_set (new_buffer, "time_for_each_line", "0");
    weechat_buffer_set (new_buffer, "input_get_unknown_commands", "0");

end:
    if (clear_buffer)
        weechat_buffer_clear (new_buffer);
    if (switch_to_buffer)
        weechat_buffer_set (new_buffer, "display", "1");

    return new_buffer;
}
コード例 #3
0
ファイル: script-buffer.c プロジェクト: anders/weechat
void
script_buffer_show_detail_script (struct t_script_repo *script)
{
    if (!script_buffer)
        return;

    if (script_buffer_detail_script == script)
        script_buffer_detail_script = NULL;
    else
        script_buffer_detail_script = script;

    weechat_buffer_clear (script_buffer);
    script_buffer_refresh (0);

    if (!script_buffer_detail_script)
        script_buffer_check_line_outside_window ();
}
コード例 #4
0
ファイル: relay-buffer.c プロジェクト: Evalle/weechat
void
relay_buffer_refresh (const char *hotlist)
{
    struct t_relay_client *ptr_client, *client_selected;
    char str_color[256], str_status[64], str_date_start[128], str_date_end[128];
    char *str_recv, *str_sent;
    int i, length, line;
    struct tm *date_tmp;

    if (relay_buffer)
    {
        weechat_buffer_clear (relay_buffer);
        line = 0;
        client_selected = relay_client_search_by_number (relay_buffer_selected_line);
        weechat_printf_y (relay_buffer, 0,
                          "%s%s%s%s%s%s%s",
                          weechat_color("green"),
                          _("Actions (letter+enter):"),
                          weechat_color("lightgreen"),
                          /* disconnect */
                          (client_selected
                           && !RELAY_CLIENT_HAS_ENDED(client_selected)) ?
                          _("  [D] Disconnect") : "",
                          /* remove */
                          (client_selected
                           && RELAY_CLIENT_HAS_ENDED(client_selected)) ?
                          _("  [R] Remove") : "",
                          /* purge old */
                          _("  [P] Purge finished"),
                          /* quit */
                          _("  [Q] Close this buffer"));
        for (ptr_client = relay_clients; ptr_client;
             ptr_client = ptr_client->next_client)
        {
            snprintf (str_color, sizeof (str_color),
                      "%s,%s",
                      (line == relay_buffer_selected_line) ?
                      weechat_config_string (relay_config_color_text_selected) :
                      weechat_config_string (relay_config_color_text),
                      weechat_config_string (relay_config_color_text_bg));

            snprintf (str_status, sizeof (str_status),
                      "%s", _(relay_client_status_string[ptr_client->status]));
            length = weechat_utf8_strlen_screen (str_status);
            if (length < 20)
            {
                for (i = 0; i < 20 - length; i++)
                {
                    strcat (str_status, " ");
                }
            }

            str_date_start[0] = '\0';
            date_tmp = localtime (&(ptr_client->start_time));
            if (date_tmp)
            {
                strftime (str_date_start, sizeof (str_date_start),
                          "%a, %d %b %Y %H:%M:%S", date_tmp);
            }
            str_date_end[0] = '-';
            str_date_end[1] = '\0';
            if (ptr_client->end_time > 0)
            {
                date_tmp = localtime (&(ptr_client->end_time));
                if (date_tmp)
                {
                    strftime (str_date_end, sizeof (str_date_end),
                              "%a, %d %b %Y %H:%M:%S", date_tmp);
                }
            }

            str_recv = weechat_string_format_size (ptr_client->bytes_recv);
            str_sent = weechat_string_format_size (ptr_client->bytes_sent);

            /* first line with status, description and bytes recv/sent */
            weechat_printf_y (relay_buffer, (line * 2) + 2,
                              _("%s%s[%s%s%s%s] %s, received: %s, sent: %s"),
                              weechat_color(str_color),
                              (line == relay_buffer_selected_line) ? "*** " : "    ",
                              weechat_color(weechat_config_string (relay_config_color_status[ptr_client->status])),
                              str_status,
                              weechat_color ("reset"),
                              weechat_color (str_color),
                              ptr_client->desc,
                              (str_recv) ? str_recv : "?",
                              (str_sent) ? str_sent : "?");

            /* second line with start/end time */
            weechat_printf_y (relay_buffer, (line * 2) + 3,
                              _("%s%-26s started on: %s, ended on: %s"),
                              weechat_color(str_color),
                              " ",
                              str_date_start,
                              str_date_end);

            if (str_recv)
                free (str_recv);
            if (str_sent)
                free (str_sent);

            line++;
        }
        if (hotlist)
            weechat_buffer_set (relay_buffer, "hotlist", hotlist);
    }
}
コード例 #5
0
ファイル: xfer-buffer.c プロジェクト: lp0/weechat
void
xfer_buffer_refresh (const char *hotlist)
{
    struct t_xfer *ptr_xfer, *xfer_selected;
    char str_color[256], suffix[32], status[64], date[128], eta[128];
    char str_ip[128], str_hash[128];
    char *progress_bar, *str_pos, *str_total, *str_bytes_per_sec;
    int i, length, line, progress_bar_size, num_bars;
    unsigned long long pos, pct_complete;
    struct tm *date_tmp;

    if (xfer_buffer)
    {
        weechat_buffer_clear (xfer_buffer);
        line = 0;
        xfer_selected = xfer_search_by_number (xfer_buffer_selected_line);
        weechat_printf_y (xfer_buffer, 0,
                          "%s%s%s%s%s%s%s%s",
                          weechat_color ("green"),
                          _("Actions (letter+enter):"),
                          weechat_color ("lightgreen"),
                          /* accept */
                          (xfer_selected && XFER_IS_RECV(xfer_selected->type)
                           && (xfer_selected->status == XFER_STATUS_WAITING)) ?
                          _("  [A] Accept") : "",
                          /* cancel */
                          (xfer_selected
                           && !XFER_HAS_ENDED(xfer_selected->status)) ?
                          _("  [C] Cancel") : "",
                          /* remove */
                          (xfer_selected
                           && XFER_HAS_ENDED(xfer_selected->status)) ?
                          _("  [R] Remove") : "",
                          /* purge old */
                          _("  [P] Purge finished"),
                          /* quit */
                          _("  [Q] Close this buffer"));
        for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer)
        {
            suffix[0] = '\0';
            if (ptr_xfer->filename_suffix >= 0)
            {
                snprintf (suffix, sizeof (suffix),
                          " (.%d)", ptr_xfer->filename_suffix);
            }

            snprintf (str_color, sizeof (str_color),
                      "%s,%s",
                      (line == xfer_buffer_selected_line) ?
                      weechat_config_string (xfer_config_color_text_selected) :
                      weechat_config_string (xfer_config_color_text),
                      weechat_config_string (xfer_config_color_text_bg));

            str_ip[0] = '\0';
            if (ptr_xfer->remote_address_str)
            {
                snprintf (str_ip, sizeof (str_ip),
                          " (%s)",
                          ptr_xfer->remote_address_str);
            }

            str_hash[0] = '\0';
            if (ptr_xfer->hash_target
                && ptr_xfer->hash_handle
                && (ptr_xfer->hash_status != XFER_HASH_STATUS_UNKNOWN)
                && ((ptr_xfer->status == XFER_STATUS_ACTIVE)
                    || (ptr_xfer->status == XFER_STATUS_DONE)
                    || (ptr_xfer->status == XFER_STATUS_HASHING)))
            {
                snprintf (str_hash, sizeof (str_hash),
                          " (%s)",
                          _(xfer_hash_status_string[ptr_xfer->hash_status]));
            }

            /* display first line with remote nick, filename and plugin name/id */
            weechat_printf_y (xfer_buffer, (line * 2) + 2,
                              "%s%s%-24s %s%s%s%s (%s.%s)%s%s",
                              weechat_color (str_color),
                              (line == xfer_buffer_selected_line) ?
                              "*** " : "    ",
                              ptr_xfer->remote_nick,
                              (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "",
                              (XFER_IS_FILE(ptr_xfer->type)) ?
                              ptr_xfer->filename : _("xfer chat"),
                              (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "",
                              suffix,
                              ptr_xfer->plugin_name,
                              ptr_xfer->plugin_id,
                              str_ip,
                              str_hash);

            snprintf (status, sizeof (status),
                      "%s", _(xfer_status_string[ptr_xfer->status]));
            length = weechat_utf8_strlen_screen (status);
            if (length < 20)
            {
                for (i = 0; i < 20 - length; i++)
                {
                    strcat (status, " ");
                }
            }

            if (XFER_IS_CHAT(ptr_xfer->type))
            {
                /* display second line for chat with status and date */
                date[0] = '\0';
                date_tmp = localtime (&(ptr_xfer->start_time));
                if (date_tmp)
                {
                    if (strftime (date, sizeof (date),
                                  "%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
                        date[0] = '\0';
                }
                weechat_printf_y (xfer_buffer, (line * 2) + 3,
                                  "%s%s%s %s%s%s%s%s",
                                  weechat_color (str_color),
                                  (line == xfer_buffer_selected_line) ?
                                  "*** " : "    ",
                                  (XFER_IS_SEND(ptr_xfer->type)) ?
                                  "<<--" : "-->>",
                                  weechat_color (weechat_config_string (xfer_config_color_status[ptr_xfer->status])),
                                  status,
                                  weechat_color ("reset"),
                                  weechat_color (str_color),
                                  date);
            }
            else
            {
                /* build progress bar */
                pos = (ptr_xfer->pos <= ptr_xfer->size) ? ptr_xfer->pos : ptr_xfer->size;
                progress_bar = NULL;
                progress_bar_size = weechat_config_integer (xfer_config_look_progress_bar_size);
                if (progress_bar_size > 0)
                {
                    progress_bar = malloc (1 + progress_bar_size + 1 + 1 + 1);
                    strcpy (progress_bar, "[");
                    if (ptr_xfer->size == 0)
                    {
                        if (ptr_xfer->status == XFER_STATUS_DONE)
                            num_bars = progress_bar_size;
                        else
                            num_bars = 0;
                    }
                    else
                        num_bars = (int)(((float)(pos)/(float)(ptr_xfer->size)) * (float)progress_bar_size);
                    for (i = 0; i < num_bars - 1; i++)
                    {
                        strcat (progress_bar, "=");
                    }
                    if (num_bars > 0)
                        strcat (progress_bar, ">");
                    for (i = 0; i < progress_bar_size - num_bars; i++)
                    {
                        strcat (progress_bar, " ");
                    }
                    strcat (progress_bar, "] ");
                }

                /* computes percentage */
                if (ptr_xfer->size == 0)
                {
                    if (ptr_xfer->status == XFER_STATUS_DONE)
                        pct_complete = 100;
                    else
                        pct_complete = 0;
                }
                else
                    pct_complete = (unsigned long long)(((float)(pos)/(float)(ptr_xfer->size)) * 100);

                /* position, total and bytes per second */
                str_pos = weechat_string_format_size (pos);
                str_total = weechat_string_format_size (ptr_xfer->size);
                str_bytes_per_sec = weechat_string_format_size (ptr_xfer->bytes_per_sec);

                /* ETA */
                eta[0] = '\0';
                if (ptr_xfer->status == XFER_STATUS_ACTIVE)
                {
                    snprintf (eta, sizeof (eta),
                              "%s: %.2llu:%.2llu:%.2llu - ",
                              _("ETA"),
                              ptr_xfer->eta / 3600,
                              (ptr_xfer->eta / 60) % 60,
                              ptr_xfer->eta % 60);
                }

                /* display second line for file with status, progress bar and estimated time */
                weechat_printf_y (xfer_buffer, (line * 2) + 3,
                                  "%s%s%s %s%s%s%s%3llu%%   %s / %s  (%s%s/s)",
                                  weechat_color (str_color),
                                  (line == xfer_buffer_selected_line) ? "*** " : "    ",
                                  (XFER_IS_SEND(ptr_xfer->type)) ? "<<--" : "-->>",
                                  weechat_color (weechat_config_string (xfer_config_color_status[ptr_xfer->status])),
                                  status,
                                  weechat_color (str_color),
                                  (progress_bar) ? progress_bar : "",
                                  pct_complete,
                                  (str_pos) ? str_pos : "?",
                                  (str_total) ? str_total : "?",
                                  eta,
                                  str_bytes_per_sec);
                if (progress_bar)
                    free (progress_bar);
                if (str_pos)
                    free (str_pos);
                if (str_total)
                    free (str_total);
                if (str_bytes_per_sec)
                    free (str_bytes_per_sec);
            }
            line++;
        }
        weechat_buffer_set (xfer_buffer, "hotlist", hotlist);
    }
}