/** * @brief Initializes the core, must be called before anything else */ void Core::start() { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; QByteArray savedata = profile.loadToxSave(); if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); if (!msg.isEmpty()) emit statusMessageSet(msg); QString id = getSelfId().toString(); if (!id.isEmpty()) emit idSet(id); // TODO: This is a backwards compatibility check, // once most people have been upgraded away from the old HistoryKeeper, remove this if (Nexus::getProfile()->isEncrypted()) checkEncryptedHistory(); loadFriends(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_name(tox, onFriendNameChange, this); tox_callback_friend_typing(tox, onFriendTypingChange, this); tox_callback_friend_status_message(tox, onStatusMessageChanged, this); tox_callback_friend_status(tox, onUserStatusChanged, this); tox_callback_friend_connection_status(tox, onConnectionStatusChanged, this); tox_callback_friend_read_receipt(tox, onReadReceiptCallback, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback, this); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback, this); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback, this); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback, this); QPixmap pic = profile.loadAvatar(); if (!pic.isNull() && !pic.size().isEmpty()) { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); setAvatar(data); } else { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; setAvatar({}); } ready = true; // If we created a new profile earlier, // now that we're ready save it and ONLY THEN broadcast the new ID. // This is useful for e.g. the profileForm that searches for saves. if (isNewProfile) { profile.saveToxSave(); emit idSet(getSelfId().toString()); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer av->start(); }
/** * @brief Initializes the core, must be called before anything else */ void Core::start(const QByteArray& savedata) { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); makeAv(); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); makeAv(); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) { emit usernameSet(name); } QString msg = getStatusMessage(); if (!msg.isEmpty()) { emit statusMessageSet(msg); } ToxId id = getSelfId(); // TODO: probably useless check, comes basically directly from toxcore if (id.isValid()) { emit idSet(id); } loadFriends(); tox_callback_friend_request(tox, onFriendRequest); tox_callback_friend_message(tox, onFriendMessage); tox_callback_friend_name(tox, onFriendNameChange); tox_callback_friend_typing(tox, onFriendTypingChange); tox_callback_friend_status_message(tox, onStatusMessageChanged); tox_callback_friend_status(tox, onUserStatusChanged); tox_callback_friend_connection_status(tox, onConnectionStatusChanged); tox_callback_friend_read_receipt(tox, onReadReceiptCallback); tox_callback_conference_invite(tox, onGroupInvite); tox_callback_conference_message(tox, onGroupMessage); tox_callback_conference_namelist_change(tox, onGroupNamelistChange); tox_callback_conference_title(tox, onGroupTitleChange); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback); QByteArray data = profile.loadAvatarData(getSelfPublicKey().toString()); if (data.isEmpty()) { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; } setAvatar(data); ready = true; if (isNewProfile) { profile.saveToxSave(); } if (isReady()) { GUI::setEnabled(true); } process(); // starts its own timer av->start(); }