1
/* ---------------------------------------------------------------------
2
* Definition of VkConfig vk_config.h
3
* Configuration file parser
4
* ---------------------------------------------------------------------
5
* This file is part of Valkyrie, a front-end for Valgrind
6
* Copyright (C) 2000-2008, OpenWorks LLP <info@open-works.co.uk>
7
* This program is released under the terms of the GNU GPL v.2
8
* See the file COPYING for the full license details.
21
#include "tool_object.h"
22
#include "valkyrie_object.h"
27
EntryData( const QString &value, bool dirty )
28
: mValue(value), mDirty(dirty) { }
29
EntryData() : mValue(QString::null), mDirty(false) { }
30
QString mValue; /* the actual value we want */
31
bool mDirty; /* must the entry be written to disk? */
36
EntryKey( const QString &group=QString::null,
37
const QString &key=QString::null )
38
: mGroup(group), mKey(key), cKey( key.data() ) { }
39
QString mGroup; /* group to which this EntryKey belongs */
40
QString mKey; /* key of the entry in question */
41
const char *cKey; /* testing equality with operator < */
44
/* compares two EntryKeys (needed for QMap) */
45
inline bool operator <( const EntryKey &k1, const EntryKey &k2 )
47
int result = qstrcmp( k1.mGroup.data(), k2.mGroup.data() );
49
return ( result < 0 );
51
if ( !k1.cKey && k2.cKey )
55
if ( k1.cKey && k2.cKey )
56
result = strcmp( k1.cKey, k2.cKey );
63
typedef QMap<EntryKey, EntryData> EntryMap;
64
typedef QMap<EntryKey, EntryData>::Iterator EntryMapIterator;
68
class VkConfig : public QObject
74
bool initCfg( Valkyrie* vk );
76
bool isDirty(); /* config holds data difft to that held on disk */
77
bool sync( Valkyrie* vk ); /* write config to disk */
79
/* these fns return the values set in config.h ------------------- */
82
const char* vkVersion();
83
const char* vkCopyright();
84
const char* vkAuthor();
85
const char* vkEmail();
86
const char* vgCopyright();
88
/* these fns return values held in private vars ---------------------- */
93
QChar sepChar() { return m_sep; }
96
QFont defaultAppFont();
99
bool strToBool( QString str );
101
/* read fns ---------------------------------------------------------- */
102
QString rdEntry( const QString &pKey, const QString &pGroup );
103
int rdInt ( const QString &pKey, const QString &pGroup );
104
bool rdBool ( const QString &pKey, const QString &pGroup );
105
QFont rdFont ( const QString &pKey, const QString &pGroup=QString::null );
106
QColor rdColor( const QString &pKey );
108
/* write fns --------------------------------------------------------- */
109
void wrEntry( const QString &pValue,
110
const QString &pKey, const QString &pGroup );
111
void wrInt ( const int pValue,
112
const QString &pKey, const QString &pGroup );
113
void wrBool ( const bool &bValue,
114
const QString &pKey, const QString &pGroup );
115
void wrFont ( const QFont &rFont, const QString &pKey );
116
void wrColor( const QColor &pColor, const QString &pKey );
117
/* special version of wrEntry: adds values to the existing entry,
118
rather than replacing */
119
void addEntry( const QString &pValue,
120
const QString &pKey, const QString &pGroup );
123
bool checkRCEntry( QString path, Valkyrie* vk );
124
bool checkRCTree( Valkyrie* vk );
125
QString mkConfigHeader( void );
126
QString mkConfigDefaults( Valkyrie* vk );
127
bool writeConfigDefaults( Valkyrie* vk );
129
bool writeConfig( EntryMap rcMap, bool backup=false );
130
EntryMap parseConfigToMap( QTextStream &stream );
131
void insertData( const EntryKey &key, const EntryData &data );
132
void backupConfigFile();
133
bool parseFile( Valkyrie *vk, /*OUT*/EntryMap &map );
134
bool updateCfgFile( EntryMap &newMap, EntryMap &rcMap,
135
/*OUT*/EntryMap &dstMap );
143
QCString m_vk_version;
144
QCString m_vk_copyright;
145
QCString m_vk_author;
147
QCString m_vg_copyright;
149
QFont m_defaultAppFont;
151
QString m_vkdocPath; /* path to valkyrie docs dir */
152
QString m_rcPath; /* path to ~/valkyrie=X.X.X dir */
153
QString m_rcFileName; /* where valkyrierc lives */
154
QString m_dbasePath; /* path to dbase dir */
155
/* path to user's suppression files dir.
156
default is ~/.valkyrie/suppressions */
159
EntryMap m_EntryMap; /* the config dict */
164
/* Globally available object ------------------------------------------- */
165
extern VkConfig* vkConfig;