[PATCH] kgpg fix for large keyrings

bj at altern.org bj at altern.org
Wed Dec 3 22:55:55 GMT 2003


Hi.

With large keyrings (~900 keys), KGpg takes several minutes to start up, 
sometimes not starting at all. 

Part of the problem is that at startup, KGpg checks all keys to see if they 
have photo ID's.

With this patch, Photo ID is only checked when user wants to open a key.
I know it's not a one line bug fix, but startup time with a large keyring is 
reduced from several minutes to 4 seconds on my 900 MHz system!!!

So I think this patch should really be committed before KDE 3.2. Any 
objection ?

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	3 Dec 2003 21:43:48 -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();
 }
 
 
@@ -857,7 +854,6 @@
 
 void listKeys::slotUpdatePhoto()
 {
-    checkPhotos();
     keysList2->refreshselfkey();
 }
 
@@ -889,12 +885,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();
     }
 }
@@ -1143,26 +1153,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();
@@ -2403,6 +2393,27 @@
     delete dial;
 }
 
+bool KeyView::keyHasPhoto(QString keyId)
+{
+    bool hasPhoto=false;
+    char line[300];
+    FILE *fp;
+    QString tst;
+    fp = popen("gpg --no-secmem-warning --no-tty --with-colon --list-sigs 
"+QFile::encodeName(keyId), "r");
+    while (fgets( line, sizeof(line), fp))
+    {
+        tst=line;
+        if (tst.startsWith("uat"))
+	{
+        hasPhoto=true;
+	break;
+	}
+    }
+    pclose(fp);
+    return hasPhoto;
+}
+
+
 void KeyView::expandGroup(QListViewItem *item)
 {
 
@@ -2446,7 +2457,7 @@
 
     photoIdList.clear();
 
-    if (photoKeysList.find(item->text(6))!=-1) // contains a photo id
+    if (keyHasPhoto(item->text(6))) // contains a photo id
     {
         KgpgInterface *photoProcess=new KgpgInterface();
         photoProcess->KgpgGetPhotoList(item->text(6));
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	3 Dec 2003 21:43:48 -0000
@@ -133,7 +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;
@@ -143,6 +142,7 @@
 	void slotAddColumn(int c);
 	
 private slots:
+	bool keyHasPhoto(QString keyId);
         void  droppedfile (KURL);
         void refreshkeylist();
         gpgKey extractKey(QString keyColon);
@@ -239,7 +239,6 @@
 	void signLoop();
         void configuretoolbars();
         void saveToolbarConfig();
-        void checkPhotos();
         void slotManpage();
         void slotTip();
         void slotConfigureShortcuts();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kgpg.diff
Type: text/x-diff
Size: 3959 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20031203/b34f3e52/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20031203/b34f3e52/attachment.sig>


More information about the kde-core-devel mailing list