diff --git a/src/audio.cpp b/src/audio.cpp index 47b338218..e2cfb6d1a 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -72,6 +72,7 @@ Audio::~Audio() audioThread->wait(); if (audioThread->isRunning()) audioThread->terminate(); + delete audioThread; delete audioInLock; delete audioOutLock; @@ -123,6 +124,7 @@ void Audio::openInput(const QString& inDevDescr) alInDev = nullptr; if (tmp) alcCaptureCloseDevice(tmp); + int stereoFlag = av_DefaultSettings.audio_channels==1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; if (inDevDescr.isEmpty()) alInDev = alcCaptureOpenDevice(nullptr,av_DefaultSettings.audio_sample_rate, stereoFlag, @@ -163,6 +165,7 @@ void Audio::openOutput(const QString& outDevDescr) alOutDev = alcOpenDevice(nullptr); else alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str()); + if (!alOutDev) { qWarning() << "Audio: Cannot open output audio device"; @@ -171,8 +174,10 @@ void Audio::openOutput(const QString& outDevDescr) { if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE) alcDestroyContext(alContext); + if (tmp) alcCloseDevice(tmp); + alContext=alcCreateContext(alOutDev,nullptr); if (!alcMakeContextCurrent(alContext)) { @@ -180,7 +185,9 @@ void Audio::openOutput(const QString& outDevDescr) alcCloseDevice(alOutDev); } else + { alGenSources(1, &alMainSource); + } qDebug() << "Audio: Opening audio output "<progressLabel->setText(tr("Waiting to send...", "file transfer widget")); } else + { ui->progressLabel->setText(tr("Accept to receive this file", "file transfer widget")); + } setFixedHeight(78); } @@ -187,6 +189,7 @@ void FileTransferWidget::paintEvent(QPaintEvent *) // draw background if(drawButtonAreaNeeded()) painter.setClipRect(QRect(0,0,width()-buttonFieldWidth,height())); + painter.setBrush(QBrush(backgroundColor)); painter.drawRoundRect(geometry(), r * ratio, r); diff --git a/src/core/core.cpp b/src/core/core.cpp index 2c93b7069..4e915dcdf 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -457,7 +457,8 @@ void Core::onStatusMessageChanged(Tox*/* tox*/, uint32_t friendId, const uint8_t void Core::onUserStatusChanged(Tox*/* tox*/, uint32_t friendId, TOX_USER_STATUS userstatus, void* core) { Status status; - switch (userstatus) { + switch (userstatus) + { case TOX_USER_STATUS_NONE: status = Status::Online; break; @@ -611,6 +612,7 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag QString inviteStr = tr("/me offers friendship."); if (message.length()) inviteStr = tr("/me offers friendship, \"%1\"").arg(message); + HistoryKeeper::getInstance()->addChatEntry(userId, inviteStr, getSelfId().publicKey, QDateTime::currentDateTime(), true); emit friendAdded(friendId, userId); } @@ -826,7 +828,8 @@ void Core::setStatusMessage(const QString& message) { CString cMessage(message); - if (tox_self_set_status_message(tox, cMessage.data(), cMessage.size(), nullptr) == false) { + if (tox_self_set_status_message(tox, cMessage.data(), cMessage.size(), nullptr) == false) + { emit failedToSetStatusMessage(message); } else @@ -900,7 +903,8 @@ QByteArray Core::loadToxSave(QString path) if (fileSize > 0) { data = configurationFile.readAll(); - if (tox_is_data_encrypted((uint8_t*)data.data())) { + if (tox_is_data_encrypted((uint8_t*)data.data())) + { if (!loadEncryptedSave(data)) { configurationFile.close(); diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 9e44457b9..7900e713d 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -34,8 +34,10 @@ uint8_t* Core::videobuf; bool Core::anyActiveCalls() { for (auto& call : calls) + { if (call.active) return true; + } return false; } @@ -93,6 +95,7 @@ void Core::onAvMediaChange(void* toxav, int32_t callId, void* core) int friendId; if (toxav_get_peer_csettings((ToxAv*)toxav, callId, 0, &settings) < 0) goto fail; + friendId = toxav_get_peer_id((ToxAv*)toxav, callId, 0); if (friendId < 0) goto fail; @@ -220,6 +223,7 @@ void Core::cleanupCall(int32_t callId) calls[callId].sendVideoTimer->stop(); if (calls[callId].videoEnabled) Camera::getInstance()->unsubscribe(); + Audio::unsuscribeInput(); toxav_kill_transmission(Core::getInstance()->toxav, callId); } @@ -286,9 +290,7 @@ void Core::sendCallAudio(int32_t callId, ToxAv* toxav) } if ((r = toxav_send_audio(toxav, callId, dest, r)) < 0) - { qDebug() << "Core: toxav_send_audio error"; - } } calls[callId].sendAudioTimer->start(); } @@ -336,9 +338,7 @@ void Core::sendCallVideo(int32_t callId) void Core::micMuteToggle(int32_t callId) { if (calls[callId].active) - { calls[callId].muteMic = !calls[callId].muteMic; - } } void Core::volMuteToggle(int32_t callId) diff --git a/src/core/coreencryption.cpp b/src/core/coreencryption.cpp index 2df15fe57..864aca6de 100644 --- a/src/core/coreencryption.cpp +++ b/src/core/coreencryption.cpp @@ -190,7 +190,9 @@ bool Core::loadEncryptedSave(QByteArray& data) dialogtxt = tr("The profile password failed. Please try another?", "used only when pw set before load() doesn't work"); } else + { dialogtxt = a; + } uint8_t salt[TOX_PASS_SALT_LENGTH]; tox_get_salt(reinterpret_cast(data.data()), salt); @@ -205,7 +207,9 @@ bool Core::loadEncryptedSave(QByteArray& data) return false; } else + { setPassword(pw, ptMain, salt); + } QByteArray newData(fileSize-TOX_PASS_ENCRYPTION_EXTRA_LENGTH, 0); error = !tox_pass_key_decrypt((uint8_t*)data.data(), data.size(), pwsaltedkeys[ptMain], @@ -248,7 +252,9 @@ void Core::checkEncryptedHistory() dialogtxt = tr("The chat history password failed. Please try another?", "used only when pw set before load() doesn't work"); } else + { dialogtxt = a; + } dialogtxt += "\n" + c; @@ -341,7 +347,9 @@ void Core::saveConfiguration(const QString& path) } } else + { tox_get_savedata(tox, data); + } configurationFile.write(reinterpret_cast(data), fileSize); configurationFile.commit(); diff --git a/src/friend.cpp b/src/friend.cpp index 56cf83960..82f66cb30 100644 --- a/src/friend.cpp +++ b/src/friend.cpp @@ -87,6 +87,7 @@ QString Friend::getDisplayedName() const { if (userAlias.size() == 0) return userName; + return userAlias; } diff --git a/src/group.cpp b/src/group.cpp index ea975ff90..78932545c 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -102,6 +102,7 @@ void Group::regeneratePeerList() ToxID id = Core::getInstance()->getGroupPeerToxID(groupId, i); if (id.isMine()) selfPeerNum = i; + QString toxid = id.publicKey; toxids[toxid] = peers[i]; Friend *f = FriendList::findFriend(id); @@ -177,9 +178,7 @@ QString Group::resolveToxID(const ToxID &id) const auto it = toxids.find(key); if (it != toxids.end()) - { return *it; - } return QString(); } diff --git a/src/historykeeper.cpp b/src/historykeeper.cpp index ac499cb06..2a78cfa6e 100644 --- a/src/historykeeper.cpp +++ b/src/historykeeper.cpp @@ -56,7 +56,9 @@ HistoryKeeper *HistoryKeeper::getInstance() historyInstance = new HistoryKeeper(dbIntf); return historyInstance; - } else { + } + else + { path = getHistoryPath(); } } @@ -111,9 +113,7 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) : QSqlQuery ret = db->exec("SELECT seq FROM sqlite_sequence WHERE name=\"sent_status\";"); int idCur = 0; if (ret.first()) - { idCur = ret.value(0).toInt(); - } if (idCur != idMax) { @@ -145,6 +145,7 @@ qint64 HistoryKeeper::addChatEntry(const QString& chat, const QString& message, db->exec("BEGIN TRANSACTION;"); for (auto &it : cmds) db->exec(it); + db->exec("COMMIT TRANSACTION;"); messageID++; @@ -167,7 +168,9 @@ QList HistoryKeeper::getChatHistory(HistoryKeeper::C dbAnswer = db->exec(QString("SELECT history.id, timestamp, user_id, message, status FROM history LEFT JOIN sent_status ON history.id = sent_status.id ") + QString("INNER JOIN aliases ON history.sender = aliases.id AND timestamp BETWEEN %1 AND %2 AND chat_id = %3;") .arg(time64_from).arg(time64_to).arg(chat_id)); - } else { + } + else + { // no groupchats yet } @@ -372,7 +375,8 @@ void HistoryKeeper::setSyncType(Db::syncType sType) { QString syncCmd; - switch (sType) { + switch (sType) + { case Db::syncType::stFull: syncCmd = "FULL"; break; @@ -413,5 +417,6 @@ QList HistoryKeeper::exportMessagesDeleteFile(int en qDebug() << "HistoryKeeper: count" << msgs.size() << "messages exported"; if (!removeHistory(encrypted)) qWarning() << "HistoryKeeper: couldn't delete old log file!"; + return msgs; } diff --git a/src/misc/db/encrypteddb.cpp b/src/misc/db/encrypteddb.cpp index 885921824..1228dc21d 100644 --- a/src/misc/db/encrypteddb.cpp +++ b/src/misc/db/encrypteddb.cpp @@ -41,7 +41,9 @@ EncryptedDb::EncryptedDb(const QString &fname, QList initList) : encrFile.close(); } else + { chunkPosition = 0; + } encrFile.setFileName(fileName); @@ -90,7 +92,9 @@ bool EncryptedDb::pullFileContent(const QString &fname, QByteArray &buf) if (buf.size() > 0) { fileContent += buf; - } else { + } + else + { qWarning() << "EncryptedDb::pullFileContent: Encrypted history log is corrupted: can't decrypt, will be deleted"; buf = QByteArray(); return false; @@ -108,9 +112,8 @@ bool EncryptedDb::pullFileContent(const QString &fname, QByteArray &buf) PlainDb::exec("BEGIN TRANSACTION;"); for (auto line : sqlCmds) - { QSqlQuery r = PlainDb::exec(line); - } + PlainDb::exec("COMMIT TRANSACTION;"); dbFile.close(); @@ -144,9 +147,8 @@ void EncryptedDb::appendToEncrypted(const QString &sql) QByteArray encr = Core::getInstance()->encryptData(buffer, Core::ptHistory); if (encr.size() > 0) - { encrFile.write(encr); - } + encrFile.flush(); } @@ -161,10 +163,10 @@ bool EncryptedDb::check(const QString &fname) QByteArray encrChunk = file.read(encryptedChunkSize); QByteArray buf = Core::getInstance()->decryptData(encrChunk, Core::ptHistory); if (buf.size() == 0) - { state = false; - } - } else { + } + else + { file.close(); file.open(QIODevice::WriteOnly); } diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index caec9c6e4..c02a406c0 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -54,6 +54,7 @@ Settings& Settings::getInstance() { if (!settings) settings = new Settings(); + return *settings; } @@ -92,7 +93,9 @@ QString Settings::detectProfile() { profile = askProfiles(); if (profile.isEmpty()) + { return ""; + } else { switchProfile(profile); @@ -101,7 +104,9 @@ QString Settings::detectProfile() } } else + { return path; + } } QList Settings::searchProfiles() @@ -112,6 +117,7 @@ QList Settings::searchProfiles() dir.setNameFilters(QStringList("*.tox")); for (QFileInfo file : dir.entryInfoList()) out += file.completeBaseName(); + return out; } @@ -154,7 +160,9 @@ void Settings::load() ps.endGroup(); } else + { makeToxPortable = false; + } QDir dir(getSettingsDirPath()); QString filePath = dir.filePath(FILENAME); @@ -178,7 +186,8 @@ void Settings::load() useCustomDhtList = true; qDebug() << "Using custom bootstrap nodes list"; int serverListSize = s.beginReadArray("dhtServerList"); - for (int i = 0; i < serverListSize; i ++) { + for (int i = 0; i < serverListSize; i ++) + { s.setArrayIndex(i); DhtServer server; server.name = s.value("name").toString(); @@ -190,7 +199,9 @@ void Settings::load() s.endArray(); } else + { useCustomDhtList=false; + } s.endGroup(); s.beginGroup("General"); @@ -228,9 +239,9 @@ void Settings::load() s.beginGroup("Widgets"); QList objectNames = s.childKeys(); - for (const QString& name : objectNames) { + for (const QString& name : objectNames) widgetSettings[name] = s.value(name).toByteArray(); - } + s.endGroup(); s.beginGroup("GUI"); @@ -283,7 +294,8 @@ void Settings::load() QSettings rcs(":/conf/settings.ini", QSettings::IniFormat); rcs.beginGroup("DHT Server"); int serverListSize = rcs.beginReadArray("dhtServerList"); - for (int i = 0; i < serverListSize; i ++) { + for (int i = 0; i < serverListSize; i ++) + { rcs.setArrayIndex(i); DhtServer server; server.name = rcs.value("name").toString(); @@ -357,7 +369,8 @@ void Settings::saveGlobal(QString path) s.beginGroup("DHT Server"); s.setValue("useCustomList", useCustomDhtList); s.beginWriteArray("dhtServerList", dhtServerList.size()); - for (int i = 0; i < dhtServerList.size(); i ++) { + for (int i = 0; i < dhtServerList.size(); i ++) + { s.setArrayIndex(i); s.setValue("name", dhtServerList[i].name); s.setValue("userId", dhtServerList[i].userId); @@ -398,9 +411,9 @@ void Settings::saveGlobal(QString path) s.beginGroup("Widgets"); const QList widgetNames = widgetSettings.keys(); - for (const QString& name : widgetNames) { + for (const QString& name : widgetNames) s.setValue(name, widgetSettings.value(name)); - } + s.endGroup(); s.beginGroup("GUI"); @@ -505,12 +518,15 @@ QPixmap Settings::getSavedAvatar(const QString &ownerId) QString filePath = dir.filePath("avatar_"+ownerId.left(64)); if (!QFileInfo(filePath).exists()) // try without truncation, for old self avatars filePath = dir.filePath("avatar_"+ownerId); + pic.load(filePath); saveAvatar(pic, ownerId); QFile::remove(filePath); } else + { pic.load(filePath); + } return pic; } @@ -530,6 +546,7 @@ void Settings::saveAvatarHash(const QByteArray& hash, const QString& ownerId) QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash")); if (!file.open(QIODevice::WriteOnly)) return; + file.write(hash); file.close(); } @@ -541,6 +558,7 @@ QByteArray Settings::getAvatarHash(const QString& ownerId) QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash")); if (!file.open(QIODevice::ReadOnly)) return QByteArray(); + QByteArray out = file.readAll(); file.close(); return out; @@ -840,6 +858,7 @@ void Settings::setAutoAwayTime(int newValue) { if (newValue < 0) newValue = 10; + autoAwayTime = newValue; } @@ -849,9 +868,7 @@ QString Settings::getAutoAcceptDir(const ToxID& id) const auto it = friendLst.find(key); if (it != friendLst.end()) - { return it->autoAcceptDir; - } return QString(); } @@ -1110,9 +1127,7 @@ QString Settings::getFriendAdress(const QString &publicKey) const QString key = ToxID::fromString(publicKey).publicKey; auto it = friendLst.find(key); if (it != friendLst.end()) - { return it->addr; - } return QString(); } @@ -1124,7 +1139,9 @@ void Settings::updateFriendAdress(const QString &newAddr) if (it != friendLst.end()) { it->addr = newAddr; - } else { + } + else + { friendProp fp; fp.addr = newAddr; fp.alias = ""; @@ -1138,9 +1155,7 @@ QString Settings::getFriendAlias(const ToxID &id) const QString key = id.publicKey; auto it = friendLst.find(key); if (it != friendLst.end()) - { return it->alias; - } return QString(); } @@ -1152,7 +1167,9 @@ void Settings::setFriendAlias(const ToxID &id, const QString &alias) if (it != friendLst.end()) { it->alias = alias; - } else { + } + else + { friendProp fp; fp.addr = key; fp.alias = alias; diff --git a/src/nexus.cpp b/src/nexus.cpp index 260c9b14b..2473dcbb5 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -40,6 +40,7 @@ void Nexus::start() { if (started) return; + qDebug() << "Nexus: Starting up"; // Setup the environment @@ -139,6 +140,7 @@ Nexus& Nexus::getInstance() { if (!nexus) nexus = new Nexus; + return *nexus; } @@ -168,6 +170,7 @@ QString Nexus::getSupportedImageFilter() QString res; for (auto type : QImageReader::supportedImageFormats()) res += QString("*.%1 ").arg(QString(type)); + return tr("Images (%1)", "filetype filter").arg(res.left(res.size()-1)); } diff --git a/src/offlinemsgengine.cpp b/src/offlinemsgengine.cpp index 1bd8a05ae..fce43c1bc 100644 --- a/src/offlinemsgengine.cpp +++ b/src/offlinemsgengine.cpp @@ -91,6 +91,7 @@ void OfflineMsgEngine::deliverOfflineMsgs() rec = Core::getInstance()->sendAction(f->getFriendID(), messageText); else rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText); + registerReceipt(rec, iter.key(), iter.value().msg); } } diff --git a/src/toxme.cpp b/src/toxme.cpp index 4857ccef7..af95a2925 100644 --- a/src/toxme.cpp +++ b/src/toxme.cpp @@ -69,16 +69,19 @@ ToxID Toxme::lookup(QString address) const int index = response.indexOf(pattern); if (index == -1) return id; + response = response.mid(index+pattern.size()); const int idStart = response.indexOf('"'); if (idStart == -1) return id; + response = response.mid(idStart+1); const int idEnd = response.indexOf('"'); if (idEnd == -1) return id; + response.truncate(idEnd); id = ToxID::fromString(response); @@ -93,17 +96,20 @@ int Toxme::extractError(QString json) const int index = json.indexOf(pattern); if (index == -1) return INT_MIN; + json = json.mid(index+pattern.size()); const int end = json.indexOf('}'); if (end == -1) return INT_MIN; + json.truncate(end); bool ok; int r = json.toInt(&ok); if (!ok) return INT_MIN; + return r; } diff --git a/src/widget/form/addfriendform.cpp b/src/widget/form/addfriendform.cpp index 4c38082ce..a6f229ef0 100644 --- a/src/widget/form/addfriendform.cpp +++ b/src/widget/form/addfriendform.cpp @@ -87,16 +87,22 @@ void AddFriendForm::onSendTriggered() { QString id = toxId.text().trimmed(); - if (id.isEmpty()) { + if (id.isEmpty()) + { GUI::showWarning(tr("Couldn't add friend"), tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to")); - } else if (ToxID::isToxId(id)) { + } + else if (ToxID::isToxId(id)) + { if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper()) GUI::showWarning(tr("Couldn't add friend"), tr("You can't add yourself as a friend!","When trying to add your own Tox ID as friend")); else emit friendRequested(id, getMessage()); + this->toxId.clear(); this->message.clear(); - } else { + } + else + { if (Settings::getInstance().getProxyType() != ProxyType::ptNone) { QMessageBox::StandardButton btn = QMessageBox::warning(main, "qTox", tr("qTox needs to use the Tox DNS, but can't do it through a proxy.\n\ @@ -123,7 +129,8 @@ void AddFriendForm::setIdFromClipboard() { QClipboard* clipboard = QApplication::clipboard(); QString id = clipboard->text().trimmed(); - if (Core::getInstance()->isReady() && !id.isEmpty() && ToxID::isToxId(id)) { + if (Core::getInstance()->isReady() && !id.isEmpty() && ToxID::isToxId(id)) + { if (!ToxID::fromString(id).isMine()) toxId.setText(id); } diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index c0abf3919..5cc0b1375 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -157,6 +157,7 @@ void ChatForm::onTextEditChanged() { if (isTyping) Core::getInstance()->sendTyping(f->getFriendID(), false); + isTyping = false; return; } @@ -178,6 +179,7 @@ void ChatForm::onAttachClicked() QStringList paths = QFileDialog::getOpenFileNames(0,tr("Send a file")); if (paths.isEmpty()) return; + for (QString path : paths) { QFile file(path); @@ -269,6 +271,7 @@ void ChatForm::onAvInvite(uint32_t FriendId, int CallId, bool video) callConfirm = new CallConfirmWidget(videoButton); if (isVisible()) callConfirm->show(); + connect(callConfirm, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered); connect(callConfirm, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered); @@ -283,6 +286,7 @@ void ChatForm::onAvInvite(uint32_t FriendId, int CallId, bool video) callConfirm = new CallConfirmWidget(callButton); if (isVisible()) callConfirm->show(); + connect(callConfirm, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered); connect(callConfirm, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered); @@ -534,13 +538,9 @@ void ChatForm::onAvMediaChange(uint32_t FriendId, int CallId, bool video) qDebug() << "onAvMediaChange"; if (video) - { netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName()); - } else - { netcam->hide(); - } } void ChatForm::onAnswerCallTriggered() @@ -564,10 +564,8 @@ void ChatForm::onHangupCallTriggered() //Fixes an OS X bug with ending a call while in full screen if(netcam->isFullScreen()) - { netcam->showNormal(); - } - + audioInputFlag = false; audioOutputFlag = false; emit hangupCall(callId); @@ -588,9 +586,8 @@ void ChatForm::onRejectCallTriggered() audioInputFlag = false; audioOutputFlag = false; emit rejectCall(callId); - + enableCallButtons(); - } void ChatForm::onCallTriggered() @@ -631,7 +628,7 @@ void ChatForm::onAvCallFailed(uint32_t FriendId) void ChatForm::onCancelCallTriggered() { qDebug() << "onCancelCallTriggered"; - + enableCallButtons(); netcam->hide(); @@ -806,6 +803,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered) { if (earliestMessage < since) return; + if (earliestMessage < now) { now = earliestMessage; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 09aec7099..d6ca5a4f5 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -366,7 +366,9 @@ QString GenericChatForm::resolveToxID(const ToxID &id) if (f) { return f->getDisplayedName(); - } else { + } + else + { for (auto it : GroupList::getAllGroups()) { QString res = it->resolveToxID(id); diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index a12bc1cbd..3e0b93804 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -110,10 +110,14 @@ void GroupChatForm::onSendTriggered() emit sendAction(group->getGroupId(), msg); } else + { emit sendMessage(group->getGroupId(), msg); + } } else + { addSelfMessage(msg, msg.startsWith("/me "), QDateTime::currentDateTime(), true); + } } void GroupChatForm::onUserListChanged() @@ -150,6 +154,7 @@ void GroupChatForm::onUserListChanged() QLabel* label = orderizer[names[i]]; if (i != nNames - 1) label->setText(label->text() + ", "); + namesListLayout->addWidget(label); } diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 280ac83e6..9e7cfaea3 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -41,6 +41,7 @@ void ProfileForm::refreshProfiles() bodyUI->profiles->clear(); for (QString profile : Settings::getInstance().searchProfiles()) bodyUI->profiles->addItem(profile); + QString current = Settings::getInstance().getCurrentProfile(); if (current != "") bodyUI->profiles->setCurrentText(current); @@ -194,6 +195,7 @@ void ProfileForm::onAvatarClicked() Nexus::getSupportedImageFilter()); if (filename.isEmpty()) return; + QFile file(filename); file.open(QIODevice::ReadOnly); if (!file.isOpen()) @@ -254,6 +256,7 @@ void ProfileForm::onRenameClicked() Settings::getInstance().setCurrentProfile(name); if (resetAutorun) Settings::getInstance().setAutorun(true); // fixes -p flag in autostart command line + break; } } while (true); diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index c1b26fcd8..e97589c44 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -52,6 +52,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6()); for (int i = 0; i < langs.size(); i++) bodyUI->transComboBox->insertItem(i, langs[i]); + bodyUI->transComboBox->setCurrentIndex(locales.indexOf(Settings::getInstance().getTranslation())); bodyUI->cbAutorun->setChecked(Settings::getInstance().getAutorun()); #if defined(__APPLE__) && defined(__MACH__) @@ -69,7 +70,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->minimizeToTray->setEnabled(showSystemTray); bodyUI->lightTrayIcon->setChecked(Settings::getInstance().getLightTrayIcon()); bodyUI->lightTrayIcon->setEnabled(showSystemTray); - + bodyUI->statusChanges->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); bodyUI->useEmoticons->setChecked(Settings::getInstance().getUseEmoticons()); bodyUI->autoacceptFiles->setChecked(Settings::getInstance().getAutoSaveEnabled()); @@ -83,9 +84,8 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->cbGroupchatPosition->setChecked(Settings::getInstance().getGroupchatPosition()); for (auto entry : SmileyPack::listSmileyPacks()) - { bodyUI->smileyPackBrowser->addItem(entry.first, entry.second); - } + bodyUI->smileyPackBrowser->setCurrentIndex(bodyUI->smileyPackBrowser->findData(Settings::getInstance().getSmileyPack())); reloadSmiles(); bodyUI->smileyPackBrowser->setEnabled(bodyUI->useEmoticons->isChecked()); @@ -99,6 +99,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : for (QString color : Style::themeColorNames) bodyUI->themeColorCBox->addItem(color); + bodyUI->themeColorCBox->setCurrentIndex(Settings::getInstance().getThemeColor()); bodyUI->emoticonSize->setValue(Settings::getInstance().getEmojiFontPointSize()); @@ -174,7 +175,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : connect(bodyUI->cbFauxOfflineMessaging, &QCheckBox::stateChanged, this, &GeneralForm::onFauxOfflineMessaging); connect(bodyUI->cbCompactLayout, &QCheckBox::stateChanged, this, &GeneralForm::onCompactLayout); connect(bodyUI->cbGroupchatPosition, &QCheckBox::stateChanged, this, &GeneralForm::onGroupchatPositionChanged); - + // prevent stealing mouse whell scroll // scrolling event won't be transmitted to comboboxes or qspinboxes when scrolling // you can scroll through general settings without accidentially chaning theme/skin/icons etc. @@ -331,11 +332,9 @@ void GeneralForm::onProxyAddrEdited() void GeneralForm::onProxyPortEdited(int port) { if (port > 0) - { Settings::getInstance().setProxyPort(port); - } else { + else Settings::getInstance().setProxyPort(-1); - } } void GeneralForm::onUseProxyUpdated() diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index 831f84b75..f2d728bab 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -115,8 +115,10 @@ bool PrivacyForm::setChatLogsPassword() else { if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("There is currently an unused encrypted chat history, but the password you just entered doesn't match.\n\nIf you don't care about the old history, you may delete it and use the password you just entered.\nOtherwise, hit Cancel to try again.", "This happens when enabling encryption after previously \"Disabling History\""), tr("Delete"), tr("Cancel"))) + { if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("Are you absolutely sure you want to lose the unused encrypted chat history?", "secondary popup"), tr("Delete"), tr("Cancel"))) haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate + } } } while (haveEncHist); diff --git a/src/widget/form/tabcompleter.cpp b/src/widget/form/tabcompleter.cpp index c0f59f482..19001d9ff 100644 --- a/src/widget/form/tabcompleter.cpp +++ b/src/widget/form/tabcompleter.cpp @@ -54,8 +54,10 @@ void TabCompleter::buildCompletionList() QRegExp regex(QString("^[-_\\[\\]{}|`^.\\\\]*").append(QRegExp::escape(tabAbbrev)), Qt::CaseInsensitive); for (auto name : group->getPeerList()) + { if (regex.indexIn(name) > -1) completionMap[name.toLower()] = name; + } nextCompletion = completionMap.begin(); lastCompletionLength = tabAbbrev.length(); @@ -64,12 +66,14 @@ void TabCompleter::buildCompletionList() void TabCompleter::complete() { - if (!enabled) { + if (!enabled) + { buildCompletionList(); enabled = true; } - if (nextCompletion != completionMap.end()) { + if (nextCompletion != completionMap.end()) + { // clear previous completion auto cur = msgEdit->textCursor(); cur.setPosition(cur.selectionEnd()); @@ -85,13 +89,16 @@ void TabCompleter::complete() nextCompletion++; // we're completing the first word of the line - if (msgEdit->textCursor().position() == lastCompletionLength) { + if (msgEdit->textCursor().position() == lastCompletionLength) + { msgEdit->insertPlainText(nickSuffix); lastCompletionLength += nickSuffix.length(); } } - else { // we're at the end of the list -> start over again - if (!completionMap.isEmpty()) { + else + { // we're at the end of the list -> start over again + if (!completionMap.isEmpty()) + { nextCompletion = completionMap.begin(); complete(); } diff --git a/src/widget/groupwidget.cpp b/src/widget/groupwidget.cpp index ffd73b634..a6d6118e8 100644 --- a/src/widget/groupwidget.cpp +++ b/src/widget/groupwidget.cpp @@ -60,7 +60,9 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event) if (selectedItem) { if (selectedItem == quitGroup) + { emit removeGroup(groupId); + } else if (selectedItem == setTitle) { bool ok; @@ -77,7 +79,7 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event) * element - title, the rest of the widget stays in the same CSS as it * was on mouse over. Repainting whole widget fixes style problem.” */ - this->repaint(); + this->repaint(); } } } diff --git a/src/widget/toxsave.cpp b/src/widget/toxsave.cpp index f10b98596..d2d7e2445 100644 --- a/src/widget/toxsave.cpp +++ b/src/widget/toxsave.cpp @@ -42,9 +42,7 @@ bool handleToxSave(const QString& path) } while (!core->isReady()) - { qApp->processEvents(); - } QFileInfo info(path); if (!info.exists()) diff --git a/src/widget/toxuri.cpp b/src/widget/toxuri.cpp index dffc1f459..b87f3c390 100644 --- a/src/widget/toxuri.cpp +++ b/src/widget/toxuri.cpp @@ -51,9 +51,7 @@ bool handleToxURI(const QString &toxURI) } while (!core->isReady()) - { qApp->processEvents(); - } QString toxaddr; if (toxURI.startsWith("tox://")) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 6c8f55ada..ce1061f79 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -72,6 +72,7 @@ bool toxActivateEventHandler(const QByteArray&) { if (!Widget::getInstance()->isActiveWindow()) Widget::getInstance()->forceShow(); + return true; } @@ -132,17 +133,17 @@ void Widget::init() ui->mainHead->layout()->setSpacing(0); ui->tooliconsZone->setStyleSheet(Style::resolve("QPushButton{background-color:@themeDark;border:none;}QPushButton:hover{background-color:@themeMediumDark;border:none;}")); - + if (QStyleFactory::keys().contains(Settings::getInstance().getStyle()) && Settings::getInstance().getStyle() != "None") { ui->mainHead->setStyle(QStyleFactory::create(Settings::getInstance().getStyle())); ui->mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle())); } - - ui->mainHead->setStyleSheet(Style::getStylesheet(":ui/settings/mainHead.css")); + + ui->mainHead->setStyleSheet(Style::getStylesheet(":ui/settings/mainHead.css")); ui->mainContent->setStyleSheet(Style::getStylesheet(":ui/settings/mainContent.css")); - + ui->statusHead->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css")); contactListWidget = new FriendListWidget(0, Settings::getInstance().getGroupchatPosition()); @@ -171,7 +172,7 @@ void Widget::init() Style::setThemeColor(Settings::getInstance().getThemeColor()); reloadTheme(); updateIcons(); - + filesForm = new FilesForm(); addFriendForm = new AddFriendForm; profileForm = new ProfileForm(); @@ -265,7 +266,9 @@ void Widget::updateIcons() QString status; if (eventIcon) + { status = "event"; + } else { status = ui->statusButton->property("status").toString(); @@ -291,6 +294,7 @@ Widget::~Widget() AutoUpdater::abortUpdates(); if (icon) icon->hide(); + hideMainForms(); delete profileForm; delete settingsWidget; @@ -313,6 +317,7 @@ Widget* Widget::getInstance() if (!instance) instance = new Widget(); + return instance; } @@ -337,9 +342,7 @@ void Widget::changeEvent(QEvent *event) if (event->type() == QEvent::WindowStateChange) { if (isMinimized() && Settings::getInstance().getMinimizeToTray()) - { this->hide(); - } } } @@ -448,7 +451,7 @@ void Widget::confirmExecutableOpen(const QFileInfo file) { return; } - + // The user wants to run this file, so make it executable and run it QFile(file.filePath()).setPermissions(file.permissions() | QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther); QProcess::startDetached(file.filePath()); @@ -531,13 +534,12 @@ void Widget::hideMainForms() QLayoutItem* item; while ((item = ui->mainHead->layout()->takeAt(0)) != 0) item->widget()->hide(); + while ((item = ui->mainContent->layout()->takeAt(0)) != 0) item->widget()->hide(); if (activeChatroomWidget != nullptr) - { activeChatroomWidget->setAsInactiveChatroom(); - } } void Widget::onUsernameChanged(const QString& newUsername, const QString& oldUsername) @@ -649,24 +651,21 @@ void Widget::onFriendStatusChanged(int friendId, Status status) if (isActualChange) { if (f->getStatus() == Status::Offline) - { contactListWidget->moveWidget(f->getFriendWidget(), Status::Online); - } else if (status == Status::Offline) - { contactListWidget->moveWidget(f->getFriendWidget(), Status::Offline); - } } f->setStatus(status); f->getFriendWidget()->updateStatusLight(); - + //won't print the message if there were no messages before if (!f->getChatForm()->isEmpty() && Settings::getInstance().getStatusChangeNotificationEnabled()) { QString fStatus = ""; - switch(f->getStatus()){ + switch(f->getStatus()) + { case Status::Away: fStatus = tr("away", "contact status"); break; case Status::Busy: @@ -716,9 +715,8 @@ void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget) hideMainForms(); widget->setChatForm(*ui); if (activeChatroomWidget != nullptr) - { activeChatroomWidget->setAsInactiveChatroom(); - } + activeChatroomWidget = widget; widget->setAsActiveChatroom(); setWindowTitle(widget->getName()); @@ -757,6 +755,7 @@ void Widget::newMessageAlert(GenericChatroomWidget* chat) bool inactiveWindow = isMinimized() || !isActiveWindow(); if (!inactiveWindow && activeChatroomWidget != nullptr && chat == activeChatroomWidget) return; + if (ui->statusButton->property("status").toString() == "busy") return; @@ -792,6 +791,7 @@ void Widget::playRingtone() { if (ui->statusButton->property("status").toString() == "busy") return; + QApplication::alert(this); static QFile sndFile1(":audio/ToxicIncomingCall.pcm"); // for whatever reason this plays slower/downshifted from what any other program plays the file as... but whatever @@ -932,7 +932,9 @@ void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Cha // g->getChatForm()->addSystemInfoMessage(tr("%1 has left the chat").arg(name), "white", QDateTime::currentDateTime()); } else if (change == TOX_CHAT_CHANGE_PEER_NAME) // core overwrites old name before telling us it changed... + { g->updatePeer(peernumber,Nexus::getCore()->getGroupPeerName(groupnumber, peernumber)); + } } void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const QString& title) @@ -1064,7 +1066,9 @@ void Widget::onUserAwayCheck() } } else if (autoAwayActive) + { autoAwayActive = false; + } #endif } @@ -1107,10 +1111,14 @@ void Widget::onTryCreateTrayIcon() setHidden(Settings::getInstance().getAutostartInTray()); } else + { show(); + } } else if (!isVisible()) + { show(); + } } else { @@ -1163,6 +1171,7 @@ void Widget::onFriendTypingChanged(int friendId, bool isTyping) Friend* f = FriendList::findFriend(friendId); if (!f) return; + f->getChatForm()->setFriendTyping(isTyping); } @@ -1196,9 +1205,7 @@ void Widget::processOfflineMsgs() { QList frnds = FriendList::getAllFriends(); for (Friend *f : frnds) - { f->getChatForm()->getOfflineMsgEngine()->deliverOfflineMsgs(); - } OfflineMsgEngine::globalMutex.unlock(); } @@ -1208,9 +1215,7 @@ void Widget::clearAllReceipts() { QList frnds = FriendList::getAllFriends(); for (Friend *f : frnds) - { f->getChatForm()->getOfflineMsgEngine()->removeAllReciepts(); - } } void Widget::reloadTheme()