Changeset View
Changeset View
Standalone View
Standalone View
src/tests/test_keyselectioncombo.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This file is part of libkleopatra's test suite. | ||||
3 | Copyright (c) 2016 Klarälvdalens Datakonsult AB | ||||
4 | | ||||
5 | Libkleopatra is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU General Public License, | ||||
7 | version 2, as published by the Free Software Foundation. | ||||
8 | | ||||
9 | Libkleopatra is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program; if not, write to the Free Software | ||||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
17 | */ | ||||
18 | | ||||
19 | #include "ui/keyselectioncombo.h" | ||||
20 | #include "kleo/defaultkeyfilter.h" | ||||
21 | #include <gpgme++/key.h> | ||||
22 | | ||||
23 | #include <KAboutData> | ||||
24 | #include <QDebug> | ||||
25 | | ||||
26 | #include <vector> | ||||
27 | #include <QApplication> | ||||
28 | #include <KLocalizedString> | ||||
29 | #include <QCommandLineParser> | ||||
30 | #include <QVBoxLayout> | ||||
31 | | ||||
32 | int main(int argc, char **argv) | ||||
33 | { | ||||
34 | QApplication app(argc, argv); | ||||
35 | KAboutData aboutData(QStringLiteral("test_keyselectioncombo"), i18n("KeySelectionCombo Test"), QStringLiteral("0.1")); | ||||
36 | QCommandLineParser parser; | ||||
37 | QCommandLineOption openpgpOption(QStringLiteral("openpgp"), i18n("Show OpenPGP keys")); | ||||
38 | parser.addOption(openpgpOption); | ||||
39 | QCommandLineOption smimeOption(QStringLiteral("smime"), i18n("Show S/MIME keys")); | ||||
40 | parser.addOption(smimeOption); | ||||
41 | QCommandLineOption encryptOption(QStringLiteral("encryption"), i18n("Show keys for encryption")); | ||||
42 | parser.addOption(encryptOption); | ||||
43 | QCommandLineOption signingOption(QStringLiteral("signing"), i18n("Show keys for signing")); | ||||
44 | parser.addOption(signingOption); | ||||
45 | | ||||
46 | KAboutData::setApplicationData(aboutData); | ||||
47 | parser.addVersionOption(); | ||||
48 | parser.addHelpOption(); | ||||
49 | aboutData.setupCommandLine(&parser); | ||||
50 | parser.process(app); | ||||
51 | aboutData.processCommandLine(&parser); | ||||
52 | | ||||
53 | QWidget window; | ||||
54 | QVBoxLayout layout(&window); | ||||
55 | | ||||
56 | Kleo::KeySelectionCombo combo; | ||||
57 | layout.addWidget(&combo); | ||||
58 | | ||||
59 | boost::shared_ptr<const Kleo::DefaultKeyFilter> filter(new Kleo::DefaultKeyFilter); | ||||
60 | filter->setCanSign(parser.isSet(signingOption) ? Kleo::DefaultKeyFilter::Set : Kleo::DefaultKeyFilter::DoesNotMatter); | ||||
61 | filter->setCanEncrypt(parser.isSet(encryptOption) ? Kleo::DefaultKeyFilter::Set : Kleo::DefaultKeyFilter::DoesNotMatter); | ||||
62 | filter->setIsOpenPGP(parser.isSet(openpgpOption) ? Kleo::DefaultKeyFilter::Set : Kleo::DefaultKeyFilter::NotSet); | ||||
63 | filter->setHasSecret(Kleo::DefaultKeyFilter::Set); | ||||
64 | //filter->setOwnerTrust(Kleo::DefaultKeyFilter::IsAtLeast); | ||||
65 | //filter->setOwnerTrustReferenceLevel(GpgME::Key::Ultimate); | ||||
66 | combo.setKeyFilter(filter); | ||||
67 | | ||||
68 | combo.prependCustomItem(QIcon(), i18n("No key"), QStringLiteral("no-key")); | ||||
69 | QObject::connect(&combo, &Kleo::KeySelectionCombo::currentKeyChanged, | ||||
70 | [](const GpgME::Key &key) { | ||||
71 | qDebug() << "Current key changed:" << key.keyID(); | ||||
72 | }); | ||||
73 | QObject::connect(&combo, &Kleo::KeySelectionCombo::customItemSelected, | ||||
74 | [](const QVariant &data) { | ||||
75 | qDebug() << "Custom item selected:" << data.toString(); | ||||
76 | }); | ||||
77 | | ||||
78 | window.show(); | ||||
79 | | ||||
80 | /* | ||||
81 | if (dlg.exec() == QDialog::Accepted) { | ||||
82 | qDebug() << "accepted; selected key:" << (dlg.selectedKey().userID(0).id() ? dlg.selectedKey().userID(0).id() : "<null>") << "\nselected _keys_:"; | ||||
83 | for (std::vector<GpgME::Key>::const_iterator it = dlg.selectedKeys().begin(); it != dlg.selectedKeys().end(); ++it) { | ||||
84 | qDebug() << (it->userID(0).id() ? it->userID(0).id() : "<null>"); | ||||
85 | } | ||||
86 | } else { | ||||
87 | qDebug() << "rejected"; | ||||
88 | } | ||||
89 | */ | ||||
90 | | ||||
91 | return app.exec(); | ||||
92 | } | ||||
93 | |