Tag Parser  6.5.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
statusprovider.cpp
Go to the documentation of this file.
1 #include "./statusprovider.h"
2 
3 #include <c++utilities/conversion/stringbuilder.h>
4 
5 using namespace std;
6 using namespace ConversionUtilities;
7 
8 namespace Media {
9 
20 StatusProvider::StatusProvider() :
21  m_worstNotificationType(NotificationType::None),
22  m_percentage(0.0),
23  m_abort(false),
24  m_forward(nullptr)
25 {}
26 
37 {
38  size_t id = 0;
39  for(auto &registred : m_callbacks) {
40  if(!registred) {
41  registred = callback;
42  return id;
43  }
44  ++id;
45  }
46  m_callbacks.push_back(callback);
47  return id;
48 }
49 
54 {
55  m_notifications.push_back(notification);
56  m_worstNotificationType |= notification.type();
57  invokeCallbacks();
58 }
59 
64 void StatusProvider::addNotification(NotificationType type, const string &message, const string &context)
65 {
66  m_notifications.emplace_back(type, message, context);
67  m_worstNotificationType |= type;
68  invokeCallbacks();
69 }
70 
76 {
77  if(&from == this) {
78  return;
79  }
80  m_notifications.insert(m_notifications.end(), from.m_notifications.cbegin(), from.m_notifications.cend());
81  m_worstNotificationType |= from.worstNotificationType();
82  invokeCallbacks();
83 }
84 
91 void StatusProvider::addNotifications(const string &higherContext, const StatusProvider &from)
92 {
93  if(&from == this) {
94  return;
95  }
96  for(const auto &notification : from.m_notifications) {
97  addNotification(notification.type(), notification.message(), higherContext % ',' % ' ' + notification.context());
98  }
99 }
100 
105 {
106  m_notifications.insert(m_notifications.end(), notifications.cbegin(), notifications.cend());
107  if(m_worstNotificationType != Notification::worstNotificationType()) {
108  for(const Notification &notification : notifications) {
109  if((m_worstNotificationType |= notification.type()) == Notification::worstNotificationType()) {
110  break;
111  }
112  }
113  }
114  invokeCallbacks();
115 }
116 
117 }
size_t registerCallback(CallbackFunction callback)
Registers a callback function.
const NotificationList & notifications() const
Returns notifications for the current object.
NotificationType
Specifies the notification type.
Definition: notification.h:18
NotificationType worstNotificationType() const
Returns the worst notification type.
STL namespace.
void addNotification(const Notification &notification)
This method is meant to be called by the derived class to add a notification.
static constexpr NotificationType worstNotificationType()
Returns the worst notification type.
Definition: notification.h:99
std::function< void(StatusProvider &sender)> CallbackFunction
NotificationType type() const
Returns the notification type.
Definition: notification.h:67
std::list< Notification > NotificationList
Definition: notification.h:39
The Notification class holds a notification message of a certain notification type.
Definition: notification.h:43
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
The StatusProvider class acts as a base class for objects providing status information.
void addNotifications(const StatusProvider &from)
This method is meant to be called by the derived class to add all notifications from another StatusPr...