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

Wait for calendars migration before signalling resource creation complete

parent cb075707
......@@ -27,6 +27,14 @@ See the KAlarmCal design notes (kalarmcal/DESIGN.html) for details of calendar s
<p>This section summarises some of the C++ classes used to build KAlarm.</p>
<table>
<tr><th>Class</th><th>Base class</th><th>Description</th></tr>
<tr><td><tt>CollectionSearch</tt></td><td><tt>QObject</tt></td>
<td>Fetches a list of all Akonadi collections which handle a specified mime
type, and then optionally fetches or deletes all Items from them with a
given GID. This class is only used to access KOrganizer collections.</td></tr>
</table>
<h3>Calendar Resource Classes</h3>
......@@ -59,8 +67,8 @@ See the KAlarmCal design notes (kalarmcal/DESIGN.html) for details of calendar s
<td>A dialog which shows a list of resources and allows the user to select one.</td></tr>
<tr><td><tt>DataModel</tt></td><td><tt></tt></td>
<td>A namespace which provides functions independent of which data model
type (Akonadi, etc.) is being used</td></tr>
<td>A class which provides functions independent of which data model
type (Akonadi or file resource) is being used</td></tr>
<tr><td><tt>ResourceDataModelBase</tt></td><td><tt></tt></td>
<td>Base class for models containing all calendars and the events
......@@ -130,16 +138,18 @@ See the KAlarmCal design notes (kalarmcal/DESIGN.html) for details of calendar s
<td>Delegate for a TemplateListView. Handles editing and display of the
list of alarm templates.</td></tr>
<tr><td><tt>DirResourceImportDialog</tt></td><td><tt>KAssistantDialog</tt></td>
<td>Dialogue for importing a calendar directory resource. For use when
migrating Akonadi alarm calendars.</td></tr>
<tr><td colspan=3><br><b>Akonadi Resource and Event Classes</b></td></tr>
<tr><td><tt>AkonadiDataModel</tt></td><td><tt>Akonadi::EntityTreeModel,<br>ResourceDataModelBase</tt></td>
<td>Contains all KAlarm collections and the items (alarms and templates)
within them.</td></tr>
<tr><td><tt>CollectionSearch</tt></td><td><tt>QObject</tt></td>
<td>Fetches a list of all Akonadi collections which handle a specified mime
type, and then optionally fetches or deletes all Items from them with a
given GID.</td></tr>
<tr><td><tt>AkonadiResource</tt></td><td><tt>ResourceType</tt></td>
<td>An Akonadi calendar resource.</td></tr>
<tr><td><tt>AkonadiResourceMigrator</tt></td><td><tt>QObject</tt></td>
<td>Migrates KResources alarm calendars from pre-Akonadi versions of
......@@ -151,6 +161,39 @@ See the KAlarmCal design notes (kalarmcal/DESIGN.html) for details of calendar s
<tr><td><tt>AkonadiCalendarUpdater</tt></td><td><tt>CalendarUpdater</tt></td>
<td>Updates the backend calendar format of one Akonadi alarm calendar.</td></tr>
<tr><td colspan=3><br><b>Non-Akonadi Resource and Event Classes</b></td></tr>
<tr><td><tt>FileResourceDataModel</tt></td><td><tt>QAbstractItemModel,<br>ResourceDataModelBase</tt></td>
<td>Model containing all file system calendar resources and the events
(alarms and templates) within them.</td></tr>
<tr><td><tt>FileResource</tt></td><td><tt>ResourceType</tt></td>
<td>Abstract base class for a file system calendar resource.</td></tr>
<tr><td><tt>SingleFileResource</tt></td><td><tt>FileResource</tt></td>
<td>A file system calendar resource held in a single file.</td></tr>
<tr><td><tt>SingleFileResourceConfigDialog</tt></td><td><tt>QDialog</tt></td>
<td>Configuration dialogue for a SingleFileResource resource.</td></tr>
<tr><td><tt>FileResourceMigrator</tt></td><td><tt>QObject</tt></td>
<td>Migrates Akonadi or KResources alarm calendars from previous versions
of KAlarm, and creates default calendar resources if none exist.</td></tr>
<tr><td><tt>FileResourceCreator</tt></td><td><tt>ResourceCreator</tt></td>
<td>Interactively creates a file resource.</td></tr>
<tr><td><tt>FileResourceConfigManager</tt></td><td><tt></tt></td>
<td>Manager for file system resource configuration files. Reads
configuration files and creates resources at startup, and updates
configuration files with resource configuration changes.</td></tr>
<tr><td><tt>FileResourceSettings</tt></td><td><tt></tt></td>
<td>Encapsulates the configuration settings of a file system resource.</td></tr>
<tr><td><tt>FileResourceCalendarUpdater</tt></td><td><tt>CalendarUpdater</tt></td>
<td>Updates the backend calendar format of one file resource alarm calendar.</td></tr>
</table>
</body>
......@@ -195,8 +195,6 @@ void KAlarmApp::initialise()
this, &KAlarmApp::purgeNewArchivedDefault);
connect(resources, &Resources::resourcesCreated,
this, &KAlarmApp::slotResourcesCreated);
connect(resources, &Resources::migrationCompleted,
this, &KAlarmApp::checkWritableCalendar);
connect(resources, &Resources::resourcesPopulated,
this, &KAlarmApp::processQueue);
......
......@@ -134,7 +134,6 @@ class KAlarmApp : public QApplication
void slotResourcesTimeout();
void slotResourcesCreated();
void slotEditAlarmById();
void checkWritableCalendar();
void promptArchivedCalendar();
void slotMessageFontChanged(const QFont&);
void setArchivePurgeDays();
......@@ -198,6 +197,7 @@ class KAlarmApp : public QApplication
bool checkSystemTray();
void startProcessQueue();
void setResourcesTimeout();
void checkWritableCalendar();
void checkArchivedCalendar();
void queueAlarmId(const KAEvent&);
bool dbusHandleEvent(const EventId&, QueuedAction);
......
......@@ -827,7 +827,7 @@ void AkonadiDataModel::slotCollectionBeingCreated(const QString& path, Akonadi::
*/
void AkonadiDataModel::slotCollectionTreeFetched()
{
Resources::notifyResourcesCreated();
setCalendarsCreated();
}
/******************************************************************************
......
......@@ -35,8 +35,9 @@ class FileResourceSettings;
using namespace KAlarmCal;
/** Base class for an alarm calendar resource accessed directly through the file system.
* Public access to this class and derived classes is normally via the Resource class.
/** Abstract base class for an alarm calendar resource accessed directly
* through the file system. Public access to this class and derived classes is
* normally via the Resource class.
*/
class FileResource : public ResourceType
{
......
......@@ -70,7 +70,7 @@ void FileResourceConfigManager::createResources(QObject* parent)
return;
manager->mCreated = 1;
QStringList resourceGroups = manager->mConfig->groupList().filter(QRegularExpression(QStringLiteral("^Resource \\d+$")));
QStringList resourceGroups = manager->mConfig->groupList().filter(QRegularExpression(QStringLiteral("^Resource_\\d+$")));
if (!resourceGroups.isEmpty())
{
std::sort(resourceGroups.begin(), resourceGroups.end(),
......@@ -131,7 +131,6 @@ void FileResourceConfigManager::createResources(QObject* parent)
FileResourceCalendarUpdater::waitForCompletion();
}
manager->mCreated = 2;
Resources::notifyResourcesCreated();
}
/******************************************************************************
......@@ -244,7 +243,7 @@ int FileResourceConfigManager::findResourceGroup(ResourceId id) const
*/
QString FileResourceConfigManager::groupName(int groupIndex)
{
return QStringLiteral("Resource %1").arg(groupIndex);
return QStringLiteral("Resource_%1").arg(groupIndex);
}
/******************************************************************************
......
......@@ -29,6 +29,10 @@
class KConfig;
/** Manager for configuration files for file system resources.
* Reads configuration files and creates resources at startup, and updates
* configuration files when resource configurations change.
*/
class FileResourceConfigManager
{
public:
......
......@@ -106,9 +106,12 @@ FileResourceDataModel::FileResourceDataModel(QObject* parent)
this, &FileResourceDataModel::slotResourceMessage, Qt::QueuedConnection);
FileResourceConfigManager::createResources(this);
setCalendarsCreated();
FileResourceMigrator* migrator = FileResourceMigrator::instance();
if (migrator)
if (!migrator)
setMigrationComplete();
else
{
connect(migrator, &QObject::destroyed, this, &FileResourceDataModel::slotMigrationCompleted);
setMigrationInitiated();
......
......@@ -87,7 +87,22 @@ FileResourceMigrator::~FileResourceMigrator()
FileResourceMigrator* FileResourceMigrator::instance()
{
if (!mInstance && !mCompleted)
{
// Check whether migration or default resource creation is actually needed.
CalEvent::Types needed = CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE;
const QVector<Resource> resources = Resources::allResources<FileResource>();
for (const Resource& resource : resources)
{
needed &= ~resource.alarmTypes();
if (!needed)
{
mCompleted = true;
return mInstance;
}
}
// Migration or default resource creation is required.
mInstance = new FileResourceMigrator;
}
return mInstance;
}
......@@ -103,7 +118,7 @@ void FileResourceMigrator::execute()
return;
}
qCDebug(KALARM_LOG) << "FileResourceMigrator::migrateOrCreate";
qCDebug(KALARM_LOG) << "FileResourceMigrator::execute";
// First, check whether any file system resources already exist, and if so,
// find their alarm types.
......
......@@ -42,7 +42,8 @@ public:
/** Return the unique instance, creating it if necessary.
* Note that the instance will be destroyed once migration has completed.
* @return Unique instance, or null if migration has already been done.
* @return Unique instance, or null if migration is not required or has
* already been done.
*/
static FileResourceMigrator* instance();
......
......@@ -66,13 +66,6 @@ bool Resource::failed() const
return mResource.isNull() ? true : mResource->failed();
}
#if 0
ResourceType::Ptr Resource::resource() const
{
return mResource;
}
#endif
ResourceId Resource::id() const
{
return mResource.isNull() ? -1 : mResource->id();
......
......@@ -646,7 +646,15 @@ void ResourceDataModelBase::setMigrationInitiated(bool started)
void ResourceDataModelBase::setMigrationComplete()
{
mMigrationStatus = 1;
Resources::notifyResourcesMigrated();
if (mCreationStatus)
Resources::notifyResourcesCreated();
}
void ResourceDataModelBase::setCalendarsCreated()
{
mCreationStatus = true;
if (mMigrationStatus == 1)
Resources::notifyResourcesCreated();
}
namespace
......
......@@ -173,6 +173,9 @@ protected:
/** To be called when calendar migration has been initiated (or reset). */
void setMigrationComplete();
/** To be called when all previously configured calendars have been created. */
void setCalendarsCreated();
static QString repeatText(const KAEvent&);
static QString repeatOrder(const KAEvent&);
static QString whatsThisText(int column);
......@@ -189,6 +192,7 @@ private:
static QSize mIconSize; // maximum size of any icon
int mMigrationStatus {-1}; // migration status, -1 = no, 0 = initiated, 1 = complete
bool mCreationStatus {false}; // previously configured calendar creation status
friend class DataModel;
};
......
......@@ -376,6 +376,7 @@ void Resources::notifyNewResourceInitialised(Resource& res)
*/
void Resources::notifyResourcesCreated()
{
qCDebug() << "Resources::notifyResourcesCreated";
mCreated = true;
Q_EMIT instance()->resourcesCreated();
checkResourcesPopulated();
......@@ -398,14 +399,6 @@ void Resources::notifyResourcePopulated(const ResourceType* res)
checkResourcesPopulated();
}
/******************************************************************************
* Called to notify that migration/creation of resources has completed.
*/
void Resources::notifyResourcesMigrated()
{
Q_EMIT instance()->migrationCompleted();
}
/******************************************************************************
* Called to notify that a resource is about to be removed.
*/
......
......@@ -133,10 +133,11 @@ public:
*/
static Resource destination(CalEvent::Type type, QWidget* promptParent = nullptr, bool noPrompt = false, bool* cancelled = nullptr);
/** Return whether all configured resources have been created. */
/** Return whether all configured and migrated resources have been created. */
static bool allCreated();
/** Return whether all configured resources have been loaded at least once. */
/** Return whether all configured and migrated resources have been loaded
* at least once. */
static bool allPopulated();
/** Return the resource which an event belongs to, provided that the event's
......@@ -154,15 +155,13 @@ public:
* in order to emit the resourceAdded() signal. */
static void notifyNewResourceInitialised(Resource&);
/** Called to notify that all configured resources have now been created. */
/** Called to notify that all configured and migrated resources have now
* been created. */
static void notifyResourcesCreated();
/** Called by a resource to notify that loading of events has successfully completed. */
static void notifyResourcePopulated(const ResourceType*);
/** Called to notify that migration/creation of resources has completed. */
static void notifyResourcesMigrated();
/** Called to notify that a resource is about to be removed. */
static void notifyResourceToBeRemoved(ResourceType*);
......@@ -201,18 +200,16 @@ Q_SIGNALS:
void settingsChanged(Resource&, ResourceType::Changes);
/** Emitted when all configured resource have been created (but not
* necessarily populated). Note that after this, resource migration and
* the creation of default resources is performed and notified by the
* signal migrationCompleted().
* necessarily populated), and any necessary resource migration and
* the creation of default resources has been performed.
*/
void resourcesCreated();
/** Emitted when all configured resources have been loaded for the first time. */
/** Emitted when all configured and migrated resources have been loaded for
* the first time.
*/
void resourcesPopulated();
/** Signal emitted when resource migration/creation at startup has completed. */
void migrationCompleted();
/** Emitted when a new resource has been created. */
void resourceAdded(Resource&);
......
......@@ -34,7 +34,7 @@ class SingleFileResourceConfigDialog : public QDialog
{
Q_OBJECT
public:
explicit SingleFileResourceConfigDialog(bool create, QWidget* parent);
SingleFileResourceConfigDialog(bool create, QWidget* parent);
~SingleFileResourceConfigDialog();
/** Return the file URL. */
......
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