mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08: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 bool __IS_LITTLE_ENDIAN__ = (reinterpret_cast<const uchar *>(&__ENDIAN_TEST__)[0] == 0x01);
|
||||
|
||||
BEGIN_SCOPED_ENUM(DataType)
|
||||
enum class DataType
|
||||
{
|
||||
Unknown = 0,
|
||||
Pointer = 1,
|
||||
@ -81,8 +81,7 @@ namespace
|
||||
EndMarker = 13,
|
||||
Boolean = 14,
|
||||
Float = 15
|
||||
}
|
||||
END_SCOPED_ENUM
|
||||
};
|
||||
|
||||
struct DataFieldDescriptor
|
||||
{
|
||||
|
@ -974,12 +974,12 @@ void Preferences::setGlobalMaxRatio(qreal ratio)
|
||||
|
||||
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)
|
||||
{
|
||||
setValue("Preferences/Bittorrent/MaxRatioAction", act);
|
||||
setValue("Preferences/Bittorrent/MaxRatioAction", QVariant::fromValue(act));
|
||||
}
|
||||
|
||||
// IP Filter
|
||||
|
@ -31,43 +31,28 @@
|
||||
|
||||
#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;
|
||||
|
||||
BEGIN_SCOPED_ENUM(MaxRatioAction)
|
||||
enum class MaxRatioAction
|
||||
{
|
||||
Pause,
|
||||
Remove
|
||||
}
|
||||
END_SCOPED_ENUM
|
||||
};
|
||||
|
||||
BEGIN_SCOPED_ENUM(TorrentExportFolder)
|
||||
Q_DECLARE_METATYPE(MaxRatioAction)
|
||||
|
||||
enum class TorrentExportFolder
|
||||
{
|
||||
Regular,
|
||||
Finished
|
||||
}
|
||||
END_SCOPED_ENUM
|
||||
};
|
||||
|
||||
BEGIN_SCOPED_ENUM(ShutdownAction)
|
||||
enum class ShutdownAction
|
||||
{
|
||||
None,
|
||||
Shutdown,
|
||||
Suspend,
|
||||
Hibernate
|
||||
}
|
||||
END_SCOPED_ENUM
|
||||
};
|
||||
|
||||
#endif // TYPES_H
|
||||
|
@ -469,7 +469,7 @@ void options_imp::saveOptions()
|
||||
pref->setEncryptionSetting(getEncryptionSetting());
|
||||
pref->enableAnonymousMode(checkAnonymousMode->isChecked());
|
||||
pref->setGlobalMaxRatio(getMaxRatio());
|
||||
pref->setMaxRatioAction(comboRatioLimitAct->currentIndex());
|
||||
pref->setMaxRatioAction(static_cast<MaxRatioAction>(comboRatioLimitAct->currentIndex()));
|
||||
// End Bittorrent preferences
|
||||
// Misc preferences
|
||||
// * IPFilter
|
||||
@ -804,7 +804,7 @@ void options_imp::loadOptions()
|
||||
spinMaxRatio->setEnabled(false);
|
||||
comboRatioLimitAct->setEnabled(false);
|
||||
}
|
||||
comboRatioLimitAct->setCurrentIndex(pref->getMaxRatioAction());
|
||||
comboRatioLimitAct->setCurrentIndex(static_cast<int>(pref->getMaxRatioAction()));
|
||||
// End Bittorrent preferences
|
||||
|
||||
// Web UI preferences
|
||||
|
@ -141,7 +141,7 @@ QByteArray prefjson::getPreferences()
|
||||
// Share Ratio Limiting
|
||||
data["max_ratio_enabled"] = (pref->getGlobalMaxRatio() >= 0.);
|
||||
data["max_ratio"] = pref->getGlobalMaxRatio();
|
||||
data["max_ratio_act"] = pref->getMaxRatioAction();
|
||||
data["max_ratio_act"] = QVariant::fromValue(pref->getMaxRatioAction());
|
||||
|
||||
// Web UI
|
||||
// Language
|
||||
@ -337,7 +337,7 @@ void prefjson::setPreferences(const QString& json)
|
||||
else
|
||||
pref->setGlobalMaxRatio(-1);
|
||||
if (m.contains("max_ratio_act"))
|
||||
pref->setMaxRatioAction(m["max_ratio_act"].toInt());
|
||||
pref->setMaxRatioAction(m["max_ratio_act"].value<MaxRatioAction>());
|
||||
|
||||
// Web UI
|
||||
// Language
|
||||
|
Loading…
Reference in New Issue
Block a user