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

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • core
KGpgUatNode.cpp
Go to the documentation of this file.
1 /* Copyright 2008,2009,2010,2012 Rolf Eike Beer <kde@opensource.sf-tec.de>
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License as
5  * published by the Free Software Foundation; either version 2 of
6  * the License or (at your option) version 3 or any later version
7  * accepted by the membership of KDE e.V. (or its successor approved
8  * by the membership of KDE e.V.), which shall act as a proxy
9  * defined in Section 14 of version 3 of the license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "KGpgUatNode.h"
20 
21 #include "gpgproc.h"
22 #include "KGpgKeyNode.h"
23 
24 #include <KLocale>
25 #include <KUrl>
26 
27 #include <QDir>
28 #include <QFile>
29 #include <QPixmap>
30 #include <QDateTime>
31 
32 class KGpgUatNodePrivate {
33 public:
34  KGpgUatNodePrivate(const KGpgKeyNode *parent, const unsigned int index, const QStringList &sl);
35 
36  const QString m_idx;
37  const QPixmap m_pixmap;
38  QDateTime m_creation;
39 
40 private:
41  static QPixmap loadImage(const KGpgKeyNode *parent, const QString &index);
42 };
43 
44 KGpgUatNodePrivate::KGpgUatNodePrivate(const KGpgKeyNode *parent, const unsigned int index, const QStringList &sl)
45  : m_idx(QString::number(index)),
46  m_pixmap(loadImage(parent, m_idx))
47 {
48  if (sl.count() < 6)
49  return;
50  m_creation = QDateTime::fromTime_t(sl.at(5).toUInt());
51 }
52 
53 QPixmap
54 KGpgUatNodePrivate::loadImage(const KGpgKeyNode *parent, const QString &index)
55 {
56  QPixmap pixmap;
57 #ifdef Q_OS_WIN32 //krazy:exclude=cpp
58  const QString pgpgoutput = QLatin1String("cmd /C \"echo %I\"");
59 #else
60  const QString pgpgoutput = QLatin1String("echo %I");
61 #endif
62 
63  GPGProc workProcess;
64  workProcess <<
65  QLatin1String("--no-greeting") <<
66  QLatin1String("--status-fd=2") <<
67  QLatin1String("--photo-viewer") << pgpgoutput <<
68  QLatin1String("--edit-key") << parent->getFingerprint() <<
69  QLatin1String( "uid" ) << index <<
70  QLatin1String( "showphoto" ) <<
71  QLatin1String( "quit" );
72 
73  workProcess.start();
74  workProcess.waitForFinished();
75  if (workProcess.exitCode() != 0)
76  return pixmap;
77 
78  QString tmpfile;
79  if (workProcess.readln(tmpfile) < 0)
80  return pixmap;
81 
82  KUrl url(tmpfile);
83  pixmap.load(url.path());
84  QFile::remove(url.path());
85  QDir dir;
86  dir.rmdir(url.directory());
87 
88  return pixmap;
89 }
90 
91 KGpgUatNode::KGpgUatNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl)
92  : KGpgSignableNode(parent),
93  d_ptr(new KGpgUatNodePrivate(parent, index, sl))
94 {
95 }
96 
97 KGpgUatNode::~KGpgUatNode()
98 {
99  delete d_ptr;
100 }
101 
102 QString
103 KGpgUatNode::getName() const
104 {
105  return i18n("Photo id");
106 }
107 
108 QString
109 KGpgUatNode::getSize() const
110 {
111  const Q_D(KGpgUatNode);
112 
113  return QString::number(d->m_pixmap.width()) + QLatin1Char( 'x' ) + QString::number(d->m_pixmap.height());
114 }
115 
116 QDateTime
117 KGpgUatNode::getCreation() const
118 {
119  const Q_D(KGpgUatNode);
120 
121  return d->m_creation;
122 }
123 
124 KGpgKeyNode *
125 KGpgUatNode::getParentKeyNode() const
126 {
127  return m_parent->toKeyNode();
128 }
129 
130 void
131 KGpgUatNode::readChildren()
132 {
133 }
134 
135 KgpgCore::KgpgItemType
136 KGpgUatNode::getType() const
137 {
138  return KgpgCore::ITYPE_UAT;
139 }
140 
141 KgpgCore::KgpgKeyTrust
142 KGpgUatNode::getTrust() const
143 {
144  return KgpgCore::TRUST_NOKEY;
145 }
146 
147 const QPixmap &
148 KGpgUatNode::getPixmap() const
149 {
150  const Q_D(KGpgUatNode);
151 
152  return d->m_pixmap;
153 }
154 
155 QString
156 KGpgUatNode::getId() const
157 {
158  const Q_D(KGpgUatNode);
159 
160  return d->m_idx;
161 }
162 
163 KGpgKeyNode *
164 KGpgUatNode::getKeyNode(void)
165 {
166  return getParentKeyNode()->toKeyNode();
167 }
168 
169 const KGpgKeyNode *
170 KGpgUatNode::getKeyNode(void) const
171 {
172  return getParentKeyNode()->toKeyNode();
173 }
KGpgUatNode::readChildren
virtual void readChildren()
reimplemented in every base class to read in the child data
Definition: KGpgUatNode.cpp:131
KGpgUatNode.h
KGpgUatNode::getTrust
virtual KgpgCore::KgpgKeyTrust getTrust() const
Definition: KGpgUatNode.cpp:142
GPGProc
A interface to GnuPG handling UTF8 recoding correctly.
Definition: gpgproc.h:36
KGpgUatNode::getCreation
virtual QDateTime getCreation() const
Definition: KGpgUatNode.cpp:117
GPGProc::readln
int readln(QString &line, const bool colons=false)
Reads a line of text (excluding '\n').
Definition: gpgproc.cpp:203
KgpgCore::TRUST_NOKEY
internal value, e.g. for key groups
Definition: kgpgkey.h:65
QFile::remove
bool remove()
QList::at
const T & at(int i) const
KGpgUatNode
A user attribute (i.e.
Definition: KGpgUatNode.h:36
KGpgKeyNode
A public key with or without corresponding secret key.
Definition: KGpgKeyNode.h:33
QDateTime::fromTime_t
QDateTime fromTime_t(uint seconds)
GPGProc::start
void start()
Starts the process.
Definition: gpgproc.cpp:185
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
QDir::rmdir
bool rmdir(const QString &dirName) const
KGpgKeyNode::getFingerprint
const QString & getFingerprint() const
Definition: KGpgKeyNode.cpp:75
KGpgUatNode::~KGpgUatNode
virtual ~KGpgUatNode()
Definition: KGpgUatNode.cpp:97
KGpgUatNode::getPixmap
const QPixmap & getPixmap() const
Definition: KGpgUatNode.cpp:148
KGpgUatNode::getKeyNode
virtual KGpgKeyNode * getKeyNode(void)
returns the key node this node belongs to
Definition: KGpgUatNode.cpp:164
gpgproc.h
KGpgUatNode::getId
virtual QString getId() const
Definition: KGpgUatNode.cpp:156
QString
KGpgUatNode::getType
virtual KgpgCore::KgpgItemType getType() const
Returns the item type of this object.
Definition: KGpgUatNode.cpp:136
KGpgUatNode::getParentKeyNode
virtual KGpgKeyNode * getParentKeyNode() const
Definition: KGpgUatNode.cpp:125
QPixmap::load
bool load(const QString &fileName, const char *format, QFlags< Qt::ImageConversionFlag > flags)
QStringList
QPixmap
QLatin1Char
QDir
KGpgNode::toKeyNode
KGpgKeyNode * toKeyNode()
Definition: KGpgNode.cpp:94
KGpgUatNode::getName
virtual QString getName() const
Definition: KGpgUatNode.cpp:103
KGpgUatNode::getSize
virtual QString getSize() const
Returns a string describing the size of this object.
Definition: KGpgUatNode.cpp:109
QLatin1String
KGpgNode::m_parent
KGpgExpandableNode * m_parent
Definition: KGpgNode.h:50
KgpgCore::ITYPE_UAT
user attribute to a key (i.e. photo id)
Definition: kgpgkey.h:100
KGpgKeyNode.h
KGpgUatNode::KGpgUatNode
KGpgUatNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl)
Definition: KGpgUatNode.cpp:91
KGpgSignableNode
An object that may have KGpgSignNode children.
Definition: KGpgSignableNode.h:31
QDateTime
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

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

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

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