void NemoCalendarEventQuery::refresh()
{
    if (!mIsComplete)
        return;

    mKCal::ExtendedCalendar::Ptr calendar = NemoCalendarDb::calendar();
    KCalCore::Event::Ptr event = mUid.isEmpty()?KCalCore::Event::Ptr():calendar->event(mUid);
    if (event) {
        if (mOccurrence) {
            delete mOccurrence;
            mOccurrence = 0;
        }

        mKCal::ExtendedCalendar::ExpandedIncidenceValidity eiv = {
            event->dtStart().toLocalZone().dateTime(),
            event->dtEnd().toLocalZone().dateTime()
        };

        if (!mStartTime.isNull() && event->recurs()) {
            KDateTime startTime = KDateTime(mStartTime, KDateTime::Spec(KDateTime::LocalZone));
            KCalCore::Recurrence *recurrence = event->recurrence();
            if (recurrence->recursAt(startTime)) {
                eiv.dtStart = startTime.toLocalZone().dateTime();
                eiv.dtEnd = KCalCore::Duration(event->dtStart(), event->dtEnd()).end(startTime).toLocalZone().dateTime();
            } else {
                KDateTime match = recurrence->getNextDateTime(startTime);
                if (match.isNull())
                    match = recurrence->getPreviousDateTime(startTime);

                if (!match.isNull()) {
                    eiv.dtStart = match.toLocalZone().dateTime();
                    eiv.dtEnd = KCalCore::Duration(event->dtStart(), event->dtEnd()).end(match).toLocalZone().dateTime();
                }
            }
        }

        mOccurrence = new NemoCalendarEventOccurrence(qMakePair(eiv, event.dynamicCast<KCalCore::Incidence>()), 
                                                      this);
        emit occurrenceChanged();
        emit eventChanged();
    } else {
        if (mOccurrence) {
            delete mOccurrence;
            mOccurrence = 0;
            emit occurrenceChanged();
            emit eventChanged();
        }
    }
}
示例#2
0
QString DateStringBuilder::getDateString(const KDateTime &dateTime, bool grouped)
{
    if (!dateTime.isValid() || dateTime.isNull()) {
        return QString();
    }
    QString day;
    if (QDateTime().currentDateTime().date() == dateTime.date()) {
        day = i18nc( "today", "Today" );
    }
    if (QDateTime().currentDateTime().date().addDays(1) == dateTime.date()) {
        day = i18nc( "tomorrow", "Tomorrow" );
    }
    if (QDateTime().currentDateTime().date() == dateTime.date().addDays(1)) {
        day = i18nc( "yesterday", "Yesterday" );
    }
    if (!grouped && !day.isEmpty()) {
        return day.append("/t").append(dateTime.toString("%d.%m.%Y"));
    }

    if (!grouped && day.isEmpty()) {
        return dateTime.toString("%:a %d.%m.%Y");
    }

    if (QDateTime().currentDateTime().date().weekNumber() == dateTime.date().weekNumber()) {
        return dateTime.toString("%A");
    }

    //TODO last week

    return dateTime.toString("%B");
    //KGlobal::locale()->formatDate(pimitem->getPrimaryDate().dateTime());
    //return pimitem->getPrimaryDate().dateTime().toString("ddd dd.MM hh:mm");
    //return dateTime.toString("%:a %d.%m.%Y");
}
示例#3
0
QString DateStringBuilder::getFullDateTime(const KDateTime &dateTime)
{
    if (!dateTime.isValid() || dateTime.isNull()) {
        return QString();
    }
    QString date;
    date.append(getFullDate(dateTime));
    date.append(" ");
    date.append(dateTime.toString("%k:%M:%S"));
    return date;
}
示例#4
0
文件: gdata.cpp 项目: mtux/bilbo
void GData::listRecentPosts( const QStringList &labels, int number,
                             const KDateTime &upMinTime, const KDateTime &upMaxTime,
                             const KDateTime &pubMinTime, const KDateTime &pubMaxTime )
{
  kDebug();
  Q_D( GData );
  QString urlString( "http://www.blogger.com/feeds/" + blogId() + "/posts/default" );
  if ( ! labels.empty() ) {
    urlString += "/-/" + labels.join( "/" );
  }
  kDebug() << "listRecentPosts()";
  KUrl url( urlString );

  if ( !upMinTime.isNull() ) {
    url.addQueryItem( "updated-min", upMinTime.toString() );
  }

  if( !upMaxTime.isNull() ) {
    url.addQueryItem( "updated-max", upMaxTime.toString() );
  }

  if( !pubMinTime.isNull() ) {
    url.addQueryItem( "published-min", pubMinTime.toString() );
  }

  if( !pubMaxTime.isNull() ) {
    url.addQueryItem( "published-max", pubMaxTime.toString() );
  }

  Syndication::Loader *loader = Syndication::Loader::create();
  if ( number > 0 ) {
    d->mListRecentPostsMap[ loader ] = number;
  }
  connect( loader,
           SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
           this,
           SLOT(slotListRecentPosts(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
  loader->loadFrom( url.url() );
}
示例#5
0
QString DateStringBuilder::getGroupedDate(const KDateTime &dateTime)
{
    if (!dateTime.isValid() || dateTime.isNull()) {
        return QString();
    }
    QDate currentDate = QDateTime::currentDateTime().date();
    if (currentDate.weekNumber() == dateTime.date().weekNumber()) { //this week
        return getDayName(dateTime);
    }
    if (currentDate.addDays(-7).weekNumber() == dateTime.date().weekNumber()) { //last week
        return i18n("Last Week");
    }
    if (currentDate.year() == dateTime.date().year()) { //this year
        return dateTime.toString("%B");
    }
    return dateTime.toString("%B %Y");
}
示例#6
0
QString getDayName(const KDateTime &dateTime)
{
    if (!dateTime.isValid() || dateTime.isNull()) {
        return QString();
    }
    QString day;
    if (QDateTime().currentDateTime().date() == dateTime.date()) {
        return i18n("Today" );
    }
    if (QDateTime().currentDateTime().date().addDays(1) == dateTime.date()) {
        return i18n( "Tomorrow" );
    }
    if (QDateTime().currentDateTime().date() == dateTime.date().addDays(1)) {
        return i18n("Yesterday" );
    }
    return dateTime.toString("%A");

}
示例#7
0
QString DateStringBuilder::getShortDate(const KDateTime &dateTime)
{
    if (!dateTime.isValid() || dateTime.isNull()) {
        return QString();
    }
    QDate currentDate = QDateTime().currentDateTime().date();
    if (currentDate.weekNumber() == dateTime.date().weekNumber() || currentDate.addDays(1) == dateTime.date()) { //this week or tomorrow (i.e. on sunday)
        return getDayName(dateTime);
    }
    if (currentDate.year() == dateTime.date().year()) { //this year
        //Micro optimization because this function showed up as hotspot
        static QCache<uint, QString> cache;
        uint hash = dateTime.date().month() ^ dateTime.date().day();
        if (!cache.contains(hash)) {
            cache.insert(hash, new QString(dateTime.toString("%d.%m")));
        }
        return *cache[hash];
    }
    return dateTime.toString("%d.%m.%Y");
}