mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 01:44:26 +00:00
Use c++11 enum classes instead of macros.
This commit is contained in:
parent
12d9898b5d
commit
b519700e33
@ -63,7 +63,7 @@ namespace
|
|||||||
const quint32 __ENDIAN_TEST__ = 0x00000001;
|
const quint32 __ENDIAN_TEST__ = 0x00000001;
|
||||||
const bool __IS_LITTLE_ENDIAN__ = (reinterpret_cast<const uchar *>(&__ENDIAN_TEST__)[0] == 0x01);
|
const bool __IS_LITTLE_ENDIAN__ = (reinterpret_cast<const uchar *>(&__ENDIAN_TEST__)[0] == 0x01);
|
||||||
|
|
||||||
BEGIN_SCOPED_ENUM(DataType)
|
enum class DataType
|
||||||
{
|
{
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
Pointer = 1,
|
Pointer = 1,
|
||||||
@ -81,8 +81,7 @@ namespace
|
|||||||
EndMarker = 13,
|
EndMarker = 13,
|
||||||
Boolean = 14,
|
Boolean = 14,
|
||||||
Float = 15
|
Float = 15
|
||||||
}
|
};
|
||||||
END_SCOPED_ENUM
|
|
||||||
|
|
||||||
struct DataFieldDescriptor
|
struct DataFieldDescriptor
|
||||||
{
|
{
|
||||||
|
@ -974,12 +974,12 @@ void Preferences::setGlobalMaxRatio(qreal ratio)
|
|||||||
|
|
||||||
MaxRatioAction Preferences::getMaxRatioAction() const
|
MaxRatioAction Preferences::getMaxRatioAction() const
|
||||||
{
|
{
|
||||||
return value("Preferences/Bittorrent/MaxRatioAction", MaxRatioAction::Pause).toInt();
|
return value("Preferences/Bittorrent/MaxRatioAction", QVariant::fromValue(MaxRatioAction::Pause)).value<MaxRatioAction>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preferences::setMaxRatioAction(MaxRatioAction act)
|
void Preferences::setMaxRatioAction(MaxRatioAction act)
|
||||||
{
|
{
|
||||||
setValue("Preferences/Bittorrent/MaxRatioAction", act);
|
setValue("Preferences/Bittorrent/MaxRatioAction", QVariant::fromValue(act));
|
||||||
}
|
}
|
||||||
|
|
||||||
// IP Filter
|
// IP Filter
|
||||||
|
@ -31,43 +31,28 @@
|
|||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#define BEGIN_SCOPED_ENUM(name) class name\
|
|
||||||
{\
|
|
||||||
int m_val;\
|
|
||||||
\
|
|
||||||
public:\
|
|
||||||
name() {}\
|
|
||||||
name(int val) : m_val(val) {}\
|
|
||||||
operator int() const { return m_val; }\
|
|
||||||
operator QVariant() const { return m_val; }\
|
|
||||||
\
|
|
||||||
enum
|
|
||||||
|
|
||||||
#define END_SCOPED_ENUM ; };
|
|
||||||
|
|
||||||
const qlonglong MAX_ETA = 8640000;
|
const qlonglong MAX_ETA = 8640000;
|
||||||
|
|
||||||
BEGIN_SCOPED_ENUM(MaxRatioAction)
|
enum class MaxRatioAction
|
||||||
{
|
{
|
||||||
Pause,
|
Pause,
|
||||||
Remove
|
Remove
|
||||||
}
|
};
|
||||||
END_SCOPED_ENUM
|
|
||||||
|
|
||||||
BEGIN_SCOPED_ENUM(TorrentExportFolder)
|
Q_DECLARE_METATYPE(MaxRatioAction)
|
||||||
|
|
||||||
|
enum class TorrentExportFolder
|
||||||
{
|
{
|
||||||
Regular,
|
Regular,
|
||||||
Finished
|
Finished
|
||||||
}
|
};
|
||||||
END_SCOPED_ENUM
|
|
||||||
|
|
||||||
BEGIN_SCOPED_ENUM(ShutdownAction)
|
enum class ShutdownAction
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Shutdown,
|
Shutdown,
|
||||||
Suspend,
|
Suspend,
|
||||||
Hibernate
|
Hibernate
|
||||||
}
|
};
|
||||||
END_SCOPED_ENUM
|
|
||||||
|
|
||||||
#endif // TYPES_H
|
#endif // TYPES_H
|
||||||
|
@ -469,7 +469,7 @@ void options_imp::saveOptions()
|
|||||||
pref->setEncryptionSetting(getEncryptionSetting());
|
pref->setEncryptionSetting(getEncryptionSetting());
|
||||||
pref->enableAnonymousMode(checkAnonymousMode->isChecked());
|
pref->enableAnonymousMode(checkAnonymousMode->isChecked());
|
||||||
pref->setGlobalMaxRatio(getMaxRatio());
|
pref->setGlobalMaxRatio(getMaxRatio());
|
||||||
pref->setMaxRatioAction(comboRatioLimitAct->currentIndex());
|
pref->setMaxRatioAction(static_cast<MaxRatioAction>(comboRatioLimitAct->currentIndex()));
|
||||||
// End Bittorrent preferences
|
// End Bittorrent preferences
|
||||||
// Misc preferences
|
// Misc preferences
|
||||||
// * IPFilter
|
// * IPFilter
|
||||||
@ -804,7 +804,7 @@ void options_imp::loadOptions()
|
|||||||
spinMaxRatio->setEnabled(false);
|
spinMaxRatio->setEnabled(false);
|
||||||
comboRatioLimitAct->setEnabled(false);
|
comboRatioLimitAct->setEnabled(false);
|
||||||
}
|
}
|
||||||
comboRatioLimitAct->setCurrentIndex(pref->getMaxRatioAction());
|
comboRatioLimitAct->setCurrentIndex(static_cast<int>(pref->getMaxRatioAction()));
|
||||||
// End Bittorrent preferences
|
// End Bittorrent preferences
|
||||||
|
|
||||||
// Web UI preferences
|
// Web UI preferences
|
||||||
|
@ -141,7 +141,7 @@ QByteArray prefjson::getPreferences()
|
|||||||
// Share Ratio Limiting
|
// Share Ratio Limiting
|
||||||
data["max_ratio_enabled"] = (pref->getGlobalMaxRatio() >= 0.);
|
data["max_ratio_enabled"] = (pref->getGlobalMaxRatio() >= 0.);
|
||||||
data["max_ratio"] = pref->getGlobalMaxRatio();
|
data["max_ratio"] = pref->getGlobalMaxRatio();
|
||||||
data["max_ratio_act"] = pref->getMaxRatioAction();
|
data["max_ratio_act"] = QVariant::fromValue(pref->getMaxRatioAction());
|
||||||
|
|
||||||
// Web UI
|
// Web UI
|
||||||
// Language
|
// Language
|
||||||
@ -337,7 +337,7 @@ void prefjson::setPreferences(const QString& json)
|
|||||||
else
|
else
|
||||||
pref->setGlobalMaxRatio(-1);
|
pref->setGlobalMaxRatio(-1);
|
||||||
if (m.contains("max_ratio_act"))
|
if (m.contains("max_ratio_act"))
|
||||||
pref->setMaxRatioAction(m["max_ratio_act"].toInt());
|
pref->setMaxRatioAction(m["max_ratio_act"].value<MaxRatioAction>());
|
||||||
|
|
||||||
// Web UI
|
// Web UI
|
||||||
// Language
|
// Language
|
||||||
|
Loading…
x
Reference in New Issue
Block a user