Make BitTorrent::TorrentState strongly-typed enum

This is needed to forward declare this type and pass it by value.

Conversion from/to QVariant are hanled via Q_DECLARE_METATYPE, while
TorrentState::toString() function was used in webui only and as such is
moved there.
This commit is contained in:
Eugene Shalygin
2017-02-18 01:38:40 +01:00
parent 19bb6f5fe0
commit db35bb54e1
6 changed files with 79 additions and 97 deletions

View File

@@ -131,64 +131,6 @@ AddTorrentData::AddTorrentData(const AddTorrentParams &params)
savePath = Session::instance()->defaultSavePath();
}
// TorrentState
TorrentState::TorrentState(int value)
: m_value(value)
{
}
QString TorrentState::toString() const
{
switch (m_value) {
case Error:
return QLatin1String("error");
case MissingFiles:
return QLatin1String("missingFiles");
case Uploading:
return QLatin1String("uploading");
case PausedUploading:
return QLatin1String("pausedUP");
case QueuedUploading:
return QLatin1String("queuedUP");
case StalledUploading:
return QLatin1String("stalledUP");
case CheckingUploading:
return QLatin1String("checkingUP");
case ForcedUploading:
return QLatin1String("forcedUP");
case Allocating:
return QLatin1String("allocating");
case Downloading:
return QLatin1String("downloading");
case DownloadingMetadata:
return QLatin1String("metaDL");
case PausedDownloading:
return QLatin1String("pausedDL");
case QueuedDownloading:
return QLatin1String("queuedDL");
case StalledDownloading:
return QLatin1String("stalledDL");
case CheckingDownloading:
return QLatin1String("checkingDL");
case ForcedDownloading:
return QLatin1String("forcedDL");
#if LIBTORRENT_VERSION_NUM < 10100
case QueuedForChecking:
return QLatin1String("queuedForChecking");
#endif
case CheckingResumeData:
return QLatin1String("checkingResumeData");
default:
return QLatin1String("unknown");
}
}
TorrentState::operator int() const
{
return m_value;
}
// TorrentHandle
const qreal TorrentHandle::USE_GLOBAL_RATIO = -2.;

View File

@@ -120,48 +120,35 @@ namespace BitTorrent
quint32 numPeers = 0;
};
class TorrentState
enum class TorrentState
{
public:
enum
{
Unknown = -1,
Unknown = -1,
ForcedDownloading,
Downloading,
DownloadingMetadata,
Allocating,
StalledDownloading,
ForcedDownloading,
Downloading,
DownloadingMetadata,
Allocating,
StalledDownloading,
ForcedUploading,
Uploading,
StalledUploading,
QueuedDownloading,
QueuedUploading,
CheckingUploading,
CheckingDownloading,
ForcedUploading,
Uploading,
StalledUploading,
#if LIBTORRENT_VERSION_NUM < 10100
QueuedForChecking,
QueuedForChecking,
#endif
CheckingResumeData,
CheckingResumeData,
QueuedDownloading,
QueuedUploading,
PausedDownloading,
PausedUploading,
CheckingUploading,
CheckingDownloading,
MissingFiles,
Error
};
PausedDownloading,
PausedUploading,
TorrentState(int value);
operator int() const;
QString toString() const;
private:
int m_value;
MissingFiles,
Error
};
class TorrentHandle : public QObject
@@ -474,4 +461,6 @@ namespace BitTorrent
};
}
Q_DECLARE_METATYPE(BitTorrent::TorrentState)
#endif // BITTORRENT_TORRENTHANDLE_H

View File

@@ -37,7 +37,6 @@ typedef QSet<QString> QStringSet;
namespace BitTorrent
{
class TorrentHandle;
class TorrentState;
}
class TorrentFilter