1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "PVREventLogJob.h"
10
11 #include "ServiceBroker.h"
12 #include "dialogs/GUIDialogKaiToast.h"
13 #include "events/EventLog.h"
14 #include "events/NotificationEvent.h"
15
16 namespace PVR
17 {
18
CPVREventLogJob(bool bNotifyUser,bool bError,const std::string & label,const std::string & msg,const std::string & icon)19 CPVREventLogJob::CPVREventLogJob(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon)
20 {
21 AddEvent(bNotifyUser, bError, label, msg, icon);
22 }
23
AddEvent(bool bNotifyUser,bool bError,const std::string & label,const std::string & msg,const std::string & icon)24 void CPVREventLogJob::AddEvent(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon)
25 {
26 m_events.emplace_back(Event(bNotifyUser, bError, label, msg, icon));
27 }
28
DoWork()29 bool CPVREventLogJob::DoWork()
30 {
31 for (const auto& event : m_events)
32 {
33 if (event.m_bNotifyUser)
34 CGUIDialogKaiToast::QueueNotification(
35 event.m_bError ? CGUIDialogKaiToast::Error : CGUIDialogKaiToast::Info, event.m_label.c_str(), event.m_msg, 5000, true);
36
37 // Write event log entry.
38 CServiceBroker::GetEventLog().Add(
39 std::make_shared<CNotificationEvent>(event.m_label, event.m_msg, event.m_icon, event.m_bError ? EventLevel::Error : EventLevel::Information));
40 }
41 return true;
42 }
43
44 } // namespace PVR
45