Commit d1d99767 authored by Frank Roscher's avatar Frank Roscher
Browse files

Fix saving and loading of suspended reminders in KOrganizer

We need to wait for all collections to be available when restoring
reminders at startup, or they won't get loaded properly. Additionally,
we must delete reminders one by one as they are dismissed instead of
just cleaning out the config file after each startup.

BUG: 280321
FIXED-IN: 4.10
CCBUG: 146336
CCBUG: 180413
CCBUG: 302865
REVIEW: 107546
parent 68102027
......@@ -414,8 +414,7 @@ void AlarmDialog::dismiss( ReminderList selections )
delete *it;
}
// TODO 4.7: enable and test this
//removeFromConfig( ids );
removeFromConfig( ids );
}
void AlarmDialog::edit()
......@@ -697,7 +696,7 @@ void AlarmDialog::slotSave()
{
KSharedConfig::Ptr config = KGlobal::config();
KConfigGroup generalConfig( config, "General" );
int numReminders = generalConfig.readEntry( "Reminders", 0 );
int numReminders = 0;
QTreeWidgetItemIterator it( mIncidenceTree );
while ( *it ) {
......
......@@ -103,18 +103,40 @@ KOAlarmClient::KOAlarmClient( QObject *parent )
connect( &mCheckTimer, SIGNAL(timeout()), SLOT(checkAlarms()) );
connect( mCalendarModel, SIGNAL(collectionPopulated(Akonadi::Collection::Id)),
SLOT(checkAlarms()) );
SLOT(deferredInit()) );
connect( mCalendarModel, SIGNAL(collectionTreeFetched(Akonadi::Collection::List)),
SLOT(checkAlarms()) );
SLOT(deferredInit()) );
KConfigGroup alarmGroup( KGlobal::config(), "Alarms" );
const int interval = alarmGroup.readEntry( "Interval", 60 );
kDebug() << "KOAlarmClient check interval:" << interval << "seconds.";
mLastChecked = alarmGroup.readEntry( "CalendarsLastChecked", QDateTime() );
checkAlarms();
mCheckTimer.start( 1000 * interval ); // interval in seconds
}
KOAlarmClient::~KOAlarmClient()
{
delete mCalendar;
#if !defined(KORGAC_AKONADI_AGENT)
delete mDocker;
delete mDialog;
#endif
}
void KOAlarmClient::deferredInit()
{
if ( !collectionsAvailable() ) {
return;
}
kDebug(5891) << "Performing delayed initialization.";
// load reminders that were active when quitting
KConfigGroup genGroup( KGlobal::config(), "General" );
const int numReminders = genGroup.readEntry( "Reminders", 0 );
for ( int i=1; i<=numReminders; ++i ) {
const QString group( QString( "Incidence-%1" ).arg( i ) );
const KConfigGroup incGroup( KGlobal::config(), group );
......@@ -140,23 +162,11 @@ KOAlarmClient::KOAlarmClient( QObject *parent )
}
}
}
if ( numReminders ) {
genGroup.writeEntry( "Reminders", 0 );
genGroup.sync();
}
// Now that everything is set up, a first check for reminders can be performed.
checkAlarms();
mCheckTimer.start( 1000 * interval ); // interval in seconds
}
KOAlarmClient::~KOAlarmClient()
{
delete mCalendar;
#if !defined(KORGAC_AKONADI_AGENT)
delete mDocker;
delete mDialog;
#endif
}
bool KOAlarmClient::dockerEnabled()
{
......@@ -165,22 +175,15 @@ bool KOAlarmClient::dockerEnabled()
return generalGroup.readEntry( "ShowReminderDaemon", true );
}
void KOAlarmClient::checkAlarms()
{
KConfigGroup cfg( KGlobal::config(), "General" );
if ( !cfg.readEntry( "Enabled", true ) ) {
return;
}
// We do not want to miss any reminders, so don't perform check unless
// the list of collections is available.
bool KOAlarmClient::collectionsAvailable()
{
// The list of collections must be available.
if ( !mCalendarModel->isCollectionTreeFetched() ) {
kDebug(5891) << "CollectionTree has not been fetched yet; aborting check.";
return;
return false;
}
// Collections also need to be populated if we want to be sure not to miss any reminders.
// All collections must be populated.
const int rowCount = mCalendarModel->rowCount();
for ( int row = 0; row < rowCount; ++row ) {
static const int column = 0;
......@@ -188,11 +191,29 @@ void KOAlarmClient::checkAlarms()
bool haveData =
mCalendarModel->data( index, CalendarSupport::CalendarModel::IsPopulatedRole ).toBool();
if ( !haveData ) {
kDebug(5891) << "Collections have not been populated yet; aborting check.";
return;
return false;
}
}
return true;
}
void KOAlarmClient::checkAlarms()
{
KConfigGroup cfg( KGlobal::config(), "General" );
if ( !cfg.readEntry( "Enabled", true ) ) {
return;
}
// We do not want to miss any reminders, so don't perform check unless
// the collections are available and populated.
if ( !collectionsAvailable() ) {
kDebug(5891) << "Collections are not available; aborting check.";
return;
}
QDateTime from = mLastChecked.addSecs( 1 );
mLastChecked = QDateTime::currentDateTime();
......
......@@ -72,6 +72,7 @@ class KOAlarmClient : public QObject
void slotQuit();
protected slots:
void deferredInit();
void checkAlarms();
signals:
......@@ -80,6 +81,7 @@ class KOAlarmClient : public QObject
private:
bool dockerEnabled();
bool collectionsAvailable();
void createReminder( CalendarSupport::Calendar *calendar, const Akonadi::Item &incidence,
const QDateTime &dt, const QString &displayText );
void saveLastCheckTime();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment