Exemplo n.º 1
0
static VbResult normal_descent(Client *c, const NormalCmdInfo *info)
{
    int count = info->count ? info->count : 1;
    const char *uri, *p = NULL, *domain = NULL;

    uri = c->state.uri;

    /* get domain part */
    if (!uri || !*uri
        || !(domain = strstr(uri, "://"))
        || !(domain = strchr(domain + 3, '/'))
    ) {
        return RESULT_ERROR;
    }

    switch (info->key2) {
        case 'U':
            p = domain;
            break;

        case 'u':
            /* start at the end */
            p = uri + strlen(uri);
            /* if last char is / increment count to step over this first */
            if (*(p - 1) == '/') {
                count++;
            }
            for (int i = 0; i < count; i++) {
                while (*(p--) != '/') {
                    if (p == uri) {
                        /* reach the beginning */
                        return RESULT_ERROR;
                    }
                }
            }
            /* keep the last / in uri */
            p++;
            break;
    }

    /* if the url is shorter than the domain use the domain instead */
    if (p < domain) {
        p = domain;
    }

    Arg a = {TARGET_CURRENT};
    a.s   = g_strndup(uri, p - uri + 1);

    vb_load_uri(c, &a);
    g_free(a.s);

    return RESULT_COMPLETE;
}
Exemplo n.º 2
0
/**
 * Open the last closed page.
 */
static VbResult normal_open(Client *c, const NormalCmdInfo *info)
{
    Arg a;
    if (!vb.files[FILES_CLOSED]) {
        return RESULT_ERROR;
    }

    a.i = info->key == 'U' ? TARGET_NEW : TARGET_CURRENT;
    a.s = util_file_pop_line(vb.files[FILES_CLOSED], NULL);
    if (!a.s) {
        return RESULT_ERROR;
    }

    vb_load_uri(c, &a);
    g_free(a.s);

    return RESULT_COMPLETE;
}
Exemplo n.º 3
0
gboolean command_queue(const Arg *arg)
{
    gboolean res = false;
    int count = 0;
    char *uri;

    switch (arg->i) {
        case COMMAND_QUEUE_POP:
            if ((uri = bookmark_queue_pop(&count))) {
                res = vb_load_uri(&(Arg){VB_TARGET_CURRENT, uri});
                g_free(uri);
            }
            vb_echo(VB_MSG_NORMAL, false, "Queue length %d", count);
            break;

        case COMMAND_QUEUE_PUSH:
            res = bookmark_queue_push(arg->s ? arg->s : vb.state.uri);
            if (res) {
                vb_echo(VB_MSG_NORMAL, false, "Pushed to queue");
            }
            break;

        case COMMAND_QUEUE_UNSHIFT:
            res = bookmark_queue_unshift(arg->s ? arg->s : vb.state.uri);
            if (res) {
                vb_echo(VB_MSG_NORMAL, false, "Pushed to queue");
            }
            break;

        case COMMAND_QUEUE_CLEAR:
            if (bookmark_queue_clear()) {
                vb_echo(VB_MSG_NORMAL, false, "Queue cleared");
            }
            break;
    }

    return res;
}
Exemplo n.º 4
0
static VbResult normal_g_cmd(Client *c, const NormalCmdInfo *info)
{
    Arg a;
    switch (info->key2) {
        case ';': {
            const char prompt[4] = {'g', ';', info->key3, 0};

            return normal_do_hint(c, prompt);
        }

        case 'F':
            return normal_view_inspector(c, info);

        case 'f':
            return normal_view_source(c, info);

        case 'g':
            return normal_scroll(c, info);

        case 'H':
        case 'h':
            a.i = info->key2 == 'H' ? TARGET_NEW : TARGET_CURRENT;
            a.s = NULL;
            vb_load_uri(c, &a);
            return RESULT_COMPLETE;

        case 'i':
            ext_proxy_focus_input(c);
            return RESULT_COMPLETE;

        case 'U':
        case 'u':
            return normal_descent(c, info);
    }

    return RESULT_ERROR;
}
Exemplo n.º 5
0
static VbResult normal_open_clipboard(Client *c, const NormalCmdInfo *info)
{
    Arg a = {info->key == 'P' ? TARGET_NEW : TARGET_CURRENT};

    /* if register is not the default - read out of the internal register */
    if (info->reg) {
        a.s = g_strdup(vb_register_get(c, info->reg));
    } else {
        /* if no register is given use the system clipboard */
        a.s = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
        if (!a.s) {
            a.s = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_NONE));
        }
    }

    if (a.s) {
        vb_load_uri(c, &a);
        g_free(a.s);

        return RESULT_COMPLETE;
    }

    return RESULT_ERROR;
}