[Winpt-commits] r244 - trunk/Src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jul 3 16:10:23 CEST 2006


Author: twoaday
Date: 2006-07-03 16:10:21 +0200 (Mon, 03 Jul 2006)
New Revision: 244

Modified:
   trunk/Src/ChangeLog
   trunk/Src/wptFileManager.cpp
   trunk/Src/wptFileManagerDlg.cpp
   trunk/Src/wptKeyManager.cpp
   trunk/Src/wptKeyManagerDlg.cpp
   trunk/Src/wptMAPI.cpp
   trunk/Src/wptMDSumDlg.cpp
   trunk/Src/wptMainProc.cpp
   trunk/Src/wptProgressDlg.cpp
Log:


Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/ChangeLog	2006-07-03 14:10:21 UTC (rev 244)
@@ -1,4 +1,18 @@
 
+2006-07-01  Timo Schulz  <ts at g10code.de>
+
+	* wptFileManager.cpp (fm_sort): Rewritten.
+	(fm_build): Modify param type. Change all callers.
+	(fm_cmp_cb): Adjusted for the new code.
+	* wptMDSumDlg.cpp (mdsum_dlg_proc): Minor changes and model
+	for the list view.
+	* wptFileManagerDlg.cpp (file_manager_dlg_proc): Use info
+	context and model for the list view.
+	(update_status_bar): Fix calculation of the size of the
+	selected files.
+	* wptProgressDlg.cpp (wait_for_progress_cb): Changed semantic
+	and return type.
+	
 2006-06-28  Timo Schulz  <ts at g10code.de>
 
 	* wptGPGPrefsDlg.cpp (load_gpg4win_values): Fix control logic

Modified: trunk/Src/wptFileManager.cpp
===================================================================
--- trunk/Src/wptFileManager.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptFileManager.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -60,18 +60,41 @@
 void verify_show_signature_state (gpgme_signature_t sig);
 
 
-/* Symbolic column IDs. */
-enum {
-    FM_COL_STAT = 0,
-    FM_COL_NAME = 1,
-    FM_COL_OP   = 2
-};
-
 static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",
 				  ".mp3", ".wav", ".mid", ".wma",
 				  ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};
 
 
+/* Add a new file to the model @fm. */
+static void
+fm_model_add_file (fm_model_t *fm, fm_model_t file)
+{
+    fm_model_t m;
+
+    if (!*fm) {
+	*fm = file;
+	return;
+    }
+    for (m = *fm; m->next; m = m->next)
+	;
+    m->next = file;
+}
+
+
+/* Search for a file model based on the name @name. */
+static fm_model_t
+fm_model_find_file (fm_model_t fm, const char *name)
+{
+    fm_model_t m;
+
+    for (m=fm; m; m=m->next) {
+	if (!stricmp (m->name, name))
+	    return m;
+    }
+    return NULL;
+}
+
+
 /* Check if the drive given by @fname is a floppy disc.
    Return value: -1 for success. */
 static int
@@ -374,39 +397,71 @@
 }
 
 
-/* Build the File Manager list view control. */
-int
-fm_build (listview_ctrl_t *lv, HWND ctrl)
+/* Build the File Manager dialog context. */
+void
+fm_build (fm_info_t *r_fm, HWND ctrl)
 {
     int i;
-    listview_ctrl_t c;
+    fm_info_t fm;
     struct listview_column_s col[] = {
 	{0,  80, (char *)_("Status") },
 	{1, 256, (char *)_("Name") },
 	{2, 128, (char *)_("Operation") },
 	{0,   0, NULL}	
     };
-	
-    listview_new (&c, ctrl);
+
+    fm = new fm_info_s;
+    memset (fm, 0, sizeof *fm);
+    listview_new (&fm->lv, ctrl);
     for (i = 0; col[i].width; i++)
-	listview_add_column (c, &col[i]);
-    listview_set_ext_style (c);
-    if (lv)
-	*lv = c;
-    return 0;
+	listview_add_column (fm->lv, &col[i]);
+    listview_set_ext_style (fm->lv);
+    fm->model = NULL; /*init*/
+    *r_fm = fm;
 }
 
 
-/* Release the File Manager listview control. */
-void
-fm_delete (listview_ctrl_t lv)
+/* Release the file model. */
+static void
+fm_model_release (fm_model_t mod)
 {
-    if (lv) {
-	listview_release(lv);	
+    fm_model_t m;
+
+    while (mod) {
+	m = mod->next;
+	free_if_alloc (mod->name);
+	free_if_alloc (mod->op);
+	free_if_alloc (mod->status);
+	free_if_alloc (mod);
+	mod = m;
     }
 }
 
 
+/* Reset the File Manager info context. */
+void
+fm_reset (fm_info_t fm)
+{
+    listview_del_all_items (fm->lv);
+    fm_model_release (fm->model);
+    fm->model = NULL;
+}
+
+
+/* Release the File Manager dialog context. */
+void
+fm_delete (fm_info_t fm)
+{
+    if (!fm)
+	return;
+    if (fm->menu)
+	DestroyMenu (fm->menu);
+    listview_release (fm->lv);
+    fm_model_release (fm->model);
+    free_if_alloc (fm);   
+}
+
+
 int
 fm_state_new (fm_state_t * ctx)
 {
@@ -444,13 +499,13 @@
 static int
 fm_check_for_entry (listview_ctrl_t lv, const char *file)
 {
-    char name[512];
+    char name[MAX_PATH+128];
     int i;
 
     memset (name, 0, sizeof (name));
     for (i = 0; i < listview_count_items (lv, 0); i++) {
 	listview_get_item_text (lv, i, FM_COL_NAME, name, sizeof (name) - 1);
-	if (!strcmp( name, file))
+	if (!strcmp (name, file))
 	    return 1; /* found */	
     }
 
@@ -459,29 +514,34 @@
 
 
 static int
-fm_set_ftype (listview_ctrl_t lv, const char *name)
+fm_set_ftype (listview_ctrl_t lv, fm_model_t *fm, const char *name)
 {
+    fm_model_t m;
     const char *type;
     int rc;
 
     rc = fm_check_for_entry (lv, name);
     if (rc)
 	return 0;
+    m = new fm_model_s;
+    memset (m, 0, sizeof *m);
     type = fm_get_file_type (name, NULL);
     if (!type || !strcmp (type, "UNKNOWN"))
 	type = gnupg_check_file_ext (name, NULL);
-    rc = listview_add_item (lv, " ");
-    if (rc)
-	return -1;
+    listview_add_item2 (lv, " ", (void*)m);
     listview_add_sub_item (lv, 0, FM_COL_STAT, type);
     listview_add_sub_item (lv, 0, FM_COL_NAME, name);
+    m->name = m_strdup (name);
+    m->status = m_strdup (type);
+    m->op = NULL;
+    fm_model_add_file (fm, m);
     return 0;
 }
 
 
 /* Add all files from the directory @path to the list view @lv. */
 static int
-fm_add_dir_files (listview_ctrl_t lv, char *path)
+fm_add_dir_files (listview_ctrl_t lv, fm_model_t *fm, char *path)
 {
     struct _finddata_t fd;
     char *p;
@@ -497,7 +557,7 @@
 	p[strlen (path)-1] = 0;
 	strcat (p, fd.name);
 	if (!is_directory (p))
-	    fm_set_ftype (lv, p);
+	    fm_set_ftype (lv, fm, p);
 	free_if_alloc (p);
     } while (_findnext (hd, &fd) == 0);
     _findclose (hd);
@@ -508,7 +568,7 @@
 /* Add the drag & drop files from @dd_files to the 
    list view control @lv. */
 int
-fm_add_dropped_files (listview_ctrl_t lv, HDROP dd_files)
+fm_add_dropped_files (fm_info_t fm, HDROP dd_files)
 {
     char name[384+4];
     int nfiles;
@@ -520,9 +580,9 @@
     for (i = 0;  i < nfiles; i++) {
 	DragQueryFile (dd_files, i, name, sizeof (name) -1);
 	if (is_directory (name))
-	    rc = fm_add_dir_files (lv, name);
+	    rc = fm_add_dir_files (fm->lv, &fm->model, name);
 	else
-	    rc = fm_set_ftype (lv, name);
+	    rc = fm_set_ftype (fm->lv, &fm->model, name);
 	if (rc == -1)
 	    break; /* XXX: fixme? */
     }
@@ -535,21 +595,28 @@
    figure out the type of it. 
    Return value: 0 on success. */
 static int
-add_single_file (listview_ctrl_t lv, const char *name)
+add_single_file (listview_ctrl_t lv, fm_model_t *fm, const char *name)
 {
+    fm_model_t m;
     const char *type;
     int rc = 0;
-
+    
     type = fm_get_file_type (name, NULL);
     if (!type)
 	return WPTERR_FILE_OPEN;
+    m = new fm_model_s;
+    memset (m, 0, sizeof *m);
     if (!strcmp (type, "UNKNOWN"))	
 	type = gnupg_check_file_ext (name, NULL);
-    rc = listview_add_item (lv, "");
+    rc = listview_add_item2 (lv, "", (void*)m);
     if (!rc) {
 	listview_add_sub_item (lv, 0, FM_COL_STAT, type);
 	listview_add_sub_item (lv, 0, FM_COL_NAME, name);
     }
+    m->status = m_strdup (type);
+    m->name = m_strdup (name);
+    m->op = NULL;
+    fm_model_add_file (fm, m);
     return rc;
 }
 
@@ -557,7 +624,7 @@
 /* Use the common Open-File-Dialog to allow the user to
    add one ore more selected files to the listview @lv. */
 int
-fm_add_opened_files (listview_ctrl_t lv, HWND dlg)
+fm_add_opened_files (fm_info_t fm, HWND dlg)
 {
     OPENFILENAME open;
     char file[512], name[MAX_PATH+1];
@@ -599,13 +666,13 @@
 	    path = m_strdup (name);
 	else {
 	    char *p = make_filename (path, name, NULL);
-	    rc = add_single_file (lv, p);
+	    rc = add_single_file (fm->lv, &fm->model, p);
 	    free_if_alloc (p);
 	}
 	n++;
     }
     if (n == 1) /* single file selected. */
-	rc = add_single_file (lv, path);
+	rc = add_single_file (fm->lv, &fm->model, path);
     free_if_alloc (path);
     return rc;
 }
@@ -1935,26 +2002,37 @@
 static int CALLBACK
 fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
 {
-    const char *a = "";
-    const char *b = "";
+    fm_model_t a, b;
+    int cmpres = 0;
 
+    a = (fm_model_t)first;
+    b = (fm_model_t)second;
+    if (!a || !b)
+	return 0;
+
     switch ((int)sortby) {
-    case FM_SORT_STAT:
+    case FM_COL_STAT:
+	cmpres = stricmp (a->status, b->status);
 	break;
-    case FM_SORT_NAME:
+
+    case FM_COL_NAME:
+	cmpres = stricmp (a->name, b->name);
 	break;
-    case FM_SORT_OP:
+
+    case FM_COL_OP:
+	if (a->op && b->op)
+	    cmpres = stricmp (a->op, b->op);
 	break;
     }
-    return stricmp (a, b);
+    return cmpres;
 }
-	
 
+
 /* Sort the list items from @lv with the mode given by @sortby. */
 int
 fm_sort (listview_ctrl_t lv, int sortby)
 {
-    return listview_sort_items (lv, sortby, fm_cmp_cb);
+    return ListView_SortItems (lv->ctrl, fm_cmp_cb, (LPARAM)sortby);
 }
 
 

Modified: trunk/Src/wptFileManagerDlg.cpp
===================================================================
--- trunk/Src/wptFileManagerDlg.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptFileManagerDlg.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -1,5 +1,5 @@
 /* wptFileMangerDlg.cpp - File Manager
- *	Copyright (C) 2001-2005 Timo Schulz
+ *	Copyright (C) 2001-2006 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -240,13 +240,6 @@
         }
         return FALSE;
         
-    case WM_SYSCOMMAND:
-        if (LOWORD (wparam) == SC_CLOSE) {
-            c->cancel = 1;
-            EndDialog (dlg, FALSE);
-        }
-        return FALSE;
-        
     case WM_COMMAND:
         switch (LOWORD (wparam)) {
         case IDC_IMPORT_DOIT:
@@ -398,7 +391,8 @@
 {
     struct stat st;
     char buf[128];
-    int n;
+    int i, n;
+    DWORD len = 0;
 
     if (!lv) { /* flush */
 	SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 Byte");
@@ -408,18 +402,24 @@
     n = listview_count_items (lv, 1);
     _snprintf (buf, sizeof (buf)-1, _("%d Object(s) marked"), n);
     SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)buf);
-    listview_get_item_text (lv, listview_get_curr_pos (lv), 1, buf, 127);
-    if (stat (buf, &st) == 0) {
-	if (st.st_size < 1024)
-	    _snprintf (buf, sizeof (buf)-1, "%d Byte", st.st_size);
-	else if (st.st_size < 1048576)
-	    _snprintf (buf, sizeof (buf)-1, "%d KB", st.st_size/1024);
-	else
-	    _snprintf (buf, sizeof (buf)-1, "%d MB", st.st_size/1024/1024);
-	SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf);
+    if (!n)
+	return;
+    for (i=0; i < listview_count_items (lv, 0); i++) {
+	if (!listview_get_item_state (lv, i))
+	    continue;
+	listview_get_item_text (lv, i, 1, buf, sizeof (buf)-1);
+	if (stat (buf, &st) == 0)
+	    len += st.st_size;
     }
+    if (!len)
+	_snprintf (buf, sizeof (buf)-1, "0 Byte");
+    else if (len < 1024)
+	_snprintf (buf, sizeof (buf)-1, "%d Byte", len);
+    else if (st.st_size < 1048576)
+	_snprintf (buf, sizeof (buf)-1, "%d KB", len/1024);
     else
-	SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 Byte");
+	_snprintf (buf, sizeof (buf)-1, "%d MB", len/1024/1024);
+    SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf);
 }
 
 
@@ -489,9 +489,7 @@
 BOOL CALLBACK
 file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
 {
-    static HWND statbar;
-    static listview_ctrl_t lv = NULL;
-    static HMENU menu = NULL;
+    static fm_info_t fm = NULL;
     static int always_ontop = 0;
     HWND fl;
     
@@ -501,30 +499,31 @@
 	if (always_ontop == -1)
 	    always_ontop = 0;
 	SetWindowText (dlg, _("File Manager (use drag & drop to add files)"));
-	menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC);
-	set_menu_text_bypos (menu, 0, _("File"));
-	set_menu_text_bypos (menu, 1, _("Edit"));
-	set_menu_text_bypos (menu, 2, _("View"));
-        set_menu_text (menu, ID_FILEMISC_OPEN, _("&Open...") );
-        set_menu_text (menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") );
-	set_menu_text (menu, ID_FILEMISC_ENCRYPT_ZIP, _("Encrypt into ZIP"));
-        set_menu_text (menu, ID_FILEMISC_DECRYPT, _("&Decrypt") );
-        set_menu_text (menu, ID_FILEMISC_SIGN, _("&Sign") );
-        set_menu_text (menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") );
-        set_menu_text (menu, ID_FILEMISC_VERIFY, _("&Verify") );        
-        set_menu_text (menu, ID_FILEMISC_SYMENC, _("S&ymmetric") );
-        set_menu_text (menu, ID_FILEMISC_IMPORT, _("&Import") );
-        set_menu_text (menu, ID_FILEMISC_EXPORT, _("E&xport") );
-        set_menu_text (menu, ID_FILEMISC_QUIT, _("Exit"));
-        set_menu_text (menu, ID_FILEMISC_CLEAR, _("&Reset") );
-	set_menu_text (menu, ID_FILEMISC_ONTOP, _("Always on Top"));
-	set_menu_text (menu, ID_FILEMISC_PASTE, _("&Paste"));
-	set_menu_text (menu, ID_FILEMISC_SELALL, _("&Select All"));
-	set_menu_text (menu, ID_FILEMISC_PREFS, _("&Preferences"));
-	set_menu_text (menu, ID_FILEMISC_SEND, _("Send as Mail"));
-	set_menu_text (menu, ID_FILEMISC_LIST, _("&List Packets"));
-	set_menu_text (menu, ID_FILEMISC_WIPE_FREES, _("Wipe Free Space"));
-	set_menu_text (menu, ID_FILEMISC_WIPE, _("&Wipe"));	
+	fm_build (&fm, GetDlgItem (dlg, IDC_FILE_LIST));
+	fm->menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC);
+	set_menu_text_bypos (fm->menu, 0, _("File"));
+	set_menu_text_bypos (fm->menu, 1, _("Edit"));
+	set_menu_text_bypos (fm->menu, 2, _("View"));
+        set_menu_text (fm->menu, ID_FILEMISC_OPEN, _("&Open...") );
+        set_menu_text (fm->menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") );
+	set_menu_text (fm->menu, ID_FILEMISC_ENCRYPT_ZIP, _("Encrypt into ZIP"));
+        set_menu_text (fm->menu, ID_FILEMISC_DECRYPT, _("&Decrypt") );
+        set_menu_text (fm->menu, ID_FILEMISC_SIGN, _("&Sign") );
+        set_menu_text (fm->menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") );
+        set_menu_text (fm->menu, ID_FILEMISC_VERIFY, _("&Verify") );        
+        set_menu_text (fm->menu, ID_FILEMISC_SYMENC, _("S&ymmetric") );
+        set_menu_text (fm->menu, ID_FILEMISC_IMPORT, _("&Import") );
+        set_menu_text (fm->menu, ID_FILEMISC_EXPORT, _("E&xport") );
+        set_menu_text (fm->menu, ID_FILEMISC_QUIT, _("Exit"));
+        set_menu_text (fm->menu, ID_FILEMISC_CLEAR, _("&Reset") );
+	set_menu_text (fm->menu, ID_FILEMISC_ONTOP, _("Always on Top"));
+	set_menu_text (fm->menu, ID_FILEMISC_PASTE, _("&Paste"));
+	set_menu_text (fm->menu, ID_FILEMISC_SELALL, _("&Select All"));
+	set_menu_text (fm->menu, ID_FILEMISC_PREFS, _("&Preferences"));
+	set_menu_text (fm->menu, ID_FILEMISC_SEND, _("Send as Mail"));
+	set_menu_text (fm->menu, ID_FILEMISC_LIST, _("&List Packets"));
+	set_menu_text (fm->menu, ID_FILEMISC_WIPE_FREES, _("Wipe Free Space"));
+	set_menu_text (fm->menu, ID_FILEMISC_WIPE, _("&Wipe"));	
 
 	fl = GetDlgItem (dlg, IDC_FILE_LIST);
 	filelist_proc.dlg = dlg;
@@ -537,43 +536,45 @@
 		BUG (NULL);
 	    }
 	}
-        SetMenu (dlg, menu);
+        SetMenu (dlg, fm->menu);
 	if (!always_ontop)
-	    set_menu_state (menu, ID_FILEMISC_ONTOP, MFS_UNCHECKED);
+	    set_menu_state (fm->menu, ID_FILEMISC_ONTOP, MFS_UNCHECKED);
 	else
 	    center_window2 (dlg, NULL, HWND_TOPMOST);
-        fm_build (&lv, GetDlgItem (dlg, IDC_FILE_LIST));
+        
 	center_window (dlg, NULL);
         SetForegroundWindow (dlg);
-	statbar = setup_status_bar (dlg);
-	filelist_proc.opaque = (void*)statbar;
+	fm->statbar = setup_status_bar (dlg);
+	filelist_proc.opaque = (void*)fm->statbar;
         return TRUE;
 
     case WM_DESTROY:
-        if (lv) {
-            fm_delete (lv);
-            lv = NULL;
+        if (fm) {
+	    fm_delete (fm);
+            fm = NULL;
         }
-        if (menu) {
-            DestroyMenu (menu);
-            menu = NULL;
-        }
 	set_reg_winpt_flag ("AlwaysOnTop", always_ontop);
         return FALSE;
         
     case WM_DROPFILES:
-        fm_add_dropped_files (lv, (HDROP)wparam);
+        fm_add_dropped_files (fm, (HDROP)wparam);
         return TRUE;
         
     case WM_NOTIFY:
         NMHDR *notify;
 	int pos;
-	HMENU hm;
+	HMENU hm;	
 
         notify = (NMHDR *)lparam;
+	if (notify && notify->code == LVN_COLUMNCLICK 
+	    && notify->idFrom == IDC_FILE_LIST) {
+	    NMLISTVIEW *p = (LPNMLISTVIEW) lparam;
+	    fm_sort (fm->lv, p->iSubItem);
+	}
+
 	if (notify && notify->code == NM_CLICK &&
 	    notify->idFrom == IDC_FILE_LIST)
-	    update_status_bar (statbar, lv);
+	    update_status_bar (fm->statbar, fm->lv);
         if (notify && notify->code == NM_RCLICK
             && notify->idFrom == IDC_FILE_LIST) {
             POINT p;
@@ -591,9 +592,9 @@
             set_menu_text (popup, ID_FILECTX_WIPE, _("Wipe"));
 	    set_menu_text (popup, ID_FILECTX_SEND, _("Send as Mail"));
 	    set_menu_text (popup, ID_FILECTX_LIST, _("List Packets"));
-	    if (!is_openpgp_file (lv))
+	    if (!is_openpgp_file (fm->lv))
 		set_menu_state (popup, ID_FILECTX_LIST, MF_GRAYED|MF_DISABLED);
-	    update_ui_items (dlg, popup, true, lv);
+	    update_ui_items (dlg, popup, true, fm->lv);
             TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
             DestroyMenu (popup);
             DestroyMenu (hm);
@@ -601,15 +602,17 @@
 	if (notify && notify->code == NM_CLICK
             && notify->idFrom == IDC_FILE_LIST) {
 	    hm = GetMenu (dlg);
-	    pos = listview_get_curr_pos (lv);
-	    if (!fm_check_file_type (lv, pos, FM_DECRYPT))
+	    pos = listview_get_curr_pos (fm->lv);
+	    if (!fm_check_file_type (fm->lv, pos, FM_DECRYPT))
 		set_menu_state (hm, ID_FILEMISC_SEND, MF_GRAYED|MF_DISABLED);
 	    else
 		set_menu_state (hm, ID_FILEMISC_SEND, MF_ENABLED);
 	}
 	if (notify && notify->code == LVN_ITEMCHANGED &&
-            ((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */
-	    update_ui_items (dlg, GetMenu (dlg), false, lv);
+            ((LPNMLISTVIEW)lparam)->uNewState) { /* item selected? */
+	    update_ui_items (dlg, GetMenu (dlg), false, fm->lv);
+	    update_status_bar (fm->statbar, fm->lv);
+	}
         return TRUE;
         
     case WM_SYSCOMMAND:
@@ -640,23 +643,23 @@
 	    break;
             
 	case ID_FILEMISC_SELALL:
-	    listview_select_all (lv);
+	    listview_select_all (fm->lv);
 	    break;
 
 	case ID_FILEMISC_PASTE:
-	    fm_verify_pasted_detsig (lv, dlg);
+	    fm_verify_pasted_detsig (fm->lv, dlg);
 	    break;
 
 	case ID_FILEMISC_ONTOP:
 	    always_ontop ^= 1;	    		
-	    set_menu_state (menu, ID_FILEMISC_ONTOP, 
+	    set_menu_state (fm->menu, ID_FILEMISC_ONTOP, 
 			    always_ontop == 0? MFS_UNCHECKED : MFS_CHECKED);
 	    center_window2 (dlg, NULL, 
 			    always_ontop == 0? HWND_NOTOPMOST : HWND_TOPMOST);
 	    break;
 
 	case ID_FILEMISC_SEND:
-	    fm_send_file (lv);
+	    fm_send_file (fm->lv);
 	    break;
 
 	case ID_FILEMISC_PREFS:
@@ -673,7 +676,7 @@
         case ID_FILEMISC_VERIFY:
         case ID_FILEMISC_WIPE:
 	case ID_FILEMISC_ENCRYPT_ZIP:
-            fm_parse_files (lv, dlg, LOWORD (wparam));
+            fm_parse_files (fm->lv, dlg, LOWORD (wparam));
 	    SetForegroundWindow (dlg);
             return TRUE;
 	    
@@ -690,16 +693,17 @@
 	    case ID_FILEMISC_MD_SHA256:	algo = GPGME_MD_SHA256; break;
 	    default:			algo = GPGME_MD_SHA1; break;
 	    }
-	    fm_print_md (lv, dlg, algo);
+	    fm_print_md (fm->lv, dlg, algo);
 	    SetForegroundWindow (dlg);
 	    return TRUE;
             
         case ID_FILEMISC_CLEAR:
-            listview_del_all_items (lv);
+            fm_reset (fm);
+	    update_status_bar (fm->statbar, NULL);
             return TRUE;
             
         case ID_FILEMISC_OPEN:
-            fm_add_opened_files( lv, dlg );
+            fm_add_opened_files (fm, dlg);
             return TRUE;
             
             /* context menu entries */

Modified: trunk/Src/wptKeyManager.cpp
===================================================================
--- trunk/Src/wptKeyManager.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptKeyManager.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -52,6 +52,24 @@
 #include "wptGPGME.h"
 
 
+/* Remove all kind of invalid characters which would
+   result in an illegal file name. */
+static void
+secure_filename (char *file, size_t len)
+{
+    char *p = file;
+    size_t i;
+
+    /* XXX: it is possible that the recipient has a different
+            charset and thus maybe 8-bit chars should be stripped also. */
+    for (i=0; i < len; i++) {
+	if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|' ||
+	    p[i] == '\\' || p[i] == '/')
+	    p[i] = '_';
+    }
+}
+
+
 /* Return a user friendly key representation in @buf of
    the key given by @keyid. */
 void 
@@ -823,10 +841,7 @@
     n = strlen (c->uids->name)+1 + MAX_PATH + 5;
     fname = new char[n+1];
     get_temp_name (fname, n-5, c->uids->name);
-    for (pos=0; pos < (int)strlen (fname); pos++) {
-	if (fname[pos] == ' ')
-	    fname[pos] = '_';
-    }
+    secure_filename (fname, strlen (fname));
     strcat (fname, ".asc");
     ctx = new GPGME ();
     ctx->setArmor (true);
@@ -881,7 +896,7 @@
 
 
 /* Refresh the selected keys from the default keyserver. */
-void
+int
 km_refresh_from_keyserver (listview_ctrl_t lv, HWND dlg)
 {
     int cnt, id, i;    
@@ -891,11 +906,11 @@
         id = msg_box (dlg, _("Do you really want to refresh all keys in the keyring?"),
 		      _("Key Manager"), MB_YESNO);
         if (id == IDNO)
-            return;
+            return -1;
 	if (kserver_check_inet_connection ()) {
 	    msg_box (dlg, _("Could not connect to keyserver, abort procedure."),
 		     _("Key Manager"), MB_ERR);
-	    return;
+	    return -1;
 	}
     }
     if (listview_count_items (lv, 1) == 1)
@@ -906,6 +921,7 @@
 		km_refresh_one_key (lv, dlg, i, KM_KS_REFRESH);	
 	}
     }
+    return 0;
 }
 
 
@@ -996,7 +1012,6 @@
 km_gen_export_filename (const char *keyid, int is_secret)
 {
     winpt_key_s key;
-    size_t i;
     char *p;
 
     memset (&key, 0, sizeof (key));
@@ -1007,11 +1022,7 @@
     if (!p)
 	BUG (0);
     sprintf (p, "%s%s.asc", key.ext->uids->name, is_secret? "_sec" : "");
-    for (i=0; i < strlen (p); i++) {
-	if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|' ||
-	    p[i] == '\\' || p[i] == '/')
-	    p[i] = '_';
-    }
+    secure_filename (p, strlen (p));
     return p;
 }
 

Modified: trunk/Src/wptKeyManagerDlg.cpp
===================================================================
--- trunk/Src/wptKeyManagerDlg.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptKeyManagerDlg.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -1330,8 +1330,8 @@
         keylist_proc.current = (WNDPROC)keylist_subclass_proc;
         keylist_proc.old = (WNDPROC)GetWindowLong(kl, GWL_WNDPROC);
         if (keylist_proc.old) {
-            if( !SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {
-                msg_box (dlg, _("Could not set keylist window procedure."), 
+            if (!SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {
+                msg_box (dlg, "Could not set keylist window procedure.",
 			 _("Key Manager"), MB_ERR);
 		BUG (NULL);
 	    }
@@ -1507,7 +1507,8 @@
             break;
 
 	case NM_RCLICK:
-	    wait_for_progress_cb ();
+	    if (!wait_for_progress_cb (0))
+		break;
             if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
 		l_idx =listview_get_curr_pos (kmi->lv);
 		if (l_idx == -1)
@@ -1577,7 +1578,8 @@
                 NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
                 int sortby = 0;
 
-		wait_for_progress_cb ();
+		if (!wait_for_progress_cb (0))
+		    break;
                 switch (nft->iSubItem) {
                 case 0:  sortby = KEY_SORT_USERID; break;
                 case 1:  sortby = KEY_SORT_KEYID; break;
@@ -1940,9 +1942,9 @@
 			 _("Key Manager"), MB_INFO);
 		listview_select_all (kmi->lv);
 	    }
-            km_refresh_from_keyserver (kmi->lv, dlg);
-	    msg_box (dlg, _("Keyserver refresh finished."), 
-		     _("Key Manager"), MB_OK);
+            if (!km_refresh_from_keyserver (kmi->lv, dlg))
+		msg_box (dlg, _("Keyserver refresh finished."), 
+			 _("Key Manager"), MB_OK);
             break;
                         
 	/** Context menu **/

Modified: trunk/Src/wptMAPI.cpp
===================================================================
--- trunk/Src/wptMAPI.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptMAPI.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -1,5 +1,5 @@
 /* wptMAPI.cpp - MAPI interface for sending keys.
- *	Copyright (C) 2003, 2004, 2005, 2006 Timo Schulz
+ *	Copyright (C) 2003-2006 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -45,6 +45,43 @@
 #define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name)
 
 
+/* Table with all valid MAPI errors. */
+struct mapi_err_s {
+    int err_no;
+    const char *msg;
+} mapi_errors[] = {
+    {MAPI_E_FAILURE, "One or more unspecified errors occurred. "},
+    {MAPI_E_AMBIGUOUS_RECIPIENT, "A recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set. "},
+    {MAPI_E_ATTACHMENT_NOT_FOUND, "The specified attachment was not found. "},
+    {MAPI_E_ATTACHMENT_OPEN_FAILURE, "The specified attachment could not be opened. "},
+    {MAPI_E_BAD_RECIPTYPE, "The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC. "},
+    {MAPI_E_INSUFFICIENT_MEMORY, "There was insufficient memory to proceed." },
+    {MAPI_E_INVALID_RECIPS, "One or more recipients were invalid or did not resolve to any address."},
+    {MAPI_E_LOGIN_FAILURE, "There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed."},
+    {MAPI_E_TEXT_TOO_LARGE, "The text in the message was too large."},
+    {MAPI_E_TOO_MANY_FILES, "There were too many file attachments."},
+    {MAPI_E_TOO_MANY_RECIPIENTS, "There were too many recipients."},
+    {MAPI_E_UNKNOWN_RECIPIENT, "A recipient did not appear in the address list."},
+    {MAPI_E_USER_ABORT, "The user canceled one of the dialog boxes."},
+    {SUCCESS_SUCCESS, "The call succeeded and the message was sent."},
+    {0, NULL}
+};
+
+
+/* Return a human readable MAPI error based on the given error @err. */
+const char*
+mapi_strerror (int err)
+{
+    int i;
+
+    for (i=0; mapi_errors[i].msg; i++) {
+	if (err == mapi_errors[i].err_no)
+	    return mapi_errors[i].msg;
+    }
+    return mapi_errors[0].msg;
+}
+
+
 /* Load MAPI library and set function pointers.
    Return value: 0 on success. */
 int
@@ -73,11 +110,11 @@
 void
 mapi_deinit (void)
 {
-    if (hlib) {
-	FreeLibrary (hlib);
-	hlib = NULL;
-	init = 0;
-    }
+    if (!hlib)
+	return;
+    FreeLibrary (hlib);
+    hlib = NULL;
+    init = 0;
 }
 
 
@@ -93,7 +130,7 @@
 
     rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);
     if (rc != SUCCESS_SUCCESS) {
-	MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK);
+	MessageBox (NULL, mapi_strerror (rc), _("MAPI Login failed"), MB_WARN);
 	goto fail;
     }
     rc = mapi_send_documents (0, ";", ascfile, NULL, 0);
@@ -120,9 +157,9 @@
 
 
 static void
-free_recip_tab (MapiRecipDesc *recip, size_t n)
+free_recip_tab (MapiRecipDesc *recip, DWORD n)
 {
-    size_t i;
+    DWORD i;
 
     if (!recip)
 	return;
@@ -135,9 +172,9 @@
 
 
 static void
-free_files_tab (MapiFileDesc *files, size_t n)
+free_files_tab (MapiFileDesc *files, DWORD n)
 {
-    size_t i;
+    DWORD i;
 
     if (!files)
 	return;
@@ -159,7 +196,6 @@
     MapiMessage *msg;
     MapiRecipDesc *recip;
     MapiFileDesc *attch;
-    gpgme_key_t to = key->ctx;
     char *p, *kinf;
     const char *s;
     int rc;
@@ -169,7 +205,7 @@
 
     rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);
     if (rc != SUCCESS_SUCCESS) {
-	MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK);
+	MessageBox (NULL, mapi_strerror (rc), _("MAPI Login failed"), MB_WARN);
 	return rc;
     }
 
@@ -201,7 +237,7 @@
 	if (!recip)
 	    BUG (0);
 	recip[0].ulRecipClass = MAPI_TO;
-	p = recip[0].lpszName = strdup (to->uids->uid);	
+	p = recip[0].lpszName = strdup (key->ext->uids->uid);
 	if (!p)    
 	    BUG (0);
 	msg->lpRecips = recip;

Modified: trunk/Src/wptMDSumDlg.cpp
===================================================================
--- trunk/Src/wptMDSumDlg.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptMDSumDlg.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -1,4 +1,4 @@
-/* wptMDSumDlg.cpp
+/* wptMDSumDlg.cpp - Dialog to show hash values for files
  *	Copyright (C) 2003, 2005, 2006 Timo Schulz
  *
  * This file is part of WinPT.
@@ -34,15 +34,72 @@
 #include "wptErrors.h"
 
 
+/* maximum hash size in octets (sha256=32) */
+#define MAX_HASHSIZE 32
+
 /* Symbolic column IDs. */
 enum md_col_t {COL_MD=0, COL_NAME};
 
 
+/* A model which represents the contents of the list view. */
+struct hashlist_model_s {
+    struct hashlist_model_s *next;
+    char *name;
+    BYTE *md;
+    DWORD mdlen;
+};
+typedef struct hashlist_model_s *hashlist_model_t;
+
+
+/* Release the file list @hm. */
+static void
+hashmodel_release (hashlist_model_t hm)
+{
+    hashlist_model_t t;
+
+    while (hm) {
+	t = hm->next;
+	free_if_alloc (hm->name);
+	free_if_alloc (hm->md);
+	free_if_alloc (hm);
+	hm = t;
+    }
+}
+
+
+/* Add a new file with the name @name to the list @hm. */
+static hashlist_model_t
+hashmodel_add_file (hashlist_model_t *hm, const char *name, 
+		    const BYTE *mdbuf, size_t mdlen)
+{
+    hashlist_model_t t, n;
+
+    t = new hashlist_model_s;
+    if (!t)
+	BUG (NULL);
+    memset (t, 0, sizeof *t);
+    t->name = m_strdup (name);
+    t->mdlen = mdlen;
+    t->md = new BYTE[mdlen];
+    if (!t->md)
+	BUG (NULL);
+    memcpy (t->md, mdbuf, mdlen);
+    if (!*hm)
+	*hm = t;
+    else {
+	for (n = *hm; n->next; n=n->next)
+	    ;
+	n->next = t;
+    }
+    return t;
+}
+
+
 /* Return a printable digest of the buffer @mdbuf. */
 static const char*
 printable_digest (BYTE *mdbuf, size_t n)
 {
-    static char mdasc[128];
+    static char mdasc[4*MAX_HASHSIZE];
     size_t i;
 
     for (i = 0; i < n; i++)
@@ -59,6 +116,8 @@
     case GPGME_MD_SHA1:	    return "SHA1";
     case GPGME_MD_RMD160:   return "RMD160";
     case GPGME_MD_SHA256:   return "SHA256";
+    case GPGME_MD_SHA384:   return "SHA384";
+    case GPGME_MD_SHA512:   return "SHA512";
     default:		    break;
     }
     return "";
@@ -68,21 +127,23 @@
 /* Hash the selected file from the FM listview control in @md.
    Add the results to the listview @lv. */
 static void
-hash_selected_files (md_file_s *md, listview_ctrl_t lv)
+hash_selected_files (md_file_s *md, listview_ctrl_t lv, hashlist_model_t *r_fl)
 {
-    BYTE mdbuf[32];
+    hashlist_model_t item;
+    BYTE mdbuf[MAX_HASHSIZE];
     char fname[256+1];
+    size_t n;
     int i;
-    size_t n;
 
     for (i = 0; i < listview_count_items (md->lv, 0); i++) {
-	if (listview_get_item_state (md->lv, i)) {
-	    listview_get_item_text (md->lv, i, 1, fname, sizeof (fname)-1);
-	    if (!gpg_md_hash_file (md->mdalgo, fname, mdbuf, &n)) {
-		listview_add_item (lv, "");
-		listview_add_sub_item (lv, 0, COL_MD, printable_digest (mdbuf, n));
-		listview_add_sub_item (lv, 0, COL_NAME, fname);	
-	    }   
+	if (!listview_get_item_state (md->lv, i))
+	    continue;
+	listview_get_item_text (md->lv, i, 1, fname, sizeof (fname)-1);
+	if (!gpg_md_hash_file (md->mdalgo, fname, mdbuf, &n)) {
+	    item = hashmodel_add_file (r_fl, fname, mdbuf, n);
+	    listview_add_item2 (lv, "", (void*)item);
+	    listview_add_sub_item (lv, 0, COL_MD, printable_digest (mdbuf, n));
+	    listview_add_sub_item (lv, 0, COL_NAME, fname);
 	}	
     }
 }
@@ -99,14 +160,31 @@
 }
 
 
+/* Sorting callback. */
+static int CALLBACK
+sort_cb (LPARAM first, LPARAM second, LPARAM param)
+{
+    hashlist_model_t a, b;
+    int sortby = (int)param;
+    int cmpres = 0;
 
+    a = (hashlist_model_t)first;
+    b = (hashlist_model_t)second;
+    if (sortby == COL_NAME)
+	cmpres = stricmp (a->name, b->name);
+    else
+	cmpres = memcmp (a->md, b->md, a->mdlen);
+    return cmpres;
+}
 
+
 /* Dialog box procedure to show and calculate file digests. */
 BOOL CALLBACK
 mdsum_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
 {
     static listview_ctrl_t lv;
     static struct md_file_s *md;
+    static hashlist_model_t hm = NULL;
     struct listview_column_s cols[] = {
         {0, 264, (char *)_("Digest")},
         {1, 160, (char *)_("Name")},
@@ -114,7 +192,7 @@
     };
     gpgme_data_t sumlist;
     const char *name, *algname;
-    char fname[300], mdasc[128];
+    char fname[MAX_PATH+64], mdasc[MAX_HASHSIZE*4];
     int i;
 
     switch (msg) {
@@ -125,7 +203,7 @@
 	listview_new (&lv, GetDlgItem (dlg, IDC_MDSUM_LIST));
 	for (i = 0; i < cols[i].width; i++)
 	    listview_add_column (lv, &cols[i]);
-	hash_selected_files (md, lv);
+	hash_selected_files (md, lv, &hm);
 	SetDlgItemText (dlg, IDC_MDSUM_COPY, _("&Save..."));
 	SetDlgItemText (dlg, IDOK, _("&Close"));
 	SetDlgItemText (dlg, IDC_MDSUM_TOCLIP, _("Save to clipboard"));
@@ -138,8 +216,19 @@
 	    listview_release (lv);
 	    lv = NULL;
 	}
+	if (hm) {
+	    hashmodel_release (hm);
+	    hm = NULL;
+	}
 	break;
 
+    case WM_NOTIFY:
+	if (((NMHDR *)lparam)->code == LVN_COLUMNCLICK) {
+	    NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
+	    ListView_SortItems (lv->ctrl, sort_cb, nft->iSubItem);
+	}
+	break;
+
     case WM_COMMAND:
 	switch (LOWORD (wparam)) {
 	case IDOK:

Modified: trunk/Src/wptMainProc.cpp
===================================================================
--- trunk/Src/wptMainProc.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptMainProc.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -390,7 +390,8 @@
 
 	    gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1;
 
-	    wait_for_progress_cb ();
+	    if (!wait_for_progress_cb (0))
+		break;
             SetForegroundWindow (hwnd);
             GetCursorPos (&p);
             hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT));
@@ -433,7 +434,8 @@
             break;
             
         case WM_LBUTTONDBLCLK:
-	    wait_for_progress_cb ();
+	    if (!wait_for_progress_cb (0))
+		break;
 	    gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1;
             SendMessage (hwnd, WM_COMMAND, ID_WINPT_KEY, 0);
             break;

Modified: trunk/Src/wptProgressDlg.cpp
===================================================================
--- trunk/Src/wptProgressDlg.cpp	2006-07-03 14:10:00 UTC (rev 243)
+++ trunk/Src/wptProgressDlg.cpp	2006-07-03 14:10:21 UTC (rev 244)
@@ -100,13 +100,17 @@
 }
 
 
-/* Wait until the progress thread terminates. */
-void
-wait_for_progress_cb (void)
+/* Wait the given time @millis for the progress thread
+   but only if it is active. Return state of the thread.
+   Return value: 1 if signaled or done. */
+int
+wait_for_progress_cb (DWORD millis)
 {
     if (!curr_thread)
-	return;
-    WaitForSingleObject (curr_thread, INFINITE);
+	return 1;
+    if (WaitForSingleObject (curr_thread, millis) == WAIT_OBJECT_0)
+	return 1;
+    return 0;
 }
 
 
@@ -117,7 +121,7 @@
     struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
     DWORD tid;
 
-    log_debug ("progress enter %d %d\r\n", off, max);
+    /*log_debug ("progress enter %d %d\r\n", off, max);*/
     if (!pfx || pfx->error)
 	return;
     if (what)



More information about the Winpt-commits mailing list