LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
notificationactionhandler.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
10 #include <QStringList>
11 
12 namespace LC::Util
13 {
15  : Entity_ (e)
16  {
17  Entity_.Additional_ [QStringLiteral ("HandlingObject")] = QVariant::fromValue (QObject_ptr (this));
18  }
19 
20  void NotificationActionHandler::AddFunction (const QString& name, Callback_t callback)
21  {
22  ActionName2Callback_ << qMakePair (name, callback);
23  static const auto notificationAction = QStringLiteral ("NotificationActions");
24  const QStringList& sl = Entity_.Additional_ [notificationAction].toStringList ();
25  Entity_.Additional_ [notificationAction] = sl + QStringList (name);
26  }
27 
29  {
30  DependentObjects_ << QPointer<QObject> (obj);
31  }
32 
34  {
35  if (std::any_of (DependentObjects_.begin (), DependentObjects_.end (),
36  [] (const auto& obj) { return obj.isNull (); }))
37  return;
38 
39  ActionName2Callback_.at (idx).second ();
40  }
41 }
UTIL_XPC_API void AddFunction(const QString &name, Callback_t action)
Adds an action with the given name.
UTIL_XPC_API NotificationActionHandler(Entity &entity, QObject *=nullptr)
Creates the handler on the given entity.
std::shared_ptr< QObject > QObject_ptr
Definition: structures.h:220
std::function< void()> Callback_t
Type of functions used as actions in the handler.
QMap< QString, QVariant > Additional_
Additional parameters.
Definition: structures.h:164
A message used for inter-plugin communication.
Definition: structures.h:95
UTIL_XPC_API void AddDependentObject(QObject *object)
Adds an object as a dependent object.