diff --git a/src/core.cpp b/src/core.cpp index 325028b03..58fd47aff 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -259,10 +259,6 @@ void Core::start() toxav_register_audio_recv_callback(toxav, playCallAudio, this); toxav_register_video_recv_callback(toxav, playCallVideo, this); - uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE]; - tox_get_address(tox, friendAddress); - emit friendAddressGenerated(CFriendAddress::toString(friendAddress)); - QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString()); if (!pic.isNull() && !pic.size().isEmpty()) { @@ -1116,13 +1112,17 @@ bool Core::loadConfiguration(QString path) // set GUI with user and statusmsg QString name = getUsername(); - if (name != "") + if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); - if (msg != "") + if (!msg.isEmpty()) emit statusMessageSet(msg); + QString id = getSelfId().toString(); + if (!id.isEmpty()) + emit idSet(id); + loadFriends(); return true; } diff --git a/src/core.h b/src/core.h index dfeeaddde..0542f0e97 100644 --- a/src/core.h +++ b/src/core.h @@ -123,8 +123,6 @@ signals: void friendAvatarChanged(int friendId, const QPixmap& pic); void friendAvatarRemoved(int friendId); - void friendAddressGenerated(const QString& friendAddress); - void friendRemoved(int friendId); void friendLastSeenChanged(int friendId, const QDateTime& dateTime); @@ -137,6 +135,7 @@ signals: void usernameSet(const QString& username); void statusMessageSet(const QString& message); void statusSet(Status status); + void idSet(const QString& id); void selfAvatarChanged(const QPixmap& pic); void messageSentResult(int friendId, const QString& message, int messageId); diff --git a/src/filetransferinstance.cpp b/src/filetransferinstance.cpp index 8880b044c..daedf5ecf 100644 --- a/src/filetransferinstance.cpp +++ b/src/filetransferinstance.cpp @@ -84,11 +84,11 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t if (lastUpdateTime.secsTo(now) < 1) //update every 1s return; - int timediff = startTime.secsTo(now); + int timediff = effStartTime.secsTo(now); if (timediff <= 0) return; - long rawspeed = BytesSent / timediff; + long rawspeed = (BytesSent - previousBytesSent) / timediff; speed = getHumanReadableSize(rawspeed)+"/s"; size = getHumanReadableSize(Filesize); @@ -146,7 +146,7 @@ void FileTransferInstance::onFileTransferAccepted(ToxFile File) remotePaused = false; state = tsProcessing; - startTime = QDateTime::currentDateTime(); + effStartTime = QDateTime::currentDateTime(); emit stateUpdated(); } @@ -226,7 +226,7 @@ void FileTransferInstance::acceptRecvRequest() Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path); state = tsProcessing; - startTime = QDateTime::currentDateTime(); + effStartTime = QDateTime::currentDateTime(); emit stateUpdated(); } @@ -243,6 +243,11 @@ void FileTransferInstance::pauseResumeRecv() // if (state == tsProcessing) // state = tsPaused; // else state = tsProcessing; + if (state == tsPaused) + { + effStartTime = QDateTime::currentDateTime(); + previousBytesSent = lastBytesSent; + } emit stateUpdated(); } @@ -259,6 +264,11 @@ void FileTransferInstance::pauseResumeSend() // if (state == tsProcessing) // state = tsPaused; // else state = tsProcessing; + if (state == tsPaused) + { + effStartTime = QDateTime::currentDateTime(); + previousBytesSent = lastBytesSent; + } emit stateUpdated(); } diff --git a/src/filetransferinstance.h b/src/filetransferinstance.h index a4f6524ee..386e8bd01 100644 --- a/src/filetransferinstance.h +++ b/src/filetransferinstance.h @@ -74,8 +74,8 @@ private: QImage pic; QString filename, size, speed, eta; QString filenameElided; - QDateTime startTime, lastUpdateTime; - long long lastBytesSent, totalBytes; + QDateTime effStartTime, lastUpdateTime; + long long lastBytesSent, totalBytes, previousBytesSent = 0; // last var used for eta on resumes int fileNum; int friendId; int contentPrefWidth; diff --git a/src/main.cpp b/src/main.cpp index 1d447dbf9..e02db84a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,6 @@ #include "misc/settings.h" #include #include -#include #include #include @@ -32,18 +31,6 @@ int main(int argc, char *argv[]) QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()); a.addLibraryPath("platforms"); - // Load translations - QTranslator translator; - if (Settings::getInstance().getUseTranslations()) - { - QString locale = QLocale::system().name().section('_', 0, 0); - if (locale=="en" || translator.load(locale,":translations/")) - qDebug() << "Loaded translation "+locale; - else - qDebug() << "Error loading translation "+locale; - a.installTranslator(&translator); - } - // Install Unicode 6.1 supporting font QFontDatabase::addApplicationFont("://DejaVuSans.ttf"); diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index 037b4cbb6..773ec5457 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -108,7 +108,7 @@ void Settings::load() s.beginGroup("General"); enableIPv6 = s.value("enableIPv6", true).toBool(); - useTranslations = s.value("useTranslations", true).toBool(); + translation = s.value("translation", "").toString(); makeToxPortable = s.value("makeToxPortable", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); @@ -216,7 +216,7 @@ void Settings::save(QString path) s.beginGroup("General"); s.setValue("enableIPv6", enableIPv6); - s.setValue("useTranslations",useTranslations); + s.setValue("translation",translation); s.setValue("makeToxPortable",makeToxPortable); s.setValue("autostartInTray",autostartInTray); s.setValue("useProxy", useProxy); @@ -389,14 +389,14 @@ void Settings::setStatusChangeNotificationEnabled(bool newValue) statusChangeNotificationEnabled = newValue; } -bool Settings::getUseTranslations() const +QString Settings::getTranslation() const { - return useTranslations; + return translation; } -void Settings::setUseTranslations(bool newValue) +void Settings::setTranslation(QString newValue) { - useTranslations = newValue; + translation = newValue; } bool Settings::getForceTCP() const diff --git a/src/misc/settings.h b/src/misc/settings.h index 79675fbd8..ee85b4177 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -58,8 +58,8 @@ public: QString getCurrentProfile() const; void setCurrentProfile(QString profile); - bool getUseTranslations() const; - void setUseTranslations(bool newValue); + QString getTranslation() const; + void setTranslation(QString newValue); bool getForceTCP() const; void setForceTCP(bool newValue); @@ -179,7 +179,7 @@ private: bool dontShowDhtDialog; bool enableIPv6; - bool useTranslations; + QString translation; static bool makeToxPortable; bool autostartInTray; diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index e5f2ed23b..78867b60e 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -23,6 +23,9 @@ #include #include +static QStringList locales = {"de", "en", "fr", "it", "mannol", "pirate", "pl", "ru", "fi", "uk"}; +static QStringList langs = {"Deustch", "English", "Français", "Italiano", "mannol", "Pirate", "Polski", "Русский", "Suomi", "Українська"}; + GeneralForm::GeneralForm(SettingsWidget *myParent) : GenericForm(tr("General"), QPixmap(":/img/settings/general.png")) { @@ -32,7 +35,9 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->setupUi(this); bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6()); - bodyUI->cbUseTranslations->setChecked(Settings::getInstance().getUseTranslations()); + for (int i = 0; i < langs.size(); i++) + bodyUI->transComboBox->insertItem(i, langs[i]); + bodyUI->transComboBox->setCurrentIndex(locales.indexOf(Settings::getInstance().getTranslation())); bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable()); bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray()); bodyUI->statusChangesCheckbox->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); @@ -64,7 +69,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : onUseProxyUpdated(); connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); - connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated); + connect(bodyUI->transComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onTranslationUpdated())); connect(bodyUI->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated); connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray); connect(bodyUI->statusChangesCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange); @@ -88,9 +93,10 @@ void GeneralForm::onEnableIPv6Updated() Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked()); } -void GeneralForm::onUseTranslationUpdated() +void GeneralForm::onTranslationUpdated() { - Settings::getInstance().setUseTranslations(bodyUI->cbUseTranslations->isChecked()); + Settings::getInstance().setTranslation(locales[bodyUI->transComboBox->currentIndex()]); + Widget::getInstance()->setTranslation(); } void GeneralForm::onMakeToxPortableUpdated() diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index 31a73eb32..bae1eb8d0 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -32,7 +32,7 @@ public: private slots: void onEnableIPv6Updated(); - void onUseTranslationUpdated(); + void onTranslationUpdated(); void onMakeToxPortableUpdated(); void onSetAutostartInTray(); void onSmileyBrowserIndexChanged(int index); diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui index 7201a2bc6..924bc057b 100644 --- a/src/widget/form/settings/generalsettings.ui +++ b/src/widget/form/settings/generalsettings.ui @@ -30,11 +30,31 @@ - - - Use translations - - + + + + + The translation may not load until qTox restarts. + + + Translation: + + + + + + + + 0 + 0 + + + + The translation may not load until qTox restarts. + + + + diff --git a/src/widget/form/settings/identityform.cpp b/src/widget/form/settings/identityform.cpp index 80407ff1e..691aa4d86 100644 --- a/src/widget/form/settings/identityform.cpp +++ b/src/widget/form/settings/identityform.cpp @@ -46,6 +46,7 @@ IdentityForm::IdentityForm() : connect(bodyUI->toxIdLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked())); connect(toxId, SIGNAL(clicked()), this, SLOT(copyIdClicked())); + connect(Core::getInstance(), &Core::idSet, this, &IdentityForm::setToxId); connect(bodyUI->userName, SIGNAL(editingFinished()), this, SLOT(onUserNameEdited())); connect(bodyUI->statusMessage, SIGNAL(editingFinished()), this, SLOT(onStatusMessageEdited())); connect(bodyUI->loadButton, &QPushButton::clicked, this, &IdentityForm::onLoadClicked); @@ -96,14 +97,10 @@ void IdentityForm::present() bodyUI->statusMessage->setText(Core::getInstance()->getStatusMessage()); } -void IdentityForm::setUserName(const QString &name) +void IdentityForm::setToxId(const QString& id) { - bodyUI->userName->setText(name); -} - -void IdentityForm::setStatusMessage(const QString &msg) -{ - bodyUI->statusMessage->setText(msg); + toxId->setText(id); + toxId->setCursorPosition(0); } void IdentityForm::onLoadClicked() diff --git a/src/widget/form/settings/identityform.h b/src/widget/form/settings/identityform.h index fa3759903..f21f653f1 100644 --- a/src/widget/form/settings/identityform.h +++ b/src/widget/form/settings/identityform.h @@ -47,9 +47,6 @@ public: IdentityForm(); ~IdentityForm(); - void setUserName(const QString &name); - void setStatusMessage(const QString &msg); - virtual void present(); signals: @@ -57,6 +54,7 @@ signals: void statusMessageChanged(QString); private slots: + void setToxId(const QString& id); void copyIdClicked(); void onUserNameEdited(); void onStatusMessageEdited(); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 1f73036b4..742433f88 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -43,8 +43,10 @@ #include #include #include -#include #include +#include +#include + Widget *Widget::instance{nullptr}; @@ -53,7 +55,8 @@ Widget::Widget(QWidget *parent) ui(new Ui::MainWindow), activeChatroomWidget{nullptr} { - + translator = new QTranslator; + setTranslation(); } void Widget::init() @@ -312,7 +315,7 @@ QString Widget::getUsername() void Widget::onAvatarClicked() { QString filename = QFileDialog::getOpenFileName(this, tr("Choose a profile picture"), QDir::homePath()); - if (filename == "") + if (filename.isEmpty()) return; QFile file(filename); file.open(QIODevice::ReadOnly); @@ -546,22 +549,24 @@ void Widget::onFriendStatusChanged(int friendId, Status status) f->friendStatus = status; f->widget->updateStatusLight(); - QString fStatus = ""; - switch(f->friendStatus){ - case Status::Away: - fStatus = tr("away", "contact status"); break; - case Status::Busy: - fStatus = tr("busy", "contact status"); break; - case Status::Offline: - fStatus = tr("offline", "contact status"); break; - default: - fStatus = tr("online", "contact status"); break; - } - - //won't print the message if there were no messages before + //won't print the message if there were no messages before if(f->chatForm->getNumberOfMessages() != 0 && Settings::getInstance().getStatusChangeNotificationEnabled() == true) - f->chatForm->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getName()).arg(fStatus), "white"); + { + QString fStatus = ""; + switch(f->friendStatus){ + case Status::Away: + fStatus = tr("away", "contact status"); break; + case Status::Busy: + fStatus = tr("busy", "contact status"); break; + case Status::Offline: + fStatus = tr("offline", "contact status"); break; + default: + fStatus = tr("online", "contact status"); break; + } + f->chatForm->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getName()).arg(fStatus), + "white", QDateTime::currentDateTime()); + } } void Widget::onFriendStatusMessageChanged(int friendId, const QString& message) @@ -902,3 +907,17 @@ void Widget::onGroupSendResult(int groupId, const QString& message, int result) if (result == -1) g->chatForm->addSystemInfoMessage("Message failed to send", "red"); } + +void Widget::setTranslation() +{ + // Load translations + QCoreApplication::removeTranslator(translator); + QString locale; + if ((locale = Settings::getInstance().getTranslation()) == "") + locale = QLocale::system().name().section('_', 0, 0); + if (translator->load(locale,":translations/")) + qDebug() << "Loaded translation" << locale; + else + qDebug() << "Error loading translation" << locale; + QCoreApplication::installTranslator(translator); +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 2166d6613..6e1f1a8d4 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -41,6 +41,7 @@ class Camera; class FriendListWidget; class MaskablePixmapWidget; class QTimer; +class QTranslator; class Widget : public QMainWindow { @@ -59,7 +60,8 @@ public: bool getIsWindowMinimized(); static QList searchProfiles(); void clearContactsList(); - void setIdleTimer(int minutes); + void setIdleTimer(int minutes); + void setTranslation(); ~Widget(); virtual void closeEvent(QCloseEvent *event); @@ -138,6 +140,7 @@ private: bool notify(QObject *receiver, QEvent *event); bool autoAwayActive = false; QTimer* idleTimer; + QTranslator* translator; }; #endif // WIDGET_H