File indexing completed on 2024-05-05 17:33:57
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Matthias Fuchs <mat69@gmx.net> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "comicdata.h" 0008 0009 #include <KLocalizedString> 0010 #include <Plasma/Theme> 0011 // Qt 0012 #include <QPainter> 0013 0014 ComicData::ComicData() 0015 { 0016 } 0017 0018 void ComicData::init(const QString &id, const KConfigGroup &config) 0019 { 0020 mId = id; 0021 mCfg = config; 0022 load(); 0023 } 0024 0025 void ComicData::load() 0026 { 0027 mScaleComic = mCfg.readEntry(QLatin1String("scaleToContent_") + mId, false); 0028 mMaxStripNum = mCfg.readEntry(QLatin1String("maxStripNum_") + mId, 0); 0029 mStored = mCfg.readEntry(QLatin1String("storedPosition_") + mId, QString()); 0030 } 0031 0032 void ComicData::save() 0033 { 0034 mCfg.writeEntry(QLatin1String("scaleToContent_") + mId, mScaleComic); 0035 mCfg.writeEntry(QLatin1String("maxStripNum_") + mId, mMaxStripNum); 0036 mCfg.writeEntry(QLatin1String("storedPosition_") + id(), mStored); 0037 0038 // no next, thus the most recent strip 0039 if (!hasNext()) { 0040 mCfg.writeEntry(QLatin1String("lastStripVisited_") + mId, true); 0041 mCfg.writeEntry(QLatin1String("lastStrip_") + mId, mLast); 0042 } 0043 } 0044 0045 void ComicData::setScaleComic(bool scale) 0046 { 0047 mScaleComic = scale; 0048 save(); 0049 } 0050 0051 void ComicData::storePosition(bool store) 0052 { 0053 mStored = (store ? mCurrent : QString()); 0054 save(); 0055 } 0056 0057 void ComicData::setData(const ComicMetaData &data) 0058 { 0059 if (!data.error) { 0060 mImage = data.image; 0061 mPrev = data.previousIdentifier; 0062 mNext = data.nextIdentifier; 0063 mAdditionalText = data.additionalText; 0064 mReady = true; 0065 } 0066 0067 mWebsiteUrl = data.websiteUrl; 0068 mImageUrl = data.imageUrl; 0069 mShopUrl = data.shopUrl; 0070 mFirst = data.firstStripIdentifier; 0071 mStripTitle = data.stripTitle; 0072 mAuthor = data.comicAuthor; 0073 mTitle = data.providerName; 0074 mType = data.identifierType; 0075 0076 QString temp = data.identifier; 0077 mCurrent = temp.remove(mId + QLatin1Char(':')); 0078 0079 // found a new last identifier 0080 if (!hasNext()) { 0081 mLast = mCurrent; 0082 } 0083 0084 mCurrentReadable.clear(); 0085 if (mType == IdentifierType::NumberIdentifier) { 0086 mCurrentReadable = i18nc("an abbreviation for Number", "# %1", mCurrent); 0087 int tempNum = mCurrent.toInt(); 0088 if (mMaxStripNum < tempNum) { 0089 mMaxStripNum = tempNum; 0090 } 0091 0092 temp = mFirst.remove(mId + QLatin1Char(':')); 0093 mFirstStripNum = temp.toInt(); 0094 } else if (mType == IdentifierType::DateIdentifier && QDate::fromString(temp, QStringLiteral("yyyy-MM-dd")).isValid()) { 0095 mCurrentReadable = mCurrent; 0096 } else if (mType == IdentifierType::StringIdentifier) { 0097 mCurrentReadable = mCurrent; 0098 } 0099 0100 mIsLeftToRight = data.isLeftToRight; 0101 mIsTopToBottom = data.isTopToBottom; 0102 0103 save(); 0104 }