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

Use Resource::displayId() for user-visible resource ID

parent 046d4153
/*
* alarmcalendar.cpp - KAlarm calendar file access
* Program: kalarm
* Copyright © 2001-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2001-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
......@@ -899,7 +899,7 @@ bool AlarmCalendar::addEvent(KAEvent& evnt, QWidget* promptParent, bool useEvent
// Check that the event type is valid for the calendar
Resource nullresource;
Resource& resource(resourceptr ? *resourceptr : nullresource);
qCDebug(KALARM_LOG) << "AlarmCalendar::addEvent:" << evnt.id() << ", resource" << resource.id();
qCDebug(KALARM_LOG) << "AlarmCalendar::addEvent:" << evnt.id() << ", resource" << resource.displayId();
const CalEvent::Type type = evnt.category();
if (type != mEventType)
{
......
/*
* kalarmapp.cpp - the KAlarm application object
* Program: kalarm
* Copyright © 2001-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2001-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
......@@ -1199,7 +1199,7 @@ void KAlarmApp::purgeNewArchivedDefault(const Resource& resource)
{
if (Resources::isStandard(resource, CalEvent::ARCHIVED))
{
qCDebug(KALARM_LOG) << "KAlarmApp::purgeNewArchivedDefault:" << resource.id() << ": standard archived...";
qCDebug(KALARM_LOG) << "KAlarmApp::purgeNewArchivedDefault:" << resource.displayId() << ": standard archived...";
if (mArchivedPurgeDays >= 0)
purge(mArchivedPurgeDays);
else
......
/*
* akonadidatamodel.cpp - KAlarm calendar file access using Akonadi
* Program: kalarm
* Copyright © 2007-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2007-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
......@@ -405,7 +405,7 @@ bool AkonadiDataModel::reload(const Resource& resource)
{
if (!resource.isValid())
return false;
qCDebug(KALARM_LOG) << "AkonadiDataModel::reload:" << resource.id();
qCDebug(KALARM_LOG) << "AkonadiDataModel::reload:" << resource.displayId();
Collection collection(resource.id());
mMonitor->setCollectionMonitored(collection, false);
mMonitor->setCollectionMonitored(collection, true);
......
/*
* akonadiresource.cpp - class for an Akonadi alarm calendar resource
* 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
......@@ -380,7 +380,7 @@ bool AkonadiResource::removeResource()
{
if (!isValid())
return false;
qCDebug(KALARM_LOG) << "AkonadiResource::removeResource:" << id();
qCDebug(KALARM_LOG) << "AkonadiResource::removeResource:" << displayId();
notifyDeletion();
// Note: Don't use CollectionDeleteJob, since that also deletes the backend storage.
AgentManager* agentManager = AgentManager::self();
......@@ -399,7 +399,7 @@ void AkonadiResource::slotCollectionRemoved(const Collection& collection)
{
if (collection.id() == id())
{
qCDebug(KALARM_LOG) << "AkonadiResource::slotCollectionRemoved:" << id();
qCDebug(KALARM_LOG) << "AkonadiResource::slotCollectionRemoved:" << displayId();
disconnect(AkonadiDataModel::monitor(), nullptr, this, nullptr);
ResourceType::removeResource(collection.id());
}
......
/*
* resource.cpp - generic class containing an alarm calendar resource
* 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
......@@ -78,6 +78,11 @@ ResourceId Resource::id() const
return mResource.isNull() ? -1 : mResource->id();
}
ResourceId Resource::displayId() const
{
return mResource.isNull() ? -1 : mResource->displayId();
}
Resource::StorageType Resource::storageType() const
{
return mResource.isNull() ? NoStorage : static_cast<StorageType>(mResource->storageType());
......@@ -88,6 +93,11 @@ QString Resource::storageTypeString(bool description) const
return mResource.isNull() ? QString() : mResource->storageTypeString(description);
}
QString Resource::storageTypeString(ResourceType::StorageType type)
{
return ResourceType::storageTypeString(type);
}
QUrl Resource::location() const
{
return mResource.isNull() ? QUrl() : mResource->location();
......
/*
* resource.h - generic class containing an alarm calendar resource
* 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
......@@ -73,6 +73,9 @@ public:
/** Return the resource's unique ID. */
ResourceId id() const;
/** Return the resource's unique ID, as shown to the user. */
ResourceId displayId() const;
/** Return the type of storage used by the resource. */
StorageType storageType() const;
......@@ -83,6 +86,11 @@ public:
*/
QString storageTypeString(bool description) const;
/** Return the type description of a resource (file, remote file, etc.)
* for display purposes. This is equivalent to storageTypeString(true).
*/
static QString storageTypeString(ResourceType::StorageType);
/** Return the location(s) of the resource (URL, file path, etc.) */
QUrl location() const;
......
/*
* resourcedatamodelbase.cpp - base for models containing calendars and events
* Program: kalarm
* Copyright © 2007-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2007-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
......@@ -157,6 +157,9 @@ QVariant ResourceDataModelBase::headerData(int section, Qt::Orientation orientat
return QVariant();
}
/******************************************************************************
* Return whether resourceData() or eventData() handle a role.
*/
bool ResourceDataModelBase::roleHandled(int role) const
{
switch (role)
......
/*
* resourcemodel.cpp - models containing flat list of resources
* Program: kalarm
* Copyright © 2007-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2007-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
......@@ -421,9 +421,9 @@ void ResourceCheckListModel::resourceSettingsChanged(Resource& res, ResourceType
return;
if (change & ResourceType::Enabled)
qCDebug(KALARM_LOG) << debugType("resourceSettingsChanged").constData() << res.id() << "Enabled" << res.enabledTypes();
qCDebug(KALARM_LOG) << debugType("resourceSettingsChanged").constData() << res.displayId() << "Enabled" << res.enabledTypes();
if (change & ResourceType::AlarmTypes)
qCDebug(KALARM_LOG) << debugType("resourceSettingsChanged").constData() << res.id() << "AlarmTypes" << res.alarmTypes();
qCDebug(KALARM_LOG) << debugType("resourceSettingsChanged").constData() << res.displayId() << "AlarmTypes" << res.alarmTypes();
const QModelIndex ix = mModel->resourceIndex(res);
if (ix.isValid())
......
/*
* resource.cpp - generic class containing an alarm calendar resource
* 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
......@@ -450,7 +450,7 @@ void Resources::notifySettingsChanged(ResourceType* res, ResourceType::Changes c
if ((change & ResourceType::ReadOnly) && res->readOnly())
{
qCDebug(KALARM_LOG) << "Resources::notifySettingsChanged:" << res->id() << "ReadOnly";
qCDebug(KALARM_LOG) << "Resources::notifySettingsChanged:" << res->displayId() << "ReadOnly";
// A read-only resource can't be the default for any alarm type
const CalEvent::Types std = standardTypes(r, false);
if (std != CalEvent::EMPTY)
......
/*
* resourcetype.cpp - base class for an alarm calendar resource type
* 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
......@@ -42,6 +42,11 @@ bool ResourceType::failed() const
return mFailed || !isValid();
}
ResourceId ResourceType::displayId() const
{
return id();
}
bool ResourceType::isEnabled(CalEvent::Type type) const
{
return (type == CalEvent::EMPTY) ? enabledTypes() : enabledTypes() & type;
......@@ -295,7 +300,19 @@ void ResourceType::setFailed()
mFailed = true;
}
QString ResourceType::storageTypeStr(bool description, bool file, bool local) const
QString ResourceType::storageTypeString(StorageType type)
{
switch (type)
{
case File:
case Directory:
return storageTypeStr(true, (type == File), true);
default:
return QString();
}
}
QString ResourceType::storageTypeStr(bool description, bool file, bool local)
{
if (description)
return file ? i18nc("@info", "KAlarm Calendar File") : i18nc("@info", "KAlarm Calendar Directory");
......
/*
* resourcetype.h - base class for an alarm calendar resource type
* 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
......@@ -96,6 +96,9 @@ public:
/** Return the resource's unique ID. */
ResourceId id() const { return mId; }
/** Return the resource's unique ID, as shown to the user. */
virtual ResourceId displayId() const;
/** Return the type of storage used by the resource. */
virtual StorageType storageType() const = 0;
......@@ -106,6 +109,11 @@ public:
*/
virtual QString storageTypeString(bool description) const = 0;
/** Return the type description of a resource (file, remote file, etc.)
* for display purposes. This is equivalent to storageTypeString(true).
*/
static QString storageTypeString(StorageType);
/** Return the location(s) of the resource (URL, file path, etc.) */
virtual QUrl location() const = 0;
......@@ -423,7 +431,7 @@ protected:
*/
void setFailed();
QString storageTypeStr(bool description, bool file, bool local) const;
static QString storageTypeStr(bool description, bool file, bool local);
template <class T> static T* resource(Resource&);
template <class T> static const T* resource(const Resource&);
......
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