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
};
/* 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 ******/
#define RSCONFIG_USER_LEVEL_NEW 0x0001 /* no friends */
#define RSCONFIG_USER_LEVEL_BASIC 0x0002 /* no connections */
#define RSCONFIG_USER_LEVEL_CASUAL 0x0003 /* firewalled */
#define RSCONFIG_USER_LEVEL_POWER 0x0004 /* good! */
#define RSCONFIG_USER_LEVEL_OVERRIDE 0x0005 /* forced to POWER level */
enum class RsConfigUserLvl : uint8_t
{
NEW = 1, /* no friends */
BASIC = 2, /* no connections */
CASUAL = 3, /* firewalled */
POWER = 4, /* good! */
OVERRIDE= 5 /* forced to POWER level */
};
@ -359,7 +353,7 @@ public:
/* New Stuff */
virtual uint32_t getUserLevel() = 0;
virtual RsConfigUserLvl getUserLevel() = 0;
virtual RsNetState getNetState() = 0;
virtual RsNetworkMode getNetworkMode() = 0;

View File

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

View File

@ -72,7 +72,7 @@ virtual std::string getRetroshareDataDirectory();
/* New Stuff */
virtual uint32_t getUserLevel();
virtual RsConfigUserLvl getUserLevel();
virtual RsNetState getNetState();
virtual RsNetworkMode getNetworkMode();
@ -108,7 +108,7 @@ bool findConfigurationOption(uint32_t key, std::string &keystr);
p3GeneralConfig *mGeneralConfig;
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 mRateUpload;

View File

@ -105,7 +105,7 @@ void GetStartedDialog::showEvent ( QShowEvent * /*event*/ )
void GetStartedDialog::updateFromUserLevel()
{
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW;
RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
userLevel = rsConfig->getUserLevel();
ui.inviteCheckBox->setChecked(false);
@ -116,19 +116,19 @@ void GetStartedDialog::updateFromUserLevel()
switch(userLevel)
{
// FALLS THROUGH EVERYWHERE.
case RSCONFIG_USER_LEVEL_POWER:
case RSCONFIG_USER_LEVEL_OVERRIDE:
case RsConfigUserLvl::POWER:
case RsConfigUserLvl::OVERRIDE:
ui.firewallCheckBox->setChecked(true);
/* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL:
case RsConfigUserLvl::CASUAL:
ui.connectCheckBox->setChecked(true);
/* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC:
case RsConfigUserLvl::BASIC:
ui.addCheckBox->setChecked(true);
ui.inviteCheckBox->setChecked(true);
default:
case RSCONFIG_USER_LEVEL_NEW:
case RsConfigUserLvl::NEW:
break;
}
@ -325,7 +325,7 @@ void GetStartedDialog::emailSupport()
return;
}
uint32_t userLevel;
RsConfigUserLvl userLevel;
{
RsAutoUpdatePage::lockAllEvents();
@ -427,7 +427,7 @@ void GetStartedDialog::emailSupport()
sysVersion = "Linux";
#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 += QString("I am having trouble with RetroShare.");