Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Add-ons
Commits
5882229e
Commit
5882229e
authored
Mar 12, 2022
by
Alexander Lohnau
💬
Browse files
applets/comic: Use struct rather than using QVariantMap
parent
1026957a
Changes
15
Hide whitespace changes
Inline
Side-by-side
applets/comic/checknewstrips.cpp
View file @
5882229e
...
...
@@ -5,7 +5,6 @@
*/
#include
"checknewstrips.h"
#include
"engine/comic.h"
#include
<QTimer>
...
...
@@ -25,12 +24,12 @@ CheckNewStrips::CheckNewStrips(const QStringList &identifiers, ComicEngine *engi
start
();
}
void
CheckNewStrips
::
dataUpdated
(
const
QString
&
source
,
const
QVariantMap
&
data
)
void
CheckNewStrips
::
dataUpdated
(
const
QString
&
source
,
const
ComicMetaData
&
data
)
{
QString
lastIdentifierSuffix
;
if
(
!
data
[
QStringLiteral
(
"Error"
)].
toBool
()
)
{
lastIdentifierSuffix
=
data
[
QStringLiteral
(
"Identifier"
)].
toString
()
;
if
(
!
data
.
error
)
{
lastIdentifierSuffix
=
data
.
identifier
;
lastIdentifierSuffix
.
remove
(
source
);
}
...
...
@@ -43,7 +42,7 @@ void CheckNewStrips::dataUpdated(const QString &source, const QVariantMap &data)
if
(
mIndex
<
mIdentifiers
.
count
())
{
const
QString
newSource
=
mIdentifiers
[
mIndex
]
+
QLatin1Char
(
':'
);
mEngine
->
requestSource
(
newSource
,
[
this
,
newSource
](
const
QVariantMap
&
data
)
{
mEngine
->
requestSource
(
newSource
,
[
this
,
newSource
](
const
auto
&
data
)
{
dataUpdated
(
newSource
,
data
);
});
}
else
{
...
...
@@ -60,7 +59,7 @@ void CheckNewStrips::start()
if
(
mIndex
<
mIdentifiers
.
count
())
{
const
QString
newSource
=
mIdentifiers
[
mIndex
]
+
QLatin1Char
(
':'
);
mEngine
->
requestSource
(
newSource
,
[
this
,
newSource
](
const
QVariantMap
&
data
)
{
mEngine
->
requestSource
(
newSource
,
[
this
,
newSource
](
const
auto
&
data
)
{
dataUpdated
(
newSource
,
data
);
});
}
...
...
applets/comic/checknewstrips.h
View file @
5882229e
...
...
@@ -30,7 +30,7 @@ Q_SIGNALS:
void
lastStrip
(
int
index
,
const
QString
&
identifier
,
const
QString
&
suffix
);
public
Q_SLOTS
:
void
dataUpdated
(
const
QString
&
name
,
const
QVariantMap
&
data
);
void
dataUpdated
(
const
QString
&
name
,
const
ComicMetaData
&
data
);
private
Q_SLOTS
:
void
start
();
...
...
applets/comic/comic.cpp
View file @
5882229e
...
...
@@ -35,7 +35,6 @@
#include
"comicmodel.h"
#include
"comicupdater.h"
#include
"engine/comic.h"
Q_GLOBAL_STATIC
(
ComicUpdater
,
globalComicUpdater
)
...
...
@@ -141,7 +140,7 @@ ComicApplet::~ComicApplet()
delete
mSavingDir
;
}
void
ComicApplet
::
dataUpdated
(
const
QString
&
source
,
const
QVariantMap
&
data
)
void
ComicApplet
::
dataUpdated
(
const
QString
&
source
,
const
ComicMetaData
&
data
)
{
setBusy
(
false
);
...
...
@@ -153,12 +152,9 @@ void ComicApplet::dataUpdated(const QString &source, const QVariantMap &data)
setConfigurationRequired
(
false
);
// there was an error, display information as image
const
bool
hasError
=
data
[
QStringLiteral
(
"Error"
)].
toBool
();
const
bool
errorAutoFixable
=
data
[
QStringLiteral
(
"Error automatically fixable"
)].
toBool
();
if
(
hasError
)
{
const
QString
previousIdentifierSuffix
=
data
[
QStringLiteral
(
"Previous identifier suffix"
)].
toString
();
if
(
mEngine
&&
!
mShowErrorPicture
&&
!
previousIdentifierSuffix
.
isEmpty
())
{
updateComic
(
previousIdentifierSuffix
);
if
(
data
.
error
)
{
if
(
mEngine
&&
!
mShowErrorPicture
&&
!
data
.
previousIdentifier
.
isEmpty
())
{
updateComic
(
data
.
previousIdentifier
);
}
return
;
}
...
...
@@ -181,13 +177,13 @@ void ComicApplet::dataUpdated(const QString &source, const QVariantMap &data)
// prefetch the previous and following comic for faster navigation
if
(
mCurrent
.
hasNext
())
{
const
QString
prefetch
=
mCurrent
.
id
()
+
QLatin1Char
(
':'
)
+
mCurrent
.
next
();
mEngine
->
requestSource
(
prefetch
,
[
this
,
prefetch
](
const
QVariantMap
&
data
)
{
mEngine
->
requestSource
(
prefetch
,
[
this
,
prefetch
](
const
auto
&
data
)
{
dataUpdated
(
prefetch
,
data
);
});
}
if
(
mCurrent
.
hasPrev
())
{
const
QString
prefetch
=
mCurrent
.
id
()
+
QLatin1Char
(
':'
)
+
mCurrent
.
prev
();
mEngine
->
requestSource
(
prefetch
,
[
this
,
prefetch
](
const
QVariantMap
&
data
)
{
mEngine
->
requestSource
(
prefetch
,
[
this
,
prefetch
](
const
auto
&
data
)
{
dataUpdated
(
prefetch
,
data
);
});
}
...
...
@@ -474,7 +470,7 @@ void ComicApplet::updateComic(const QString &identifierSuffix)
mIdentifierError
.
clear
();
}
mOldSource
=
identifier
;
mEngine
->
requestSource
(
identifier
,
[
this
,
identifier
](
const
QVariantMap
&
data
)
{
mEngine
->
requestSource
(
identifier
,
[
this
,
identifier
](
const
auto
&
data
)
{
dataUpdated
(
identifier
,
data
);
});
slotScaleToContent
();
...
...
applets/comic/comic.h
View file @
5882229e
...
...
@@ -11,14 +11,14 @@
#ifndef COMIC_H
#define COMIC_H
#include
"comicdata.h"
#include
<QDate>
#include
<QUrl>
#include
<Plasma/Applet>
#include
"activecomicmodel.h"
#include
"comicdata.h"
#include
"engine/comic.h"
class
CheckNewStrips
;
class
ComicModel
;
...
...
@@ -29,7 +29,6 @@ class QAction;
class
QSortFilterProxyModel
;
class
QTimer
;
class
SavingDir
;
class
ComicEngine
;
class
ComicApplet
:
public
Plasma
::
Applet
{
...
...
@@ -118,7 +117,7 @@ Q_SIGNALS:
void
maxComicLimitChanged
();
public
Q_SLOTS
:
void
dataUpdated
(
const
QString
&
name
,
const
QVariantMap
&
data
);
void
dataUpdated
(
const
QString
&
name
,
const
ComicMetaData
&
data
);
private
Q_SLOTS
:
void
slotTabChanged
(
const
QString
&
newIdentifier
);
...
...
applets/comic/comicarchivejob.cpp
View file @
5882229e
...
...
@@ -121,7 +121,7 @@ void ComicArchiveJob::start()
}
}
void
ComicArchiveJob
::
dataUpdated
(
const
QString
&
source
,
const
QVariantMap
&
data
)
void
ComicArchiveJob
::
dataUpdated
(
const
QString
&
source
,
const
ComicMetaData
&
data
)
{
if
(
!
mZip
)
{
qWarning
()
<<
"No zip file, aborting."
;
...
...
@@ -131,21 +131,21 @@ void ComicArchiveJob::dataUpdated(const QString &source, const QVariantMap &data
return
;
}
const
QString
currentIdentifier
=
data
[
QStringLiteral
(
"Identifier"
)].
toString
()
;
const
QString
currentIdentifier
=
data
.
identifier
;
QString
currentIdentifierSuffix
=
currentIdentifier
;
currentIdentifierSuffix
.
remove
(
mPluginName
+
QLatin1Char
(
':'
));
const
QImage
image
=
data
[
QStringLiteral
(
"Image"
)].
value
<
QImage
>
()
;
const
bool
hasError
=
data
[
QStringLiteral
(
"Error"
)].
toBool
()
||
image
.
isNull
();
const
QString
previousIdentifierSuffix
=
data
[
QStringLiteral
(
"P
revious
i
dentifier
suffix"
)].
toString
()
;
const
QString
nextIdentifierSuffix
=
data
[
QStringLiteral
(
"N
ext
i
dentifier
suffix"
)].
toString
()
;
const
QString
firstIdentifierSuffix
=
data
[
QStringLiteral
(
"F
irst
s
trip
i
dentifier
suffix"
)].
toString
()
;
const
QImage
image
=
data
.
image
;
const
bool
hasError
=
data
.
error
||
image
.
isNull
();
const
QString
previousIdentifierSuffix
=
data
.
p
revious
I
dentifier
;
const
QString
nextIdentifierSuffix
=
data
.
n
ext
I
dentifier
;
const
QString
firstIdentifierSuffix
=
data
.
f
irst
S
trip
I
dentifier
;
mAuthors
<<
data
[
QStringLiteral
(
"C
omic
Author
"
)].
toString
()
.
split
(
QLatin1Char
(
','
),
Qt
::
SkipEmptyParts
);
mAuthors
<<
data
.
c
omicAuthor
.
split
(
QLatin1Char
(
','
),
Qt
::
SkipEmptyParts
);
mAuthors
.
removeDuplicates
();
if
(
mComicTitle
.
isEmpty
())
{
mComicTitle
=
data
[
QStringLiteral
(
"Title"
)].
toString
()
;
mComicTitle
=
data
.
stripTitle
;
}
if
(
hasError
)
{
...
...
@@ -330,7 +330,7 @@ void ComicArchiveJob::requestComic(QString identifier) // krazy:exclude=passbyva
qMakePair
(
QStringLiteral
(
"source"
),
identifier
),
qMakePair
(
QStringLiteral
(
"destination"
),
mDest
.
toString
()));
mEngine
->
requestSource
(
identifier
,
[
this
,
identifier
](
const
QVariantMap
&
data
)
{
mEngine
->
requestSource
(
identifier
,
[
this
,
identifier
](
const
auto
&
data
)
{
dataUpdated
(
identifier
,
data
);
});
}
...
...
applets/comic/comicarchivejob.h
View file @
5882229e
...
...
@@ -66,7 +66,7 @@ public:
void
start
()
override
;
public
Q_SLOTS
:
void
dataUpdated
(
const
QString
&
source
,
const
QVariantMap
&
data
);
void
dataUpdated
(
const
QString
&
source
,
const
ComicMetaData
&
data
);
protected:
bool
doKill
()
override
;
...
...
applets/comic/comicdata.cpp
View file @
5882229e
...
...
@@ -54,25 +54,24 @@ void ComicData::storePosition(bool store)
save
();
}
void
ComicData
::
setData
(
const
QVariantMap
&
data
)
void
ComicData
::
setData
(
const
ComicMetaData
&
data
)
{
const
bool
hasError
=
data
[
QStringLiteral
(
"Error"
)].
toBool
();
if
(
!
hasError
)
{
mImage
=
data
[
QStringLiteral
(
"Image"
)].
value
<
QImage
>
();
mPrev
=
data
[
QStringLiteral
(
"Previous identifier suffix"
)].
toString
();
mNext
=
data
[
QStringLiteral
(
"Next identifier suffix"
)].
toString
();
mAdditionalText
=
data
[
QStringLiteral
(
"Additional text"
)].
toString
();
if
(
!
data
.
error
)
{
mImage
=
data
.
image
;
mPrev
=
data
.
previousIdentifier
;
mNext
=
data
.
nextIdentifier
;
mAdditionalText
=
data
.
additionalText
;
}
mWebsiteUrl
=
data
[
QStringLiteral
(
"W
ebsite
Url
"
)].
toUrl
()
;
mImageUrl
=
data
[
QStringLiteral
(
"I
mage
Url
"
)].
toUrl
()
;
mShopUrl
=
data
[
QStringLiteral
(
"S
hop
Url
"
)].
toUrl
()
;
mFirst
=
data
[
QStringLiteral
(
"F
irst
s
trip
i
dentifier
suffix"
)].
toString
()
;
mStripTitle
=
data
[
QStringLiteral
(
"S
trip
t
itle
"
)].
toString
()
;
mAuthor
=
data
[
QStringLiteral
(
"C
omic
Author
"
)].
toString
()
;
mTitle
=
data
[
QStringLiteral
(
"Title"
)].
toString
()
;
mWebsiteUrl
=
data
.
w
ebsiteUrl
;
mImageUrl
=
data
.
i
mageUrl
;
mShopUrl
=
data
.
s
hopUrl
;
mFirst
=
data
.
f
irst
S
trip
I
dentifier
;
mStripTitle
=
data
.
s
trip
T
itle
;
mAuthor
=
data
.
c
omicAuthor
;
mTitle
=
data
.
providerName
;
const
QString
suffixType
=
data
[
QStringLiteral
(
"SuffixType"
)].
toString
()
;
const
QString
suffixType
=
data
.
suffixType
;
if
(
suffixType
==
QLatin1String
(
"Date"
))
{
mType
=
Date
;
}
else
if
(
suffixType
==
QLatin1String
(
"Number"
))
{
...
...
@@ -81,7 +80,7 @@ void ComicData::setData(const QVariantMap &data)
mType
=
String
;
}
QString
temp
=
data
[
QStringLiteral
(
"Identifier"
)].
toString
()
;
QString
temp
=
data
.
identifier
;
mCurrent
=
temp
.
remove
(
mId
+
QLatin1Char
(
':'
));
// found a new last identifier
...
...
@@ -105,8 +104,8 @@ void ComicData::setData(const QVariantMap &data)
mCurrentReadable
=
mCurrent
;
}
mIsLeftToRight
=
data
[
QStringLiteral
(
"
isLeftToRight
"
)].
toBool
()
;
mIsTopToBottom
=
data
[
QStringLiteral
(
"
isTopToBottom
"
)].
toBool
()
;
mIsLeftToRight
=
data
.
isLeftToRight
;
mIsTopToBottom
=
data
.
isTopToBottom
;
save
();
}
...
...
applets/comic/comicdata.h
View file @
5882229e
...
...
@@ -8,6 +8,7 @@
#define COMIC_DATA_H
#include
"comicinfo.h"
#include
"engine/types.h"
// Qt
#include
<KConfigGroup>
...
...
@@ -22,7 +23,7 @@ public:
void
init
(
const
QString
&
id
,
const
KConfigGroup
&
config
);
void
setData
(
const
QVariantMap
&
data
);
void
setData
(
const
ComicMetaData
&
data
);
IdentifierType
type
()
const
{
...
...
applets/comic/comicmodel.cpp
View file @
5882229e
...
...
@@ -7,7 +7,6 @@
*/
#include
"comicmodel.h"
#include
"engine/comic.h"
#include
"engine/comicprovider.h"
#include
<QDebug>
...
...
applets/comic/comicmodel.h
View file @
5882229e
...
...
@@ -12,6 +12,7 @@
#include
<QAbstractTableModel>
#include
"engine/comic.h"
class
ComicModel
:
public
QAbstractTableModel
{
Q_OBJECT
...
...
applets/comic/engine/cachedprovider.cpp
View file @
5882229e
...
...
@@ -6,6 +6,7 @@
#include
"cachedprovider.h"
#include
"comic_debug.h"
#include
"types.h"
#include
<QDebug>
#include
<QDir>
...
...
@@ -121,7 +122,7 @@ bool CachedProvider::isCached(const QString &identifier)
return
QFile
::
exists
(
identifierToPath
(
identifier
));
}
bool
CachedProvider
::
storeInCache
(
const
QString
&
identifier
,
const
QImage
&
comic
,
const
Settings
&
info
)
bool
CachedProvider
::
storeInCache
(
const
QString
&
identifier
,
const
QImage
&
comic
,
const
ComicMetaData
&
data
)
{
const
QString
path
=
identifierToPath
(
identifier
);
...
...
@@ -130,19 +131,22 @@ bool CachedProvider::storeInCache(const QString &identifier, const QImage &comic
const
QString
pathMain
=
identifierToPath
(
comicName
);
const
QString
dirPath
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericDataLocation
)
+
QLatin1String
(
"/plasma_engine_comic/"
);
if
(
!
info
.
isEmpty
())
{
QSettings
settings
(
path
+
QLatin1String
(
".conf"
),
QSettings
::
IniFormat
);
QSettings
settingsMain
(
pathMain
+
QLatin1String
(
".conf"
),
QSettings
::
IniFormat
);
settingsMain
.
setValue
(
QStringLiteral
(
"firstStripIdentifier"
),
data
.
firstStripIdentifier
);
settingsMain
.
setValue
(
QStringLiteral
(
"title"
),
data
.
providerName
);
settingsMain
.
setValue
(
QStringLiteral
(
"lastCachedStripIdentifier"
),
data
.
lastCachedStripIdentifier
);
settingsMain
.
setValue
(
QStringLiteral
(
"suffixType"
),
data
.
suffixType
);
settingsMain
.
setValue
(
QStringLiteral
(
"shopUrl"
),
data
.
shopUrl
);
settingsMain
.
setValue
(
QStringLiteral
(
"isLeftToRight"
),
data
.
isLeftToRight
);
settingsMain
.
setValue
(
QStringLiteral
(
"isTopToBottom"
),
data
.
isTopToBottom
);
for
(
Settings
::
const_iterator
i
=
info
.
constBegin
();
i
!=
info
.
constEnd
();
++
i
)
{
if
((
i
.
key
()
==
QLatin1String
(
"firstStripIdentifier"
))
||
(
i
.
key
()
==
QLatin1String
(
"title"
))
||
(
i
.
key
()
==
QLatin1String
(
"lastCachedStripIdentifier"
))
||
(
i
.
key
()
==
QLatin1String
(
"suffixType"
))
||
(
i
.
key
()
==
QLatin1String
(
"shopUrl"
))
||
(
i
.
key
()
==
QLatin1String
(
"isLeftToRight"
))
||
(
i
.
key
()
==
QLatin1String
(
"isTopToBottom"
)))
{
settingsMain
.
setValue
(
i
.
key
(),
i
.
value
());
}
else
{
settings
.
setValue
(
i
.
key
(),
i
.
value
());
}
}
QSettings
settings
(
path
+
QLatin1String
(
".conf"
),
QSettings
::
IniFormat
);
settings
.
setValue
(
QStringLiteral
(
"additionalText"
),
data
.
additionalText
);
settings
.
setValue
(
QStringLiteral
(
"comicAuthor"
),
data
.
comicAuthor
);
settings
.
setValue
(
QStringLiteral
(
"imageUrl"
),
data
.
imageUrl
);
settings
.
setValue
(
QStringLiteral
(
"nextIdentifier"
),
data
.
nextIdentifier
);
settings
.
setValue
(
QStringLiteral
(
"previousIdentifier"
),
data
.
previousIdentifier
);
settings
.
setValue
(
QStringLiteral
(
"websiteUrl"
),
data
.
websiteUrl
);
QStringList
comics
;
if
(
settingsMain
.
contains
(
QLatin1String
(
"comics"
)))
{
...
...
@@ -180,7 +184,6 @@ bool CachedProvider::storeInCache(const QString &identifier, const QImage &comic
}
}
settingsMain
.
setValue
(
QLatin1String
(
"comics"
),
comics
);
}
return
comic
.
save
(
path
,
"PNG"
);
}
...
...
applets/comic/engine/cachedprovider.h
View file @
5882229e
...
...
@@ -8,6 +8,7 @@
#define CACHEDPROVIDER_H
#include
"comicprovider.h"
#include
"types.h"
#include
<QHash>
...
...
@@ -121,7 +122,7 @@ public:
/**
* Stores the given @p comic with the given @p identifier in the cache.
*/
static
bool
storeInCache
(
const
QString
&
identifier
,
const
QImage
&
comic
,
const
Settings
&
info
=
Settings
()
);
static
bool
storeInCache
(
const
QString
&
identifier
,
const
QImage
&
comic
,
const
ComicMetaData
&
info
);
/**
* Returns the website of the comic.
...
...
applets/comic/engine/comic.cpp
View file @
5882229e
...
...
@@ -35,7 +35,10 @@ ComicEngine::~ComicEngine()
void
ComicEngine
::
init
()
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
connect
(
&
m_networkConfigurationManager
,
&
QNetworkConfigurationManager
::
onlineStateChanged
,
this
,
&
ComicEngine
::
onOnlineStateChanged
);
QT_WARNING_POP
}
void
ComicEngine
::
onOnlineStateChanged
(
bool
isOnline
)
...
...
@@ -100,7 +103,7 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
// ... start a new query otherwise
if
(
parts
.
count
()
<
2
)
{
callback
(
QVariantMap
{{
QLatin1String
(
"E
rror
"
),
true
}
}
);
callback
(
ComicMetaData
{.
e
rror
=
true
});
qWarning
()
<<
"Less than two arguments specified."
;
return
false
;
}
...
...
@@ -108,7 +111,7 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
// User might have installed more from GHNS
loadProviders
();
if
(
!
mProviders
.
contains
(
parts
[
0
]))
{
callback
(
QVariantMap
{{
QLatin1String
(
"E
rror
"
),
true
}
}
);
callback
(
ComicMetaData
{.
e
rror
=
true
});
qWarning
()
<<
identifier
<<
"comic plugin does not seem to be installed."
;
return
false
;
}
...
...
@@ -117,12 +120,12 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
// check if there is a connection
if
(
!
m_networkConfigurationManager
.
isOnline
())
{
mIdentifierError
=
identifier
;
callback
(
QVariantMap
{
{
QLatin1String
(
"E
rror
"
),
true
},
{
QLatin1String
(
"E
rror
a
utomatically
f
ixable
"
),
true
},
{
QLatin1String
(
"I
dentifier
"
),
identifier
},
{
QLatin1String
(
"P
revious
i
dentifier
suffix"
),
lastCachedIdentifier
(
identifier
)
},
}
);
ComicMetaData
data
;
data
.
e
rror
=
true
;
data
.
e
rror
A
utomatically
F
ixable
=
true
;
data
.
i
dentifier
=
identifier
;
data
.
p
revious
I
dentifier
=
lastCachedIdentifier
(
identifier
)
;
callback
(
data
);
qCDebug
(
PLASMA_COMIC
)
<<
"No internet connection, using cached data"
;
return
true
;
}
...
...
@@ -150,10 +153,9 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
}
args
<<
QStandardPaths
::
locate
(
QStandardPaths
::
GenericDataLocation
,
QLatin1String
(
"plasma/comics/"
)
+
parts
[
0
]
+
QLatin1String
(
"/metadata.desktop"
));
// provider = service->createInstance<ComicProvider>(this, args);
provider
=
new
ComicProviderKross
(
this
,
args
);
if
(
!
provider
)
{
callback
(
QVariantMap
{{
QLatin1String
(
"E
rror
"
),
true
}
}
);
callback
(
ComicMetaData
{.
e
rror
=
true
});
return
false
;
}
provider
->
setIsCurrent
(
isCurrentComic
);
...
...
@@ -193,33 +195,31 @@ void ComicEngine::finished(ComicProvider *provider, ComicRequestCallback callbac
// if there is a valid image and if there is a next comic
// (if we're on today's comic it could become stale)
if
(
!
provider
->
inherits
(
"CachedProvider"
)
&&
!
provider
->
image
().
isNull
()
&&
!
provider
->
nextIdentifier
().
isEmpty
())
{
CachedProvider
::
Settings
info
;
info
[
QLatin1String
(
"websiteUrl"
)]
=
provider
->
websiteUrl
().
toString
(
QUrl
::
PrettyDecoded
);
info
[
QLatin1String
(
"imageUrl"
)]
=
provider
->
imageUrl
().
url
();
info
[
QLatin1String
(
"shopUrl"
)]
=
provider
->
shopUrl
().
toString
(
QUrl
::
PrettyDecoded
);
info
[
QLatin1String
(
"nextIdentifier"
)]
=
provider
->
nextIdentifier
();
info
[
QLatin1String
(
"previousIdentifier"
)]
=
provider
->
previousIdentifier
();
info
[
QLatin1String
(
"title"
)]
=
provider
->
name
();
info
[
QLatin1String
(
"suffixType"
)]
=
provider
->
suffixType
();
info
[
QLatin1String
(
"lastCachedStripIdentifier"
)]
=
provider
->
identifier
().
mid
(
provider
->
identifier
().
indexOf
(
QLatin1Char
(
':'
))
+
1
);
QString
isLeftToRight
;
QString
isTopToBottom
;
info
[
QLatin1String
(
"isLeftToRight"
)]
=
isLeftToRight
.
setNum
(
provider
->
isLeftToRight
());
info
[
QLatin1String
(
"isTopToBottom"
)]
=
isTopToBottom
.
setNum
(
provider
->
isTopToBottom
());
ComicMetaData
info
;
info
.
websiteUrl
=
provider
->
websiteUrl
();
info
.
imageUrl
=
provider
->
imageUrl
();
info
.
shopUrl
=
provider
->
shopUrl
();
info
.
nextIdentifier
=
provider
->
nextIdentifier
();
info
.
previousIdentifier
=
provider
->
previousIdentifier
();
info
.
providerName
=
provider
->
name
();
info
.
suffixType
=
provider
->
suffixType
();
info
.
lastCachedStripIdentifier
=
provider
->
identifier
().
mid
(
provider
->
identifier
().
indexOf
(
QLatin1Char
(
':'
))
+
1
);
info
.
isLeftToRight
=
provider
->
isLeftToRight
();
info
.
isTopToBottom
=
provider
->
isTopToBottom
();
// data that should be only written if available
if
(
!
provider
->
comicAuthor
().
isEmpty
())
{
info
[
QLatin1String
(
"
comicAuthor
"
)]
=
provider
->
comicAuthor
();
info
.
comicAuthor
=
provider
->
comicAuthor
();
}
if
(
!
provider
->
firstStripIdentifier
().
isEmpty
())
{
info
[
QLatin1String
(
"
firstStripIdentifier
"
)]
=
provider
->
firstStripIdentifier
();
info
.
firstStripIdentifier
=
provider
->
firstStripIdentifier
();
}
if
(
!
provider
->
additionalText
().
isEmpty
())
{
info
[
QLatin1String
(
"
additionalText
"
)]
=
provider
->
additionalText
();
info
.
additionalText
=
provider
->
additionalText
();
}
if
(
!
provider
->
stripTitle
().
isEmpty
())
{
info
[
QLatin1String
(
"
stripTitle
"
)]
=
provider
->
stripTitle
();
info
.
stripTitle
=
provider
->
stripTitle
();
}
CachedProvider
::
storeInCache
(
provider
->
identifier
(),
provider
->
image
(),
info
);
...
...
@@ -251,18 +251,17 @@ void ComicEngine::error(ComicProvider *provider, ComicRequestCallback callback)
identifier
=
identifier
.
left
(
identifier
.
indexOf
(
QLatin1Char
(
':'
))
+
1
);
}
QVariantMap
data
{
{
QLatin1String
(
"Identifier"
),
identifier
},
{
QLatin1String
(
"Error"
),
true
},
};
ComicMetaData
data
;
data
.
identifier
=
identifier
;
data
.
error
=
true
;
// if there was an error loading the last cached comic strip, do not return its id anymore
const
QString
lastCachedId
=
lastCachedIdentifier
(
identifier
);
if
(
lastCachedId
!=
provider
->
identifier
().
mid
(
provider
->
identifier
().
indexOf
(
QLatin1Char
(
':'
))
+
1
))
{
// sets the previousIdentifier to the identifier of a strip that has been cached before
data
.
insert
(
QLatin1String
(
"P
revious
i
dentifier
suffix"
),
lastCachedId
)
;
data
.
p
revious
I
dentifier
=
lastCachedId
;
}
data
.
insert
(
QLatin1String
(
"N
ext
i
dentifier
suffix"
),
QString
()
)
;
data
.
n
ext
I
dentifier
=
QString
();
const
QString
key
=
m_jobs
.
key
(
provider
);
if
(
!
key
.
isEmpty
())
{
...
...
@@ -286,24 +285,24 @@ void ComicEngine::setComicData(ComicProvider *provider, ComicRequestCallback cal
identifier
=
identifier
.
left
(
identifier
.
indexOf
(
QLatin1Char
(
':'
))
+
1
);
}
callback
({
{
QLatin1String
(
"Image"
),
provider
->
image
()},
{
QLatin1String
(
"Website Url"
),
provider
->
websiteUrl
()},
{
QLatin1String
(
"Image Url"
),
provider
->
imag
eUrl
()
},
{
QLatin1String
(
"S
hop
Url
"
),
provider
->
shopUrl
()
},
{
QLatin1String
(
"N
ext
i
dentifier
suffix"
),
provider
->
nextIdentifier
()
},
{
QLatin1String
(
"P
revious
i
dentifier
suffix"
),
provider
->
previousIdentifier
()
},
{
QLatin1String
(
"C
omic
Author
"
),
provider
->
comicAuthor
()
},
{
QLatin1String
(
"A
dditional
t
ext
"
),
provider
->
additionalText
()
},
{
QLatin1String
(
"S
trip
t
itle
"
),
provider
->
stripTitle
()
},
{
QLatin1String
(
"F
irst
s
trip
i
dentifier
suffix"
),
provider
->
firstStripIdentifier
()
},
{
QLatin1String
(
"I
dentifier
"
),
provider
->
identifier
()
},
{
QLatin1String
(
"Title"
),
provider
->
name
()
},
{
QLatin1String
(
"S
uffixType
"
),
provider
->
suffixType
()
},
{
QLatin1String
(
"
isLeftToRight
"
),
provider
->
isLeftToRight
()
},
{
QLatin1String
(
"
isTopToBottom
"
),
provider
->
isTopToBottom
()
},
{
QLatin1String
(
"Error"
),
false
},
}
);
ComicMetaData
data
;
data
.
imageUrl
=
provider
->
image
Url
();
data
.
image
=
provider
->
image
();
data
.
websiteUrl
=
provider
->
websit
eUrl
()
;
data
.
s
hopUrl
=
provider
->
shopUrl
()
;
data
.
n
ext
I
dentifier
=
provider
->
nextIdentifier
()
;
data
.
p
revious
I
dentifier
=
provider
->
previousIdentifier
()
;
data
.
c
omicAuthor
=
provider
->
comicAuthor
()
;
data
.
a
dditional
T
ext
=
provider
->
additionalText
()
;
data
.
s
trip
T
itle
=
provider
->
stripTitle
()
;
data
.
f
irst
S
trip
I
dentifier
=
provider
->
firstStripIdentifier
()
;
data
.
i
dentifier
=
provider
->
identifier
()
;
data
.
providerName
=
provider
->
name
()
;
data
.
s
uffixType
=
provider
->
suffixType
()
;
data
.
isLeftToRight
=
provider
->
isLeftToRight
()
;
data
.
isTopToBottom
=
provider
->
isTopToBottom
()
;
callback
(
data
);
}
QString
ComicEngine
::
lastCachedIdentifier
(
const
QString
&
identifier
)
const
...
...
applets/comic/engine/comic.h
View file @
5882229e
...
...
@@ -11,15 +11,12 @@
#include
<QIcon>
#include
<QNetworkConfigurationManager>
#include
<QSet>
#include
<QUrl>
#include
<QVariant>
class
ComicProvider
;
#include
"types.h"
struct
ComicProviderInfo
{
QString
pluginId
;
QString
name
;
QString
icon
;
};
class
ComicProvider
;
/**
* This class provides the comic strip.
...
...
@@ -45,7 +42,7 @@ public:
QList
<
ComicProviderInfo
>
loadProviders
();
void
setMaxComicLimit
(
int
maxComicLimit
);
using
ComicRequestCallback
=
const
std
::
function
<
void
(
const
QVariantMap
&
data
)
>
&
;
using
ComicRequestCallback
=
const
std
::
function
<
void
(
const
ComicMetaData
&
data
)
>
&
;
bool
requestSource
(
const
QString
&
identifier
,
ComicRequestCallback
callback
);
Q_SIGNALS:
...
...
@@ -65,7 +62,10 @@ private:
QString
lastCachedIdentifier
(
const
QString
&
identifier
)
const
;
QString
mIdentifierError
;
QHash
<
QString
,
ComicProvider
*>
m_jobs
;
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
QNetworkConfigurationManager
m_networkConfigurationManager
;
QT_WARNING_POP
QSet
<
QString
>
mProviders
;
};
...
...
applets/comic/engine/types.h
0 → 100644
View file @
5882229e
#ifndef COMIC_ENGINE_TYPES
#define COMIC_ENGINE_TYPES