2023-02-13 19:38:23 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
2024-04-16 19:05:04 +00:00
|
|
|
// ES-DE Frontend
|
2023-02-13 19:38:23 +00:00
|
|
|
// GuiThemeDownloader.h
|
|
|
|
//
|
|
|
|
// Theme downloader.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ES_APP_GUIS_GUI_THEME_DOWNLOADER_H
|
|
|
|
#define ES_APP_GUIS_GUI_THEME_DOWNLOADER_H
|
|
|
|
|
|
|
|
#include "GuiComponent.h"
|
2023-03-21 18:01:44 +00:00
|
|
|
#include "components/BusyComponent.h"
|
2023-03-22 19:56:48 +00:00
|
|
|
#include "components/ButtonComponent.h"
|
2023-02-13 19:38:23 +00:00
|
|
|
#include "components/ComponentGrid.h"
|
2023-03-22 19:56:48 +00:00
|
|
|
#include "components/ComponentList.h"
|
2023-03-29 17:08:22 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2023-02-13 19:38:23 +00:00
|
|
|
#include "components/NinePatchComponent.h"
|
2023-03-29 17:08:22 +00:00
|
|
|
#include "components/ScrollIndicatorComponent.h"
|
2023-02-13 19:38:23 +00:00
|
|
|
#include "components/TextComponent.h"
|
|
|
|
#include "renderers/Renderer.h"
|
|
|
|
#include "views/ViewController.h"
|
|
|
|
|
2023-03-21 18:01:44 +00:00
|
|
|
#include <git2/clone.h>
|
|
|
|
#include <git2/errors.h>
|
|
|
|
#include <git2/global.h>
|
|
|
|
#include <git2/merge.h>
|
|
|
|
#include <git2/reset.h>
|
|
|
|
#include <git2/revparse.h>
|
|
|
|
#include <git2/status.h>
|
2023-03-22 19:56:48 +00:00
|
|
|
#include <git2/version.h>
|
2023-03-21 18:01:44 +00:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <future>
|
|
|
|
#include <thread>
|
|
|
|
|
2023-02-13 19:38:23 +00:00
|
|
|
class GuiThemeDownloader : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2023-03-31 21:00:23 +00:00
|
|
|
GuiThemeDownloader(std::function<void()> updateCallback);
|
2023-03-21 18:01:44 +00:00
|
|
|
~GuiThemeDownloader();
|
2023-02-13 19:38:23 +00:00
|
|
|
|
2023-03-21 18:01:44 +00:00
|
|
|
void update(int deltaTime) override;
|
|
|
|
void render(const glm::mat4& parentTrans) override;
|
|
|
|
|
2023-02-13 19:38:23 +00:00
|
|
|
void onSizeChanged() override;
|
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
|
|
|
HelpStyle getHelpStyle() override { return ViewController::getInstance()->getViewHelpStyle(); }
|
|
|
|
|
|
|
|
private:
|
2023-03-27 19:29:37 +00:00
|
|
|
struct Screenshot {
|
|
|
|
std::string image;
|
|
|
|
std::string caption;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ThemeEntry {
|
|
|
|
std::string name;
|
|
|
|
std::string reponame;
|
|
|
|
std::string url;
|
|
|
|
std::string manualExtension;
|
2023-03-29 17:08:22 +00:00
|
|
|
std::string author;
|
2023-03-27 19:29:37 +00:00
|
|
|
std::vector<std::string> variants;
|
|
|
|
std::vector<std::string> colorSchemes;
|
|
|
|
std::vector<std::string> aspectRatios;
|
2023-12-20 21:30:11 +00:00
|
|
|
std::vector<std::string> fontSizes;
|
2023-03-27 19:29:37 +00:00
|
|
|
std::vector<std::string> transitions;
|
|
|
|
std::vector<Screenshot> screenshots;
|
2023-03-29 17:08:22 +00:00
|
|
|
bool newEntry;
|
2024-04-16 19:05:04 +00:00
|
|
|
bool deprecated;
|
2023-03-27 19:29:37 +00:00
|
|
|
bool invalidRepository;
|
2023-04-02 19:05:22 +00:00
|
|
|
bool corruptRepository;
|
2023-04-01 10:55:58 +00:00
|
|
|
bool shallowRepository;
|
2023-03-27 19:29:37 +00:00
|
|
|
bool manuallyDownloaded;
|
|
|
|
bool hasLocalChanges;
|
|
|
|
bool isCloned;
|
|
|
|
ThemeEntry()
|
2023-03-29 17:08:22 +00:00
|
|
|
: newEntry {false}
|
2024-04-16 19:05:04 +00:00
|
|
|
, deprecated {false}
|
2023-03-29 17:08:22 +00:00
|
|
|
, invalidRepository {false}
|
2023-04-02 19:05:22 +00:00
|
|
|
, corruptRepository {false}
|
2023-04-01 10:55:58 +00:00
|
|
|
, shallowRepository {false}
|
2023-03-27 19:29:37 +00:00
|
|
|
, manuallyDownloaded {false}
|
|
|
|
, hasLocalChanges {false}
|
|
|
|
, isCloned {false}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool fetchThemesList();
|
2023-04-01 17:27:54 +00:00
|
|
|
bool fetchRepository(const std::string& repositoryName, bool allowReset = false);
|
2023-03-27 19:29:37 +00:00
|
|
|
bool cloneRepository(const std::string& repositoryName, const std::string& url);
|
|
|
|
|
2023-04-02 19:05:22 +00:00
|
|
|
bool checkLocalChanges(git_repository* repository);
|
|
|
|
bool checkCorruptRepository(git_repository* repository);
|
2023-03-27 19:29:37 +00:00
|
|
|
void resetRepository(git_repository* repository);
|
|
|
|
void makeInventory();
|
2023-04-02 19:05:22 +00:00
|
|
|
bool renameDirectory(const std::string& path, const std::string& extension);
|
2023-03-27 19:29:37 +00:00
|
|
|
void parseThemesList();
|
|
|
|
|
|
|
|
void populateGUI();
|
|
|
|
void updateGUI();
|
2023-03-29 17:08:22 +00:00
|
|
|
void updateInfoPane();
|
2023-03-30 17:19:36 +00:00
|
|
|
void setupFullscreenViewer();
|
2023-03-27 19:29:37 +00:00
|
|
|
|
2023-02-13 19:38:23 +00:00
|
|
|
Renderer* mRenderer;
|
|
|
|
NinePatchComponent mBackground;
|
|
|
|
ComponentGrid mGrid;
|
2023-03-31 18:40:40 +00:00
|
|
|
std::shared_ptr<ComponentGrid> mCenterGrid;
|
2023-03-22 19:56:48 +00:00
|
|
|
std::shared_ptr<ComponentList> mList;
|
|
|
|
std::shared_ptr<ComponentGrid> mButtons;
|
|
|
|
BusyComponent mBusyAnim;
|
2023-03-31 21:00:23 +00:00
|
|
|
std::function<void()> mUpdateCallback;
|
2023-02-13 19:38:23 +00:00
|
|
|
|
2023-03-27 19:29:37 +00:00
|
|
|
struct ThemeGUIEntry {
|
|
|
|
std::shared_ptr<TextComponent> themeName;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<ThemeGUIEntry> mThemeGUIEntries;
|
|
|
|
|
2023-03-29 20:21:55 +00:00
|
|
|
enum class StatusType {
|
|
|
|
STATUS_NO_CHANGE,
|
|
|
|
STATUS_DOWNLOADING,
|
|
|
|
STATUS_UPDATING
|
|
|
|
};
|
|
|
|
|
2023-03-23 19:44:58 +00:00
|
|
|
enum class RepositoryError {
|
2023-03-26 18:49:44 +00:00
|
|
|
NO_REPO_ERROR,
|
2023-03-23 19:44:58 +00:00
|
|
|
NOT_A_REPOSITORY,
|
|
|
|
INVALID_ORIGIN,
|
2023-04-01 17:27:54 +00:00
|
|
|
HAS_DIVERGED,
|
|
|
|
CLONE_ERROR,
|
|
|
|
FETCH_ERROR
|
2023-03-23 19:44:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RepositoryError mRepositoryError;
|
2023-03-29 17:08:22 +00:00
|
|
|
std::string mThemeDirectory;
|
2023-03-29 20:21:55 +00:00
|
|
|
std::string mMessage;
|
2023-03-21 18:01:44 +00:00
|
|
|
std::thread mFetchThread;
|
|
|
|
std::promise<bool> mPromise;
|
|
|
|
std::future<bool> mFuture;
|
|
|
|
std::atomic<bool> mFetching;
|
|
|
|
std::atomic<bool> mLatestThemesList;
|
2023-03-31 19:36:05 +00:00
|
|
|
bool mAttemptedFetch;
|
2023-03-31 20:12:31 +00:00
|
|
|
bool mHasThemeUpdates;
|
2023-03-21 18:01:44 +00:00
|
|
|
static inline std::atomic<float> mReceivedObjectsProgress {0.0f};
|
|
|
|
static inline std::atomic<float> mResolveDeltaProgress {0.0f};
|
2023-08-14 20:40:32 +00:00
|
|
|
std::vector<ThemeEntry> mThemes;
|
2023-03-29 20:21:55 +00:00
|
|
|
StatusType mStatusType;
|
|
|
|
std::string mStatusText;
|
2023-03-30 17:19:36 +00:00
|
|
|
bool mFullscreenViewing;
|
|
|
|
size_t mFullscreenViewerIndex;
|
2023-03-29 17:08:22 +00:00
|
|
|
|
|
|
|
std::shared_ptr<ImageComponent> mScrollUp;
|
|
|
|
std::shared_ptr<ImageComponent> mScrollDown;
|
|
|
|
std::shared_ptr<ScrollIndicatorComponent> mScrollIndicator;
|
|
|
|
std::vector<float> mGrayRectangleCoords;
|
2023-03-21 18:01:44 +00:00
|
|
|
|
2023-03-29 17:08:22 +00:00
|
|
|
std::shared_ptr<ImageComponent> mScreenshot;
|
2023-03-30 17:19:36 +00:00
|
|
|
std::vector<std::shared_ptr<ImageComponent>> mViewerScreenshots;
|
|
|
|
std::vector<std::shared_ptr<TextComponent>> mViewerCaptions;
|
|
|
|
std::shared_ptr<TextComponent> mViewerIndicatorLeft;
|
|
|
|
std::shared_ptr<TextComponent> mViewerIndicatorRight;
|
2023-03-29 17:08:22 +00:00
|
|
|
std::shared_ptr<TextComponent> mDownloadStatus;
|
|
|
|
std::shared_ptr<TextComponent> mLocalChanges;
|
2023-02-13 19:38:23 +00:00
|
|
|
std::shared_ptr<TextComponent> mTitle;
|
2023-03-29 17:08:22 +00:00
|
|
|
std::shared_ptr<TextComponent> mVariantsLabel;
|
|
|
|
std::shared_ptr<TextComponent> mColorSchemesLabel;
|
|
|
|
std::shared_ptr<TextComponent> mAspectRatiosLabel;
|
2023-12-20 21:30:11 +00:00
|
|
|
std::shared_ptr<TextComponent> mFontSizesLabel;
|
2023-03-29 17:08:22 +00:00
|
|
|
std::shared_ptr<TextComponent> mAuthor;
|
|
|
|
std::shared_ptr<TextComponent> mVariantCount;
|
|
|
|
std::shared_ptr<TextComponent> mColorSchemesCount;
|
|
|
|
std::shared_ptr<TextComponent> mAspectRatiosCount;
|
2023-12-20 21:30:11 +00:00
|
|
|
std::shared_ptr<TextComponent> mFontSizesCount;
|
2023-02-13 19:38:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ES_APP_GUIS_GUI_THEME_DOWNLOADER_H
|