Esempio n. 1
0
void MyMoneyReport::validDateRange ( QDate& _db, QDate& _de )
{
  _db = fromDate();
  _de = toDate();

  // if either begin or end date are invalid we have one of the following
  // possible date filters:
  //
  // a) begin date not set - first transaction until given end date
  // b) end date not set   - from given date until last transaction
  // c) both not set       - first transaction until last transaction
  //
  // If there is no transaction in the engine at all, we use the current
  // year as the filter criteria.

  if ( !_db.isValid() || !_de.isValid() ) {
    QValueList<MyMoneyTransaction> list = MyMoneyFile::instance()->transactionList ( *this );
    QDate tmpBegin, tmpEnd;

    if ( !list.isEmpty() ) {
      qHeapSort ( list );
      tmpBegin = list.front().postDate();
      tmpEnd = list.back().postDate();
    } else {
      tmpBegin = QDate ( QDate::currentDate().year(), 1, 1 ); // the first date in the file
      tmpEnd = QDate ( QDate::currentDate().year(), 12, 31 );// the last date in the file
    }
    if ( !_db.isValid() )
      _db = tmpBegin;
    if ( !_de.isValid() )
      _de = tmpEnd;
  }
  if ( _db > _de )
    _db = _de;
}
void CalDavClient::startQuickSync()
{
    FUNCTION_CALL_TRACE;

    mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC()));
    mKCal::ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar);

    storage->open();
    storage->load(QDateTime::currentDateTime().toUTC().addMonths(-6).date(),
                  QDateTime::currentDateTime().toUTC().addMonths(12).date());

    // we add 2 seconds to ensure that the timestamp doesn't
    // fall prior to when the calendar db commit fs sync finalises.
    KDateTime fromDate(lastSyncTime().addSecs(2));
    LOG_DEBUG("\n\nLAST SYNC TIME = " << fromDate.toString() << "\n\n");

    KCalCore::Incidence::List inserted;
    KCalCore::Incidence::List modified;
    KCalCore::Incidence::List deleted;
    QString errorString;
    if (!loadStorageChanges(storage, fromDate, &inserted, &modified, &deleted, &errorString)) {
        storage->close();
        calendar->close();
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, errorString);
        return;
    }
    LOG_DEBUG("Changes: inserted = " << inserted.count()
              << "modified = " << modified.count()
              << "deleted = " << deleted.count());
    if (inserted.isEmpty() && modified.isEmpty() && deleted.isEmpty()) {
        // no local changes to send, just do a REPORT to pull updates from server
        retrieveETags();
    } else {
        for (int i=0; i<inserted.count(); i++) {
            Put *put = new Put(mNAManager, &mSettings);
            mRequests.insert(put);
            connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            put->createEvent(inserted[i]);
        }
        for (int i=0; i<modified.count(); i++) {
            Put *put = new Put(mNAManager, &mSettings);
            mRequests.insert(put);
            connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            put->updateEvent(modified[i]);
        }
        for (int i=0; i<deleted.count(); i++) {
            Delete *del = new Delete(mNAManager, &mSettings);
            mRequests.insert(del);
            connect(del, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            del->deleteEvent(deleted[i]);
        }
    }
    storage->close();
    calendar->close();
}
QByteArray OpCancelBookingRequ::marshall()
{

    QByteArray serialized_data;
    QDataStream stream(&serialized_data, QIODevice::WriteOnly);
    stream << localRequestId();
    stream << leaveYear();
    stream << fromDate();
    stream << toDate();
    stream << firstDayHalf();
    stream << lastDayHalf();
    stream << dayHalf();
    stream << note();
    return serialized_data;
}