Commit ee76d1ea authored by Sergio Martins's avatar Sergio Martins
Browse files

When dismissing an alarm, check if it's in config and remove it from there too.

Otherwise it will popup when you restart korgac.
Fixes kolab/issue4382
MERGE: trunk
(cherry picked from commit ba29b5af)

Conflicts:

	korganizer/korgac/alarmdialog.cpp
	korganizer/korgac/alarmdialog.h
parent fe0f8a9d
......@@ -91,6 +91,12 @@ class ReminderListItem : public QTreeWidgetItem
bool mNotified;
};
struct ConfItem {
QString uid;
KUrl akonadiUrl;
QDateTime remindAt;
};
bool ReminderListItem::operator<( const QTreeWidgetItem &other ) const
{
switch( treeWidget()->sortColumn() ) {
......@@ -395,6 +401,7 @@ void AlarmDialog::dismissAll()
void AlarmDialog::dismiss( ReminderList selections )
{
QList<Akonadi::Item::Id> ids;
for ( ReminderList::Iterator it = selections.begin(); it != selections.end(); ++it ) {
kDebug() << "removing " << CalendarSupport::incidence( (*it)->mIncidence )->summary();
if ( mIncidenceTree->itemBelow( *it ) ) {
......@@ -403,8 +410,11 @@ void AlarmDialog::dismiss( ReminderList selections )
mIncidenceTree->setCurrentItem( mIncidenceTree->itemAbove( *it ) );
}
mIncidenceTree->removeItemWidget( *it, 0 );
ids.append( (*it)->mIncidence.id() );
delete *it;
}
removeFromConfig( ids );
}
void AlarmDialog::edit()
......@@ -928,4 +938,44 @@ bool AlarmDialog::openIncidenceEditorNG( const Akonadi::Item &item )
return true;
}
void AlarmDialog::removeFromConfig( const QList<Akonadi::Item::Id> &ids )
{
KSharedConfig::Ptr config = KGlobal::config();
KConfigGroup genGroup( config, "General" );
const int oldNumReminders = genGroup.readEntry( "Reminders", 0 );
QList<ConfItem> newReminders;
// Delete everything
for ( int i = 1; i <= oldNumReminders; ++i ) {
const QString group( QString( "Incidence-%1" ).arg( i ) );
KConfigGroup incGroup( config, group );
const QString uid = incGroup.readEntry( "UID" );
const QDateTime remindAtDate = incGroup.readEntry( "RemindAt", QDateTime() );
const KUrl akonadiUrl = incGroup.readEntry( "AkonadiUrl" );
const Akonadi::Item::Id id = Akonadi::Item::fromUrl( akonadiUrl ).id();
if ( !ids.contains( id ) ) {
ConfItem ci;
ci.akonadiUrl = akonadiUrl;
ci.remindAt = remindAtDate;
ci.uid = uid;
newReminders.append( ci );
}
config->deleteGroup( group );
}
genGroup.writeEntry( "Reminders", newReminders.count() );
//Write everything except those which have an uid we dont want
for ( int i = 0; i < newReminders.count(); ++i ) {
const QString group( QString( "Incidence-%1" ).arg( i + 1 ) );
KConfigGroup incGroup( config, group );
incGroup.writeEntry( "UID", newReminders[i].uid );
incGroup.writeEntry( "RemindAt", newReminders[i].remindAt );
incGroup.writeEntry( "AkonadiUrl", newReminders[i].akonadiUrl );
incGroup.sync();
}
genGroup.sync();
}
#include "alarmdialog.moc"
......@@ -24,8 +24,9 @@
#ifndef ALARMDIALOG_H
#define ALARMDIALOG_H
#include <KDialog>
#include <Akonadi/Item>
#include <KDialog>
#include <KCalCore/Incidence>
#include <KDateTime>
......@@ -102,6 +103,9 @@ class AlarmDialog : public KDialog
const QDateTime &reminderAt,
QString &displayStr );
// Removes each Incidence-X group that has one of the specified uids
void removeFromConfig( const QList<Akonadi::Item::Id> & );
// Opens through dbus, @deprecated
bool openIncidenceEditorThroughKOrganizer( const KCalCore::Incidence::Ptr &incidence );
......
......@@ -117,11 +117,11 @@ KOAlarmClient::KOAlarmClient( QObject *parent )
const KUrl url = incGroup.readEntry( "AkonadiUrl" );
Akonadi::Item::Id akonadiItemId = -1;
if( ! url.isValid() ) {
if ( !url.isValid() ) {
// logic to migrate old KOrganizer incidence uid's to a Akonadi item.
const QString uid = incGroup.readEntry( "UID" );
if( ! uid.isEmpty() ) {
akonadiItemId = mCalendar->itemIdForIncidenceUid(uid);
if ( !uid.isEmpty() ) {
akonadiItemId = mCalendar->itemIdForIncidenceUid( uid );
}
} else {
akonadiItemId = Akonadi::Item::fromUrl( url ).id();
......
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