[Winpt-commits] r241 - trunk/Src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 29 13:15:57 CEST 2006


Author: twoaday
Date: 2006-06-29 13:15:55 +0200 (Thu, 29 Jun 2006)
New Revision: 241

Modified:
   trunk/Src/ChangeLog
   trunk/Src/wptClipEncryptDlg.cpp
   trunk/Src/wptGPGPrefsDlg.cpp
   trunk/Src/wptKeyManager.cpp
   trunk/Src/wptListView.cpp
Log:


Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog	2006-06-29 11:15:00 UTC (rev 240)
+++ trunk/Src/ChangeLog	2006-06-29 11:15:55 UTC (rev 241)
@@ -1,4 +1,12 @@
 
+2006-06-28  Timo Schulz  <ts at g10code.de>
+
+	* wptGPGPrefsDlg.cpp (load_gpg4win_values): Fix control logic
+	and memory leak.
+	* wptListView.cpp (listview_find_substr): New.
+	(listview_sort_items): Use symbolic ids.
+	* wptKeyManager.cpp (km_find_key): Allow substring search.
+	
 2006-06-27  Timo Schulz  <ts at g10code.de>
 
 	* wptClipDecryptDlg.cpp (clip_decrypt_dlg): Also call viewer

Modified: trunk/Src/wptClipEncryptDlg.cpp
===================================================================
--- trunk/Src/wptClipEncryptDlg.cpp	2006-06-29 11:15:00 UTC (rev 240)
+++ trunk/Src/wptClipEncryptDlg.cpp	2006-06-29 11:15:55 UTC (rev 241)
@@ -231,7 +231,7 @@
 	    n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1);
 	    if (!n)
 		break;
-	    n = listview_find (lv, tmpbuf);
+	    n = listview_find (lv, tmpbuf, 0);
 	    if (n != -1) {		
 		int oldpos = listview_get_curr_pos (lv);
 		listview_select_one (lv, n);

Modified: trunk/Src/wptGPGPrefsDlg.cpp
===================================================================
--- trunk/Src/wptGPGPrefsDlg.cpp	2006-06-29 11:15:00 UTC (rev 240)
+++ trunk/Src/wptGPGPrefsDlg.cpp	2006-06-29 11:15:55 UTC (rev 241)
@@ -1,5 +1,5 @@
 /* wptGPGPrefsDlg.cpp - GnuPG Preferences
- *	Copyright (C) 2001-2005 Timo Schulz
+ *	Copyright (C) 2001-2006 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -68,6 +68,7 @@
 	}
 	free_if_alloc (p);
     }
+    free_if_alloc (path);
 
     p = get_reg_entry_mo ();
     if (p) {
@@ -78,15 +79,23 @@
 	}
 	free_if_alloc (p);
     }
-
+    
+    path = get_reg_entry_gpg ("HomeDir");
     p = multi_gnupg_path (1);
+    if (path && dir_exist_check (path) == 0 && p && strcmp (path, p)) {
+	/* The 'HomeDir' has a higher priority so if the key exists and is 
+	   different from the multi user path, we force the use of it. */
+	free_if_alloc (p);
+	p = path;
+    }
+    else
+	free_if_alloc (path);
     if (p) {
 	SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);
 	EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE);
 	EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE);
 	free_if_alloc (p);
     }
-
     return true;
 }
 

Modified: trunk/Src/wptKeyManager.cpp
===================================================================
--- trunk/Src/wptKeyManager.cpp	2006-06-29 11:15:00 UTC (rev 240)
+++ trunk/Src/wptKeyManager.cpp	2006-06-29 11:15:55 UTC (rev 241)
@@ -959,17 +959,20 @@
 }
 
 
+/* Provide a search dialog and try to find and select
+   the key which matches the entered pattern. */
 void
 km_find_key (HWND dlg, listview_ctrl_t lv)
 {
     int oldpos = listview_get_curr_pos (lv);
     int n;
     char *name = get_input_dialog (dlg, _("Search"), _("Search for:"));
-    if (name == NULL)
+
+    if (!name)
 	return;
     if (oldpos < 0)
 	oldpos = 0;
-    n = listview_find (lv, name);
+    n = listview_find (lv, name, 1);
     if (n != -1) {
 	listview_select_one (lv, n);
 	listview_scroll (lv, oldpos, n);
@@ -993,6 +996,7 @@
 km_gen_export_filename (const char *keyid, int is_secret)
 {
     winpt_key_s key;
+    size_t i;
     char *p;
 
     memset (&key, 0, sizeof (key));
@@ -1003,8 +1007,9 @@
     if (!p)
 	BUG (0);
     sprintf (p, "%s%s.asc", key.ext->uids->name, is_secret? "_sec" : "");
-    for (size_t i=0; i < strlen (p); i++) {
-	if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|')
+    for (i=0; i < strlen (p); i++) {
+	if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|' ||
+	    p[i] == '\\' || p[i] == '/')
 	    p[i] = '_';
     }
     return p;

Modified: trunk/Src/wptListView.cpp
===================================================================
--- trunk/Src/wptListView.cpp	2006-06-29 11:15:00 UTC (rev 240)
+++ trunk/Src/wptListView.cpp	2006-06-29 11:15:55 UTC (rev 241)
@@ -118,15 +118,15 @@
 
 
 int
-listview_add_item( listview_ctrl_t ctx, const char *text )
+listview_add_item (listview_ctrl_t ctx, const char *text)
 {
     int rc = 0;
     LV_ITEM lvi;
 
-    memset( &lvi, 0, sizeof lvi );
+    memset (&lvi, 0, sizeof lvi);
     lvi.mask = LVIF_TEXT;
     lvi.pszText = (char *)text;
-    rc = ListView_InsertItem( ctx->ctrl, &lvi );
+    rc = ListView_InsertItem (ctx->ctrl, &lvi);
     if( rc == -1 )
 	rc = 1;	
     ctx->items++;
@@ -182,6 +182,7 @@
     return (void*)lvi.lParam;
 }
 
+
 int
 listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)
 {
@@ -298,7 +299,7 @@
 {	
     HWND hheader;
     HDITEM hdi;
-    int idx;
+    int idx, sort_desc = 0;
 
     ListView_SortItems (ctx->ctrl, sort_cb, sortby);
     hheader = ListView_GetHeader (ctx->ctrl);
@@ -327,16 +328,17 @@
     default:                 idx = 0; break;
     }
 
+    sort_desc = sortby & KEYLIST_SORT_DESC;
     /* Set image to currently sorted field */
     memset (&hdi, 0, sizeof(hdi));
     hdi.mask = HDI_IMAGE | HDI_FORMAT;
     Header_GetItem (hheader, idx, &hdi);   
     hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;
     if (!ctx->ext_chkbox)
-	hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ? 
-					IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);
+	hdi.iImage = imagelist_getindex (sort_desc? IMI_SORT_DOWNARROW :
+						    IMI_SORT_UPARROW);
     else
-	hdi.iImage = (sortby & KEYLIST_SORT_DESC)? 2 : 3;
+	hdi.iImage = sort_desc? KEY_IMG_SORT_DOWN : KEY_IMG_SORT_UP;
     Header_SetItem (hheader, idx, &hdi);
     return 0;
 }
@@ -404,7 +406,8 @@
 void
 listview_select_one (listview_ctrl_t ctx, int pos)
 {
-    ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);
+    ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, 
+					    LVIS_FOCUSED|LVIS_SELECTED);
 }
 
 
@@ -415,13 +418,35 @@
     
     if (oldpos == -1)
 	oldpos = 0;
-    //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);
+    //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", 
+		//oldpos, newpos, newpos-oldpos);
     ListView_Scroll (ctx->ctrl,	0, (newpos-oldpos)*size);
 }
 
 
+static int 
+listview_find_substr (listview_ctrl_t ctx, const char *str)
+{
+    char buf[256];
+    int i, n, fnd = 0;
+
+    /* We assume the first column contains text. */
+    n = listview_count_items (ctx, 0);
+    for (i = 0; i < n; i++) {
+	listview_get_item_text (ctx, i, 0, buf, sizeof (buf)-1);
+	if (stristr (buf, str)) {
+	    fnd = 1;
+	    break;
+	}
+    }
+    if (!fnd)
+	i = -1; /* not found */
+    return i;
+}
+
+
 int
-listview_find (listview_ctrl_t ctx, const char *str)
+listview_find (listview_ctrl_t ctx, const char *str, int substr)
 {
     LVFINDINFO inf;
     int pos;
@@ -431,6 +456,8 @@
     inf.flags = LVFI_STRING|LVFI_PARTIAL;
     inf.psz = str;
     pos = ListView_FindItem (ctx->ctrl, -1, &inf);
+    if (pos == -1 && substr)
+	pos = listview_find_substr (ctx, str);
     return pos;
 }
 



More information about the Winpt-commits mailing list