mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
add choose translations (restart required, dynamic changing is lots of work)
This commit is contained in:
parent
26eb08aa00
commit
4e7a183360
13
src/main.cpp
13
src/main.cpp
|
@ -18,7 +18,6 @@
|
|||
#include "misc/settings.h"
|
||||
#include <QApplication>
|
||||
#include <QFontDatabase>
|
||||
#include <QTranslator>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include <QMessageBox>
|
||||
#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) :
|
||||
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()
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
|
||||
private slots:
|
||||
void onEnableIPv6Updated();
|
||||
void onUseTranslationUpdated();
|
||||
void onTranslationUpdated();
|
||||
void onMakeToxPortableUpdated();
|
||||
void onSetAutostartInTray();
|
||||
void onSmileyBrowserIndexChanged(int index);
|
||||
|
|
|
@ -30,12 +30,32 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cbUseTranslations">
|
||||
<layout class="QHBoxLayout" name="transLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="transLabel">
|
||||
<property name="toolTip">
|
||||
<string>The translation may not load until qTox restarts.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string extracomment="Text on a checkbox to enable translations">Use translations</string>
|
||||
<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>
|
||||
<widget class="QCheckBox" name="cbMakeToxPortable">
|
||||
<property name="toolTip">
|
||||
|
|
|
@ -43,8 +43,10 @@
|
|||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
#include <QTimer>
|
||||
#include <tox/tox.h>
|
||||
#include <QStyleFactory>
|
||||
#include <QTranslator>
|
||||
#include <tox/tox.h>
|
||||
|
||||
|
||||
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,6 +549,10 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
|||
f->friendStatus = status;
|
||||
f->widget->updateStatusLight();
|
||||
|
||||
//won't print the message if there were no messages before
|
||||
if(f->chatForm->getNumberOfMessages() != 0
|
||||
&& Settings::getInstance().getStatusChangeNotificationEnabled() == true)
|
||||
{
|
||||
QString fStatus = "";
|
||||
switch(f->friendStatus){
|
||||
case Status::Away:
|
||||
|
@ -557,11 +564,9 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
|||
default:
|
||||
fStatus = tr("online", "contact status"); break;
|
||||
}
|
||||
|
||||
//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");
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ class Camera;
|
|||
class FriendListWidget;
|
||||
class MaskablePixmapWidget;
|
||||
class QTimer;
|
||||
class QTranslator;
|
||||
|
||||
class Widget : public QMainWindow
|
||||
{
|
||||
|
@ -60,6 +61,7 @@ public:
|
|||
static QList<QString> searchProfiles();
|
||||
void clearContactsList();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user