Commit 3764355e authored by Jiří Paleček's avatar Jiří Paleček Committed by David Jarvie
Browse files

Use QSharedPointer where possible instead of raw pointers

parent ecc05efe
Pipeline #207231 passed with stage
in 1 minute and 43 seconds
......@@ -19,7 +19,7 @@
#include <KLocalizedString>
FileResource::FileResource(FileResourceSettings* settings)
FileResource::FileResource(FileResourceSettings::Ptr settings)
: ResourceType(settings->id())
, mSettings(settings)
{
......
......@@ -46,7 +46,7 @@ public:
/** Constructor.
* Initialises the resource and initiates loading its events.
*/
explicit FileResource(FileResourceSettings* settings);
explicit FileResource(QSharedPointer<FileResourceSettings> settings);
~FileResource() override;
......@@ -386,7 +386,7 @@ protected:
*/
void setStatus(Status);
FileResourceSettings* mSettings; // the resource's configuration
QSharedPointer<FileResourceSettings> mSettings; // the resource's configuration
int mVersion {KACalendar::IncompatibleFormat}; // the calendar format version
KACalendar::Compat mCompatibility {KACalendar::Incompatible}; // whether resource is in compatible format
......
......@@ -252,7 +252,7 @@ Resource FileResourceConfigManager::createResource(FileResourceSettings::Ptr& se
switch (settings->storageType())
{
case FileResourceSettings::File:
return SingleFileResource::create(settings.data());
return SingleFileResource::create(settings);
case FileResourceSettings::Directory: // not currently intended to be implemented
default:
return Resource::null();
......
......@@ -42,7 +42,7 @@ namespace
const int SAVE_TIMER_DELAY = 1000; // 1 second
}
Resource SingleFileResource::create(FileResourceSettings* settings)
Resource SingleFileResource::create(FileResourceSettings::Ptr settings)
{
if (!settings || !settings->isValid())
return Resource::null(); // return invalid Resource
......@@ -58,7 +58,7 @@ Resource SingleFileResource::create(FileResourceSettings* settings)
/******************************************************************************
* Constructor.
*/
SingleFileResource::SingleFileResource(FileResourceSettings* settings)
SingleFileResource::SingleFileResource(FileResourceSettings::Ptr settings)
: FileResource(settings)
, mSaveTimer(new QTimer(this))
{
......@@ -633,10 +633,10 @@ bool SingleFileResource::writeToFile(const QString& fileName, QString& errorMess
return false;
}
KACalendar::setKAlarmVersion(mCalendar); // write the application ID into the calendar
KCalendarCore::FileStorage* fileStorage = mFileStorage.data();
KCalendarCore::FileStorage::Ptr fileStorage = mFileStorage;
if (!mFileStorage || fileName != mFileStorage->fileName())
fileStorage = new KCalendarCore::FileStorage(mCalendar, fileName,
new KCalendarCore::ICalFormat());
fileStorage = KCalendarCore::FileStorage::Ptr::create(mCalendar, fileName,
new KCalendarCore::ICalFormat());
bool success = true;
if (!fileStorage->save()) // this sets mCalendar->modified to false
......@@ -646,9 +646,6 @@ bool SingleFileResource::writeToFile(const QString& fileName, QString& errorMess
success = false;
}
if (fileStorage != mFileStorage.data())
delete fileStorage;
return success;
}
......
......@@ -34,13 +34,13 @@ public:
/** Construct a new SingleFileResource.
* Initialises the resource and initiates loading its events.
*/
static Resource create(FileResourceSettings* settings);
static Resource create(FileResourceSettings::Ptr settings);
protected:
/** Constructor.
* Initialises the resource and initiates loading its events.
*/
explicit SingleFileResource(FileResourceSettings* settings);
explicit SingleFileResource(FileResourceSettings::Ptr settings);
public:
~SingleFileResource() override;
......
Supports Markdown
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