forked from blue/squawk
first moves to safe pasword storing, preparing the structure
This commit is contained in:
parent
ddfb3419cc
commit
3477226367
21 changed files with 288 additions and 153 deletions
|
@ -35,8 +35,8 @@ enum class ConnectionState {
|
|||
};
|
||||
Q_ENUM_NS(ConnectionState)
|
||||
static const std::deque<QString> connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"};
|
||||
static const ConnectionState connectionStateHighest = ConnectionState::error;
|
||||
static const ConnectionState connectionStateLowest = ConnectionState::disconnected;
|
||||
static const ConnectionState ConnectionStateHighest = ConnectionState::error;
|
||||
static const ConnectionState ConnectionStateLowest = ConnectionState::disconnected;
|
||||
|
||||
enum class Availability {
|
||||
online,
|
||||
|
@ -48,8 +48,8 @@ enum class Availability {
|
|||
offline
|
||||
};
|
||||
Q_ENUM_NS(Availability)
|
||||
static const Availability availabilityHighest = Availability::offline;
|
||||
static const Availability availabilityLowest = Availability::online;
|
||||
static const Availability AvailabilityHighest = Availability::offline;
|
||||
static const Availability AvailabilityLowest = Availability::online;
|
||||
static const std::deque<QString> availabilityThemeIcons = {
|
||||
"user-online",
|
||||
"user-away",
|
||||
|
@ -59,7 +59,6 @@ static const std::deque<QString> availabilityThemeIcons = {
|
|||
"user-invisible",
|
||||
"user-offline"
|
||||
};
|
||||
static const std::deque<QString> availabilityNames = {"Online", "Away", "Absent", "Busy", "Chatty", "Invisible", "Offline"};
|
||||
|
||||
enum class SubscriptionState {
|
||||
none,
|
||||
|
@ -69,10 +68,9 @@ enum class SubscriptionState {
|
|||
unknown
|
||||
};
|
||||
Q_ENUM_NS(SubscriptionState)
|
||||
static const SubscriptionState subscriptionStateHighest = SubscriptionState::unknown;
|
||||
static const SubscriptionState subscriptionStateLowest = SubscriptionState::none;
|
||||
static const SubscriptionState SubscriptionStateHighest = SubscriptionState::unknown;
|
||||
static const SubscriptionState SubscriptionStateLowest = SubscriptionState::none;
|
||||
static const std::deque<QString> subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"};
|
||||
static const std::deque<QString> subscriptionStateNames = {"None", "From", "To", "Both", "Unknown"};
|
||||
|
||||
enum class Affiliation {
|
||||
unspecified,
|
||||
|
@ -83,9 +81,8 @@ enum class Affiliation {
|
|||
owner
|
||||
};
|
||||
Q_ENUM_NS(Affiliation)
|
||||
static const Affiliation affiliationHighest = Affiliation::owner;
|
||||
static const Affiliation affiliationLowest = Affiliation::unspecified;
|
||||
static const std::deque<QString> affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"};
|
||||
static const Affiliation AffiliationHighest = Affiliation::owner;
|
||||
static const Affiliation AffiliationLowest = Affiliation::unspecified;
|
||||
|
||||
enum class Role {
|
||||
unspecified,
|
||||
|
@ -95,9 +92,8 @@ enum class Role {
|
|||
moderator
|
||||
};
|
||||
Q_ENUM_NS(Role)
|
||||
static const Role roleHighest = Role::moderator;
|
||||
static const Role roleLowest = Role::unspecified;
|
||||
static const std::deque<QString> roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"};
|
||||
static const Role RoleHighest = Role::moderator;
|
||||
static const Role RoleLowest = Role::unspecified;
|
||||
|
||||
enum class Avatar {
|
||||
empty,
|
||||
|
@ -105,10 +101,21 @@ enum class Avatar {
|
|||
valid
|
||||
};
|
||||
Q_ENUM_NS(Avatar)
|
||||
static const Avatar AvatarHighest = Avatar::valid;
|
||||
static const Avatar AvatarLowest = Avatar::empty;
|
||||
|
||||
|
||||
static const std::deque<QString> messageStateNames = {"Pending", "Sent", "Delivered", "Error"};
|
||||
static const std::deque<QString> messageStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"};
|
||||
|
||||
enum class AccountPassword {
|
||||
plain,
|
||||
jammed,
|
||||
kwallet,
|
||||
alwaysAsk
|
||||
};
|
||||
Q_ENUM_NS(AccountPassword)
|
||||
static const AccountPassword AccountPasswordHighest = AccountPassword::alwaysAsk;
|
||||
static const AccountPassword AccountPasswordLowest = AccountPassword::plain;
|
||||
|
||||
}
|
||||
#endif // SHARED_ENUMS_H
|
||||
|
|
|
@ -65,6 +65,12 @@ Shared::Global::Global():
|
|||
tr("Sent"),
|
||||
tr("Delivered"),
|
||||
tr("Error")
|
||||
}),
|
||||
accountPassword({
|
||||
tr("Plain"),
|
||||
tr("Jammed"),
|
||||
tr("KWallet"),
|
||||
tr("Always Ask")
|
||||
})
|
||||
{
|
||||
if (instance != 0) {
|
||||
|
@ -81,90 +87,56 @@ Shared::Global * Shared::Global::getInstance()
|
|||
|
||||
QString Shared::Global::getName(Message::State rl)
|
||||
{
|
||||
return instance->messageState[int(rl)];
|
||||
return instance->messageState[static_cast<int>(rl)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::Affiliation af)
|
||||
{
|
||||
return instance->affiliation[int(af)];
|
||||
return instance->affiliation[static_cast<int>(af)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::Availability av)
|
||||
{
|
||||
return instance->availability[int(av)];
|
||||
return instance->availability[static_cast<int>(av)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::ConnectionState cs)
|
||||
{
|
||||
return instance->connectionState[int(cs)];
|
||||
return instance->connectionState[static_cast<int>(cs)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::Role rl)
|
||||
{
|
||||
return instance->role[int(rl)];
|
||||
return instance->role[static_cast<int>(rl)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::SubscriptionState ss)
|
||||
{
|
||||
return instance->subscriptionState[int(ss)];
|
||||
return instance->subscriptionState[static_cast<int>(ss)];
|
||||
}
|
||||
|
||||
template<>
|
||||
Shared::Availability Shared::Global::fromInt(int src)
|
||||
QString Shared::Global::getName(Shared::AccountPassword ap)
|
||||
{
|
||||
if (src < static_cast<int>(Shared::availabilityLowest) && src > static_cast<int>(Shared::availabilityHighest)) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
}
|
||||
|
||||
return static_cast<Shared::Availability>(src);
|
||||
return instance->accountPassword[static_cast<int>(ap)];
|
||||
}
|
||||
|
||||
template<>
|
||||
Shared::Availability Shared::Global::fromInt(unsigned int src)
|
||||
{
|
||||
if (src < static_cast<int>(Shared::availabilityLowest) && src > static_cast<int>(Shared::availabilityHighest)) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
}
|
||||
|
||||
return static_cast<Shared::Availability>(src);
|
||||
}
|
||||
#define FROM_INT_INPL(Enum) \
|
||||
template<> \
|
||||
Enum Shared::Global::fromInt(int src) \
|
||||
{ \
|
||||
if (src < static_cast<int>(Enum##Lowest) && src > static_cast<int>(Enum##Highest)) { \
|
||||
throw EnumOutOfRange(#Enum); \
|
||||
} \
|
||||
return static_cast<Enum>(src); \
|
||||
} \
|
||||
template<> \
|
||||
Enum Shared::Global::fromInt(unsigned int src) {return fromInt<Enum>(static_cast<int>(src));}
|
||||
|
||||
template<>
|
||||
Shared::ConnectionState Shared::Global::fromInt(int src)
|
||||
{
|
||||
if (src < static_cast<int>(Shared::connectionStateLowest) && src > static_cast<int>(Shared::connectionStateHighest)) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
}
|
||||
|
||||
return static_cast<Shared::ConnectionState>(src);
|
||||
}
|
||||
|
||||
template<>
|
||||
Shared::ConnectionState Shared::Global::fromInt(unsigned int src)
|
||||
{
|
||||
if (src < static_cast<int>(Shared::connectionStateLowest) && src > static_cast<int>(Shared::connectionStateHighest)) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
}
|
||||
|
||||
return static_cast<Shared::ConnectionState>(src);
|
||||
}
|
||||
|
||||
template<>
|
||||
Shared::SubscriptionState Shared::Global::fromInt(int src)
|
||||
{
|
||||
if (src < static_cast<int>(Shared::subscriptionStateLowest) && src > static_cast<int>(Shared::subscriptionStateHighest)) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
}
|
||||
|
||||
return static_cast<Shared::SubscriptionState>(src);
|
||||
}
|
||||
|
||||
template<>
|
||||
Shared::SubscriptionState Shared::Global::fromInt(unsigned int src)
|
||||
{
|
||||
if (src < static_cast<int>(Shared::subscriptionStateLowest) && src > static_cast<int>(Shared::subscriptionStateHighest)) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
}
|
||||
|
||||
return static_cast<Shared::SubscriptionState>(src);
|
||||
}
|
||||
FROM_INT_INPL(Shared::Message::State)
|
||||
FROM_INT_INPL(Shared::Affiliation)
|
||||
FROM_INT_INPL(Shared::ConnectionState)
|
||||
FROM_INT_INPL(Shared::Role)
|
||||
FROM_INT_INPL(Shared::SubscriptionState)
|
||||
FROM_INT_INPL(Shared::AccountPassword)
|
||||
FROM_INT_INPL(Shared::Avatar)
|
||||
FROM_INT_INPL(Shared::Availability)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "enums.h"
|
||||
#include "message.h"
|
||||
#include "exception.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
@ -42,6 +43,7 @@ namespace Shared {
|
|||
static QString getName(Affiliation af);
|
||||
static QString getName(Role rl);
|
||||
static QString getName(Message::State rl);
|
||||
static QString getName(AccountPassword ap);
|
||||
|
||||
const std::deque<QString> availability;
|
||||
const std::deque<QString> connectionState;
|
||||
|
@ -49,6 +51,7 @@ namespace Shared {
|
|||
const std::deque<QString> affiliation;
|
||||
const std::deque<QString> role;
|
||||
const std::deque<QString> messageState;
|
||||
const std::deque<QString> accountPassword;
|
||||
|
||||
template<typename T>
|
||||
static T fromInt(int src);
|
||||
|
@ -56,6 +59,19 @@ namespace Shared {
|
|||
template<typename T>
|
||||
static T fromInt(unsigned int src);
|
||||
|
||||
class EnumOutOfRange:
|
||||
public Utils::Exception
|
||||
{
|
||||
public:
|
||||
EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {}
|
||||
|
||||
std::string getMessage() const{
|
||||
return "An attempt to get enum " + name + " from integer out of range of that enum";
|
||||
}
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
private:
|
||||
static Global* instance;
|
||||
};
|
||||
|
|
|
@ -46,6 +46,8 @@ public:
|
|||
delivered,
|
||||
error
|
||||
};
|
||||
static const State StateHighest = State::error;
|
||||
static const State StateLowest = State::pending;
|
||||
|
||||
Message(Type p_type);
|
||||
Message();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue