• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • kgpgconf
configwriter.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  configwriter.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "configwriter.h"
34 
35 #include "configuration.h"
36 
37 #include <QByteArray>
38 #include <QDateTime>
39 #include <QIODevice>
40 #include <QString>
41 #include <QStringList>
42 #include <QTextStream>
43 #include <QVector>
44 
45 #include <cassert>
46 
47 namespace {
48  struct GpgConfConfEntry {
49  GpgConfConfEntry() : changeFlag( ConfigEntry::UnspecifiedMutability ), useDefault( false ) {}
50 
51  QString component;
52  QString option;
53  ConfigEntry::Mutability changeFlag;
54  bool useDefault;
55  QString value;
56  QString toString() const {
57  QString changeStr;
58  if ( changeFlag == ConfigEntry::Change )
59  changeStr = QLatin1String("[change]");
60  else if ( changeFlag == ConfigEntry::NoChange )
61  changeStr = QLatin1String("[no-change]");
62 
63  QString str;
64  if ( useDefault )
65  str += QString::fromLatin1( " %1 %2 [default]\n" ).arg( component, option );
66  if ( !( useDefault && changeStr.isEmpty() ) )
67  str += QString::fromLatin1( " %1 %2 %3 %4\n" ).arg( component, option, changeStr, value );
68  return str;
69  }
70  };
71 }
72 
73 class ConfigWriter::Private
74 {
75 public:
76  QIODevice* device;
77  bool write( const QString& line );
78 
79 };
80 
81 ConfigWriter::ConfigWriter( QIODevice* device ) : d( new Private )
82 {
83  assert( device );
84  d->device = device;
85 }
86 
87 ConfigWriter::~ConfigWriter()
88 {
89  delete d;
90 }
91 
92 bool ConfigWriter::writeConfig( Config* config ) const
93 {
94  assert( d->device->isOpen() );
95  assert( d->device->isWritable() );
96 
97  QVector<GpgConfConfEntry> lines;
98 
99  Q_FOREACH ( const QString & i, config->componentList() )
100  {
101  ConfigComponent* const component = config->component( i );
102  assert( component );
103  Q_FOREACH ( const QString & j, component->groupList() )
104  {
105  ConfigGroup* const group = component->group( j );
106  assert( group );
107  Q_FOREACH ( const QString & k, group->entryList() )
108  {
109  ConfigEntry* const entry = group->entry( k );
110  assert( entry );
111  if ( entry->mutability() != ConfigEntry::UnspecifiedMutability || entry->useBuiltInDefault() || !entry->outputString().isEmpty() )
112  {
113  GpgConfConfEntry cfgentry;
114  cfgentry.useDefault = entry->useBuiltInDefault();
115  cfgentry.value = entry->useBuiltInDefault() ? QString() : entry->outputString();
116  cfgentry.component = component->name();
117  cfgentry.option = entry->name();
118  cfgentry.changeFlag = entry->mutability();
119  lines.append( cfgentry );
120  }
121  }
122  }
123  }
124 
125  QTextStream out( d->device );
126  out << QString::fromLatin1( "# gpgconf configuration file generated by kgpgconf on %1\n\n" ).arg( QDateTime::currentDateTime().toString() );
127 
128  out << "*";
129  Q_FOREACH ( const GpgConfConfEntry & i, lines )
130  {
131  out << i.toString();
132  }
133  return true;
134 }
135 
ConfigEntry::outputString
QString outputString() const
Definition: configuration.cpp:569
ConfigComponent::groupList
QStringList groupList() const
Definition: configuration.cpp:175
Config::component
ConfigComponent * component(const QString &name) const
Definition: configuration.cpp:133
ConfigComponent::name
QString name() const
Definition: configuration.cpp:155
ConfigGroup::entry
ConfigEntry * entry(const QString &name) const
Definition: configuration.cpp:248
option
const char * option
Definition: kleopatraapplication.cpp:91
ConfigWriter::ConfigWriter
ConfigWriter(QIODevice *device)
Definition: configwriter.cpp:81
Config::componentList
QStringList componentList() const
Definition: configuration.cpp:128
Config
Definition: configuration.h:46
ConfigComponent::group
ConfigGroup * group(const QString &name) const
Definition: configuration.cpp:180
d
#define d
Definition: adduseridcommand.cpp:90
ConfigComponent
Definition: configuration.h:64
configuration.h
ConfigWriter::writeConfig
bool writeConfig(Config *config) const
Definition: configwriter.cpp:92
ConfigGroup
Definition: configuration.h:94
ConfigEntry::mutability
Mutability mutability() const
Definition: configuration.cpp:309
ConfigEntry::Mutability
Mutability
Definition: configuration.h:127
ConfigEntry::Change
Definition: configuration.h:130
ConfigEntry::name
QString name() const
Definition: configuration.cpp:275
ConfigEntry::NoChange
Definition: configuration.h:129
configwriter.h
ConfigEntry::useBuiltInDefault
bool useBuiltInDefault() const
Definition: configuration.cpp:314
ConfigGroup::entryList
QStringList entryList() const
Definition: configuration.cpp:243
ConfigEntry::UnspecifiedMutability
Definition: configuration.h:128
ConfigWriter::~ConfigWriter
~ConfigWriter()
Definition: configwriter.cpp:87
QIODevice
ConfigEntry
Definition: configuration.h:123
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal