File indexing completed on 2024-04-28 15:39:42

0001 /* SPDX-FileCopyrightText: 2014 Jesper K. Pedersen <blackie@kde.org>
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef REMOTECOMMAND_H
0007 #define REMOTECOMMAND_H
0008 
0009 #include "SearchInfo.h"
0010 #include "Types.h"
0011 
0012 #include <QBuffer>
0013 #include <QDataStream>
0014 #include <QImage>
0015 #include <QMap>
0016 #include <QPainter>
0017 #include <QPair>
0018 #include <QString>
0019 #include <QStringList>
0020 #include <memory>
0021 
0022 namespace RemoteControl
0023 {
0024 class SerializerInterface;
0025 
0026 const int VERSION = 7;
0027 
0028 enum class CommandType {
0029     ThumbnailResult,
0030     CategoryListResult,
0031     SearchRequest,
0032     SearchResult,
0033     ThumbnailRequest,
0034     ThumbnailCancelRequest,
0035     TimeCommand,
0036     ImageDetailsRequest,
0037     ImageDetailsResult,
0038     CategoryItemsResult,
0039     StaticImageRequest,
0040     StaticImageResult,
0041     ToggleTokenRequest
0042 };
0043 
0044 class RemoteCommand
0045 {
0046 public:
0047     RemoteCommand(CommandType type);
0048     virtual ~RemoteCommand();
0049     virtual void encode(QDataStream &) const;
0050     virtual void decode(QDataStream &);
0051     CommandType commandType() const;
0052 
0053     void addSerializer(SerializerInterface *serializer);
0054     static std::unique_ptr<RemoteCommand> create(CommandType commandType);
0055 
0056 private:
0057     QList<SerializerInterface *> m_serializers;
0058     CommandType m_type;
0059 };
0060 
0061 class ThumbnailResult : public RemoteCommand
0062 {
0063 public:
0064     ThumbnailResult(ImageId imageId = {}, const QString &label = {}, const QImage &image = QImage(), ViewType type = {});
0065     ImageId imageId;
0066     QString label;
0067     QImage image;
0068     ViewType type;
0069 };
0070 
0071 struct Category {
0072     QString name;
0073     QImage icon;
0074     bool enabled;
0075     CategoryViewType viewType;
0076 };
0077 
0078 class CategoryListResult : public RemoteCommand
0079 {
0080 public:
0081     CategoryListResult();
0082     QList<Category> categories;
0083 };
0084 
0085 class SearchRequest : public RemoteCommand
0086 {
0087 public:
0088     SearchRequest(SearchType type = {}, const SearchInfo &searchInfo = {}, int size = {});
0089     SearchType type;
0090     SearchInfo searchInfo;
0091     int size; // Only used for SearchType::Categories
0092 };
0093 
0094 class SearchResult : public RemoteCommand
0095 {
0096 public:
0097     SearchResult(SearchType type = {}, const QList<int> &result = {});
0098     SearchType type;
0099     QList<int> result;
0100 };
0101 
0102 class ThumbnailRequest : public RemoteCommand
0103 {
0104 public:
0105     ThumbnailRequest(ImageId imageId = {}, const QSize &size = {}, ViewType type = {});
0106     ImageId imageId;
0107     QSize size;
0108     ViewType type;
0109 };
0110 
0111 class ThumbnailCancelRequest : public RemoteCommand
0112 {
0113 public:
0114     ThumbnailCancelRequest(ImageId imageId = {}, ViewType type = {});
0115     ImageId imageId;
0116     ViewType type;
0117 };
0118 
0119 class TimeCommand : public RemoteCommand
0120 {
0121 public:
0122     TimeCommand();
0123     void encode(QDataStream &stream) const override;
0124     void decode(QDataStream &stream) override;
0125 };
0126 
0127 class ImageDetailsRequest : public RemoteCommand
0128 {
0129 public:
0130     ImageDetailsRequest(ImageId imageId = {});
0131     ImageId imageId;
0132 };
0133 
0134 struct CategoryItemDetails {
0135     CategoryItemDetails(const QString &name = {}, const QString &age = {})
0136         : name(name)
0137         , age(age)
0138     {
0139     }
0140     QString name;
0141     QString age;
0142 };
0143 
0144 using CategoryItemDetailsList = QList<CategoryItemDetails>;
0145 
0146 class ImageDetailsResult : public RemoteCommand
0147 {
0148 public:
0149     ImageDetailsResult();
0150     QString fileName;
0151     QString date;
0152     QString description;
0153     QMap<QString, CategoryItemDetailsList> categories;
0154 };
0155 
0156 class CategoryItemsResult : public RemoteCommand
0157 {
0158 public:
0159     CategoryItemsResult(const QStringList &items = {});
0160     QStringList items;
0161 };
0162 
0163 class StaticImageRequest : public RemoteCommand
0164 {
0165 public:
0166     StaticImageRequest(int size = {});
0167     int size;
0168 };
0169 
0170 class StaticImageResult : public RemoteCommand
0171 {
0172 public:
0173     StaticImageResult(const QImage &homeIcon = {}, const QImage &kphotoalbumIcon = {}, const QImage &discoverIcon = {});
0174     QImage homeIcon;
0175     QImage kphotoalbumIcon;
0176     QImage discoverIcon;
0177 };
0178 
0179 class ToggleTokenRequest : public RemoteCommand
0180 {
0181 public:
0182     enum State { On,
0183                  Off };
0184     ToggleTokenRequest(ImageId imageId = {}, const QString &token = {}, State state = {});
0185     ImageId imageId;
0186     QString token;
0187     State state;
0188 };
0189 
0190 }
0191 #endif // REMOTECOMMAND_H