File indexing completed on 2024-05-05 17:33:57
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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0017 #include <QNetworkConfigurationManager> 0018 #endif 0019 #include <QUrl> 0020 0021 #include <Plasma/Applet> 0022 0023 #include "activecomicmodel.h" 0024 #include "comicdata.h" 0025 #include "engine/comic.h" 0026 0027 class CheckNewStrips; 0028 class ComicModel; 0029 class ConfigWidget; 0030 class QAction; 0031 class KJob; 0032 class QAction; 0033 class QSortFilterProxyModel; 0034 class QTimer; 0035 class SavingDir; 0036 0037 class ComicApplet : public Plasma::Applet 0038 { 0039 Q_OBJECT 0040 Q_PROPERTY(QObject *comicsModel READ comicsModel NOTIFY comicModelChanged) 0041 Q_PROPERTY(QObject *availableComicsModel READ availableComicsModel CONSTANT) 0042 Q_PROPERTY(bool showComicUrl READ showComicUrl WRITE setShowComicUrl NOTIFY showComicUrlChanged) 0043 Q_PROPERTY(bool showComicAuthor READ showComicAuthor WRITE setShowComicAuthor NOTIFY showComicAuthorChanged) 0044 Q_PROPERTY(bool showComicTitle READ showComicTitle WRITE setShowComicTitle NOTIFY showComicTitleChanged) 0045 Q_PROPERTY(bool showComicIdentifier READ showComicIdentifier WRITE setShowComicIdentifier NOTIFY showComicIdentifierChanged) 0046 Q_PROPERTY(bool showErrorPicture READ showErrorPicture WRITE setShowErrorPicture NOTIFY showErrorPictureChanged) 0047 Q_PROPERTY(bool arrowsOnHover READ arrowsOnHover WRITE setArrowsOnHover NOTIFY arrowsOnHoverChanged) 0048 Q_PROPERTY(bool middleClick READ middleClick WRITE setMiddleClick NOTIFY middleClickChanged) 0049 Q_PROPERTY(QVariantMap comicData READ comicData NOTIFY comicDataChanged) 0050 Q_PROPERTY(bool showActualSize READ showActualSize WRITE setShowActualSize NOTIFY showActualSizeChanged) 0051 Q_PROPERTY(QStringList tabIdentifiers READ tabIdentifiers WRITE setTabIdentifiers NOTIFY tabIdentifiersChanged) 0052 Q_PROPERTY(int checkNewComicStripsInterval READ checkNewComicStripsInterval WRITE setCheckNewComicStripsInterval NOTIFY checkNewComicStripsIntervalChanged) 0053 Q_PROPERTY(int providerUpdateInterval READ providerUpdateInterval WRITE setProviderUpdateInterval NOTIFY providerUpdateIntervalChanged) 0054 Q_PROPERTY(int maxComicLimit READ maxComicLimit WRITE setMaxComicLimit NOTIFY maxComicLimitChanged) 0055 0056 public: 0057 ComicApplet(QObject *parent, const KPluginMetaData &data, const QVariantList &args); 0058 ~ComicApplet() override; 0059 0060 void init() override; 0061 QList<QAction *> contextualActions() override; 0062 0063 // For QML 0064 QObject *comicsModel() const; 0065 QObject *availableComicsModel() const; 0066 QVariantMap comicData() const; 0067 0068 QStringList tabIdentifiers() const; 0069 void setTabIdentifiers(const QStringList &tabs); 0070 0071 bool showComicUrl() const; 0072 void setShowComicUrl(bool show); 0073 0074 bool showComicAuthor() const; 0075 void setShowComicAuthor(bool show); 0076 0077 bool showComicTitle() const; 0078 void setShowComicTitle(bool show); 0079 0080 bool showComicIdentifier() const; 0081 void setShowComicIdentifier(bool show); 0082 0083 bool showErrorPicture() const; 0084 void setShowErrorPicture(bool show); 0085 0086 bool arrowsOnHover() const; 0087 void setArrowsOnHover(bool show); 0088 0089 bool middleClick() const; 0090 void setMiddleClick(bool show); 0091 0092 bool showActualSize() const; 0093 void setShowActualSize(bool show); 0094 0095 int checkNewComicStripsInterval() const; 0096 void setCheckNewComicStripsInterval(int interval); 0097 0098 int providerUpdateInterval() const; 0099 void setProviderUpdateInterval(int interval); 0100 0101 void setMaxComicLimit(int limit); 0102 int maxComicLimit() const; 0103 // End for QML 0104 0105 Q_SIGNALS: 0106 void comicModelChanged(); 0107 void showComicUrlChanged(); 0108 void showComicAuthorChanged(); 0109 void showComicTitleChanged(); 0110 void showComicIdentifierChanged(); 0111 void showErrorPictureChanged(); 0112 void arrowsOnHoverChanged(); 0113 void middleClickChanged(); 0114 void comicDataChanged(); 0115 void tabHighlightRequest(const QString &id, bool highlight); 0116 void showNextNewStrip(); 0117 void showActualSizeChanged(); 0118 void tabIdentifiersChanged(); 0119 void checkNewComicStripsIntervalChanged(); 0120 void providerUpdateIntervalChanged(); 0121 void maxComicLimitChanged(); 0122 0123 private Q_SLOTS: 0124 void slotTabChanged(const QString &newIdentifier); 0125 void slotNextDay(); 0126 void slotPreviousDay(); 0127 void slotFirstDay(); 0128 void slotCurrentDay(); 0129 void slotFoundLastStrip(int index, const QString &identifier, const QString &suffix); 0130 void slotGoJump(); 0131 void slotSaveComicAs(); 0132 void slotScaleToContent(); 0133 void slotShop(); 0134 void slotWebsite(); 0135 void slotStorePosition(); 0136 void checkDayChanged(); 0137 0138 public Q_SLOTS: 0139 void configChanged() override; 0140 void saveConfig(); 0141 Q_INVOKABLE void updateComic(const QString &identifierSuffix = QString()); 0142 0143 Q_INVOKABLE void goJump() 0144 { 0145 slotGoJump(); 0146 } 0147 0148 Q_INVOKABLE void shop() 0149 { 0150 slotShop(); 0151 } 0152 0153 Q_INVOKABLE void tabChanged(const QString &newIdentifier) 0154 { 0155 slotTabChanged(newIdentifier); 0156 } 0157 0158 Q_INVOKABLE void loadProviders(); 0159 Q_INVOKABLE void positionFullView(QWindow *window); 0160 0161 private: 0162 void changeComic(bool differentComic); 0163 void updateUsedComics(); 0164 void updateContextMenu(); 0165 void updateView(); 0166 void refreshComicData(); 0167 void setTabHighlighted(const QString &id, bool highlight); 0168 bool isTabHighlighted(const QString &id) const; 0169 void dataUpdated(const ComicMetaData &data); 0170 0171 private: 0172 ComicModel *mModel; 0173 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0174 QT_WARNING_PUSH 0175 QT_WARNING_DISABLE_DEPRECATED 0176 QNetworkConfigurationManager m_networkConfigurationManager; 0177 QT_WARNING_POP 0178 #endif 0179 QString mPreviousFailedIdentifier; 0180 QSortFilterProxyModel *mProxy; 0181 ActiveComicModel *mActiveComicModel; 0182 QVariantMap mComicData; 0183 0184 QDate mCurrentDay; 0185 0186 QString mIdentifierError; 0187 QString mOldSource; 0188 ConfigWidget *mConfigWidget; 0189 bool mDifferentComic; 0190 bool mShowComicUrl; 0191 bool mShowComicAuthor; 0192 bool mShowComicTitle; 0193 bool mShowComicIdentifier; 0194 bool mShowErrorPicture; 0195 bool mArrowsOnHover; 0196 bool mMiddleClick; 0197 int mCheckNewComicStripsInterval; 0198 int mMaxComicLimit; 0199 CheckNewStrips *mCheckNewStrips; 0200 QTimer *mDateChangedTimer; 0201 QList<QAction *> mActions; 0202 QAction *mActionGoFirst; 0203 QAction *mActionGoLast; 0204 QAction *mActionGoJump; 0205 QAction *mActionScaleContent; 0206 QAction *mActionWebsite; 0207 QAction *mActionShop; 0208 QAction *mActionStorePosition; 0209 QAction *mActionNextNewStripTab; 0210 QAction *mActionSaveComicAs; 0211 QAction *mActionCreateComicBook; 0212 QSizeF mMaxSize; 0213 QSizeF mLastSize; 0214 QSizeF mIdealSize; 0215 ComicEngine *const mEngine; 0216 0217 // Tabs 0218 bool mTabAdded; 0219 QStringList mTabIdentifier; 0220 0221 ComicData mCurrent; 0222 SavingDir *mSavingDir; 0223 }; 0224 0225 #endif