Commit 35aaf644 authored by David Jarvie's avatar David Jarvie
Browse files

Move migration status to base class; CamelCase headers

parent 12e77242
......@@ -20,32 +20,28 @@
#include "akonadimodel.h"
#include "alarmtime.h"
#include "autoqpointer.h"
#include "calendarmigrator.h"
#include "mainwindow.h"
#include "preferences.h"
#include "synchtimer.h"
#include "resources/resources.h"
#include "kalarmsettings.h"
#include "kalarmdirsettings.h"
#include "kalarm_debug.h"
#include <kalarmcal/alarmtext.h>
#include <kalarmcal/compatibilityattribute.h>
#include <kalarmcal/eventattribute.h>
#include <AkonadiCore/agentfilterproxymodel.h>
#include <AkonadiCore/agentinstancecreatejob.h>
#include <AkonadiCore/agentmanager.h>
#include <AkonadiCore/agenttype.h>
#include <AkonadiCore/attributefactory.h>
#include <AkonadiCore/changerecorder.h>
#include <AkonadiCore/collectiondeletejob.h>
#include <AkonadiCore/collectionfetchjob.h>
#include <AkonadiCore/entitydisplayattribute.h>
#include <AkonadiCore/item.h>
#include <AkonadiCore/itemfetchscope.h>
#include <AkonadiWidgets/agenttypedialog.h>
#include <AkonadiCore/AgentFilterProxyModel>
#include <AkonadiCore/AgentInstanceCreateJob>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/AgentType>
#include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/ChangeRecorder>
#include <AkonadiCore/CollectionDeleteJob>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/Item>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiWidgets/AgentTypeDialog>
#include <KLocalizedString>
#include <KColorUtils>
......@@ -54,7 +50,6 @@
#include <QApplication>
#include <QFileInfo>
#include <QTimer>
#include "kalarm_debug.h"
using namespace Akonadi;
using namespace KAlarmCal;
......@@ -88,8 +83,6 @@ AkonadiModel::AkonadiModel(ChangeRecorder* monitor, QObject* parent)
: EntityTreeModel(monitor, parent)
, ResourceDataModelBase()
, mMonitor(monitor)
, mMigrationChecked(false)
, mMigrating(false)
{
// Populate all collections, selected/enabled or unselected/disabled.
setItemPopulationStrategy(ImmediatePopulation);
......@@ -153,18 +146,16 @@ void AkonadiModel::checkResources(ServerManager::State state)
switch (state)
{
case ServerManager::Running:
if (!mMigrationChecked)
if (!isMigrating() && !isMigrationComplete())
{
qCDebug(KALARM_LOG) << "AkonadiModel::checkResources: Server running";
mMigrationChecked = true;
mMigrating = true;
setMigrationInitiated();
CalendarMigrator::execute();
}
break;
case ServerManager::NotRunning:
qCDebug(KALARM_LOG) << "AkonadiModel::checkResources: Server stopped";
mMigrationChecked = false;
mMigrating = false;
setMigrationInitiated(false);
initCalendarMigrator();
Q_EMIT serverStopped();
break;
......@@ -186,14 +177,6 @@ void AkonadiModel::initCalendarMigrator()
this, &AkonadiModel::slotMigrationCompleted);
}
/******************************************************************************
* Return whether calendar migration has completed.
*/
bool AkonadiModel::isMigrationCompleted() const
{
return mMigrationChecked && !mMigrating;
}
ChangeRecorder* AkonadiModel::monitor()
{
return instance()->mMonitor;
......@@ -723,14 +706,14 @@ void AkonadiModel::slotCollectionChanged(const Akonadi::Collection& c, const QSe
void AkonadiModel::setCollectionChanged(Resource& resource, const Collection& collection, bool checkCompat)
{
AkonadiResource::notifyCollectionChanged(resource, collection, checkCompat);
if (mMigrating)
if (isMigrating())
{
mCollectionIdsBeingCreated.removeAll(collection.id());
if (mCollectionsBeingCreated.isEmpty() && mCollectionIdsBeingCreated.isEmpty()
&& CalendarMigrator::completed())
{
qCDebug(KALARM_LOG) << "AkonadiModel::setCollectionChanged: Migration completed";
mMigrating = false;
setMigrationComplete();
Q_EMIT migrationCompleted();
}
}
......@@ -786,7 +769,7 @@ void AkonadiModel::slotMigrationCompleted()
if (mCollectionsBeingCreated.isEmpty() && mCollectionIdsBeingCreated.isEmpty())
{
qCDebug(KALARM_LOG) << "AkonadiModel: Migration completed";
mMigrating = false;
setMigrationComplete();
Q_EMIT migrationCompleted();
}
}
......
......@@ -23,13 +23,11 @@
#include "resources/resourcedatamodelbase.h"
#include "resources/akonadiresource.h"
#include "eventid.h"
#include <kalarmcal/kaevent.h>
#include <kalarmcal/collectionattribute.h>
#include <KAlarmCal/KAEvent>
#include <AkonadiCore/entitytreemodel.h>
#include <AkonadiCore/servermanager.h>
#include <AkonadiCore/EntityTreeModel>
#include <AkonadiCore/ServerManager>
#include <QColor>
#include <QHash>
......@@ -40,7 +38,6 @@ namespace Akonadi
class ChangeRecorder;
}
class QPixmap;
class KJob;
using namespace KAlarmCal;
......@@ -78,9 +75,6 @@ class AkonadiModel : public Akonadi::EntityTreeModel, public ResourceDataModelBa
/** Reload all collections' data from Akonadi storage (not from the backend). */
void reload();
/** Return whether calendar migration/creation at initialisation has completed. */
bool isMigrationCompleted() const;
KAEvent event(const QString& eventId) const;
KAEvent event(const QModelIndex&) const;
using QObject::event; // prevent warning about hidden virtual method
......@@ -191,8 +185,6 @@ class AkonadiModel : public Akonadi::EntityTreeModel, public ResourceDataModelBa
QHash<QString, EventIds> mEventIds; // collection and item ID for each event ID
mutable QHash<Akonadi::Collection::Id, Resource> mResources;
QQueue<KAEvent> mPendingEventChanges; // changed events with changedEvent() signal pending
bool mMigrationChecked; // whether calendar migration has been checked at startup
bool mMigrating; // currently migrating calendars
};
#endif // AKONADIMODEL_H
......
......@@ -29,17 +29,17 @@
#include "resources/akonadiresource.h"
#include "kalarm_debug.h"
#include <kalarmcal/collectionattribute.h>
#include <kalarmcal/compatibilityattribute.h>
#include <kalarmcal/version.h>
#include <AkonadiCore/agentinstancecreatejob.h>
#include <AkonadiCore/agentmanager.h>
#include <AkonadiCore/collectionfetchjob.h>
#include <AkonadiCore/collectionfetchscope.h>
#include <AkonadiCore/collectionmodifyjob.h>
#include <AkonadiCore/entitydisplayattribute.h>
#include <AkonadiCore/resourcesynchronizationjob.h>
#include <KAlarmCal/CollectionAttribute>
#include <KAlarmCal/CompatibilityAttribute>
#include <KAlarmCal/Version>
#include <AkonadiCore/AgentInstanceCreateJob>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/CollectionModifyJob>
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/ResourceSynchronizationJob>
#include <KLocalizedString>
#include <KConfig>
......
......@@ -21,13 +21,12 @@
#ifndef CALENDARMIGRATOR_H
#define CALENDARMIGRATOR_H
#include <kalarmcal/kacalendar.h>
#include <KAlarmCal/KACalendar>
#include <AkonadiCore/agentinstance.h>
#include <AkonadiCore/collection.h>
#include <AkonadiCore/AgentInstance>
#include <AkonadiCore/Collection>
class KJob;
namespace KRES { class Resource; }
namespace Akonadi { class CollectionFetchJob; }
class CalendarCreator;
......
......@@ -1144,7 +1144,7 @@ void KAlarmApp::checkWritableCalendar()
MessageWin::redisplayAlarms();
}
if (!treeFetched
|| !AkonadiModel::instance()->isMigrationCompleted())
|| !AkonadiModel::instance()->isMigrationComplete())
return;
static bool done = false;
if (done)
......
......@@ -26,10 +26,10 @@
#include "calendarmigrator.h"
#include "kalarm_debug.h"
#include <kalarmcal/akonadi.h>
#include <kalarmcal/compatibilityattribute.h>
#include <kalarmcal/eventattribute.h>
#include <kalarmcal/version.h>
#include <KAlarmCal/Akonadi>
#include <KAlarmCal/CompatibilityAttribute>
#include <KAlarmCal/EventAttribute>
#include <KAlarmCal/Version>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/ChangeRecorder>
......
......@@ -23,7 +23,7 @@
#include "resource.h"
#include <kalarmcal/collectionattribute.h>
#include <KAlarmCal/CollectionAttribute>
#include <AkonadiCore/Collection>
#include <AkonadiCore/Item>
......
......@@ -23,7 +23,7 @@
#include "resource.h"
#include <kalarmcal/kacalendar.h>
#include <KAlarmCal/KACalendar>
#include <KDescendantsProxyModel>
......
......@@ -20,15 +20,16 @@
#include "resourcedatamodelbase.h"
#include "resource.h"
#include "alarmtime.h"
#include "mainwindow.h"
#include "messagebox.h"
#include "preferences.h"
#include "resources/resource.h"
#include "kalarm_debug.h"
#include <kalarmcal/alarmtext.h>
#include <kalarmcal/kaevent.h>
#include <KAlarmCal/AlarmText>
#include <KAlarmCal/KAEvent>
#include <KLocalizedString>
#include <KColorUtils>
......@@ -602,4 +603,24 @@ void ResourceDataModelBase::handleResourceMessage(ResourceType::MessageType type
KAMessageBox::informationList(MainWindow::mainMainWindow(), message, {details});
}
bool ResourceDataModelBase::isMigrationComplete() const
{
return mMigrationStatus == 1;
}
bool ResourceDataModelBase::isMigrating() const
{
return mMigrationStatus == 0;
}
void ResourceDataModelBase::setMigrationInitiated(bool started)
{
mMigrationStatus = (started ? 0 : -1);
}
void ResourceDataModelBase::setMigrationComplete()
{
mMigrationStatus = 1;
}
// vim: et sw=4:
......@@ -21,9 +21,9 @@
#ifndef RESOURCEDATAMODELBASE_H
#define RESOURCEDATAMODELBASE_H
#include "resources/resourcetype.h"
#include "resourcetype.h"
#include <kalarmcal/kacalendar.h>
#include <KAlarmCal/KACalendar>
#include <QSize>
......@@ -92,6 +92,9 @@ class ResourceDataModelBase
/** Return offset to add to headerData() role, for item models. */
virtual int headerDataEventRoleOffset() const { return 0; }
/** Return whether calendar migration/creation at initialisation has completed. */
bool isMigrationComplete() const;
protected:
ResourceDataModelBase();
......@@ -114,6 +117,15 @@ class ResourceDataModelBase
/** Called when a resource notifies a message to display to the user. */
void handleResourceMessage(ResourceType::MessageType, const QString& message, const QString& details);
/** Return whether calendar migration is currently in progress. */
bool isMigrating() const;
/** To be called when calendar migration has been initiated (or reset). */
void setMigrationInitiated(bool started = true);
/** To be called when calendar migration has been initiated (or reset). */
void setMigrationComplete();
static QString repeatText(const KAEvent&);
static QString repeatOrder(const KAEvent&);
static QString whatsThisText(int column);
......@@ -126,6 +138,8 @@ class ResourceDataModelBase
static QPixmap* mEmailIcon;
static QPixmap* mAudioIcon;
static QSize mIconSize; // maximum size of any icon
int mMigrationStatus{-1}; // migration status, -1 = no, 0 = initiated, 1 = complete
};
#endif // RESOURCEDATAMODELBASE_H
......
......@@ -23,7 +23,7 @@
#include "resource.h"
#include <kalarmcal/kacalendar.h>
#include <KAlarmCal/KACalendar>
#include <KDescendantsProxyModel>
#include <KCheckableProxyModel>
......
......@@ -21,8 +21,8 @@
#ifndef RESOURCETYPE_H
#define RESOURCETYPE_H
#include <kalarmcal/kacalendar.h>
#include <kalarmcal/kaevent.h>
#include <KAlarmCal/KACalendar>
#include <KAlarmCal/KAEvent>
#include <QObject>
#include <QSharedPointer>
......
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