671
672
/******************************************************************************
672
* Return the alarm time text in the form "date time".
674
QString AkonadiModel::alarmTimeText(const DateTime& dateTime) const
676
if (!dateTime.isValid())
677
return i18nc("@info/plain Alarm never occurs", "Never");
678
KLocale* locale = KGlobal::locale();
679
KDateTime kdt = dateTime.effectiveKDateTime().toTimeSpec(Preferences::timeZone());
680
QString dateTimeText = locale->formatDate(kdt.date(), KLocale::ShortDate);
681
if (!dateTime.isDateOnly()
682
|| (!dateTime.isClockTime() && kdt.utcOffset() != dateTime.utcOffset()))
684
// Display the time of day if it's a date/time value, or if it's
685
// a date-only value but it's in a different time zone
686
dateTimeText += QLatin1Char(' ');
687
QString time = locale->formatTime(kdt.time());
688
if (mTimeHourPos == -2)
690
// Initialise the position of the hour within the time string, if leading
691
// zeroes are omitted, so that displayed times can be aligned with each other.
692
mTimeHourPos = -1; // default = alignment isn't possible/sensible
693
if (QApplication::isLeftToRight()) // don't try to align right-to-left languages
695
QString fmt = locale->timeFormat();
696
int i = fmt.indexOf(QRegExp("%[kl]")); // check if leading zeroes are omitted
697
if (i >= 0 && i == fmt.indexOf(QLatin1Char('%'))) // and whether the hour is first
698
mTimeHourPos = i; // yes, so need to align
701
if (mTimeHourPos >= 0 && (int)time.length() > mTimeHourPos + 1
702
&& time[mTimeHourPos].isDigit() && !time[mTimeHourPos + 1].isDigit())
703
dateTimeText += QLatin1Char('~'); // improve alignment of times with no leading zeroes
704
dateTimeText += time;
706
return dateTimeText + QLatin1Char(' ');
709
/******************************************************************************
710
* Return the time-to-alarm text.
712
QString AkonadiModel::timeToAlarmText(const DateTime& dateTime) const
714
if (!dateTime.isValid())
715
return i18nc("@info/plain Alarm never occurs", "Never");
716
KDateTime now = KDateTime::currentUtcDateTime();
717
if (dateTime.isDateOnly())
719
int days = now.date().daysTo(dateTime.date());
720
// xgettext: no-c-format
721
return i18nc("@info/plain n days", "%1d", days);
723
int mins = (now.secsTo(dateTime.effectiveKDateTime()) + 59) / 60;
726
char minutes[3] = "00";
727
minutes[0] = (mins%60) / 10 + '0';
728
minutes[1] = (mins%60) % 10 + '0';
730
return i18nc("@info/plain hours:minutes", "%1:%2", mins/60, minutes);
731
int days = mins / (24*60);
732
mins = mins % (24*60);
733
return i18nc("@info/plain days hours:minutes", "%1d %2:%3", days, mins/60, minutes);
736
/******************************************************************************
737
673
* Recursive function to emit the dataChanged() signal for all items in a
738
674
* specified column range.