2014-09-15 18:45:59 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
2014-10-06 00:17:01 +08:00
|
|
|
#include "ui_generalsettings.h"
|
2014-09-15 18:45:59 +08:00
|
|
|
#include "generalform.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/widget/form/settingswidget.h"
|
|
|
|
#include "src/widget/widget.h"
|
|
|
|
#include "src/misc/settings.h"
|
|
|
|
#include "src/misc/smileypack.h"
|
2014-10-06 04:49:44 +08:00
|
|
|
#include <QMessageBox>
|
2014-10-09 06:31:20 +08:00
|
|
|
#include <QStyleFactory>
|
2014-09-15 18:45:59 +08:00
|
|
|
|
2014-10-18 07:06:30 +08:00
|
|
|
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", "Українська"};
|
|
|
|
|
2014-10-17 00:17:25 +08:00
|
|
|
GeneralForm::GeneralForm(SettingsWidget *myParent) :
|
2014-10-17 23:24:23 +08:00
|
|
|
GenericForm(tr("General"), QPixmap(":/img/settings/general.png"))
|
2014-09-15 18:45:59 +08:00
|
|
|
{
|
2014-10-17 01:24:16 +08:00
|
|
|
parent = myParent;
|
|
|
|
|
2014-10-06 00:17:01 +08:00
|
|
|
bodyUI = new Ui::GeneralSettings;
|
|
|
|
bodyUI->setupUi(this);
|
2014-10-17 00:17:25 +08:00
|
|
|
|
2014-10-06 00:17:01 +08:00
|
|
|
bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6());
|
2014-10-18 09:15:26 +08:00
|
|
|
for (int i = 0; i < langs.size(); i++)
|
2014-10-18 07:06:30 +08:00
|
|
|
bodyUI->transComboBox->insertItem(i, langs[i]);
|
|
|
|
bodyUI->transComboBox->setCurrentIndex(locales.indexOf(Settings::getInstance().getTranslation()));
|
2014-10-06 00:17:01 +08:00
|
|
|
bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
|
2014-10-08 22:17:05 +08:00
|
|
|
bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray());
|
2014-10-20 03:47:06 +08:00
|
|
|
bodyUI->closeToTrayCheckbox->setChecked(Settings::getInstance().getCloseToTray());
|
2014-10-11 07:18:32 +08:00
|
|
|
bodyUI->statusChangesCheckbox->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled());
|
2014-09-30 17:44:27 +08:00
|
|
|
|
|
|
|
for (auto entry : SmileyPack::listSmileyPacks())
|
2014-10-06 00:17:01 +08:00
|
|
|
{
|
|
|
|
bodyUI->smileyPackBrowser->addItem(entry.first, entry.second);
|
|
|
|
}
|
|
|
|
bodyUI->smileyPackBrowser->setCurrentIndex(bodyUI->smileyPackBrowser->findData(Settings::getInstance().getSmileyPack()));
|
2014-10-08 23:10:57 +08:00
|
|
|
reloadSmiles();
|
2014-10-11 07:18:32 +08:00
|
|
|
|
2014-10-09 06:31:20 +08:00
|
|
|
bodyUI->styleBrowser->addItems(QStyleFactory::keys());
|
|
|
|
bodyUI->styleBrowser->addItem("None");
|
2014-10-17 00:17:25 +08:00
|
|
|
|
2014-10-09 06:31:20 +08:00
|
|
|
if(QStyleFactory::keys().contains(Settings::getInstance().getStyle()))
|
|
|
|
bodyUI->styleBrowser->setCurrentText(Settings::getInstance().getStyle());
|
|
|
|
else
|
|
|
|
bodyUI->styleBrowser->setCurrentText("None");
|
|
|
|
|
2014-10-17 01:49:50 +08:00
|
|
|
bodyUI->autoAwaySpinBox->setValue(Settings::getInstance().getAutoAwayTime());
|
|
|
|
|
2014-10-06 04:49:44 +08:00
|
|
|
bodyUI->cbUDPDisabled->setChecked(Settings::getInstance().getForceTCP());
|
|
|
|
bodyUI->proxyAddr->setText(Settings::getInstance().getProxyAddr());
|
|
|
|
int port = Settings::getInstance().getProxyPort();
|
|
|
|
if (port != -1)
|
2014-10-07 10:09:15 +08:00
|
|
|
bodyUI->proxyPort->setValue(port);
|
|
|
|
|
|
|
|
bodyUI->cbUseProxy->setChecked(Settings::getInstance().getUseProxy());
|
|
|
|
onUseProxyUpdated();
|
2014-10-08 22:17:05 +08:00
|
|
|
|
2014-10-06 04:49:44 +08:00
|
|
|
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
|
2014-10-18 07:06:30 +08:00
|
|
|
connect(bodyUI->transComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onTranslationUpdated()));
|
2014-10-06 04:49:44 +08:00
|
|
|
connect(bodyUI->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated);
|
2014-10-08 22:17:05 +08:00
|
|
|
connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray);
|
2014-10-20 03:47:06 +08:00
|
|
|
connect(bodyUI->closeToTrayCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray);
|
2014-10-11 07:18:32 +08:00
|
|
|
connect(bodyUI->statusChangesCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange);
|
2014-10-06 00:17:01 +08:00
|
|
|
connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int)));
|
2014-10-06 04:49:44 +08:00
|
|
|
// new syntax can't handle overloaded signals... (at least not in a pretty way)
|
|
|
|
connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated);
|
|
|
|
connect(bodyUI->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited);
|
2014-10-07 10:09:15 +08:00
|
|
|
connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int)));
|
|
|
|
connect(bodyUI->cbUseProxy, &QCheckBox::stateChanged, this, &GeneralForm::onUseProxyUpdated);
|
2014-10-09 06:31:20 +08:00
|
|
|
connect(bodyUI->styleBrowser, SIGNAL(currentTextChanged(QString)), this, SLOT(onStyleSelected(QString)));
|
2014-10-17 01:49:50 +08:00
|
|
|
connect(bodyUI->autoAwaySpinBox, SIGNAL(editingFinished()), this, SLOT(onAutoAwayChanged()));
|
2014-09-15 18:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GeneralForm::~GeneralForm()
|
|
|
|
{
|
2014-10-06 00:17:01 +08:00
|
|
|
delete bodyUI;
|
2014-09-15 18:45:59 +08:00
|
|
|
}
|
2014-09-30 17:44:27 +08:00
|
|
|
|
|
|
|
void GeneralForm::onEnableIPv6Updated()
|
|
|
|
{
|
2014-10-06 00:17:01 +08:00
|
|
|
Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked());
|
2014-09-30 17:44:27 +08:00
|
|
|
}
|
|
|
|
|
2014-10-18 07:06:30 +08:00
|
|
|
void GeneralForm::onTranslationUpdated()
|
2014-09-30 17:44:27 +08:00
|
|
|
{
|
2014-10-18 07:06:30 +08:00
|
|
|
Settings::getInstance().setTranslation(locales[bodyUI->transComboBox->currentIndex()]);
|
|
|
|
Widget::getInstance()->setTranslation();
|
2014-09-30 17:44:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralForm::onMakeToxPortableUpdated()
|
|
|
|
{
|
2014-10-06 00:17:01 +08:00
|
|
|
Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
|
2014-09-30 17:44:27 +08:00
|
|
|
}
|
|
|
|
|
2014-10-08 22:17:05 +08:00
|
|
|
void GeneralForm::onSetAutostartInTray()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked());
|
|
|
|
}
|
|
|
|
|
2014-10-20 03:47:06 +08:00
|
|
|
void GeneralForm::onSetCloseToTray()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setCloseToTray(bodyUI->closeToTrayCheckbox->isChecked());
|
|
|
|
}
|
|
|
|
|
2014-10-09 06:31:20 +08:00
|
|
|
void GeneralForm::onStyleSelected(QString style)
|
|
|
|
{
|
|
|
|
Settings::getInstance().setStyle(style);
|
|
|
|
this->setStyle(QStyleFactory::create(style));
|
2014-10-17 01:24:16 +08:00
|
|
|
parent->setBodyHeadStyle(style);
|
2014-10-09 06:31:20 +08:00
|
|
|
}
|
|
|
|
|
2014-10-17 01:49:50 +08:00
|
|
|
void GeneralForm::onAutoAwayChanged()
|
|
|
|
{
|
2014-10-17 02:48:45 +08:00
|
|
|
int minutes = bodyUI->autoAwaySpinBox->value();
|
|
|
|
Settings::getInstance().setAutoAwayTime(minutes);
|
|
|
|
Widget::getInstance()->setIdleTimer(minutes);
|
2014-10-17 01:49:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-11 07:18:32 +08:00
|
|
|
void GeneralForm::onSetStatusChange()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChangesCheckbox->isChecked());
|
|
|
|
}
|
|
|
|
|
2014-09-30 17:44:27 +08:00
|
|
|
void GeneralForm::onSmileyBrowserIndexChanged(int index)
|
|
|
|
{
|
2014-10-06 00:17:01 +08:00
|
|
|
QString filename = bodyUI->smileyPackBrowser->itemData(index).toString();
|
2014-09-30 17:44:27 +08:00
|
|
|
Settings::getInstance().setSmileyPack(filename);
|
2014-10-08 23:10:57 +08:00
|
|
|
reloadSmiles();
|
2014-09-30 17:44:27 +08:00
|
|
|
}
|
2014-10-06 04:49:44 +08:00
|
|
|
|
|
|
|
void GeneralForm::onUDPUpdated()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setForceTCP(bodyUI->cbUDPDisabled->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralForm::onProxyAddrEdited()
|
|
|
|
{
|
|
|
|
Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text());
|
|
|
|
}
|
|
|
|
|
2014-10-07 10:09:15 +08:00
|
|
|
void GeneralForm::onProxyPortEdited(int port)
|
2014-10-06 04:49:44 +08:00
|
|
|
{
|
2014-10-07 10:09:15 +08:00
|
|
|
if (port > 0)
|
2014-10-06 04:49:44 +08:00
|
|
|
{
|
2014-10-07 10:09:15 +08:00
|
|
|
Settings::getInstance().setProxyPort(port);
|
|
|
|
} else {
|
2014-10-06 04:49:44 +08:00
|
|
|
Settings::getInstance().setProxyPort(-1);
|
2014-10-07 10:09:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralForm::onUseProxyUpdated()
|
|
|
|
{
|
|
|
|
bool state = bodyUI->cbUseProxy->isChecked();
|
|
|
|
|
|
|
|
bodyUI->proxyAddr->setEnabled(state);
|
|
|
|
bodyUI->proxyPort->setEnabled(state);
|
|
|
|
Settings::getInstance().setUseProxy(state);
|
2014-10-06 04:49:44 +08:00
|
|
|
}
|
2014-10-08 23:10:57 +08:00
|
|
|
|
|
|
|
void GeneralForm::reloadSmiles()
|
|
|
|
{
|
2014-10-11 23:53:20 +08:00
|
|
|
QList<QStringList> emoticons = SmileyPack::getInstance().getEmoticons();
|
|
|
|
QStringList smiles;
|
2014-10-14 02:50:54 +08:00
|
|
|
smiles << ":)" << ";)" << ":p" << ":O" << ":["; //just in case...
|
|
|
|
|
|
|
|
for(int i = 0; i < emoticons.size(); i++)
|
|
|
|
smiles.push_front(emoticons.at(i).first());
|
|
|
|
|
2014-10-08 23:10:57 +08:00
|
|
|
int pixSize = 30;
|
|
|
|
bodyUI->smile1->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[0]).pixmap(pixSize, pixSize));
|
|
|
|
bodyUI->smile2->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[1]).pixmap(pixSize, pixSize));
|
|
|
|
bodyUI->smile3->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[2]).pixmap(pixSize, pixSize));
|
|
|
|
bodyUI->smile4->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[3]).pixmap(pixSize, pixSize));
|
|
|
|
bodyUI->smile5->setPixmap(SmileyPack::getInstance().getAsIcon(smiles[4]).pixmap(pixSize, pixSize));
|
2014-10-11 23:53:20 +08:00
|
|
|
|
|
|
|
bodyUI->smile1->setToolTip(smiles[0]);
|
|
|
|
bodyUI->smile2->setToolTip(smiles[1]);
|
|
|
|
bodyUI->smile3->setToolTip(smiles[2]);
|
|
|
|
bodyUI->smile4->setToolTip(smiles[3]);
|
|
|
|
bodyUI->smile5->setToolTip(smiles[4]);
|
2014-10-08 23:10:57 +08:00
|
|
|
}
|