37 #include "qgpgmeprogresstokenmapper.h"
39 #include <tdelocale.h>
53 static const struct Desc pk_dsa[] = {
54 { 0, I18N_NOOP( "Generating DSA key..."), false, false }
57 static const struct Desc pk_elg[] = {
58 { 0, I18N_NOOP( "Generating ElGamal key..."), false, false }
61 static const struct Desc primegen[] = {
63 { 0, I18N_NOOP( "Searching for a large prime number..."), false, false }
66 static const struct Desc need_entropy[] = {
67 { 0, I18N_NOOP( "Waiting for new entropy from random number generator (you might want to exercise the harddisks or move the mouse)..."), false, false }
70 static const struct Desc tick[] = {
71 { 0, I18N_NOOP( "Please wait..."), false, false }
74 static const struct Desc starting_agent[] = {
75 { 0, I18N_NOOP( "Starting gpg-agent (you should consider starting a global instance instead)..."), false, false }
83 #define make_token(x) { #x, x, sizeof(x) / sizeof(*x) }
87 make_token(need_entropy),
89 make_token(starting_agent)
95 Kleo::QGpgMEProgressTokenMapper * Kleo::QGpgMEProgressTokenMapper::mSelf = 0;
97 const Kleo::QGpgMEProgressTokenMapper * Kleo::QGpgMEProgressTokenMapper::instance() {
99 (void) new QGpgMEProgressTokenMapper();
103 Kleo::QGpgMEProgressTokenMapper::QGpgMEProgressTokenMapper() {
107 Kleo::QGpgMEProgressTokenMapper::~QGpgMEProgressTokenMapper() {
111 typedef std::map< TQString, std::map<int,Desc> > Map;
113 static const Map & makeMap() {
115 for ( unsigned int i = 0 ; i < sizeof tokens / sizeof *tokens ; ++i ) {
116 assert( tokens[i].token );
117 const TQString token = TQString::fromLatin1( tokens[i].token ).lower();
118 for ( unsigned int j = 0 ; j < tokens[i].numDesc ; ++j ) {
119 const Desc & desc = tokens[i].desc[j];
120 assert( desc.display );
121 map[ token ][ desc.type ] = desc;
127 TQString Kleo::QGpgMEProgressTokenMapper::map( const char * tokenUtf8, int subtoken, int cur, int tot ) const {
128 if ( !tokenUtf8 || !*tokenUtf8 )
131 if ( qstrcmp( tokenUtf8, "file:" ) == 0 )
134 return map( TQString::fromUtf8( tokenUtf8 ), subtoken, cur, tot );
137 TQString Kleo::QGpgMEProgressTokenMapper::map( const TQString & token, int subtoken, int cur, int tot ) const {
138 if ( token.startsWith( "file:" ) )
141 static const Map & tokenMap = makeMap();
143 const Map::const_iterator it1 = tokenMap.find( token.lower() );
144 if ( it1 == tokenMap.end() )
146 std::map<int,Desc>::const_iterator it2 = it1->second.find( subtoken );
147 if ( it2 == it1->second.end() )
148 it2 = it1->second.find( 0 );
149 if ( it2 == it1->second.end() )
151 const Desc & desc = it2->second;
152 TQString result = i18n( desc.display );
154 result = result.arg( cur );
156 result = result.arg( tot );
|