28 #include <QStringList>
29 #include <QTextStream>
31 class KGpgGroupNodePrivate {
33 KGpgGroupNodePrivate(
const QString &name);
47 int findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines);
49 static const QRegExp &groupPattern();
50 static const QString &groupTag();
53 KGpgGroupNodePrivate::KGpgGroupNodePrivate(
const QString &name)
59 KGpgGroupNodePrivate::findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines)
63 if (!conffile.exists())
66 if (!conffile.open(QIODevice::ReadWrite))
69 stream.setDevice(&conffile);
73 while (!stream.atEnd()) {
74 const QString rawLine = stream.readLine();
76 QString parsedLine = rawLine.simplified().section(QLatin1Char(
'#'), 0, 0);
78 if (groupPattern().exactMatch(parsedLine)) {
80 parsedLine = parsedLine.remove(0, 6);
81 if (parsedLine.startsWith(m_name)) {
82 if (parsedLine.mid(m_name.length()).simplified().startsWith(QLatin1Char(
'='))) {
102 KGpgGroupNodePrivate::groupPattern()
104 static const QRegExp groupre(QLatin1String(
"^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$"));
110 KGpgGroupNodePrivate::groupTag()
112 static const QString grouptag(QLatin1String(
"group "));
119 d_ptr(new KGpgGroupNodePrivate(name))
121 foreach (
const QString &
id, members)
129 d_ptr(new KGpgGroupNodePrivate(name))
131 Q_ASSERT(members.count() > 0);
147 KgpgCore::KgpgItemType
164 return i18np(
"1 key",
"%1 keys",
children.count());
180 int index = d->findGroupEntry(conffile, t, lines);
187 kDebug(2100) <<
"Group " << d->m_name <<
" not renamed, group does not exist";
192 const QString values = lines[index].simplified().mid(6 + d->m_name.length());
193 lines[index] = d->groupTag() + newName + QLatin1Char(
' ') + values;
196 t << lines.join(QLatin1String(
"\n")) + QLatin1Char(
'\n');
209 int index = d->findGroupEntry(conffile, t, lines);
215 QStringList memberIds;
220 const QString groupEntry = d->groupTag() + d->m_name + QLatin1String(
" = ") +
221 memberIds.join(QLatin1String(
" "));
224 lines[index] = groupEntry;
229 t << lines.join(QLatin1String(
"\n")) + QLatin1Char(
'\n');
240 int index = d->findGroupEntry(conffile, t, lines);
249 lines.removeAt(index);
251 t << lines.join(QLatin1String(
"\n")) + QLatin1Char(
'\n');
260 if (!qfile.exists() || !qfile.open(QIODevice::ReadOnly))
263 QTextStream t(&qfile);
266 QString line = t.readLine().simplified().section(QLatin1Char(
'#'), 0, 0);
267 if (!KGpgGroupNodePrivate::groupPattern().exactMatch(line))
273 groups.append(line.replace(QLatin1Char(
'='), QLatin1Char(
' ')).simplified());
KGpgRootNode * toRootNode()
QList< KGpgKeyNode * > List
static QString gpgConfigPath()
Get The path of the gpg configuration file.
A GnuPG group of public keys.
virtual QString getName() const
virtual KGpgNode * getChild(const int index) const
Returns the child node at the given index.
KGpgGroupNode(KGpgRootNode *parent, const QString &name, const QStringList &members)
A public key with or without corresponding secret key.
The parent of all key data objects.
void rename(const QString &newName)
Rename this group node.
KGpgGroupMemberNode * toGroupMemberNode()
virtual int getChildCount()
Return how many child nodes exist.
virtual QString getSize() const
Return size of group.
static QStringList readGroups()
get all groups from GnuPG config file
the element is a GnuPG key group
virtual KgpgCore::KgpgItemType getType() const
Returns the item type of this object.
The abstract base class for all classes that may have child objects.
virtual QString getId() const
A member of a GnuPG group.
KGpgExpandableNode * m_parent
void saveMembers()
Write the current members to GnuPG config file.
void remove()
Remove this group from the GnuPG config file.
virtual void readChildren()
reimplemented in every base class to read in the child data