Changeset View
Changeset View
Standalone View
Standalone View
src/core/interfaces/Logger.h
Show All 13 Lines | |||||
14 | * this program. If not, see <http://www.gnu.org/licenses/>. * | 14 | * this program. If not, see <http://www.gnu.org/licenses/>. * | ||
15 | ****************************************************************************************/ | 15 | ****************************************************************************************/ | ||
16 | 16 | | |||
17 | #ifndef AMAROK_LOGGER_H | 17 | #ifndef AMAROK_LOGGER_H | ||
18 | #define AMAROK_LOGGER_H | 18 | #define AMAROK_LOGGER_H | ||
19 | 19 | | |||
20 | #include "core/amarokcore_export.h" | 20 | #include "core/amarokcore_export.h" | ||
21 | 21 | | |||
22 | #include <QMetaType> | 22 | #include <QMetaMethod> | ||
23 | #include <QObject> | 23 | #include <QObject> | ||
24 | 24 | | |||
25 | #include <functional> | ||||
26 | | ||||
27 | | ||||
25 | class KJob; | 28 | class KJob; | ||
26 | class QNetworkReply; | 29 | class QNetworkReply; | ||
27 | 30 | | |||
28 | namespace Amarok | 31 | namespace Amarok | ||
29 | { | 32 | { | ||
30 | /** | 33 | /** | ||
31 | * This interface provides methods that allow backend components to notify the user. | 34 | * This interface provides methods that allow backend components to notify the user. | ||
32 | * Users of this class may not make assumptions about the kind of notifications that | 35 | * Users of this class may not make assumptions about the kind of notifications that | ||
33 | * will be sent to the user. | 36 | * will be sent to the user. | ||
34 | * | 37 | * | ||
35 | * The class name is up for discussion btw. | 38 | * The class name is up for discussion btw. | ||
36 | */ | 39 | */ | ||
37 | class AMAROK_CORE_EXPORT Logger | 40 | class AMAROK_CORE_EXPORT Logger | ||
38 | { | 41 | { | ||
39 | public: | 42 | public: | ||
40 | 43 | | |||
41 | enum MessageType { Information, Warning, Error }; | 44 | enum MessageType { Information, Warning, Error }; | ||
42 | 45 | | |||
43 | Logger() {} | 46 | Logger() {} | ||
44 | virtual ~Logger() {} | 47 | virtual ~Logger() {} | ||
45 | 48 | | |||
46 | public Q_SLOTS: | | |||
47 | | ||||
48 | /** | 49 | /** | ||
49 | * Informs the user about the progress of a job, i.e. a download job. | 50 | * Informs the user about the progress of a job, i.e. a download job. | ||
50 | * At the very least, the user is notified about the start and end of the job. | 51 | * At the very least, the user is notified about the start and end of the job. | ||
51 | * | 52 | * | ||
52 | * @param job The job whose progress should be monitored | 53 | * @param job The job whose progress should be monitored | ||
53 | * @param text An additional text that will be part of the notification | 54 | * @param text An additional text that will be part of the notification | ||
54 | * @param obj The object that will be called if the user cancels the job. If not set, the job will not be cancellable | 55 | * @param obj The object that will be called if the user cancels the job. If not set, the job will not be cancellable | ||
55 | * @param slot The slot on the given object that will be called if the user cancels the job. No slot will be called if not set. | 56 | * @param slot The slot on the given object that will be called if the user cancels the job. No slot will be called if not set. | ||
56 | * The signal will be emitted from the GUI thread. The receiver may not make assumptions about the sender | 57 | * The signal will be emitted from the GUI thread. The receiver may not make assumptions about the sender | ||
57 | * @param type The Qt connection type to use for the connection to the receiving slot. Defaults to Qt::AutoConnection | 58 | * @param type The Qt connection type to use for the connection to the receiving slot. Defaults to Qt::AutoConnection | ||
58 | */ | 59 | */ | ||
59 | virtual void newProgressOperation( KJob *job, const QString &text, QObject *obj = 0, const char *slot = 0, Qt::ConnectionType type = Qt::AutoConnection ) = 0; | 60 | template<class Object = QObject, class Func = void (QObject::*)(), class... FuncArgs> | ||
61 | void newProgressOperation( KJob *job, const QString &text, Object *obj = nullptr, Func slot = nullptr, Qt::ConnectionType type = Qt::AutoConnection, FuncArgs... args ) | ||||
heikobecker: This line seems to cause a build error on FreeBSD, which uses clang (contrary to the Linux… | |||||
62 | { | ||||
63 | std::function<void ()> function = [obj, slot, args...] () | ||||
64 | { | ||||
65 | ( *obj.*slot )( args... ); | ||||
66 | }; | ||||
67 | newProgressOperationImpl( job, text, obj, obj ? function : nullptr, type ); | ||||
68 | } | ||||
60 | 69 | | |||
61 | /** | 70 | /** | ||
62 | * Informs the user about the progress of a network request. | 71 | * Informs the user about the progress of a network request. | ||
63 | * At the very least, the user is notified about the start and end of the request. | 72 | * At the very least, the user is notified about the start and end of the request. | ||
64 | * | 73 | * | ||
65 | * @param reply The network reply object whose progress should be monitored | 74 | * @param reply The network reply object whose progress should be monitored | ||
66 | * @param text An additional text that will be part of the notification | 75 | * @param text An additional text that will be part of the notification | ||
67 | * @param obj The object that will be called if the user cancels the network request. If not set, the progress will not be cancellable | 76 | * @param obj The object that will be called if the user cancels the network request. If not set, the progress will not be cancellable | ||
68 | * @param slot The slot on the given object that will be called if the user cancels the network request. No slot will be called if not set. | 77 | * @param slot The slot on the given object that will be called if the user cancels the network request. No slot will be called if not set. | ||
69 | * The signal will be emitted from the GUI thread. The receiver may not make assumptions about the sender | 78 | * The signal will be emitted from the GUI thread. The receiver may not make assumptions about the sender | ||
70 | * @param type The Qt connection type to use for the connection to the receiving slot. Defaults to Qt::AutoConnection | 79 | * @param type The Qt connection type to use for the connection to the receiving slot. Defaults to Qt::AutoConnection | ||
71 | */ | 80 | */ | ||
72 | virtual void newProgressOperation( QNetworkReply *reply, const QString &text, QObject *obj = 0, const char *slot = 0, Qt::ConnectionType type = Qt::AutoConnection ) = 0; | 81 | template<class Object = QObject, class Func = void (QObject::*)(), class... FuncArgs> | ||
82 | void newProgressOperation( QNetworkReply *reply, const QString &text, Object *obj = nullptr, Func slot = nullptr, Qt::ConnectionType type = Qt::AutoConnection, FuncArgs... args ) | ||||
83 | { | ||||
84 | std::function<void ()> function = [obj, slot, args...] () | ||||
85 | { | ||||
86 | ( *obj.*slot )( args... ); | ||||
87 | }; | ||||
88 | newProgressOperationImpl( reply, text, obj, obj ? function : nullptr, type ); | ||||
89 | } | ||||
73 | 90 | | |||
74 | /** | 91 | /** | ||
75 | * Informs the user about the progress of a generic QObject | 92 | * Informs the user about the progress of a generic QObject | ||
76 | * | 93 | * | ||
77 | * @param sender The object sending the required signals. This sender must emit singals | 94 | * @param sender The object sending the required signals. This sender must emit signals | ||
78 | * incrementProgress() and endProgressOperation() and optionally totalSteps(). | 95 | * incrementProgress() and endProgressOperation() and optionally totalSteps(). | ||
79 | * @param text An additional text that will be part of the notification | 96 | * @param text An additional text that will be part of the notification | ||
80 | * @param maximum The maximum value of the progress operation | 97 | * @param maximum The maximum value of the progress operation | ||
81 | * @param obj The object that will be called if the user cancels the network request. If not | 98 | * @param obj The object that will be called if the user cancels the network request. If not | ||
82 | * set, the progress will not be cancellable | 99 | * set, the progress will not be cancellable | ||
83 | * @param slot The slot on the given object that will be called if the user cancels the | 100 | * @param slot The slot on the given object that will be called if the user cancels the | ||
84 | * network request. No slot will be called if not set. | 101 | * network request. No slot will be called if not set. | ||
85 | * The signal will be emitted from the GUI thread. The receiver may not make assumptions | 102 | * The signal will be emitted from the GUI thread. The receiver may not make assumptions | ||
86 | * about the sender | 103 | * about the sender | ||
87 | * @param type The Qt connection type to use for the connection to the receiving slot. | 104 | * @param type The Qt connection type to use for the connection to the receiving slot. | ||
88 | * Defaults to Qt::AutoConnection | 105 | * Defaults to Qt::AutoConnection | ||
89 | */ | 106 | */ | ||
90 | virtual void newProgressOperation( QObject *sender, const QString &text, int maximum = 100, | 107 | template<class Sender, class Object = QObject, class Func = void (QObject::*)(), class... FuncArgs> | ||
91 | QObject *obj = 0, const char *slot = 0, | 108 | typename std::enable_if<!std::is_convertible<Sender*, KJob*>::value && !std::is_convertible<Sender*, QNetworkReply*>::value && std::is_convertible<Sender*, QObject*>::value>::type | ||
92 | Qt::ConnectionType type = Qt::AutoConnection ) = 0; | 109 | newProgressOperation( Sender *sender, const QString &text, int maximum = 100, Object *obj = nullptr, Func slot = nullptr, Qt::ConnectionType type = Qt::AutoConnection, FuncArgs... args ) | ||
110 | { | ||||
111 | auto increment = QMetaMethod::fromSignal( &Sender::incrementProgress ); | ||||
112 | auto end = QMetaMethod::fromSignal( &Sender::endProgressOperation ); | ||||
113 | | ||||
114 | std::function<void ()> function = [obj, slot, args...] () | ||||
115 | { | ||||
116 | ( *obj.*slot )( args... ); | ||||
117 | }; | ||||
118 | newProgressOperationImpl( sender, increment, end, text, maximum, obj, obj ? function : nullptr, type ); | ||||
119 | } | ||||
93 | 120 | | |||
94 | /** | 121 | /** | ||
95 | * Sends a notification to the user. | 122 | * Sends a notification to the user. | ||
96 | * This method will send a notification containing the given text to the user. | 123 | * This method will send a notification containing the given text to the user. | ||
97 | * | 124 | * | ||
98 | * @param text The text that the notification will contain | 125 | * @param text The text that the notification will contain | ||
99 | */ | 126 | */ | ||
100 | virtual void shortMessage( const QString &text ) = 0; | 127 | virtual void shortMessage( const QString &text ) = 0; | ||
101 | 128 | | |||
102 | /** | 129 | /** | ||
103 | * Send a notification to the user with an additional context. | 130 | * Send a notification to the user with an additional context. | ||
104 | * A notification will be send to the user containing the given text. Additionally, it will convey the context given by @p type. | 131 | * A notification will be send to the user containing the given text. Additionally, it will convey the context given by @p type. | ||
105 | * @param text The text that the notification will contain | 132 | * @param text The text that the notification will contain | ||
106 | * @param type The context of the notification | 133 | * @param type The context of the notification | ||
107 | */ | 134 | */ | ||
108 | virtual void longMessage( const QString &text, MessageType type = Information ) = 0; | 135 | virtual void longMessage( const QString &text, MessageType type = Information ) = 0; | ||
136 | | ||||
137 | virtual void newProgressOperationImpl( KJob *job, const QString &text, QObject *context, const std::function<void ()> &function, Qt::ConnectionType type ) = 0; | ||||
138 | virtual void newProgressOperationImpl( QNetworkReply *reply, const QString &text, QObject *context, const std::function<void ()> &function, Qt::ConnectionType type ) = 0; | ||||
139 | virtual void newProgressOperationImpl( QObject *sender, const QMetaMethod &increment, const QMetaMethod &end, const QString &text, | ||||
140 | int maximum, QObject *context, const std::function<void ()> &function, Qt::ConnectionType type ) = 0; | ||||
109 | }; | 141 | }; | ||
110 | } | 142 | } | ||
111 | 143 | | |||
112 | #endif | 144 | #endif |
This line seems to cause a build error on FreeBSD, which uses clang (contrary to the Linux build):
"error: missing default argument on parameter 'args' void newProgressOperation( KJob *job, const QString &text, Object *obj = nullptr, Func slot = nullptr, Qt::ConnectionType type = Qt::AutoConnection, FuncArgs... args )
Full log: https://build.kde.org/job/Extragear%20amarok%20kf5-qt5%20FreeBSDQt5.9/38/console