fully editable datetime format in msg list
This commit is contained in:
parent
5ef90cc691
commit
8cb7c1c496
@ -86,10 +86,12 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
|
||||
connect(m_ui->m_checkUpdateAllFeedsOnStartup, &QCheckBox::toggled, m_ui->m_spinStartupUpdateDelay, &TimeSpinBox::setEnabled);
|
||||
connect(m_ui->m_spinFeedUpdateTimeout, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
&SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_cmbMessagesDateTimeFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
|
||||
connect(m_ui->m_cmbMessagesDateTimeFormat, &QComboBox::currentTextChanged, this,
|
||||
&SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_cmbMessagesTimeFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
connect(m_ui->m_cmbMessagesTimeFormat, &QComboBox::currentTextChanged, this,
|
||||
&SettingsFeedsMessages::dirtifySettings);
|
||||
|
||||
connect(m_ui->m_cmbCountsFeedList, &QComboBox::currentTextChanged, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_cmbCountsFeedList, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&SettingsFeedsMessages::dirtifySettings);
|
||||
@ -97,6 +99,11 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
|
||||
connect(m_ui->m_checkMultilineArticleList, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_checkMultilineArticleList, &QCheckBox::toggled, this, &SettingsFeedsMessages::requireRestart);
|
||||
|
||||
connect(m_ui->m_cmbMessagesDateTimeFormat, &QComboBox::currentTextChanged,
|
||||
this, &SettingsFeedsMessages::updateDateTimeTooltip);
|
||||
connect(m_ui->m_cmbMessagesTimeFormat, &QComboBox::currentTextChanged,
|
||||
this, &SettingsFeedsMessages::updateDateTimeTooltip);
|
||||
|
||||
connect(m_ui->m_btnChangeMessagesFont, &QPushButton::clicked, this, [&]() {
|
||||
changeFont(*m_ui->m_lblMessagesFont);
|
||||
});
|
||||
@ -119,32 +126,30 @@ SettingsFeedsMessages::~SettingsFeedsMessages() {
|
||||
}
|
||||
|
||||
void SettingsFeedsMessages::initializeMessageDateFormats() {
|
||||
QStringList datetime_formats, time_formats;
|
||||
const QDateTime current_dt = QDateTime::currentDateTime();
|
||||
const QLocale current_locale = qApp->localization()->loadedLocale();
|
||||
auto installed_languages = qApp->localization()->installedLanguages();
|
||||
/*
|
||||
QStringList datetime_formats, time_formats;
|
||||
const QDateTime current_dt = QDateTime::currentDateTime();
|
||||
const QLocale current_locale = qApp->localization()->loadedLocale();
|
||||
auto installed_languages = qApp->localization()->installedLanguages();
|
||||
|
||||
for (const Language& lang : qAsConst(installed_languages)) {
|
||||
QLocale locale(lang.m_code);
|
||||
for (const Language& lang : qAsConst(installed_languages)) {
|
||||
QLocale locale(lang.m_code);
|
||||
|
||||
datetime_formats << locale.dateTimeFormat(QLocale::FormatType::LongFormat)
|
||||
<< locale.dateTimeFormat(QLocale::FormatType::ShortFormat)
|
||||
<< locale.dateTimeFormat(QLocale::FormatType::NarrowFormat);
|
||||
time_formats << locale.timeFormat(QLocale::FormatType::LongFormat)
|
||||
<< locale.timeFormat(QLocale::FormatType::ShortFormat)
|
||||
<< locale.timeFormat(QLocale::FormatType::NarrowFormat);
|
||||
}
|
||||
datetime_formats << locale.dateTimeFormat(QLocale::FormatType::LongFormat)
|
||||
<< locale.dateTimeFormat(QLocale::FormatType::ShortFormat)
|
||||
<< locale.dateTimeFormat(QLocale::FormatType::NarrowFormat);
|
||||
time_formats << locale.timeFormat(QLocale::FormatType::LongFormat)
|
||||
<< locale.timeFormat(QLocale::FormatType::ShortFormat)
|
||||
<< locale.timeFormat(QLocale::FormatType::NarrowFormat);
|
||||
}
|
||||
|
||||
datetime_formats.removeDuplicates();
|
||||
time_formats.removeDuplicates();
|
||||
datetime_formats.removeDuplicates();
|
||||
time_formats.removeDuplicates();*/
|
||||
|
||||
for (const QString& format : qAsConst(datetime_formats)) {
|
||||
m_ui->m_cmbMessagesDateTimeFormat->addItem(current_locale.toString(current_dt, format), format);
|
||||
}
|
||||
QStringList patterns = TextFactory::dateTimePatterns();
|
||||
|
||||
for (const QString& format : qAsConst(time_formats)) {
|
||||
m_ui->m_cmbMessagesTimeFormat->addItem(current_locale.toString(current_dt, format), format);
|
||||
}
|
||||
m_ui->m_cmbMessagesDateTimeFormat->addItems(patterns);
|
||||
m_ui->m_cmbMessagesTimeFormat->addItems(patterns);
|
||||
}
|
||||
|
||||
void SettingsFeedsMessages::changeFont(QLabel& lbl) {
|
||||
@ -199,22 +204,12 @@ void SettingsFeedsMessages::loadSettings() {
|
||||
#endif
|
||||
|
||||
m_ui->m_checkMessagesDateTimeFormat->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::UseCustomDate)).toBool());
|
||||
|
||||
int index_format = m_ui->m_cmbMessagesDateTimeFormat->findData(settings()->value(GROUP(Messages),
|
||||
SETTING(Messages::CustomDateFormat)).toString());
|
||||
|
||||
if (index_format >= 0) {
|
||||
m_ui->m_cmbMessagesDateTimeFormat->setCurrentIndex(index_format);
|
||||
}
|
||||
m_ui->m_cmbMessagesDateTimeFormat->setCurrentText(settings()->value(GROUP(Messages),
|
||||
SETTING(Messages::CustomDateFormat)).toString());
|
||||
|
||||
m_ui->m_checkMessagesTimeFormat->setChecked(settings()->value(GROUP(Messages), SETTING(Messages::UseCustomTime)).toBool());
|
||||
|
||||
index_format = m_ui->m_cmbMessagesTimeFormat->findData(settings()->value(GROUP(Messages),
|
||||
SETTING(Messages::CustomTimeFormat)).toString());
|
||||
|
||||
if (index_format >= 0) {
|
||||
m_ui->m_cmbMessagesTimeFormat->setCurrentIndex(index_format);
|
||||
}
|
||||
m_ui->m_cmbMessagesTimeFormat->setCurrentText(settings()->value(GROUP(Messages),
|
||||
SETTING(Messages::CustomTimeFormat)).toString());
|
||||
|
||||
QFont fon;
|
||||
|
||||
@ -280,11 +275,8 @@ void SettingsFeedsMessages::saveSettings() {
|
||||
settings()->setValue(GROUP(Messages), Messages::UseCustomDate, m_ui->m_checkMessagesDateTimeFormat->isChecked());
|
||||
settings()->setValue(GROUP(Messages), Messages::UseCustomTime, m_ui->m_checkMessagesTimeFormat->isChecked());
|
||||
|
||||
settings()->setValue(GROUP(Messages), Messages::CustomDateFormat,
|
||||
m_ui->m_cmbMessagesDateTimeFormat->itemData(m_ui->m_cmbMessagesDateTimeFormat->currentIndex()).toString());
|
||||
|
||||
settings()->setValue(GROUP(Messages), Messages::CustomTimeFormat,
|
||||
m_ui->m_cmbMessagesTimeFormat->itemData(m_ui->m_cmbMessagesTimeFormat->currentIndex()).toString());
|
||||
settings()->setValue(GROUP(Messages), Messages::CustomDateFormat, m_ui->m_cmbMessagesDateTimeFormat->currentText());
|
||||
settings()->setValue(GROUP(Messages), Messages::CustomTimeFormat, m_ui->m_cmbMessagesTimeFormat->currentText());
|
||||
|
||||
// Save fonts.
|
||||
settings()->setValue(GROUP(Messages), Messages::PreviewerFontStandard, m_ui->m_lblMessagesFont->font().toString());
|
||||
@ -302,3 +294,16 @@ void SettingsFeedsMessages::saveSettings() {
|
||||
|
||||
onEndSaveSettings();
|
||||
}
|
||||
|
||||
void SettingsFeedsMessages::updateDateTimeTooltip() {
|
||||
QComboBox* sndr = qobject_cast<QComboBox*>(sender());
|
||||
|
||||
if (sndr != nullptr) {
|
||||
if (sndr->currentText().simplified().isEmpty()) {
|
||||
sndr->setToolTip({});
|
||||
}
|
||||
else {
|
||||
sndr->setToolTip(QDateTime::currentDateTime().toString(sndr->currentText()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ class SettingsFeedsMessages : public SettingsPanel {
|
||||
virtual void loadSettings();
|
||||
virtual void saveSettings();
|
||||
|
||||
private slots:
|
||||
void updateDateTimeTooltip();
|
||||
|
||||
private:
|
||||
void changeFont(QLabel& lbl);
|
||||
|
||||
|
@ -383,6 +383,9 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="13" column="0">
|
||||
@ -406,6 +409,9 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="0" colspan="2">
|
||||
|
@ -73,13 +73,7 @@ QDateTime TextFactory::parseDateTime(const QString& date_time) {
|
||||
QTime time_zone_offset;
|
||||
const QLocale locale(QLocale::Language::C);
|
||||
bool positive_time_zone_offset = false;
|
||||
QStringList date_patterns;
|
||||
|
||||
date_patterns << QSL("yyyy-MM-ddTHH:mm:ss") << QSL("MMM dd yyyy hh:mm:ss") <<
|
||||
QSL("MMM d yyyy hh:mm:ss") << QSL("ddd, dd MMM yyyy HH:mm:ss") << QSL("ddd, d MMM yyyy HH:mm:ss") <<
|
||||
QSL("dd MMM yyyy") << QSL("yyyy-MM-dd HH:mm:ss.z") << QSL("yyyy-MM-dd") <<
|
||||
QSL("yyyy") << QSL("yyyy-MM") << QSL("yyyy-MM-dd") << QSL("yyyy-MM-ddThh:mm") <<
|
||||
QSL("yyyy-MM-ddThh:mm:ss") << QSL("d MMM yyyy HH:mm:ss");
|
||||
static QStringList date_patterns = dateTimePatterns();
|
||||
QStringList timezone_offset_patterns;
|
||||
|
||||
timezone_offset_patterns << QSL("+hh:mm") << QSL("-hh:mm") << QSL("+hhmm")
|
||||
@ -133,6 +127,15 @@ QDateTime TextFactory::parseDateTime(qint64 milis_from_epoch) {
|
||||
return QDateTime::fromMSecsSinceEpoch(milis_from_epoch, Qt::TimeSpec::UTC);
|
||||
}
|
||||
|
||||
QStringList TextFactory::dateTimePatterns() {
|
||||
return QStringList() << QSL("yyyy-MM-ddTHH:mm:ss") << QSL("MMM dd yyyy hh:mm:ss") <<
|
||||
QSL("MMM d yyyy hh:mm:ss") << QSL("ddd, dd MMM yyyy HH:mm:ss") << QSL("ddd, d MMM yyyy HH:mm:ss") <<
|
||||
QSL("dd MMM yyyy") << QSL("yyyy-MM-dd HH:mm:ss.z") << QSL("yyyy-MM-dd") <<
|
||||
QSL("yyyy") << QSL("yyyy-MM") << QSL("yyyy-MM-dd") << QSL("yyyy-MM-ddThh:mm") <<
|
||||
QSL("yyyy-MM-ddThh:mm:ss") << QSL("d MMM yyyy HH:mm:ss") << QSL("hh:mm:ss") <<
|
||||
QSL("h:m:s AP") << QSL("h:m") << QSL("h.m");
|
||||
}
|
||||
|
||||
QString TextFactory::encrypt(const QString& text, quint64 key) {
|
||||
return SimpleCrypt(key == 0 ? initializeSecretEncryptionKey() : key).encryptToString(text);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class TextFactory {
|
||||
// Converts 1970-epoch miliseconds to date/time.
|
||||
// NOTE: This method tries to always return time in UTC.
|
||||
static QDateTime parseDateTime(qint64 milis_from_epoch);
|
||||
static QStringList dateTimePatterns();
|
||||
static QString encrypt(const QString& text, quint64 key = 0);
|
||||
static QString decrypt(const QString& text, quint64 key = 0);
|
||||
static QString newline();
|
||||
|
Loading…
x
Reference in New Issue
Block a user