Commit f7154534 authored by Tomáš Trnka's avatar Tomáš Trnka
Browse files

Treat feed IDs as unsigned everywhere

This fixes several bugs introduced by commit 230b8f20
("Port all instance of KRandom") which switched the random number
generator used in FeedList::generateId() from KRandom to
QRandomGenerator. The former generates positive signed integers while
the latter generates unsigned ints. While TreeNode already used uint to
store the IDs, other classes used plain int. Half of the newly generated
IDs thus got mapped to negative values, confusing various validity
checks.

BUG: 429444
parent fb848652
......@@ -113,7 +113,7 @@ public:
void jobFinished();
QWeakPointer<FeedList> m_list;
int m_subscriptionId = -1;
uint m_subscriptionId = 0;
};
DeleteSubscriptionCommand::Private::Private(DeleteSubscriptionCommand *qq)
......@@ -137,13 +137,13 @@ DeleteSubscriptionCommand::~DeleteSubscriptionCommand()
delete d;
}
void DeleteSubscriptionCommand::setSubscription(const QWeakPointer<FeedList> &feedList, int subId)
void DeleteSubscriptionCommand::setSubscription(const QWeakPointer<FeedList> &feedList, uint subId)
{
d->m_list = feedList;
d->m_subscriptionId = subId;
}
int DeleteSubscriptionCommand::subscriptionId() const
uint DeleteSubscriptionCommand::subscriptionId() const
{
return d->m_subscriptionId;
}
......
......@@ -23,9 +23,9 @@ public:
explicit DeleteSubscriptionCommand(QObject *parent = nullptr);
~DeleteSubscriptionCommand() override;
void setSubscription(const QWeakPointer<FeedList> &feedList, int subId);
void setSubscription(const QWeakPointer<FeedList> &feedList, uint subId);
int subscriptionId() const;
uint subscriptionId() const;
QWeakPointer<FeedList> feedList() const;
private:
......
......@@ -68,14 +68,14 @@ public:
void jobFinished();
QSharedPointer<FeedList> m_list;
int m_subscriptionId;
uint m_subscriptionId;
SubscriptionListView *m_subscriptionListView = nullptr;
};
EditSubscriptionCommand::Private::Private(EditSubscriptionCommand *qq)
: q(qq)
, m_list()
, m_subscriptionId(-1)
, m_subscriptionId(0)
, m_subscriptionListView(nullptr)
{
}
......@@ -95,13 +95,13 @@ EditSubscriptionCommand::~EditSubscriptionCommand()
delete d;
}
void EditSubscriptionCommand::setSubscription(const QSharedPointer<FeedList> &feedList, int subId)
void EditSubscriptionCommand::setSubscription(const QSharedPointer<FeedList> &feedList, uint subId)
{
d->m_list = feedList;
d->m_subscriptionId = subId;
}
int EditSubscriptionCommand::subscriptionId() const
uint EditSubscriptionCommand::subscriptionId() const
{
return d->m_subscriptionId;
}
......
......@@ -24,8 +24,8 @@ public:
explicit EditSubscriptionCommand(QObject *parent = nullptr);
~EditSubscriptionCommand() override;
void setSubscription(const QSharedPointer<FeedList> &feedList, int subId);
int subscriptionId() const;
void setSubscription(const QSharedPointer<FeedList> &feedList, uint subId);
uint subscriptionId() const;
QSharedPointer<FeedList> feedList() const;
SubscriptionListView *subscriptionListView() const;
......
......@@ -35,7 +35,7 @@ public:
void jobFinished(KJob *);
QWeakPointer<FeedList> m_feedList;
QVector<int> m_feeds;
QVector<uint> m_feeds;
QSet<KJob *> m_jobs;
};
......@@ -80,7 +80,7 @@ void ExpireItemsCommand::Private::createDeleteJobs()
return;
}
for (const int i : qAsConst(m_feeds)) {
for (const uint i : qAsConst(m_feeds)) {
Feed *const feed = qobject_cast<Feed *>(feedList->findByID(i));
if (feed) {
addDeleteJobForFeed(feed);
......@@ -109,12 +109,12 @@ QWeakPointer<FeedList> ExpireItemsCommand::feedList() const
return d->m_feedList;
}
void ExpireItemsCommand::setFeeds(const QVector<int> &feeds)
void ExpireItemsCommand::setFeeds(const QVector<uint> &feeds)
{
d->m_feeds = feeds;
}
QVector<int> ExpireItemsCommand::feeds() const
QVector<uint> ExpireItemsCommand::feeds() const
{
return d->m_feeds;
}
......
......@@ -28,8 +28,8 @@ public:
void setFeedList(const QWeakPointer<FeedList> &feedList);
QWeakPointer<FeedList> feedList() const;
void setFeeds(const QVector<int> &feeds);
QVector<int> feeds() const;
void setFeeds(const QVector<uint> &feeds);
QVector<uint> feeds() const;
private:
void doStart() override;
......
......@@ -37,7 +37,7 @@ public:
Akregator::Backend::Storage *storage;
QList<TreeNode *> flatList;
Folder *rootNode;
QHash<int, TreeNode *> idMap;
QHash<uint, TreeNode *> idMap;
AddNodeVisitor *addNodeVisitor;
RemoveNodeVisitor *removeNodeVisitor;
QHash<QString, QList<Feed *>> urlMap;
......@@ -163,9 +163,9 @@ FeedList::FeedList(Backend::Storage *storage)
addNode(rootNode, true);
}
QVector<int> FeedList::feedIds() const
QVector<uint> FeedList::feedIds() const
{
QVector<int> ids;
QVector<uint> ids;
const auto f = feeds();
for (const Feed *const i : f) {
ids += i->id();
......@@ -368,12 +368,12 @@ QDomDocument FeedList::toOpml() const
return doc;
}
const TreeNode *FeedList::findByID(int id) const
const TreeNode *FeedList::findByID(uint id) const
{
return d->idMap[id];
}
TreeNode *FeedList::findByID(int id)
TreeNode *FeedList::findByID(uint id)
{
return d->idMap[id];
}
......
......@@ -72,8 +72,8 @@ public:
Q_REQUIRED_RESULT bool isEmpty() const;
const TreeNode *findByID(int id) const;
TreeNode *findByID(int id);
const TreeNode *findByID(uint id) const;
TreeNode *findByID(uint id);
Q_REQUIRED_RESULT QList<const TreeNode *> findByTitle(const QString &title) const;
Q_REQUIRED_RESULT QList<TreeNode *> findByTitle(const QString &title);
......@@ -90,7 +90,7 @@ public:
Q_REQUIRED_RESULT QVector<const Akregator::Feed *> feeds() const;
Q_REQUIRED_RESULT QVector<Akregator::Feed *> feeds();
Q_REQUIRED_RESULT QVector<int> feedIds() const;
Q_REQUIRED_RESULT QVector<uint> feedIds() const;
/**
* returns all folders in this list
......
......@@ -23,17 +23,17 @@ MoveSubscriptionJob::MoveSubscriptionJob(QObject *parent)
: KJob(parent)
, m_id(0)
, m_destFolderId(0)
, m_afterId(-1)
, m_afterId(0)
, m_feedList(Kernel::self()->feedList())
{
}
void MoveSubscriptionJob::setSubscriptionId(int id)
void MoveSubscriptionJob::setSubscriptionId(uint id)
{
m_id = id;
}
void MoveSubscriptionJob::setDestination(int folder, int afterChild)
void MoveSubscriptionJob::setDestination(uint folder, uint afterChild)
{
m_destFolderId = folder;
m_afterId = afterChild;
......@@ -87,7 +87,7 @@ RenameSubscriptionJob::RenameSubscriptionJob(QObject *parent)
{
}
void RenameSubscriptionJob::setSubscriptionId(int id)
void RenameSubscriptionJob::setSubscriptionId(uint id)
{
m_id = id;
}
......@@ -104,7 +104,7 @@ void RenameSubscriptionJob::start()
void RenameSubscriptionJob::doRename()
{
if (m_id > 0) {
if (m_id != 0) {
TreeNode *const node = m_feedList->findByID(m_id);
if (node) {
node->setTitle(m_name);
......@@ -120,7 +120,7 @@ DeleteSubscriptionJob::DeleteSubscriptionJob(QObject *parent)
{
}
void DeleteSubscriptionJob::setSubscriptionId(int id)
void DeleteSubscriptionJob::setSubscriptionId(uint id)
{
m_id = id;
}
......
......@@ -26,8 +26,8 @@ class AKREGATOR_EXPORT MoveSubscriptionJob : public KJob
public:
explicit MoveSubscriptionJob(QObject *parent = nullptr);
void setSubscriptionId(int id);
void setDestination(int folder, int afterChild);
void setSubscriptionId(uint id);
void setDestination(uint folder, uint afterChild);
void start() override;
......@@ -35,9 +35,9 @@ private Q_SLOTS:
void doMove();
private:
int m_id = 0;
int m_destFolderId = 0;
int m_afterId = -1;
uint m_id = 0;
uint m_destFolderId = 0;
uint m_afterId = 0;
QWeakPointer<FeedList> m_feedList;
};
......@@ -47,7 +47,7 @@ class AKREGATOR_EXPORT RenameSubscriptionJob : public KJob
public:
explicit RenameSubscriptionJob(QObject *parent = nullptr);
void setSubscriptionId(int id);
void setSubscriptionId(uint id);
void setName(const QString &name);
void start() override;
......@@ -56,7 +56,7 @@ private Q_SLOTS:
void doRename();
private:
int m_id;
uint m_id;
QString m_name;
QSharedPointer<FeedList> m_feedList;
};
......@@ -67,13 +67,13 @@ class AKREGATOR_EXPORT DeleteSubscriptionJob : public KJob
public:
explicit DeleteSubscriptionJob(QObject *parent = nullptr);
void setSubscriptionId(int id);
void setSubscriptionId(uint id);
void start() override;
private:
void doDelete();
int m_id;
uint m_id;
QWeakPointer<FeedList> m_feedList;
};
}
......@@ -545,7 +545,7 @@ bool SubscriptionListModel::dropMimeData(const QMimeData *data, Qt::DropAction a
}
auto *job = new MoveSubscriptionJob(this);
job->setSubscriptionId(node->id());
job->setDestination(destFolder->id(), after ? after->id() : -1);
job->setDestination(destFolder->id(), after ? after->id() : 0);
job->start();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment