1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'pr462'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-18 12:13:47 +02:00
commit b0b5e5872c
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
14 changed files with 113 additions and 74 deletions

View File

@ -259,10 +259,6 @@ void Core::start()
toxav_register_audio_recv_callback(toxav, playCallAudio, this); toxav_register_audio_recv_callback(toxav, playCallAudio, this);
toxav_register_video_recv_callback(toxav, playCallVideo, 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()); QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString());
if (!pic.isNull() && !pic.size().isEmpty()) if (!pic.isNull() && !pic.size().isEmpty())
{ {
@ -1116,13 +1112,17 @@ bool Core::loadConfiguration(QString path)
// set GUI with user and statusmsg // set GUI with user and statusmsg
QString name = getUsername(); QString name = getUsername();
if (name != "") if (!name.isEmpty())
emit usernameSet(name); emit usernameSet(name);
QString msg = getStatusMessage(); QString msg = getStatusMessage();
if (msg != "") if (!msg.isEmpty())
emit statusMessageSet(msg); emit statusMessageSet(msg);
QString id = getSelfId().toString();
if (!id.isEmpty())
emit idSet(id);
loadFriends(); loadFriends();
return true; return true;
} }

View File

@ -123,8 +123,6 @@ signals:
void friendAvatarChanged(int friendId, const QPixmap& pic); void friendAvatarChanged(int friendId, const QPixmap& pic);
void friendAvatarRemoved(int friendId); void friendAvatarRemoved(int friendId);
void friendAddressGenerated(const QString& friendAddress);
void friendRemoved(int friendId); void friendRemoved(int friendId);
void friendLastSeenChanged(int friendId, const QDateTime& dateTime); void friendLastSeenChanged(int friendId, const QDateTime& dateTime);
@ -137,6 +135,7 @@ signals:
void usernameSet(const QString& username); void usernameSet(const QString& username);
void statusMessageSet(const QString& message); void statusMessageSet(const QString& message);
void statusSet(Status status); void statusSet(Status status);
void idSet(const QString& id);
void selfAvatarChanged(const QPixmap& pic); void selfAvatarChanged(const QPixmap& pic);
void messageSentResult(int friendId, const QString& message, int messageId); void messageSentResult(int friendId, const QString& message, int messageId);

View File

@ -84,11 +84,11 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
if (lastUpdateTime.secsTo(now) < 1) //update every 1s if (lastUpdateTime.secsTo(now) < 1) //update every 1s
return; return;
int timediff = startTime.secsTo(now); int timediff = effStartTime.secsTo(now);
if (timediff <= 0) if (timediff <= 0)
return; return;
long rawspeed = BytesSent / timediff; long rawspeed = (BytesSent - previousBytesSent) / timediff;
speed = getHumanReadableSize(rawspeed)+"/s"; speed = getHumanReadableSize(rawspeed)+"/s";
size = getHumanReadableSize(Filesize); size = getHumanReadableSize(Filesize);
@ -146,7 +146,7 @@ void FileTransferInstance::onFileTransferAccepted(ToxFile File)
remotePaused = false; remotePaused = false;
state = tsProcessing; state = tsProcessing;
startTime = QDateTime::currentDateTime(); effStartTime = QDateTime::currentDateTime();
emit stateUpdated(); emit stateUpdated();
} }
@ -226,7 +226,7 @@ void FileTransferInstance::acceptRecvRequest()
Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path); Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path);
state = tsProcessing; state = tsProcessing;
startTime = QDateTime::currentDateTime(); effStartTime = QDateTime::currentDateTime();
emit stateUpdated(); emit stateUpdated();
} }
@ -243,6 +243,11 @@ void FileTransferInstance::pauseResumeRecv()
// if (state == tsProcessing) // if (state == tsProcessing)
// state = tsPaused; // state = tsPaused;
// else state = tsProcessing; // else state = tsProcessing;
if (state == tsPaused)
{
effStartTime = QDateTime::currentDateTime();
previousBytesSent = lastBytesSent;
}
emit stateUpdated(); emit stateUpdated();
} }
@ -259,6 +264,11 @@ void FileTransferInstance::pauseResumeSend()
// if (state == tsProcessing) // if (state == tsProcessing)
// state = tsPaused; // state = tsPaused;
// else state = tsProcessing; // else state = tsProcessing;
if (state == tsPaused)
{
effStartTime = QDateTime::currentDateTime();
previousBytesSent = lastBytesSent;
}
emit stateUpdated(); emit stateUpdated();
} }

View File

@ -74,8 +74,8 @@ private:
QImage pic; QImage pic;
QString filename, size, speed, eta; QString filename, size, speed, eta;
QString filenameElided; QString filenameElided;
QDateTime startTime, lastUpdateTime; QDateTime effStartTime, lastUpdateTime;
long long lastBytesSent, totalBytes; long long lastBytesSent, totalBytes, previousBytesSent = 0; // last var used for eta on resumes
int fileNum; int fileNum;
int friendId; int friendId;
int contentPrefWidth; int contentPrefWidth;

View File

@ -18,7 +18,6 @@
#include "misc/settings.h" #include "misc/settings.h"
#include <QApplication> #include <QApplication>
#include <QFontDatabase> #include <QFontDatabase>
#include <QTranslator>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QDebug> #include <QDebug>
@ -32,18 +31,6 @@ int main(int argc, char *argv[])
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()); QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
a.addLibraryPath("platforms"); 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 // Install Unicode 6.1 supporting font
QFontDatabase::addApplicationFont("://DejaVuSans.ttf"); QFontDatabase::addApplicationFont("://DejaVuSans.ttf");

View File

@ -108,7 +108,7 @@ void Settings::load()
s.beginGroup("General"); s.beginGroup("General");
enableIPv6 = s.value("enableIPv6", true).toBool(); enableIPv6 = s.value("enableIPv6", true).toBool();
useTranslations = s.value("useTranslations", true).toBool(); translation = s.value("translation", "").toString();
makeToxPortable = s.value("makeToxPortable", false).toBool(); makeToxPortable = s.value("makeToxPortable", false).toBool();
autostartInTray = s.value("autostartInTray", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool();
forceTCP = s.value("forceTCP", false).toBool(); forceTCP = s.value("forceTCP", false).toBool();
@ -216,7 +216,7 @@ void Settings::save(QString path)
s.beginGroup("General"); s.beginGroup("General");
s.setValue("enableIPv6", enableIPv6); s.setValue("enableIPv6", enableIPv6);
s.setValue("useTranslations",useTranslations); s.setValue("translation",translation);
s.setValue("makeToxPortable",makeToxPortable); s.setValue("makeToxPortable",makeToxPortable);
s.setValue("autostartInTray",autostartInTray); s.setValue("autostartInTray",autostartInTray);
s.setValue("useProxy", useProxy); s.setValue("useProxy", useProxy);
@ -389,14 +389,14 @@ void Settings::setStatusChangeNotificationEnabled(bool newValue)
statusChangeNotificationEnabled = 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 bool Settings::getForceTCP() const

View File

@ -58,8 +58,8 @@ public:
QString getCurrentProfile() const; QString getCurrentProfile() const;
void setCurrentProfile(QString profile); void setCurrentProfile(QString profile);
bool getUseTranslations() const; QString getTranslation() const;
void setUseTranslations(bool newValue); void setTranslation(QString newValue);
bool getForceTCP() const; bool getForceTCP() const;
void setForceTCP(bool newValue); void setForceTCP(bool newValue);
@ -179,7 +179,7 @@ private:
bool dontShowDhtDialog; bool dontShowDhtDialog;
bool enableIPv6; bool enableIPv6;
bool useTranslations; QString translation;
static bool makeToxPortable; static bool makeToxPortable;
bool autostartInTray; bool autostartInTray;

View File

@ -23,6 +23,9 @@
#include <QMessageBox> #include <QMessageBox>
#include <QStyleFactory> #include <QStyleFactory>
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) : GeneralForm::GeneralForm(SettingsWidget *myParent) :
GenericForm(tr("General"), QPixmap(":/img/settings/general.png")) GenericForm(tr("General"), QPixmap(":/img/settings/general.png"))
{ {
@ -32,7 +35,9 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
bodyUI->setupUi(this); bodyUI->setupUi(this);
bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6()); 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->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray()); bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray());
bodyUI->statusChangesCheckbox->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); bodyUI->statusChangesCheckbox->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled());
@ -64,7 +69,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
onUseProxyUpdated(); onUseProxyUpdated();
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); 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->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated);
connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray); connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray);
connect(bodyUI->statusChangesCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange); connect(bodyUI->statusChangesCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange);
@ -88,9 +93,10 @@ void GeneralForm::onEnableIPv6Updated()
Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked()); 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() void GeneralForm::onMakeToxPortableUpdated()

View File

@ -32,7 +32,7 @@ public:
private slots: private slots:
void onEnableIPv6Updated(); void onEnableIPv6Updated();
void onUseTranslationUpdated(); void onTranslationUpdated();
void onMakeToxPortableUpdated(); void onMakeToxPortableUpdated();
void onSetAutostartInTray(); void onSetAutostartInTray();
void onSmileyBrowserIndexChanged(int index); void onSmileyBrowserIndexChanged(int index);

View File

@ -30,11 +30,31 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QCheckBox" name="cbUseTranslations"> <layout class="QHBoxLayout" name="transLayout">
<property name="text"> <item>
<string extracomment="Text on a checkbox to enable translations">Use translations</string> <widget class="QLabel" name="transLabel">
</property> <property name="toolTip">
</widget> <string>The translation may not load until qTox restarts.</string>
</property>
<property name="text">
<string>Translation:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="transComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The translation may not load until qTox restarts.</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="cbMakeToxPortable"> <widget class="QCheckBox" name="cbMakeToxPortable">

View File

@ -46,6 +46,7 @@ IdentityForm::IdentityForm() :
connect(bodyUI->toxIdLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked())); connect(bodyUI->toxIdLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
connect(toxId, 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->userName, SIGNAL(editingFinished()), this, SLOT(onUserNameEdited()));
connect(bodyUI->statusMessage, SIGNAL(editingFinished()), this, SLOT(onStatusMessageEdited())); connect(bodyUI->statusMessage, SIGNAL(editingFinished()), this, SLOT(onStatusMessageEdited()));
connect(bodyUI->loadButton, &QPushButton::clicked, this, &IdentityForm::onLoadClicked); connect(bodyUI->loadButton, &QPushButton::clicked, this, &IdentityForm::onLoadClicked);
@ -96,14 +97,10 @@ void IdentityForm::present()
bodyUI->statusMessage->setText(Core::getInstance()->getStatusMessage()); bodyUI->statusMessage->setText(Core::getInstance()->getStatusMessage());
} }
void IdentityForm::setUserName(const QString &name) void IdentityForm::setToxId(const QString& id)
{ {
bodyUI->userName->setText(name); toxId->setText(id);
} toxId->setCursorPosition(0);
void IdentityForm::setStatusMessage(const QString &msg)
{
bodyUI->statusMessage->setText(msg);
} }
void IdentityForm::onLoadClicked() void IdentityForm::onLoadClicked()

View File

@ -47,9 +47,6 @@ public:
IdentityForm(); IdentityForm();
~IdentityForm(); ~IdentityForm();
void setUserName(const QString &name);
void setStatusMessage(const QString &msg);
virtual void present(); virtual void present();
signals: signals:
@ -57,6 +54,7 @@ signals:
void statusMessageChanged(QString); void statusMessageChanged(QString);
private slots: private slots:
void setToxId(const QString& id);
void copyIdClicked(); void copyIdClicked();
void onUserNameEdited(); void onUserNameEdited();
void onStatusMessageEdited(); void onStatusMessageEdited();

View File

@ -43,8 +43,10 @@
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
#include <QTimer> #include <QTimer>
#include <tox/tox.h>
#include <QStyleFactory> #include <QStyleFactory>
#include <QTranslator>
#include <tox/tox.h>
Widget *Widget::instance{nullptr}; Widget *Widget::instance{nullptr};
@ -53,7 +55,8 @@ Widget::Widget(QWidget *parent)
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
activeChatroomWidget{nullptr} activeChatroomWidget{nullptr}
{ {
translator = new QTranslator;
setTranslation();
} }
void Widget::init() void Widget::init()
@ -312,7 +315,7 @@ QString Widget::getUsername()
void Widget::onAvatarClicked() void Widget::onAvatarClicked()
{ {
QString filename = QFileDialog::getOpenFileName(this, tr("Choose a profile picture"), QDir::homePath()); QString filename = QFileDialog::getOpenFileName(this, tr("Choose a profile picture"), QDir::homePath());
if (filename == "") if (filename.isEmpty())
return; return;
QFile file(filename); QFile file(filename);
file.open(QIODevice::ReadOnly); file.open(QIODevice::ReadOnly);
@ -546,22 +549,24 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
f->friendStatus = status; f->friendStatus = status;
f->widget->updateStatusLight(); f->widget->updateStatusLight();
QString fStatus = ""; //won't print the message if there were no messages before
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
if(f->chatForm->getNumberOfMessages() != 0 if(f->chatForm->getNumberOfMessages() != 0
&& Settings::getInstance().getStatusChangeNotificationEnabled() == true) && 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) 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) if (result == -1)
g->chatForm->addSystemInfoMessage("Message failed to send", "red"); 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);
}

View File

@ -41,6 +41,7 @@ class Camera;
class FriendListWidget; class FriendListWidget;
class MaskablePixmapWidget; class MaskablePixmapWidget;
class QTimer; class QTimer;
class QTranslator;
class Widget : public QMainWindow class Widget : public QMainWindow
{ {
@ -59,7 +60,8 @@ public:
bool getIsWindowMinimized(); bool getIsWindowMinimized();
static QList<QString> searchProfiles(); static QList<QString> searchProfiles();
void clearContactsList(); void clearContactsList();
void setIdleTimer(int minutes); void setIdleTimer(int minutes);
void setTranslation();
~Widget(); ~Widget();
virtual void closeEvent(QCloseEvent *event); virtual void closeEvent(QCloseEvent *event);
@ -138,6 +140,7 @@ private:
bool notify(QObject *receiver, QEvent *event); bool notify(QObject *receiver, QEvent *event);
bool autoAwayActive = false; bool autoAwayActive = false;
QTimer* idleTimer; QTimer* idleTimer;
QTranslator* translator;
}; };
#endif // WIDGET_H #endif // WIDGET_H