~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to kalarm/akonadimodel.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "akonadimodel.h"
 
22
#include "alarmtime.h"
22
23
#include "autoqpointer.h"
23
24
#include "calendarmigrator.h"
24
25
#include "mainwindow.h"
281
282
                            break;
282
283
                        case Qt::DisplayRole:
283
284
                            if (event.expired())
284
 
                                return alarmTimeText(event.startDateTime());
285
 
                            return alarmTimeText(event.nextTrigger(KAEvent::DISPLAY_TRIGGER));
 
285
                                return AlarmTime::alarmTimeText(event.startDateTime());
 
286
                            return AlarmTime::alarmTimeText(event.nextTrigger(KAEvent::DISPLAY_TRIGGER));
286
287
                        case SortRole:
287
288
                        {
288
289
                            DateTime due;
306
307
                        case Qt::DisplayRole:
307
308
                            if (event.expired())
308
309
                                return QString();
309
 
                            return timeToAlarmText(event.nextTrigger(KAEvent::DISPLAY_TRIGGER));
 
310
                            return AlarmTime::timeToAlarmText(event.nextTrigger(KAEvent::DISPLAY_TRIGGER));
310
311
                        case SortRole:
311
312
                        {
312
313
                            if (event.expired())
669
670
}
670
671
 
671
672
/******************************************************************************
672
 
* Return the alarm time text in the form "date time".
673
 
*/
674
 
QString AkonadiModel::alarmTimeText(const DateTime& dateTime) const
675
 
{
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()))
683
 
    {
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)
689
 
        {
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
694
 
            {
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
699
 
            }
700
 
        }
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;
705
 
    }
706
 
    return dateTimeText + QLatin1Char(' ');
707
 
}
708
 
 
709
 
/******************************************************************************
710
 
* Return the time-to-alarm text.
711
 
*/
712
 
QString AkonadiModel::timeToAlarmText(const DateTime& dateTime) const
713
 
{
714
 
    if (!dateTime.isValid())
715
 
        return i18nc("@info/plain Alarm never occurs", "Never");
716
 
    KDateTime now = KDateTime::currentUtcDateTime();
717
 
    if (dateTime.isDateOnly())
718
 
    {
719
 
        int days = now.date().daysTo(dateTime.date());
720
 
        // xgettext: no-c-format
721
 
        return i18nc("@info/plain n days", "%1d", days);
722
 
    }
723
 
    int mins = (now.secsTo(dateTime.effectiveKDateTime()) + 59) / 60;
724
 
    if (mins < 0)
725
 
        return QString();
726
 
    char minutes[3] = "00";
727
 
    minutes[0] = (mins%60) / 10 + '0';
728
 
    minutes[1] = (mins%60) % 10 + '0';
729
 
    if (mins < 24*60)
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);
734
 
}
735
 
 
736
 
/******************************************************************************
737
673
* Recursive function to emit the dataChanged() signal for all items in a
738
674
* specified column range.
739
675
*/