1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/widget/form/settings/generalform.cpp

284 lines
11 KiB
C++
Raw Normal View History

/*
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"
#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"
#include "src/core.h"
2014-10-06 04:49:44 +08:00
#include <QMessageBox>
#include <QStyleFactory>
#include <QTime>
#include <QFileDialog>
2014-11-05 04:05:30 +08:00
static QStringList locales = {"bg", "de", "en", "fr", "it", "mannol", "pirate", "pl", "ru", "fi", "uk"};
static QStringList langs = {"Български", "Deustch", "English", "Français", "Italiano", "mannol", "Pirate", "Polski", "Русский", "Suomi", "Українська"};
static QStringList timeFormats = {"hh:mm AP", "hh:mm", "hh:mm:ss AP", "hh:mm:ss"};
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-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++)
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());
bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray());
2014-10-20 19:50:12 +08:00
bodyUI->closeToTray->setChecked(Settings::getInstance().getCloseToTray());
bodyUI->minimizeToTray->setChecked(Settings::getInstance().getMinimizeToTray());
bodyUI->statusChanges->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled());
bodyUI->useEmoticons->setChecked(Settings::getInstance().getUseEmoticons());
bodyUI->autoacceptFiles->setChecked(Settings::getInstance().getAutoSaveEnabled());
bodyUI->autoSaveFilesDir->setEnabled(Settings::getInstance().getAutoSaveEnabled());
bodyUI->autoSaveFilesDir->setText(Settings::getInstance().getAutoSaveFilesDir());
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();
bodyUI->styleBrowser->addItem(tr("None"));
bodyUI->styleBrowser->addItems(QStyleFactory::keys());
2014-10-17 00:17:25 +08:00
if(QStyleFactory::keys().contains(Settings::getInstance().getStyle()))
bodyUI->styleBrowser->setCurrentText(Settings::getInstance().getStyle());
else
2014-10-30 00:25:47 +08:00
bodyUI->styleBrowser->setCurrentText(tr("None"));
bodyUI->emoticonSize->setValue(Settings::getInstance().getEmojiFontPointSize());
QStringList timestamps;
timestamps << QString("%1 - %2").arg(timeFormats[0],QTime::currentTime().toString(timeFormats[0]))
<< QString("%1 - %2").arg(timeFormats[1],QTime::currentTime().toString(timeFormats[1]))
<< QString("%1 - %2").arg(timeFormats[2],QTime::currentTime().toString(timeFormats[2]))
<< QString("%1 - %2").arg(timeFormats[3],QTime::currentTime().toString(timeFormats[3]));
bodyUI->timestamp->addItems(timestamps);
bodyUI->timestamp->setCurrentText(QString("%1 - %2").arg(Settings::getInstance().getTimestampFormat(),
QTime::currentTime().toString(Settings::getInstance().getTimestampFormat()))
); //idiot proof enough?
2014-10-17 01:49:50 +08:00
bodyUI->autoAwaySpinBox->setValue(Settings::getInstance().getAutoAwayTime());
bodyUI->cbEnableUDP->setChecked(!Settings::getInstance().getForceTCP());
2014-10-06 04:49:44 +08:00
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();
//general
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);
connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray);
2014-10-20 19:50:12 +08:00
connect(bodyUI->closeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray);
connect(bodyUI->minimizeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetMinimizeToTray);
2014-10-20 19:50:12 +08:00
connect(bodyUI->statusChanges, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange);
connect(bodyUI->autoAwaySpinBox, SIGNAL(editingFinished()), this, SLOT(onAutoAwayChanged()));
connect(bodyUI->autoacceptFiles, &QCheckBox::stateChanged, this, &GeneralForm::onAutoAcceptFileChange);
//theme
connect(bodyUI->useEmoticons, &QCheckBox::stateChanged, this, &GeneralForm::onUseEmoticonsChange);
2014-10-06 00:17:01 +08:00
connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int)));
connect(bodyUI->styleBrowser, SIGNAL(currentTextChanged(QString)), this, SLOT(onStyleSelected(QString)));
connect(bodyUI->emoticonSize, SIGNAL(editingFinished()), this, SLOT(onEmoticonSizeChanged()));
connect(bodyUI->timestamp, SIGNAL(currentIndexChanged(int)), this, SLOT(onTimestampSelected(int)));
//connection
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
connect(bodyUI->cbEnableUDP, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated);
connect(bodyUI->cbUseProxy, &QCheckBox::stateChanged, this, &GeneralForm::onUseProxyUpdated);
2014-10-06 04:49:44 +08:00
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->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked);
}
GeneralForm::~GeneralForm()
{
2014-10-06 00:17:01 +08:00
delete bodyUI;
}
void GeneralForm::onEnableIPv6Updated()
{
2014-10-06 00:17:01 +08:00
Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked());
}
void GeneralForm::onTranslationUpdated()
{
Settings::getInstance().setTranslation(locales[bodyUI->transComboBox->currentIndex()]);
Widget::getInstance()->setTranslation();
}
void GeneralForm::onMakeToxPortableUpdated()
{
2014-10-06 00:17:01 +08:00
Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
}
void GeneralForm::onSetAutostartInTray()
{
Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked());
}
2014-10-20 03:47:06 +08:00
void GeneralForm::onSetCloseToTray()
{
2014-10-20 19:50:12 +08:00
Settings::getInstance().setCloseToTray(bodyUI->closeToTray->isChecked());
}
void GeneralForm::onSetMinimizeToTray()
{
Settings::getInstance().setMinimizeToTray(bodyUI->minimizeToTray->isChecked());
2014-10-20 03:47:06 +08:00
}
void GeneralForm::onStyleSelected(QString style)
{
if(bodyUI->styleBrowser->currentIndex() == 0)
Settings::getInstance().setStyle("None");
else
Settings::getInstance().setStyle(style);
this->setStyle(QStyleFactory::create(style));
2014-10-17 01:24:16 +08:00
parent->setBodyHeadStyle(style);
}
void GeneralForm::onEmoticonSizeChanged()
{
Settings::getInstance().setEmojiFontPointSize(bodyUI->emoticonSize->value());
}
void GeneralForm::onTimestampSelected(int index)
{
Settings::getInstance().setTimestampFormat(
bodyUI->timestamp->currentText().split(" ").at(0));
}
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
}
void GeneralForm::onAutoAcceptFileChange()
{
if(bodyUI->autoacceptFiles->isChecked() == true)
{
Settings::getInstance().setAutoSaveEnabled(true);
bodyUI->autoSaveFilesDir->setEnabled(true);
connect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()), this, SLOT(onAutoSaveDirChange()));
}
else
{
Settings::getInstance().setAutoSaveEnabled(false);
bodyUI->autoSaveFilesDir->setEnabled(false);
disconnect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()),this, SLOT(onAutoSaveDirChange()));
}
}
void GeneralForm::onAutoSaveDirChange()
{
QString directory = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"));
Settings::getInstance().setAutoSaveFilesDir(directory);
bodyUI->autoSaveFilesDir->setText(directory);
}
void GeneralForm::onUseEmoticonsChange()
{
Settings::getInstance().setUseEmoticons(bodyUI->useEmoticons->isChecked());
}
void GeneralForm::onSetStatusChange()
{
2014-10-20 19:50:12 +08:00
Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked());
}
void GeneralForm::onSmileyBrowserIndexChanged(int index)
{
2014-10-06 00:17:01 +08:00
QString filename = bodyUI->smileyPackBrowser->itemData(index).toString();
Settings::getInstance().setSmileyPack(filename);
2014-10-08 23:10:57 +08:00
reloadSmiles();
}
2014-10-06 04:49:44 +08:00
void GeneralForm::onUDPUpdated()
{
Settings::getInstance().setForceTCP(!bodyUI->cbEnableUDP->isChecked());
2014-10-06 04:49:44 +08:00
}
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::onReconnectClicked()
{
if (Core::getInstance()->anyActiveCalls())
QMessageBox::warning(this, tr("Call active", "popup title"),
tr("You can't disconnect while a call is active!", "popup text"));
else
emit Widget::getInstance()->changeProfile(Settings::getInstance().getCurrentProfile());
}
2014-10-08 23:10:57 +08:00
void GeneralForm::reloadSmiles()
{
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));
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
}