summaryrefslogtreecommitdiffstats
path: root/kgpg/kgpg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kgpg/kgpg.cpp')
-rw-r--r--kgpg/kgpg.cpp129
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 : bj@altern.org
+
+ updated to handle gpg21 : Sun Jul 30 10:18:29 CEST 2017
+ copyright : (C) 2017 by Emanoil Kotsev
+ email : deloptes@yahoo.com
***************************************************************************/
/***************************************************************************
@@ -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);
}
}