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 Browser Integration
Commits
a0d175aa
Commit
a0d175aa
authored
Jan 01, 2021
by
Kai Uwe Broulik
🍇
Browse files
Move conversion of data URL into QImage into base class
Removes code duplication
parent
a0c57d41
Changes
4
Hide whitespace changes
Inline
Side-by-side
host/abstractkrunnerplugin.cpp
View file @
a0d175aa
...
...
@@ -48,6 +48,29 @@ bool AbstractKRunnerPlugin::onUnload()
return
true
;
}
QImage
AbstractKRunnerPlugin
::
imageFromDataUrl
(
const
QString
&
dataUrl
)
{
QImage
image
;
if
(
!
dataUrl
.
startsWith
(
QLatin1String
(
"data:"
)))
{
return
image
;
}
const
int
b64start
=
dataUrl
.
indexOf
(
QLatin1Char
(
','
));
if
(
b64start
==
-
1
)
{
qWarning
()
<<
"Invalid data URL format for"
<<
dataUrl
.
left
(
30
);
return
image
;
}
const
QByteArray
b64
=
dataUrl
.
rightRef
(
dataUrl
.
count
()
-
b64start
-
1
).
toLatin1
();
const
QByteArray
data
=
QByteArray
::
fromBase64
(
b64
);
if
(
!
image
.
loadFromData
(
data
))
{
qWarning
()
<<
"Failed to load favicon image from"
<<
dataUrl
.
left
(
30
);
}
return
image
;
}
RemoteImage
AbstractKRunnerPlugin
::
serializeImage
(
const
QImage
&
image
)
{
QImage
convertedImage
=
image
.
convertToFormat
(
QImage
::
Format_RGBA8888
);
...
...
host/abstractkrunnerplugin.h
View file @
a0d175aa
...
...
@@ -34,6 +34,7 @@ protected:
int
protocolVersion
,
QObject
*
parent
);
static
QImage
imageFromDataUrl
(
const
QString
&
dataUrl
);
static
RemoteImage
serializeImage
(
const
QImage
&
image
);
public:
...
...
host/historyrunnerplugin.cpp
View file @
a0d175aa
...
...
@@ -165,19 +165,10 @@ void HistoryRunnerPlugin::handleData(const QString& event, const QJsonObject& js
urlWithoutPassword
.
setPassword
({});
match
.
properties
.
insert
(
QStringLiteral
(
"urls"
),
QUrl
::
toStringList
(
QList
<
QUrl
>
{
urlWithoutPassword
}));
if
(
favIconUrl
.
startsWith
(
QLatin1String
(
"data:"
)))
{
const
int
b64start
=
favIconUrl
.
indexOf
(
QLatin1Char
(
','
));
if
(
b64start
!=
-
1
)
{
QByteArray
b64
=
favIconUrl
.
rightRef
(
favIconUrl
.
count
()
-
b64start
-
1
).
toLatin1
();
QByteArray
data
=
QByteArray
::
fromBase64
(
b64
);
QImage
image
;
if
(
image
.
loadFromData
(
data
))
{
const
RemoteImage
remoteImage
=
serializeImage
(
image
);
match
.
properties
.
insert
(
QStringLiteral
(
"icon-data"
),
QVariant
::
fromValue
(
remoteImage
));
}
else
{
qWarning
()
<<
"Failed to load favicon image for"
<<
match
.
id
<<
match
.
text
;
}
}
const
QImage
favIcon
=
imageFromDataUrl
(
favIconUrl
);
if
(
!
favIcon
.
isNull
())
{
const
RemoteImage
remoteImage
=
serializeImage
(
favIcon
);
match
.
properties
.
insert
(
QStringLiteral
(
"icon-data"
),
QVariant
::
fromValue
(
remoteImage
));
}
qreal
relevance
=
0
;
...
...
host/tabsrunnerplugin.cpp
View file @
a0d175aa
...
...
@@ -187,20 +187,10 @@ void TabsRunnerPlugin::handleData(const QString& event, const QJsonObject& json)
}
else
{
match
.
iconName
=
Settings
::
self
().
environmentDescription
().
iconName
;
const
QString
favIconData
=
tab
.
value
(
QStringLiteral
(
"favIconData"
)).
toString
();
if
(
favIconData
.
startsWith
(
QLatin1String
(
"data:"
)))
{
const
int
b64start
=
favIconData
.
indexOf
(
QLatin1Char
(
','
));
if
(
b64start
!=
-
1
)
{
QByteArray
b64
=
favIconData
.
rightRef
(
favIconData
.
count
()
-
b64start
-
1
).
toLatin1
();
QByteArray
data
=
QByteArray
::
fromBase64
(
b64
);
QImage
image
;
if
(
image
.
loadFromData
(
data
))
{
const
RemoteImage
remoteImage
=
serializeImage
(
image
);
match
.
properties
.
insert
(
QStringLiteral
(
"icon-data"
),
QVariant
::
fromValue
(
remoteImage
));
}
else
{
qWarning
()
<<
"Failed to load favicon image for"
<<
match
.
id
<<
match
.
text
;
}
}
const
QImage
favIcon
=
imageFromDataUrl
(
tab
.
value
(
QStringLiteral
(
"favIconData"
)).
toString
());
if
(
!
favIcon
.
isNull
())
{
const
RemoteImage
remoteImage
=
serializeImage
(
favIcon
);
match
.
properties
.
insert
(
QStringLiteral
(
"icon-data"
),
QVariant
::
fromValue
(
remoteImage
));
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment