38 #include <QStringList>
45 static QString gpgconf_unescape(
const QString& str )
48 return KUrl::fromPercentEncoding( str.toUtf8() );
51 static QString gpgconf_escape(
const QString& str )
54 QString enc = QLatin1String(KUrl::toPercentEncoding( str ));
56 enc.replace( QLatin1Char(
','), QLatin1String(
"%2c") );
60 static QString urlpart_encode(
const QString& str )
63 enc.replace( QLatin1Char(
'%'), QLatin1String(
"%25") );
64 enc.replace( QLatin1Char(
':'), QLatin1String(
"%3a") );
69 static QString urlpart_decode(
const QString& str )
71 return KUrl::fromPercentEncoding( str.toLatin1() );
78 QStringList items = str.split( QLatin1Char(
':') );
79 if ( items.count() == 5 )
81 QStringList::const_iterator it = items.constBegin();
83 url.setProtocol( QLatin1String(
"ldap") );
84 url.setHost( urlpart_decode( *it++ ) );
85 url.setPort( (*it++).toInt() );
86 url.setPath( QLatin1String(
"/") );
87 url.setUserName( urlpart_decode( *it++ ) );
88 url.setPassword( urlpart_decode( *it++ ) );
89 url.setQuery( urlpart_decode( *it ) );
93 kWarning() <<
"parseURL: malformed LDAP server:" << str;
105 assert( url.protocol() == QLatin1String(
"ldap") );
106 return urlpart_encode( url.host() ) + QLatin1Char(
':') +
107 QString::number( url.port() ) + QLatin1Char(
':') +
108 urlpart_encode( url.userName() ) + QLatin1Char(
':') +
109 urlpart_encode( url.password() ) + QLatin1Char(
':') +
112 urlpart_encode( KUrl::fromPercentEncoding( url.query().mid(1).toLatin1() ) );
125 qDeleteAll( m_components );
130 return m_components.keys();
135 return m_components[
name];
141 if ( m_components.contains( component->
name() ) )
152 qDeleteAll( m_groups );
167 return m_description;
177 return m_groups.keys();
182 return m_groups[
name];
188 if ( m_groups.contains( group->
name() ) )
196 if ( m_entries.contains( name ) )
197 return m_entries[name];
215 return m_entries.isEmpty();
220 qDeleteAll( m_entries );
235 return m_description;
245 return m_entries.keys();
250 return m_entries[
name];
256 if ( m_entries.contains( entry->
name() ) )
282 if ( m_name == name )
290 return m_description;
295 if ( m_description == desc )
297 m_description = desc;
303 if ( m_mutability == mutability )
321 if ( useDefault == m_useDefault )
323 m_useDefault = useDefault;
330 m_isList = listType ==
List;
340 const bool list = isList();
345 return list ? i18nc(
"as in \"verbosity level\"",
"Level" ) : i18n(
"Set/Unset" );
347 return list ? i18n(
"String List" ) : i18n(
"String" );
349 return list ? i18n(
"List of Integers" ) : i18n(
"Integer" );
351 return list ? i18n(
"List of Unsigned Integers" ) : i18n(
"Unsigned Integer " );
353 return list ? i18n(
"Path List" ) : i18n(
"Path" );
355 return list ? i18n(
"List of URLs" ) : i18n(
"URL" );
357 return list ? i18n(
"List of LDAP URLs" ) : i18n(
"LDAP URL" );
359 return list ? i18n(
"Directory Path List" ) : i18n(
"Directory Path" );
364 bool ConfigEntry::isList()
const
371 assert( m_argType ==
None );
373 return m_value.toBool();
378 return toString( NoEscape );
383 assert( m_argType ==
Int );
385 return m_value.toInt();
390 assert( m_argType ==
UInt );
392 return m_value.toUInt();
397 assert( m_argType ==
Path || m_argType ==
Url || m_argType ==
LdapUrl );
399 QString str = m_value.toString();
400 if ( m_argType ==
Path )
406 return parseUrl( m_argType, str );
409 bool ConfigEntry::isStringType()
const
411 return ( m_argType ==
String
419 assert( isStringType() );
421 return m_value.toStringList();
426 assert( m_argType ==
Int );
431 ret.append( (*it).toInt() );
438 assert( m_argType ==
UInt );
443 ret.append( (*it).toUInt() );
450 assert( m_argType ==
Path || m_argType ==
Url || m_argType ==
LdapUrl );
452 const QStringList lst = m_value.toStringList();
455 Q_FOREACH(
const QString &i, lst )
457 if ( m_argType ==
Path ) {
462 ret << parseUrl( m_argType, i );
470 m_value = stringToValue( raw, Unescape );
475 m_value = stringToValue( raw, DoNotUnescape );
480 assert( m_argType ==
None );
490 m_value = stringToValue( str, DoNotUnescape );
499 assert( m_argType ==
Int );
513 QString str = splitUrl( m_argType, url );
520 assert( m_argType ==
None );
528 assert( m_argType ==
None );
530 return m_value.toUInt();
543 ret << QVariant( *it );
553 ret << QVariant( *it );
562 Q_FOREACH(
const KUrl& i, urls ) {
563 lst << splitUrl( m_argType, i );
571 return toString( Quote );
574 QVariant ConfigEntry::stringToValue(
const QString& str, UnescapeMode mode )
const
576 const bool isString = isStringType();
577 const bool unescape = mode & Unescape;
580 const QStringList items = str.split( QLatin1Char(
','), QString::SkipEmptyParts );
581 for( QStringList::const_iterator valit = items.constBegin(); valit != items.constEnd(); ++valit ) {
582 QString val = *valit;
584 if ( val.isEmpty() ) {
585 lst << QVariant( QString() );
588 else if ( unescape ) {
589 if( val.startsWith( QLatin1Char(
'"') ) )
592 kWarning() <<
"String value should start with '\"' :" << val;
595 lst << QVariant( unescape ? gpgconf_unescape( val ) : val );
602 return QVariant( QString() );
603 else if ( unescape ) {
604 if( val.startsWith( QLatin1Char(
'"') ) )
607 kWarning() <<
"String value should start with '\"' :" << val;
610 return QVariant( unescape ? gpgconf_unescape( val ) : val );
615 QString ConfigEntry::toString( ConfigEntry::EscapeMode mode )
const
617 const bool escape = mode & Escape;
618 const bool quote = mode & Quote;
621 if ( isStringType() ) {
622 if ( m_value.isNull() )
624 else if ( isList() ) {
625 QStringList lst = m_value.toStringList();
626 if ( escape || quote ) {
627 for( QStringList::iterator it = lst.begin(); it != lst.end(); ++it ) {
628 if ( !(*it).isNull() )
631 *it = gpgconf_escape( *it );
633 *it = (*it).prepend( QLatin1Char(
'\"') );
637 QString res = lst.join( QLatin1String(
",") );
641 QString res = m_value.toString();
643 res = gpgconf_escape( res );
645 res = res.prepend( QLatin1Char(
'\"') );
651 if ( m_argType ==
None ) {
652 return m_value.toBool() ? QString::fromLatin1(
"1" ) : QString();
654 assert( m_argType ==
Int || m_argType ==
UInt );
655 return m_value.toString();
660 if ( m_argType ==
None ) {
662 return numTimesSet > 0 ? QString::number( numTimesSet ) : QString();
668 ret << (*it).toString();
670 return ret.join( QLatin1String(
",") );
QString outputString() const
void setUIntValue(unsigned int)
QStringList groupList() const
ConfigComponent * component(const QString &name) const
QList< int > intValueList() const
void setStringValueList(const QStringList &)
QList< unsigned int > uintValueList() const
ConfigEntry * entry(const QString &name) const
ConfigEntry * entry(const QString &name) const
ConfigComponent(const QString &name)
void setValueFromUiString(const QString &str)
QString typeDescription() const
Human-readable (i.e.
unsigned int uintValue() const
void setUseBuiltInDefault(bool useDefault)
ConfigEntry(const QString &name)
void setDescription(const QString &description)
void setNumberOfTimesSet(unsigned int)
QStringList stringValueList() const
void setValueFromRawString(const QString &str)
QStringList componentList() const
void setDescription(const QString &description)
ConfigGroup * group(const QString &name) const
void addEntry(ConfigEntry *entry)
void setName(const QString &name)
QString stringValue() const
ConfigGroup(const QString &name)
QString description() const
void addComponent(ConfigComponent *component)
void setDescription(const QString &description)
Mutability mutability() const
void setName(const QString &name)
QString description() const
void setStringValue(const QString &)
void setIntValueList(const QList< int > &)
void setURLValue(const KUrl &)
void setMutability(Mutability mutability)
unsigned int numberOfTimesSet() const
void setName(const QString &name)
void setURLValueList(const KUrl::List &)
void setArgType(ArgType type, ListType listType)
void addGroup(ConfigGroup *group)
KUrl::List urlValueList() const
bool useBuiltInDefault() const
QStringList entryList() const
void setUIntValueList(const QList< unsigned int > &)
QString description() const