mirror of
https://github.com/transmission/transmission
synced 2025-02-22 06:00:41 +00:00
refactor: prefer std::set over QSet (#5703)
* refactor: use std::set instead of QSet in WatchDir.cc * refactor: use std::set instead of QSet in FileTreeView.cc * refactor: use std::set instead of QSet in ColumnResizer.cc * refactor: use std::set instead of QSet in Prefs.cc * chore: fix rebase error that changed libsmall snapshot * refactor: more replace QSet with std::set
This commit is contained in:
parent
69b293a793
commit
237223aeaf
20 changed files with 90 additions and 91 deletions
|
@ -1006,7 +1006,6 @@ private:
|
||||||
friend tr_stat const* tr_torrentStat(tr_torrent* tor);
|
friend tr_stat const* tr_torrentStat(tr_torrent* tor);
|
||||||
friend tr_torrent* tr_torrentNew(tr_ctor* ctor, tr_torrent** setme_duplicate_of);
|
friend tr_torrent* tr_torrentNew(tr_ctor* ctor, tr_torrent** setme_duplicate_of);
|
||||||
friend uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor);
|
friend uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor);
|
||||||
friend uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor);
|
|
||||||
|
|
||||||
enum class VerifyState : uint8_t
|
enum class VerifyState : uint8_t
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ ColumnResizer::ColumnResizer(QObject* parent)
|
||||||
|
|
||||||
void ColumnResizer::addLayout(QGridLayout* layout)
|
void ColumnResizer::addLayout(QGridLayout* layout)
|
||||||
{
|
{
|
||||||
layouts_ << layout;
|
layouts_.emplace(layout);
|
||||||
scheduleUpdate();
|
scheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <libtransmission/tr-macros.h>
|
#include <libtransmission/tr-macros.h>
|
||||||
|
@ -33,5 +34,5 @@ private:
|
||||||
void scheduleUpdate();
|
void scheduleUpdate();
|
||||||
|
|
||||||
QTimer timer_;
|
QTimer timer_;
|
||||||
QSet<QGridLayout*> layouts_;
|
std::set<QGridLayout*> layouts_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1428,19 +1428,20 @@ void DetailsDialog::onRemoveTrackerClicked()
|
||||||
// make a map of torrentIds to announce URLs to remove
|
// make a map of torrentIds to announce URLs to remove
|
||||||
QItemSelectionModel* selection_model = ui_.trackersView->selectionModel();
|
QItemSelectionModel* selection_model = ui_.trackersView->selectionModel();
|
||||||
QModelIndexList const selected_rows = selection_model->selectedRows();
|
QModelIndexList const selected_rows = selection_model->selectedRows();
|
||||||
QMultiMap<int, int> torrent_id_to_tracker_ids;
|
auto torrent_id_to_tracker_ids = std::map<int, std::set<int>>{};
|
||||||
|
|
||||||
for (QModelIndex const& i : selected_rows)
|
for (auto const& model_index : selected_rows)
|
||||||
{
|
{
|
||||||
auto const inf = ui_.trackersView->model()->data(i, TrackerModel::TrackerRole).value<TrackerInfo>();
|
auto const inf = ui_.trackersView->model()->data(model_index, TrackerModel::TrackerRole).value<TrackerInfo>();
|
||||||
torrent_id_to_tracker_ids.insert(inf.torrent_id, inf.st.id);
|
torrent_id_to_tracker_ids[inf.torrent_id].insert(inf.st.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// batch all of a tracker's torrents into one command
|
// batch all of a tracker's torrents into one command
|
||||||
for (int const id : torrent_id_to_tracker_ids.uniqueKeys())
|
for (auto const& [torrent_id, tracker_ids] : torrent_id_to_tracker_ids)
|
||||||
{
|
{
|
||||||
torrent_ids_t const ids{ id };
|
auto const ids = torrent_ids_t{ torrent_id };
|
||||||
torrentSet(ids, TR_KEY_trackerRemove, torrent_id_to_tracker_ids.values(id));
|
auto const values = std::vector<int>{ std::begin(tracker_ids), std::end(tracker_ids) };
|
||||||
|
torrentSet(ids, TR_KEY_trackerRemove, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
selection_model->clearSelection();
|
selection_model->clearSelection();
|
||||||
|
@ -1582,15 +1583,15 @@ static constexpr tr_quark priorityKey(int priority)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetailsDialog::onFilePriorityChanged(QSet<int> const& indices, int priority)
|
void DetailsDialog::onFilePriorityChanged(file_indices_t const& indices, int priority)
|
||||||
{
|
{
|
||||||
torrentSet(priorityKey(priority), indices.values());
|
torrentSet(priorityKey(priority), std::vector<int>{ std::begin(indices), std::end(indices) });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetailsDialog::onFileWantedChanged(QSet<int> const& indices, bool wanted)
|
void DetailsDialog::onFileWantedChanged(file_indices_t const& indices, bool wanted)
|
||||||
{
|
{
|
||||||
tr_quark const key = wanted ? TR_KEY_files_wanted : TR_KEY_files_unwanted;
|
tr_quark const key = wanted ? TR_KEY_files_wanted : TR_KEY_files_unwanted;
|
||||||
torrentSet(key, indices.values());
|
torrentSet(key, std::vector<int>{ std::begin(indices), std::end(indices) });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetailsDialog::onPathEdited(QString const& old_path, QString const& new_name)
|
void DetailsDialog::onPathEdited(QString const& old_path, QString const& new_name)
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSet>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <libtransmission/tr-macros.h>
|
#include <libtransmission/tr-macros.h>
|
||||||
|
@ -77,8 +76,8 @@ private slots:
|
||||||
void onTrackerListEdited(QString);
|
void onTrackerListEdited(QString);
|
||||||
|
|
||||||
// Files tab
|
// Files tab
|
||||||
void onFilePriorityChanged(QSet<int> const& file_indices, int);
|
void onFilePriorityChanged(file_indices_t const& file_indices, int);
|
||||||
void onFileWantedChanged(QSet<int> const& file_indices, bool);
|
void onFileWantedChanged(file_indices_t const& file_indices, bool);
|
||||||
void onPathEdited(QString const& old_path, QString const& new_name);
|
void onPathEdited(QString const& old_path, QString const& new_name);
|
||||||
void onOpenRequested(QString const& path) const;
|
void onOpenRequested(QString const& path) const;
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ int FileTreeItem::priority() const
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTreeItem::setSubtreePriority(int priority, QSet<int>& ids)
|
void FileTreeItem::setSubtreePriority(int priority, file_indices_t& setme_changed_ids)
|
||||||
{
|
{
|
||||||
if (priority_ != priority)
|
if (priority_ != priority)
|
||||||
{
|
{
|
||||||
|
@ -344,13 +344,13 @@ void FileTreeItem::setSubtreePriority(int priority, QSet<int>& ids)
|
||||||
|
|
||||||
if (file_index_ >= 0)
|
if (file_index_ >= 0)
|
||||||
{
|
{
|
||||||
ids.insert(file_index_);
|
setme_changed_ids.insert(file_index_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FileTreeItem* const child : children_)
|
for (FileTreeItem* const child : children_)
|
||||||
{
|
{
|
||||||
child->setSubtreePriority(priority, ids);
|
child->setSubtreePriority(priority, setme_changed_ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,21 +386,21 @@ int FileTreeItem::isSubtreeWanted() const
|
||||||
return wanted;
|
return wanted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTreeItem::setSubtreeWanted(bool b, QSet<int>& ids)
|
void FileTreeItem::setSubtreeWanted(bool wanted, file_indices_t& setme_changed_ids)
|
||||||
{
|
{
|
||||||
if (is_wanted_ != b)
|
if (is_wanted_ != wanted)
|
||||||
{
|
{
|
||||||
is_wanted_ = b;
|
is_wanted_ = wanted;
|
||||||
|
|
||||||
if (file_index_ >= 0)
|
if (file_index_ >= 0)
|
||||||
{
|
{
|
||||||
ids.insert(file_index_);
|
setme_changed_ids.insert(file_index_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FileTreeItem* const child : children_)
|
for (FileTreeItem* const child : children_)
|
||||||
{
|
{
|
||||||
child->setSubtreeWanted(b, ids);
|
child->setSubtreeWanted(wanted, setme_changed_ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QSet>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include <libtransmission/tr-macros.h>
|
#include <libtransmission/tr-macros.h>
|
||||||
|
|
||||||
#include "Utils.h" // for std::hash<QString>
|
#include "Utils.h" // for std::hash<QString>
|
||||||
|
#include "Typedefs.h"
|
||||||
|
|
||||||
class FileTreeItem
|
class FileTreeItem
|
||||||
{
|
{
|
||||||
|
@ -69,8 +69,8 @@ public:
|
||||||
|
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
std::pair<int, int> update(QString const& name, bool want, int priority, uint64_t have, bool update_fields);
|
std::pair<int, int> update(QString const& name, bool want, int priority, uint64_t have, bool update_fields);
|
||||||
void setSubtreeWanted(bool, QSet<int>& file_ids);
|
void setSubtreeWanted(bool wanted, file_indices_t& setme_changed_ids);
|
||||||
void setSubtreePriority(int priority, QSet<int>& file_ids);
|
void setSubtreePriority(int priority, file_indices_t& setme_changed_ids);
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto fileIndex() const noexcept
|
[[nodiscard]] constexpr auto fileIndex() const noexcept
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <libtransmission/transmission.h> // priorities
|
#include <libtransmission/transmission.h> // priorities
|
||||||
|
|
||||||
|
@ -412,7 +413,7 @@ void FileTreeModel::emitParentsChanged(
|
||||||
QModelIndex const& index,
|
QModelIndex const& index,
|
||||||
int first_column,
|
int first_column,
|
||||||
int last_column,
|
int last_column,
|
||||||
QSet<QModelIndex>* visited_parent_indices)
|
std::set<QModelIndex>* visited_parent_indices)
|
||||||
{
|
{
|
||||||
assert(first_column <= last_column);
|
assert(first_column <= last_column);
|
||||||
|
|
||||||
|
@ -429,7 +430,7 @@ void FileTreeModel::emitParentsChanged(
|
||||||
|
|
||||||
if (visited_parent_indices != nullptr)
|
if (visited_parent_indices != nullptr)
|
||||||
{
|
{
|
||||||
if (visited_parent_indices->contains(walk))
|
if (visited_parent_indices->count(walk) != 0U)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -525,7 +526,7 @@ void FileTreeModel::setWanted(QModelIndexList const& indices, bool wanted)
|
||||||
|
|
||||||
QModelIndexList const orphan_indices = getOrphanIndices(indices);
|
QModelIndexList const orphan_indices = getOrphanIndices(indices);
|
||||||
|
|
||||||
QSet<int> file_ids;
|
auto file_ids = file_indices_t{};
|
||||||
|
|
||||||
for (QModelIndex const& i : orphan_indices)
|
for (QModelIndex const& i : orphan_indices)
|
||||||
{
|
{
|
||||||
|
@ -537,14 +538,14 @@ void FileTreeModel::setWanted(QModelIndexList const& indices, bool wanted)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit parent changes separately to avoid multiple updates for same items
|
// emit parent changes separately to avoid multiple updates for same items
|
||||||
QSet<QModelIndex> parent_indices;
|
auto parent_indices = std::set<QModelIndex>{};
|
||||||
|
|
||||||
for (QModelIndex const& i : orphan_indices)
|
for (QModelIndex const& i : orphan_indices)
|
||||||
{
|
{
|
||||||
emitParentsChanged(i, COL_SIZE, COL_WANTED, &parent_indices);
|
emitParentsChanged(i, COL_SIZE, COL_WANTED, &parent_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_ids.isEmpty())
|
if (!std::empty(file_ids))
|
||||||
{
|
{
|
||||||
emit wantedChanged(file_ids, wanted);
|
emit wantedChanged(file_ids, wanted);
|
||||||
}
|
}
|
||||||
|
@ -559,7 +560,7 @@ void FileTreeModel::setPriority(QModelIndexList const& indices, int priority)
|
||||||
|
|
||||||
QModelIndexList const orphan_indices = getOrphanIndices(indices);
|
QModelIndexList const orphan_indices = getOrphanIndices(indices);
|
||||||
|
|
||||||
QSet<int> file_ids;
|
auto file_ids = file_indices_t{};
|
||||||
|
|
||||||
for (QModelIndex const& i : orphan_indices)
|
for (QModelIndex const& i : orphan_indices)
|
||||||
{
|
{
|
||||||
|
@ -571,14 +572,13 @@ void FileTreeModel::setPriority(QModelIndexList const& indices, int priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit parent changes separately to avoid multiple updates for same items
|
// emit parent changes separately to avoid multiple updates for same items
|
||||||
QSet<QModelIndex> parent_indices;
|
auto parent_indices = std::set<QModelIndex>{};
|
||||||
|
|
||||||
for (QModelIndex const& i : orphan_indices)
|
for (QModelIndex const& i : orphan_indices)
|
||||||
{
|
{
|
||||||
emitParentsChanged(i, COL_PRIORITY, COL_PRIORITY, &parent_indices);
|
emitParentsChanged(i, COL_PRIORITY, COL_PRIORITY, &parent_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_ids.isEmpty())
|
if (!std::empty(file_ids))
|
||||||
{
|
{
|
||||||
emit priorityChanged(file_ids, priority);
|
emit priorityChanged(file_ids, priority);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@
|
||||||
#include <cstdint> // uint64_t
|
#include <cstdint> // uint64_t
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QSet>
|
|
||||||
|
|
||||||
#include <libtransmission/tr-macros.h>
|
#include <libtransmission/tr-macros.h>
|
||||||
|
|
||||||
|
#include "Typedefs.h" // file_indices_t
|
||||||
|
|
||||||
class FileTreeItem;
|
class FileTreeItem;
|
||||||
|
|
||||||
class FileTreeModel final : public QAbstractItemModel
|
class FileTreeModel final : public QAbstractItemModel
|
||||||
|
@ -77,8 +79,8 @@ public:
|
||||||
bool setData(QModelIndex const& index, QVariant const& value, int role = Qt::EditRole) override;
|
bool setData(QModelIndex const& index, QVariant const& value, int role = Qt::EditRole) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void priorityChanged(QSet<int> const& file_indices, int);
|
void priorityChanged(file_indices_t const& file_indices, int);
|
||||||
void wantedChanged(QSet<int> const& file_indices, bool);
|
void wantedChanged(file_indices_t const& file_indices, bool);
|
||||||
void pathEdited(QString const& oldpath, QString const& new_name);
|
void pathEdited(QString const& oldpath, QString const& new_name);
|
||||||
void openRequested(QString const& path);
|
void openRequested(QString const& path);
|
||||||
|
|
||||||
|
@ -89,7 +91,7 @@ private:
|
||||||
QModelIndex const&,
|
QModelIndex const&,
|
||||||
int first_column,
|
int first_column,
|
||||||
int last_column,
|
int last_column,
|
||||||
QSet<QModelIndex>* visited_parent_indices = nullptr);
|
std::set<QModelIndex>* visited_parent_indices = nullptr);
|
||||||
void emitSubtreeChanged(QModelIndex const&, int first_column, int last_column);
|
void emitSubtreeChanged(QModelIndex const&, int first_column, int last_column);
|
||||||
FileTreeItem* findItemForFileIndex(int file_index) const;
|
FileTreeItem* findItemForFileIndex(int file_index) const;
|
||||||
FileTreeItem* itemFromIndex(QModelIndex const&) const;
|
FileTreeItem* itemFromIndex(QModelIndex const&) const;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -253,7 +254,7 @@ void FileTreeView::onlyCheckSelectedItems()
|
||||||
|
|
||||||
std::sort(wanted_indices.begin(), wanted_indices.end());
|
std::sort(wanted_indices.begin(), wanted_indices.end());
|
||||||
|
|
||||||
QSet<QModelIndex> wanted_indices_parents;
|
auto wanted_indices_parents = std::set<QModelIndex>{};
|
||||||
|
|
||||||
for (QModelIndex const& i : wanted_indices)
|
for (QModelIndex const& i : wanted_indices)
|
||||||
{
|
{
|
||||||
|
@ -294,7 +295,7 @@ void FileTreeView::onlyCheckSelectedItems()
|
||||||
{
|
{
|
||||||
unwanted_indices << child_index;
|
unwanted_indices << child_index;
|
||||||
}
|
}
|
||||||
else if (!wanted_indices_parents.contains(child_index))
|
else if (wanted_indices_parents.count(child_index) == 0U)
|
||||||
{
|
{
|
||||||
unwanted_indices << child_index;
|
unwanted_indices << child_index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QSet>
|
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
#include <libtransmission/tr-macros.h>
|
#include <libtransmission/tr-macros.h>
|
||||||
|
|
||||||
#include "Torrent.h" // FileList
|
#include "Torrent.h" // FileList
|
||||||
|
#include "Typedefs.h" // file_indices_t
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
|
@ -33,8 +33,8 @@ public:
|
||||||
void setEditable(bool editable);
|
void setEditable(bool editable);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void priorityChanged(QSet<int> const& file_indices, int priority);
|
void priorityChanged(file_indices_t const& file_indices, int priority);
|
||||||
void wantedChanged(QSet<int> const& file_indices, bool wanted);
|
void wantedChanged(file_indices_t const& file_indices, bool wanted);
|
||||||
void pathEdited(QString const& old_path, QString const& new_name);
|
void pathEdited(QString const& old_path, QString const& new_name);
|
||||||
void openRequested(QString const& path);
|
void openRequested(QString const& path);
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ void OptionsDialog::onSessionUpdated()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionsDialog::onPriorityChanged(QSet<int> const& file_indices, int priority)
|
void OptionsDialog::onPriorityChanged(file_indices_t const& file_indices, int priority)
|
||||||
{
|
{
|
||||||
for (int const i : file_indices)
|
for (int const i : file_indices)
|
||||||
{
|
{
|
||||||
|
@ -213,7 +213,7 @@ void OptionsDialog::onPriorityChanged(QSet<int> const& file_indices, int priorit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionsDialog::onWantedChanged(QSet<int> const& file_indices, bool is_wanted)
|
void OptionsDialog::onWantedChanged(file_indices_t const& file_indices, bool is_wanted)
|
||||||
{
|
{
|
||||||
for (int const i : file_indices)
|
for (int const i : file_indices)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSet>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@
|
||||||
#include "AddData.h" // AddData
|
#include "AddData.h" // AddData
|
||||||
#include "BaseDialog.h"
|
#include "BaseDialog.h"
|
||||||
#include "Torrent.h" // FileList
|
#include "Torrent.h" // FileList
|
||||||
|
#include "Typedefs.h" // file_indices_t
|
||||||
#include "ui_OptionsDialog.h"
|
#include "ui_OptionsDialog.h"
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
|
@ -45,8 +45,8 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAccepted();
|
void onAccepted();
|
||||||
void onPriorityChanged(QSet<int> const& file_indices, int);
|
void onPriorityChanged(file_indices_t const& file_indices, int);
|
||||||
void onWantedChanged(QSet<int> const& file_indices, bool);
|
void onWantedChanged(file_indices_t const& file_indices, bool);
|
||||||
|
|
||||||
void onSourceChanged();
|
void onSourceChanged();
|
||||||
void onDestinationChanged();
|
void onDestinationChanged();
|
||||||
|
|
|
@ -225,7 +225,7 @@ Prefs::Prefs(QString config_dir)
|
||||||
|
|
||||||
// these are the prefs that don't get saved to settings.json
|
// these are the prefs that don't get saved to settings.json
|
||||||
// when the application exits.
|
// when the application exits.
|
||||||
temporary_prefs_ << FILTER_TEXT;
|
temporary_prefs_.insert(FILTER_TEXT);
|
||||||
|
|
||||||
auto top = get_default_app_settings();
|
auto top = get_default_app_settings();
|
||||||
top.merge(tr_sessionLoadSettings(config_dir_.toUtf8().constData(), nullptr));
|
top.merge(tr_sessionLoadSettings(config_dir_.toUtf8().constData(), nullptr));
|
||||||
|
@ -326,7 +326,7 @@ Prefs::~Prefs()
|
||||||
|
|
||||||
for (int i = 0; i < PREFS_COUNT; ++i)
|
for (int i = 0; i < PREFS_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if (temporary_prefs_.contains(i))
|
if (temporary_prefs_.count(i) != 0U)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ private:
|
||||||
|
|
||||||
QString const config_dir_;
|
QString const config_dir_;
|
||||||
|
|
||||||
QSet<int> temporary_prefs_;
|
std::set<int> temporary_prefs_;
|
||||||
std::array<QVariant, PREFS_COUNT> mutable values_;
|
std::array<QVariant, PREFS_COUNT> mutable values_;
|
||||||
|
|
||||||
static std::array<PrefItem, PREFS_COUNT> const Items;
|
static std::array<PrefItem, PREFS_COUNT> const Items;
|
||||||
|
|
|
@ -460,7 +460,7 @@ Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark cons
|
||||||
return torrentSetImpl(&args);
|
return torrentSetImpl(&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QList<int> const& value)
|
Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, std::vector<int> const& value)
|
||||||
{
|
{
|
||||||
tr_variant args;
|
tr_variant args;
|
||||||
tr_variantInitDict(&args, 2);
|
tr_variantInitDict(&args, 2);
|
||||||
|
|
|
@ -88,7 +88,7 @@ public:
|
||||||
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, int val);
|
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, int val);
|
||||||
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, double val);
|
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, double val);
|
||||||
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QString const& val);
|
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QString const& val);
|
||||||
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QList<int> const& val);
|
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, std::vector<int> const& val);
|
||||||
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QStringList const& val);
|
Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QStringList const& val);
|
||||||
|
|
||||||
void torrentSetLocation(torrent_ids_t const& torrent_ids, QString const& path, bool do_move);
|
void torrentSetLocation(torrent_ids_t const& torrent_ids, QString const& path, bool do_move);
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
|
|
||||||
using torrent_ids_t = std::unordered_set<tr_torrent_id_t>;
|
using torrent_ids_t = std::unordered_set<tr_torrent_id_t>;
|
||||||
|
|
||||||
|
using file_indices_t = std::set<int>;
|
||||||
|
|
|
@ -76,51 +76,44 @@ void WatchDir::setPath(QString const& path, bool is_enabled)
|
||||||
|
|
||||||
void WatchDir::watcherActivated(QString const& path)
|
void WatchDir::watcherActivated(QString const& path)
|
||||||
{
|
{
|
||||||
auto const dir = QDir{ path };
|
|
||||||
|
|
||||||
// get the list of files currently in the watch directory
|
// get the list of files currently in the watch directory
|
||||||
QSet<QString> files;
|
auto const dir = QDir{ path };
|
||||||
|
auto const files = dir.entryList(QDir::Readable | QDir::Files);
|
||||||
for (QString const& str : dir.entryList(QDir::Readable | QDir::Files))
|
|
||||||
{
|
|
||||||
files.insert(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to add any new files which end in torrent
|
// try to add any new files which end in torrent
|
||||||
auto const new_files = files - watch_dir_files_;
|
|
||||||
auto const torrent_suffix = QStringLiteral(".torrent");
|
auto const torrent_suffix = QStringLiteral(".torrent");
|
||||||
|
for (auto const& name : files)
|
||||||
for (QString const& name : new_files)
|
|
||||||
{
|
{
|
||||||
if (name.endsWith(torrent_suffix, Qt::CaseInsensitive))
|
if (!name.endsWith(torrent_suffix, Qt::CaseInsensitive) || (watch_dir_files_.count(name) != 0U))
|
||||||
{
|
{
|
||||||
QString const filename = dir.absoluteFilePath(name);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (metainfoTest(filename))
|
auto const filename = dir.absoluteFilePath(name);
|
||||||
|
switch (metainfoTest(filename))
|
||||||
|
{
|
||||||
|
case AddResult::Success:
|
||||||
|
emit torrentFileAdded(filename);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AddResult::Duplicate:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AddResult::Error:
|
||||||
{
|
{
|
||||||
case AddResult::Success:
|
// give the torrent a few seconds to finish downloading
|
||||||
emit torrentFileAdded(filename);
|
auto* t = new QTimer(this);
|
||||||
break;
|
t->setObjectName(dir.absoluteFilePath(name));
|
||||||
|
t->setSingleShot(true);
|
||||||
case AddResult::Duplicate:
|
connect(t, &QTimer::timeout, this, &WatchDir::onTimeout);
|
||||||
break;
|
t->start(5000);
|
||||||
|
|
||||||
case AddResult::Error:
|
|
||||||
{
|
|
||||||
// give the torrent a few seconds to finish downloading
|
|
||||||
auto* t = new QTimer{ this };
|
|
||||||
t->setObjectName(dir.absoluteFilePath(name));
|
|
||||||
t->setSingleShot(true);
|
|
||||||
connect(t, &QTimer::timeout, this, &WatchDir::onTimeout);
|
|
||||||
t->start(5000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update our file list so that we can use it
|
// update our file list so that we can use it
|
||||||
// for comparison the next time around
|
// for comparison the next time around
|
||||||
watch_dir_files_ = files;
|
watch_dir_files_ = { std::begin(files), std::end(files) };
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchDir::rescanAllWatchedDirectories()
|
void WatchDir::rescanAllWatchedDirectories()
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <QSet>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <libtransmission/tr-macros.h>
|
#include <libtransmission/tr-macros.h>
|
||||||
|
@ -47,6 +47,6 @@ private:
|
||||||
|
|
||||||
TorrentModel const& model_;
|
TorrentModel const& model_;
|
||||||
|
|
||||||
QSet<QString> watch_dir_files_;
|
std::set<QString> watch_dir_files_;
|
||||||
std::unique_ptr<QFileSystemWatcher> watcher_;
|
std::unique_ptr<QFileSystemWatcher> watcher_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue