From c285bb0ab8879c6c933062b05f30f197cd0ff3f7 Mon Sep 17 00:00:00 2001 From: sehraf Date: Sun, 9 Feb 2020 22:11:25 +0100 Subject: [PATCH] convert RSCONFIG_USER_LEVEL to enum class --- libretroshare/src/retroshare/rsconfig.h | 24 ++++++++------------ libretroshare/src/rsserver/p3serverconfig.cc | 22 +++++++++--------- libretroshare/src/rsserver/p3serverconfig.h | 4 ++-- retroshare-gui/src/gui/GetStartedDialog.cpp | 16 ++++++------- 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/libretroshare/src/retroshare/rsconfig.h b/libretroshare/src/retroshare/rsconfig.h index 65c61b4fd..9650b056f 100644 --- a/libretroshare/src/retroshare/rsconfig.h +++ b/libretroshare/src/retroshare/rsconfig.h @@ -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; diff --git a/libretroshare/src/rsserver/p3serverconfig.cc b/libretroshare/src/rsserver/p3serverconfig.cc index d562034c7..d7c14ae76 100644 --- a/libretroshare/src/rsserver/p3serverconfig.cc +++ b/libretroshare/src/rsserver/p3serverconfig.cc @@ -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 */ diff --git a/libretroshare/src/rsserver/p3serverconfig.h b/libretroshare/src/rsserver/p3serverconfig.h index fbd9c1fc9..199a09e05 100644 --- a/libretroshare/src/rsserver/p3serverconfig.h +++ b/libretroshare/src/rsserver/p3serverconfig.h @@ -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; diff --git a/retroshare-gui/src/gui/GetStartedDialog.cpp b/retroshare-gui/src/gui/GetStartedDialog.cpp index 3c4c14cf5..7357ffb2f 100644 --- a/retroshare-gui/src/gui/GetStartedDialog.cpp +++ b/retroshare-gui/src/gui/GetStartedDialog.cpp @@ -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::type>(userLevel)) + "\n"; text += "\n"; text += QString("I am having trouble with RetroShare.");