File: cdlgkeyinfo.cpp

package info (click to toggle)
gpgkeys 0.3.1-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 276 kB
  • ctags: 241
  • sloc: cpp: 2,007; makefile: 53
file content (195 lines) | stat: -rw-r--r-- 5,803 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * GPG Keys 
 * ckeyinfo.cpp
 * (c) 2001 Peter Mathiasson <peter@mathiasson.nu>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation
 */

#include <qstatusbar.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qfont.h>
#include <qprocess.h>
#include <qlistview.h>
#include <qpopupmenu.h>
#include "cdlgserversearch.h"
#include "clistviewitem.h"
#include "cdlgkeyinfo.h"
#include "functions.h"
#include "config.h"

/* --------------------------------------------------------------------------------- */

CDlgKeyInfo::CDlgKeyInfo( QWidget *parent, const QString tmpKeyId, const QString tmpUserId ) :
CDlgKeyInfoUI( parent, 0, TRUE )
{

    userId = tmpUserId;
    keyId = tmpKeyId;
    
    /* Set Font */
    QFont fixedFont = readConfigFont( "fixedfont", FIX_FONT );
    setFont( readConfigFont( "stdfont", STD_FONT ) );
    lvSubKeys->setFont( fixedFont );
    lvUserID->setFont( fixedFont );

    /* Create Popup Menu */
    popupMenu = new QPopupMenu( this );
    popupMenu->insertItem( tr( "&Lookup Key" ), this, SLOT(lookupKey()), CTRL+Key_L );

    /* UserID ListView */
    connect( lvUserID, SIGNAL(contextMenuRequested(QListViewItem*,const QPoint&,int)),
             this, SLOT(contextMenuRequested(QListViewItem*,const QPoint&,int)) );

    /* Fetch key information */
    getKeyInfo();

}

/* --------------------------------------------------------------------------------- */

void CDlgKeyInfo::getKeyInfo()
{
    /* Clear ListViews */
    lvUserID->clear();
    lvSubKeys->clear();
    
    /* Set Caption */
    setCaption( userId + tr( " (Fetching Information...)" ) );

    /* Create Process */
    gpgProc = new QProcess( this );
    gpgProc->addArgument( readConfigString( "gpgpath", GPGPATH ) );
    gpgProc->addArgument( "--list-sigs" );
    gpgProc->addArgument( "--fingerprint" );
    gpgProc->addArgument( "--with-colon" );
    gpgProc->addArgument( "0x" + keyId );
    connect( gpgProc, SIGNAL(processExited()), this, SLOT(processDone()) );
    connect( gpgProc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) );
    
    /* Run GPG */
    if ( !gpgProc->start() ) {        
        return;
    }
}

/* --------------------------------------------------------------------------------- */

void CDlgKeyInfo::processDone()
{
    setCaption( userId );
}

/* --------------------------------------------------------------------------------- */

void CDlgKeyInfo::readFromStdout()
{
    QStringList entry;
    static bool publicSig;

    while ( gpgProc->canReadLineStdout() ) {
        
        /* Read/Split Line */
        entry = QStringList::split( ':', gpgProc->readLineStdout(), TRUE );

        /* Public Key */
        if ( entry[0] == "pub" ) {

            /* Set Information */
            publicSig = TRUE;
            editKeyID->setText( entry[4] );
            editTrust->setText( getTrust( entry[1] ) );
            editType->setText( entry[2] + "/" + getCipher( entry[3] ) );
            editDate->setText( entry[5] );
            editExpiration->setText( entry[6] );

            /* Create UserID */
            itemUid = new CListViewItem( lvUserID, CListViewItem::USERID );
            itemUid->setText( 0, fromUtf8( entry[9] ) );
            itemUid->setText( 1, getTrust( entry[1] ) );

        }

        /* User ID */
        else if ( entry[0] == "uid" ) {
            itemUid = new CListViewItem( lvUserID, CListViewItem::USERID );
            itemUid->setText( 0, fromUtf8( entry[9] ) );
            itemUid->setText( 1, getTrust( entry[1] ) );
        }

        /* Fingerprint */
        else if ( entry[0] == "fpr" ) {

            /* Set Fingerprint */
            editFingerprint->setText( entry[9] );

        }

        /* Sub Key */
        else if ( entry[0] == "sub" ) {

            /* Add ListView Item */
            QListViewItem *item = new QListViewItem( lvSubKeys );
            item->setText( 0, entry[4] );
            item->setText( 1, entry[2] + "/" + getCipher( entry[3] ) );
            item->setText( 2, entry[5] );
            item->setText( 3, entry[6] );
            publicSig = FALSE;

        }

        /* Signature */
        else if ( entry[0] == "sig" && publicSig ) {
            CListViewItem *item = new CListViewItem( itemUid, CListViewItem::SIGNATURE );
            item->setText( 0, fromUtf8( entry[9] ) );
            item->setText( 2, getCipher( entry[3] ) );
            item->setText( 3, entry[5] );            
            item->setText( 4, entry[4] );
        }
        
    }
}

/* --------------------------------------------------------------------------------- */

void CDlgKeyInfo::contextMenuRequested( QListViewItem *tmpItem, const QPoint &pos, int )
{
    /* Abort if no item selected */
    if ( !tmpItem )
        return;

    /* Display Menu */
    CListViewItem *item = (CListViewItem*)tmpItem;
    if ( item->type == CListViewItem::SIGNATURE )
        popupMenu->exec( pos );
}

/* --------------------------------------------------------------------------------- */

void CDlgKeyInfo::lookupKey()
{
    /* Get Item */
    CListViewItem *item = (CListViewItem*)lvUserID->currentItem();

    /* Check Item */
    if ( item->type != CListViewItem::SIGNATURE )
        return;

    /* Display Dialog */
    CDlgServerSearch dlgServerSearch( this, "0x" + item->text(4).right(8) );
    connect( &dlgServerSearch, SIGNAL(newPublic()), this, SLOT(reReadInfo()) );
    dlgServerSearch.exec();
}

/* --------------------------------------------------------------------------------- */

void CDlgKeyInfo::reReadInfo()
{
    getKeyInfo();
    emit newPublic();
}

/* --------------------------------------------------------------------------------- */