bool Profile::checkPassword() { if (isRemoved) return false; return !loadToxSave().isEmpty(); }
QByteArray Core::loadToxSave(QString path) { QByteArray data; loadPath = ""; // if not empty upon return, then user forgot a password and is switching // If we can't get a lock, then another instance is already using that profile while (!ProfileLocker::lock(QFileInfo(path).baseName())) { qWarning() << "Profile "<<QFileInfo(path).baseName()<<" is already in use, pick another"; GUI::showWarning(tr("Profile already in use"), tr("Your profile is already used by another qTox\n" "Please select another profile")); QString tmppath = Settings::getInstance().askProfiles(); if (tmppath.isEmpty()) continue; Settings::getInstance().switchProfile(tmppath); path = QDir(Settings::getSettingsDirPath()).filePath(tmppath + TOX_EXT); HistoryKeeper::resetInstance(); } QFile configurationFile(path); qDebug() << "Core::loadConfiguration: reading from " << path; if (!configurationFile.exists()) { qWarning() << "The Tox configuration file "<<path<<" was not found"; return data; } if (!configurationFile.open(QIODevice::ReadOnly)) { qCritical() << "File " << path << " cannot be opened"; return data; } qint64 fileSize = configurationFile.size(); if (fileSize > 0) { data = configurationFile.readAll(); if (tox_is_data_encrypted((uint8_t*)data.data())) { if (!loadEncryptedSave(data)) { configurationFile.close(); QString profile; do { profile = Settings::getInstance().askProfiles(); } while (profile.isEmpty()); if (!profile.isEmpty()) { Settings::getInstance().switchProfile(profile); HistoryKeeper::resetInstance(); return loadToxSave(QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT)); } return QByteArray(); } } } configurationFile.close(); return data; }
void Core::start() { qDebug() << "Core: Starting up"; QByteArray savedata = loadToxSave(loadPath); make_tox(savedata); // Do we need to create a new save & profile? if (savedata.isNull()) { qDebug() << "Save file not found, creating a new profile"; Settings::getInstance().load(); setStatusMessage(tr("Toxing on qTox")); setUsername(tr("qTox User")); } qsrand(time(nullptr)); // 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); // tox core is already decrypted if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs()) 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); toxav_register_callstate_callback(toxav, onAvInvite, av_OnInvite, this); toxav_register_callstate_callback(toxav, onAvStart, av_OnStart, this); toxav_register_callstate_callback(toxav, onAvCancel, av_OnCancel, this); toxav_register_callstate_callback(toxav, onAvReject, av_OnReject, this); toxav_register_callstate_callback(toxav, onAvEnd, av_OnEnd, this); toxav_register_callstate_callback(toxav, onAvRinging, av_OnRinging, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnPeerCSChange, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnSelfCSChange, this); toxav_register_callstate_callback(toxav, onAvRequestTimeout, av_OnRequestTimeout, this); toxav_register_callstate_callback(toxav, onAvPeerTimeout, av_OnPeerTimeout, this); toxav_register_audio_callback(toxav, playCallAudio, this); toxav_register_video_callback(toxav, playCallVideo, this); QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString()); 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() << "Core: Error loading self avatar"; } 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 (savedata.isNull()) { saveConfiguration(); emit idSet(getSelfId().toString()); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer }