File indexing completed on 2024-05-12 05:29:34

0001 /*
0002  *   SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0003  *   SPDX-FileCopyrightText: 2008 Marco Martin <notmart@gmail.com>
0004  *   SPDX-FileCopyrightText: 2008-2010 Matthias Fuchs <mat69@gmx.net>
0005  *   SPDX-FileCopyrightText: 2012 Reza Fatahilah Shah <rshah0385@kireihana.com>
0006  *   SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0007  *   SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
0008  *
0009  *   SPDX-License-Identifier: GPL-2.0-or-later
0010  */
0011 
0012 #ifndef COMIC_H
0013 #define COMIC_H
0014 
0015 #include <QDate>
0016 #include <QUrl>
0017 
0018 #include <Plasma/Applet>
0019 
0020 #include "activecomicmodel.h"
0021 #include "comicdata.h"
0022 #include "engine/comic.h"
0023 
0024 class CheckNewStrips;
0025 class ComicModel;
0026 class ConfigWidget;
0027 class QAction;
0028 class KJob;
0029 class QAction;
0030 class QSortFilterProxyModel;
0031 class QTimer;
0032 class SavingDir;
0033 
0034 class ComicApplet : public Plasma::Applet
0035 {
0036     Q_OBJECT
0037     Q_PROPERTY(QObject *comicsModel READ comicsModel NOTIFY comicModelChanged)
0038     Q_PROPERTY(QObject *availableComicsModel READ availableComicsModel CONSTANT)
0039     Q_PROPERTY(bool showComicUrl READ showComicUrl WRITE setShowComicUrl NOTIFY showComicUrlChanged)
0040     Q_PROPERTY(bool showComicAuthor READ showComicAuthor WRITE setShowComicAuthor NOTIFY showComicAuthorChanged)
0041     Q_PROPERTY(bool showComicTitle READ showComicTitle WRITE setShowComicTitle NOTIFY showComicTitleChanged)
0042     Q_PROPERTY(bool showComicIdentifier READ showComicIdentifier WRITE setShowComicIdentifier NOTIFY showComicIdentifierChanged)
0043     Q_PROPERTY(bool showErrorPicture READ showErrorPicture WRITE setShowErrorPicture NOTIFY showErrorPictureChanged)
0044     Q_PROPERTY(bool arrowsOnHover READ arrowsOnHover WRITE setArrowsOnHover NOTIFY arrowsOnHoverChanged)
0045     Q_PROPERTY(bool middleClick READ middleClick WRITE setMiddleClick NOTIFY middleClickChanged)
0046     Q_PROPERTY(QVariantMap comicData READ comicData NOTIFY comicDataChanged)
0047     Q_PROPERTY(bool showActualSize READ showActualSize WRITE setShowActualSize NOTIFY showActualSizeChanged)
0048     Q_PROPERTY(QStringList tabIdentifiers READ tabIdentifiers WRITE setTabIdentifiers NOTIFY tabIdentifiersChanged)
0049     Q_PROPERTY(int checkNewComicStripsInterval READ checkNewComicStripsInterval WRITE setCheckNewComicStripsInterval NOTIFY checkNewComicStripsIntervalChanged)
0050     Q_PROPERTY(int maxComicLimit READ maxComicLimit WRITE setMaxComicLimit NOTIFY maxComicLimitChanged)
0051 
0052 public:
0053     ComicApplet(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
0054     ~ComicApplet() override;
0055 
0056     void init() override;
0057     QList<QAction *> contextualActions() override;
0058 
0059     // For QML
0060     QObject *comicsModel() const;
0061     QObject *availableComicsModel() const;
0062     QVariantMap comicData() const;
0063 
0064     QStringList tabIdentifiers() const;
0065     void setTabIdentifiers(const QStringList &tabs);
0066 
0067     bool showComicUrl() const;
0068     void setShowComicUrl(bool show);
0069 
0070     bool showComicAuthor() const;
0071     void setShowComicAuthor(bool show);
0072 
0073     bool showComicTitle() const;
0074     void setShowComicTitle(bool show);
0075 
0076     bool showComicIdentifier() const;
0077     void setShowComicIdentifier(bool show);
0078 
0079     bool showErrorPicture() const;
0080     void setShowErrorPicture(bool show);
0081 
0082     bool arrowsOnHover() const;
0083     void setArrowsOnHover(bool show);
0084 
0085     bool middleClick() const;
0086     void setMiddleClick(bool show);
0087 
0088     bool showActualSize() const;
0089     void setShowActualSize(bool show);
0090 
0091     int checkNewComicStripsInterval() const;
0092     void setCheckNewComicStripsInterval(int interval);
0093 
0094     void setMaxComicLimit(int limit);
0095     int maxComicLimit() const;
0096     // End for QML
0097 
0098 Q_SIGNALS:
0099     void comicModelChanged();
0100     void showComicUrlChanged();
0101     void showComicAuthorChanged();
0102     void showComicTitleChanged();
0103     void showComicIdentifierChanged();
0104     void showErrorPictureChanged();
0105     void arrowsOnHoverChanged();
0106     void middleClickChanged();
0107     void comicDataChanged();
0108     void tabHighlightRequest(const QString &id, bool highlight);
0109     void showNextNewStrip();
0110     void showActualSizeChanged();
0111     void tabIdentifiersChanged();
0112     void checkNewComicStripsIntervalChanged();
0113     void maxComicLimitChanged();
0114 
0115 private Q_SLOTS:
0116     void slotTabChanged(const QString &newIdentifier);
0117     void slotNextDay();
0118     void slotPreviousDay();
0119     void slotFirstDay();
0120     void slotCurrentDay();
0121     void slotFoundLastStrip(int index, const QString &identifier, const QString &suffix);
0122     void slotGoJump();
0123     void slotSaveComicAs();
0124     void slotScaleToContent();
0125     void slotShop();
0126     void slotWebsite();
0127     void slotStorePosition();
0128     void checkDayChanged();
0129 
0130 public Q_SLOTS:
0131     void configChanged() override;
0132     void saveConfig();
0133     Q_INVOKABLE void updateComic(const QString &identifierSuffix = QString());
0134 
0135     Q_INVOKABLE void goJump()
0136     {
0137         slotGoJump();
0138     }
0139 
0140     Q_INVOKABLE void shop()
0141     {
0142         slotShop();
0143     }
0144 
0145     Q_INVOKABLE void tabChanged(const QString &newIdentifier)
0146     {
0147         slotTabChanged(newIdentifier);
0148     }
0149 
0150     Q_INVOKABLE void loadProviders();
0151     Q_INVOKABLE void positionFullView(QWindow *window);
0152 
0153 private:
0154     void changeComic(bool differentComic);
0155     void updateUsedComics();
0156     void updateContextMenu();
0157     void updateView();
0158     void refreshComicData();
0159     void setTabHighlighted(const QString &id, bool highlight);
0160     bool isTabHighlighted(const QString &id) const;
0161     void dataUpdated(const ComicMetaData &data);
0162 
0163 private:
0164     ComicModel *mModel;
0165     QString mPreviousFailedIdentifier;
0166     QSortFilterProxyModel *mProxy;
0167     ActiveComicModel *mActiveComicModel;
0168     QVariantMap mComicData;
0169 
0170     QDate mCurrentDay;
0171 
0172     QString mIdentifierError;
0173     QString mOldSource;
0174     ConfigWidget *mConfigWidget;
0175     bool mDifferentComic;
0176     bool mShowComicUrl;
0177     bool mShowComicAuthor;
0178     bool mShowComicTitle;
0179     bool mShowComicIdentifier;
0180     bool mShowErrorPicture;
0181     bool mArrowsOnHover;
0182     bool mMiddleClick;
0183     int mCheckNewComicStripsInterval;
0184     int mMaxComicLimit;
0185     CheckNewStrips *mCheckNewStrips;
0186     QTimer *mDateChangedTimer;
0187     QList<QAction *> mActions;
0188     QAction *mActionGoFirst;
0189     QAction *mActionGoLast;
0190     QAction *mActionGoJump;
0191     QAction *mActionScaleContent;
0192     QAction *mActionWebsite;
0193     QAction *mActionShop;
0194     QAction *mActionStorePosition;
0195     QAction *mActionNextNewStripTab;
0196     QAction *mActionSaveComicAs;
0197     QAction *mActionCreateComicBook;
0198     QSizeF mMaxSize;
0199     QSizeF mLastSize;
0200     QSizeF mIdealSize;
0201     ComicEngine *const mEngine;
0202 
0203     // Tabs
0204     bool mTabAdded;
0205     QStringList mTabIdentifier;
0206 
0207     ComicData mCurrent;
0208     SavingDir *mSavingDir;
0209 };
0210 
0211 #endif