Commit e39eee72 authored by David Jarvie's avatar David Jarvie
Browse files

Bug 336942 part 1: Reset internal data when Akonadi server restarts

When the Akonadi server restarts, internal data needs to be reset. In
particular, the FavoriteCollectionsModel collections list needs to be
cleared.

Alarms still don't show up after a server restart - changing Lazy
population to Immediate population fixes this, but is not desirable.
parent e275dff2
......@@ -128,9 +128,7 @@ AkonadiModel::AkonadiModel(ChangeRecorder* monitor, QObject* parent)
#endif
connect(monitor, SIGNAL(collectionChanged(Akonadi::Collection,QSet<QByteArray>)), SLOT(slotCollectionChanged(Akonadi::Collection,QSet<QByteArray>)));
connect(monitor, SIGNAL(collectionRemoved(Akonadi::Collection)), SLOT(slotCollectionRemoved(Akonadi::Collection)));
connect(CalendarMigrator::instance(), SIGNAL(creating(QString,Akonadi::Collection::Id,bool)),
SLOT(slotCollectionBeingCreated(QString,Akonadi::Collection::Id,bool)));
connect(CalendarMigrator::instance(), SIGNAL(destroyed(QObject*)), SLOT(slotMigrationCompleted()));
initCalendarMigrator();
MinuteTimer::connect(this, SLOT(slotUpdateTimeTo()));
Preferences::connect(SIGNAL(archivedColourChanged(QColor)), this, SLOT(slotUpdateArchivedColour(QColor)));
Preferences::connect(SIGNAL(disabledColourChanged(QColor)), this, SLOT(slotUpdateDisabledColour(QColor)));
......@@ -153,22 +151,54 @@ AkonadiModel::~AkonadiModel()
}
/******************************************************************************
* Called when the server manager is running, i.e. the agent manager knows about
* Called when the server manager changes state.
* If it is now running, i.e. the agent manager knows about
* all existing resources.
* Once it is running, if necessary migrate any KResources alarm calendars from
* Once it is running, i.e. the agent manager knows about
* all existing resources, if necessary migrate any KResources alarm calendars from
* pre-Akonadi versions of KAlarm, or create default Akonadi calendar resources
* if any are missing.
*/
void AkonadiModel::checkResources(ServerManager::State state)
{
if (!mResourcesChecked && state == ServerManager::Running)
switch (state)
{
mResourcesChecked = true;
mMigrating = true;
CalendarMigrator::execute();
case ServerManager::Running:
if (!mResourcesChecked)
{
kDebug() << "Server running";
mResourcesChecked = true;
mMigrating = true;
CalendarMigrator::execute();
}
break;
case ServerManager::NotRunning:
kDebug() << "Server stopped";
mResourcesChecked = false;
mMigrating = false;
mCollectionAlarmTypes.clear();
mCollectionRights.clear();
mCollectionEnabled.clear();
initCalendarMigrator();
emit serverStopped();
break;
default:
break;
}
}
/******************************************************************************
* Initialise the calendar migrator so that it can be run (either for the first
* time, or again).
*/
void AkonadiModel::initCalendarMigrator()
{
CalendarMigrator::reset();
connect(CalendarMigrator::instance(), SIGNAL(creating(QString,Akonadi::Collection::Id,bool)),
SLOT(slotCollectionBeingCreated(QString,Akonadi::Collection::Id,bool)));
connect(CalendarMigrator::instance(), SIGNAL(destroyed(QObject*)), SLOT(slotMigrationCompleted()));
}
/******************************************************************************
* Return whether calendar migration has completed.
*/
......@@ -1654,13 +1684,13 @@ void AkonadiModel::setCollectionChanged(const Collection& collection, const QSet
// Check for the collection being enabled/disabled
if (attributeNames.contains(CollectionAttribute::name()))
{
static bool first = true;
static bool firstEnabled = true;
const CalEvent::Types oldEnabled = mCollectionEnabled.value(collection.id(), CalEvent::EMPTY);
const CalEvent::Types newEnabled = collection.hasAttribute<CollectionAttribute>() ? collection.attribute<CollectionAttribute>()->enabled() : CalEvent::EMPTY;
if (first || newEnabled != oldEnabled)
if (firstEnabled || newEnabled != oldEnabled)
{
kDebug() << "Collection" << collection.id() << ": enabled ->" << newEnabled;
first = false;
firstEnabled = false;
mCollectionEnabled[collection.id()] = newEnabled;
emit collectionStatusChanged(collection, Enabled, static_cast<int>(newEnabled), rowInserted);
}
......
......@@ -244,6 +244,9 @@ class AkonadiModel : public Akonadi::EntityTreeModel
/** Signal emitted when calendar migration/creation has completed. */
void migrationCompleted();
/** Signal emitted when the Akonadi server has stopped. */
void serverStopped();
protected:
virtual QVariant entityHeaderData(int section, Qt::Orientation, int role, HeaderGroup) const;
virtual int entityColumnCount(HeaderGroup) const;
......@@ -291,6 +294,7 @@ class AkonadiModel : public Akonadi::EntityTreeModel
};
AkonadiModel(Akonadi::ChangeRecorder*, QObject* parent);
void initCalendarMigrator();
KAEvent event(const Akonadi::Item&, const QModelIndex&, Akonadi::Collection*) const;
void signalDataChanged(bool (*checkFunc)(const Akonadi::Item&), int startColumn, int endColumn, const QModelIndex& parent);
void setCollectionChanged(const Akonadi::Collection&, const QSet<QByteArray>&, bool rowInserted);
......
......@@ -147,6 +147,14 @@ CalendarMigrator::~CalendarMigrator()
mInstance = 0;
}
/******************************************************************************
* Reset to allow migration to be run again.
*/
void CalendarMigrator::reset()
{
mCompleted = false;
}
/******************************************************************************
* Create and return the unique CalendarMigrator instance.
*/
......
......@@ -45,6 +45,7 @@ class CalendarMigrator : public QObject
public:
~CalendarMigrator();
static CalendarMigrator* instance();
static void reset();
static void execute();
static void updateToCurrentFormat(const Akonadi::Collection&, bool ignoreKeepFormat, QWidget* parent);
static bool completed() { return mCompleted; }
......
......@@ -677,6 +677,7 @@ CollectionControlModel::CollectionControlModel(QObject* parent)
connect(AkonadiModel::instance(), SIGNAL(collectionPopulated(Akonadi::Collection::Id)),
SLOT(collectionPopulated()));
#endif
connect(AkonadiModel::instance(), SIGNAL(serverStopped()), SLOT(reset()));
}
/******************************************************************************
......@@ -1299,6 +1300,20 @@ bool CollectionControlModel::waitUntilPopulated(Collection::Id colId, int timeou
}
#endif
/******************************************************************************
* Called when the Akonadi server has stopped. Reset the model.
*/
void CollectionControlModel::reset()
{
delete mPopulatedCheckLoop;
mPopulatedCheckLoop = 0;
// Clear the collections list. This is required because addCollection() or
// setCollections() don't work if the collections which they specify are
// already in the list.
setCollections(Collection::List());
}
/******************************************************************************
* Exit from the populated event loop when a collection has been populated.
*/
......
......@@ -286,6 +286,7 @@ class CollectionControlModel : public Akonadi::FavoriteCollectionsModel
static QString typeListForDisplay(CalEvent::Types);
private slots:
void reset();
void statusChanged(const Akonadi::Collection&, AkonadiModel::Change, const QVariant& value, bool inserted);
void collectionPopulated();
......
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