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

Annotation of /trunk/Src/wptProgressDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 3939 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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 twoaday 25 #include "wptErrors.h"
32 twoaday 2
33 twoaday 23 /* Handle to the dialog window. */
34 twoaday 2 static HWND progress_dlg = NULL;
35    
36 twoaday 23
37     /* Dialog procedure to show the progress of an operation. */
38 twoaday 2 static BOOL CALLBACK
39     progress_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
40     {
41     static progress_filter_s * pfx = NULL;
42    
43     switch (msg) {
44     case WM_INITDIALOG:
45     pfx = (struct progress_filter_s *)lparam;
46     if (!pfx)
47     BUG (0);
48     progress_dlg = dlg;
49     pfx->dlg = dlg;
50 twoaday 25 SendDlgItemMessage (dlg, IDC_PROGRESS_BAR,
51     PBM_SETRANGE, 0, MAKELPARAM (0, 100));
52 twoaday 2 SetDlgItemInt (pfx->dlg, IDC_PROGRESS_TOTAL, pfx->total, FALSE);
53     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
54     SetDlgItemText (pfx->dlg, IDC_PROGRESS_WHAT, pfx->what);
55 twoaday 23 center_window2 (dlg, NULL, HWND_TOPMOST);
56     center_window (dlg, NULL);
57 twoaday 2 SetForegroundWindow (dlg);
58     return TRUE;
59     }
60     return FALSE;
61 twoaday 23 }
62 twoaday 2
63    
64 twoaday 23 /* Thread to start the progress dialog.
65     @opaque contains the context for the dialog. */
66 twoaday 2 static DWORD WINAPI
67 twoaday 23 progress_cb_thread (void *opaque)
68 twoaday 2 {
69 twoaday 25 struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
70 twoaday 4
71     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PROGRESS,
72 twoaday 25 pfx? pfx->hwnd : GetActiveWindow (),
73 twoaday 2 progress_dlg_proc, (LPARAM)opaque);
74 twoaday 25 ExitThread (0);
75 twoaday 2 return TRUE;
76 twoaday 23 }
77 twoaday 2
78    
79 twoaday 23 /* Close the progress dialog (if still open) and close all handles in @pfx. */
80 twoaday 2 void
81 twoaday 25 progress_cleanup (progress_filter_s *pfx)
82 twoaday 2 {
83     EndDialog (progress_dlg, TRUE);
84     if (!pfx)
85     return;
86     if (pfx->dlg) {
87     EndDialog (pfx->dlg, TRUE);
88     pfx->dlg = NULL;
89     }
90     if (pfx->thread_hd) {
91     CloseHandle (pfx->thread_hd);
92     pfx->thread_hd = NULL;
93     }
94     pfx->curr = 0;
95     pfx->total = 0;
96     pfx->error = 0;
97 twoaday 5 memset (pfx, 0, sizeof *pfx); /*XXX: does this really work? */
98 twoaday 2 }
99    
100    
101 twoaday 25 /* Generic callback for operations with a progress bar. */
102 twoaday 2 void
103 twoaday 25 progress_callback (void *opaque, const char *what, int type, int off, int max)
104 twoaday 2 {
105 twoaday 25 struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
106 twoaday 2 DWORD tid;
107    
108 twoaday 25 log_debug ("progress enter %d %d\r\n", off, max);
109 twoaday 2 if (!pfx || pfx->error)
110     return;
111 twoaday 25 if (what)
112     pfx->what = what;
113 twoaday 2 pfx->curr = off;
114     pfx->total = max;
115     if (!off && !pfx->thread_hd) {
116     pfx->thread_hd = CreateThread (NULL, 0, progress_cb_thread, (void *)pfx, 0, &tid);
117     if (!pfx->thread_hd) {
118     msg_box (NULL, _("Could not create progress thread."), _("WinPT"), MB_ERR);
119     pfx->error = 1;
120     return;
121     }
122 twoaday 25 log_debug ("progress_callback: started thread %08lX\r\n", tid);
123 twoaday 2 }
124 twoaday 25 else if (pfx->dlg != NULL) {
125 twoaday 2 size_t n = pfx->curr * 100 / pfx->total;
126     SendDlgItemMessage (pfx->dlg, IDC_PROGRESS_BAR, PBM_SETPOS, (WPARAM)n, 0);
127     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
128     }
129 twoaday 25 if (off >= max) {
130 twoaday 2 progress_cleanup (pfx);
131 twoaday 25 }
132 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26