Commit 52bf03b4 authored by David Jarvie's avatar David Jarvie
Browse files

Implement generic interactive resource creation class

parent 52ed513c
......@@ -100,6 +100,7 @@ set(kalarm_bin_SRCS ${kalarm_bin_SRCS}
resources/resourcedatamodelbase.cpp
resources/resourcemodel.cpp
resources/resourceselectdialog.cpp
resources/resourcecreator.cpp
resources/eventmodel.cpp
resources/datamodel.cpp
resources/akonadidatamodel.cpp
......
/*
* akonadiresourcecreator.cpp - interactively create an Akonadi resource
* Program: kalarm
* Copyright © 2011,2019 David Jarvie <djarvie@kde.org>
* Copyright © 2011-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -37,30 +37,21 @@
#include <KMessageBox>
#include <KLocalizedString>
#include <QTimer>
using namespace Akonadi;
using namespace KAlarmCal;
AkonadiResourceCreator::AkonadiResourceCreator(CalEvent::Type defaultType, QWidget* parent)
: QObject()
, mParent(parent)
, mDefaultType(defaultType)
: ResourceCreator(defaultType, parent)
{
}
/******************************************************************************
* Create a new resource. The user will be prompted to enter its configuration.
*/
void AkonadiResourceCreator::createResource()
{
QTimer::singleShot(0, this, &AkonadiResourceCreator::getAgentType);
}
void AkonadiResourceCreator::getAgentType()
void AkonadiResourceCreator::doCreateResource()
{
qCDebug(KALARM_LOG) << "AkonadiResourceCreator::getAgentType: Type:" << mDefaultType;
qCDebug(KALARM_LOG) << "AkonadiResourceCreator::doCreateResource: Type:" << mDefaultType;
// Use AutoQPointer to guard against crash on application exit while
// the dialogue is still open. It prevents double deletion (both on
// deletion of parent, and on return from this function).
......
/*
* akonadiresourcecreator.h - interactively create an Akonadi resource
* Program: kalarm
* Copyright © 2011,2019 David Jarvie <djarvie@kde.org>
* Copyright © 2011-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,41 +21,33 @@
#ifndef AKONADIRESOURCECREATOR_H
#define AKONADIRESOURCECREATOR_H
#include <KAlarmCal/KACalendar>
#include "resourcecreator.h"
#include <AkonadiCore/AgentInstance>
#include <AkonadiCore/AgentType>
using namespace KAlarmCal;
class QWidget;
class KJob;
class Resource;
class AkonadiResourceCreator : public QObject
class AkonadiResourceCreator : public ResourceCreator
{
Q_OBJECT
public:
AkonadiResourceCreator(CalEvent::Type defaultType, QWidget* parent);
void createResource();
Akonadi::AgentInstance agentInstance() const { return mAgentInstance; }
Q_SIGNALS:
void resourceAdded(Resource&, CalEvent::Type);
private Q_SLOTS:
void getAgentType();
void agentInstanceCreated(KJob*);
void slotResourceAdded(Resource&);
private:
template <class Settings> void setResourceAlarmType();
template <class Settings> QString getResourcePath();
QWidget* mParent;
CalEvent::Type mDefaultType;
Akonadi::AgentType mAgentType;
Akonadi::AgentInstance mAgentInstance;
Q_OBJECT
public:
AkonadiResourceCreator(KAlarmCal::CalEvent::Type defaultType, QWidget* parent);
Akonadi::AgentInstance agentInstance() const { return mAgentInstance; }
protected Q_SLOTS:
void doCreateResource() override;
private Q_SLOTS:
void agentInstanceCreated(KJob*);
void slotResourceAdded(Resource&);
private:
template <class Settings> void setResourceAlarmType();
template <class Settings> QString getResourcePath();
Akonadi::AgentType mAgentType;
Akonadi::AgentInstance mAgentInstance;
};
#endif // AKONADIRESOURCECREATOR_H
......
/*
* datamodel.cpp - calendar data model dependent functions
* Program: kalarm
* Copyright © 2019 David Jarvie <djarvie@kde.org>
* Copyright © 2019-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,6 +22,7 @@
#include "akonadidatamodel.h"
#include "akonadiresource.h"
#include "akonadiresourcecreator.h"
#include "eventmodel.h"
#include "resourcemodel.h"
......@@ -83,6 +84,11 @@ TemplateListModel* allTemplateListModel()
return TemplateListModel::all<AkonadiDataModel>();
}
ResourceCreator* createResourceCreator(KAlarmCal::CalEvent::Type defaultType, QWidget* parent)
{
return new AkonadiResourceCreator(defaultType, parent);
}
} // namespace DataModel
// vim: et sw=4:
/*
* datamodel.h - calendar data model dependent functions
* Program: kalarm
* Copyright © 2019 David Jarvie <djarvie@kde.org>
* Copyright © 2019-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,12 +21,16 @@
#ifndef DATAMODEL_H
#define DATAMODEL_H
#include <KAlarmCal/KACalendar>
class Resource;
class ResourceListModel;
class ResourceFilterCheckListModel;
class AlarmListModel;
class TemplateListModel;
class ResourceCreator;
class QObject;
class QWidget;
/** Class to create objects dependent on data model. */
namespace DataModel
......@@ -58,6 +62,8 @@ AlarmListModel* allAlarmListModel();
TemplateListModel* createTemplateListModel(QObject* parent);
TemplateListModel* allTemplateListModel();
ResourceCreator* createResourceCreator(KAlarmCal::CalEvent::Type defaultType, QWidget* parent);
} // namespace DataModel
#endif // DATAMODEL_H
......
/*
* resourcecreator.cpp - base class to interactively create a resource
* Program: kalarm
* Copyright © 2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "resourcecreator.h"
#include "kalarm_debug.h"
#include <QTimer>
using namespace KAlarmCal;
ResourceCreator::ResourceCreator(CalEvent::Type defaultType, QWidget* parent)
: QObject()
, mParent(parent)
, mDefaultType(defaultType)
{
}
/******************************************************************************
* Create a new resource. The user will be prompted to enter its configuration.
*/
void ResourceCreator::createResource()
{
QTimer::singleShot(0, this, &ResourceCreator::doCreateResource);
}
// vim: et sw=4:
/*
* resourcecreator.h - base class to interactively create a resource
* Program: kalarm
* Copyright © 2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef RESOURCECREATOR_H
#define RESOURCECREATOR_H
#include <KAlarmCal/KACalendar>
class QWidget;
class Resource;
/**
* Base class for interactively creating a resource.
* Derived classes must call deleteLater() to delete themselves if resource
* creation is unsuccessful, i.e. if the resourceAdded() signal is not called.
*/
class ResourceCreator : public QObject
{
Q_OBJECT
public:
ResourceCreator(KAlarmCal::CalEvent::Type defaultType, QWidget* parent);
void createResource();
Q_SIGNALS:
/** Signal emitted when a resource has been created.
* @param type The default alarm type specified in the constructor.
*/
void resourceAdded(Resource&, KAlarmCal::CalEvent::Type);
protected Q_SLOTS:
virtual void doCreateResource() = 0;
protected:
QWidget* mParent;
KAlarmCal::CalEvent::Type mDefaultType;
};
#endif // RESOURCECREATOR_H
// vim: et sw=4:
/*
* resourceselector.cpp - calendar resource selection widget
* Program: kalarm
* Copyright © 2006-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2006-2020 David Jarvie <djarvie@kde.org>
* Based on KOrganizer's ResourceView class and KAddressBook's ResourceSelection class,
* Copyright (C) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
* Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
......@@ -170,8 +170,8 @@ void ResourceSelector::reinstateAlarmTypeScrollBars()
*/
void ResourceSelector::addResource()
{
AkonadiResourceCreator* creator = new AkonadiResourceCreator(mCurrentAlarmType, this);
connect(creator, &AkonadiResourceCreator::resourceAdded, this, &ResourceSelector::slotResourceAdded);
ResourceCreator* creator = DataModel::createResourceCreator(mCurrentAlarmType, this);
connect(creator, &ResourceCreator::resourceAdded, this, &ResourceSelector::slotResourceAdded);
creator->createResource();
}
......
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