diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index a76059c7a..2b526dd90 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -114,6 +114,8 @@ void Settings::load() proxyPort = s.value("proxyPort", 0).toInt(); currentProfile = s.value("currentProfile", "").toString(); autoAwayTime = s.value("autoAwayTime", 10).toInt(); + autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); + autoSaveDir = s.value("autoSaveDir", QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)).toString(); s.endGroup(); s.beginGroup("Widgets"); @@ -135,6 +137,7 @@ void Settings::load() minimizeOnClose = s.value("minimizeOnClose", false).toBool(); minimizeToTray = s.value("minimizeToTray", false).toBool(); useNativeStyle = s.value("nativeStyle", false).toBool(); + useEmoticons = s.value("useEmoticons", true).toBool(); style = s.value("style", "None").toString(); statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool(); s.endGroup(); @@ -238,6 +241,8 @@ void Settings::save(QString path) s.setValue("proxyPort", proxyPort); s.setValue("currentProfile", currentProfile); s.setValue("autoAwayTime", autoAwayTime); + s.setValue("autoSaveEnabled", autoSaveEnabled); + s.setValue("autoSaveDir", autoSaveDir); s.endGroup(); s.beginGroup("Widgets"); @@ -259,7 +264,8 @@ void Settings::save(QString path) s.setValue("minimizeOnClose", minimizeOnClose); s.setValue("minimizeToTray", minimizeToTray); s.setValue("nativeStyle", useNativeStyle); - s.setValue("style",style); + s.setValue("useEmoticons", useEmoticons); + s.setValue("style", style); s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled); s.endGroup(); @@ -403,6 +409,26 @@ void Settings::setStyle(const QString& newStyle) style = newStyle; } +void Settings::setUseEmoticons(bool newValue) +{ + useEmoticons = newValue; +} + +bool Settings::getUseEmoticons() const +{ + return useEmoticons; +} + +void Settings::setAutoSaveEnabled(bool newValue) +{ + autoSaveEnabled = newValue; +} + +bool Settings::getAutoSaveEnabled() const +{ + return autoSaveEnabled; +} + void Settings::setAutostartInTray(bool newValue) { autostartInTray = newValue; @@ -449,6 +475,17 @@ void Settings::setTranslation(QString newValue) translation = newValue; } + +QString Settings::getAutoSaveFilesDir() const +{ + return autoSaveDir; +} + +void Settings::setAutoSaveFilesDir(QString newValue) +{ + autoSaveDir = newValue; +} + bool Settings::getForceTCP() const { return forceTCP; diff --git a/src/misc/settings.h b/src/misc/settings.h index 9ff363df4..60204c9ad 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -60,12 +60,21 @@ public: QString getStyle() const; void setStyle(const QString& newValue); + + bool getUseEmoticons() const; + void setUseEmoticons(bool newValue); QString getCurrentProfile() const; void setCurrentProfile(QString profile); QString getTranslation() const; void setTranslation(QString newValue); + + QString getAutoSaveFilesDir() const; + void setAutoSaveFilesDir(QString newValue); + + void setAutoSaveEnabled(bool newValue); + bool getAutoSaveEnabled() const; bool getForceTCP() const; void setForceTCP(bool newValue); @@ -201,10 +210,13 @@ private: bool enableIPv6; QString translation; + QString autoSaveDir; static bool makeToxPortable; bool autostartInTray; bool closeToTray; bool minimizeToTray; + bool useEmoticons; + bool autoSaveEnabled; bool forceTCP; diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index d78a95043..dd04118a9 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -23,10 +23,15 @@ #include "src/core.h" #include #include +#include +#include +#include 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"}; + GeneralForm::GeneralForm(SettingsWidget *myParent) : GenericForm(tr("General"), QPixmap(":/img/settings/general.png")) { @@ -44,7 +49,10 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : 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->setText(Settings::getInstance().getAutoSaveFilesDir()); + for (auto entry : SmileyPack::listSmileyPacks()) { bodyUI->smileyPackBrowser->addItem(entry.first, entry.second); @@ -60,6 +68,19 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : else 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? + bodyUI->autoAwaySpinBox->setValue(Settings::getInstance().getAutoAwayTime()); bodyUI->cbEnableUDP->setChecked(!Settings::getInstance().getForceTCP()); @@ -71,21 +92,29 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->cbUseProxy->setChecked(Settings::getInstance().getUseProxy()); onUseProxyUpdated(); - connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); + //general 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->closeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray); - connect(bodyUI->minimizeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetMinimizeToTray); + connect(bodyUI->minimizeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetMinimizeToTray); connect(bodyUI->statusChanges, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange); + connect(bodyUI->autoAwaySpinBox, SIGNAL(editingFinished()), this, SLOT(onAutoAwayChanged())); + connect(bodyUI->autoacceptFiles, &QCheckBox::stateChanged, this, &GeneralForm::onAutoAcceptFileChange); + if(bodyUI->autoacceptFiles->isChecked()) + connect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()), this, SLOT(onAutoSaveDirChange())); + //theme + connect(bodyUI->useEmoticons, &QCheckBox::stateChanged, this, &GeneralForm::onUseEmoticonsChange); connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int))); - // new syntax can't handle overloaded signals... (at least not in a pretty way) + 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); connect(bodyUI->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited); connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int))); - connect(bodyUI->cbUseProxy, &QCheckBox::stateChanged, this, &GeneralForm::onUseProxyUpdated); - connect(bodyUI->styleBrowser, SIGNAL(currentTextChanged(QString)), this, SLOT(onStyleSelected(QString))); - connect(bodyUI->autoAwaySpinBox, SIGNAL(editingFinished()), this, SLOT(onAutoAwayChanged())); connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked); } @@ -136,6 +165,17 @@ void GeneralForm::onStyleSelected(QString style) 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)); +} + void GeneralForm::onAutoAwayChanged() { int minutes = bodyUI->autoAwaySpinBox->value(); @@ -143,6 +183,36 @@ void GeneralForm::onAutoAwayChanged() Widget::getInstance()->setIdleTimer(minutes); } +void GeneralForm::onAutoAcceptFileChange() +{ + if(bodyUI->autoacceptFiles->isChecked() == true) + { + Settings::getInstance().setAutoSaveEnabled(true); + connect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()), this, SLOT(onAutoSaveDirChange())); + } + else + { + Settings::getInstance().setAutoSaveEnabled(false); + disconnect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()),this, SLOT(onAutoSaveDirChange())); + } +} + +void GeneralForm::onAutoSaveDirChange() +{ + QString previousDir = Settings::getInstance().getAutoSaveFilesDir(); + QString directory = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title")); + if(directory.isEmpty()) + directory = previousDir; + + Settings::getInstance().setAutoSaveFilesDir(directory); + bodyUI->autoSaveFilesDir->setText(directory); +} + +void GeneralForm::onUseEmoticonsChange() +{ + Settings::getInstance().setUseEmoticons(bodyUI->useEmoticons->isChecked()); +} + void GeneralForm::onSetStatusChange() { Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked()); diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index 535bd06e6..0701661f4 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -35,17 +35,22 @@ private slots: void onTranslationUpdated(); void onMakeToxPortableUpdated(); void onSetAutostartInTray(); - void onSetCloseToTray(); + void onSetCloseToTray(); void onSmileyBrowserIndexChanged(int index); void onUDPUpdated(); void onProxyAddrEdited(); void onProxyPortEdited(int port); void onUseProxyUpdated(); - void onStyleSelected(QString style); + void onEmoticonSizeChanged(); + void onStyleSelected(QString style); + void onTimestampSelected(int index); void onSetStatusChange(); void onAutoAwayChanged(); + void onUseEmoticonsChange(); void onSetMinimizeToTray(); void onReconnectClicked(); + void onAutoAcceptFileChange(); + void onAutoSaveDirChange(); private: Ui::GeneralSettings *bodyUI; diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui index 1856e0ad0..7bdc0a97c 100644 --- a/src/widget/form/settings/generalsettings.ui +++ b/src/widget/form/settings/generalsettings.ui @@ -39,8 +39,8 @@ 0 0 - 525 - 624 + 511 + 739 @@ -64,7 +64,7 @@ The translation may not load until qTox restarts. - Translation: + Translation @@ -132,7 +132,7 @@ Qt::LeftToRight - Auto away after (0 to disable): + Auto away after (0 to disable) @@ -163,6 +163,37 @@ + + + + Autoaccept files + + + + + + + + + Save files in + + + + + + + + 0 + 0 + + + + PushButton + + + + + @@ -172,12 +203,19 @@ Theme + + + + Use emoticons + + + - Smiley Pack: + Smiley Pack @@ -255,7 +293,7 @@ - Style: + Style @@ -271,6 +309,63 @@ + + + + + + Emoticon size + + + + + + + + 0 + 0 + + + + + + + px + + + 1 + + + 2147483647 + + + 25 + + + + + + + + + + + Timestamp format + + + + + + + + 0 + 0 + + + + + +