summaryrefslogtreecommitdiffstats
path: root/kgpg/keyinfowidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kgpg/keyinfowidget.cpp')
-rw-r--r--kgpg/keyinfowidget.cpp292
1 files changed, 183 insertions, 109 deletions
diff --git a/kgpg/keyinfowidget.cpp b/kgpg/keyinfowidget.cpp
index 1de61af..1b833ac 100644
--- a/kgpg/keyinfowidget.cpp
+++ b/kgpg/keyinfowidget.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
***************************************************************************/
/***************************************************************************
@@ -90,36 +94,56 @@ KgpgKeyInfo::KgpgKeyInfo(TQWidget *parent, const char *name,TQString sigkey):KDi
void KgpgKeyInfo::slotDisableKey(bool isOn)
{
-TDEProcess kp;
-
- kp<<"gpg"
- <<"--no-tty"
- <<"--edit-key"
- <<displayedKeyID;
-if (isOn) kp<<"disable";
-else kp<<"enable";
+// kdDebug(2100) << k_funcinfo << endl;
+ TDEProcess kp;
+
+ kp<<"gpg" <<"--no-tty" <<"--edit-key" <<displayedKeyID;
+ if (isOn) kp<<"disable";
+ else kp<<"enable";
kp<<"save";
- kp.start(TDEProcess::Block);
-loadKey(displayedKeyID);
-keyWasChanged=true;
+ kp.start(TDEProcess::Block);
+ loadKey(displayedKeyID);
+ keyWasChanged=true;
}
void KgpgKeyInfo::loadKey(TQString Keyid)
{
-TQColor trustColor;
-TQString fingervalue=TQString();
-FILE *pass;
-char line[200]="";
-TQString gpgOutput,fullID;
-
-TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprint --list-key "+KShellProcess::quote(Keyid);
-
- pass=popen(TQFile::encodeName(gpgcmd),"r");
- while ( fgets( line, sizeof(line), pass)) {
- gpgOutput=TQString::fromUtf8(line);
- if (gpgOutput.startsWith("uat"))
- hasPhoto=true;
- if (gpgOutput.startsWith("pub")) {
+// kdDebug(2100) << k_funcinfo << endl;
+ FILE *pass;
+ char line[200]="";
+ TQString currentKey;
+ TQMap<TQString,TQStringList> hashMap;
+
+ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprint --list-key "+KShellProcess::quote(Keyid);
+
+ pass=popen(TQFile::encodeName(gpgcmd),"r");
+ while ( fgets( line, sizeof(line), pass) ) {
+ TQString tst=TQString::fromUtf8(line);
+ if ( tst.startsWith("pub") ) {
+ currentKey = tst.section(':',4,4);
+ TQStringList lst; lst << tst;
+ hashMap.insert(currentKey,lst);
+ }
+ else {
+ hashMap.find(currentKey).data().append(tst);
+ }
+ }
+ pclose(pass);
+
+ TQMap<TQString,TQStringList>::Iterator ite;
+ for (ite = hashMap.begin(); ite != hashMap.end(); ite++) {
+ TQStringList::Iterator it;
+ TQString fullname,gpgOutput;
+ TQColor trustColor;
+ TQString fingervalue=TQString();
+
+ for (it = ite.data().begin(); it != ite.data().end(); it++) {
+ TQString gpgOutput = (*it);
+
+ if (gpgOutput.startsWith("uat")) {
+ hasPhoto=true;
+ }
+ if ( gpgOutput.startsWith("pub") ) {
TQString algo=gpgOutput.section(':',3,3);
switch( algo.toInt() ) {
case 1:
@@ -198,21 +222,39 @@ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprin
prop->kLTrust->setText(tr);
prop->pixmapTrust->setPaletteBackgroundColor(trustColor);
- fullID=gpgOutput.section(':',4,4);
- displayedKeyID=fullID.right(8);
- prop->tLID->setText(fullID);
+ TQString fullID=gpgOutput.section(':',4,4);
+ displayedKeyID=fullID.right(8);
+ prop->tLID->setText(fullID);
- TQString fullname=gpgOutput.section(':',9,9);
+ fullname=gpgOutput.section(':',9,9);
- TQDate date = TQDate::fromString(gpgOutput.section(':',5,5), Qt::ISODate);
- prop->tLCreation->setText(TDEGlobal::locale()->formatDate(date));
+ TQDate date;
+ if (KgpgInterface::getGpgVersion() >= 210 ) {
+ TQDateTime timestamp;
+ timestamp.setTime_t(gpgOutput.section(':',5,5).toInt());
+ date = timestamp.date();
+ }
+ else {
+ date = TQDate::fromString(gpgOutput.section(':',5,5), Qt::ISODate);
+ }
+ Q_ASSERT ( date.isValid())/* tqWarning("create date is not valid")*/;
- if (gpgOutput.section(':',6,6).isEmpty()) expirationDate=i18n("Unlimited");
- else
- {
- date = TQDate::fromString(gpgOutput.section(':',6,6), Qt::ISODate);
- expirationDate=TDEGlobal::locale()->formatDate(date);
- }
+ prop->tLCreation->setText(TDEGlobal::locale()->formatDate(date));
+ if (gpgOutput.section(':',6,6).isEmpty()) {
+ expirationDate=i18n("Unlimited");
+ }
+ else {
+ if (KgpgInterface::getGpgVersion() >= 210 ) {
+ TQDateTime timestamp;
+ timestamp.setTime_t(gpgOutput.section(':',6,6).toInt());
+ date = timestamp.date();
+ }
+ else {
+ date = TQDate::fromString(gpgOutput.section(':',6,6), Qt::ISODate);
+ }
+ Q_ASSERT (date.isValid()) /* tqWarning("Expirationdate date is not valid")*/;
+ expirationDate=TDEGlobal::locale()->formatDate(date);
+ }
prop->tLExpiration->setText(expirationDate);
prop->tLLength->setText(gpgOutput.section(':',2,2));
@@ -240,7 +282,25 @@ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprin
break;
}
prop->kCOwnerTrust->setCurrentItem(ownerTrust);
+ }
+
+ if ( gpgOutput.startsWith("uid") && fullname.isEmpty() ) {
+ fullname = gpgOutput.section(':',9,9);
+ }
+ if (gpgOutput.startsWith("fpr") && (fingervalue.isNull())) {
+ fingervalue=gpgOutput.section(':',9,9);
+ // format fingervalue in 4-digit groups
+ uint len = fingervalue.length();
+ if ((len > 0) && (len % 4 == 0)) {
+ for (uint n = 0; 4*(n+1) < len; n++) {
+ fingervalue.insert(5*n+4, ' ');
+ }
+ }
+ prop->lEFinger->setText(fingervalue);
+ }
+ }
+ if (!fullname.isEmpty()) {
if (fullname.find("<")!=-1) {
TQString kmail=fullname;
if (fullname.find(")")!=-1)
@@ -266,29 +326,20 @@ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprin
prop->tLComment->setText(i18n("none"));
prop->tLName->setText("<qt><b>"+KgpgInterface::checkForUtf8(kname).replace(TQRegExp("<"),"&lt;")+"</b></qt>");
-
- }
- if (gpgOutput.startsWith("fpr") && (fingervalue.isNull())) {
- fingervalue=gpgOutput.section(':',9,9);
- // format fingervalue in 4-digit groups
- uint len = fingervalue.length();
- if ((len > 0) && (len % 4 == 0))
- for (uint n = 0; 4*(n+1) < len; n++)
- fingervalue.insert(5*n+4, ' ');
- prop->lEFinger->setText(fingervalue);
}
}
- pclose(pass);
}
void KgpgKeyInfo::slotSetMainPhoto(TQStringList list)
{
+// kdDebug(2100) << k_funcinfo << endl;
prop->comboId->insertStringList(list);
reloadMainPhoto(prop->comboId->currentText());
}
void KgpgKeyInfo::reloadMainPhoto(const TQString &uid)
{
+// kdDebug(2100) << k_funcinfo << endl;
kgpginfotmp=new KTempFile();
kgpginfotmp->setAutoDelete(true);
@@ -305,6 +356,7 @@ void KgpgKeyInfo::reloadMainPhoto(const TQString &uid)
void KgpgKeyInfo::slotMainImageRead(TDEProcess *p)
{
+// kdDebug(2100) << k_funcinfo << endl;
p->deleteLater();
TQPixmap pixmap;
pixmap.load(kgpginfotmp->name());
@@ -319,10 +371,11 @@ KgpgKeyInfo::~KgpgKeyInfo()
void KgpgKeyInfo::slotSetPhoto(const TQPixmap &pix)
{
-TQImage dup=pix.convertToImage();
-TQPixmap dup2;
-dup2.convertFromImage(dup.scale(prop->pLPhoto->width(),prop->pLPhoto->height(),TQ_ScaleMin));
-prop->pLPhoto->setPixmap(dup2);
+// kdDebug(2100) << k_funcinfo << endl;
+ TQImage dup=pix.convertToImage();
+ TQPixmap dup2;
+ dup2.convertFromImage(dup.scale(prop->pLPhoto->width(),prop->pLPhoto->height(),TQ_ScaleMin));
+ prop->pLPhoto->setPixmap(dup2);
}
@@ -330,6 +383,7 @@ prop->pLPhoto->setPixmap(dup2);
void KgpgKeyInfo::finishphotoreadprocess(KProcIO *p)
{
+// kdDebug(2100) << k_funcinfo << endl;
TQString required=TQString();
while (p->readln(required,true)!=-1)
if (required.find("keyedit.prompt")!=-1) {
@@ -342,6 +396,7 @@ void KgpgKeyInfo::finishphotoreadprocess(KProcIO *p)
void KgpgKeyInfo::openPhoto()
{
+// kdDebug(2100) << k_funcinfo << endl;
TDETrader::OfferList offers = TDETrader::self()->query("image/jpeg", "Type == 'Application'");
KService::Ptr ptr = offers.first();
//KMessageBox::sorry(0,ptr->desktopEntryName());
@@ -352,61 +407,69 @@ void KgpgKeyInfo::openPhoto()
void KgpgKeyInfo::slotChangeExp()
{
-chdate=new KDialogBase( this, "choose_date", true,i18n("Choose New Expiration"),KDialogBase::Ok | KDialogBase::Cancel);
-TQWidget *page = new TQWidget(chdate);
-kb= new TQCheckBox(i18n("Unlimited"),page );
-
-if (prop->tLExpiration->text()==i18n("Unlimited"))
-{
-kdt= new KDatePicker( page );
-kb->setChecked(true);
-kdt->setEnabled(false);
-}
-else
-kdt= new KDatePicker(page,TDEGlobal::locale()->readDate(prop->tLExpiration->text()));
-TQVBoxLayout *vbox=new TQVBoxLayout(page,3);
-vbox->addWidget(kdt);
-vbox->addWidget(kb);
-connect(kb,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableDate(bool)));
-connect(chdate,TQT_SIGNAL(okClicked()),this,TQT_SLOT(slotChangeDate()));
-connect(kdt,TQT_SIGNAL(dateChanged(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate)));
-connect(kdt,TQT_SIGNAL(dateEntered(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate)));
-
-chdate->setMainWidget(page);
-chdate->show();
+// kdDebug(2100) << k_funcinfo << endl;
+ chdate=new KDialogBase( this, "choose_date", true,i18n("Choose New Expiration"),KDialogBase::Ok | KDialogBase::Cancel);
+ TQWidget *page = new TQWidget(chdate);
+ kb= new TQCheckBox(i18n("Unlimited"),page );
+
+ if (prop->tLExpiration->text()==i18n("Unlimited")) {
+ kdt= new KDatePicker( page );
+ kb->setChecked(true);
+ kdt->setEnabled(false);
+ }
+ else {
+ kdt= new KDatePicker(page,TDEGlobal::locale()->readDate(prop->tLExpiration->text()));
+ }
+ TQVBoxLayout *vbox=new TQVBoxLayout(page,3);
+ vbox->addWidget(kdt);
+ vbox->addWidget(kb);
+ connect(kb,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableDate(bool)));
+ connect(chdate,TQT_SIGNAL(okClicked()),this,TQT_SLOT(slotChangeDate()));
+ connect(kdt,TQT_SIGNAL(dateChanged(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate)));
+ connect(kdt,TQT_SIGNAL(dateEntered(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate)));
+
+ chdate->setMainWidget(page);
+ chdate->show();
}
void KgpgKeyInfo::slotCheckDate(TQDate date)
{
-chdate->enableButtonOK(date>=TQDate::currentDate ());
+// kdDebug(2100) << k_funcinfo << endl;
+// kdDebug(2100) << "slotCheckDate" << date<<endl;
+ chdate->enableButtonOK(date>=TQDate::currentDate ());
}
void KgpgKeyInfo::slotChangeDate()
{
-KgpgInterface *KeyExpirationProcess=new KgpgInterface();
- if (kb->isChecked())
- KeyExpirationProcess->KgpgKeyExpire(displayedKeyID,TQDate::currentDate(),true);
- else
+// kdDebug(2100) << k_funcinfo << endl;
+ KgpgInterface *KeyExpirationProcess=new KgpgInterface();
+// kdDebug(2100) << "slotChangeDate" << kdt->date()<<endl;
+ if (kb->isChecked()) {
+ KeyExpirationProcess->KgpgKeyExpire(displayedKeyID,TQDate::currentDate(),true);
+ }
+ else {
KeyExpirationProcess->KgpgKeyExpire(displayedKeyID,kdt->date(),false);
- connect(KeyExpirationProcess,TQT_SIGNAL(expirationFinished(int)),this,TQT_SLOT(slotInfoExpirationChanged(int)));
+ }
+ connect(KeyExpirationProcess,TQT_SIGNAL(expirationFinished(int)),this,TQT_SLOT(slotInfoExpirationChanged(int)));
}
void KgpgKeyInfo::slotEnableDate(bool isOn)
{
-if (isOn)
-{
-kdt->setEnabled(false);
-chdate->enableButtonOK(true);
-}
-else
-{
-kdt->setEnabled(true);
-chdate->enableButtonOK(kdt->date()>=TQDate::currentDate ());
-}
+// kdDebug(2100) << k_funcinfo << endl;
+ if (isOn) {
+ kdt->setEnabled(false);
+ chdate->enableButtonOK(true);
+ }
+ else {
+ kdt->setEnabled(true);
+ //kdDebug(2100) << "slotEnableDate" << kdt->date()<<endl;
+ chdate->enableButtonOK(kdt->date()>=TQDate::currentDate ());
+ }
}
void KgpgKeyInfo::slotinfoimgread(TDEProcess *)
{
+// kdDebug(2100) << k_funcinfo << endl;
TQPixmap pixmap;
pixmap.load(kgpginfotmp->name());
emit signalPhotoId(pixmap);
@@ -415,13 +478,15 @@ void KgpgKeyInfo::slotinfoimgread(TDEProcess *)
void KgpgKeyInfo::slotChangePass()
{
- KgpgInterface *ChangeKeyPassProcess=new KgpgInterface();
- ChangeKeyPassProcess->KgpgChangePass(displayedKeyID);
+// kdDebug(2100) << k_funcinfo << endl;
+ KgpgInterface *ChangeKeyPassProcess=new KgpgInterface();
+ ChangeKeyPassProcess->KgpgChangePass(displayedKeyID);
connect(ChangeKeyPassProcess,TQT_SIGNAL(passwordChanged()),this,TQT_SLOT(slotInfoPasswordChanged()));
}
void KgpgKeyInfo::slotChangeTrust(int newTrust)
{
+// kdDebug(2100) << k_funcinfo << endl;
KgpgInterface *KeyTrustProcess=new KgpgInterface();
KeyTrustProcess->KgpgTrustExpire(displayedKeyID,newTrust);
connect(KeyTrustProcess,TQT_SIGNAL(trustfinished()),this,TQT_SLOT(slotInfoTrustChanged()));
@@ -430,36 +495,45 @@ void KgpgKeyInfo::slotChangeTrust(int newTrust)
void KgpgKeyInfo::slotInfoPasswordChanged()
{
-KPassivePopup::message(i18n("Passphrase for the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this);
+// kdDebug(2100) << k_funcinfo << endl;
+ KPassivePopup::message(i18n("Passphrase for the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this);
}
void KgpgKeyInfo::slotInfoTrustChanged()
{
-keyWasChanged=true;
-loadKey(displayedKeyID);
-//KPassivePopup::message(i18n("Owner trust of the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this,0,600);
+ keyWasChanged=true;
+ loadKey(displayedKeyID);
+ //KPassivePopup::message(i18n("Owner trust of the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this,0,600);
}
void KgpgKeyInfo::slotInfoExpirationChanged(int res)
{
-TQString infoMessage,infoText;
-if (res==3)
-{
-keyWasChanged=true;
-if (kb->isChecked()) prop->tLExpiration->setText(i18n("Unlimited"));
-else prop->tLExpiration->setText(TDEGlobal::locale()->formatDate(kdt->date()));
-}
-if (res==2) {
-infoMessage=i18n("Could not change expiration");infoText=i18n("Bad passphrase");
-KPassivePopup::message(infoMessage,infoText,TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this);
-}
+// kdDebug(2100) << k_funcinfo << endl;
+ TQString infoMessage,infoText;
+ if (res==3) {
+ keyWasChanged=true;
+ if (kb->isChecked()) {
+ prop->tLExpiration->setText(i18n("Unlimited"));
+ }
+ else {
+ prop->tLExpiration->setText(TDEGlobal::locale()->formatDate(kdt->date()));
+ }
+ }
+ if (res==2) {
+ infoMessage=i18n("Could not change expiration");
+ infoText=i18n("Bad passphrase");
+ KPassivePopup::message(infoMessage,infoText,TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this);
+ }
}
void KgpgKeyInfo::slotPreOk()
{
-if (keyWasChanged) emit keyNeedsRefresh();
-accept();
+// kdDebug(2100) << k_funcinfo << endl;
+ if (keyWasChanged) {
+ emit keyNeedsRefresh();
+ }
+ accept();
}
#include "keyinfowidget.moc"