From 858b047efb5627824438cb3877e7bec0cebb3751 Mon Sep 17 00:00:00 2001 From: zautrix Date: Fri, 03 Jun 2005 23:10:45 +0000 Subject: fixxx --- (limited to 'korganizer/calendarview.cpp') diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 503ef12..36db9c4 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -138,6 +138,124 @@ extern int globalFlagBlockAgenda; extern int globalFlagBlockStartup; +MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList alarms,QDateTime start ) : QTextBrowser(parent) + +{ + mAlarms = alarms; + setBackgroundColor( QColor( 86, 153, 205 ) ); + QString mText = "\n"; + //mText += "\n\n\n

"; +#ifdef DESKTOP_VERSION + mText += "

"; +#else + mText += "

"; +#endif + // mText += ""; + //mEventDate = QDate::currentDate(); +#ifdef DESKTOP_VERSION + mText += " " + i18n("You missed the alarms for the following events or todos:")+"

"; +#else + mText += " " + i18n("You missed the alarms for the following events or todos:")+""; +#endif + mText += "
"; + + Incidence * inc = getNextInc( start ); + int time = 0; + mText += ""; + while ( inc ) { + QDateTime dt ; + QString tempText = "getNextOccurence( start, &ok ); + if ( !ok ) continue; + if ( inc->type() == "Event" ) { + tempText += "href=\"event:"; + } else if ( inc->type() == "Todo" ) { + tempText += "href=\"todo:"; + } + tempText += inc->uid() + "\">"; + if ( inc->type() == "Todo" ) + tempText += i18n("Todo: "); + if ( inc->summary().length() > 0 ) + tempText += inc->summary(); + else + tempText += i18n("-no summary-"); + QString timestr; + if (!inc->doesFloat()) + timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; + else + timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; + if ( dt.date() == QDate::currentDate() && time == 0 ) { + time = 1; + mText +="
"; + mText += "
"; + mText += ""; + + } + if ( dt.date() > QDate::currentDate() && time != 2 ) { + time = 2; + mText +="
"; + mText += "
"; + mText += ""; + } + mText +="\n"; + inc = getNextInc( start ); + } + mText +="
"; + mText += timestr; + mText += ""; + mText += tempText; + mText += "
"; + setText( mText ); +} + +Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) +{ + QDateTime dt ; + Incidence * retInc; + Incidence * inc = mAlarms.first(); + if ( inc == 0 ) + return 0; + bool ok; + dt = inc->getNextOccurence( start, &ok ); + if ( ! ok ) return 0; + QDateTime dtn ; + retInc = inc; + inc = mAlarms.next(); + while ( inc ) { + dtn = inc->getNextOccurence( start, &ok ); + if ( ! ok ) return 0; + if ( dtn < dt ) { + dt = dtn; + retInc = inc; + } + inc = mAlarms.next(); + } + mAlarms.remove( retInc ); + return retInc; + +} +void MissedAlarmTextBrowser::setSource(const QString & n) +{ + if (n.startsWith("event:")) { +#ifdef DESKTOP_VERSION + emit showIncidence(n.mid(8)); +#else + emit showIncidence(n.mid(6)); +#endif + return; + } else if (n.startsWith("todo:")) { +#ifdef DESKTOP_VERSION + emit showIncidence(n.mid(7)); +#else + emit showIncidence(n.mid(5)); +#endif + return; + } +} + class KOBeamPrefs : public QDialog { @@ -506,7 +624,45 @@ CalendarView::~CalendarView() delete mEventViewerDialog; //kdDebug() << "~CalendarView() done" << endl; } +void CalendarView::checkAlarms() +{ + KConfig *config = KOGlobals::config(); + config->setGroup( "AppRun" ); + QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); + int secs = config->readNumEntry( "LatestProgramStop" ) - 30; + //secs -= ( 3600 * 24*3 ); // debug only + QDateTime latest = dt.addSecs ( secs ); + qDebug("KO: Last termination on %s ", latest.toString().latin1()); + QPtrList el = mCalendar->rawIncidences(); + QPtrList al; + Incidence* inL = el.first(); + while ( inL ) { + bool ok = false; + int offset = 0; + QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; + if ( ok ) { + //qDebug("OK %s",next.toString().latin1()); + if ( next < QDateTime::currentDateTime() ) { + al.append( inL ); + qDebug("found missed alarm: %s ", inL->summary().latin1() ); + } + } + inL = el.next(); + } + if ( al.count() ) { + QDialog dia ( this, "huhu", true ); + dia.setCaption( i18n("KO/Pi: Missing alarm notification!") ); + QVBoxLayout* lay = new QVBoxLayout( &dia ); + lay->setSpacing( 3 ); + lay->setMargin( 3 ); + MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( &dia, al, latest ); + connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); + lay->addWidget( matb ); + dia.resize(240,240); + dia.exec(); + } +} void CalendarView::showDay( QDate d ) { dateNavigator()->blockSignals( true ); @@ -1969,7 +2125,9 @@ void CalendarView::writeSettings() KOPrefs::instance()->writeConfig(); writeFilterSettings(config); - + config->setGroup( "AppRun" ); + QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); + config->writeEntry( "LatestProgramStop", dt.secsTo( QDateTime::currentDateTime() ) ); config->setGroup( "Views" ); config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); @@ -3921,7 +4079,12 @@ void CalendarView::deleteIncidence() deleteIncidence(incidence); } } - +void CalendarView::showIncidence(QString uid) +{ + Incidence *inc = mCalendar->incidence( uid ); + if ( inc ) + showIncidence( inc ); +} void CalendarView::showIncidence(Incidence *incidence) { mViewerCallerIsSearchDialog = false; -- cgit v0.9.0.2