Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > cf746698214707f972e669b661d0ae59 > files > 29

kdepim4-4.14.10-1.3.mga5.src.rpm

From 0df8c74d5869612667e6f72b3de368fa8a77c9b4 Mon Sep 17 00:00:00 2001
From: Andre Heinecke <aheinecke@intevation.de>
Date: Tue, 10 Nov 2015 15:41:05 +0100
Subject: [PATCH 29/74] Backport fixes for search external certificates

Do not prefix query with 0x and show prefix info.

This generalizes the lookupcertificatescommand again so that
it can be used with a generic query. Prefixing 0x this low was wrong
and is also not necessary at least with SKS Keyservers.

Accordingly don't show the information text about how adding
or leaving out the 0x prefix might change results. Only show
it in case a search for a keyid or fingerprint does not return
a result.

(cherry picked from commit c2a6ef0c41598ef801a5b8a0438e59a7e2ae9b97)

Conflicts:
	kleopatra/commands/lookupcertificatescommand.cpp

Add --search command line option.

This option runs the lookupcertificatescommand with the provided
search string. This basically opens the external keysearch dialog.

The option implements the KDE 3 behavior of kleopatras
--query --external but I found it easier to understand if It is
named like the GnuPG --search option and does not mix the
"open certificate details / search on keyserver" options.

Behavior of the --query option is not documented a bit more
detailed in the help string.

CCBUG: 175980
(cherry picked from commit fcf92035b9a44f51d89e02268f1fdbc3e4c2ca3a)

Conflicts:
	kleopatra/kleopatra_options.h
	kleopatra/kleopatraapplication.cpp

Make "Search for External Certificates" work again

This uses the newly added search option to open kleopatra's
Keyserver search dialog instead of just opening Kleopatra.

CCBUG: 175980
(cherry picked from commit d591b2bbfa132632901870dedf00994009a37666)

Conflicts:
	libkleo/src/ui/keyselectiondialog.cpp
---
 kleopatra/commands/lookupcertificatescommand.cpp | 77 +++++++++++++-----------
 kleopatra/kleopatraapplication.cpp               | 44 +++++++++-----
 libkleo/ui/keyselectiondialog.cpp                |  7 +--
 3 files changed, 74 insertions(+), 54 deletions(-)

diff --git a/kleopatra/commands/lookupcertificatescommand.cpp b/kleopatra/commands/lookupcertificatescommand.cpp
index b54cd45d8f..0ba87edfc0 100644
--- a/kleopatra/commands/lookupcertificatescommand.cpp
+++ b/kleopatra/commands/lookupcertificatescommand.cpp
@@ -82,7 +82,7 @@ public:
     explicit Private( LookupCertificatesCommand * qq, KeyListController * c );
     ~Private();
 
-    QString fingerPrint;
+    QString query;
     void init();
 
 private:
@@ -100,8 +100,9 @@ private:
 
 private:
     using ImportCertificatesCommand::Private::showError;
-    void showError( QWidget * parent, const KeyListResult & result );
-    void showResult( QWidget * parent, const KeyListResult & result );
+    void showError(QWidget *parent, const KeyListResult &result);
+    void showResult(QWidget *parent, const KeyListResult &result);
+    void showHexPrefixInfo() const;
     void createDialog();
     KeyListJob * createKeyListJob( GpgME::Protocol proto ) const {
         const CryptoBackend::Protocol * const cbp = CryptoBackendFactory::instance()->protocol( proto );
@@ -152,11 +153,11 @@ LookupCertificatesCommand::LookupCertificatesCommand( KeyListController * c )
     d->init();
 }
 
-LookupCertificatesCommand::LookupCertificatesCommand( const QString & fingerPrint, KeyListController * c )
-    : ImportCertificatesCommand( new Private( this, c ) )
+LookupCertificatesCommand::LookupCertificatesCommand(const QString &query, KeyListController *c)
+    : ImportCertificatesCommand(new Private(this, c))
 {
     d->init();
-    d->fingerPrint = fingerPrint;
+    d->query = query;
 }
 
 LookupCertificatesCommand::LookupCertificatesCommand( QAbstractItemView * v, KeyListController * c )
@@ -182,17 +183,15 @@ void LookupCertificatesCommand::doStart() {
     d->createDialog();
     assert( d->dialog );
 
-    // if have prespecified fingerPrint, load into find field
-    // and start search
-    if ( ! d->fingerPrint.isEmpty() ) {
-        if ( !d->fingerPrint.startsWith( QLatin1String("0x") ) )
-            d->fingerPrint = QLatin1String("0x") + d->fingerPrint;
-        d->dialog->setSearchText( d->fingerPrint );
-        // Start Search
-        d->slotSearchTextChanged( d->fingerPrint );
+    // if we have a prespecified query, load it into find field
+    // and start the search
+    if (!d->query.isEmpty()) {
+        d->dialog->setSearchText(d->query);
+        d->slotSearchTextChanged(d->query);
+    } else {
+        d->dialog->setPassive(false);
     }
 
-    d->dialog->setPassive( false );
     d->dialog->show();
 
 }
@@ -223,22 +222,10 @@ void LookupCertificatesCommand::Private::slotSearchTextChanged( const QString &
         dialog->setCertificates( std::vector<Key>() );
     }
 
-    const QRegExp rx( QLatin1String( "(?:0x|0X)?[0-9a-fA-F]{6,}" ) );
-    if ( rx.exactMatch( str ) )
-        information( str.startsWith( QLatin1String( "0x" ), Qt::CaseInsensitive )
-                     ? i18n("<p>You seem to be searching for a fingerPrint or a key-id.</p>"
-                            "<p>Different keyservers expect different ways to search for these. "
-                            "Some require a \"0x\" prefix, while others require there be no such prefix.</p>"
-                            "<p>If your search does not yield any results, try removing the 0x prefix from your search.</p>")
-                     : i18n("<p>You seem to be searching for a fingerPrint or a key-id.</p>"
-                            "<p>Different keyservers expect different ways to search for these. "
-                            "Some require a \"0x\" prefix, while others require there be no such prefix.</p>"
-                            "<p>If your search does not yield any results, try adding the 0x prefix to your search.</p>"),
-                     i18n("Hex-String Search"),
-                     QLatin1String( "lookup-certificates-warn-0x-prefix" ) );
-
-    startKeyListJob( CMS,     str );
-    startKeyListJob( OpenPGP, str );
+    query = str;
+
+    startKeyListJob(CMS,     str);
+    startKeyListJob(OpenPGP, str);
 
 }
 
@@ -278,9 +265,13 @@ void LookupCertificatesCommand::Private::slotKeyListResult( const KeyListResult
     if ( keyListing.result.isTruncated() )
         showResult( dialog, keyListing.result );
 
-    if ( dialog ) {
-        dialog->setPassive( false );
-        dialog->setCertificates( keyListing.keys );
+    if (keyListing.keys.empty()) {
+        showHexPrefixInfo();
+    }
+
+    if (dialog) {
+        dialog->setPassive(false);
+        dialog->setCertificates(keyListing.keys);
     } else {
         finished();
     }
@@ -395,6 +386,24 @@ bool LookupCertificatesCommand::Private::checkConfig() const {
     return ok;
 }
 
+void LookupCertificatesCommand::Private::showHexPrefixInfo() const
+{
+    const QRegExp rx(QLatin1String("(?:0x|0X)?[0-9a-fA-F]{6,}"));
+    if (rx.exactMatch(query)) {
+        information(query.startsWith(QLatin1String("0x"), Qt::CaseInsensitive)
+                    ? i18n("<p>You seem to be searching for a fingerPrint or a key-id.</p>"
+                           "<p>Different keyservers expect different ways to search for these. "
+                           "Some require a \"0x\" prefix, while others require there be no such prefix.</p>"
+                           "<p>If your search does not yield any results, try removing the 0x prefix from your search.</p>")
+                    : i18n("<p>You seem to be searching for a fingerPrint or a key-id.</p>"
+                           "<p>Different keyservers expect different ways to search for these. "
+                           "Some require a \"0x\" prefix, while others require there be no such prefix.</p>"
+                           "<p>If your search does not yield any results, try adding the 0x prefix to your search.</p>"),
+                    i18n("Hex-String Search"),
+                    QLatin1String("lookup-certificates-warn-0x-prefix"));
+    }
+}
+
 #undef d
 #undef q
 
diff --git a/kleopatra/kleopatraapplication.cpp b/kleopatra/kleopatraapplication.cpp
index a6efbfe880..597fc1b47e 100644
--- a/kleopatra/kleopatraapplication.cpp
+++ b/kleopatra/kleopatraapplication.cpp
@@ -106,6 +106,7 @@ static const struct {
     { "verify",             I18N_NOOP("Verify file/signature"),                   "V" },
     { "decrypt-verify",     I18N_NOOP("Decrypt and/or verify file(s)"),          "D" },
     { "query <fingerprint>",I18N_NOOP("Search for Certificate by fingerprint"),   "q" },
+    { "search <string>"    ,I18N_NOOP("Search for Certificate on Keyserver"),      "" },
     { "parent-windowid <windowId>",   I18N_NOOP("Parent Window Id for dialogs"),   "" },
     //{ "show-certificate",   I18N_NOOP("Show Certificate(s) by fingerprint(s)"),   ""  },
 };
@@ -283,6 +284,34 @@ int KleopatraApplication::newInstance() {
         return 1;
     }
 
+    // Check for Parent Window id
+    WId parentId = 0;
+    if (args->isSet("parent-windowid")) {
+#ifdef Q_OS_WIN
+        // WId is not a portable type as it is a pointer type on Windows.
+        // casting it from an integer is ok though as the values are guranteed to
+        // be compatible in the documentation.
+        parentId = reinterpret_cast<WId>(args->getOption( "parent-windowid").toUInt());
+#else
+        parentId = args->getOption("parent-windowid").toUInt();
+#endif
+    }
+
+
+    if ( args->isSet("search") ) {
+        const QString needle = args->getOption( "search" );
+        if ( needle.isEmpty() ) {
+          kDebug() << "no search string specified: --query";
+          return 1;
+        }
+        LookupCertificatesCommand * const cmd = new LookupCertificatesCommand( needle, 0 );
+        if ( parentId != 0 ) {
+            cmd->setParentWId( parentId );
+        };
+        cmd->start();
+        return 0;
+    }
+
     // Check for --query command
     if ( args->isSet( "query" ) ) {
         const QString fingerPrint = args->getOption( "query" );
@@ -291,24 +320,11 @@ int KleopatraApplication::newInstance() {
           return 1;
         }
 
-        // Check for Parent Window id
-        WId parentId = 0;
-        if ( args->isSet( "parent-windowid" ) ) {
-#ifdef Q_OS_WIN
-            // WId is not a portable type as it is a pointer type on Windows.
-            // casting it from an integer is ok though as the values are guranteed to
-            // be compatible in the documentation.
-            parentId = reinterpret_cast<WId>( args->getOption( "parent-windowid" ).toUInt() );
-#else
-            parentId = args->getOption( "parent-windowid" ).toUInt();
-#endif
-        }
-
         // Search for local keys
         const GpgME::Key &key = Kleo::KeyCache::instance()->findByKeyIDOrFingerprint( fingerPrint.toLocal8Bit().data() );
         if ( key.isNull() ) {
             // Show external search dialog
-            LookupCertificatesCommand * const cmd = new LookupCertificatesCommand( fingerPrint, 0 );
+            LookupCertificatesCommand *const cmd = new LookupCertificatesCommand(fingerPrint, 0);
             if ( parentId != 0 ) {
                 cmd->setParentWId( parentId );
             };
diff --git a/libkleo/ui/keyselectiondialog.cpp b/libkleo/ui/keyselectiondialog.cpp
index cfa06ff7af..19c81eb40a 100644
--- a/libkleo/ui/keyselectiondialog.cpp
+++ b/libkleo/ui/keyselectiondialog.cpp
@@ -580,13 +580,8 @@ void Kleo::KeySelectionDialog::slotRereadKeys() {
 void Kleo::KeySelectionDialog::slotStartCertificateManager( const QString &query )
 {
   QStringList args;
-  // ### waits for bug 175980 to be fixed, ie. those command line args to be added again
-#if 0
-  // ### port to libkleopatra
   if ( !query.isEmpty() )
-    args << QLatin1String("--external") << QLatin1String("--query") << KUrl::decode_string( query );
-#endif
-  Q_UNUSED( query );
+    args << QLatin1String("--search") << query;
   if( !QProcess::startDetached( QLatin1String("kleopatra"), args ) )
     KMessageBox::error( this,
                         i18n( "Could not start certificate manager; "
-- 
2.14.1