void Core::setStatus(Status status) { TOX_USERSTATUS userstatus; switch (status) { case Status::Online: userstatus = TOX_USERSTATUS_NONE; break; case Status::Away: userstatus = TOX_USERSTATUS_AWAY; break; case Status::Busy: userstatus = TOX_USERSTATUS_BUSY; break; default: userstatus = TOX_USERSTATUS_INVALID; break; } if (tox_set_user_status(tox, userstatus) == 0) { saveConfiguration(); emit statusSet(status); } else { emit failedToSetStatus(status); } }
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); } }
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { bool have_note = false; const char *errmsg; 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); return; } char status[MAX_STR_SIZE]; snprintf(status, sizeof(status), "%s", argv[1]); str_to_lower(status); TOX_USERSTATUS status_kind; if (!strcmp(status, "online")) status_kind = TOX_USERSTATUS_NONE; else if (!strcmp(status, "away")) status_kind = TOX_USERSTATUS_AWAY; else if (!strcmp(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, SYS_MSG, 0, 0, errmsg); return; } tox_set_user_status(m, status_kind); prompt_update_status(prompt, status_kind); if (have_note) { if (argv[2][0] != '\"') { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Note must be enclosed in quotes."); return; } /* 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); } }
void Core::setStatus(Status status) { TOX_USERSTATUS userstatus; switch (status) { case Status::Online: userstatus = TOX_USERSTATUS_NONE; break; case Status::Away: userstatus = TOX_USERSTATUS_AWAY; break; case Status::Busy: userstatus = TOX_USERSTATUS_BUSY; break; default: userstatus = TOX_USERSTATUS_INVALID; break; } tox_set_user_status(tox, userstatus); }
static void tox_thread_message(Tox *tox, ToxAv *av, uint64_t time, uint8_t msg, uint16_t param1, uint16_t param2, void *data) { switch(msg) { case TOX_SETNAME: { /* param1: name length * data: name */ tox_set_name(tox, data, param1); break; } case TOX_SETSTATUSMSG: { /* param1: status length * data: status message */ tox_set_status_message(tox, data, param1); break; } case TOX_SETSTATUS: { /* param1: status */ tox_set_user_status(tox, param1); break; } case TOX_ADDFRIEND: { /* param1: length of message * data: friend id + message */ int r; if(!param1) { STRING* default_add_msg = SPTR(DEFAULT_FRIEND_REQUEST_MESSAGE); r = tox_add_friend(tox, data, default_add_msg->str, default_add_msg->length); } else { r = tox_add_friend(tox, data, data + TOX_FRIEND_ADDRESS_SIZE, param1); } if(r < 0) { uint8_t addf_error; switch(r) { case TOX_FAERR_TOOLONG: addf_error = ADDF_TOOLONG; break; case TOX_FAERR_NOMESSAGE: addf_error = ADDF_NOMESSAGE; break; case TOX_FAERR_OWNKEY: addf_error = ADDF_OWNKEY; break; case TOX_FAERR_ALREADYSENT: addf_error = ADDF_ALREADYSENT; break; case TOX_FAERR_BADCHECKSUM: addf_error = ADDF_BADCHECKSUM; break; case TOX_FAERR_SETNEWNOSPAM: addf_error = ADDF_SETNEWNOSPAM; break; case TOX_FAERR_NOMEM: addf_error = ADDF_NOMEM; break; case TOX_FAERR_UNKNOWN: default: addf_error = ADDF_UNKNOWN; break; } postmessage(FRIEND_ADD, 1, addf_error, data); } else { postmessage(FRIEND_ADD, 0, r, data); } break; } case TOX_DELFRIEND: { /* param1: friend # */ tox_del_friend(tox, param1); postmessage(FRIEND_DEL, 0, 0, data); break; } case TOX_ACCEPTFRIEND: { /* data: FRIENDREQ */ FRIENDREQ *req = data; int r = tox_add_friend_norequest(tox, req->id); postmessage(FRIEND_ACCEPT, (r < 0), (r < 0) ? 0 : r, req); break; } case TOX_SENDMESSAGE: { /* param1: friend # * param2: message length * data: message */ log_write(tox, param1, data, param2, 1, LOG_FILE_MSG_TYPE_TEXT); void *p = data; while(param2 > TOX_MAX_MESSAGE_LENGTH) { uint16_t len = TOX_MAX_MESSAGE_LENGTH - utf8_unlen(p + TOX_MAX_MESSAGE_LENGTH); tox_send_message(tox, param1, p, len); param2 -= len; p += len; } tox_send_message(tox, param1, p, param2); free(data); break; } case TOX_SENDACTION: { /* param1: friend # * param2: message length * data: message */ log_write(tox, param1, data, param2, 1, LOG_FILE_MSG_TYPE_ACTION); void *p = data; while(param2 > TOX_MAX_MESSAGE_LENGTH) { uint16_t len = TOX_MAX_MESSAGE_LENGTH - utf8_unlen(p + TOX_MAX_MESSAGE_LENGTH); tox_send_action(tox, param1, p, len); param2 -= len; p += len; } tox_send_action(tox, param1, p, param2); free(data); break; } case TOX_SENDMESSAGEGROUP: { /* param1: group # * param2: message length * data: message */ tox_group_message_send(tox, param1, data, param2); free(data); break; } case TOX_SENDACTIONGROUP: { /* param1: group # * param2: message length * data: message */ tox_group_action_send(tox, param1, data, param2); free(data); } case TOX_SET_TYPING: { /* param1: friend # */ // Check if user has switched to another friend window chat. // Take care not to react on obsolete data from old Tox instance. _Bool need_resetting = (typing_state.tox == tox) && (typing_state.friendnumber != param1) && (typing_state.sent_value); if(need_resetting) { // Tell previous friend that he's betrayed. tox_set_user_is_typing(tox, typing_state.friendnumber, 0); // Mark that new friend doesn't know that we're typing yet. typing_state.sent_value = 0; } // Mark us as typing to this friend at the moment. // utox_thread_work_for_typing_notifications() will // send a notification if it deems necessary. typing_state.tox = tox; typing_state.friendnumber = param1; typing_state.time = time; //debug("Set typing state for friend (%d): %d\n", typing_state.friendnumber, typing_state.sent_value); break; } case TOX_CALL: { /* param1: friend # */ int32_t id; toxav_call(av, &id, param1, &av_DefaultSettings, 10); postmessage(FRIEND_CALL_STATUS, param1, id, (void*)CALL_RINGING); break; } case TOX_CALL_VIDEO: { /* param1: friend # */ ToxAvCSettings settings = av_DefaultSettings; settings.call_type = av_TypeVideo; settings.max_video_width = max_video_width; settings.max_video_height = max_video_height; int32_t id; toxav_call(av, &id, param1, &settings, 10); postmessage(FRIEND_CALL_STATUS, param1, id, (void*)CALL_RINGING_VIDEO); break; } case TOX_CALL_VIDEO_ON: { /* param1: friend # * param2: call # */ ToxAvCSettings settings = av_DefaultSettings; settings.call_type = av_TypeVideo; settings.max_video_width = max_video_width; settings.max_video_height = max_video_height; toxav_change_settings(av, param2, &settings); postmessage(FRIEND_CALL_START_VIDEO, param1, param2, NULL); break; } case TOX_CALL_VIDEO_OFF: { /* param1: friend # * param2: call # */ toxav_change_settings(av, param2, &av_DefaultSettings); postmessage(FRIEND_CALL_STOP_VIDEO, param1, param2, NULL); break; } case TOX_ACCEPTCALL: { /* param1: call # */ ToxAvCSettings settings = av_DefaultSettings; if(param2) { settings.call_type = av_TypeVideo; settings.max_video_width = max_video_width; settings.max_video_height = max_video_height; } toxav_answer(av, param1, &settings); break; } case TOX_HANGUP: { /* param1: call # */ toxav_hangup(av, param1); break; } case TOX_NEWGROUP: { /* */ int g = -1; if (param1) { g = toxav_add_av_groupchat(tox, &callback_av_group_audio, NULL); } else { g = tox_add_groupchat(tox); } if(g != -1) { postmessage(GROUP_ADD, g, 0, tox); } break; } case TOX_LEAVEGROUP: { /* param1: group # */ tox_del_groupchat(tox, param1); break; } case TOX_GROUPINVITE: { /* param1: group # * param2: friend # */ tox_invite_friend(tox, param2, param1); break; } case TOX_GROUPCHANGETOPIC: { /* param1: group # * param2: topic length * data: topic */ tox_group_set_title(tox, param1, data, param2); postmessage(GROUP_TITLE, param1, param2, data); break; } case TOX_GROUP_AUDIO_START:{ /* param1: group # */ postmessage(GROUP_AUDIO_START, param1, 0, NULL); break; } case TOX_GROUP_AUDIO_END:{ /* param1: group # */ postmessage(GROUP_AUDIO_END, param1, 0, NULL); break; } case TOX_SENDFILES: { /* param1: friend # * param2: offset of first file name in data * data: file names */ if(param2 == 0xFFFF) { //paths with line breaks uint8_t *name = data, *p = data, *s = name; while(*p) { _Bool end = 1; while(*p) { if(*p == '\n') { *p = 0; end = 0; break; } if(*p == '/' || *p == '\\') { s = p + 1; } p++; } if(strcmp2(name, "file://") == 0) { name += 7; } utox_transfer_start_file(tox, param1, name, s, p - s); p++; s = name = p; if(end) { break; } } } else { //windows path list uint8_t *name = data; _Bool multifile = (name[param2 - 1] == 0); if(!multifile) { utox_transfer_start_file(tox, param1, data, data + param2, strlen(data) - param2); } else { uint8_t *p = name + param2; name += param2 - 1; if(*(name - 1) != '\\') { *name++ = '\\'; } while(*p) { int len = strlen((char*)p) + 1; memmove(name, p, len); p += len; utox_transfer_start_file(tox, param1, data, name, len - 1); } } } free(data); break; } case TOX_SEND_INLINE: { /* param1: friend id data: pointer to a TOX_SEND_INLINE_MSG struct */ struct TOX_SEND_INLINE_MSG *tsim = data; utox_transfer_start_memory(tox, param1, tsim->image->png_data, tsim->image_size); free(tsim); break; } case TOX_ACCEPTFILE: { /* param1: friend # * param2: file # * data: path to write file */ FILE_T *ft = &friend[param1].incoming[param2]; ft->data = fopen(data, "wb"); if(!ft->data) { free(data); break; } ft->path = data; ft->status = FT_SEND; tox_file_send_control(tox, param1, 1, param2, TOX_FILECONTROL_ACCEPT, NULL, 0); postmessage(FRIEND_FILE_IN_STATUS, param1, param2, (void*)FILE_OK); break; } case TOX_FILE_IN_CANCEL: { /* param1: friend # * param2: file # */ FILE_T *ft = &friend[param1].incoming[param2]; if(ft->data) { if(ft->inline_png) { free(ft->data); } else { fclose(ft->data); free(ft->path); } } ft->status = FT_NONE; tox_file_send_control(tox, param1, 1, param2, TOX_FILECONTROL_KILL, NULL, 0); postmessage(FRIEND_FILE_IN_STATUS, param1, param2, (void*)FILE_KILLED); break; } case TOX_FILE_OUT_CANCEL: { /* param1: friend # * param2: file # */ FILE_T *ft = &friend[param1].outgoing[param2]; ft->status = FT_KILL; tox_file_send_control(tox, param1, 0, param2, TOX_FILECONTROL_KILL, NULL, 0); postmessage(FRIEND_FILE_OUT_STATUS, param1, param2, (void*)FILE_KILLED); break; } case TOX_FILE_IN_PAUSE: { /* param1: friend # * param2: file # */ tox_file_send_control(tox, param1, 1, param2, TOX_FILECONTROL_PAUSE, NULL, 0); postmessage(FRIEND_FILE_IN_STATUS, param1, param2, (void*)FILE_PAUSED); break; } case TOX_FILE_OUT_PAUSE: { /* param1: friend # * param2: file # */ FILE_T *ft = &friend[param1].outgoing[param2]; ft->status = FT_PAUSE; tox_file_send_control(tox, param1, 0, param2, TOX_FILECONTROL_PAUSE, NULL, 0); postmessage(FRIEND_FILE_OUT_STATUS, param1, param2, (void*)FILE_PAUSED); break; } case TOX_FILE_IN_RESUME: { /* param1: friend # * param2: file # */ tox_file_send_control(tox, param1, 1, param2, TOX_FILECONTROL_ACCEPT, NULL, 0); postmessage(FRIEND_FILE_IN_STATUS, param1, param2, (void*)FILE_OK); break; } case TOX_FILE_OUT_RESUME: { /* param1: friend # * param2: file # */ FILE_T *ft = &friend[param1].outgoing[param2]; ft->status = FT_SEND; tox_file_send_control(tox, param1, 0, param2, TOX_FILECONTROL_ACCEPT, NULL, 0); postmessage(FRIEND_FILE_OUT_STATUS, param1, param2, (void*)FILE_OK); break; } } }