File indexing completed on 2024-05-19 04:07:53

0001 /*
0002     SPDX-FileCopyrightText: 2011 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PALAPELI_COMPONENTS_H
0008 #define PALAPELI_COMPONENTS_H
0009 
0010 #include "puzzle.h"
0011 #include "puzzlestructs.h"
0012 
0013 class KConfigGroup;
0014 class QTemporaryDir;
0015 
0016 #define COMPONENT_SUBCLASS(mytype) \
0017     public: \
0018     enum { ComponentType = mytype }; \
0019     Type type() const override { return mytype; }
0020 
0021 namespace Palapeli
0022 {
0023     class MetadataComponent : public Palapeli::PuzzleComponent
0024     {
0025         COMPONENT_SUBCLASS(Metadata)
0026         public:
0027             explicit MetadataComponent(const Palapeli::PuzzleMetadata& metadata) : metadata(metadata) {}
0028 
0029             Palapeli::PuzzleMetadata metadata;
0030     };
0031 
0032     class ContentsComponent : public Palapeli::PuzzleComponent
0033     {
0034         COMPONENT_SUBCLASS(Contents)
0035         public:
0036             explicit ContentsComponent(const Palapeli::PuzzleContents& contents) : contents(contents) {}
0037 
0038             Palapeli::PuzzleContents contents;
0039     };
0040 
0041     ///This is a valid mainComponent.
0042     class CreationContextComponent : public Palapeli::PuzzleComponent
0043     {
0044         COMPONENT_SUBCLASS(CreationContext)
0045         public:
0046             explicit CreationContextComponent(const Palapeli::PuzzleCreationContext& creationContext) : creationContext(creationContext) {}
0047 
0048             Palapeli::PuzzleCreationContext creationContext;
0049             Palapeli::PuzzleComponent* cast(Type type) const override;
0050     };
0051 
0052     ///This component copies the data (i.e. everything in puzzlestructs.h) from
0053     ///an existing puzzle. This is a valid mainComponent.
0054     class CopyComponent : public Palapeli::PuzzleComponent
0055     {
0056         COMPONENT_SUBCLASS(Copy)
0057         public:
0058             explicit CopyComponent(Palapeli::Puzzle* puzzle);
0059 
0060             Palapeli::PuzzleComponent* cast(Type type) const override;
0061         private:
0062             Palapeli::Puzzle* m_puzzle;
0063     };
0064 
0065     ///This is a valid mainComponent.
0066     class DirectoryStorageComponent : public Palapeli::PuzzleComponent
0067     {
0068         COMPONENT_SUBCLASS(DirectoryStorage)
0069         public:
0070             DirectoryStorageComponent();
0071             static Palapeli::DirectoryStorageComponent* fromData(Palapeli::Puzzle* puzzle);
0072             ~DirectoryStorageComponent() override;
0073 
0074             QString directory() const;
0075             Palapeli::PuzzleComponent* cast(Type type) const override;
0076         private:
0077             QTemporaryDir* m_dir;
0078     };
0079 
0080     ///This is a valid mainComponent.
0081     class ArchiveStorageComponent : public Palapeli::PuzzleComponent
0082     {
0083         COMPONENT_SUBCLASS(ArchiveStorage)
0084         public:
0085             ArchiveStorageComponent();
0086             static Palapeli::ArchiveStorageComponent* fromData(Palapeli::Puzzle* puzzle);
0087 
0088             Palapeli::PuzzleComponent* cast(Type type) const override;
0089     };
0090 
0091     ///This is a valid mainComponent.
0092     class CollectionStorageComponent : public Palapeli::PuzzleComponent
0093     {
0094         COMPONENT_SUBCLASS(CollectionStorage)
0095         public:
0096             ///Takes ownership of @a group.
0097             CollectionStorageComponent(KConfigGroup* group);
0098             ~CollectionStorageComponent() override;
0099 
0100             Palapeli::PuzzleComponent* cast(Type type) const override;
0101         private:
0102             KConfigGroup* m_group;
0103     };
0104 
0105     ///This is used by the collection if, instead of an actual puzzle archive,
0106     ///only a desktop file and an image is available (like for the puzzles from
0107     ///the default collection).
0108     class RetailStorageComponent : public Palapeli::PuzzleComponent
0109     {
0110         COMPONENT_SUBCLASS(RetailStorage)
0111         public:
0112             explicit RetailStorageComponent(const QString& desktopFile);
0113 
0114             Palapeli::PuzzleComponent* cast(Type type) const override;
0115         private:
0116             QString m_desktopFile;
0117     };
0118 }
0119 
0120 #undef COMPONENT_SUBCLASS
0121 
0122 #endif // PALAPELI_COMPONENTS_H