• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
krootprop.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Mark Donohoe (donohoe@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tqwidget.h>
21
22#include "config.h"
23#ifdef TQ_WS_X11 // not needed anyway :-)
24
25#include "krootprop.h"
26#include "tdeglobal.h"
27#include "tdelocale.h"
28#include "kcharsets.h"
29#include "tdeapplication.h"
30#include <tqtextstream.h>
31
32#include <X11/Xlib.h>
33#include <X11/Xatom.h>
34
35KRootProp::KRootProp(const TQString& rProp )
36{
37 atom = 0;
38 dirty = false;
39 setProp( rProp );
40}
41
42KRootProp::~KRootProp()
43{
44 sync();
45 propDict.clear();
46}
47
48void KRootProp::sync()
49{
50 if ( !dirty )
51 return;
52
53 TQString propString;
54 if ( !propDict.isEmpty() )
55 {
56 TQMap<TQString,TQString>::Iterator it = propDict.begin();
57 TQString keyvalue;
58
59 while ( it != propDict.end() )
60 {
61 keyvalue = TQString( "%1=%2\n").arg(it.key()).arg(it.data());
62 propString += keyvalue;
63 ++it;
64 }
65 }
66
67 XChangeProperty( tqt_xdisplay(), tqt_xrootwin(), atom,
68 XA_STRING, 8, PropModeReplace,
69 (const unsigned char *)propString.utf8().data(),
70 propString.length());
71 XFlush( tqt_xdisplay() );
72}
73
74void KRootProp::setProp( const TQString& rProp )
75{
76 Atom type;
77 int format;
78 unsigned long nitems;
79 unsigned long bytes_after;
80 long offset;
81
82 // If a property has already been opened write
83 // the dictionary back to the root window
84
85 if( atom )
86 sync();
87
88 property_ = rProp;
89 if( rProp.isEmpty() )
90 return;
91
92 atom = XInternAtom( tqt_xdisplay(), rProp.utf8(), False);
93
94 TQString s;
95 offset = 0; bytes_after = 1;
96 while (bytes_after != 0)
97 {
98 unsigned char *buf = 0;
99 if (XGetWindowProperty( tqt_xdisplay(), tqt_xrootwin(), atom, offset, 256,
100 False, XA_STRING, &type, &format, &nitems, &bytes_after,
101 &buf) == Success && buf)
102 {
103 s += TQString::fromUtf8((const char*)buf);
104 offset += nitems/4;
105 XFree(buf);
106 }
107 }
108
109 // Parse through the property string stripping out key value pairs
110 // and putting them in the dictionary
111
112 TQString keypair;
113 int i=0;
114 TQString key;
115 TQString value;
116
117 while(s.length() >0 )
118 {
119 // parse the string for first key-value pair separator '\n'
120
121 i = s.find("\n");
122 if(i == -1)
123 i = s.length();
124
125 // extract the key-values pair and remove from string
126
127 keypair = s.left(i);
128 s.remove(0,i+1);
129
130 // split key and value and add to dictionary
131
132 keypair.simplifyWhiteSpace();
133
134 i = keypair.find( "=" );
135 if( i != -1 )
136 {
137 key = keypair.left( i );
138 value = keypair.mid( i+1 );
139 propDict.insert( key, value );
140 }
141 }
142}
143
144
145TQString KRootProp::prop() const
146{
147 return property_;
148}
149
150void KRootProp::destroy()
151{
152 dirty = false;
153 propDict.clear();
154 if( atom ) {
155 XDeleteProperty( tqt_xdisplay(), tqt_xrootwin(), atom );
156 atom = 0;
157 }
158}
159
160TQString KRootProp::readEntry( const TQString& rKey,
161 const TQString& pDefault ) const
162{
163 if( propDict.contains( rKey ) )
164 return propDict[ rKey ];
165 else
166 return pDefault;
167}
168
169int KRootProp::readNumEntry( const TQString& rKey, int nDefault ) const
170{
171
172 TQString aValue = readEntry( rKey );
173 if( !aValue.isNull() )
174 {
175 bool ok;
176
177 int rc = aValue.toInt( &ok );
178 if (ok)
179 return rc;
180 }
181 return nDefault;
182}
183
184
185TQFont KRootProp::readFontEntry( const TQString& rKey,
186 const TQFont* pDefault ) const
187{
188 TQFont aRetFont;
189 TQFont aDefFont;
190
191 if (pDefault)
192 aDefFont = *pDefault;
193
194 TQString aValue = readEntry( rKey );
195 if( aValue.isNull() )
196 return aDefFont; // Return default font
197
198 if ( !aRetFont.fromString( aValue ) && pDefault )
199 aRetFont = aDefFont;
200
201 return aRetFont;
202}
203
204
205TQColor KRootProp::readColorEntry( const TQString& rKey,
206 const TQColor* pDefault ) const
207{
208 TQColor aRetColor;
209 int nRed = 0, nGreen = 0, nBlue = 0;
210
211 if( pDefault )
212 aRetColor = *pDefault;
213
214 TQString aValue = readEntry( rKey );
215 if( aValue.isNull() )
216 return aRetColor;
217
218 // Support #ffffff style color naming.
219 // Help ease transistion from legacy KDE setups
220 if( aValue.find("#") == 0 ) {
221 aRetColor.setNamedColor( aValue );
222 return aRetColor;
223 }
224
225 // Parse "red,green,blue"
226 // find first comma
227 int nIndex1 = aValue.find( ',' );
228 if( nIndex1 == -1 )
229 return aRetColor;
230 // find second comma
231 int nIndex2 = aValue.find( ',', nIndex1+1 );
232 if( nIndex2 == -1 )
233 return aRetColor;
234
235 bool bOK;
236 nRed = aValue.left( nIndex1 ).toInt( &bOK );
237 nGreen = aValue.mid( nIndex1+1,
238 nIndex2-nIndex1-1 ).toInt( &bOK );
239 nBlue = aValue.mid( nIndex2+1 ).toInt( &bOK );
240
241 aRetColor.setRgb( nRed, nGreen, nBlue );
242
243 return aRetColor;
244}
245
246TQString KRootProp::writeEntry( const TQString& rKey, const TQString& rValue )
247{
248 dirty = true;
249 if ( propDict.contains( rKey ) ) {
250 TQString aValue = propDict[ rKey ];
251 propDict.replace( rKey, rValue );
252 return aValue;
253 }
254 else {
255 propDict.insert( rKey, rValue );
256 return TQString::null;
257 }
258}
259
260TQString KRootProp::writeEntry( const TQString& rKey, int nValue )
261{
262 TQString aValue;
263
264 aValue.setNum( nValue );
265
266 return writeEntry( rKey, aValue );
267}
268
269TQString KRootProp::writeEntry( const TQString& rKey, const TQFont& rFont )
270{
271 return writeEntry( rKey, TQString(rFont.toString()) );
272}
273
274TQString KRootProp::writeEntry( const TQString& rKey, const TQColor& rColor )
275{
276 TQString aValue = TQString( "%1,%2,%3").arg(rColor.red()).arg(rColor.green()).arg(rColor.blue() );
277
278 return writeEntry( rKey, aValue );
279}
280
281TQString KRootProp::removeEntry(const TQString& rKey)
282{
283 if (propDict.contains(rKey)) {
284 dirty = true;
285 TQString aValue = propDict[rKey];
286 propDict.remove(rKey);
287 return aValue;
288 } else
289 return TQString::null;
290}
291
292TQStringList KRootProp::listEntries() const
293{
294 TQMap<TQString,TQString>::ConstIterator it;
295 TQStringList list;
296
297 TQMap<TQString,TQString>::ConstIterator end(propDict.end());
298 for (it=propDict.begin(); it!=end; ++it)
299 list += it.key();
300
301 return list;
302}
303#endif
KRootProp::readEntry
TQString readEntry(const TQString &rKey, const TQString &pDefault=TQString::null) const
Reads the value of an entry specified by rKey in the current property.
KRootProp::readColorEntry
TQColor readColorEntry(const TQString &rKey, const TQColor *pDefault=0) const
Reads a TQColor.
KRootProp::KRootProp
KRootProp(const TQString &rProp=TQString::null)
Constructs a KRootProp object for the property rProp.
KRootProp::readNumEntry
int readNumEntry(const TQString &rKey, int nDefault=0) const
Reads a numerical value.
KRootProp::writeEntry
TQString writeEntry(const TQString &rKey, const TQString &rValue)
Writes a (key/value) pair.
KRootProp::~KRootProp
~KRootProp()
Destructs the KRootProp object.
KRootProp::destroy
void destroy()
Destroys the property completely.
KRootProp::removeEntry
TQString removeEntry(const TQString &rKey)
Removes an entry.
KRootProp::sync
void sync()
Flushes the entry cache.
KRootProp::readFontEntry
TQFont readFontEntry(const TQString &rKey, const TQFont *pDefault=0) const
Reads a TQFont value.
KRootProp::prop
TQString prop() const
Returns the name of the property under which keys are searched.
KRootProp::setProp
void setProp(const TQString &rProp=TQString())
Sets the property in which keys will be searched.
KRootProp::listEntries
TQStringList listEntries() const
Returns a list of all keys.
TDEStdAccel::key
int key(StdAccel id)
Definition: tdestdaccel.cpp:383
TDEStdAccel::end
const TDEShortcut & end()
Goto end of the document.
Definition: tdestdaccel.cpp:289
tdelocale.h

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.