LeechCraft 0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
ijobholder.h
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
9#pragma once
10
11#include <concepts>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <vector>
16#include <QDateTime>
17#include <QModelIndex>
18#include <QObject>
20
21class QAbstractItemModel;
22class QMenu;
23class QToolBar;
24
25template<typename>
26class QList;
27
28namespace LC
29{
30 enum class ProcessKind : std::uint8_t
31 {
35 };
36
47 {
48 TaskParameters Parameters_ {};
49
51
52 bool operator== (const ProcessInfo& other) const = default;
53 };
54
55 struct NewsInfo
56 {
57 qlonglong Count_ = 0;
58 QDateTime LastUpdate_;
59
60 bool operator== (const NewsInfo& other) const = default;
61 };
62
63 using SpecificInfo = std::variant<
66 >;
67
68 struct RowInfo
69 {
70 QString Name_;
72
73 bool operator== (const RowInfo& other) const = default;
74 };
75
76 enum class ProcessState : std::uint8_t
77 {
83 };
84
95
96 constexpr int operator+ (JobHolderRole role) noexcept
97 {
98 return static_cast<int> (role);
99 }
100
101 template<>
103
105 {
107 Total, // qint64
109 State, // ProcessState
110 StateCustomText, // QString
111 };
112
113 constexpr int operator+ (JobHolderProcessRole role) noexcept
114 {
115 return static_cast<int> (role);
116 }
117
118 template<>
120}
121
123{
124public:
126
160 virtual QAbstractItemModel& GetRepresentation () = 0;
161
165 {
167 QModelIndex Current_;
168
169 static RowSelection FromMaybe (const std::optional<QModelIndex>& row)
170 {
171 if (!row)
172 return {};
173 return FromSingle (*row);
174 }
175
176 static RowSelection FromSingle (const QModelIndex& row)
177 {
178 return { .Rows_ { row }, .Current_ { row } };
179 }
180 };
181
194 virtual void HandleSelectedRowsChanging ([[maybe_unused]] const RowSelection& selection) {}
195
206 virtual void HandleSelectedRowsSettled ([[maybe_unused]] const RowSelection& selection) {}
207
208 // Invoked synchronously from the corresponding QAbstractItemView signals.
209 virtual void HandleActivated (const QModelIndex&) {}
210 virtual void HandleClicked (const QModelIndex&) {}
211 virtual void HandleDoubleClicked (const QModelIndex&) {}
212 virtual void HandlePressed (const QModelIndex&) {}
213
214 virtual QWidget* GetInfoWidget () { return nullptr; }
215 virtual QToolBar* GetControls () { return nullptr; }
216 virtual QMenu* GetContextMenu () { return nullptr; }
217};
218
219using IJobHolderRepresentationHandler_ptr = std::unique_ptr<IJobHolderRepresentationHandler>;
220
246class Q_DECL_EXPORT IJobHolder
247{
248protected:
249 virtual ~IJobHolder () = default;
250public:
268
292 virtual std::vector<IJobHolderRepresentationHandler_ptr> CreateRepresentationHandlers (const ViewCallbacks& callbacks) = 0;
293protected:
300 template<std::derived_from<IJobHolderRepresentationHandler>... Handlers>
301 static std::vector<IJobHolderRepresentationHandler_ptr> MakeHandlers (std::unique_ptr<Handlers>... handlers)
302 {
303 std::vector<IJobHolderRepresentationHandler_ptr> result;
304 result.reserve (sizeof... (Handlers));
305 (result.push_back (std::move (handlers)), ...);
306 return result;
307 }
308};
309
312
313Q_DECLARE_INTERFACE (IJobHolder, "org.Deviant.LeechCraft.IJobHolder/1.0")
Interface for plugins holding jobs or persistent notifications.
Definition ijobholder.h:247
virtual std::vector< IJobHolderRepresentationHandler_ptr > CreateRepresentationHandlers(const ViewCallbacks &callbacks)=0
Creates the handlers representing the jobs of this plugin.
virtual ~IJobHolder()=default
static std::vector< IJobHolderRepresentationHandler_ptr > MakeHandlers(std::unique_ptr< Handlers >... handlers)
Wraps the given handlers into the list to be returned from CreateRepresentationHandlers().
Definition ijobholder.h:301
virtual void HandleActivated(const QModelIndex &)
Definition ijobholder.h:209
virtual ~IJobHolderRepresentationHandler()=default
virtual void HandleSelectedRowsChanging(const RowSelection &selection)
Called from a clean stack whenever the selection or the current row changes.
Definition ijobholder.h:194
virtual void HandleSelectedRowsSettled(const RowSelection &selection)
Called from a clean stack once the selection has settled.
Definition ijobholder.h:206
virtual QMenu * GetContextMenu()
Definition ijobholder.h:216
virtual QAbstractItemModel & GetRepresentation()=0
Returns the item representation model.
virtual QToolBar * GetControls()
Definition ijobholder.h:215
virtual void HandleClicked(const QModelIndex &)
Definition ijobholder.h:210
virtual QWidget * GetInfoWidget()
Definition ijobholder.h:214
virtual void HandleDoubleClicked(const QModelIndex &)
Definition ijobholder.h:211
virtual void HandlePressed(const QModelIndex &)
Definition ijobholder.h:212
std::unique_ptr< IJobHolderRepresentationHandler > IJobHolderRepresentationHandler_ptr
Definition ijobholder.h:219
Definition constants.h:15
constexpr int operator+(JobHolderRole role) noexcept
Definition ijobholder.h:96
constexpr int MaxValue
Definition maxvalue.h:14
ProcessState
Definition ijobholder.h:77
JobHolderProcessRole
Definition ijobholder.h:105
JobHolderRole
This enum contains roles that are used to query job states.
Definition ijobholder.h:88
std::variant< ProcessInfo, NewsInfo > SpecificInfo
Definition ijobholder.h:63
ProcessKind
Definition ijobholder.h:31
The callbacks into the view showing the handlers' representations.
Definition ijobholder.h:254
std::function< void(IJobHolderRepresentationHandler::RowSelection)> SetSelection_
Selects the given rows of the handler's representation.
Definition ijobholder.h:266
The rows of this handler's representation selected in the view.
Definition ijobholder.h:165
static RowSelection FromSingle(const QModelIndex &row)
Definition ijobholder.h:176
QModelIndex Current_
One of Rows_ (at the 0'th column), or invalid.
Definition ijobholder.h:167
static RowSelection FromMaybe(const std::optional< QModelIndex > &row)
Definition ijobholder.h:169
QList< QModelIndex > Rows_
The selected rows, at the 0'th column, in the view's order.
Definition ijobholder.h:166
qlonglong Count_
Definition ijobholder.h:57
bool operator==(const NewsInfo &other) const =default
QDateTime LastUpdate_
Definition ijobholder.h:58
Describes a process represented by a row in an IJobHolder model.
Definition ijobholder.h:47
bool operator==(const ProcessInfo &other) const =default
TaskParameters Parameters_
Definition ijobholder.h:48
ProcessKind Kind_
Definition ijobholder.h:50
SpecificInfo Specific_
Definition ijobholder.h:71
bool operator==(const RowInfo &other) const =default
QString Name_
Definition ijobholder.h:70
Q_DECLARE_METATYPE(QVariantList *)