Browse Source

Follow project coding style. Issue #2192.

adaptive-webui-19844
buinsky 10 years ago
parent
commit
6644791458
  1. 859
      src/qtlibtorrent/qtorrenthandle.cpp
  2. 168
      src/qtlibtorrent/qtorrenthandle.h
  3. 1642
      src/transferlistwidget.cpp
  4. 115
      src/transferlistwidget.h
  5. 25
      src/webui/btjson.cpp
  6. 16
      src/webui/www/public/filters.html

859
src/qtlibtorrent/qtorrenthandle.cpp

File diff suppressed because it is too large Load Diff

168
src/qtlibtorrent/qtorrenthandle.h

@ -42,7 +42,8 @@ QT_END_NAMESPACE @@ -42,7 +42,8 @@ QT_END_NAMESPACE
class QTorrentState
{
public:
enum {
enum
{
Unknown = -1,
Error,
@ -71,93 +72,94 @@ private: @@ -71,93 +72,94 @@ private:
// A wrapper for torrent_handle in libtorrent
// to interact well with Qt types
class QTorrentHandle : public libtorrent::torrent_handle {
class QTorrentHandle: public libtorrent::torrent_handle
{
public:
//
// Constructors
//
QTorrentHandle() {}
explicit QTorrentHandle(const libtorrent::torrent_handle& h);
//
// Getters
//
QString hash() const;
QString name() const;
QString current_tracker() const;
bool is_paused() const;
bool has_filtered_pieces() const;
libtorrent::size_type total_size() const;
libtorrent::size_type piece_length() const;
int num_pieces() const;
QString save_path() const;
QString save_path_parsed() const;
QStringList url_seeds() const;
libtorrent::size_type actual_size() const;
int num_files() const;
int queue_position() const;
bool is_queued() const;
QString filename_at(unsigned int index) const;
libtorrent::size_type filesize_at(unsigned int index) const;
QString filepath_at(unsigned int index) const;
QString orig_filepath_at(unsigned int index) const;
libtorrent::torrent_status::state_t state() const;
QString creator() const;
QString comment() const;
QStringList absolute_files_path() const;
QStringList absolute_files_path_uneeded() const;
bool has_missing_files() const;
bool is_seed() const;
bool is_checking() const;
bool is_sequential_download() const;
QString creation_date() const;
qlonglong creation_date_unix() const;
bool priv() const;
bool first_last_piece_first() const;
QString root_path() const;
QString firstFileSavePath() const;
bool has_error() const;
QString error() const;
void downloading_pieces(libtorrent::bitfield& bf) const;
bool has_metadata() const;
void file_progress(std::vector<libtorrent::size_type>& fp) const;
QTorrentState torrentState() const;
qulonglong eta() const;
//
// Setters
//
void pause() const;
void resume() const;
void remove_url_seed(const QString& seed) const;
void add_url_seed(const QString& seed) const;
void set_tracker_login(const QString& username, const QString& password) const;
void move_storage(const QString& path) const;
void prioritize_first_last_piece(bool b) const;
void rename_file(int index, const QString& name) const;
bool save_torrent_file(const QString& path) const;
void prioritize_files(const std::vector<int>& files) const;
void file_priority(int index, int priority) const;
//
// Operators
//
bool operator ==(const QTorrentHandle& new_h) const;
static bool is_paused(const libtorrent::torrent_status &status);
static int queue_position(const libtorrent::torrent_status &status);
static bool is_queued(const libtorrent::torrent_status &status);
static bool is_seed(const libtorrent::torrent_status &status);
static bool is_checking(const libtorrent::torrent_status &status);
static bool has_error(const libtorrent::torrent_status &status);
static float progress(const libtorrent::torrent_status &status);
static QString filepath_at(const libtorrent::torrent_info &info, unsigned int index);
//
// Constructors
//
QTorrentHandle() {}
explicit QTorrentHandle(const libtorrent::torrent_handle& h);
//
// Getters
//
QString hash() const;
QString name() const;
QString current_tracker() const;
bool is_paused() const;
bool has_filtered_pieces() const;
libtorrent::size_type total_size() const;
libtorrent::size_type piece_length() const;
int num_pieces() const;
QString save_path() const;
QString save_path_parsed() const;
QStringList url_seeds() const;
libtorrent::size_type actual_size() const;
int num_files() const;
int queue_position() const;
bool is_queued() const;
QString filename_at(unsigned int index) const;
libtorrent::size_type filesize_at(unsigned int index) const;
QString filepath_at(unsigned int index) const;
QString orig_filepath_at(unsigned int index) const;
libtorrent::torrent_status::state_t state() const;
QString creator() const;
QString comment() const;
QStringList absolute_files_path() const;
QStringList absolute_files_path_uneeded() const;
bool has_missing_files() const;
bool is_seed() const;
bool is_checking() const;
bool is_sequential_download() const;
QString creation_date() const;
qlonglong creation_date_unix() const;
bool priv() const;
bool first_last_piece_first() const;
QString root_path() const;
QString firstFileSavePath() const;
bool has_error() const;
QString error() const;
void downloading_pieces(libtorrent::bitfield& bf) const;
bool has_metadata() const;
void file_progress(std::vector<libtorrent::size_type>& fp) const;
QTorrentState torrentState() const;
qulonglong eta() const;
//
// Setters
//
void pause() const;
void resume() const;
void remove_url_seed(const QString& seed) const;
void add_url_seed(const QString& seed) const;
void set_tracker_login(const QString& username, const QString& password) const;
void move_storage(const QString& path) const;
void prioritize_first_last_piece(bool b) const;
void rename_file(int index, const QString& name) const;
bool save_torrent_file(const QString& path) const;
void prioritize_files(const std::vector<int>& files) const;
void file_priority(int index, int priority) const;
//
// Operators
//
bool operator ==(const QTorrentHandle& new_h) const;
static bool is_paused(const libtorrent::torrent_status &status);
static int queue_position(const libtorrent::torrent_status &status);
static bool is_queued(const libtorrent::torrent_status &status);
static bool is_seed(const libtorrent::torrent_status &status);
static bool is_checking(const libtorrent::torrent_status &status);
static bool has_error(const libtorrent::torrent_status &status);
static float progress(const libtorrent::torrent_status &status);
static QString filepath_at(const libtorrent::torrent_info &info, unsigned int index);
private:
void prioritize_first_last_piece(int file_index, bool b) const;
void prioritize_first_last_piece(int file_index, bool b) const;
};

1642
src/transferlistwidget.cpp

File diff suppressed because it is too large Load Diff

115
src/transferlistwidget.h

@ -47,77 +47,78 @@ class QSortFilterProxyModel; @@ -47,77 +47,78 @@ class QSortFilterProxyModel;
class QStandardItemModel;
QT_END_NAMESPACE
class TransferListWidget: public QTreeView {
Q_OBJECT
class TransferListWidget: public QTreeView
{
Q_OBJECT
public:
TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession* BTSession);
~TransferListWidget();
TorrentModel* getSourceModel() const;
TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession* BTSession);
~TransferListWidget();
TorrentModel* getSourceModel() const;
public slots:
void setSelectionLabel(QString label);
void setRefreshInterval(int t);
void setSelectedTorrentsLocation();
void startSelectedTorrents();
void startVisibleTorrents();
void pauseSelectedTorrents();
void pauseVisibleTorrents();
void deleteSelectedTorrents();
void deleteVisibleTorrents();
void increasePrioSelectedTorrents();
void decreasePrioSelectedTorrents();
void topPrioSelectedTorrents();
void bottomPrioSelectedTorrents();
void copySelectedMagnetURIs() const;
void openSelectedTorrentsFolder() const;
void recheckSelectedTorrents();
void setDlLimitSelectedTorrents();
void setUpLimitSelectedTorrents();
void setMaxRatioSelectedTorrents();
void previewSelectedTorrents();
void hidePriorityColumn(bool hide);
void displayDLHoSMenu(const QPoint&);
void applyNameFilter(const QString& name);
void applyStatusFilter(int f);
void applyLabelFilterAll();
void applyLabelFilter(QString label);
void previewFile(QString filePath);
void removeLabelFromRows(QString label);
void renameSelectedTorrent();
void setSelectionLabel(QString label);
void setRefreshInterval(int t);
void setSelectedTorrentsLocation();
void startSelectedTorrents();
void startVisibleTorrents();
void pauseSelectedTorrents();
void pauseVisibleTorrents();
void deleteSelectedTorrents();
void deleteVisibleTorrents();
void increasePrioSelectedTorrents();
void decreasePrioSelectedTorrents();
void topPrioSelectedTorrents();
void bottomPrioSelectedTorrents();
void copySelectedMagnetURIs() const;
void openSelectedTorrentsFolder() const;
void recheckSelectedTorrents();
void setDlLimitSelectedTorrents();
void setUpLimitSelectedTorrents();
void setMaxRatioSelectedTorrents();
void previewSelectedTorrents();
void hidePriorityColumn(bool hide);
void displayDLHoSMenu(const QPoint&);
void applyNameFilter(const QString& name);
void applyStatusFilter(int f);
void applyLabelFilterAll();
void applyLabelFilter(QString label);
void previewFile(QString filePath);
void removeLabelFromRows(QString label);
void renameSelectedTorrent();
protected:
int getRowFromHash(QString hash) const;
QString getHashFromRow(int row) const;
QModelIndex mapToSource(const QModelIndex &index) const;
QModelIndex mapFromSource(const QModelIndex &index) const;
void saveSettings();
bool loadSettings();
QStringList getSelectedTorrentsHashes() const;
int getRowFromHash(QString hash) const;
QString getHashFromRow(int row) const;
QModelIndex mapToSource(const QModelIndex &index) const;
QModelIndex mapFromSource(const QModelIndex &index) const;
void saveSettings();
bool loadSettings();
QStringList getSelectedTorrentsHashes() const;
protected slots:
void torrentDoubleClicked(const QModelIndex& index);
void displayListMenu(const QPoint&);
void currentChanged(const QModelIndex& current, const QModelIndex&);
void toggleSelectedTorrentsSuperSeeding() const;
void toggleSelectedTorrentsSequentialDownload() const;
void toggleSelectedFirstLastPiecePrio() const;
void askNewLabelForSelection();
void torrentDoubleClicked(const QModelIndex& index);
void displayListMenu(const QPoint&);
void currentChanged(const QModelIndex& current, const QModelIndex&);
void toggleSelectedTorrentsSuperSeeding() const;
void toggleSelectedTorrentsSequentialDownload() const;
void toggleSelectedFirstLastPiecePrio() const;
void askNewLabelForSelection();
private:
bool openUrl(const QString& _path) const;
bool openUrl(const QString& _path) const;
signals:
void currentTorrentChanged(const QTorrentHandle &h);
void currentTorrentChanged(const QTorrentHandle &h);
private:
TransferListDelegate *listDelegate;
TorrentModel *listModel;
TransferListSortModel *nameFilterModel;
QBtSession* BTSession;
MainWindow *main_window;
QShortcut *editHotkey;
QShortcut *deleteHotkey;
TransferListDelegate *listDelegate;
TorrentModel *listModel;
TransferListSortModel *nameFilterModel;
QBtSession* BTSession;
MainWindow *main_window;
QShortcut *editHotkey;
QShortcut *deleteHotkey;
};
#endif // TRANSFERLISTWIDGET_H

25
src/webui/btjson.cpp

@ -55,7 +55,7 @@ using namespace libtorrent; @@ -55,7 +55,7 @@ using namespace libtorrent;
static QElapsedTimer cacheTimer; \
static bool initialized = false; \
if (initialized && !cacheTimer.hasExpired(DUR)) \
return json::toJson(VAR); \
return json::toJson(VAR); \
initialized = true; \
cacheTimer.start(); \
VAR = VARTYPE()
@ -65,7 +65,7 @@ using namespace libtorrent; @@ -65,7 +65,7 @@ using namespace libtorrent;
static QString prev_hash; \
static QElapsedTimer cacheTimer; \
if (prev_hash == HASH && !cacheTimer.hasExpired(DUR)) \
return json::toJson(VAR); \
return json::toJson(VAR); \
prev_hash = HASH; \
cacheTimer.start(); \
VAR = VARTYPE()
@ -157,26 +157,26 @@ public: @@ -157,26 +157,26 @@ public:
switch (type_) {
case QVariant::Int:
return greaterThan_ ? torrent1.toMap().value(key_).toInt() > torrent2.toMap().value(key_).toInt()
: torrent1.toMap().value(key_).toInt() < torrent2.toMap().value(key_).toInt();
: torrent1.toMap().value(key_).toInt() < torrent2.toMap().value(key_).toInt();
case QVariant::LongLong:
return greaterThan_ ? torrent1.toMap().value(key_).toLongLong() > torrent2.toMap().value(key_).toLongLong()
: torrent1.toMap().value(key_).toLongLong() < torrent2.toMap().value(key_).toLongLong();
: torrent1.toMap().value(key_).toLongLong() < torrent2.toMap().value(key_).toLongLong();
case QVariant::ULongLong:
return greaterThan_ ? torrent1.toMap().value(key_).toULongLong() > torrent2.toMap().value(key_).toULongLong()
: torrent1.toMap().value(key_).toULongLong() < torrent2.toMap().value(key_).toULongLong();
: torrent1.toMap().value(key_).toULongLong() < torrent2.toMap().value(key_).toULongLong();
case QMetaType::Float:
return greaterThan_ ? torrent1.toMap().value(key_).toFloat() > torrent2.toMap().value(key_).toFloat()
: torrent1.toMap().value(key_).toFloat() < torrent2.toMap().value(key_).toFloat();
: torrent1.toMap().value(key_).toFloat() < torrent2.toMap().value(key_).toFloat();
case QVariant::Double:
return greaterThan_ ? torrent1.toMap().value(key_).toDouble() > torrent2.toMap().value(key_).toDouble()
: torrent1.toMap().value(key_).toDouble() < torrent2.toMap().value(key_).toDouble();
: torrent1.toMap().value(key_).toDouble() < torrent2.toMap().value(key_).toDouble();
default:
return greaterThan_ ? torrent1.toMap().value(key_).toString() > torrent2.toMap().value(key_).toString()
: torrent1.toMap().value(key_).toString() < torrent2.toMap().value(key_).toString();
: torrent1.toMap().value(key_).toString() < torrent2.toMap().value(key_).toString();
}
#else
return greaterThan_ ? torrent1.toMap().value(key_) > torrent2.toMap().value(key_)
: torrent1.toMap().value(key_) < torrent2.toMap().value(key_);
: torrent1.toMap().value(key_) < torrent2.toMap().value(key_);
#endif
}
@ -236,7 +236,7 @@ static QVariantMap toMap(const QTorrentHandle& h) @@ -236,7 +236,7 @@ static QVariantMap toMap(const QTorrentHandle& h)
* - "state": Torrent state
*/
QByteArray btjson::getTorrents(QString filter, QString label,
QString sortedColumn, bool reverse, int limit, int offset)
QString sortedColumn, bool reverse, int limit, int offset)
{
QVariantList torrent_list;
@ -245,7 +245,7 @@ QByteArray btjson::getTorrents(QString filter, QString label, @@ -245,7 +245,7 @@ QByteArray btjson::getTorrents(QString filter, QString label,
std::vector<torrent_handle>::const_iterator end = torrents.end();
QTorrentFilter torrentFilter(filter, label);
for( ; it != end; ++it) {
for(; it != end; ++it) {
QTorrentHandle torrent = QTorrentHandle(*it);
if (torrentFilter.apply(torrent))
@ -294,8 +294,9 @@ QByteArray btjson::getTrackersForTorrent(const QString& hash) @@ -294,8 +294,9 @@ QByteArray btjson::getTrackersForTorrent(const QString& hash)
tracker_dict[KEY_TRACKER_URL] = tracker_url;
const TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
QString status;
if (it->verified)
if (it->verified) {
status = tr("Working");
}
else {
if (it->updating && it->fails == 0)
status = tr("Updating...");

16
src/webui/www/public/filters.html

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
<ul class="filterList">
<li id="all_filter"><a href="#" onclick="setFilter('all');"><img src="images/skin/filterall.png"/>_(All)</a></li>
<li id="downloading_filter"><a href="#" onclick="setFilter('downloading');"><img src="images/skin/downloading.png"/>_(Downloading)</a></li>
<li id="completed_filter"><a href="#" onclick="setFilter('completed');"><img src="images/skin/uploading.png"/>_(Completed)</a></li>
<li id="paused_filter"><a href="#" onclick="setFilter('paused');"><img src="images/skin/paused.png"/>_(Paused)</a></li>
<li id="active_filter"><a href="#" onclick="setFilter('active');"><img src="images/skin/filteractive.png"/>_(Active)</a></li>
<li id="inactive_filter"><a href="#" onclick="setFilter('inactive');"><img src="images/skin/filterinactive.png"/>_(Inactive)</a></li>
</ul>
<ul class="filterList">
<li id="all_filter"><a href="#" onclick="setFilter('all');"><img src="images/skin/filterall.png"/>_(All)</a></li>
<li id="downloading_filter"><a href="#" onclick="setFilter('downloading');"><img src="images/skin/downloading.png"/>_(Downloading)</a></li>
<li id="completed_filter"><a href="#" onclick="setFilter('completed');"><img src="images/skin/uploading.png"/>_(Completed)</a></li>
<li id="paused_filter"><a href="#" onclick="setFilter('paused');"><img src="images/skin/paused.png"/>_(Paused)</a></li>
<li id="active_filter"><a href="#" onclick="setFilter('active');"><img src="images/skin/filteractive.png"/>_(Active)</a></li>
<li id="inactive_filter"><a href="#" onclick="setFilter('inactive');"><img src="images/skin/filterinactive.png"/>_(Inactive)</a></li>
</ul>
Loading…
Cancel
Save