Browse Source

Use c++11 enum classes instead of macros.

adaptive-webui-19844
Vladimir Golovnev (Glassez) 9 years ago
parent
commit
b519700e33
  1. 5
      src/core/net/private/geoipdatabase.cpp
  2. 4
      src/core/preferences.cpp
  3. 31
      src/core/types.h
  4. 4
      src/gui/options_imp.cpp
  5. 4
      src/webui/prefjson.cpp

5
src/core/net/private/geoipdatabase.cpp

@ -63,7 +63,7 @@ namespace @@ -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 @@ -81,8 +81,7 @@ namespace
EndMarker = 13,
Boolean = 14,
Float = 15
}
END_SCOPED_ENUM
};
struct DataFieldDescriptor
{

4
src/core/preferences.cpp

@ -974,12 +974,12 @@ void Preferences::setGlobalMaxRatio(qreal ratio) @@ -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
src/core/types.h

@ -31,43 +31,28 @@ @@ -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
};
Q_DECLARE_METATYPE(MaxRatioAction)
BEGIN_SCOPED_ENUM(TorrentExportFolder)
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

4
src/gui/options_imp.cpp

@ -469,7 +469,7 @@ void options_imp::saveOptions() @@ -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() @@ -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

4
src/webui/prefjson.cpp

@ -141,7 +141,7 @@ QByteArray prefjson::getPreferences() @@ -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) @@ -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…
Cancel
Save