diff options
author | Emanoil Kotsev <[email protected]> | 2017-12-09 15:54:36 +0100 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2017-12-09 16:02:55 +0100 |
commit | e2bee02e9917c7407de600d7d577cd536e281b4a (patch) | |
tree | 88fcf0746895aa267bd4268d66abc584267f1965 /kgpg/kgpg.cpp | |
parent | e2a62bdbfbe2ddfb9a3ffc37a9bfba158767480e (diff) | |
download | tdeutils-e2bee02e9917c7407de600d7d577cd536e281b4a.tar.gz tdeutils-e2bee02e9917c7407de600d7d577cd536e281b4a.zip |
Add support for GnuPG 2.1
This resolves Bug 2791
Sort keys by name on export
Fix the twice display of the default key server
Signed-off-by: Emanoil Kotsev <[email protected]>
Additional formatting adjustments
Signed-off-by: Slávek Banko <[email protected]>
(cherry picked from commit 9125ead96055376ab2b48f8b5780524c0ee244ac)
Diffstat (limited to 'kgpg/kgpg.cpp')
-rw-r--r-- | kgpg/kgpg.cpp | 129 |
1 files changed, 95 insertions, 34 deletions
diff --git a/kgpg/kgpg.cpp b/kgpg/kgpg.cpp index c711e3a..0d7acd2 100644 --- a/kgpg/kgpg.cpp +++ b/kgpg/kgpg.cpp @@ -4,6 +4,10 @@ begin : Mon Nov 18 2002 copyright : (C) 2002 by Jean-Baptiste Mardelle email : [email protected] + + updated to handle gpg21 : Sun Jul 30 10:18:29 CEST 2017 + copyright : (C) 2017 by Emanoil Kotsev + email : [email protected] ***************************************************************************/ /*************************************************************************** @@ -174,7 +178,7 @@ compressionScheme=cp; void MyView::startFolderEncode(TQStringList selec,TQStringList encryptOptions,bool ,bool symetric) { -TQString extension; +TQString extension=""; if (compressionScheme==0) extension=".zip"; @@ -646,33 +650,65 @@ void MyView::startWizard() wiz->kURLRequester2->setMode(2);*/ FILE *fp,*fp2; - TQString tst,tst2,name,trustedvals="idre-"; + TQString trustedvals="idre-"; TQString firstKey=TQString(); char line[300]; bool counter=false; + TQString currentKey; + TQMap<TQString,TQStringList> hashMap; fp = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-secret-keys", "r"); while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - if (tst.startsWith("sec")) { - name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); - if (!name.isEmpty()) { - fp2 = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-keys "+TQFile::encodeName(tst.section(':',4,4)), "r"); - while ( fgets( line, sizeof(line), fp2)) { - tst2=TQString::fromUtf8(line); - if (tst2.startsWith("pub") && (trustedvals.find(tst2.section(':',1,1))==-1)) { - counter=true; - wiz->CBdefault->insertItem(tst.section(':',4,4).right(8)+": "+name); - if (firstKey.isEmpty()) - firstKey=tst.section(':',4,4).right(8)+": "+name; - break; - } - } - pclose(fp2); - } - } - } - pclose(fp); + TQString tst=TQString::fromUtf8(line); + kdDebug(2100) << k_funcinfo << "Read one secret key line: " << tst << endl; + if ( tst.startsWith("sec") ) { + currentKey = tst.section(':',4,4); + TQStringList lst; lst << tst; + hashMap.insert(currentKey,lst); + } + else { + hashMap.find(currentKey).data().append(tst); + } + } + pclose(fp); + + TQMap<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TDEListViewItem *item; + TQStringList::Iterator it; + + TQString name,id; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + if (tst.startsWith("sec") ) { + if ( KgpgInterface::getGpgVersion() < 210) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + id = tst.section(':',4,4); + } + if ( tst.startsWith("uid") && KgpgInterface::getGpgVersion() >= 210 ) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + } + + if (!name.isEmpty()) { + fp2 = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-keys "+TQFile::encodeName(id), "r"); + while ( fgets( line, sizeof(line), fp2)) { + TQString tst2=TQString::fromUtf8(line); + if (tst2.startsWith("pub") && (trustedvals.find(tst2.section(':',1,1))==-1)) { + counter=true; + wiz->CBdefault->insertItem(id.right(8)+": "+name); + if (firstKey.isEmpty()) { + firstKey=id.right(8)+": "+name; + } + break; + } + } + pclose(fp2); + } + } + wiz->CBdefault->setCurrentItem(firstKey); //connect(wiz->pushButton4,TQT_SIGNAL(clicked()),TQT_TQOBJECT(this),TQT_SLOT(slotGenKey())); if (!counter) @@ -692,23 +728,48 @@ void MyView::startWizard() void MyView::slotWizardChange() { - TQString tst,name; - char line[300]; - FILE *fp; if (wiz->indexOf(wiz->currentPage())==2) { TQString defaultID=KgpgInterface::getGpgSetting("default-key",wiz->kURLRequester1->url()); if (defaultID.isEmpty()) return; - fp = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-secret-keys "+TQFile::encodeName(defaultID), "r"); - while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - if (tst.startsWith("sec")) { - name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); - wiz->CBdefault->setCurrentItem(tst.section(':',4,4).right(8)+": "+name); - } - } - pclose(fp); + + char line[300]; + FILE *fp; + TQString id, name, currentKey; + TQMap<TQString,TQStringList> hashMap; + fp = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-secret-keys "+TQFile::encodeName(defaultID), "r"); + while ( fgets( line, sizeof(line), fp)) { + TQString tst=TQString::fromUtf8(line); + kdDebug(2100) << k_funcinfo << "Read one secret key line: " << tst << endl; + if ( tst.startsWith("sec") ) { + currentKey = tst.section(':',4,4); + TQStringList lst; lst << tst; + hashMap.insert(currentKey,lst); + } + else { + hashMap.find(currentKey).data().append(tst); + } + } + pclose(fp); + + TQMap<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + for (TQStringList::Iterator it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + tst=TQString::fromUtf8(line); + if ( tst.startsWith("sec") ) { + if (KgpgInterface::getGpgVersion() < 210) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + id=tst.section(':',4,4).right(8); + } + if ( (tst.startsWith("uid") && KgpgInterface::getGpgVersion() >= 210) ) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + } + } + wiz->CBdefault->setCurrentItem(id+": "+name); } } |