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 Workspace
Commits
e5e13a3f
Commit
e5e13a3f
authored
Jan 20, 2022
by
Eugene Popov
🇺🇦
Committed by
Fushan Wen
Feb 18, 2022
Browse files
Avoid memory leaks by misusing HistoryItem::mimeData()
parent
45185e25
Pipeline
#139458
passed with stage
in 5 minutes and 46 seconds
Changes
7
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
klipper/historyimageitem.h
View file @
e5e13a3f
...
...
@@ -18,6 +18,12 @@ public:
~
HistoryImageItem
()
override
{
}
HistoryItemType
type
()
const
override
{
return
HistoryItemType
::
Image
;
}
QString
text
()
const
override
;
bool
operator
==
(
const
HistoryItem
&
rhs
)
const
override
{
...
...
klipper/historyitem.h
View file @
e5e13a3f
...
...
@@ -15,6 +15,13 @@ class QDataStream;
class
HistoryItem
;
typedef
QSharedPointer
<
HistoryItem
>
HistoryItemPtr
;
typedef
QSharedPointer
<
const
HistoryItem
>
HistoryItemConstPtr
;
enum
class
HistoryItemType
{
Text
,
Image
,
Url
,
};
/**
* An entry in the clipboard history.
*/
...
...
@@ -24,6 +31,11 @@ public:
explicit
HistoryItem
(
const
QByteArray
&
uuid
);
virtual
~
HistoryItem
();
/**
* Returns the item type.
*/
virtual
HistoryItemType
type
()
const
=
0
;
/**
* Return the current item as text
* An image would be returned as a descriptive
...
...
@@ -112,3 +124,4 @@ inline QDataStream &operator<<(QDataStream &lhs, HistoryItem const *const rhs)
Q_DECLARE_METATYPE
(
HistoryItem
*
)
Q_DECLARE_METATYPE
(
HistoryItemPtr
)
Q_DECLARE_METATYPE
(
HistoryItemConstPtr
)
Q_DECLARE_METATYPE
(
HistoryItemType
)
klipper/historymodel.cpp
View file @
e5e13a3f
...
...
@@ -56,14 +56,6 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
}
QSharedPointer
<
HistoryItem
>
item
=
m_items
.
at
(
index
.
row
());
HistoryItemType
type
=
HistoryItemType
::
Text
;
if
(
dynamic_cast
<
HistoryStringItem
*>
(
item
.
data
()))
{
type
=
HistoryItemType
::
Text
;
}
else
if
(
dynamic_cast
<
HistoryImageItem
*>
(
item
.
data
()))
{
type
=
HistoryItemType
::
Image
;
}
else
if
(
dynamic_cast
<
HistoryURLItem
*>
(
item
.
data
()))
{
type
=
HistoryItemType
::
Url
;
}
switch
(
role
)
{
case
Qt
::
DisplayRole
:
...
...
@@ -75,11 +67,11 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
case
UuidRole
:
return
item
->
uuid
();
case
TypeRole
:
return
QVariant
::
fromValue
<
HistoryItemType
>
(
type
);
return
QVariant
::
fromValue
<
HistoryItemType
>
(
item
->
type
()
);
case
Base64UuidRole
:
return
item
->
uuid
().
toBase64
();
case
TypeIntRole
:
return
int
(
type
);
return
int
(
item
->
type
()
);
}
return
QVariant
();
}
...
...
klipper/historymodel.h
View file @
e5e13a3f
...
...
@@ -10,12 +10,6 @@
class
HistoryItem
;
enum
class
HistoryItemType
{
Text
,
Image
,
Url
,
};
class
HistoryModel
:
public
QAbstractListModel
{
Q_OBJECT
...
...
@@ -80,5 +74,3 @@ inline void HistoryModel::setDisplayImages(bool show)
{
m_displayImages
=
show
;
}
Q_DECLARE_METATYPE
(
HistoryItemType
)
klipper/historystringitem.h
View file @
e5e13a3f
...
...
@@ -19,6 +19,12 @@ public:
~
HistoryStringItem
()
override
{
}
HistoryItemType
type
()
const
override
{
return
HistoryItemType
::
Text
;
}
QString
text
()
const
override
;
bool
operator
==
(
const
HistoryItem
&
rhs
)
const
override
{
...
...
klipper/historyurlitem.h
View file @
e5e13a3f
...
...
@@ -16,6 +16,12 @@ class HistoryURLItem : public HistoryItem
{
public:
HistoryURLItem
(
const
QList
<
QUrl
>
&
urls
,
const
KUrlMimeData
::
MetaDataMap
&
metaData
,
bool
cut
);
HistoryItemType
type
()
const
override
{
return
HistoryItemType
::
Url
;
}
QString
text
()
const
override
;
bool
operator
==
(
const
HistoryItem
&
rhs
)
const
override
;
QMimeData
*
mimeData
()
const
override
;
...
...
klipper/klipper.cpp
View file @
e5e13a3f
...
...
@@ -605,7 +605,7 @@ HistoryItemPtr Klipper::applyClipChanges(const QMimeData *clipData)
Ignore
lock
(
m_locklevel
);
if
(
!
(
history
()
->
empty
()))
{
if
(
m_bIgnoreImages
&&
history
()
->
first
()
->
mimeData
()
->
has
Image
()
)
{
if
(
m_bIgnoreImages
&&
history
()
->
first
()
->
type
()
==
HistoryItemType
::
Image
)
{
history
()
->
remove
(
history
()
->
first
());
}
}
...
...
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