forked from sba1/simplemail
-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.c
346 lines (294 loc) · 10.1 KB
/
status.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/***************************************************************************
SimpleMail - Copyright (C) 2000 Hynek Schlawack and Sebastian Bauer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
/**
* @file status.c
*
* @note TODO: This status stuff needs an overhaul.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "atcleanup.h"
#include "debug.h"
#include "estimate.h"
#include "smintl.h"
#include "status.h"
#include "support.h"
#include "support_indep.h"
#include "mainwnd.h"
#include "statuswnd.h"
static struct estimate gauge_est;
static int gauge_maximal;
static int gauge_value;
static int mail_maximal;
static int mail_current; /* starts at 1 */
static int mail_current_size; /* size of current mail */
static char *status_text;
static char *status_head;
static char *status_line;
static int status_cleanup_registered;
/**
* Cleanup resources.
*
* @param user_data
*/
static void status_cleanup(void *user_data)
{
free(status_line);
free(status_text);
free(status_head);
}
/******************************************************************
Returns the status text
*******************************************************************/
static char *status_get_status(char *msg)
{
static char buf[128];
static char time_buf[64];
int time = estimate_calc_remaining(&gauge_est,gauge_value/1024);
if (time < 60) sm_snprintf(time_buf,sizeof(time_buf),_("%d s"),time);
else sm_snprintf(time_buf,sizeof(time_buf),_("%d min %d s"),time/60,time%60);
if (msg) sm_snprintf(buf,sizeof(buf),"%s\n%s %s",msg,_("Time remaining:"),time_buf);
else return time_buf;
return buf;
}
static char *status_get_time_str(void)
{
static char time_buf[64];
int time = estimate_calc_remaining(&gauge_est,gauge_value/1024);
if (time < 60) sm_snprintf(time_buf,sizeof(time_buf),_("%d s"),time);
else sm_snprintf(time_buf,sizeof(time_buf),_("%d min %d s"),time/60,time%60);
return time_buf;
}
/******************************************************************
Initialize the window with as the given type
*******************************************************************/
void status_init(int type)
{
status_mail_list_clear();
}
/******************************************************************
Opens the status window.
*******************************************************************/
int status_open(void)
{
return statuswnd_open(1);
}
/******************************************************************
Opens the status window but doesn't not activate it.
*******************************************************************/
int status_open_notactivated(void)
{
return statuswnd_open(0);
}
/******************************************************************
...
*******************************************************************/
void status_close(void)
{
statuswnd_close();
}
/******************************************************************
Set the title of the status window
*******************************************************************/
void status_set_title(char *title)
{
statuswnd_set_title(title);
}
/******************************************************************
Set the title of the status window
*******************************************************************/
void status_set_title_utf8(char *title)
{
statuswnd_set_title_utf8(title);
}
/******************************************************************
Set the status line for connecting to a server
*******************************************************************/
void status_set_connect_to_server(char *server)
{
static char buf[80];
sm_snprintf(buf,sizeof(buf),_("Connecting to server %s..."),server);
statuswnd_set_status(buf);
}
/******************************************************************
Sets the gauge to a maximal value and tell that it's a bytes
gauge
*******************************************************************/
void status_init_gauge_as_bytes(int maximal)
{
estimate_init(&gauge_est,maximal/1024);
gauge_maximal = maximal;
gauge_value = 0;
statuswnd_init_gauge(maximal);
}
/******************************************************************
Sets the gauge current value
*******************************************************************/
void status_set_gauge(int value)
{
static char status_buf[100];
static char gauge_buf[256];
static int last_seconds;
int seconds = sm_get_current_seconds();
gauge_value = value;
if (last_seconds == seconds) return;
sm_snprintf(gauge_buf,sizeof(gauge_buf),_("%d KB / %d KB (time left: %s)"), gauge_value / 1024, gauge_maximal / 1024, status_get_time_str());
statuswnd_set_gauge(value);
statuswnd_set_gauge_text(gauge_buf);
sm_snprintf(status_buf,sizeof(status_buf),_("Processing mail %d (%d KB) of %d"),mail_current,mail_current_size / 1024, mail_maximal);
statuswnd_set_status(status_buf);
last_seconds = seconds;
}
/******************************************************************
Set the status line
*******************************************************************/
void status_set_line(char *str)
{
free(status_line);
status_line = mystrdup(str);
statuswnd_set_status(status_get_status(status_line));
if (!status_cleanup_registered)
{
atcleanup(status_cleanup,NULL);
status_cleanup_registered = 1;
}
}
/******************************************************************
Set the status text
*******************************************************************/
void status_set_status(char *str)
{
free(status_text);
status_text = mystrdup(str);
statuswnd_set_status(status_text);
main_set_status_text(status_text);
if (!status_cleanup_registered)
{
atcleanup(status_cleanup,NULL);
status_cleanup_registered = 1;
}
}
/******************************************************************
Set the head of the status window
*******************************************************************/
void status_set_head(char *head)
{
free(status_head);
status_head = mystrdup(head);
statuswnd_set_head(status_head);
if (!status_cleanup_registered)
{
atcleanup(status_cleanup,NULL);
status_cleanup_registered = 1;
}
}
/******************************************************************
Initialize the number of mails to download
*******************************************************************/
void status_init_mail(int maximal)
{
mail_maximal = maximal;
mail_current = 0;
}
/******************************************************************
Set the current mail
*******************************************************************/
void status_set_mail(int current, int current_size)
{
mail_current = current;
mail_current_size = current_size;
}
/******************************************************************
Insert a mail into the status mail list which turns it into
a mail selection window
*******************************************************************/
void status_mail_list_insert(int mno, int mflags, int msize)
{
statuswnd_mail_list_insert(mno,mflags,msize);
}
/******************************************************************
Set the flags of the given mail number
*******************************************************************/
void status_mail_list_set_flags(int mno, int mflags)
{
statuswnd_mail_list_set_flags(mno,mflags);
}
/******************************************************************
Set some additional infos to the given mail. The mail has to be
inserted before.
*******************************************************************/
void status_mail_list_set_info(int mno, char *from, char *subject, char *date)
{
statuswnd_mail_list_set_info(mno,from,subject,date);
}
/******************************************************************
Returns mail flags for the given mail. Returns -1 if mail is not
in the mail selection
*******************************************************************/
int status_mail_list_get_flags(int mno)
{
return statuswnd_mail_list_get_flags(mno);
}
/******************************************************************
Clears the mail list
*******************************************************************/
void status_mail_list_clear(void)
{
statuswnd_mail_list_clear();
}
/******************************************************************
Freezes the mail list.
*******************************************************************/
void status_mail_list_freeze(void)
{
statuswnd_mail_list_freeze();
}
/******************************************************************
Thaws the mail list.
*******************************************************************/
void status_mail_list_thaw(void)
{
statuswnd_mail_list_thaw();
}
/******************************************************************
Wait's for user interaction. Returns 0 for negative respone
(aborting) otherwise another value
*******************************************************************/
int status_wait(void)
{
return statuswnd_wait();
}
/******************************************************************
Returns wheather the current server should be skipped
*******************************************************************/
int status_skipped(void)
{
return statuswnd_skipped();
}
/******************************************************************
Returns 0 if user has aborted the statistic listing
*******************************************************************/
int status_more_statistics(void)
{
return statuswnd_more_statistics();
}
/******************************************************************
Check if the current transfering should be aborted
*******************************************************************/
int status_check_abort(void)
{
return 0;
}