~ubuntu-branches/ubuntu/oneiric/valkyrie/oneiric

« back to all changes in this revision

Viewing changes to valkyrie/vk_config.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-09-02 22:08:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110902220834-kigsixteppj9epp5
Tags: 2.0.0-0ubuntu1
* New upstream release. (LP: #635129, LP: #832886, LP: #721298)
* Standards bumped to 3.9.2, no changes required.
* d/control, d/rules: cdbs removed, dh minimal rule instead.
* d/control: build system is qmake not autotools
* d/control: bump required qt to qt4
* d/valkyrie.install: installing html docs manually as make install
  no longer does so.
* d/patches/valkyrie-2.0.0-fix-doc.dir.patch: Fix doc path to match
  policy. Also corrects LP: #588074 since the documentation link now
  works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
9
 
 */
10
 
 
11
 
#ifndef __VK_CONFIG_H
12
 
#define __VK_CONFIG_H
13
 
 
14
 
#include <qfile.h>
15
 
#include <qmap.h>
16
 
#include <qobject.h>
17
 
#include <qcstring.h>
18
 
#include <qstring.h>
19
 
#include <qfont.h>
20
 
 
21
 
#include "tool_object.h"
22
 
#include "valkyrie_object.h"
23
 
 
24
 
 
25
 
struct EntryData
26
 
{
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? */
32
 
};
33
 
 
34
 
struct EntryKey
35
 
{
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 <     */
42
 
};
43
 
 
44
 
/* compares two EntryKeys (needed for QMap) */
45
 
inline bool operator <( const EntryKey &k1, const EntryKey &k2 )
46
 
{
47
 
   int result = qstrcmp( k1.mGroup.data(), k2.mGroup.data() );
48
 
   if ( result != 0 )
49
 
      return ( result < 0 );     
50
 
 
51
 
   if ( !k1.cKey && k2.cKey )
52
 
      return true;
53
 
 
54
 
   result = 0;
55
 
   if ( k1.cKey && k2.cKey )
56
 
      result = strcmp( k1.cKey, k2.cKey );
57
 
   if ( result != 0 )
58
 
      return result < 0;
59
 
 
60
 
   return false;
61
 
}
62
 
 
63
 
typedef QMap<EntryKey, EntryData> EntryMap;
64
 
typedef QMap<EntryKey, EntryData>::Iterator EntryMapIterator;
65
 
 
66
 
 
67
 
 
68
 
class VkConfig : public QObject
69
 
{
70
 
public:
71
 
   VkConfig();
72
 
   ~VkConfig();
73
 
 
74
 
   bool initCfg( Valkyrie* vk );
75
 
 
76
 
   bool isDirty();   /* config holds data difft to that held on disk */
77
 
   bool sync( Valkyrie* vk );  /* write config to disk */
78
 
 
79
 
   /* these fns return the values set in config.h ------------------- */
80
 
   const char* vkname();
81
 
   const char* vkName();
82
 
   const char* vkVersion();
83
 
   const char* vkCopyright();
84
 
   const char* vkAuthor();
85
 
   const char* vkEmail();
86
 
   const char* vgCopyright();
87
 
 
88
 
   /* these fns return values held in private vars ---------------------- */
89
 
   QString vkdocDir();
90
 
   QString rcDir();
91
 
   QString dbaseDir();
92
 
   QString suppDir();
93
 
   QChar sepChar() { return m_sep; }
94
 
   QStyle* vkStyle();
95
 
   QPalette vkPalette();
96
 
   QFont defaultAppFont();
97
 
 
98
 
   /* util functions */
99
 
   bool strToBool( QString str );
100
 
 
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 );
107
 
 
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 );
121
 
 
122
 
private:
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 );
128
 
 
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 );
136
 
 
137
 
private:
138
 
   QChar m_sep;
139
 
   bool  m_dirty;
140
 
 
141
 
   QCString m_vk_name;
142
 
   QCString m_vk_Name;
143
 
   QCString m_vk_version;
144
 
   QCString m_vk_copyright;
145
 
   QCString m_vk_author;
146
 
   QCString m_vk_email;
147
 
   QCString m_vg_copyright;
148
 
 
149
 
   QFont m_defaultAppFont;
150
 
 
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 */
157
 
   QString m_suppPath;
158
 
 
159
 
   EntryMap m_EntryMap;       /* the config dict */
160
 
};
161
 
 
162
 
 
163
 
 
164
 
/* Globally available object ------------------------------------------- */
165
 
extern VkConfig* vkConfig;
166
 
 
167
 
#endif