LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
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 <memory>
12 #include <QtPlugin>
13 #include "interfaces/structures.h"
14 
15 class QAbstractItemModel;
16 class QMenu;
17 class QModelIndex;
18 class QToolBar;
19 
20 template<typename>
21 class QList;
22 
23 namespace LC
24 {
25  enum class ProcessKind : std::uint8_t
26  {
27  Download,
28  Upload,
29  Generic,
30  };
31 
41  struct ProcessInfo
42  {
43  TaskParameters Parameters_ {};
44 
46 
47  bool operator== (const ProcessInfo& other) const = default;
48  };
49 
50  struct NewsInfo
51  {
52  qlonglong Count_ = 0;
53  QDateTime LastUpdate_;
54 
55  bool operator== (const NewsInfo& other) const = default;
56  };
57 
58  using SpecificInfo = std::variant<
60  NewsInfo
61  >;
62 
63  struct RowInfo
64  {
65  QString Name_;
67 
68  bool operator== (const RowInfo& other) const = default;
69  };
70 
71  enum class ProcessState : std::uint8_t
72  {
73  Running,
74  Paused,
75  Finished,
76  Error,
77  Unknown,
78  };
79 
82  enum class JobHolderRole
83  {
89  };
90 
91  constexpr int operator+ (JobHolderRole role) noexcept
92  {
93  return static_cast<int> (role);
94  }
95 
96  template<>
98 
100  {
101  Done = MaxValue<JobHolderRole> + 1, // qint64
102  Total, // qint64
103  ProgressCustomText, // QString
104  State, // ProcessState
105  StateCustomText, // QString
106  };
107 
109  {
110  return static_cast<int> (role);
111  }
112 
113  template<>
115 }
116 
118 {
119 public:
120  virtual ~IJobHolderRepresentationHandler () = default;
121 
154  virtual QAbstractItemModel& GetRepresentation () = 0;
155 
156  virtual void HandleCurrentChanged (const QModelIndex&) {}
157  virtual void HandleCurrentColumnChanged (const QModelIndex&) {}
158  virtual void HandleCurrentRowChanged (const QModelIndex&) {}
160 
161  virtual void HandleActivated (const QModelIndex&) {}
162  virtual void HandleClicked (const QModelIndex&) {}
163  virtual void HandleDoubleClicked (const QModelIndex&) {}
164  virtual void HandleEntered (const QModelIndex&) {}
165  virtual void HandlePressed (const QModelIndex&) {}
166 
167  virtual QWidget* GetInfoWidget () { return nullptr; }
168  virtual QToolBar* GetControls () { return nullptr; }
169  virtual QMenu* GetContextMenu () { return nullptr; }
170 };
171 
172 using IJobHolderRepresentationHandler_ptr = std::unique_ptr<IJobHolderRepresentationHandler>;
173 
198 class Q_DECL_EXPORT IJobHolder
199 {
200 protected:
201  virtual ~IJobHolder () = default;
202 public:
203  virtual IJobHolderRepresentationHandler_ptr CreateRepresentationHandler () = 0;
204 };
205 
208 
209 Q_DECLARE_INTERFACE (IJobHolder, "org.Deviant.LeechCraft.IJobHolder/1.0")
virtual ~IJobHolderRepresentationHandler()=default
bool operator==(const ProcessInfo &other) const =default
virtual void HandleClicked(const QModelIndex &)
Definition: ijobholder.h:162
virtual void HandleCurrentRowChanged(const QModelIndex &)
Definition: ijobholder.h:158
constexpr int operator+(JobHolderRole role) noexcept
Definition: ijobholder.h:91
ProcessKind
Definition: ijobholder.h:25
virtual QWidget * GetInfoWidget()
Definition: ijobholder.h:167
virtual QToolBar * GetControls()
Definition: ijobholder.h:168
virtual void HandleActivated(const QModelIndex &)
Definition: ijobholder.h:161
ProcessKind Kind_
Definition: ijobholder.h:45
bool operator==(const RowInfo &other) const =default
virtual void HandleEntered(const QModelIndex &)
Definition: ijobholder.h:164
TaskParameters Parameters_
Definition: ijobholder.h:43
Describes a process represented by a row in an IJobHolder model.
Definition: ijobholder.h:41
JobHolderRole
This enum contains roles that are used to query job states.
Definition: ijobholder.h:82
std::unique_ptr< IJobHolderRepresentationHandler > IJobHolderRepresentationHandler_ptr
Definition: ijobholder.h:172
constexpr int MaxValue< JobHolderProcessRole >
Definition: ijobholder.h:114
Interface for plugins holding jobs or persistent notifications.
Definition: ijobholder.h:198
std::variant< ProcessInfo, NewsInfo > SpecificInfo
Definition: ijobholder.h:61
virtual QAbstractItemModel & GetRepresentation()=0
Returns the item representation model.
virtual void HandleDoubleClicked(const QModelIndex &)
Definition: ijobholder.h:163
Q_DECLARE_METATYPE(QVariantList *)
bool operator==(const NewsInfo &other) const =default
virtual void HandleSelectedRowsChanged(const QList< QModelIndex > &)
Definition: ijobholder.h:159
auto Tup2 &&tup2 noexcept
Definition: ctstringutils.h:68
virtual void HandleCurrentChanged(const QModelIndex &)
Definition: ijobholder.h:156
QString Name_
Definition: ijobholder.h:65
virtual void HandleCurrentColumnChanged(const QModelIndex &)
Definition: ijobholder.h:157
SpecificInfo Specific_
Definition: ijobholder.h:66
constexpr int MaxValue< JobHolderRole >
Definition: ijobholder.h:97
constexpr int MaxValue< CustomDataRoles >
Definition: structures.h:188
virtual QMenu * GetContextMenu()
Definition: ijobholder.h:169
ProcessState
Definition: ijobholder.h:71
QDateTime LastUpdate_
Definition: ijobholder.h:53
virtual void HandlePressed(const QModelIndex &)
Definition: ijobholder.h:165
qlonglong Count_
Definition: ijobholder.h:52
JobHolderProcessRole
Definition: ijobholder.h:99