convert RSCONFIG_USER_LEVEL to enum class

This commit is contained in:
sehraf 2020-02-09 22:11:25 +01:00
parent 3f5dcecc4d
commit c285bb0ab8
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
4 changed files with 30 additions and 36 deletions

View File

@ -101,24 +101,18 @@ enum class RsNetState : uint8_t
ADV_DARK_FORWARD= 10 ADV_DARK_FORWARD= 10
}; };
/* matched to the uPnP states */
#define UPNP_STATE_UNINITIALISED 0
#define UPNP_STATE_UNAVAILABILE 1
#define UPNP_STATE_READY 2
#define UPNP_STATE_FAILED_TCP 3
#define UPNP_STATE_FAILED_UDP 4
#define UPNP_STATE_ACTIVE 5
/************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/ /************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/
#define RSCONFIG_USER_LEVEL_NEW 0x0001 /* no friends */ enum class RsConfigUserLvl : uint8_t
#define RSCONFIG_USER_LEVEL_BASIC 0x0002 /* no connections */ {
#define RSCONFIG_USER_LEVEL_CASUAL 0x0003 /* firewalled */ NEW = 1, /* no friends */
#define RSCONFIG_USER_LEVEL_POWER 0x0004 /* good! */ BASIC = 2, /* no connections */
#define RSCONFIG_USER_LEVEL_OVERRIDE 0x0005 /* forced to POWER level */ CASUAL = 3, /* firewalled */
POWER = 4, /* good! */
OVERRIDE= 5 /* forced to POWER level */
};
@ -359,7 +353,7 @@ public:
/* New Stuff */ /* New Stuff */
virtual uint32_t getUserLevel() = 0; virtual RsConfigUserLvl getUserLevel() = 0;
virtual RsNetState getNetState() = 0; virtual RsNetState getNetState() = 0;
virtual RsNetworkMode getNetworkMode() = 0; virtual RsNetworkMode getNetworkMode() = 0;

View File

@ -48,7 +48,7 @@ p3ServerConfig::p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
mUserLevel = RSCONFIG_USER_LEVEL_NEW; /* START LEVEL */ mUserLevel = RsConfigUserLvl::NEW; /* START LEVEL */
mRateDownload = DEFAULT_DOWNLOAD_KB_RATE; mRateDownload = DEFAULT_DOWNLOAD_KB_RATE;
mRateUpload = DEFAULT_UPLOAD_KB_RATE; mRateUpload = DEFAULT_UPLOAD_KB_RATE;
@ -264,9 +264,9 @@ std::string p3ServerConfig::getRetroshareDataDirectory()
/* New Stuff */ /* New Stuff */
uint32_t p3ServerConfig::getUserLevel() RsConfigUserLvl p3ServerConfig::getUserLevel()
{ {
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW; RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
{ {
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
userLevel = mUserLevel; userLevel = mUserLevel;
@ -274,33 +274,33 @@ uint32_t p3ServerConfig::getUserLevel()
switch(userLevel) switch(userLevel)
{ {
case RSCONFIG_USER_LEVEL_OVERRIDE: case RsConfigUserLvl::OVERRIDE:
break; break;
#define MIN_BASIC_FRIENDS 2 #define MIN_BASIC_FRIENDS 2
// FALL THROUGH EVERYTHING. // FALL THROUGH EVERYTHING.
default: default:
case RSCONFIG_USER_LEVEL_NEW: case RsConfigUserLvl::NEW:
{ {
if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS) if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS)
{ {
userLevel = RSCONFIG_USER_LEVEL_BASIC; userLevel = RsConfigUserLvl::BASIC;
} }
} }
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC: case RsConfigUserLvl::BASIC:
{ {
/* check that we have some lastConnect > 0 */ /* check that we have some lastConnect > 0 */
if (mPeerMgr->haveOnceConnected()) if (mPeerMgr->haveOnceConnected())
{ {
userLevel = RSCONFIG_USER_LEVEL_CASUAL; userLevel = RsConfigUserLvl::CASUAL;
} }
} }
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL: case RsConfigUserLvl::CASUAL:
case RSCONFIG_USER_LEVEL_POWER: case RsConfigUserLvl::POWER:
{ {
/* check that the firewall is open */ /* check that the firewall is open */
@ -314,7 +314,7 @@ uint32_t p3ServerConfig::getUserLevel()
(RsNatHoleMode::NATPMP == firewallMode) || (RsNatHoleMode::NATPMP == firewallMode) ||
(RsNatHoleMode::FORWARDED == firewallMode)))) (RsNatHoleMode::FORWARDED == firewallMode))))
{ {
userLevel = RSCONFIG_USER_LEVEL_POWER; userLevel = RsConfigUserLvl::POWER;
} }
} }
break; /* for all */ break; /* for all */

View File

@ -72,7 +72,7 @@ virtual std::string getRetroshareDataDirectory();
/* New Stuff */ /* New Stuff */
virtual uint32_t getUserLevel(); virtual RsConfigUserLvl getUserLevel();
virtual RsNetState getNetState(); virtual RsNetState getNetState();
virtual RsNetworkMode getNetworkMode(); virtual RsNetworkMode getNetworkMode();
@ -108,7 +108,7 @@ bool findConfigurationOption(uint32_t key, std::string &keystr);
p3GeneralConfig *mGeneralConfig; p3GeneralConfig *mGeneralConfig;
RsMutex configMtx; RsMutex configMtx;
uint32_t mUserLevel; // store last one... will later be a config Item too. RsConfigUserLvl mUserLevel; // store last one... will later be a config Item too.
float mRateDownload; float mRateDownload;
float mRateUpload; float mRateUpload;

View File

@ -105,7 +105,7 @@ void GetStartedDialog::showEvent ( QShowEvent * /*event*/ )
void GetStartedDialog::updateFromUserLevel() void GetStartedDialog::updateFromUserLevel()
{ {
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW; RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
userLevel = rsConfig->getUserLevel(); userLevel = rsConfig->getUserLevel();
ui.inviteCheckBox->setChecked(false); ui.inviteCheckBox->setChecked(false);
@ -116,19 +116,19 @@ void GetStartedDialog::updateFromUserLevel()
switch(userLevel) switch(userLevel)
{ {
// FALLS THROUGH EVERYWHERE. // FALLS THROUGH EVERYWHERE.
case RSCONFIG_USER_LEVEL_POWER: case RsConfigUserLvl::POWER:
case RSCONFIG_USER_LEVEL_OVERRIDE: case RsConfigUserLvl::OVERRIDE:
ui.firewallCheckBox->setChecked(true); ui.firewallCheckBox->setChecked(true);
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL: case RsConfigUserLvl::CASUAL:
ui.connectCheckBox->setChecked(true); ui.connectCheckBox->setChecked(true);
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC: case RsConfigUserLvl::BASIC:
ui.addCheckBox->setChecked(true); ui.addCheckBox->setChecked(true);
ui.inviteCheckBox->setChecked(true); ui.inviteCheckBox->setChecked(true);
default: default:
case RSCONFIG_USER_LEVEL_NEW: case RsConfigUserLvl::NEW:
break; break;
} }
@ -325,7 +325,7 @@ void GetStartedDialog::emailSupport()
return; return;
} }
uint32_t userLevel; RsConfigUserLvl userLevel;
{ {
RsAutoUpdatePage::lockAllEvents(); RsAutoUpdatePage::lockAllEvents();
@ -427,7 +427,7 @@ void GetStartedDialog::emailSupport()
sysVersion = "Linux"; sysVersion = "Linux";
#endif #endif
#endif #endif
text += QString("My RetroShare Configuration is: (%1, %2, 0x60%3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(userLevel) + "\n"; text += QString("My RetroShare Configuration is: (%1, %2, %3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(static_cast<typename std::underlying_type<RsConfigUserLvl>::type>(userLevel)) + "\n";
text += "\n"; text += "\n";
text += QString("I am having trouble with RetroShare."); text += QString("I am having trouble with RetroShare.");