Пример #1
0
void
DiaryWindow::nextClicked()
{
#if 0
    switch (viewMode->currentIndex()) {
    case 0 : // monthly
        {
#endif
        int month = calendarModel->getMonth();
        int year = calendarModel->getYear();
        QDate when = QDate(year, month, 1).addMonths(1);
        calendarModel->setMonth(when.month(), when.year());
        title->setText(QString("%1 %2").arg(QDate::longMonthName(when.month())).arg(when.year()));
#if 0
        }
        break;
    case 1 : // weekly
        {
        QDateTime when = weeklyView->getStartTime();
        when = when.addDays(7);
        weeklyView->setDateRange(when.date(), when.addDays(6).date());
        weeklyView->setViewMode(QxtScheduleView::DayView);
        title->setText(QString("Week %1 %2").arg(when.date().weekNumber()).arg(when.date().year()));
        }
        break;
    }
#endif
}
Пример #2
0
void DateTimeGrid::paintMonthGrid( QPainter* painter,
                                  const QRectF& /*sceneRect*/,
                                  const QRectF& exposedRect,
                                  AbstractRowController* /*rowController*/,
                                  QWidget* widget )
{
    //qDebug()<<"paintMonthGrid()"<<scale()<<dayWidth();
    QDateTime dt = d->chartXtoDateTime( exposedRect.left() );
    dt.setTime( QTime( 0, 0, 0, 0 ) );
    dt = dt.addDays( 1 - dt.date().day() );
    for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) {
        QPen pen = painter->pen();
        pen.setBrush( QApplication::palette().dark() );
        if ( dt.date().addMonths( 1 ).month() == 1 && dt.date().addDays( 1 ).day() == 1 ) {
            pen.setStyle( Qt::SolidLine );
        } else if ( dt.date().addDays( 1 ).day() == 1 ) {
            pen.setStyle( Qt::DashLine );
        } else {
            pen.setStyle( Qt::NoPen );
        }
        painter->setPen( pen );
        paintFreeDay( painter, x, exposedRect, dt.date(), widget );
        if ( pen.style() != Qt::NoPen ) {
            //qDebug()<<"paintMonthGrid()"<<dt;
            x += dayWidth() - 1;
            painter->drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) );
        }
    }
}
void RollingFileAppender::computeFrequency()
{
  QMutexLocker locker(&m_rollingMutex);

  const QDateTime startTime(QDate(1999, 1, 1), QTime(0, 0));
  const QString startString = startTime.toString(m_datePatternString);

  if (startString != startTime.addSecs(60).toString(m_datePatternString))
    m_frequency = MinutelyRollover;
  else if (startString != startTime.addSecs(60 * 60).toString(m_datePatternString))
    m_frequency = HourlyRollover;
  else if (startString != startTime.addSecs(60 * 60 * 12).toString(m_datePatternString))
    m_frequency = HalfDailyRollover;
  else if (startString != startTime.addDays(1).toString(m_datePatternString))
    m_frequency = DailyRollover;
  else if (startString != startTime.addDays(7).toString(m_datePatternString))
    m_frequency = WeeklyRollover;
  else if (startString != startTime.addMonths(1).toString(m_datePatternString))
    m_frequency = MonthlyRollover;
  else
  {
    Q_ASSERT_X(false, "DailyRollingFileAppender::computeFrequency", "The pattern '%1' does not specify a frequency");
    return;
  }
}
Пример #4
0
void HouseKeeper::flushLogs()
{
    int numdays = gCoreContext->GetNumSetting("LogCleanDays", 14);
    int maxdays = gCoreContext->GetNumSetting("LogCleanMax", 30);

    QDateTime days = QDateTime::currentDateTime();
    days = days.addDays(0 - numdays);
    QDateTime max = QDateTime::currentDateTime();
    max = max.addDays(0 - maxdays);

    MSqlQuery result(MSqlQuery::InitCon());
    if (result.isConnected())
    {
        result.prepare("DELETE FROM mythlog WHERE "
                       "acknowledged=1 and logdate < :DAYS ;");
        result.bindValue(":DAYS", days);
        if (!result.exec())
            MythDB::DBError("HouseKeeper::flushLogs -- delete acknowledged",
                            result);

        result.prepare("DELETE FROM mythlog WHERE logdate< :MAX ;");
        result.bindValue(":MAX", max);
        if (!result.exec())
            MythDB::DBError("HouseKeeper::flushLogs -- delete old",
                            result);
    }
}
Пример #5
0
QStringList EventModel::getOccurrences(int range, QDate dateFrom)const
{
    int securityCounter = 1000;
    QStringList result;

    QDateTime tmpDateTime = dateTime;
    do
    {
        if ((tmpDateTime.date().daysTo(QDate::currentDate()) <=0) && (QDate::currentDate().daysTo(tmpDateTime.date()) <= range ))
        result.push_back(tmpDateTime.toString(dateTimeFormatString));
        switch(repeatPeriod)
        {
        case(1):
            tmpDateTime = tmpDateTime.addDays(repeatEvery);
            break;
        case(7):
            tmpDateTime = tmpDateTime.addDays(repeatEvery*7);
            break;
        case(30):
            tmpDateTime = tmpDateTime.addMonths(repeatEvery);
            break;
        case(0):
        default:
            break;
        }
        securityCounter--;

    } while ((securityCounter > 0) && (QDate::currentDate().daysTo(tmpDateTime.date()) <= range ) && (repeatPeriod!=0) );
    return result;
}
Пример #6
0
/**
 * @brief TTiming::addWallClockIntervalOptimized skips to long distances
 * @param actual
 * @param calculated
 * @return
 */
QDateTime TTiming::addWallClockIntervalOptimized(QDateTime actual, QDateTime calculated)
{
    if (wall_clock.period.years == 0)
        calculated = calculated.addYears(actual.date().year()-calculated.date().year()); // should give 0 on iterations
    else
        calculated = calculated.addYears(wall_clock.period.years);
    if (wall_clock.period.months == 0)
        calculated = calculated.addMonths(actual.date().month()-calculated.date().month());
    else
        calculated = calculated.addMonths(wall_clock.period.months);

    if (wall_clock.period.days == 0)
        calculated = calculated.addDays(actual.date().day()-calculated.date().day());
    else
        calculated = calculated.addDays(wall_clock.period.days);
    if (wall_clock.period.hours == 0)
        calculated = calculated.addSecs((actual.time().hour()-calculated.time().hour())*3600);
    else
        calculated = calculated.addSecs(wall_clock.period.hours*3600);
    if (wall_clock.period.minutes == 0)
        calculated = calculated.addSecs((actual.time().minute()-calculated.time().minute())*60);
    else
        calculated = calculated.addSecs(wall_clock.period.minutes*60);
    return calculated.addSecs(wall_clock.period.seconds);
}
 virtual QNetworkCacheMetaData metaData(const QUrl &url)
 {
     QNetworkCacheMetaData metaData;
     if (!cachedData.isEmpty()) {
         metaData.setUrl(url);
         QDateTime now = QDateTime::currentDateTime();
         metaData.setLastModified(now.addDays(-1));
         metaData.setExpirationDate(now.addDays(1));
         metaData.setSaveToDisk(true);
     }
     return metaData;
 }
Пример #8
0
void KOEditorFreeBusy::slotUpdateGanttView( const QDateTime &dtFrom, const QDateTime &dtTo )
{
  mDtStart = dtFrom;
  mDtEnd = dtTo;
  bool block = mGanttView->getUpdateEnabled( );
  mGanttView->setUpdateEnabled( false );
  QDateTime horizonStart = QDateTime( dtFrom.addDays( -15 ).date() );
  mGanttView->setHorizonStart( horizonStart  );
  mGanttView->setHorizonEnd( dtTo.addDays( 15 ) );
  mEventRectangle->setDateTimes( dtFrom, dtTo );
  mGanttView->setUpdateEnabled( block );
  mGanttView->centerTimelineAfterShow( dtFrom );
}
Пример #9
0
/*! Paints the week scale header.
 * \sa paintHeader()
 */
void DateTimeGrid::paintWeekScaleHeader( QPainter* painter,  const QRectF& headerRect, const QRectF& exposedRect,
                                        qreal offset, QWidget* widget )
{
    QStyle* style = widget?widget->style():QApplication::style();

    // Paint a section for each week
    QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() );
    sdt.setTime( QTime( 0, 0, 0, 0 ) );
    // Go backwards until start of week
    while ( sdt.date().dayOfWeek() != d->weekStart ) sdt = sdt.addDays( -1 );
    QDateTime dt = sdt;
    for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset;
            dt = dt.addDays( 7 ),x=d->dateTimeToChartX( dt ) ) {
        QStyleOptionHeader opt;
        opt.init( widget );
        opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*7, headerRect.height()/2. ).toRect();
        opt.text = QString::number( dt.date().weekNumber() );
        opt.textAlignment = Qt::AlignCenter;
        // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
        style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
        QStyleOptionHeader subopt = opt;
        subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
        if ( subopt.rect.isValid() ) {
            style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
        }
    }

    // Paint a section for each month
    dt = sdt;
    for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) {
        //qDebug()<<"paintWeekScaleHeader()"<<dt;
        QDate next = dt.date().addMonths( 1 );
        next = next.addDays( 1 - next.day() );

        QStyleOptionHeader opt;
        opt.init( widget );
        opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*dt.date().daysTo( next ), headerRect.height()/2. ).toRect();
        opt.text = QDate::longMonthName( dt.date().month() );
        opt.textAlignment = Qt::AlignCenter;
        // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
        style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
        QStyleOptionHeader subopt = opt;
        subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
        if ( subopt.rect.isValid() ) {
            style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
        }

        dt.setDate( next );
    }
}
Пример #10
0
qint64 timeUntilTomorrow()
{
    QDateTime now = QDateTime::currentDateTime();
    QDateTime tomorrow = now.addDays(1); // Tomorrow.
    tomorrow.setTime(QTime()); // Midnight.
    return now.msecsTo(tomorrow);
}
Пример #11
0
void EventEditTest::shouldHaveCorrectStartEndDateTime()
{
    MessageViewer::EventEdit edit;
    KMime::Message::Ptr msg(new KMime::Message);
    QString subject = QStringLiteral("Test Note");
    msg->subject(true)->fromUnicodeString(subject, "us-ascii");
    edit.setMessage(msg);

    QDateTime currentDateTime = QDateTime::currentDateTime();
    MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("startdatetimeedit"));
    startDateTime->setDateTime(currentDateTime);

    QDateTime endDt = currentDateTime.addDays(1);
    MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("enddatetimeedit"));
    endDateTime->setDateTime(endDt);

    QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
    QVERIFY(noteedit);
    QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
    QTest::keyClick(noteedit, Qt::Key_Enter);
    QCOMPARE(spy.count(), 1);
    KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value<KCalCore::Event::Ptr>();
    QVERIFY(eventPtr);
    QCOMPARE(eventPtr->dtStart().date(), currentDateTime.date());
    QCOMPARE(eventPtr->dtStart().time().hour(), currentDateTime.time().hour());
    QCOMPARE(eventPtr->dtStart().time().minute(), currentDateTime.time().minute());

    QCOMPARE(eventPtr->dtEnd().date(), endDt.date());
    QCOMPARE(eventPtr->dtEnd().time().hour(), endDt.time().hour());
    QCOMPARE(eventPtr->dtEnd().time().minute(), endDt.time().minute());
}
void interplanetaryDialog::on_buttonBox_accepted()
{
    // Create a new scenario
    SpaceScenario* scenario = new SpaceScenario();
    scenario->setName("This is a demo");

    ScenarioSC* sc = new ScenarioSC();
    sc->setName("my satellite demo");
    sc->ElementIdentifier()->setName("my satellite demo");

    // Create the initial position (Keplerian elements)
    ScenarioKeplerianElementsType* elements = new ScenarioKeplerianElementsType();
    elements->setSemiMajorAxis(87000.0);
    elements->setEccentricity(0.0045);
    elements->setInclination(27.456);
    elements->setRAAN(132.34);
    elements->setArgumentOfPeriapsis(231.34);
    elements->setTrueAnomaly(45.32);

    // Create the initial attitude (Euler elements)
    ScenarioEulerType*  initAtt = new ScenarioEulerType();
    initAtt->setPhi(0.00000);
    initAtt->setTheta(0.00000);
    initAtt->setPsi(0.00000);
    initAtt->setPhiDot(0.00000);
    initAtt->setThetaDot(0.00000);
    initAtt->setPsiDot(0.00000);

    // Create the trajectory arc
    ScenarioLoiteringType* loitering = new ScenarioLoiteringType();
    loitering->ElementIdentifier()->setName("loitering");
    loitering->ElementIdentifier()->setColorName("Yellow");
    loitering->Environment()->CentralBody()->setName("Earth");
    loitering->InitialPosition()->setCoordinateSystem("INERTIAL J2000");
    loitering->PropagationPosition()->setTimeStep(60.0);
    loitering->PropagationPosition()->setPropagator("TWO BODY");
    loitering->PropagationPosition()->setIntegrator("RK4");
    loitering->InitialAttitude()->setCoordinateSystem("EULER 123");
    loitering->PropagationAttitude()->setIntegrator("");	// Not defined in STA yet
    loitering->PropagationAttitude()->setTimeStep(60.0);

    // Time-line
    QDateTime TheCurrentDateAndTime = QDateTime::currentDateTime(); // Get the current epoch
    loitering->TimeLine()->setStartTime(TheCurrentDateAndTime);
    loitering->TimeLine()->setEndTime(TheCurrentDateAndTime.addDays(1));
    loitering->TimeLine()->setStepTime(60.0);

    loitering->InitialPosition()->setAbstract6DOFPosition(QSharedPointer<ScenarioAbstract6DOFPositionType>(elements));
    //loitering->InitialAttitude()->setAbstract6DOFAttitude(initAtt);
    loitering->InitialAttitude()->setAbstract6DOFAttitude(QSharedPointer<ScenarioAbstract6DOFAttitudeType>(initAtt));

    // Create the spacecraft
    sc->SCMission()->TrajectoryPlan()->AbstractTrajectory().append(QSharedPointer<ScenarioAbstractTrajectoryType>(loitering));

    // Add it to the scenario
    scenario->AbstractParticipant().append(QSharedPointer<ScenarioParticipantType>(sc));

    mainwindow->setScenario(scenario);
    return;
}
Пример #13
0
static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime)
{
    switch (jobHold) {
    case QCUPSSupport::Indefinite:
        return QStringLiteral("indefinite");
    case QCUPSSupport::DayTime:
        return QStringLiteral("day-time");
    case QCUPSSupport::Night:
        return QStringLiteral("night");
    case QCUPSSupport::SecondShift:
        return QStringLiteral("second-shift");
    case QCUPSSupport::ThirdShift:
        return QStringLiteral("third-shift");
    case QCUPSSupport::Weekend:
        return QStringLiteral("weekend");
    case QCUPSSupport::SpecificTime:
        if (!holdUntilTime.isNull()) {
            // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent
            QDateTime localDateTime = QDateTime::currentDateTime();
            // Check if time is for tomorrow in case of DST change overnight
            if (holdUntilTime < localDateTime.time())
                localDateTime = localDateTime.addDays(1);
            localDateTime.setTime(holdUntilTime);
            return localDateTime.toUTC().time().toString(QStringLiteral("HH:mm"));
        }
        // else fall through:
    case QCUPSSupport::NoHold:
        return QString();
    }
    Q_UNREACHABLE();
    return QString();
}
Пример #14
0
QDateTime TTiming::addWallClockInterval(QDateTime calculated)
{
    calculated = calculated.addYears(wall_clock.period.years);
    calculated = calculated.addMonths(wall_clock.period.months);
    calculated = calculated.addDays(wall_clock.period.days);
    return calculated.addSecs((wall_clock.period.hours*3600) + (wall_clock.period.minutes*60) + (wall_clock.period.seconds));
}
Пример #15
0
void DateVariable::update()
{
    QDateTime target;
    switch (m_type) {
    case Fixed:
        target = m_time;
        break;
    case AutoUpdate:
        target = QDateTime::currentDateTime();
        break;
    }
    target = target.addSecs(m_secsOffset);
    target = target.addDays(m_daysOffset);
    target = target.addMonths(m_monthsOffset);
    target = target.addYears(m_yearsOffset);
    switch (m_displayType) {
    case Custom:
        setValue(target.toString(m_definition));
        break;
    case Time:
        setValue(target.time().toString(Qt::LocalDate));
        break;
    case Date:
        setValue(target.date().toString(Qt::LocalDate));
        break;
    }
}
Пример #16
0
void plugin::calculate_next_periodic_timeout(const plugin::EventTimeStructure& ts) {
    QDateTime t;
    QDateTime datetime = QDateTime::currentDateTime();
    datetime.setTime ( ts.time );

    int dow = QDate::currentDate().dayOfWeek() - 1;
    int offsetdays = 0;

    // If it is too late for the alarm today then
    // try with the next weekday
    if ( QTime::currentTime() > ts.time ) {
        dow = ( dow+1 ) % 7;
        ++offsetdays;
    }

    // Search for the next activated weekday
    for ( ; offsetdays < 8; ++offsetdays ) {
        if ( ts.days.testBit(dow) ) break;
        dow = ( dow+1 ) % 7;
    }

    if ( offsetdays < 8 ) {
        addToEvents(datetime.addDays ( offsetdays ), ts);
    }
}
Пример #17
0
CreateProposalDialog::CreateProposalDialog(QWidget *parent) :
	QDialog(parent), ui(new Ui::CreateProposalDialog), model(0) {
	ui->setupUi(this);

#ifdef Q_WS_MAC // Icons on push buttons are very uncommon on Mac
	ui->addButton->setIcon(QIcon());
	ui->clearButton->setIcon(QIcon());
	ui->createButton->setIcon(QIcon());
#endif

	connect(ui->upgradeCheckbox, &QCheckBox::clicked, this, &CreateProposalDialog::updateUpgradeFields);
	connect(ui->spendPoolFundsCheckBox, &QCheckBox::clicked, this, &CreateProposalDialog::updateSpendPoolFields);
	connect(ui->addButton, &QPushButton::clicked, this, &CreateProposalDialog::addEntry);
	connect(ui->clearButton, &QPushButton::clicked, this, &CreateProposalDialog::clear);

	QDateTime minDateTime = QDateTime::currentDateTime().addSecs(MIN_PROPOSAL_DEADLINE_TIME + 1 * HOUR);
	QDateTime maxDateTime = minDateTime.addSecs(MAX_PROPOSAL_DEADLINE_TIME);

	//default 3 days later at 9 pm
	QDateTime defaultDateTime = minDateTime.addDays(3);

	defaultDateTime.setTime(QTime());//clear time
	defaultDateTime = defaultDateTime.addSecs(21 * HOUR);//set to 9 pm

	connect(ui->editDeadline, &QDateTimeEdit::dateTimeChanged, this, &CreateProposalDialog::updateLabelEditDeadline);

	ui->editDeadline->setDateTimeRange(minDateTime, maxDateTime);
	ui->editDeadline->setDateTime(defaultDateTime);

	updateUpgradeFields();
	updateSpendPoolFields();

}
Пример #18
0
//update the whole database in 30 days from today
bool updateDB(){
	//if not exist root directory then create
	QDir dbdir(".");
	dbdir.mkdir("Resources");

	QDateTime dt;
	QDate d;
	dt.setDate(d.currentDate());   //get current date
	QFileInfo dbfile;
	for(int x = 0; x < 31; x ++){
		QString date = dt.addDays(x).toString("yyyy-MM-dd");
		//qDebug() << date;
		dbfile.setFile("Resources\\" + date + ".xml");
		if(dbfile.exists())continue;     //check if data file existed
		else if(!createDB(date))return false;
	}

	//create user data file
	dbfile.setFile("Resources\\userDB.xml");
	if(!dbfile.exists()){
		QFile file("Resources\\userDB.xml");
		if(!file.open(QFile::WriteOnly | QFile::Text))return false;
		QDomDocument doc;
		QDomProcessingInstruction instruction;
		instruction = doc.createProcessingInstruction("xml","version=\"1.0\"");
		doc.appendChild(instruction);
		QDomElement root = doc.createElement("userIndex");
		doc.appendChild(root);
		QTextStream out(&file);
		doc.save(out,4);
		file.close();
	}

	return true;
}
Пример #19
0
void QgsDateTimeEdit::resetBeforeChange( int delta )
{
  QDateTime dt = QDateTime::currentDateTime();
  switch ( currentSection() )
  {
    case QDateTimeEdit::DaySection:
      dt = dt.addDays( delta );
      break;
    case QDateTimeEdit::MonthSection:
      dt = dt.addMonths( delta );
      break;
    case QDateTimeEdit::YearSection:
      dt = dt.addYears( delta );
      break;
    default:
      break;
  }
  if ( dt < minimumDateTime() )
  {
    dt = minimumDateTime();
  }
  else if ( dt > maximumDateTime() )
  {
    dt = maximumDateTime();
  }
  QDateTimeEdit::setDateTime( dt );
}
Пример #20
0
QString AttributeHelper::convertInitialValue( const DefinitionInfo& info, const QString& value ) const
{
    AttributeType type = toAttributeType( info );

    if ( ( type == TextAttribute || type == EnumAttribute || type == UserAttribute ) && value.startsWith( QLatin1String( "[Me]" ) ) )
        return dataManager->currentUserName();

    if ( type == DateTimeAttribute && value.startsWith( QLatin1String( "[Today]" ) ) ) {
        QDateTime date;
        if ( info.metadata( "local" ).toBool() )
            date = QDateTime::currentDateTime().toUTC();
        else
            date = QDateTime::currentDateTime();

        QString offset = value.mid( 7 );
        if ( !offset.isEmpty() )
            date = date.addDays( offset.toInt() );

        if ( info.metadata( "time" ).toBool() )
            return DateTimeHelper::formatDateTime( date );
        else
            return DateTimeHelper::formatDate( date.date() );
    }

    return value;
}
Пример #21
0
void CaBundleUpdater::start()
{
    QFile updateFile(m_lastUpdateFileName);
    bool updateNow = false;

    if (updateFile.exists()) {
        if (updateFile.open(QFile::ReadOnly)) {
            QDateTime updateTime = QDateTime::fromString(updateFile.readAll());
            updateNow = updateTime.addDays(5) < QDateTime::currentDateTime();
        }
        else {
            qWarning() << "CaBundleUpdater::start cannot open file for reading" << m_lastUpdateFileName;
        }
    }
    else {
        updateNow = true;
    }

    if (updateNow) {
        m_progress = CheckLastUpdate;

        QUrl url = QUrl::fromEncoded(QString(Qz::WWWADDRESS + QL1S("/certs/bundle_version")).toUtf8());
        m_reply = m_manager->get(QNetworkRequest(url));
        connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
    }
}
Пример #22
0
void QGeoMapReplyNokia::networkFinished()
{
    if (!m_reply)
        return;

    if (m_reply->error() != QNetworkReply::NoError)
        return;

    QVariant fromCache = m_reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
    setCached(fromCache.toBool());

    if (!isCached()) {
        QAbstractNetworkCache *cache = m_reply->manager()->cache();
        if (cache) {
            QNetworkCacheMetaData metaData = cache->metaData(m_reply->url());
            QDateTime exp = QDateTime::currentDateTime();
            exp = exp.addDays(14);
            metaData.setExpirationDate(exp);
            cache->updateMetaData(metaData);
        }
    }

    setMapImageData(m_reply->readAll());
    setMapImageFormat("PNG");
    setFinished(true);

    m_reply->deleteLater();
    m_reply = 0;
}
Пример #23
0
void MainWindow::slotDoFind( const QString& txt, const QDate &dt,
               bool caseSensitive, bool /*backwards*/,
               int category )
{
    // if true at the end we will start at the begin again and afterwards
    // we will emit string not found
    static bool wrapAround = true;
    static QDateTime startdt;

    if ( !m_inSearch ) {
        startdt = QDateTime( dt, QTime(0,0,0) );
        m_inSearch = true;
    }

    OPimEvent ev = manager()->find( txt, caseSensitive, startdt );
    if ( ev.uid() != 0 ) {
//X        dayView->setStartViewTime( dtEnd.time().hour() );
        currentView()->showDay( startdt.date() );
        startdt = startdt.addDays(1);
    }
    else {
        if ( wrapAround ) {
            emit signalFindWrapAround();
            startdt = QDateTime();
        }
        else
            emit signalFindNotFound();
        wrapAround = !wrapAround;
    }
}
void OldDataDeleter::slotCleanUp()
{
    qDebug() << Q_FUNC_INFO << "START";

    QDateTime currentDate = QDateTime::currentDateTime();
    QDateTime removalDate = currentDate.addDays(REMOVAL_TARGET_DAYS);

    int cleanUpInterval = DAYS_TO_MS(CLEANUP_PERIOD_DAYS);

    qDebug() << Q_FUNC_INFO << "Cleanup interval: " << cleanUpInterval;

    m_pCleanUpTimer->setInterval(cleanUpInterval);

    if (!m_pCallModel) {
        m_pCallModel = new AccountSpecificCallModel(this);
        m_pCallModel->setPropertyMask(CommHistory::Event::PropertySet()
                                      << CommHistory::Event::Type);

        connect(m_pCallModel,
                SIGNAL(modelReady(bool)),
                this,
                SLOT(slotDeleteCalls()),
                Qt::UniqueConnection);

        connect(m_pCallModel,
                SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
                this,
                SLOT(slotRowsRemoved(const QModelIndex&,int,int)),
                Qt::UniqueConnection);
    }
Пример #25
0
bool StatisticEmailSender::checkSend(DBConn *conn) const
{
	QDateTime time = QDateTime::currentDateTime();
	time = time.addDays(-2);

	QString sql =
			"SELECT count(*)"
				" FROM email_history"
				" WHERE type = ? AND ddate > ?";

	QSqlQuery q(conn->qtDatabase());
	q.prepare(sql);
	q.bindValue(0, 1);
	q.bindValue(1, time);

	bool res = conn->executeQuery(q);
	if ( (res == true) && (q.isActive()) )
	{
		if (q.next() == true)
		{
			res = q.value(0).toInt() == 0;
		}
	}
	return res;
}
void RBDtoWeatherDialog::processDay(QDateTime date)
{
    QDateTime dates;
    dates.setDate(date.date());
    if(date.time() > QTime(21, 0)){
        dates = dates.addDays(1);
        dates.setTime(QTime(0, 0));
    }else{
        if(date.time() <= QTime(3, 0)) dates.setTime(QTime(0, 0));
        if(date.time() > QTime(3, 0) && date.time() <= QTime(9, 0)) dates.setTime(QTime(6, 0));
        if(date.time() > QTime(9, 0) && date.time() <= QTime(15, 0)) dates.setTime(QTime(12, 0));
        if(date.time() > QTime(15, 0) && date.time() <= QTime(21, 0)) dates.setTime(QTime(18, 0));
    };

    QSqlQuery insert;
    QSqlQuery select;

    select.exec(QString("SELECT * FROM tiempos WHERE fecha = '%1'").arg(dates.toString("yyyy-MM-dd hh:mm:ss")));
    qDebug() << select.lastQuery() << select.lastError();
    if(select.next()){
        insert.exec(QString("UPDATE estadotiempos SET maxima = %1, minima = %2, vientovel = %3, direccionviento = %4"
                            ", precipitacion = %5, mil500 = %6 WHERE fecha LIKE '%7'")
                    .arg(select.record().field("maxima").value().toDouble())
                    .arg(select.record().field("minima").value().toDouble())
                    .arg(select.record().field("vientovel").value().toDouble())
                    .arg(select.record().field("direccionviento").value().toDouble())
                    .arg(select.record().field("precipitacion").value().toInt())
                    .arg(select.record().field("mil500").value().toInt())
                    .arg(date.toString("yyyy-MM-dd hh:mm:ss"))
                    );
        qDebug() << insert.lastQuery() << insert.lastError();
    };
}
void DateTimePickerRecipe::onValueChanged(QDateTime value)
{
    QDateTime today = QDateTime::currentDateTime();

    // We compare the date that is set on the Picker to the current date and set different
    // images depending on how far in the future (or past) that date is.
    if (value < today.addDays(-1)) {
        mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_past.png"));
    } else if (value >= today.addDays(-1) && value <= today.addDays(3)) {
        mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_new.png"));
    } else if ( value < today.addMonths(1) ) {
        mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_old.png"));
    } else {
        mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_ancient.png"));
    }
}
Пример #28
0
/*! Paints the day scale header.
 * \sa paintHeader()
 */
void DateTimeGrid::paintDayScaleHeader( QPainter* painter,  const QRectF& headerRect, const QRectF& exposedRect,
                                qreal offset, QWidget* widget )
{
    // For starters, support only the regular tab-per-day look
    QStyle* style = widget?widget->style():QApplication::style();

    // Paint a section for each day
    QDateTime dt = d->chartXtoDateTime( offset+exposedRect.left() );
    dt.setTime( QTime( 0, 0, 0, 0 ) );
    for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset;
          dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) {
        QStyleOptionHeader opt;
        opt.init( widget );
        opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth(), headerRect.height()/2. ).toRect();
        opt.text = dt.toString( QString::fromAscii( "ddd" ) ).left( 1 );
        opt.textAlignment = Qt::AlignCenter;
        // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
        style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
        QStyleOptionHeader subopt = opt;
        subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
        if ( subopt.rect.isValid() ) {
            style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
        }
    }

    dt = d->chartXtoDateTime( offset+exposedRect.left() );
    dt.setTime( QTime( 0, 0, 0, 0 ) );
    // Go backwards until start of week
    while ( dt.date().dayOfWeek() != d->weekStart ) dt = dt.addDays( -1 );
    // Paint a section for each week
    for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset;
          dt = dt.addDays( 7 ),x2=d->dateTimeToChartX( dt ) ) {
        QStyleOptionHeader opt;
        opt.init( widget );
        opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*7., headerRect.height()/2. ).toRect();
        opt.text = QString::number( dt.date().weekNumber() );
        opt.textAlignment = Qt::AlignCenter;
        // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
        style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
        QStyleOptionHeader subopt = opt;
        subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
        if ( subopt.rect.isValid() ) {
            style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
        }
    }
}
Пример #29
0
void Validity::setDiff(const Validity *start, int number, int range)
{
	QDateTime dt = start->dateTime();

	switch (range) {
		case 0: dt = dt.addDays(number); break;
		case 1: dt = dt.addMonths(number); break;
		case 2: dt = dt.addYears(number); break;
	}

	// one day less if we go from 0:00:00 to 23:59:59
	if (midnight)
		dt = dt.addDays(-1);

	setDateTime(dt);
	mytime = start->mytime;
}
void SchedulerJobInstance::calculateNextRunTime() const {
	QDateTime nextRun = runTimeToday();

	nextRun.setDate(QDate::currentDate().addDays( (weekday() + 1) - QDate::currentDate().dayOfWeek() ));
	if (nextRun < QDateTime::currentDateTime()) {
		nextRun = nextRun.addDays(7);
	}
	d->nextRunTime = nextRun;
}