2020-04-03 22:28:15 +00:00
/*
* Squawk messenger .
* Copyright ( C ) 2019 Yury Gubich < blue @ macaw . me >
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "global.h"
# include "enums.h"
Shared : : Global * Shared : : Global : : instance = 0 ;
2020-04-13 19:57:23 +00:00
const std : : set < QString > Shared : : Global : : supportedImagesExts = { " png " , " jpg " , " webp " , " jpeg " , " gif " , " svg " } ;
2020-04-03 22:28:15 +00:00
Shared : : Global : : Global ( ) :
availability ( {
2020-04-10 22:15:08 +00:00
tr ( " Online " , " Availability " ) ,
tr ( " Away " , " Availability " ) ,
tr ( " Absent " , " Availability " ) ,
tr ( " Busy " , " Availability " ) ,
tr ( " Chatty " , " Availability " ) ,
tr ( " Invisible " , " Availability " ) ,
tr ( " Offline " , " Availability " )
2020-04-03 22:28:15 +00:00
} ) ,
connectionState ( {
2020-04-10 22:15:08 +00:00
tr ( " Disconnected " , " ConnectionState " ) ,
tr ( " Connecting " , " ConnectionState " ) ,
tr ( " Connected " , " ConnectionState " ) ,
tr ( " Error " , " ConnectionState " )
2020-04-03 22:28:15 +00:00
} ) ,
subscriptionState ( {
2020-04-10 22:15:08 +00:00
tr ( " None " , " SubscriptionState " ) ,
tr ( " From " , " SubscriptionState " ) ,
tr ( " To " , " SubscriptionState " ) ,
tr ( " Both " , " SubscriptionState " ) ,
tr ( " Unknown " , " SubscriptionState " )
2020-04-03 22:28:15 +00:00
} ) ,
affiliation ( {
2020-04-10 22:15:08 +00:00
tr ( " Unspecified " , " Affiliation " ) ,
tr ( " Outcast " , " Affiliation " ) ,
tr ( " Nobody " , " Affiliation " ) ,
tr ( " Member " , " Affiliation " ) ,
tr ( " Admin " , " Affiliation " ) ,
tr ( " Owner " , " Affiliation " )
2020-04-03 22:28:15 +00:00
} ) ,
role ( {
2020-04-10 22:15:08 +00:00
tr ( " Unspecified " , " Role " ) ,
tr ( " Nobody " , " Role " ) ,
tr ( " Visitor " , " Role " ) ,
tr ( " Participant " , " Role " ) ,
tr ( " Moderator " , " Role " )
2020-04-03 22:28:15 +00:00
} ) ,
messageState ( {
2020-04-10 22:15:08 +00:00
tr ( " Pending " , " MessageState " ) ,
tr ( " Sent " , " MessageState " ) ,
tr ( " Delivered " , " MessageState " ) ,
tr ( " Error " , " MessageState " )
2020-04-04 16:40:32 +00:00
} ) ,
accountPassword ( {
2020-04-10 22:15:08 +00:00
tr ( " Plain " , " AccountPassword " ) ,
tr ( " Jammed " , " AccountPassword " ) ,
tr ( " Always Ask " , " AccountPassword " ) ,
tr ( " KWallet " , " AccountPassword " )
} ) ,
accountPasswordDescription ( {
tr ( " Your password is going to be stored in config file in plain text " , " AccountPasswordDescription " ) ,
tr ( " Your password is going to be stored in config file but jammed with constant encryption key you can find in program source code. It might look like encryption but it's not " , " AccountPasswordDescription " ) ,
tr ( " Squawk is going to query you for the password on every start of the program " , " AccountPasswordDescription " ) ,
tr ( " Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions " , " AccountPasswordDescription " )
} ) ,
pluginSupport ( {
{ " KWallet " , false }
2020-04-03 22:28:15 +00:00
} )
{
if ( instance ! = 0 ) {
throw 551 ;
}
instance = this ;
}
Shared : : Global * Shared : : Global : : getInstance ( )
{
return instance ;
}
QString Shared : : Global : : getName ( Message : : State rl )
{
2020-04-04 16:40:32 +00:00
return instance - > messageState [ static_cast < int > ( rl ) ] ;
2020-04-03 22:28:15 +00:00
}
QString Shared : : Global : : getName ( Shared : : Affiliation af )
{
2020-04-04 16:40:32 +00:00
return instance - > affiliation [ static_cast < int > ( af ) ] ;
2020-04-03 22:28:15 +00:00
}
QString Shared : : Global : : getName ( Shared : : Availability av )
{
2020-04-04 16:40:32 +00:00
return instance - > availability [ static_cast < int > ( av ) ] ;
2020-04-03 22:28:15 +00:00
}
QString Shared : : Global : : getName ( Shared : : ConnectionState cs )
{
2020-04-04 16:40:32 +00:00
return instance - > connectionState [ static_cast < int > ( cs ) ] ;
2020-04-03 22:28:15 +00:00
}
QString Shared : : Global : : getName ( Shared : : Role rl )
{
2020-04-04 16:40:32 +00:00
return instance - > role [ static_cast < int > ( rl ) ] ;
2020-04-03 22:28:15 +00:00
}
QString Shared : : Global : : getName ( Shared : : SubscriptionState ss )
{
2020-04-04 16:40:32 +00:00
return instance - > subscriptionState [ static_cast < int > ( ss ) ] ;
2020-04-03 22:28:15 +00:00
}
2020-04-04 16:40:32 +00:00
QString Shared : : Global : : getName ( Shared : : AccountPassword ap )
2020-04-03 22:28:15 +00:00
{
2020-04-04 16:40:32 +00:00
return instance - > accountPassword [ static_cast < int > ( ap ) ] ;
2020-04-03 22:28:15 +00:00
}
2020-04-10 22:15:08 +00:00
void Shared : : Global : : setSupported ( const QString & pluginName , bool support )
{
std : : map < QString , bool > : : iterator itr = instance - > pluginSupport . find ( pluginName ) ;
if ( itr ! = instance - > pluginSupport . end ( ) ) {
itr - > second = support ;
}
}
bool Shared : : Global : : supported ( const QString & pluginName )
{
std : : map < QString , bool > : : iterator itr = instance - > pluginSupport . find ( pluginName ) ;
if ( itr ! = instance - > pluginSupport . end ( ) ) {
return itr - > second ;
}
return false ;
}
QString Shared : : Global : : getDescription ( Shared : : AccountPassword ap )
{
return instance - > accountPasswordDescription [ static_cast < int > ( ap ) ] ;
}
2020-04-04 16:40:32 +00:00
# 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 ) ) ; }
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 )