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

Use standard user notification function in calendar migration

parent fc948172
......@@ -25,6 +25,7 @@
#include "kalarmdirsettings.h"
#include "mainwindow.h"
#include "resources/akonadiresource.h"
#include "resources/resources.h"
#include "lib/messagebox.h"
#include "kalarm_debug.h"
......@@ -120,7 +121,7 @@ class CalendarUpdater : public QObject
Q_OBJECT
public:
CalendarUpdater(const Collection& collection, bool dirResource,
bool ignoreKeepFormat, bool newCollection, QObject* parent);
bool ignoreKeepFormat, bool newCollection, QObject* parent, QWidget* promptParent = nullptr);
~CalendarUpdater();
// Return whether another instance is already updating this collection
bool isDuplicate() const { return mDuplicate; }
......@@ -134,6 +135,7 @@ class CalendarUpdater : public QObject
static QList<CalendarUpdater*> mInstances;
Akonadi::Collection mCollection;
QObject* mParent;
QWidget* mPromptParent;
const bool mDirResource;
const bool mIgnoreKeepFormat;
const bool mNewCollection;
......@@ -354,11 +356,8 @@ void CalendarMigrator::calendarCreated(CalendarCreator* creator)
"Failed to convert old configuration for calendar <resource>%1</resource>. "
"Please use Import Alarms to load its alarms into a new or existing calendar.", creator->resourceName());
const QString locn = i18nc("@info File path or URL", "Location: %1", creator->path());
if (creator->errorMessage().isEmpty())
errmsg = xi18nc("@info", "<para>%1</para><para>%2</para>", errmsg, locn);
else
errmsg = xi18nc("@info", "<para>%1</para><para>%2<nl/>(%3)</para>", errmsg, locn, creator->errorMessage());
KAMessageBox::error(MainWindow::mainMainWindow(), errmsg);
errmsg = xi18nc("@info", "<para>%1</para><para>%2</para>", errmsg, locn);
Resources::notifyResourceMessage(-1, ResourceType::MessageType::Error, errmsg, creator->errorMessage());
}
creator->deleteLater();
......@@ -380,7 +379,7 @@ void CalendarMigrator::calendarCreated(CalendarCreator* creator)
* Note: the collection should be up to date: use AkonadiModel::refresh() before
* calling this function.
*/
void CalendarMigrator::updateToCurrentFormat(const Resource& resource, bool ignoreKeepFormat, QWidget* parent)
void CalendarMigrator::updateToCurrentFormat(const Resource& resource, bool ignoreKeepFormat, QObject* parent)
{
qCDebug(KALARM_LOG) << "CalendarMigrator::updateToCurrentFormat:" << resource.id();
if (CalendarUpdater::containsCollection(resource.id()))
......@@ -398,9 +397,7 @@ void CalendarMigrator::updateToCurrentFormat(const Resource& resource, bool igno
return;
}
const Collection& collection = AkonadiResource::collection(resource);
if (!parent)
parent = MainWindow::mainMainWindow();
CalendarUpdater* updater = new CalendarUpdater(collection, dirResource, ignoreKeepFormat, false, parent);
CalendarUpdater* updater = new CalendarUpdater(collection, dirResource, ignoreKeepFormat, false, parent, qobject_cast<QWidget*>(parent));
QTimer::singleShot(0, updater, &CalendarUpdater::update);
}
......@@ -409,9 +406,11 @@ void CalendarMigrator::updateToCurrentFormat(const Resource& resource, bool igno
QList<CalendarUpdater*> CalendarUpdater::mInstances;
CalendarUpdater::CalendarUpdater(const Collection& collection, bool dirResource,
bool ignoreKeepFormat, bool newCollection, QObject* parent)
: mCollection(collection)
bool ignoreKeepFormat, bool newCollection, QObject* parent, QWidget* promptParent)
: QObject(parent)
, mCollection(collection)
, mParent(parent)
, mPromptParent(promptParent ? promptParent : MainWindow::mainMainWindow())
, mDirResource(dirResource)
, mIgnoreKeepFormat(ignoreKeepFormat)
, mNewCollection(newCollection)
......@@ -461,7 +460,7 @@ bool CalendarUpdater::update()
const QString versionString = KAlarmCal::getVersionString(compatAttr->version());
const QString msg = conversionPrompt(mCollection.name(), versionString, false);
qCDebug(KALARM_LOG) << "CalendarUpdater::update: Version" << versionString;
if (KAMessageBox::warningYesNo(qobject_cast<QWidget*>(mParent), msg) != KMessageBox::Yes)
if (KAMessageBox::warningYesNo(mPromptParent, msg) != KMessageBox::Yes)
result = false; // the user chose not to update the calendar
else
{
......@@ -484,10 +483,9 @@ bool CalendarUpdater::update()
}
if (!errmsg.isEmpty())
{
KAMessageBox::error(MainWindow::mainMainWindow(),
xi18nc("@info", "%1<nl/>(%2)",
xi18nc("@info/plain", "Failed to update format of calendar <resource>%1</resource>", mCollection.name()),
errmsg));
Resources::notifyResourceMessage(mCollection.id(), ResourceType::MessageType::Error,
xi18nc("@info", "Failed to update format of calendar <resource>%1</resource>", mCollection.name()),
errmsg);
}
}
if (!mNewCollection)
......
......@@ -47,7 +47,7 @@ class CalendarMigrator : public QObject
static CalendarMigrator* instance();
static void reset();
static void execute();
static void updateToCurrentFormat(const Resource&, bool ignoreKeepFormat, QWidget* parent = nullptr);
static void updateToCurrentFormat(const Resource&, bool ignoreKeepFormat, QObject* parent);
static bool completed() { return mCompleted; }
template <class Interface> static Interface* getAgentInterface(const Akonadi::AgentInstance&, QString& errorMessage, QObject* parent);
......@@ -72,7 +72,7 @@ class CalendarMigrator : public QObject
template <class Interface> static bool updateStorageFormat(const Akonadi::AgentInstance&, QString& errorMessage, QObject* parent);
static CalendarMigrator* mInstance;
QList<CalendarCreator*> mCalendarsPending; // pending calendar migration or creation jobs
QList<CalendarCreator*> mCalendarsPending; // pending calendar migration or creation jobs
QList<Akonadi::CollectionFetchJob*> mFetchesPending; // pending collection fetch jobs for existing resources
CalEvent::Types mExistingAlarmTypes; // alarm types provided by existing Akonadi resources
static bool mCompleted; // execute() has completed
......
......@@ -717,6 +717,7 @@ void AkonadiResource::notifyCollectionChanged(Resource& res, const Collection& c
|| !hadCompat
|| *collection.attribute<CompatibilityAttribute>() != *akres->mCollection.attribute<CompatibilityAttribute>())
{
//TODO: check if a temporary AkonadiResource object is actually needed, as in the comment
// Update to current KAlarm format if necessary, and if the user agrees.
// Create a new temporary 'Resource' object, because the one passed
// to this method can get overwritten with an old version of its
......@@ -725,7 +726,7 @@ void AkonadiResource::notifyCollectionChanged(Resource& res, const Collection& c
qCDebug(KALARM_LOG) << "AkonadiResource::setCollectionChanged:" << collection.id() << ": compatibility ->" << collection.attribute<CompatibilityAttribute>()->compatibility();
// Note that the AkonadiResource will be deleted once no more
// QSharedPointers reference it.
CalendarMigrator::updateToCurrentFormat(res, false);
CalendarMigrator::updateToCurrentFormat(res, false, akres);
}
}
}
......
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