mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Use default-constructed QLocale for date/time/whatever else formatting
Qt 6 chenged the QDateTime API to use QLocale::c() rather than QLocale::system(), using default-constructed QLocale will make this consistent and overradable application-wide Other formating use-cases as QLocale::decimalPoint use default-constructed QLocale now, too
This commit is contained in:
parent
2c1933bdb8
commit
7b5781b845
22 changed files with 50 additions and 41 deletions
|
@ -79,12 +79,12 @@ Authorizations::Entry ParseEntry(const MTPDauthorization &data) {
|
|||
const auto nowDate = now.date();
|
||||
const auto lastDate = lastTime.date();
|
||||
if (lastDate == nowDate) {
|
||||
result.active = lastTime.toString(cTimeFormat());
|
||||
result.active = QLocale().toString(lastTime, cTimeFormat());
|
||||
} else if (lastDate.year() == nowDate.year()
|
||||
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
||||
result.active = langDayOfWeek(lastDate);
|
||||
} else {
|
||||
result.active = lastDate.toString(cDateFormat());
|
||||
result.active = QLocale().toString(lastDate, cDateFormat());
|
||||
}
|
||||
}
|
||||
result.location = country;
|
||||
|
|
|
@ -1376,7 +1376,7 @@ QString PrepareRequestedRowStatus(TimeId date) {
|
|||
const auto now = QDateTime::currentDateTime();
|
||||
const auto parsed = base::unixtime::parse(date);
|
||||
const auto parsedDate = parsed.date();
|
||||
const auto time = parsed.time().toString(cTimeFormat());
|
||||
const auto time = QLocale().toString(parsed.time(), cTimeFormat());
|
||||
const auto generic = [&] {
|
||||
return tr::lng_group_requests_status_date_time(
|
||||
tr::now,
|
||||
|
|
|
@ -200,7 +200,7 @@ private:
|
|||
left / 86400));
|
||||
} else {
|
||||
const auto time = base::unixtime::parse(link.expireDate).time();
|
||||
add(QLocale::system().toString(time, QLocale::LongFormat));
|
||||
add(QLocale().toString(time, QLocale::LongFormat));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -209,7 +209,7 @@ void BoxController::Row::refreshStatus() {
|
|||
return;
|
||||
}
|
||||
auto text = [this] {
|
||||
auto time = ItemDateTime(_items.front()).time().toString(cTimeFormat());
|
||||
auto time = QLocale().toString(ItemDateTime(_items.front()).time(), cTimeFormat());
|
||||
auto today = QDateTime::currentDateTime().date();
|
||||
if (_date == today) {
|
||||
return tr::lng_call_box_status_today(tr::now, lt_time, time);
|
||||
|
|
|
@ -33,7 +33,8 @@ rpl::producer<QString> StartsWhenText(rpl::producer<TimeId> date) {
|
|||
const auto tillToday = tillTomorrow + kDay;
|
||||
const auto tillAfter = tillToday + kDay;
|
||||
|
||||
const auto time = parsedDate.time().toString(
|
||||
const auto time = QLocale().toString(
|
||||
parsedDate.time(),
|
||||
Ui::Integration::Instance().timeFormat());
|
||||
auto exact = tr::lng_group_call_starts_short_date(
|
||||
lt_date,
|
||||
|
|
|
@ -272,8 +272,8 @@ void Application::run() {
|
|||
|
||||
DEBUG_LOG(("Application Info: inited..."));
|
||||
|
||||
cChangeDateFormat(QLocale::system().dateFormat(QLocale::ShortFormat));
|
||||
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
|
||||
cChangeDateFormat(QLocale().dateFormat(QLocale::ShortFormat));
|
||||
cChangeTimeFormat(QLocale().timeFormat(QLocale::ShortFormat));
|
||||
|
||||
DEBUG_LOG(("Application Info: starting app..."));
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ QString filedialogDefaultName(
|
|||
QString base;
|
||||
if (fileTime) {
|
||||
const auto date = base::unixtime::parse(fileTime);
|
||||
base = prefix + date.toString("_yyyy-MM-dd_HH-mm-ss");
|
||||
base = prefix + QLocale().toString(date, "_yyyy-MM-dd_HH-mm-ss");
|
||||
} else {
|
||||
struct tm tm;
|
||||
time_t t = time(NULL);
|
||||
|
|
|
@ -1102,8 +1102,8 @@ std::optional<QString> RestrictionError(
|
|||
auto restrictedUntil = channel->restrictedUntil();
|
||||
if (restrictedUntil > 0 && !ChannelData::IsRestrictedForever(restrictedUntil)) {
|
||||
auto restrictedUntilDateTime = base::unixtime::parse(channel->restrictedUntil());
|
||||
auto date = restrictedUntilDateTime.toString(cDateFormat());
|
||||
auto time = restrictedUntilDateTime.toString(cTimeFormat());
|
||||
auto date = QLocale().toString(restrictedUntilDateTime, cDateFormat());
|
||||
auto time = QLocale().toString(restrictedUntilDateTime, cTimeFormat());
|
||||
|
||||
switch (restriction) {
|
||||
case Flag::SendPolls:
|
||||
|
|
|
@ -399,14 +399,15 @@ QString OnlineText(TimeId online, TimeId now) {
|
|||
}
|
||||
const auto onlineFull = base::unixtime::parse(online);
|
||||
const auto nowFull = base::unixtime::parse(now);
|
||||
const auto locale = QLocale();
|
||||
if (onlineFull.date() == nowFull.date()) {
|
||||
const auto onlineTime = onlineFull.time().toString(cTimeFormat());
|
||||
const auto onlineTime = locale.toString(onlineFull.time(), cTimeFormat());
|
||||
return tr::lng_status_lastseen_today(tr::now, lt_time, onlineTime);
|
||||
} else if (onlineFull.date().addDays(1) == nowFull.date()) {
|
||||
const auto onlineTime = onlineFull.time().toString(cTimeFormat());
|
||||
const auto onlineTime = locale.toString(onlineFull.time(), cTimeFormat());
|
||||
return tr::lng_status_lastseen_yesterday(tr::now, lt_time, onlineTime);
|
||||
}
|
||||
const auto date = onlineFull.date().toString(cDateFormat());
|
||||
const auto date = locale.toString(onlineFull.date(), cDateFormat());
|
||||
return tr::lng_status_lastseen_date(tr::now, lt_date, date);
|
||||
}
|
||||
|
||||
|
@ -425,15 +426,16 @@ QString OnlineTextFull(not_null<UserData*> user, TimeId now) {
|
|||
}
|
||||
const auto onlineFull = base::unixtime::parse(user->onlineTill);
|
||||
const auto nowFull = base::unixtime::parse(now);
|
||||
const auto locale = QLocale();
|
||||
if (onlineFull.date() == nowFull.date()) {
|
||||
const auto onlineTime = onlineFull.time().toString(cTimeFormat());
|
||||
const auto onlineTime = locale.toString(onlineFull.time(), cTimeFormat());
|
||||
return tr::lng_status_lastseen_today(tr::now, lt_time, onlineTime);
|
||||
} else if (onlineFull.date().addDays(1) == nowFull.date()) {
|
||||
const auto onlineTime = onlineFull.time().toString(cTimeFormat());
|
||||
const auto onlineTime = locale.toString(onlineFull.time(), cTimeFormat());
|
||||
return tr::lng_status_lastseen_yesterday(tr::now, lt_time, onlineTime);
|
||||
}
|
||||
const auto date = onlineFull.date().toString(cDateFormat());
|
||||
const auto time = onlineFull.time().toString(cTimeFormat());
|
||||
const auto date = locale.toString(onlineFull.date(), cDateFormat());
|
||||
const auto time = locale.toString(onlineFull.time(), cTimeFormat());
|
||||
return tr::lng_status_lastseen_date_time(tr::now, lt_date, date, lt_time, time);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,12 +72,12 @@ void PaintRowDate(QPainter &p, QDateTime date, QRect &rectForName, bool active,
|
|||
const auto wasSameDay = (lastDate == nowDate);
|
||||
const auto wasRecently = qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds;
|
||||
if (wasSameDay || wasRecently) {
|
||||
return lastTime.toString(cTimeFormat());
|
||||
return QLocale().toString(lastTime, cTimeFormat());
|
||||
} else if (lastDate.year() == nowDate.year()
|
||||
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
||||
return langDayOfWeek(lastDate);
|
||||
} else {
|
||||
return lastDate.toString(cDateFormat());
|
||||
return QLocale().toString(lastDate, cDateFormat());
|
||||
}
|
||||
}();
|
||||
PaintRowTopRight(p, dt, rectForName, active, selected);
|
||||
|
|
|
@ -533,8 +533,6 @@ QString InnerWidget::tooltipText() const {
|
|||
if (_mouseCursorState == CursorState::Date
|
||||
&& _mouseAction == MouseAction::None) {
|
||||
if (const auto view = Element::Hovered()) {
|
||||
const auto format = QLocale::system().dateTimeFormat(
|
||||
QLocale::LongFormat);
|
||||
auto dateText = HistoryView::DateTooltipText(view);
|
||||
|
||||
const auto sentIt = _itemDates.find(view->data());
|
||||
|
@ -542,7 +540,9 @@ QString InnerWidget::tooltipText() const {
|
|||
dateText += '\n' + tr::lng_sent_date(
|
||||
tr::now,
|
||||
lt_date,
|
||||
base::unixtime::parse(sentIt->second).toString(format));
|
||||
QLocale().toString(
|
||||
base::unixtime::parse(sentIt->second),
|
||||
QLocale::LongFormat));
|
||||
}
|
||||
return dateText;
|
||||
}
|
||||
|
|
|
@ -2655,7 +2655,7 @@ TextForMimeData HistoryInner::getSelectedText() const {
|
|||
TextForMimeData &&unwrapped) {
|
||||
const auto i = texts.emplace(item->position(), Part{
|
||||
.name = item->author()->name(),
|
||||
.time = ItemDateTime(item).toString(timeFormat),
|
||||
.time = QLocale().toString(ItemDateTime(item), timeFormat),
|
||||
.unwrapped = std::move(unwrapped),
|
||||
}).first;
|
||||
fullSize += i->second.name.size()
|
||||
|
|
|
@ -1145,7 +1145,7 @@ HistoryService::PreparedText HistoryService::prepareCallScheduledText(
|
|||
Ui::Text::WithEntities);
|
||||
}
|
||||
};
|
||||
const auto time = scheduled.time().toString(cTimeFormat());
|
||||
const auto time = QLocale().toString(scheduled.time(), cTimeFormat());
|
||||
const auto prepareGeneric = [&] {
|
||||
prepareWithDate(tr::lng_group_call_starts_date(
|
||||
tr::now,
|
||||
|
|
|
@ -83,7 +83,7 @@ enum class FilterType {
|
|||
const auto decimalPart = duration % kPrecision;
|
||||
return QString("%1%2%3")
|
||||
.arg(durationString)
|
||||
.arg(QLocale::system().decimalPoint())
|
||||
.arg(QLocale().decimalPoint())
|
||||
.arg(decimalPart);
|
||||
}
|
||||
|
||||
|
|
|
@ -437,7 +437,7 @@ void BottomInfo::layoutDateText() {
|
|||
: QString();
|
||||
const auto author = _data.author;
|
||||
const auto prefix = !author.isEmpty() ? qsl(", ") : QString();
|
||||
const auto date = edited + _data.date.toString(cTimeFormat());
|
||||
const auto date = edited + QLocale().toString(_data.date, cTimeFormat());
|
||||
const auto afterAuthor = prefix + date;
|
||||
const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor);
|
||||
const auto authorWidth = st::msgDateFont->width(author);
|
||||
|
|
|
@ -250,19 +250,20 @@ TextSelection ShiftItemSelection(
|
|||
}
|
||||
|
||||
QString DateTooltipText(not_null<Element*> view) {
|
||||
const auto format = QLocale::system().dateTimeFormat(QLocale::LongFormat);
|
||||
auto dateText = view->dateTime().toString(format);
|
||||
const auto locale = QLocale();
|
||||
const auto format = QLocale::LongFormat;
|
||||
auto dateText = locale.toString(view->dateTime(), format);
|
||||
if (const auto editedDate = view->displayedEditDate()) {
|
||||
dateText += '\n' + tr::lng_edited_date(
|
||||
tr::now,
|
||||
lt_date,
|
||||
base::unixtime::parse(editedDate).toString(format));
|
||||
locale.toString(base::unixtime::parse(editedDate), format));
|
||||
}
|
||||
if (const auto forwarded = view->data()->Get<HistoryMessageForwarded>()) {
|
||||
dateText += '\n' + tr::lng_forwarded_date(
|
||||
tr::now,
|
||||
lt_date,
|
||||
base::unixtime::parse(forwarded->originalDate).toString(format));
|
||||
locale.toString(base::unixtime::parse(forwarded->originalDate), format));
|
||||
if (forwarded->imported) {
|
||||
dateText = tr::lng_forwarded_imported(tr::now)
|
||||
+ "\n\n" + dateText;
|
||||
|
|
|
@ -1976,7 +1976,7 @@ TextForMimeData ListWidget::getSelectedText() const {
|
|||
const auto wrapItem = [&](
|
||||
not_null<HistoryItem*> item,
|
||||
TextForMimeData &&unwrapped) {
|
||||
auto time = ItemDateTime(item).toString(timeFormat);
|
||||
auto time = QLocale().toString(ItemDateTime(item), timeFormat);
|
||||
auto part = TextForMimeData();
|
||||
auto size = item->author()->name().size()
|
||||
+ time.size()
|
||||
|
|
|
@ -46,7 +46,7 @@ Call::Call(
|
|||
, _video(call->video) {
|
||||
const auto item = parent->data();
|
||||
_text = Data::MediaCall::Text(item, _reason, _video);
|
||||
_status = parent->dateTime().time().toString(cTimeFormat());
|
||||
_status = QLocale().toString(parent->dateTime().time(), cTimeFormat());
|
||||
if (_duration) {
|
||||
_status = tr::lng_call_duration_info(
|
||||
tr::now,
|
||||
|
|
|
@ -218,7 +218,9 @@ QString langDateTime(const QDateTime &date) {
|
|||
lt_date,
|
||||
langDayOfMonth(date.date()),
|
||||
lt_time,
|
||||
date.time().toString(Ui::Integration::Instance().timeFormat()));
|
||||
QLocale().toString(
|
||||
date.time(),
|
||||
Ui::Integration::Instance().timeFormat()));
|
||||
}
|
||||
|
||||
QString langDateTimeFull(const QDateTime &date) {
|
||||
|
@ -227,5 +229,7 @@ QString langDateTimeFull(const QDateTime &date) {
|
|||
lt_date,
|
||||
langDayOfMonthFull(date.date()),
|
||||
lt_time,
|
||||
date.time().toString(Ui::Integration::Instance().timeFormat()));
|
||||
QLocale().toString(
|
||||
date.time(),
|
||||
Ui::Integration::Instance().timeFormat()));
|
||||
}
|
||||
|
|
|
@ -1020,7 +1020,7 @@ void Widget::handleSongChange() {
|
|||
const auto date = [item] {
|
||||
const auto parsed = ItemDateTime(item);
|
||||
const auto date = parsed.date();
|
||||
const auto time = parsed.time().toString(cTimeFormat());
|
||||
const auto time = QLocale().toString(parsed.time(), cTimeFormat());
|
||||
const auto today = QDateTime::currentDateTime().date();
|
||||
if (date == today) {
|
||||
return tr::lng_player_message_today(
|
||||
|
|
|
@ -289,7 +289,8 @@ void GroupCallBar::paint(Painter &p) {
|
|||
}
|
||||
const auto parsed = base::unixtime::parse(_content.scheduleDate);
|
||||
const auto date = parsed.date();
|
||||
const auto time = parsed.time().toString(
|
||||
const auto time = QLocale().toString(
|
||||
parsed.time(),
|
||||
Ui::Integration::Instance().timeFormat());
|
||||
const auto today = QDate::currentDate();
|
||||
if (date == today) {
|
||||
|
|
|
@ -88,19 +88,19 @@ QString FormatDateTime(
|
|||
return tr::lng_mediaview_today(
|
||||
tr::now,
|
||||
lt_time,
|
||||
date.time().toString(timeFormat));
|
||||
QLocale().toString(date.time(), timeFormat));
|
||||
} else if (date.date().addDays(1) == now.date()) {
|
||||
return tr::lng_mediaview_yesterday(
|
||||
tr::now,
|
||||
lt_time,
|
||||
date.time().toString(timeFormat));
|
||||
QLocale().toString(date.time(), timeFormat));
|
||||
} else {
|
||||
return tr::lng_mediaview_date_time(
|
||||
tr::now,
|
||||
lt_date,
|
||||
date.date().toString(dateFormat),
|
||||
QLocale().toString(date.date(), dateFormat),
|
||||
lt_time,
|
||||
date.time().toString(timeFormat));
|
||||
QLocale().toString(date.time(), timeFormat));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue