Qt: Add static factor methods for protocol

* lang/qt/src/qgpgmebackend.cpp (QGpgME::openpgp, QGpgME::smime): New.
* lang/qt/src/qgpgmebackend.h: Declare.
* lang/qt/tests/t-keylist.cpp (KeyListTest::testSingleKeyListSync):
  Use new functions.

--
This replaces the cryptobackendfactory functionality from libkleo.
This commit is contained in:
Andre Heinecke 2016-04-03 02:29:14 -08:00
parent faf987dd62
commit 0991485170
3 changed files with 33 additions and 2 deletions

View File

@ -507,3 +507,21 @@ const char *QGpgME::QGpgMEBackend::enumerateProtocols(int i) const
default: return 0;
}
}
static QGpgME::QGpgMEBackend *gpgmeBackend;
QGpgME::Protocol *QGpgME::openpgp()
{
if (!gpgmeBackend) {
gpgmeBackend = new QGpgME::QGpgMEBackend();
}
return gpgmeBackend->openpgp();
}
QGpgME::Protocol *QGpgME::smime()
{
if (!gpgmeBackend) {
gpgmeBackend = new QGpgME::QGpgMEBackend();
}
return gpgmeBackend->smime();
}

View File

@ -72,6 +72,20 @@ namespace QGpgME
class CryptoConfig;
class Protocol;
/** Obtain a reference to the OpenPGP Protocol.
*
* The reference is to a static object.
* @returns Refrence to the OpenPGP Protocol.
*/
Protocol *openpgp();
/** Obtain a reference to the smime Protocol.
*
* The reference is to a static object.
* @returns Refrence to the smime Protocol.
*/
Protocol *smime();
class QGpgMEBackend
{
public:

View File

@ -14,8 +14,7 @@ private Q_SLOTS:
void testSingleKeyListSync()
{
QGpgMEBackend backend;
KeyListJob *job = backend.openpgp()->keyListJob(false, false, false);
KeyListJob *job = openpgp()->keyListJob(false, false, false);
std::vector<GpgME::Key> keys;
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);