mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
convert RS_OPMODE to enum class
This commit is contained in:
parent
c285bb0ab8
commit
1a7510b2c9
@ -120,10 +120,13 @@ enum class RsConfigUserLvl : uint8_t
|
||||
#define RS_CONFIG_ADVANCED 0x0101
|
||||
|
||||
|
||||
#define RS_OPMODE_FULL 0x0001
|
||||
#define RS_OPMODE_NOTURTLE 0x0002
|
||||
#define RS_OPMODE_GAMING 0x0003
|
||||
#define RS_OPMODE_MINIMAL 0x0004
|
||||
enum class RsOpMode : uint8_t
|
||||
{
|
||||
FULL = 1,
|
||||
NOTURTLE= 2,
|
||||
GAMING = 3,
|
||||
MINIMAL = 4
|
||||
};
|
||||
|
||||
|
||||
class RsConfigStartup
|
||||
@ -371,7 +374,7 @@ public:
|
||||
* @jsonapi{development}
|
||||
* @return return the current operating mode
|
||||
*/
|
||||
virtual uint32_t getOperatingMode() = 0;
|
||||
virtual RsOpMode getOperatingMode() = 0;
|
||||
|
||||
/**
|
||||
* @brief setOperatingMode set the current oprating mode
|
||||
@ -379,7 +382,7 @@ public:
|
||||
* @param[in] opMode new opearting mode
|
||||
* @return
|
||||
*/
|
||||
virtual bool setOperatingMode(uint32_t opMode) = 0;
|
||||
virtual bool setOperatingMode(RsOpMode opMode) = 0;
|
||||
|
||||
/**
|
||||
* @brief setOperatingMode set the current operating mode from string
|
||||
|
@ -52,7 +52,7 @@ p3ServerConfig::p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr
|
||||
mRateDownload = DEFAULT_DOWNLOAD_KB_RATE;
|
||||
mRateUpload = DEFAULT_UPLOAD_KB_RATE;
|
||||
|
||||
mOpMode = RS_OPMODE_FULL;
|
||||
mOpMode = RsOpMode::FULL;
|
||||
|
||||
rsConfig = this;
|
||||
}
|
||||
@ -86,7 +86,7 @@ void p3ServerConfig::load_config()
|
||||
}
|
||||
|
||||
/* enable operating mode */
|
||||
uint32_t opMode = getOperatingMode();
|
||||
RsOpMode opMode = getOperatingMode();
|
||||
switchToOperatingMode(opMode);
|
||||
}
|
||||
|
||||
@ -357,27 +357,27 @@ RsConnectModes p3ServerConfig::getConnectModes()
|
||||
/* Operating Mode */
|
||||
#define RS_CONFIG_OPERATING_STRING "OperatingMode"
|
||||
|
||||
uint32_t p3ServerConfig::getOperatingMode()
|
||||
RsOpMode p3ServerConfig::getOperatingMode()
|
||||
{
|
||||
#ifdef SAVE_OPERATING_MODE
|
||||
std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING);
|
||||
uint32_t mode = RS_OPMODE_FULL;
|
||||
uint32_t mode = RsOpMode::FULL;
|
||||
|
||||
if (modestr == "FULL")
|
||||
{
|
||||
mode = RS_OPMODE_FULL;
|
||||
mode = RsOpMode::FULL;
|
||||
}
|
||||
else if (modestr == "NOTURTLE")
|
||||
{
|
||||
mode = RS_OPMODE_NOTURTLE;
|
||||
mode = RsOpMode::NOTURTLE;
|
||||
}
|
||||
else if (modestr == "GAMING")
|
||||
{
|
||||
mode = RS_OPMODE_GAMING;
|
||||
mode = RsOpMode::GAMING;
|
||||
}
|
||||
else if (modestr == "MINIMAL")
|
||||
{
|
||||
mode = RS_OPMODE_MINIMAL;
|
||||
mode = RsOpMode::MINIMAL;
|
||||
}
|
||||
return mode;
|
||||
#else
|
||||
@ -387,24 +387,24 @@ uint32_t p3ServerConfig::getOperatingMode()
|
||||
}
|
||||
|
||||
|
||||
bool p3ServerConfig::setOperatingMode(uint32_t opMode)
|
||||
bool p3ServerConfig::setOperatingMode(RsOpMode opMode)
|
||||
{
|
||||
#ifdef SAVE_OPERATING_MODE
|
||||
std::string modestr = "FULL";
|
||||
switch(opMode)
|
||||
{
|
||||
case RS_OPMODE_FULL:
|
||||
case RsOpMode::FULL:
|
||||
modestr = "FULL";
|
||||
break;
|
||||
case RS_OPMODE_NOTURTLE:
|
||||
case RsOpMode::NOTURTLE:
|
||||
modestr = "NOTURTLE";
|
||||
|
||||
break;
|
||||
case RS_OPMODE_GAMING:
|
||||
case RsOpMode::GAMING:
|
||||
modestr = "GAMING";
|
||||
|
||||
break;
|
||||
case RS_OPMODE_MINIMAL:
|
||||
case RsOpMode::MINIMAL:
|
||||
modestr = "MINIMAL";
|
||||
break;
|
||||
}
|
||||
@ -420,31 +420,31 @@ bool p3ServerConfig::setOperatingMode(uint32_t opMode)
|
||||
|
||||
bool p3ServerConfig::setOperatingMode(const std::string &opModeStr)
|
||||
{
|
||||
uint32_t opMode = RS_OPMODE_FULL;
|
||||
RsOpMode opMode = RsOpMode::FULL;
|
||||
std::string upper;
|
||||
stringToUpperCase(opModeStr, upper);
|
||||
|
||||
if (upper == "NOTURTLE")
|
||||
{
|
||||
opMode = RS_OPMODE_NOTURTLE;
|
||||
opMode = RsOpMode::NOTURTLE;
|
||||
}
|
||||
else if (upper == "GAMING")
|
||||
{
|
||||
opMode = RS_OPMODE_GAMING;
|
||||
opMode = RsOpMode::GAMING;
|
||||
}
|
||||
else if (upper == "MINIMAL")
|
||||
{
|
||||
opMode = RS_OPMODE_MINIMAL;
|
||||
opMode = RsOpMode::MINIMAL;
|
||||
}
|
||||
else // "FULL" by default
|
||||
{
|
||||
opMode = RS_OPMODE_FULL;
|
||||
opMode = RsOpMode::FULL;
|
||||
}
|
||||
|
||||
return setOperatingMode(opMode);
|
||||
}
|
||||
|
||||
bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
|
||||
bool p3ServerConfig::switchToOperatingMode(RsOpMode opMode)
|
||||
{
|
||||
float dl_rate = 0;
|
||||
float ul_rate = 0;
|
||||
@ -456,13 +456,13 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
|
||||
ul_rate = mRateUpload;
|
||||
}
|
||||
|
||||
std::cerr << "p3ServerConfig::switchToOperatingMode(" << opMode << ")";
|
||||
std::cerr << "p3ServerConfig::switchToOperatingMode(" << static_cast<typename std::underlying_type<RsOpMode>::type>(opMode) << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
switch (opMode)
|
||||
{
|
||||
default:
|
||||
case RS_OPMODE_FULL:
|
||||
case RsOpMode::FULL:
|
||||
/* switch on all transfers */
|
||||
/* 100% bandwidth */
|
||||
/* switch on popups, enable hashing */
|
||||
@ -470,14 +470,14 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
|
||||
//setMaxRate(false, mro); // Out / Upload.
|
||||
turtle_enabled = true;
|
||||
break;
|
||||
case RS_OPMODE_NOTURTLE:
|
||||
case RsOpMode::NOTURTLE:
|
||||
/* switch on all transfers - except turtle, enable hashing */
|
||||
/* 100% bandwidth */
|
||||
/* switch on popups, enable hashing */
|
||||
turtle_enabled = false;
|
||||
|
||||
break;
|
||||
case RS_OPMODE_GAMING:
|
||||
case RsOpMode::GAMING:
|
||||
/* switch on all transfers */
|
||||
/* reduce bandwidth to 25% */
|
||||
/* switch off popups, enable hashing */
|
||||
@ -486,7 +486,7 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
|
||||
dl_rate *= 0.25;
|
||||
ul_rate *= 0.25;
|
||||
break;
|
||||
case RS_OPMODE_MINIMAL:
|
||||
case RsOpMode::MINIMAL:
|
||||
/* switch off all transfers */
|
||||
/* reduce bandwidth to 10%, but make sure there is enough for VoIP */
|
||||
/* switch on popups, enable hashing */
|
||||
|
@ -84,8 +84,8 @@ virtual bool getConfigurationOption(uint32_t key, std::string &opt);
|
||||
virtual bool setConfigurationOption(uint32_t key, const std::string &opt);
|
||||
|
||||
/* Operating Mode */
|
||||
virtual uint32_t getOperatingMode();
|
||||
virtual bool setOperatingMode(uint32_t opMode);
|
||||
virtual RsOpMode getOperatingMode();
|
||||
virtual bool setOperatingMode(RsOpMode opMode);
|
||||
virtual bool setOperatingMode(const std::string &opModeStr);
|
||||
|
||||
virtual int SetMaxDataRates( int downKb, int upKb );
|
||||
@ -97,7 +97,7 @@ virtual int GetTrafficSum( uint64_t &inb, uint64_t &outb );
|
||||
|
||||
private:
|
||||
|
||||
bool switchToOperatingMode(uint32_t opMode);
|
||||
bool switchToOperatingMode(RsOpMode opMode);
|
||||
|
||||
bool findConfigurationOption(uint32_t key, std::string &keystr);
|
||||
|
||||
@ -112,7 +112,7 @@ bool findConfigurationOption(uint32_t key, std::string &keystr);
|
||||
float mRateDownload;
|
||||
float mRateUpload;
|
||||
|
||||
uint32_t mOpMode;
|
||||
RsOpMode mOpMode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1548,13 +1548,13 @@ void MainWindow::processLastArgs()
|
||||
if (opModeStatus) {
|
||||
QString opmode = Rshare::opmode().toLower();
|
||||
if (opmode == "noturtle") {
|
||||
opModeStatus->setCurrentIndex(RS_OPMODE_NOTURTLE - 1);
|
||||
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
|
||||
} else if (opmode == "gaming") {
|
||||
opModeStatus->setCurrentIndex(RS_OPMODE_GAMING - 1);
|
||||
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::GAMING) - 1);
|
||||
} else if (opmode == "minimal") {
|
||||
opModeStatus->setCurrentIndex(RS_OPMODE_MINIMAL - 1);
|
||||
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::MINIMAL) - 1);
|
||||
} else if (opmode != "") {
|
||||
opModeStatus->setCurrentIndex(RS_OPMODE_FULL - 1);
|
||||
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::FULL) - 1);
|
||||
}
|
||||
opModeStatus->setOpMode();
|
||||
} else {
|
||||
|
@ -39,13 +39,13 @@ OpModeStatus::OpModeStatus(QWidget *parent)
|
||||
opMode_Minimal_Color = QColor("#FFCCCC");
|
||||
|
||||
/* add the options */
|
||||
addItem(tr("Normal Mode"), RS_OPMODE_FULL);
|
||||
addItem(tr("Normal Mode"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::FULL));
|
||||
setItemData(0, opMode_Full_Color, Qt::BackgroundRole);
|
||||
addItem(tr("No Anon D/L"), RS_OPMODE_NOTURTLE);
|
||||
addItem(tr("No Anon D/L"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE));
|
||||
setItemData(1, opMode_NoTurtle_Color, Qt::BackgroundRole);
|
||||
addItem(tr("Gaming Mode"), RS_OPMODE_GAMING);
|
||||
addItem(tr("Gaming Mode"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::GAMING));
|
||||
setItemData(2, opMode_Gaming_Color, Qt::BackgroundRole);
|
||||
addItem(tr("Low Traffic"), RS_OPMODE_MINIMAL);
|
||||
addItem(tr("Low Traffic"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::MINIMAL));
|
||||
setItemData(3, opMode_Minimal_Color, Qt::BackgroundRole);
|
||||
|
||||
connect(this, SIGNAL(activated( int )), this, SLOT(setOpMode()));
|
||||
@ -59,23 +59,23 @@ OpModeStatus::OpModeStatus(QWidget *parent)
|
||||
|
||||
void OpModeStatus::getOpMode()
|
||||
{
|
||||
int opMode = rsConfig->getOperatingMode();
|
||||
RsOpMode opMode = rsConfig->getOperatingMode();
|
||||
switch(opMode)
|
||||
{
|
||||
default:
|
||||
case RS_OPMODE_FULL:
|
||||
case RsOpMode::FULL:
|
||||
setCurrentIndex(0);
|
||||
setProperty("opMode", "Full");
|
||||
break;
|
||||
case RS_OPMODE_NOTURTLE:
|
||||
case RsOpMode::NOTURTLE:
|
||||
setCurrentIndex(1);
|
||||
setProperty("opMode", "NoTurtle");
|
||||
break;
|
||||
case RS_OPMODE_GAMING:
|
||||
case RsOpMode::GAMING:
|
||||
setCurrentIndex(2);
|
||||
setProperty("opMode", "Gaming");
|
||||
break;
|
||||
case RS_OPMODE_MINIMAL:
|
||||
case RsOpMode::MINIMAL:
|
||||
setCurrentIndex(3);
|
||||
setProperty("opMode", "Minimal");
|
||||
break;
|
||||
@ -94,19 +94,19 @@ void OpModeStatus::setOpMode()
|
||||
|
||||
int idx = currentIndex();
|
||||
QVariant var = itemData(idx);
|
||||
uint32_t opMode = var.toUInt();
|
||||
RsOpMode opMode = static_cast<RsOpMode>(var.toUInt());
|
||||
|
||||
QString message = tr("<p>Warning: This Operating mode disables the tunneling service. This means you can use distant chat not anonymously download files and the mail service will be slower.</p><p>This state will be saved after restart, so do not forget that you changed it!</p>");
|
||||
|
||||
if(opMode == RS_OPMODE_NOTURTLE && ! Settings->getPageAlreadyDisplayed(QString("RS_OPMODE_NO_TURTLE")))
|
||||
if(opMode == RsOpMode::NOTURTLE && ! Settings->getPageAlreadyDisplayed(QString("RsOpMode::NO_TURTLE")))
|
||||
{
|
||||
QMessageBox::warning(NULL,tr("Turtle routing disabled!"),message);
|
||||
Settings->setPageAlreadyDisplayed(QString("RS_OPMODE_NO_TURTLE"),true) ;
|
||||
Settings->setPageAlreadyDisplayed(QString("RsOpMode::NO_TURTLE"),true) ;
|
||||
}
|
||||
if( (opMode == RS_OPMODE_MINIMAL && ! Settings->getPageAlreadyDisplayed(QString("RS_OPMODE_MINIMAL"))))
|
||||
if( (opMode == RsOpMode::MINIMAL && ! Settings->getPageAlreadyDisplayed(QString("RsOpMode::MINIMAL"))))
|
||||
{
|
||||
QMessageBox::warning(NULL,tr("Turtle routing disabled!"),message);
|
||||
Settings->setPageAlreadyDisplayed(QString("RS_OPMODE_MINIMAL"),true) ;
|
||||
Settings->setPageAlreadyDisplayed(QString("RsOpMode::MINIMAL"),true) ;
|
||||
}
|
||||
|
||||
rsConfig->setOperatingMode(opMode);
|
||||
|
Loading…
Reference in New Issue
Block a user