Sorting the keyring by different fields (patch)

Miguel Coca e970095@zipi.fi.upm.es
Fri Oct 19 17:37:02 2001


--hHWLQfXTYDoKhP50
Content-Type: multipart/mixed; boundary="MGYHOYXEY6WxJCY8"
Content-Disposition: inline


--MGYHOYXEY6WxJCY8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

        Hello,

        In the past I've noticed that, by reading mailing lists where PGP
signatures are common, my keyring has been filled with lots of keys. Only a
few of them are really trustworthy, and in GPA there is no easy way to find
them.

        To solve this, I've modified GPA so that you can sort your keyring
by any field you want, including key and owner trust. I attach a patch
against the latest CVS (with ChangeLog entries at the beginning of the file,
as suggested).

        Also, I'd be willing to work on improving GPA, but I don't know what
to do exactly. The TODO file seems a bit out of date. I understand there
would be interest in replacing gpapa with gpgme. I could try to do it, but
it seems to be a major change which I would not attempt without the
developers' permission and advice :-)

        Meanwhile, I'm working on a Spanish translation. Don't count on
getting it soon, though, since there is a whole lot of strings in the
program :-)

        Sincerely,
--=20
Miguel Coca                                         e970095@zipi.fi.upm.es
PGP Key 0x27FC3CA8                         http://zipi.fi.upm.es/~e970095/

--MGYHOYXEY6WxJCY8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=gpa-sort-patch
Content-Transfer-Encoding: quoted-printable

 2001-10-18  Miguel Coca  <e970095@zipi.fi.upm.es>
=20
 	* keylist.c (keylist_clicked_on_column):=20
 	(keylist_compare_rows):=20
 	(keylist_compare_expiry):=20
 	(keylist_compare_ownertrust):=20
 	(keylist_compare_keytrust): Sort the list by a column when that
 	column's title is clicked.
 	(gpa_keylist_new): Added signal handler and sort function to
 	support sorting by different columns.
=20
Index: src/keylist.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/gpa/gpa/src/keylist.c,v
retrieving revision 1.12
diff -r1.12 keylist.c
54c54
<   /* the number and definitins of the currently visible columns */
---

> /* the number, list and definitions of the currently visible columns */
55a56
> GPAKeyListColumn *columns;
69a71,72
> /* Name of the column used to sort the list */
> GPAKeyListColumn sort_column;
81a85,89
> static gint keylist_compare_rows (GtkCList * clist, gconstpointer ptr1,
> gconstpointer ptr2);
> static void keylist_clicked_on_column (GtkCList * clist, int column);
> static gint keylist_compare_keytrust( GpapaKeytrust keytrust1,=20
> GpapaKeytrust keytrust2 );
207a216,335
> /*
> * Sorting
> */
>=20
> static gint keytrust_order[] =3D {3,8,2,1,0,7,5,6,4};
> static gint ownertrust_order[] =3D {2,3,1,0};
>=20
> static gint keylist_compare_keytrust( GpapaKeytrust keytrust1,=20
> GpapaKeytrust keytrust2 )
> {
> return keytrust_order[keytrust1] - keytrust_order[keytrust2];
> }
>=20
> static gint keylist_compare_ownertrust( GpapaOwnertrust ownertrust1,=20
> GpapaOwnertrust ownertrust2 )
> {
> return ownertrust_order[ownertrust1] - ownertrust_order[ownertrust2];
> }
>=20
> static gint keylist_compare_expiry( GDate *expiry1, GDate *expiry2 )
> {
> gint value;
> if( !expiry1 && !expiry2 )
> {
> value =3D 0;
> }
> else if( !expiry1 && expiry2 )
> {
> value =3D 1;
> }
> else if( expiry1 && !expiry2 )
> {
> value =3D -1;
> }
> else
> {
> value =3D g_date_compare( expiry1, expiry2 );
> }
> return value;
> }
>=20
> /* Compare two rows of the list, using the current sort_column */
> gint keylist_compare_rows (GtkCList * clist, gconstpointer ptr1,
> gconstpointer ptr2)
> {
> GPAKeyList * keylist =3D gtk_object_get_data (GTK_OBJECT (clist),
> "gpa_keylist");
> GtkCListRow * row1 =3D ptr1;
> GtkCListRow * row2 =3D ptr2;
> gint value;
> GpapaPublicKey * key1 =3D gpapa_get_public_key_by_ID ( row1->data,
> gpa_callback,
> keylist->window);
> GpapaPublicKey * key2 =3D gpapa_get_public_key_by_ID ( row2->data,
> gpa_callback,
> keylist->window);
> GDate *expiry1, *expiry2;
> GpapaKeytrust keytrust1, keytrust2;
> GpapaOwnertrust ownertrust1, ownertrust2;
>=20
> switch( keylist->sort_column )
> {
> case GPA_KEYLIST_EXPIRYDATE:
> expiry1 =3D gpapa_key_get_expiry_date ( GPAPA_KEY (key1), gpa_callb=
ack,=20
> keylist->window);
> expiry2 =3D gpapa_key_get_expiry_date ( GPAPA_KEY (key2), gpa_callb=
ack,=20
> keylist->window);
> value =3D keylist_compare_expiry( expiry1, expiry2 );
> break;
> case GPA_KEYLIST_KEYTRUST:
> keytrust1 =3D gpapa_public_key_get_keytrust=20
> (key1, gpa_callback, keylist->window);
> keytrust2 =3D gpapa_public_key_get_keytrust
> (key2, gpa_callback, keylist->window);
> value =3D keylist_compare_keytrust( keytrust1, keytrust2 );
> break;
> case GPA_KEYLIST_OWNERTRUST:
> ownertrust1 =3D gpapa_public_key_get_ownertrust=20
> (key1, gpa_callback, keylist->window);
> ownertrust2 =3D gpapa_public_key_get_ownertrust
> (key2, gpa_callback, keylist->window);
> value =3D keylist_compare_ownertrust( ownertrust1, ownertrust2 );
>=20
> break;
> case GPA_KEYLIST_NAME:
> case GPA_KEYLIST_ID:
> default:
> value =3D g_strcasecmp( GTK_CELL_TEXT(row1->cell[clist->sort_column=
])
> ->text,
> GTK_CELL_TEXT(row2->cell[clist->sort_column])
> ->text );
> }
>=20
> return value;
> }
>=20
> /* If the user clicks on a column we sort the list by that column. If the
> * column is the one we are using already, we sort in reverse order. */
> void keylist_clicked_on_column (GtkCList * clist, int column)
> {
> GPAKeyList * keylist =3D gtk_object_get_data (GTK_OBJECT (clist),
> "gpa_keylist");
>=20
> if( keylist->sort_column =3D=3D keylist->columns[column] )
> {
> if( GTK_CLIST(clist)->sort_type =3D=3D GTK_SORT_ASCENDING )
> gtk_clist_set_sort_type(GTK_CLIST (clist), GTK_SORT_DESCENDING);
> else
> gtk_clist_set_sort_type(GTK_CLIST (clist), GTK_SORT_ASCENDING);
> }
> else /* Always sort in ascending order when changing sort column */
> gtk_clist_set_sort_type(GTK_CLIST (clist), GTK_SORT_ASCENDING);
>=20
> keylist->sort_column =3D keylist->columns[column];
> /* This is not absolutely necessary, but we tell the list which column =
we
> are using just in case. Note: Right now it's used by
> keylist_compare_rows in the default case. */
> gtk_clist_set_sort_column (GTK_CLIST (clist), column);
> gtk_clist_sort (GTK_CLIST (clist));
> }
222a351
> keylist->sort_column =3D GPA_KEYLIST_NAME;
224a354,355
> keylist->columns =3D xmalloc (ncolumns * sizeof (columns[0]));
> memcpy( keylist->columns, columns , (ncolumns * sizeof (columns[0])) );
235a367,371
> gtk_signal_connect( GTK_OBJECT (clist), "click_column",
> GTK_SIGNAL_FUNC (keylist_clicked_on_column), NULL);
> gtk_clist_set_compare_func( GTK_CLIST (clist),=20
> (GtkCListCompareFunc) keylist_compare_rows =
);
>=20
326a463
> gtk_clist_sort (GTK_CLIST (keylist->clist));
347c484 < =20 ---
>=20
399a537
> gboolean found_sort_column =3D FALSE;
403a542,543
> keylist->columns =3D xmalloc (ncolumns * sizeof (columns[0]));
> memcpy( keylist->columns, columns , (ncolumns * sizeof (columns[0])) );
407a548,563
> }
>=20
> /* Try to find the column used to sort the list in the definitions */
> for( i =3D 0; i < ncolumns; i++ )
> if( columns[i] =3D=3D keylist->sort_column )
> {
> found_sort_column =3D TRUE;
> gtk_clist_set_sort_column( GTK_CLIST (clist), i );
> }
> /* If the old sort solumn is not found use the default (the last one,
> * that usually is the user name */
> if( !found_sort_column )
> {
> keylist->sort_column =3D columns[ncolumns-1];
> gtk_clist_set_sort_column( GTK_CLIST (clist), ncolumns-1 );
> gtk_clist_set_sort_type(GTK_CLIST (clist), GTK_SORT_ASCENDING);
--MGYHOYXEY6WxJCY8-- --hHWLQfXTYDoKhP50 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE70EhVjE3Htif8PKgRAvk9AKDMj9Y9fOKL1nRM5i7NdYulmlfuNgCfU4py 28XxXc5+uJZTWPftXma5YjA= =ZasN -----END PGP SIGNATURE----- --hHWLQfXTYDoKhP50--