Пример #1
0
void prompt_init_statusbar(ToxWindow *self, Tox *m)
{
    int x2, y2;
    getmaxyx(self->window, y2, x2);

    /* Init statusbar info */
    StatusBar *statusbar = self->stb;
    statusbar->status = TOX_USERSTATUS_NONE;
    statusbar->is_online = false;

    uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
    uint8_t statusmsg[MAX_STR_SIZE];

    pthread_mutex_lock(&Winthread.lock);
    tox_get_self_name(m, nick);
    tox_get_self_status_message(m, statusmsg, MAX_STR_SIZE);
    uint8_t status = tox_get_self_user_status(m);
    pthread_mutex_unlock(&Winthread.lock);

    snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);

    /* load prev status message or show toxic version if it has never been set */
    uint8_t ver[strlen(TOXICVER) + 1];
    strcpy(ver, TOXICVER);
    const uint8_t *toxic_ver = strtok(ver, "_");

    if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL)
        snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver);

    prompt_update_statusmessage(prompt, statusmsg, strlen(statusmsg) + 1);
    prompt_update_status(prompt, status);

    /* Init statusbar subwindow */
    statusbar->topline = subwin(self->window, 2, x2, 0, 0);
}
Пример #2
0
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    bool have_note = false;
    const char *errmsg;

    lock_status ();

    if (argc >= 2) {
        have_note = true;
    } else if (argc < 1) {
        errmsg = "Require a status. Statuses are: online, busy and away.";
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
        goto finish;
    }

    const char *status_str = argv[1];
    TOX_USER_STATUS status;

    if (!strcasecmp(status_str, "online"))
        status = TOX_USER_STATUS_NONE;
    else if (!strcasecmp(status_str, "away"))
        status = TOX_USER_STATUS_AWAY;
    else if (!strcasecmp(status_str, "busy"))
        status = TOX_USER_STATUS_BUSY;
    else {
        errmsg = "Invalid status. Valid statuses are: online, busy and away.";
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
        goto finish;
    }

    tox_self_set_status(m, status);
    prompt_update_status(prompt, status);

    if (have_note) {
        if (argv[2][0] != '\"') {
            line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Note must be enclosed in quotes.");
            goto finish;
        }

        /* remove opening and closing quotes */
        char msg[MAX_STR_SIZE];
        snprintf(msg, sizeof(msg), "%s", &argv[2][1]);
        int len = strlen(msg) - 1;
        msg[len] = '\0';

        prompt_update_statusmessage(prompt, m, msg);
    }

finish:
    unlock_status ();
}
Пример #3
0
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    uint8_t *msg = NULL;
    uint8_t *errmsg;

    if (argc >= 2) {
        msg = argv[2];

        if (msg[0] != '\"') {
            errmsg = "Note must be enclosed in quotes.";
            line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
            return;
        }
    } else if (argc != 1) {
        errmsg = "Wrong number of arguments.";
        line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
        return;
    }

    char *status = argv[1];
    int len = strlen(status);
    char l_status[len + 1];
    int i;

    for (i = 0; i <= len; ++i)
        l_status[i] = tolower(status[i]);

    TOX_USERSTATUS status_kind;

    if (!strcmp(l_status, "online"))
        status_kind = TOX_USERSTATUS_NONE;
    else if (!strcmp(l_status, "away"))
        status_kind = TOX_USERSTATUS_AWAY;
    else if (!strcmp(l_status, "busy"))
        status_kind = TOX_USERSTATUS_BUSY;
    else {
        errmsg = "Invalid status. Valid statuses are: online, busy and away.";
        line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
        return;
    }

    tox_set_user_status(m, status_kind);
    prompt_update_status(prompt, status_kind);

    if (msg != NULL) {
        msg[strlen(++msg) - 1] = L'\0'; /* remove opening and closing quotes */
        uint16_t len = strlen(msg);
        tox_set_status_message(m, msg, len);
        prompt_update_statusmessage(prompt, msg, len);
    }
}
Пример #4
0
void prompt_init_statusbar(ToxWindow *self, Tox *m)
{
    int x2, y2;
    getmaxyx(self->window, y2, x2);
    (void) y2;

    /* Init statusbar info */
    StatusBar *statusbar = self->stb;
    statusbar->status = TOX_USERSTATUS_NONE;
    statusbar->is_online = false;

    char nick[TOX_MAX_NAME_LENGTH];
    char statusmsg[MAX_STR_SIZE];

    uint16_t n_len = tox_get_self_name(m, (uint8_t *) nick);
    uint16_t s_len = tox_get_self_status_message(m, (uint8_t *) statusmsg, MAX_STR_SIZE);
    uint8_t status = tox_get_self_user_status(m);

    nick[n_len] = '\0';
    statusmsg[s_len] = '\0';

    /* load prev status message or show toxic version if it has never been set */
    char ver[strlen(TOXICVER) + 1];
    strcpy(ver, TOXICVER);
    const char *toxic_ver = strtok(ver, "_");

    if ( (s_len <= 0 || !strncmp("Toxing on Toxic", statusmsg, strlen("Toxing on Toxic"))) && toxic_ver != NULL) {
        snprintf(statusmsg, sizeof(statusmsg), "Toxing on Toxic v.%s", toxic_ver);
        s_len = strlen(statusmsg);
        statusmsg[s_len] = '\0';
        tox_set_status_message(m, (uint8_t *) statusmsg, (uint64_t) s_len); 
    }

    prompt_update_statusmessage(prompt, statusmsg);
    prompt_update_status(prompt, status);
    prompt_update_nick(prompt, nick);

    /* Init statusbar subwindow */
    statusbar->topline = subwin(self->window, 2, x2, 0, 0);
}
Пример #5
0
void prompt_init_statusbar(ToxWindow *self, Tox *m)
{
    int x2, y2;
    getmaxyx(self->window, y2, x2);
    (void) y2;

    /* Init statusbar info */
    StatusBar *statusbar = self->stb;
    statusbar->status = TOX_USER_STATUS_NONE;
    statusbar->connection = TOX_CONNECTION_NONE;

    char nick[TOX_MAX_NAME_LENGTH];
    char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];

    size_t n_len = tox_self_get_name_size(m);
    tox_self_get_name(m, (uint8_t *) nick);

    size_t s_len = tox_self_get_status_message_size(m);
    tox_self_get_status_message(m, (uint8_t *) statusmsg);

    TOX_USER_STATUS status = tox_self_get_status(m);

    nick[n_len] = '\0';
    statusmsg[s_len] = '\0';

    if (s_len == 0 || !strncmp(statusmsg, "Toxing on Toxic", strlen("Toxing on Toxic"))) {
        snprintf(statusmsg, sizeof(statusmsg), "Toxing on Toxic");
        s_len = strlen(statusmsg);
        statusmsg[s_len] = '\0';
    }

    prompt_update_statusmessage(prompt, m, statusmsg);
    prompt_update_status(prompt, status);
    prompt_update_nick(prompt, nick);

    /* Init statusbar subwindow */
    statusbar->topline = subwin(self->window, 2, x2, 0, 0);
}
Пример #6
0
static void execute(ToxWindow *self, ChatContext *ctx, StatusBar *statusbar, Tox *m, char *cmd)
{
    if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) {
        wclear(self->window);
        wclear(ctx->history);
        wprintw(ctx->history, "\n\n");
        int x, y;
        getmaxyx(self->window, y, x);
        (void) x;
        wmove(self->window, y - CURS_Y_OFFSET, 0);
    }

    else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h"))
        print_help(ctx);

    else if (!strcmp(cmd, "/quit") || !strcmp(cmd, "/exit") || !strcmp(cmd, "/q")) {
        exit_toxic(m);
    }

    else if (!strncmp(cmd, "/me ", strlen("/me "))) {
        struct tm *timeinfo = get_time();
        uint8_t *action = strchr(cmd, ' ');

        if (action == NULL) {
            wprintw(self->window, "Invalid syntax.\n");
            return;
        }

        action++;

        wattron(ctx->history, COLOR_PAIR(CYAN));
        wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
        wattroff(ctx->history, COLOR_PAIR(CYAN));

        uint8_t selfname[TOX_MAX_NAME_LENGTH];
        tox_getselfname(m, selfname, TOX_MAX_NAME_LENGTH);

        wattron(ctx->history, COLOR_PAIR(YELLOW));
        wprintw(ctx->history, "* %s %s\n", selfname, action);
        wattroff(ctx->history, COLOR_PAIR(YELLOW));

        if (!statusbar->is_online
                || tox_sendaction(m, self->friendnum, action, strlen(action) + 1) == 0) {
            wattron(ctx->history, COLOR_PAIR(RED));
            wprintw(ctx->history, " * Failed to send action\n");
            wattroff(ctx->history, COLOR_PAIR(RED));
        }
    }

    else if (!strncmp(cmd, "/status ", strlen("/status "))) {
        char *status = strchr(cmd, ' ');

        if (status == NULL) {
            wprintw(ctx->history, "Invalid syntax.\n");
            return;
        }

        status++;
        TOX_USERSTATUS status_kind;

        if (!strncmp(status, "online", strlen("online"))) {
            status_kind = TOX_USERSTATUS_NONE;
            wprintw(ctx->history, "Status set to: ");
            wattron(ctx->history, COLOR_PAIR(GREEN) | A_BOLD);
            wprintw(ctx->history, "[Online]\n");
            wattroff(ctx->history, COLOR_PAIR(GREEN) | A_BOLD);
        }

        else if (!strncmp(status, "away", strlen("away"))) {
            status_kind = TOX_USERSTATUS_AWAY;
            wprintw(ctx->history, "Status set to: ");
            wattron(ctx->history, COLOR_PAIR(YELLOW) | A_BOLD);
            wprintw(ctx->history, "[Away]\n");
            wattroff(ctx->history, COLOR_PAIR(YELLOW) | A_BOLD);
        }

        else if (!strncmp(status, "busy", strlen("busy"))) {
            status_kind = TOX_USERSTATUS_BUSY;
            wprintw(ctx->history, "Status set to: ");
            wattron(ctx->history, COLOR_PAIR(RED) | A_BOLD);
            wprintw(ctx->history, "[Busy]\n");
            wattroff(ctx->history, COLOR_PAIR(RED) | A_BOLD);
        }

        else {
            wprintw(ctx->history, "Invalid status.\n");
            return;
        }

        tox_set_userstatus(m, status_kind);
        prompt_update_status(self->prompt, status_kind); 

        uint8_t *msg = strchr(status, ' ');
        if (msg != NULL) {
            msg++;
            uint16_t len = strlen(msg) + 1;
            tox_set_statusmessage(m, msg, len);
            prompt_update_statusmessage(self->prompt, msg, len);
            wprintw(ctx->history, "Personal note set to: %s\n", msg);
        }
    }

    else if (!strncmp(cmd, "/note ", strlen("/note "))) {
        uint8_t *msg = strchr(cmd, ' ');
        msg++;
        uint16_t len = strlen(msg) + 1;
        tox_set_statusmessage(m, msg, len);
        prompt_update_statusmessage(self->prompt, msg, len);
        wprintw(ctx->history, "Personal note set to: %s\n", msg);
    }

    else if (!strncmp(cmd, "/nick ", strlen("/nick "))) {
        uint8_t *nick = strchr(cmd, ' ');

        if (nick == NULL) {
            wprintw(ctx->history, "Invalid syntax.\n");
            return;
        }

        int len = strlen(++nick);

        if (len > TOXIC_MAX_NAME_LENGTH) {
            nick[TOXIC_MAX_NAME_LENGTH] = L'\0';
            len = TOXIC_MAX_NAME_LENGTH;
        }

        tox_setname(m, nick, len+1);
        prompt_update_nick(self->prompt, nick);
        wprintw(ctx->history, "Nickname set to: %s\n", nick);
    }

    else if (!strcmp(cmd, "/myid")) {
        char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {'\0'};
        size_t i;
        uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
        tox_getaddress(m, address);

        for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
            char xx[3];
            snprintf(xx, sizeof(xx), "%02X",  address[i] & 0xff);
            strcat(id, xx);
        }

        wprintw(ctx->history, "%s\n", id);
    }

    else
        wprintw(ctx->history, "Invalid command.\n");
}