[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] kgpg fix for large keyrings
From:       bj () altern ! org
Date:       2003-12-04 12:21:00
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hello !

I've been thinking again on this patch to speed up KGpg startup time and came 
up with a much better version, which keeps the start up optimisation and 
makes opening a key twice as fast as before. (it was all related to how photo 
id's are detected/treated).

Please review the attached patch...

["kgpgbis.diff" (text/x-diff)]

Index: listkeys.cpp
===================================================================
RCS file: /home/kde/kdeutils/kgpg/listkeys.cpp,v
retrieving revision 1.162
diff -u -3 -r1.162 listkeys.cpp
--- listkeys.cpp	27 Nov 2003 11:11:23 -0000	1.162
+++ listkeys.cpp	4 Dec 2003 12:13:03 -0000
@@ -508,8 +508,6 @@
 {
     //KWin::setType(Qt::WDestructiveClose);
     keysList2 = new KeyView(this);
-    keysList2->photoKeysList=QString::null;
-
 
     setAutoSaveSettings();
     readOptions();
@@ -664,7 +662,6 @@
 
     if (!KGpgSettings::showToolbar())
         toolBar()->hide();
-    checkPhotos();
 }
 
 
@@ -794,6 +791,7 @@
     *conprocess<<"-e"<<"gpg";
     *conprocess<<"--edit-key"<<item->text(6)<<"uid";
     conprocess->start(KProcess::Block);
+    keysList2->refreshselfkey();
 }
 
 
@@ -857,7 +855,6 @@
 
 void listKeys::slotUpdatePhoto()
 {
-    checkPhotos();
     keysList2->refreshselfkey();
 }
 
@@ -889,12 +886,26 @@
     QListViewItem *newdef = keysList2->firstChild();
     while (newdef)
     {
-        if ((keysList2->photoKeysList.find(newdef->text(6))!=-1) && \
                (newdef->childCount ()>0))
-        {
+	if (newdef->childCount ()>0)
+	{
+	bool hasphoto=false;
+	QListViewItem *newdefChild = newdef->firstChild();
+	while (newdefChild)
+	{
+	if (newdefChild->text(0)==i18n("Photo id"))
+	{
+	hasphoto=true;
+	break;
+	}
+	newdefChild = newdefChild->nextSibling();
+	}
+        if (hasphoto)
+	{
             while (newdef->firstChild())
                 delete newdef->firstChild();
             keysList2->expandKey(newdef);
         }
+	}
         newdef = newdef->nextSibling();
     }
 }
@@ -1077,13 +1088,13 @@
         QString email;
         QStringList keylist;
         KABC::Addressee a;
- 
+
         KABC::AddressBook *ab = KABC::StdAddressBook::self();
         if ( !ab->load() ) {
                 KMessageBox::sorry(this,i18n("Unable to contact the address book. \
Please check your installation."));  return;
         }
- 
+
         QListViewItem * myChild = keysList2->firstChild();
         while( myChild ) {
                 //email=extractKeyMail(myChild).stripWhiteSpace();
@@ -1143,26 +1154,6 @@
 }
 
 
-
-void listKeys::checkPhotos()
-{
-    keysList2->photoKeysList=QString::null;
-    char line[300];
-    FILE *fp;
-    QString tst;
-    QString tstID;
-    fp = popen("gpg --no-secmem-warning --no-tty --with-colon --list-sigs", "r");
-    while ( fgets( line, sizeof(line), fp))
-    {
-        tst=line;
-        if (tst.startsWith("pub"))
-            tstID=QString("0x"+tst.section(':',4,4).right(8));
-        if (tst.startsWith("uat"))
-            keysList2->photoKeysList+=tstID;
-    }
-    pclose(fp);
-}
-
 void listKeys::checkList()
 {
     QPtrList<QListViewItem> exportList=keysList2->selectedItems();
@@ -1537,7 +1528,7 @@
     KService::Ptr ptr = offers.first();
     //KMessageBox::sorry(0,ptr->desktopEntryName());
     KProcIO *p=new KProcIO();
-    *p<<"gpg"<<"--no-tty"<<"--photo-viewer"<<QFile::encodeName(ptr->desktopEntryName()+" \
%i")<<"--edit-key"<<keysList2->currentItem()->parent()->text(6)<<"uid"<<keysList2->currentItem()->text(6)<<"showphoto";
 +    *p<<"gpg"<<"--no-tty"<<"--photo-viewer"<<QFile::encodeName(ptr->desktopEntryName()+" \
%i")<<"--edit-key"<<keysList2->currentItem()->parent()->text(6)<<"uid"<<keysList2->currentItem()->text(6)<<"showphoto"<<"quit";
  p->start(KProcess::DontCare,true);
 }
 
@@ -2403,6 +2394,7 @@
     delete dial;
 }
 
+
 void KeyView::expandGroup(QListViewItem *item)
 {
 
@@ -2437,34 +2429,11 @@
     return dup2;
 }
 
-
 void KeyView::expandKey(QListViewItem *item)
 {
-    //kdDebug()<<"Expanding Key"<<endl;
     if (item->childCount()!=0)
         return;   // key has already been expanded
 
-    photoIdList.clear();
-
-    if (photoKeysList.find(item->text(6))!=-1) // contains a photo id
-    {
-        KgpgInterface *photoProcess=new KgpgInterface();
-        photoProcess->KgpgGetPhotoList(item->text(6));
-        itemToOpen=item;
-        connect(photoProcess,SIGNAL(signalPhotoList(QStringList)),this,SLOT(slotSetPhotoId(QStringList)));
                
-    }
-    else
-        expandKey2(item);
-}
-
-void KeyView::slotSetPhotoId(QStringList list)
-{
-    photoIdList=list;
-    expandKey2(itemToOpen);
-}
-
-void KeyView::expandKey2(QListViewItem *item)
-{
     FILE *fp;
     QString cycle;
     QStringList tst;
@@ -2474,7 +2443,7 @@
     SmallViewItem *itemsig=NULL;
     SmallViewItem *itemrev=NULL;
     QPixmap keyPhotoId;
-    int uidNumber=0;
+    int uidNumber=2;
     bool dropFirstUid=false;
 
     kdDebug()<<"Expanding Key: "<<item->text(6)<<endl;
@@ -2486,6 +2455,9 @@
     while ( fgets( line, sizeof(line), fp))
     {
         tst=QStringList::split(":",line,true);
+	if ((tst[0]=="pub") && (tst[9].isEmpty())) /// Primary User Id is separated from \
public key + 	uidNumber=1;
+	
         if (tst[0]=="uid" || tst[0]=="uat")
         {
             if (dropFirstUid)
@@ -2498,17 +2470,15 @@
 
                 if (tst[0]=="uat")
                 {
-                    QString photoUid=QString(*photoIdList.begin());
-                    itemuid= new SmallViewItem(item,i18n("Photo \
                id"),QString::null,QString::null,"-","-","-",photoUid);
-                    photoIdList.remove(photoIdList.begin());
+                    itemuid= new SmallViewItem(item,i18n("Photo \
id"),QString::null,QString::null,"-","-","-",QString::number(uidNumber));  if \
(displayPhoto)  {
                         kgpgphototmp=new KTempFile();
                         kgpgphototmp->setAutoDelete(true);
                         QString pgpgOutput="cp %i "+kgpgphototmp->name();
                         KProcIO *p=new KProcIO();
-                        \
*p<<"gpg"<<"--no-tty"<<"--show-photos"<<"--photo-viewer"<<QFile::encodeName(pgpgOutput);
                
-                        \
*p<<"--edit-key"<<item->text(6)<<"uid"<<photoUid<<"showphoto"; +                      \
*p<<"gpg"<<"--no-tty"<<"--photo-viewer"<<QFile::encodeName(pgpgOutput); +             \
*p<<"--edit-key"<<item->text(6)<<"uid"<<QString::number(uidNumber)<<"showphoto"<<"quit";
  p->start(KProcess::Block);
 
                         QPixmap pixmap;
@@ -2523,7 +2493,6 @@
                     else
                         itemuid->setPixmap(0,pixuserphoto);
                     itemuid->setPixmap(2,uidKey.trustpic);
-                    uidNumber++;
                     cycle="uid";
                 }
                 else
@@ -2540,6 +2509,7 @@
                     cycle="uid";
                 }
             }
+	    uidNumber++;
         }
         else
             if (tst[0]=="rev")
Index: listkeys.h
===================================================================
RCS file: /home/kde/kdeutils/kgpg/listkeys.h,v
retrieving revision 1.73
diff -u -3 -r1.73 listkeys.h
--- listkeys.h	1 Nov 2003 19:31:20 -0000	1.73
+++ listkeys.h	4 Dec 2003 12:13:04 -0000
@@ -133,8 +133,6 @@
 private:
 //        bool displayMailFirst;
         QString secretList;
-        QString photoKeysList;
-	QStringList photoIdList;
         QPixmap pixkeyPair,pixkeySingle,pixkeyGroup,pixsignature,pixuserid,pixuserphoto,trustunknown,trustmarginal, \
trustbad, trustgood,pixRevoke;  QListViewItem *itemToOpen;
 	KTempFile *kgpgphototmp;
@@ -147,14 +145,12 @@
         void refreshkeylist();
         gpgKey extractKey(QString keyColon);
         void expandKey(QListViewItem *item);
-	void expandKey2(QListViewItem *item);
 	void expandGroup(QListViewItem *item);
         void refreshcurrentkey(QListViewItem *current);
 	void refreshcurrentkey(QString currentID);
 	void refreshselfkey();
 	void refreshgroups();
 	QPixmap slotGetPhoto(QString photoId,bool mini=false);
-	void slotSetPhotoId(QStringList list);
 	void slotReloadKeys(QStringList keyIDs);
 
 protected:
@@ -239,7 +235,6 @@
 	void signLoop();
         void configuretoolbars();
         void saveToolbarConfig();
-        void checkPhotos();
         void slotManpage();
         void slotTip();
         void slotConfigureShortcuts();


[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic