[Winpt-commits] r139 - trunk/Src
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Wed Jan 11 13:19:42 CET 2006
Author: twoaday
Date: 2006-01-11 13:19:41 +0100 (Wed, 11 Jan 2006)
New Revision: 139
Modified:
trunk/Src/ChangeLog
trunk/Src/wptGPGPrefsDlg.cpp
trunk/Src/wptKeyManagerDlg.cpp
trunk/Src/wptKeysigDlg.cpp
trunk/Src/wptListView.cpp
trunk/Src/wptMainProc.cpp
trunk/Src/wptSigList.cpp
Log:
2006-01-10 Timo Schulz <ts at g10code.com>
* wptMainProc.cpp (winpt_main_proc): Restore iconic
File/Key Manager windows if needed.
* wptGPGPrefsDlg.cpp (gpg_prefs_dlg_proc): Disable button.
* wptSiglist.cpp (init_cmp): New.
(siglist_sort): New.
(siglist_cmp_cb): New.
(siglist_add_key): Force NOKEY status when key was not found.
* wptKeysigDlg.cpp (recv_single_key): New.
(recv_missing_keys): Reload entire key when more than one key
was fetched.
(keysig_dlg_proc): Support sorting the listview items.
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/ChangeLog 2006-01-11 12:19:41 UTC (rev 139)
@@ -1,3 +1,17 @@
+2006-01-10 Timo Schulz <ts at g10code.com>
+
+ * wptMainProc.cpp (winpt_main_proc): Restore iconic
+ File/Key Manager windows if needed.
+ * wptGPGPrefsDlg.cpp (gpg_prefs_dlg_proc): Disable button.
+ * wptSiglist.cpp (init_cmp): New.
+ (siglist_sort): New.
+ (siglist_cmp_cb): New.
+ (siglist_add_key): Force NOKEY status when key was not found.
+ * wptKeysigDlg.cpp (recv_single_key): New.
+ (recv_missing_keys): Reload entire key when more than one key
+ was fetched.
+ (keysig_dlg_proc): Support sorting the listview items.
+
2006-01-09 Timo Schulz <ts at g10code.com>
* WinPT.cpp (load_gettext): Remove file locking.
Modified: trunk/Src/wptGPGPrefsDlg.cpp
===================================================================
--- trunk/Src/wptGPGPrefsDlg.cpp 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/wptGPGPrefsDlg.cpp 2006-01-11 12:19:41 UTC (rev 139)
@@ -61,6 +61,7 @@
if (dir_exist_check (p) == 0) {
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCALE), FALSE);
+ EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), FALSE);
}
free_if_alloc (p);
}
Modified: trunk/Src/wptKeyManagerDlg.cpp
===================================================================
--- trunk/Src/wptKeyManagerDlg.cpp 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/wptKeyManagerDlg.cpp 2006-01-11 12:19:41 UTC (rev 139)
@@ -1462,7 +1462,7 @@
case ID_KEYMISC_RECACHE:
/* If there is already a reload request,
don't bother the user with a message. */
- if (keycache_get_reload() == 1)
+ if (keycache_get_reload () == 1)
l_idx = IDYES;
else {
char inf[256];
@@ -1790,7 +1790,7 @@
km_send_to_keyserver (kmi->lv, dlg, host, port);
break;
- case ID_KEYCTX_RECVFROM:
+ case ID_KEYCTX_RECVFROM:
km_refresh_from_keyserver (kmi->lv, dlg);
break;
@@ -1811,7 +1811,6 @@
case ID_KEYCTX_FPR_COPY:
key = (gpgme_key_t) listview_get_item2 (kmi->lv, kmi->lv_idx);
- //t = get_key_fpr (key);
t = key->subkeys->fpr;
set_clip_text (NULL, t? t : "", t? strlen (t): 0);
break;
Modified: trunk/Src/wptKeysigDlg.cpp
===================================================================
--- trunk/Src/wptKeysigDlg.cpp 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/wptKeysigDlg.cpp 2006-01-11 12:19:41 UTC (rev 139)
@@ -1,5 +1,5 @@
/* wptKeysigDlg.cpp - Key signature listing
- * Copyright (C) 2001-2005 Timo Schulz
+ * Copyright (C) 2001-2006 Timo Schulz
*
* This file is part of WinPT.
*
@@ -52,7 +52,7 @@
pos = listview_get_curr_pos (lv);
if (pos == -1)
return 0;
- listview_get_item_text (lv, pos, 0, tmpbuf, sizeof (tmpbuf)-1);
+ listview_get_item_text (lv, pos, SL_COL_UID, tmpbuf, sizeof (tmpbuf)-1);
if (*tmpbuf == ' ')
return -1;
return 0;
@@ -143,7 +143,7 @@
dlg_fatal_error (dlg, "could not get dialog param");
memset (&ctx, 0, sizeof ctx);
n = listview_get_curr_pos (lv);
- listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1);
+ listview_get_item_text (lv, n, SL_COL_CLASS, tmpbuf, DIM (tmpbuf)-1);
if (!strstr (tmpbuf, "L"))
ctx.exportable = 1;
ctx._class = atoi (tmpbuf);
@@ -151,7 +151,7 @@
ctx._class = 10;
else if (ctx._class < 10)
ctx._class += 10;
- listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1);
+ listview_get_item_text (lv, n, SL_COL_ALGO, tmpbuf, DIM (tmpbuf)-1);
if (strstr (tmpbuf, "DSA"))
ctx.alg = "DSA";
else if (strstr (tmpbuf, "RSA"))
@@ -161,15 +161,15 @@
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
- listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);
+ listview_get_item_text (lv, n, SL_COL_KEYID, tmpbuf, DIM (tmpbuf)-1);
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
if (ctx.exportable)
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
- listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1);
+ listview_get_item_text (lv, n, SL_COL_UID, tmpbuf, DIM (tmpbuf)-1);
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);
tmpbuf[0] = 0;
- listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);
+ listview_get_item_text (lv, n, SL_COL_EXPIRE, tmpbuf, DIM (tmpbuf)-1);
if (strlen (tmpbuf) == 0) {
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
@@ -250,8 +250,8 @@
n = listview_count_items( lv, 0 );
for( i = 0; i < n; i++ ) {
- listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 );
- if( !strncmp( id, "NOKEY", 5 ) )
+ listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
+ if (!strncmp (id, "NOKEY", 5))
return 1;
}
@@ -260,25 +260,32 @@
/* Receive all missing keys marked in the list @lv. */
-static int
+static void
recv_missing_keys (HWND dlg, listview_ctrl_t lv)
{
- int i, n, rc=0;
+ int i, n, cnt=0;
char id[128], keyid[18+1];
+
+ i = msg_box (dlg, _("Really receive all missing keys?"),
+ _("Key Manager"), MB_YESNO|MB_INFO);
+ if (i == IDNO)
+ return;
n = listview_count_items (lv, 0);
- for( i = 0; i < n; i++ ) {
- listview_get_item_text (lv, i, 1, id, sizeof (id) - 1);
- if( !strncmp( id, "NOKEY", 5 ) ) {
- listview_get_item_text( lv, i, 4, keyid, sizeof (keyid) -1);
- rc = hkp_recv_key (dlg, default_keyserver,
- default_keyserver_port, keyid, 0, 0);
- if( rc )
+ for (i = 0; i < n; i++) {
+ listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
+ if (!strncmp (id, "NOKEY", 5)) {
+ listview_get_item_text (lv, i, SL_COL_KEYID,
+ keyid, sizeof (keyid) -1);
+ if (!hkp_recv_key (dlg, default_keyserver,
+ default_keyserver_port, keyid, 0, 0))
+ cnt++;
+ else
break;
}
}
-
- return rc;
+ if (cnt > 0)
+ keycache_set_reload (1);
}
@@ -303,6 +310,24 @@
}
+/* Fetch a single key and extract the keyid from the listview
+ entry at the pos @idx. */
+static int
+recv_single_key (HWND dlg, listview_ctrl_t lv, int idx)
+{
+ char keyid[32];
+ int rc;
+
+ listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1);
+ rc = hkp_recv_key (dlg, default_keyserver,
+ default_keyserver_port, keyid, 0, 0);
+
+ if (!rc)
+ keycache_update (0, keyid);
+ return rc;
+}
+
+
/* Load the key property dialog with the selected key from @lv. */
static void
do_load_keyprops (HWND dlg, listview_ctrl_t lv)
@@ -313,13 +338,16 @@
char status[64] = {0}, creation[64] = {0};
int n = listview_get_curr_pos (lv);
- listview_get_item_text (lv, n, 1, status, DIM (status)-1);
- listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);
- listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);
+ listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1);
+ listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1);
+ listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1);
if (!strcmp (status, "NOKEY")) {
- msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),
- _("Key Manager"), MB_INFO);
- return;
+ int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"),
+ _("Key Manager"), MB_QUEST_ASK);
+ if (id == IDNO)
+ return;
+ if (recv_single_key (dlg, lv, n))
+ return;
}
if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {
@@ -340,11 +368,11 @@
{
static listview_ctrl_t lv = NULL;
static struct winpt_key_s *k;
- char inf[384], keyid[18+1];
- int idx = 0, id, rc;
+ char inf[384];
+ int idx = 0;
HWND sl;
- switch( msg ) {
+ switch (msg) {
case WM_INITDIALOG:
k = (winpt_key_t) lparam;
if (!k)
@@ -377,8 +405,8 @@
return TRUE;
case WM_DESTROY:
- if ( lv ) {
- siglist_delete( lv );
+ if (lv) {
+ siglist_delete (lv);
lv = NULL;
}
return FALSE;
@@ -395,27 +423,43 @@
NMHDR *notify;
notify = (NMHDR *)lparam;
- if (notify && notify->code == NM_DBLCLK
+ if (!notify)
+ return FALSE;
+ if (notify->code == NM_DBLCLK
&& notify->idFrom == IDC_KEYSIG_LIST)
do_load_keyprops (dlg, lv);
- if (notify && notify->code == NM_RCLICK &&
+ if (notify->code == NM_RCLICK &&
notify->idFrom == IDC_KEYSIG_LIST &&
is_sig (lv, -1))
do_create_popup (dlg);
- if (notify && notify->code == LVN_ITEMCHANGED &&
+ if (notify->code == LVN_ITEMCHANGED &&
((LPNMLISTVIEW)lparam)->uNewState) {
idx = listview_get_curr_pos (lv);
- listview_get_item_text (lv, idx, 1, inf, DIM (inf)-1);
+ listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1);
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY),
strcmp (inf, "NOKEY") == 0? TRUE: FALSE);
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS),
is_sig (lv, -1)? TRUE : FALSE);
}
+ if (notify->code == LVN_COLUMNCLICK) {
+ NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
+ int sortby = 0;
+ switch (nft->iSubItem) {
+ //case 0: sortby = KEY_SORT_USERID; break;
+ case 1: sortby = KEY_SORT_VALIDITY; break;
+ case 2: sortby = SIG_SORT_CLASS; break;
+ case 3: sortby = KEY_SORT_CREATED; break;
+ case 4: sortby = KEY_SORT_KEYID; break;
+ case 5: sortby = SIG_SORT_EXPIRE; break;
+ case 6: sortby = KEY_SORT_ALGO; break;
+ default: return TRUE;
+ }
+ siglist_sort (lv, sortby);
+ }
break;
case WM_COMMAND:
- switch ( LOWORD( wparam ) ) {
-
+ switch (LOWORD (wparam)) {
case ID_SIGCTX_KEYPROPS:
do_load_keyprops (dlg, lv);
break;
@@ -428,21 +472,10 @@
case IDC_KEYSIG_RECVKEY:
idx = listview_get_curr_pos (lv);
- if (idx == -1) {
- id = msg_box( dlg, _("Really receive all missing keys?"),
- _("Key Manager"), MB_YESNO|MB_INFO );
- if (id == IDYES) {
- rc = recv_missing_keys (dlg, lv);
- if (!rc)
- keycache_set_reload (1);
- return TRUE;
- }
- return TRUE;
- }
- listview_get_item_text (lv, idx, 4, keyid, DIM (keyid)-1);
- rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);
- if (!rc)
- keycache_update (0, keyid);
+ if (idx == -1)
+ recv_missing_keys (dlg, lv);
+ else
+ recv_single_key (dlg, lv, idx);
return TRUE;
case IDC_KEYSIG_SIGPROPS:
Modified: trunk/Src/wptListView.cpp
===================================================================
--- trunk/Src/wptListView.cpp 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/wptListView.cpp 2006-01-11 12:19:41 UTC (rev 139)
@@ -142,14 +142,14 @@
listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
{
int rc = 0;
- LV_ITEM lvi;
+ LVITEM lvi;
- memset( &lvi, 0, sizeof lvi );
+ memset (&lvi, 0, sizeof (lvi));
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.pszText = (char *)text;
lvi.lParam = (LPARAM)magic;
- rc = ListView_InsertItem( ctx->ctrl, &lvi );
- if( rc == -1 )
+ rc = ListView_InsertItem (ctx->ctrl, &lvi);
+ if (rc == -1)
rc = 1;
ctx->items++;
return rc;
Modified: trunk/Src/wptMainProc.cpp
===================================================================
--- trunk/Src/wptMainProc.cpp 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/wptMainProc.cpp 2006-01-11 12:19:41 UTC (rev 139)
@@ -319,12 +319,14 @@
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
static NOTIFYICONDATA NID;
- static int use_hotkey = 0;
+ static int use_hotkey = 0;
+ INITCOMMONCONTROLSEX cce;
LPARAM param;
- curr_wnd_ctx currwnd = {0};
+ HWND wnd;
+ gpgme_error_t err;
+ curr_wnd_ctx currwnd = {0};
+ const char *s;
int rc, set_wc = 0, has_data = 0;
- INITCOMMONCONTROLSEX cce;
- gpgme_error_t err;
switch (msg) {
case WM_CREATE:
@@ -535,19 +537,26 @@
/** File handling **/
case ID_WINPT_FILE:
- dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_FILE,
- GetDesktopWindow(), file_manager_dlg_proc, 0,
- _("File Manager (use drag & drop to add files)"), IDS_WINPT_FILE );
+ s = _("File Manager (use drag & drop to add files)");
+ wnd = FindWindow (NULL, s);
+ if (wnd && IsIconic (wnd))
+ ShowWindow (wnd, SW_RESTORE);
+ dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_FILE,
+ GetDesktopWindow (), file_manager_dlg_proc, 0,
+ s, IDS_WINPT_FILE);
break;
/** Misc **/
case ID_WINPT_KEY:
+ wnd = FindWindow (NULL, _("Key Manager"));
+ if (wnd && IsIconic (wnd))
+ ShowWindow (wnd, SW_RESTORE);
param = 0;
- if( cmd )
+ if (cmd)
param = (LPARAM)cmd;
- dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC,
+ dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC,
GetDesktopWindow(), keymanager_dlg_proc, param,
- _("Key Manager"), IDS_WINPT_KEYMISC );
+ _("Key Manager"), IDS_WINPT_KEYMISC);
cmd = 0;
break;
Modified: trunk/Src/wptSigList.cpp
===================================================================
--- trunk/Src/wptSigList.cpp 2006-01-09 14:20:00 UTC (rev 138)
+++ trunk/Src/wptSigList.cpp 2006-01-11 12:19:41 UTC (rev 139)
@@ -99,6 +99,22 @@
}
+/* Add an item at the given pos @pos with the opaque param @ks. */
+int
+add_keysig_item (listview_ctrl_t ctx, int pos, gpgme_key_sig_t ks)
+{
+ LV_ITEM lvi;
+
+ memset (&lvi, 0, sizeof lvi);
+ lvi.iItem = pos;
+ lvi.lParam = (LPARAM)ks;
+ lvi.mask = LVIF_PARAM;
+ if (ListView_InsertItem (ctx->ctrl, &lvi) != pos)
+ return -1;
+ return 0;
+}
+
+
/* Add an userid signature @ks from the userid @uid to the sig list
control @lv.
Return value: 0 on success. */
@@ -110,13 +126,13 @@
char t[128];
const char *attr;
const char *s;
- int key_attr;
+ int key_attr, no_uid = 0;
int rc = 0;
if (ks && !IS_UID_CERT (ks->sig_class))
return 0;
- rc = listview_add_item_pos (lv, pos);
+ rc = add_keysig_item (lv, pos, ks);
if (rc)
return rc;
@@ -135,8 +151,10 @@
free (uid_utf8);
free_if_alloc (p);
}
- else
+ else {
listview_add_sub_item (lv, pos, 0, _(" user ID not found"));
+ no_uid = 1;
+ }
if (uid)
return 0;
@@ -147,6 +165,8 @@
case GPG_ERR_BAD_SIGNATURE:s = "NO"; break;
default: s = "ERROR"; break;
}
+ if (no_uid)
+ s = "NOKEY";
listview_add_sub_item (lv, pos, 1, s);
switch (ks->sig_class) {
@@ -224,3 +244,64 @@
}
return lv;
}
+
+
+/* Integer comparsion of @a and @b.
+ Return values: same as in strcmp. */
+static inline int
+int_cmp (int a, int b)
+{
+ if (a == b) return 0;
+ else if (a > b) return 1;
+ else return -1;
+ return 0;
+}
+
+
+/* Sorting callback for the signature list. */
+static int CALLBACK
+siglist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
+{
+ gpgme_key_sig_t a, b;
+ int cmpresult=0;
+
+ a = (gpgme_key_sig_t)first;
+ b = (gpgme_key_sig_t)second;
+ if (!a || !b)
+ return -1; /* this indicates that one item is a root item. */
+
+ switch (sortby) {
+ case KEY_SORT_KEYID:
+ cmpresult = strcmp (a->keyid, b->keyid);
+ break;
+
+ case KEY_SORT_CREATED:
+ cmpresult = int_cmp (a->timestamp, b->timestamp);
+ break;
+
+ case KEY_SORT_ALGO:
+ cmpresult = int_cmp (a->pubkey_algo, b->pubkey_algo);
+ break;
+
+ case KEY_SORT_VALIDITY:
+ cmpresult = int_cmp (a->status, b->status);
+ break;
+
+ case SIG_SORT_EXPIRE:
+ cmpresult = int_cmp (a->expires, a->expires);
+ break;
+
+ case SIG_SORT_CLASS:
+ cmpresult = int_cmp (a->sig_class, b->sig_class);
+ break;
+ }
+ return cmpresult;
+}
+
+
+/* Sort the signature list @sigl by @sortby. */
+void
+siglist_sort (listview_ctrl_t sigl, int sortby)
+{
+ listview_sort_items (sigl, sortby, siglist_cmp_cb);
+}
More information about the Winpt-commits
mailing list