/[winpt]/trunk/Src/wptProgressDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptProgressDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3723 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptProgressDlg.cpp - Support for the GPG progress status
2 twoaday 5 * Copyright (C) 2003, 2004, 2005 Timo Schulz
3 twoaday 2 *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #include <windows.h>
22     #include <commctrl.h>
23    
24     #include "../resource.h"
25     #include "wptGPG.h"
26     #include "wptTypes.h"
27     #include "wptCommonCtl.h"
28     #include "wptW32API.h"
29     #include "wptContext.h"
30     #include "wptVersion.h"
31    
32 twoaday 23 /* Handle to the dialog window. */
33 twoaday 2 static HWND progress_dlg = NULL;
34    
35 twoaday 23
36     /* Dialog procedure to show the progress of an operation. */
37 twoaday 2 static BOOL CALLBACK
38     progress_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
39     {
40     static progress_filter_s * pfx = NULL;
41    
42     switch (msg) {
43     case WM_INITDIALOG:
44     pfx = (struct progress_filter_s *)lparam;
45     if (!pfx)
46     BUG (0);
47     progress_dlg = dlg;
48     pfx->dlg = dlg;
49     SendDlgItemMessage (dlg, IDC_PROGRESS_BAR, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
50     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_TOTAL, pfx->total, FALSE);
51     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
52     SetDlgItemText (pfx->dlg, IDC_PROGRESS_WHAT, pfx->what);
53 twoaday 23 center_window2 (dlg, NULL, HWND_TOPMOST);
54     center_window (dlg, NULL);
55 twoaday 2 SetForegroundWindow (dlg);
56     return TRUE;
57     }
58     return FALSE;
59 twoaday 23 }
60 twoaday 2
61    
62 twoaday 23 /* Thread to start the progress dialog.
63     @opaque contains the context for the dialog. */
64 twoaday 2 static DWORD WINAPI
65 twoaday 23 progress_cb_thread (void *opaque)
66 twoaday 2 {
67 twoaday 4 struct progress_filter_s * pfx = (struct progress_filter_s *)opaque;
68    
69     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PROGRESS,
70     opaque? pfx->hwnd : GetActiveWindow (),
71 twoaday 2 progress_dlg_proc, (LPARAM)opaque);
72     return TRUE;
73 twoaday 23 }
74 twoaday 2
75    
76 twoaday 23 /* Close the progress dialog (if still open) and close all handles in @pfx. */
77 twoaday 2 void
78     progress_cleanup (progress_filter_s * pfx)
79     {
80     EndDialog (progress_dlg, TRUE);
81     if (!pfx)
82     return;
83     if (pfx->dlg) {
84     EndDialog (pfx->dlg, TRUE);
85     pfx->dlg = NULL;
86     }
87     if (pfx->thread_hd) {
88     CloseHandle (pfx->thread_hd);
89     pfx->thread_hd = NULL;
90     }
91     pfx->curr = 0;
92     pfx->total = 0;
93     pfx->error = 0;
94 twoaday 5 memset (pfx, 0, sizeof *pfx); /*XXX: does this really work? */
95 twoaday 2 }
96    
97    
98 twoaday 23 /* GPGME callback for the progress. */
99 twoaday 2 void
100 twoaday 23 progress_callback (void * opaque, const char * what, int type, int off, int max)
101 twoaday 2 {
102     struct progress_filter_s * pfx = (struct progress_filter_s *)opaque;
103     DWORD tid;
104    
105     if (!pfx || pfx->error)
106     return;
107     pfx->curr = off;
108     pfx->total = max;
109     pfx->what = what;
110     if (!off && !pfx->thread_hd) {
111     pfx->thread_hd = CreateThread (NULL, 0, progress_cb_thread, (void *)pfx, 0, &tid);
112     if (!pfx->thread_hd) {
113     msg_box (NULL, _("Could not create progress thread."), _("WinPT"), MB_ERR);
114     pfx->error = 1;
115     return;
116     }
117     }
118     else if (pfx->dlg) {
119     size_t n = pfx->curr * 100 / pfx->total;
120     SendDlgItemMessage (pfx->dlg, IDC_PROGRESS_BAR, PBM_SETPOS, (WPARAM)n, 0);
121     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
122     }
123     if (off >= max)
124     progress_cleanup (pfx);
125 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26