~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/pgputil.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "pgputil.h"
 
2
 
1
3
#include <QtCore>
2
4
#include <QStringList>
3
5
#include <QDialog>
 
6
#include <QMessageBox>
4
7
 
5
 
#include "pgputil.h"
6
8
#include "passphrasedlg.h"
7
 
 
8
 
 
9
 
PGPUtil::PGPUtil() : qcaEventHandler_(NULL), passphraseDlg_(NULL)
 
9
#include "showtextdlg.h"
 
10
 
 
11
PGPUtil* PGPUtil::instance_ = 0;
 
12
 
 
13
PGPUtil::PGPUtil() : qcaEventHandler_(NULL), passphraseDlg_(NULL), cache_no_pgp_(false)
10
14
{
11
15
        qcaEventHandler_ = new QCA::EventHandler(this);
12
16
        connect(qcaEventHandler_,SIGNAL(eventReady(int,const QCA::Event&)),SLOT(handleEvent(int,const QCA::Event&)));
123
127
 
124
128
bool PGPUtil::pgpAvailable()
125
129
{
126
 
        return (QCA::isSupported("openpgp") && keystores_.count() > 0);
 
130
        bool have_openpgp = false;
 
131
        if(!cache_no_pgp_) {
 
132
                have_openpgp = QCA::isSupported("openpgp");
 
133
                if(!have_openpgp)
 
134
                        cache_no_pgp_ = true;
 
135
        }
 
136
        return (have_openpgp && keystores_.count() > 0);
 
137
}
 
138
 
 
139
void PGPUtil::clearPGPAvailableCache()
 
140
{
 
141
        cache_no_pgp_ = false;
127
142
}
128
143
 
129
144
QString PGPUtil::stripHeaderFooter(const QString &str)
275
290
        keystores_ += ks;
276
291
}
277
292
 
278
 
 
279
 
 
280
 
 
281
 
PGPUtil* PGPUtil::instance_ = NULL;
 
293
void PGPUtil::showDiagnosticText(const QString& event, const QString& diagnostic)
 
294
{
 
295
        while (1) {
 
296
                QMessageBox msgbox(QMessageBox::Critical,
 
297
                                   tr("Error"),
 
298
                                   event,
 
299
                                   QMessageBox::Ok, 0);
 
300
                QPushButton *diag = msgbox.addButton(tr("Diagnostics"), QMessageBox::HelpRole);
 
301
                msgbox.exec();
 
302
                if (msgbox.clickedButton() == diag) {
 
303
                        ShowTextDlg* w = new ShowTextDlg(diagnostic, true, false, 0);
 
304
                        w->setWindowTitle(tr("OpenPGP Diagnostic Text"));
 
305
                        w->resize(560, 240);
 
306
                        w->exec();
 
307
 
 
308
                        continue;
 
309
                }
 
310
                else {
 
311
                        break;
 
312
                }
 
313
        }
 
314
}
 
315
 
 
316
void PGPUtil::showDiagnosticText(QCA::SecureMessage::Error error, const QString& diagnostic)
 
317
{
 
318
        showDiagnosticText(tr("There was an error trying to send the message encrypted.\nReason: %1.")
 
319
                           .arg(PGPUtil::instance().messageErrorString(error)),
 
320
                           diagnostic);
 
321
}