#include <calendar.h>
Public Member Functions | |
CalendarInstance (nap::Core &core) | |
CalendarInstance (const CalendarInstance &rhs)=delete | |
CalendarInstance & | operator= (const CalendarInstance &rhs)=delete |
bool | init (const std::string &name, bool allowFailure, CalendarItemList defaultItems, utility::ErrorState &error) |
const std::string & | getName () const |
std::string | getPath () const |
const OwnedCalendarItemList & | getItems () const |
template<typename T > | |
void | getItems (std::vector< T * > &outItems) const |
void | addItem (std::unique_ptr< CalendarItem > item) |
template<typename T , typename... Args> | |
T * | addItem (Args &&... args) |
bool | removeItem (const std::string &id) |
CalendarItem * | findByID (const std::string &id) |
template<typename T > | |
T * | findByID (const std::string &id) |
CalendarItem * | findByTitle (const std::string &title) |
template<typename T > | |
T * | findByTitle (const std::string &title) |
bool | save (utility::ErrorState &error) |
Public Attributes | |
Signal< const CalendarItem & > | itemRemoved |
Called when an item is about to be removed. More... | |
Signal< const CalendarItem & > | itemAdded |
Called when an item is added. More... | |
OwnedCalendarItemList | mItems |
List of unique calendar items. More... | |
std::string | mName |
Calendar name. More... | |
std::string | mPath |
Path to calendar file on disk. More... | |
nap::Core & | mCore |
NAP core. More... | |
Actual runtime version of a simple calendar, created by a nap::ICalendar resource on initialization. Allows for inspection, creation, loading and saving of calendar items. This model is: NOT THREAD SAFE. Don't edit, remove or add items on a different thread!
CalendarInstance | ( | nap::Core & | core | ) |
|
delete |
T * addItem | ( | Args &&... | args | ) |
Creates, initializes and adds a new item of the given type T to the calendar. Item must be of type: nap::CalendarItem and is given a unique id. The item is managed by the calendar.
args | specific calendar item construction arguments |
void addItem | ( | std::unique_ptr< CalendarItem > | item | ) |
Adds an item to this calendar. This call does not initialize the item for you. The new item must be initialized and valid. Ownership is transferred.
item | the item to add |
CalendarItem* findByID | ( | const std::string & | id | ) |
Find a calendar item by ID
id | item unique ID |
T* findByID | ( | const std::string & | id | ) |
Find a calendar item of type T by ID
id | item unique ID |
CalendarItem* findByTitle | ( | const std::string & | title | ) |
Find a calendar item by title, case sensitive.
title | item title |
T* findByTitle | ( | const std::string & | title | ) |
Find a calendar item of type T by title, case sensitive.
title | item title |
const OwnedCalendarItemList& getItems | ( | ) | const |
void getItems | ( | std::vector< T * > & | outItems | ) | const |
Returns all calendar items of type T. List is not cleared.
outItems | all calendar items of type T |
const std::string& getName | ( | ) | const |
std::string getPath | ( | ) | const |
bool init | ( | const std::string & | name, |
bool | allowFailure, | ||
CalendarItemList | defaultItems, | ||
utility::ErrorState & | error | ||
) |
Initialize the calendar using the given name and items. If a calendar with the given name is present on disk, it is loaded instead. Call saveCalendar() to write the calendar to disk.
name | name of the calendar to create |
allowFailure | if default items are created when loading from disk fails (file might be corrupt for example). |
defaultItems | default set of items to create calendar with |
error | contains the error if initialization fails |
|
delete |
bool removeItem | ( | const std::string & | id | ) |
Remove an item based on id. Note that handles are invalid after this call.
id | the unique id of the item to remove |
bool save | ( | utility::ErrorState & | error | ) |
Writes the calendar to disk.
error | contains the error if writing fails |
Signal<const CalendarItem&> itemAdded |
Called when an item is added.
Signal<const CalendarItem&> itemRemoved |
Called when an item is about to be removed.
nap::Core& mCore |
NAP core.
OwnedCalendarItemList mItems |
List of unique calendar items.
std::string mName |
Calendar name.
std::string mPath |
Path to calendar file on disk.