static void button_group_audio_onpress(void) { GROUPCHAT *g = selected_item->data; if (g->audio_calling) { postmessage_toxcore(TOX_GROUP_AUDIO_END, (g - group), 0, NULL); } else { postmessage_toxcore(TOX_GROUP_AUDIO_START, (g - group), 0, NULL); } }
static void button_group_audio_on_mup(void) { GROUPCHAT *g = flist_get_groupchat(); if (!g) { LOG_ERR("Group", "Could not get selected groupchat."); return; } // We have to take the long way around, because the UI shouldn't depend on AV if (g->active_call) { postmessage_toxcore(TOX_GROUP_AUDIO_END, g->number, 0, NULL); } else { postmessage_toxcore(TOX_GROUP_AUDIO_START, g->number, 0, NULL); } }
void friend_addid(uint8_t *id, char_t *msg, STRING_IDX msg_length) { void *data = malloc(TOX_FRIEND_ADDRESS_SIZE + msg_length * sizeof(char_t)); memcpy(data, id, TOX_FRIEND_ADDRESS_SIZE); memcpy(data + TOX_FRIEND_ADDRESS_SIZE, msg, msg_length * sizeof(char_t)); postmessage_toxcore(TOX_FRIEND_NEW, msg_length, 0, data); }
void self_remove_avatar() { unset_avatar(&self.avatar); uint8_t hex_id[TOX_FRIEND_ADDRESS_SIZE * 2]; id_to_string(hex_id, self.id_binary); delete_saved_avatar(hex_id); postmessage_toxcore(TOX_AVATAR_UNSET, 0, 0, NULL); }
void native_select_dir_ft(uint32_t fid, MSG_FILE *file) { char *path = malloc(UTOX_FILE_NAME_LENGTH); memcpy(path, file->name, file->name_length); path[file->name_length] = 0; OPENFILENAME ofn = { .lStructSize = sizeof(OPENFILENAME), .hwndOwner = hwnd, .lpstrFile = path, .nMaxFile = UTOX_FILE_NAME_LENGTH, .Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT, }; if(GetSaveFileName(&ofn)) { postmessage_toxcore(TOX_FILE_ACCEPT, fid, file->filenumber, path); } else { debug("GetSaveFileName() failed\n"); } } void native_autoselect_dir_ft(uint32_t fid, FILE_TRANSFER *file) { wchar_t *path[UTOX_FILE_NAME_LENGTH]; if(!SHGetKnownFolderPath((REFKNOWNFOLDERID)&FOLDERID_Downloads, KF_FLAG_CREATE, 0, path)) { wchar_t first[UTOX_FILE_NAME_LENGTH]; wchar_t second[UTOX_FILE_NAME_LENGTH]; wchar_t longname[UTOX_FILE_NAME_LENGTH]; swprintf(first, UTOX_FILE_NAME_LENGTH, L"%ls%ls", *path, L"\\Tox_Auto_Accept"); CreateDirectoryW(first, NULL); MultiByteToWideChar(CP_UTF8, 0, (char*)file->name, file->name_length, longname, file->name_length); swprintf(second, UTOX_FILE_NAME_LENGTH, L"%ls\\%ls", first, longname); char *send = malloc(UTOX_FILE_NAME_LENGTH); native_to_utf8str(second, send, UTOX_FILE_NAME_LENGTH); postmessage_toxcore(TOX_FILE_ACCEPT_AUTO, fid, file->file_number, send); } else { debug("NATIVE:\tUnable to auto save file!\n"); } }
/* sets self avatar, see self_set_and_save_avatar */ int self_set_avatar(const uint8_t *data, uint32_t size) { if (!set_avatar(-1, data, size)) { return 0; } uint8_t *png_data = malloc(size); memcpy(png_data, data, size); postmessage_toxcore(TOX_AVATAR_SET, UTOX_AVATAR_FORMAT_PNG, size, png_data); return 1; }
void e_group_msg_onenter(EDIT *edit) { char *text = edit->data; uint16_t length = edit->length; if (length <= 0) { return; } uint16_t command_length = 0; //, argument_length = 0; char *command = NULL; char *argument = NULL; command_length = utox_run_command(text, length, &command, &argument, 1); // TODO: Magic number if (command_length == UINT16_MAX) { edit->length = 0; return; } // LOG_NOTE("Group", "cmd %u\n", command_length); bool action = false; if (command_length) { length = length - command_length - 2; /* first / and then the SPACE */ text = argument; if ((command_length == 2) && (!memcmp(command, "me", 2))) { if (argument) { action = true; } else { return; } } } if (!text) { return; } GROUPCHAT *g = flist_get_groupchat(); if (g) { void *d = malloc(length); if (!d) { LOG_ERR("Layout Group", "edit_msg_onenter:\t Ran out of memory."); return; } memcpy(d, text, length); postmessage_toxcore((action ? TOX_GROUP_SEND_ACTION : TOX_GROUP_SEND_MESSAGE), g->number, length, d); } else { LOG_ERR("Groups", "No Group selected!"); } completion.active = 0; edit->length = 0; }
static void edit_name_onenter(EDIT *edit) { char_t *data = edit->data; STRING_IDX length = edit->length; memcpy(self.name, data, length); self.name_length = length; update_tray(); postmessage_toxcore(TOX_SELF_SET_NAME, length, 0, self.name);//! }
static void button_call_audio_onpress(void) { FRIEND *f = selected_item->data; if (f->call_state_self) { if (UTOX_SENDING_AUDIO(f->number)) { debug("Ending call: %u\n", f->number); /* var 3/4 = bool send video */ postmessage_toxcore(TOX_CALL_DISCONNECT, f->number, 0, NULL); } else { debug("Canceling call: friend = %d\n", f->number); postmessage_toxcore(TOX_CALL_DISCONNECT, f->number, 0, NULL); } } else if (UTOX_AVAILABLE_AUDIO(f->number)) { debug("Accept Call: %u\n", f->number); postmessage_toxcore(TOX_CALL_ANSWER, f->number, 0, NULL); } else { if (f->online) { postmessage_toxcore(TOX_CALL_SEND, f->number, 0, NULL); debug("Calling friend: %u\n", f->number); } } }
static void button_status_onpress(void) { self.status++; if (self.status == 3) { self.status = 0; } #ifdef UNITY if(unity_running) { mm_set_status(self.status); } #endif postmessage_toxcore(TOX_SELF_SET_STATE, self.status, 0, NULL); }
static void button_call_video_onpress(void) { FRIEND *f = selected_item->data; if (f->call_state_self) { if (SELF_ACCEPT_VIDEO(f->number)) { debug("Canceling call (video): %u\n", f->number); postmessage_toxcore(TOX_CALL_DISCONNECT, f->number, 1, NULL); } else if (UTOX_SENDING_AUDIO(f->number)) { debug("Audio call inprogress, adding video\n"); postmessage_toxcore(TOX_CALL_RESUME_VIDEO, f->number, 1, NULL); } else { debug("Ending call (video): %u\n", f->number); postmessage_toxcore(TOX_CALL_DISCONNECT, f->number, 1, NULL); } } else if (f->call_state_friend) { debug("Accept Call (video): %u %u\n", f->number, f->call_state_friend); postmessage_toxcore(TOX_CALL_ANSWER, f->number, 1, NULL); } else { if (f->online) { postmessage_toxcore(TOX_CALL_SEND, f->number, 1, NULL); debug("Calling friend (video): %u\n", f->number); } } }
static void e_group_topic_onenter(EDIT *edit) { GROUPCHAT *g = flist_get_groupchat(); if (!g) { LOG_ERR("Layout Groups", "Can't set a topic when a group isn't selected!"); return; } void *d = malloc(edit->length); if (!d){ LOG_ERR("Layout Groups", "Unable to change group topic."); return; } memcpy(d, edit->data, edit->length); postmessage_toxcore(TOX_GROUP_SET_TOPIC, g->number, edit->length, d); }
static void ugtk_opensendthread(void *args) { size_t fid = (size_t)args; void *dialog = utoxGTK_file_chooser_dialog_new((const char *)S(SEND_FILE), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, NULL); utoxGTK_file_chooser_set_select_multiple(dialog, true); void *preview = utoxGTK_image_new(); utoxGTK_file_chooser_set_preview_widget(dialog, preview); utoxGTK_signal_connect_data(dialog, "update-preview", update_image_preview, preview, NULL, 0); int result = utoxGTK_dialog_run(dialog); if (result == GTK_RESPONSE_ACCEPT) { GSList *list = utoxGTK_file_chooser_get_filenames(dialog), *p = list; while (p) { UTOX_MSG_FT *send = calloc(1, sizeof(UTOX_MSG_FT)); if (!send) { LOG_ERR("GTK", "GTK:\tUnabled to malloc for to send an FT msg"); while(p) { utoxGTK_free(p->data); p = p->next; } utoxGTK_slist_free(list); utoxGTK_open = false; return; } LOG_INFO("GTK", "Sending file %s" , p->data); send->file = fopen(p->data, "rb"); send->name = (uint8_t*)strdup(p->data); postmessage_toxcore(TOX_FILE_SEND_NEW, (uint32_t)fid, 0, send); utoxGTK_free(p->data); p = p->next; } utoxGTK_slist_free(list); } utoxGTK_widget_destroy(dialog); while (utoxGTK_events_pending()) { utoxGTK_main_iteration(); } utoxGTK_open = false; }
static void gtk_opensendthread(void *args) { uint16_t fid = (size_t)args; void *dialog = gtk_file_chooser_dialog_new((const char *)S(SEND_FILE), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_select_multiple(dialog, true); void *preview = gtk_image_new(); gtk_file_chooser_set_preview_widget(dialog, preview); g_signal_connect_data(dialog, "update-preview", update_image_preview, preview, NULL, 0); int result = gtk_dialog_run(dialog); if(result == GTK_RESPONSE_ACCEPT) { char *out = malloc(65536), *outp = out; GSList *list = gtk_file_chooser_get_filenames(dialog), *p = list; while(p) { outp = stpcpy(outp, p->data); *outp++ = '\n'; g_free_utox(p->data); p = p->next; } *outp = 0; g_slist_free_utox(list); debug("files: %s\n", out); //dont call this from this thread postmessage_toxcore(TOX_FILE_SEND_NEW, fid, 0xFFFF, out); } gtk_widget_destroy(dialog); while(gtk_events_pending()) { gtk_main_iteration(); } gtk_open = false; }
static void edit_status_onenter(EDIT *edit) { char_t *data = edit->data; STRING_IDX length = edit->length; if(length) { void *p = realloc(self.statusmsg, length); if(!p) { return; } self.statusmsg = p; memcpy(self.statusmsg, data, length); self.statusmsg_length = length; } else { self.statusmsg_length = length; } update_tray(); postmessage_toxcore(TOX_SELF_SET_STATUS, length, 0, self.statusmsg);//! }
void native_export_chatlog_init(uint32_t friend_number) { FRIEND *f = get_friend(friend_number); if (!f) { LOG_ERR("Windows7", "Could not get friend with number: %u", friend_number); return; } char *path = calloc(1, UTOX_FILE_NAME_LENGTH); if (!path){ LOG_ERR("Windows7", " Could not allocate memory." ); return; } snprintf(path, UTOX_FILE_NAME_LENGTH, "%.*s.txt", (int)f->name_length, f->name); wchar_t filepath[UTOX_FILE_NAME_LENGTH] = { 0 }; utf8_to_nativestr(path, filepath, UTOX_FILE_NAME_LENGTH * 2); OPENFILENAMEW ofn = { .lStructSize = sizeof(OPENFILENAMEW), .lpstrFilter = L".txt", .lpstrFile = filepath, .nMaxFile = UTOX_FILE_NAME_LENGTH, .Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT, .lpstrDefExt = L"txt", }; if (GetSaveFileNameW(&ofn)) { path = calloc(1, UTOX_FILE_NAME_LENGTH); if (!path){ LOG_ERR("Windows7", " Could not allocate memory." ); return; } native_to_utf8str(filepath, path, UTOX_FILE_NAME_LENGTH); FILE *file = utox_get_file_simple(path, UTOX_FILE_OPTS_WRITE); if (file) { utox_export_chatlog(f->id_str, file); } else { LOG_ERR("Windows7", "Opening file %s failed", path); } } else { LOG_ERR("Windows7", "Unable to open file and export chatlog."); } free(path); } void native_select_dir_ft(uint32_t fid, uint32_t num, FILE_TRANSFER *file) { if (!sanitize_filename(file->name)) { LOG_ERR("Windows7", "Filename is invalid and could not be sanitized"); return; } wchar_t filepath[UTOX_FILE_NAME_LENGTH] = { 0 }; utf8_to_nativestr((char *)file->name, filepath, file->name_length * 2); OPENFILENAMEW ofn = { .lStructSize = sizeof(OPENFILENAMEW), .lpstrFile = filepath, .nMaxFile = UTOX_FILE_NAME_LENGTH, .Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT, }; if (GetSaveFileNameW(&ofn)) { char *path = calloc(1, UTOX_FILE_NAME_LENGTH); if (!path) { LOG_ERR("Windows7", "Could not allocate memory for path."); return; } native_to_utf8str(filepath, path, UTOX_FILE_NAME_LENGTH * 2); postmessage_toxcore(TOX_FILE_ACCEPT, fid, num, path); } else { LOG_ERR("Windows7", "Unable to Get save file for incoming FT."); } } void native_autoselect_dir_ft(uint32_t fid, FILE_TRANSFER *file) { wchar_t *autoaccept_folder = NULL; if (settings.portable_mode) { autoaccept_folder = calloc(1, UTOX_FILE_NAME_LENGTH * sizeof(wchar_t)); utf8_to_nativestr(portable_mode_save_path, autoaccept_folder, strlen(portable_mode_save_path) * 2); } else if (SHGetKnownFolderPath((REFKNOWNFOLDERID)&FOLDERID_Downloads, KF_FLAG_CREATE, NULL, &autoaccept_folder) != S_OK) { LOG_ERR("Windows7", "Unable to get auto accept file folder!"); return; } wchar_t subpath[UTOX_FILE_NAME_LENGTH] = { 0 }; swprintf(subpath, UTOX_FILE_NAME_LENGTH, L"%ls%ls", autoaccept_folder, L"\\Tox_Auto_Accept"); if (settings.portable_mode) { free(autoaccept_folder); } else { CoTaskMemFree(autoaccept_folder); } CreateDirectoryW(subpath, NULL); if (!sanitize_filename(file->name)) { LOG_ERR("Windows7", "Filename is invalid and could not be sanitized"); return; } wchar_t filename[UTOX_FILE_NAME_LENGTH] = { 0 }; utf8_to_nativestr((char *)file->name, filename, file->name_length * 2); wchar_t fullpath[UTOX_FILE_NAME_LENGTH] = { 0 }; swprintf(fullpath, UTOX_FILE_NAME_LENGTH, L"%ls\\%ls", subpath, filename); char *path = calloc(1, UTOX_FILE_NAME_LENGTH); if (!path) { LOG_ERR("Windows7", "Could not allocate memory for path."); return; } native_to_utf8str(fullpath, path, UTOX_FILE_NAME_LENGTH); postmessage_toxcore(TOX_FILE_ACCEPT_AUTO, fid, file->file_number, path); } void launch_at_startup(bool should) { const wchar_t *run_key_path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; if (should) { HKEY hKey; if (RegOpenKeyW(HKEY_CURRENT_USER, run_key_path, &hKey) == ERROR_SUCCESS) { wchar_t path[UTOX_FILE_NAME_LENGTH * 2]; uint16_t path_length = GetModuleFileNameW(NULL, path + 1, UTOX_FILE_NAME_LENGTH * 2); path[0] = '\"'; path[path_length + 1] = '\"'; path[path_length + 2] = '\0'; path_length += 2; // 2 bytes per wchar_t uint16_t ret = RegSetKeyValueW(hKey, NULL, L"uTox", REG_SZ, path, path_length * 2); if (ret == ERROR_SUCCESS) { LOG_INFO("Windows7", "Set uTox to run at startup."); } else { LOG_ERR("Windows7", "Unable to set Registry key for startup."); } RegCloseKey(hKey); } } else { HKEY hKey; if (ERROR_SUCCESS == RegOpenKeyW(HKEY_CURRENT_USER, run_key_path, &hKey)) { uint16_t ret = RegDeleteKeyValueW(hKey, NULL, L"uTox"); if (ret == ERROR_SUCCESS) { LOG_INFO("Windows7", "Set uTox to not run at startup."); } else { LOG_ERR("Windows7", "Unable to delete Registry key for startup."); } RegCloseKey(hKey); } } }
void self_remove_avatar(void) { unset_avatar(&self.avatar); delete_saved_avatar(-1); postmessage_toxcore(TOX_AVATAR_UNSET, 0, 0, NULL); }
static void button_accept_friend_onpress(void) { FRIENDREQ *req = selected_item->data; postmessage_toxcore(TOX_FRIEND_ACCEPT, 0, 0, req); panel_friend_request.disabled = 1; }