Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KRootProp (./kdelibs/kdecore/krootprop.h:45)
class KRootProp
{
private:
Atom atom;
QMap<QString,QString> propDict;
QString property_;
bool dirty;
KRootPropPrivate *d;
protected:
public:
/**
* Construct a @ref KRootProp object for the property @p rProp.
*
**/
KRootProp( const QString& rProp = QString::null );
/**
* Destructor.
*
* Writes back any dirty configuration entries.
**/
~KRootProp();
/**
* Specify the property in which keys will be searched.
*
**/
void setProp(const QString& rProp="");
/**
* Retrieve the name of the property under which keys are searched.
**/
QString prop() const;
/**
* Destroy the property completely.
*
* I.e. all entries will be cleared
* and the property will be removed from the root window.
**/
void destroy();
/**
* Read the value of an entry specified by @p rKey in the current property
*
* @param rKey The key to search for.
* @param pDefault A default value returned if the key was not found.
* @return The value for this key or the default if no value
* was found.
**/
QString readEntry( const QString& rKey,
const QString& pDefault = QString::null ) const ;
/**
* Read a numerical value.
*
* Read the value of an entry specified by @p rKey in the current property
* and interpret it numerically.
*
* @param rKey The key to search for.
* @param nDefault A default value returned if the key was not found.
* @return The value for this key or the default if no value was found.
*/
int readNumEntry( const QString& rKey, int nDefault = 0 ) const;
/**
* Read a @ref QFont.
*
* Read the value of an entry specified by @p rKey in the current property
* and interpret it as a font object.
*
* @param rKey The key to search for.
* @param pDefault A default value returned if the key was not found.
* @return The value for this key or a default font if no value was found.
*/
QFont readFontEntry( const QString& rKey,
const QFont* pDefault = 0 ) const;
/**
* Read a @ref QColor.
*
* Read the value of an entry specified by @p rKey in the current property
* and interpret it as a color.
*
* @param rKey The key to search for.
* @param pDefault A default value returned if the key was not found.
* @return The value for this key or a default color if no value
* was found.
*/
QColor readColorEntry( const QString& rKey,
const QColor* pDefault = 0 ) const;
/**
* @ref writeEntry() overridden to accept a const @ref QString& argument.
*
* This is stored to the current property when destroying the
* config object or when calling @ref sync().
*
* @param rKey The key to write.
* @param rValue The value to write.
* @return The old value for this key. If this key did not exist,
* a null string is returned.
*
**/
QString writeEntry( const QString& rKey, const QString& rValue );
/** Write the key value pair.
* Same as above, but write a numerical value.
* @param rKey The key to write.
* @param nValue The value to write.
* @return The old value for this key. If this key did not
* exist, a null string is returned.
**/
QString writeEntry( const QString& rKey, int nValue );
/** Write the key value pair.
* Same as above, but write a font.
* @param rKey The key to write.
* @param rValue The value to write.
* @return The old value for this key. If this key did not
* exist, a null string is returned.
**/
QString writeEntry( const QString& rKey, const QFont& rFont );
/** Write the key value pair.
* Same as above, but write a color.
* @param rKey The key to write.
* @param rValue The value to write.
* @return The old value for this key. If this key did not
* exist, a null string is returned.
**/
QString writeEntry( const QString& rKey, const QColor& rColor );
/**
* Remove an entry.
* @param rKey The key to remove.
* @return The old value for this key. If this key did not
* exist, a null string is returned.
**/
QString removeEntry(const QString& rKey);
/**
* Get a list of all keys.
* @return A @ref QStringList containing all the keys.
**/
QStringList listEntries() const;
/** Flush the entry cache.
* Write back dirty configuration entries to the current property,
* This is called automatically from the destructor.
**/
void sync();
};
kdelibs'KRootProp::KRootProp() (./kdelibs/kdecore/krootprop.cpp:29)
KRootProp::KRootProp(const QString& rProp )
{
atom = 0;
dirty = FALSE;
setProp( rProp );
}
kdelibs'KRootProp::~KRootProp() (./kdelibs/kdecore/krootprop.cpp:36)
KRootProp::~KRootProp()
{
sync();
propDict.clear();
}
kdelibs'KRootProp::sync() (./kdelibs/kdecore/krootprop.cpp:42)
void KRootProp::sync()
{
if ( !dirty )
return;
QString propString;
if ( !propDict.isEmpty() )
{
QMap<QString,QString>::Iterator it = propDict.begin();
QString keyvalue;
while ( it != propDict.end() )
{
keyvalue = QString( "%1=%2\n").arg(it.key()).arg(it.data());
propString += keyvalue;
++it;
}
}
XChangeProperty( qt_xdisplay(), qt_xrootwin(), atom,
XA_STRING, 8, PropModeReplace,
(const unsigned char *)propString.utf8().data(),
propString.length());
kapp->flushX();
}
kdelibs'KRootProp::setProp() (./kdelibs/kdecore/krootprop.cpp:68)
void KRootProp::setProp( const QString& rProp )
{
Atom type;
int format;
unsigned long nitems;
unsigned long bytes_after;
long offset;
char *buf;
// If a property has already been opened write
// the dictionary back to the root window
if( atom )
sync();
property_ = rProp;
if( rProp.isEmpty() )
return;
atom = XInternAtom( qt_xdisplay(), rProp.utf8(), False);
QString s;
offset = 0; bytes_after = 1;
while (bytes_after != 0)
{
XGetWindowProperty( qt_xdisplay(), qt_xrootwin(), atom, offset, 256,
False, XA_STRING, &type, &format, &nitems, &bytes_after,
(unsigned char **)&buf);
s += QString::fromUtf8(buf);
offset += nitems/4;
if (buf)
XFree(buf);
}
// Parse through the property string stripping out key value pairs
// and putting them in the dictionary
QString keypair;
int i=0;
QString key;
QString value;
while(s.length() >0 )
{
// parse the string for first key-value pair separator '\n'
i = s.find("\n");
if(i == -1)
i = s.length();
// extract the key-values pair and remove from string
keypair = s.left(i);
s.remove(0,i+1);
// split key and value and add to dictionary
keypair.simplifyWhiteSpace();
i = keypair.find( "=" );
if( i != -1 )
{
key = keypair.left( i );
value = keypair.mid( i+1 );
propDict.insert( key, value );
}
}
}
kdelibs'KRootProp::prop() (./kdelibs/kdecore/krootprop.cpp:138)
QString KRootProp::prop() const
{
return property_;
}
kdelibs'KRootProp::destroy() (./kdelibs/kdecore/krootprop.cpp:143)
void KRootProp::destroy()
{
dirty = FALSE;
propDict.clear();
if( atom ) {
XDeleteProperty( qt_xdisplay(), qt_xrootwin(), atom );
atom = 0;
}
}
kdelibs'KRootProp::readEntry() (./kdelibs/kdecore/krootprop.cpp:153)
QString KRootProp::readEntry( const QString& rKey,
const QString& pDefault ) const
{
if( propDict.contains( rKey ) )
return propDict[ rKey ];
else
return pDefault;
}
kdelibs'KRootProp::readNumEntry() (./kdelibs/kdecore/krootprop.cpp:162)
int KRootProp::readNumEntry( const QString& rKey, int nDefault ) const
{
QString aValue = readEntry( rKey );
if( !aValue.isNull() )
{
bool ok;
int rc = aValue.toInt( &ok );
if (ok)
return rc;
}
return nDefault;
}
kdelibs'KRootProp::readFontEntry() (./kdelibs/kdecore/krootprop.cpp:178)
QFont KRootProp::readFontEntry( const QString& rKey,
const QFont* pDefault ) const
{
QFont aRetFont;
QFont aDefFont;
if (pDefault)
aDefFont = *pDefault;
QString aValue = readEntry( rKey );
if( aValue.isNull() )
return aDefFont; // Return default font
// find first part (font family)
int nIndex = aValue.find( ',' );
if( nIndex == -1 )
return aDefFont; // Return default font
aRetFont.setFamily( aValue.left( nIndex ) );
// find second part (point size)
int nOldIndex = nIndex;
nIndex = aValue.find( ',', nOldIndex+1 );
if( nIndex == -1 )
return aDefFont; // Return default font
aRetFont.setPointSize( aValue.mid( nOldIndex+1,
nIndex-nOldIndex-1 ).toUInt() );
// find third part (style hint)
nOldIndex = nIndex;
nIndex = aValue.find( ',', nOldIndex+1 );
if( nIndex == -1 )
return aDefFont; // Return default font
aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1,
nIndex-nOldIndex-1 ).toUInt() );
// find fourth part (char set)
nOldIndex = nIndex;
nIndex = aValue.find( ',', nOldIndex+1 );
if( nIndex == -1 ){
if( pDefault )
aRetFont = *pDefault;
return aRetFont;
}
QString chStr=aValue.mid( nOldIndex+1,
nIndex-nOldIndex-1 );
bool chOldEntry;
QFont::CharSet chId=(QFont::CharSet)aValue.mid( nOldIndex+1,
nIndex-nOldIndex-1 ).toUInt(&chOldEntry);
if (chOldEntry)
aRetFont.setCharSet( chId );
else if (kapp) {
if (chStr == "default")
if (KGlobal::locale())
chStr = KGlobal::locale()->charset();
else chStr = "iso-8859-1";
KGlobal::charsets()->setQFont(aRetFont,chStr);
}
// find fifth part (weight)
nOldIndex = nIndex;
nIndex = aValue.find( ',', nOldIndex+1 );
if( nIndex == -1 )
return aDefFont; // Return default font
aRetFont.setWeight( aValue.mid( nOldIndex+1,
nIndex-nOldIndex-1 ).toUInt() );
// find sixth part (font bits)
uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
if( nFontBits & 0x01 )
aRetFont.setItalic( true );
if( nFontBits & 0x02 )
aRetFont.setUnderline( true );
if( nFontBits & 0x04 )
aRetFont.setStrikeOut( true );
if( nFontBits & 0x08 )
aRetFont.setFixedPitch( true );
if( nFontBits & 0x20 )
aRetFont.setRawMode( true );
return aRetFont;
}
kdelibs'KRootProp::readColorEntry() (./kdelibs/kdecore/krootprop.cpp:263)
QColor KRootProp::readColorEntry( const QString& rKey,
const QColor* pDefault ) const
{
QColor aRetColor;
int nRed = 0, nGreen = 0, nBlue = 0;
if( pDefault )
aRetColor = *pDefault;
QString aValue = readEntry( rKey );
if( aValue.isNull() )
return aRetColor;
// Support #ffffff style colour naming.
// Help ease transistion from legacy KDE setups
if( aValue.find("#") == 0 ) {
aRetColor.setNamedColor( aValue );
return aRetColor;
}
// Parse "red,green,blue"
// find first comma
int nIndex1 = aValue.find( ',' );
if( nIndex1 == -1 )
return aRetColor;
// find second comma
int nIndex2 = aValue.find( ',', nIndex1+1 );
if( nIndex2 == -1 )
return aRetColor;
bool bOK;
nRed = aValue.left( nIndex1 ).toInt( &bOK );
nGreen = aValue.mid( nIndex1+1,
nIndex2-nIndex1-1 ).toInt( &bOK );
nBlue = aValue.mid( nIndex2+1 ).toInt( &bOK );
aRetColor.setRgb( nRed, nGreen, nBlue );
return aRetColor;
}
kdelibs'KRootProp::writeEntry() (./kdelibs/kdecore/krootprop.cpp:304)
QString KRootProp::writeEntry( const QString& rKey, const QString& rValue )
{
dirty = TRUE;
if ( propDict.contains( rKey ) ) {
QString aValue = propDict[ rKey ];
propDict.replace( rKey, rValue );
return aValue;
}
else {
propDict.insert( rKey, rValue );
return QString::null;
}
}
kdelibs'KRootProp::writeEntry() (./kdelibs/kdecore/krootprop.cpp:318)
QString KRootProp::writeEntry( const QString& rKey, int nValue )
{
QString aValue;
aValue.setNum( nValue );
return writeEntry( rKey, aValue );
}
kdelibs'KRootProp::writeEntry() (./kdelibs/kdecore/krootprop.cpp:327)
QString KRootProp::writeEntry( const QString& rKey, const QFont& rFont )
{
QString aValue;
UINT8 nFontBits = 0;
// this mimics get_font_bits() from qfont.cpp
if( rFont.italic() )
nFontBits = nFontBits | 0x01;
if( rFont.underline() )
nFontBits = nFontBits | 0x02;
if( rFont.strikeOut() )
nFontBits = nFontBits | 0x04;
if( rFont.fixedPitch() )
nFontBits = nFontBits | 0x08;
if( rFont.rawMode() )
nFontBits = nFontBits | 0x20;
QString aCharset = "default";
if( rFont.charSet() != QFont::AnyCharSet )
aCharset.setNum( static_cast<int>(rFont.charSet()) );
QTextIStream ts( &aValue );
ts << rFont.family() << "," << rFont.pointSize() << ","
<< static_cast<int>(rFont.styleHint()) << "," << aCharset << "," << rFont.weight() << ","
<< static_cast<int>(nFontBits);
return writeEntry( rKey, aValue );
}
kdelibs'KRootProp::writeEntry() (./kdelibs/kdecore/krootprop.cpp:354)
QString KRootProp::writeEntry( const QString& rKey, const QColor& rColor )
{
QString aValue = QString( "%1,%2,%3").arg(rColor.red()).arg(rColor.green()).arg(rColor.blue() );
return writeEntry( rKey, aValue );
}
kdelibs'KRootProp::removeEntry() (./kdelibs/kdecore/krootprop.cpp:361)
QString KRootProp::removeEntry(const QString& rKey)
{
if (propDict.contains(rKey)) {
dirty = TRUE;
QString aValue = propDict[rKey];
propDict.remove(rKey);
return aValue;
} else
return QString::null;
}
kdelibs'KRootProp::listEntries() (./kdelibs/kdecore/krootprop.cpp:372)
QStringList KRootProp::listEntries() const
{
QMap<QString,QString>::ConstIterator it;
QStringList list;
for (it=propDict.begin(); it!=propDict.end(); it++)
list += it.key();
return list;
}