~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to alpine/osdep/termout.wnt.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !defined(lint) && !defined(DOS)
 
2
static char rcsid[] = "$Id: termout.unx.c 159 2006-10-02 22:00:13Z hubert@u.washington.edu $";
 
3
#endif
 
4
 
 
5
/*
 
6
 * ========================================================================
 
7
 * Copyright 2006-2007 University of Washington
 
8
 *
 
9
 * Licensed under the Apache License, Version 2.0 (the "License");
 
10
 * you may not use this file except in compliance with the License.
 
11
 * You may obtain a copy of the License at
 
12
 *
 
13
 *     http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
15
 * ========================================================================
 
16
 */
 
17
#include <system.h>
 
18
#include <general.h>
 
19
 
 
20
#include "../../c-client/mail.h"        /* for MAILSTREAM and friends */
 
21
#include "../../c-client/osdep.h"
 
22
#include "../../c-client/rfc822.h"      /* for soutr_t and such */
 
23
#include "../../c-client/misc.h"        /* for cpystr proto */
 
24
#include "../../c-client/utf8.h"        /* for CHARSET and such*/
 
25
#include "../../c-client/imap4r1.h"
 
26
 
 
27
#include "../../pith/osdep/color.h"
 
28
 
 
29
#include "../../pith/charconv/filesys.h"
 
30
 
 
31
#include "../../pith/debug.h"
 
32
#include "../../pith/conf.h"
 
33
#include "../../pith/newmail.h"
 
34
 
 
35
#include "../../pico/estruct.h"
 
36
#include "../../pico/pico.h"
 
37
#include "../../pico/keydefs.h"
 
38
 
 
39
#include "../../pico/osdep/mswin.h"
 
40
 
 
41
#include "../flagmaint.h"
 
42
 
 
43
#include "termout.wnt.h"
 
44
 
 
45
/*======================================================================
 
46
       Routines for painting the screen
 
47
          - figure out what the terminal type is
 
48
          - deal with screen size changes
 
49
          - save special output sequences
 
50
          - the usual screen clearing, cursor addressing and scrolling
 
51
 
 
52
 
 
53
     This library gives programs the ability to easily access the
 
54
     termcap information and write screen oriented and raw input
 
55
     programs.  The routines can be called as needed, except that
 
56
     to use the cursor / screen routines there must be a call to
 
57
     InitScreen() first.  The 'Raw' input routine can be used
 
58
     independently, however. (Elm comment)
 
59
 
 
60
     Not sure what the original source of this code was. It got to be
 
61
     here as part of ELM. It has been changed significantly from the
 
62
     ELM version to be more robust in the face of inconsistent terminal
 
63
     autowrap behaviour. Also, the unused functions were removed, it was
 
64
     made to pay attention to the window size, and some code was made nicer
 
65
     (in my opinion anyways). It also outputs the terminal initialization
 
66
     strings and provides for minimal scrolling and detects terminals
 
67
     with out enough capabilities. (Pine comment, 1990)
 
68
 
 
69
*/
 
70
 
 
71
#define PUTLINE_BUFLEN  256
 
72
 
 
73
static int   _lines, _columns;
 
74
 
 
75
int     config_screen(struct ttyo **);
 
76
 
 
77
BOOL CALLBACK  __export 
 
78
args_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
79
 
 
80
BOOL CALLBACK  __export 
 
81
login_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
82
 
 
83
BOOL CALLBACK  __export 
 
84
flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
85
 
 
86
BOOL CALLBACK  __export 
 
87
sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
88
 
 
89
BOOL CALLBACK  __export 
 
90
config_vars_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
91
 
 
92
BOOL CALLBACK  __export 
 
93
config_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
94
 
 
95
void
 
96
init_screen(void)
 
97
{
 
98
    /*
 
99
     * If we want to show it, turn it on. If we don't care, put it back
 
100
     * to the way it was originally.
 
101
     */
 
102
    mswin_showcaret(F_ON(F_SHOW_CURSOR, ps_global));
 
103
    mswin_trayicon(F_ON(F_ENABLE_TRAYICON, ps_global));
 
104
    return;                                     /* NO OP */
 
105
}
 
106
 
 
107
void
 
108
end_screen(char *message, int exit_val)
 
109
{
 
110
    int footer_rows_was_one = 0;
 
111
 
 
112
    if(panicking())
 
113
      return;
 
114
 
 
115
    if(FOOTER_ROWS(ps_global) == 1){
 
116
        footer_rows_was_one++;
 
117
        FOOTER_ROWS(ps_global) = 3;
 
118
        mark_status_unknown();
 
119
    }
 
120
 
 
121
    flush_status_messages(exit_val ? 0 : 1);
 
122
 
 
123
    blank_keymenu(_lines - 2, 0);
 
124
 
 
125
    if(message){
 
126
        StartInverse();
 
127
        PutLine0(_lines - 2, 0, message);
 
128
    }
 
129
    
 
130
    EndInverse();
 
131
 
 
132
    MoveCursor(_lines - 1, 0);
 
133
 
 
134
    mswin_showcaret(F_ON(F_SHOW_CURSOR, ps_global));
 
135
 
 
136
    if(footer_rows_was_one){
 
137
        FOOTER_ROWS(ps_global) = 1;
 
138
        mark_status_unknown();
 
139
    }
 
140
}
 
141
 
 
142
/*----------------------------------------------------------------------
 
143
      Initialize the screen for output, set terminal type, etc
 
144
 
 
145
   Args: tt -- Pointer to variable to store the tty output structure.
 
146
 
 
147
 Result:  terminal size is discovered and set pine state
 
148
          termcap entry is fetched and stored in local variables
 
149
          make sure terminal has adequate capabilites
 
150
          evaluate scrolling situation
 
151
          returns status of indicating the state of the screen/termcap entry
 
152
 
 
153
      Returns:
 
154
        -1 indicating no terminal name associated with this shell,
 
155
        -2..-n  No termcap for this terminal type known
 
156
        -3 Can't open termcap file 
 
157
        -4 Terminal not powerful enough - missing clear to eoln or screen
 
158
                                               or cursor motion
 
159
 
 
160
  ----*/
 
161
int
 
162
config_screen(struct ttyo **tt)
 
163
{
 
164
    struct ttyo *ttyo;
 
165
 
 
166
    _line  =  0;                /* where are we right now?? */
 
167
    _col   =  0;                /* assume zero, zero...     */
 
168
 
 
169
    mswin_getscreensize(&_lines, &_columns);
 
170
    if (_lines > MAX_SCREEN_ROWS)
 
171
        _lines = MAX_SCREEN_ROWS;
 
172
    if (_columns > MAX_SCREEN_COLS)
 
173
        _columns = MAX_SCREEN_COLS;
 
174
 
 
175
    ttyo = (struct ttyo *)fs_get(sizeof(struct ttyo));
 
176
    ttyo->screen_cols = _columns;
 
177
    ttyo->screen_rows = _lines ;
 
178
    ttyo->header_rows = 2;
 
179
    ttyo->footer_rows = 3;
 
180
 
 
181
    *tt = ttyo;
 
182
 
 
183
    return(0);
 
184
}
 
185
 
 
186
/*----------------------------------------------------------------------
 
187
       Get the current window size
 
188
  
 
189
   Args: ttyo -- pointer to structure to store window size in
 
190
 
 
191
  NOTE: we don't override the given values unless we know better
 
192
 ----*/
 
193
int
 
194
get_windsize(struct ttyo *ttyo)
 
195
{
 
196
    char        fontName[LF_FACESIZE+1];
 
197
    char        fontSize[12];
 
198
    char        fontStyle[64];
 
199
    char        fontCharSet[256];
 
200
    char        windowPosition[32], windowPositionReg[32];
 
201
    char        foreColor[64], backColor[64];
 
202
    int         newRows, newCols;
 
203
    char        cursorStyle[32];
 
204
 
 
205
    cursorStyle[0] = '\0';
 
206
 
 
207
    /* Get the new window parameters and update the 'pinerc' variables. */
 
208
    mswin_getwindow(fontName, sizeof(fontName), fontSize, sizeof(fontSize),
 
209
                    fontStyle, sizeof(fontStyle),
 
210
                    windowPosition, sizeof(windowPosition),
 
211
                    foreColor, sizeof(foreColor),
 
212
                    backColor, sizeof(backColor),
 
213
                    cursorStyle, sizeof(cursorStyle),
 
214
                    fontCharSet, sizeof(fontCharSet));
 
215
 
 
216
    if(!ps_global->VAR_FONT_NAME
 
217
       || strucmp(ps_global->VAR_FONT_NAME, fontName))
 
218
      set_variable(V_FONT_NAME, fontName, 1, 0,
 
219
                   ps_global->ew_for_except_vars);
 
220
 
 
221
    if(!ps_global->VAR_FONT_SIZE
 
222
       || strucmp(ps_global->VAR_FONT_SIZE, fontSize))
 
223
      set_variable(V_FONT_SIZE, fontSize, 1, 0,
 
224
                   ps_global->ew_for_except_vars);
 
225
 
 
226
    if(!ps_global->VAR_FONT_STYLE
 
227
       || strucmp(ps_global->VAR_FONT_STYLE, fontStyle))
 
228
      set_variable(V_FONT_STYLE, fontStyle, 1, 0,
 
229
                   ps_global->ew_for_except_vars);
 
230
 
 
231
    if(!ps_global->VAR_FONT_CHAR_SET
 
232
       || strucmp(ps_global->VAR_FONT_CHAR_SET, fontCharSet))
 
233
      set_variable(V_FONT_CHAR_SET, fontCharSet, 1, 0,
 
234
                   ps_global->ew_for_except_vars);
 
235
 
 
236
    if(F_ON(F_STORE_WINPOS_IN_CONFIG, ps_global)){
 
237
        if(!ps_global->VAR_WINDOW_POSITION
 
238
           || strucmp(ps_global->VAR_WINDOW_POSITION, windowPosition))
 
239
          set_variable(V_WINDOW_POSITION, windowPosition, 1, 0,
 
240
                       ps_global->ew_for_except_vars);
 
241
    }
 
242
    else{
 
243
        /*
 
244
         * Get the window position stored in the registry.
 
245
         *
 
246
         * If current window position is not in the registry or is
 
247
         * different from what is there, save it.
 
248
         */
 
249
        if(strnicmp(windowPosition, "MIN0", 4)
 
250
           && (!mswin_reg(MSWR_OP_GET, MSWR_PINE_POS, windowPositionReg,
 
251
                          sizeof(windowPositionReg)) ||
 
252
               strucmp(windowPositionReg, windowPosition))
 
253
           && (ps_global->update_registry != UREG_NEVER_SET))
 
254
          mswin_reg(MSWR_OP_SET | MSWR_OP_FORCE, MSWR_PINE_POS, windowPosition,
 
255
                    (size_t)NULL);
 
256
    }
 
257
    
 
258
    mswin_getprintfont(fontName, sizeof(fontName),
 
259
                       fontSize, sizeof(fontSize),
 
260
                       fontStyle, sizeof(fontStyle),
 
261
                       fontCharSet, sizeof(fontCharSet));
 
262
    if(!ps_global->VAR_PRINT_FONT_NAME
 
263
       || strucmp(ps_global->VAR_PRINT_FONT_NAME, fontName))
 
264
      set_variable(V_PRINT_FONT_NAME, fontName, 1, 0,
 
265
                   ps_global->ew_for_except_vars);
 
266
 
 
267
    if(!ps_global->VAR_PRINT_FONT_SIZE
 
268
       || strucmp(ps_global->VAR_PRINT_FONT_SIZE, fontSize))
 
269
      set_variable(V_PRINT_FONT_SIZE, fontSize, 1, 0,
 
270
                   ps_global->ew_for_except_vars);
 
271
 
 
272
    if(!ps_global->VAR_PRINT_FONT_STYLE
 
273
       || strucmp(ps_global->VAR_PRINT_FONT_STYLE, fontStyle))
 
274
      set_variable(V_PRINT_FONT_STYLE, fontStyle, 1, 0,
 
275
                   ps_global->ew_for_except_vars);
 
276
 
 
277
    if(!ps_global->VAR_PRINT_FONT_CHAR_SET
 
278
       || strucmp(ps_global->VAR_PRINT_FONT_CHAR_SET, fontCharSet))
 
279
      set_variable(V_PRINT_FONT_CHAR_SET, fontCharSet, 1, 0,
 
280
                   ps_global->ew_for_except_vars);
 
281
 
 
282
    if(!ps_global->VAR_NORM_FORE_COLOR
 
283
       || strucmp(ps_global->VAR_NORM_FORE_COLOR, foreColor))
 
284
      set_variable(V_NORM_FORE_COLOR, foreColor, 1, 0,
 
285
                   ps_global->ew_for_except_vars);
 
286
 
 
287
    if(!ps_global->VAR_NORM_BACK_COLOR
 
288
       || strucmp(ps_global->VAR_NORM_BACK_COLOR, backColor))
 
289
      set_variable(V_NORM_BACK_COLOR, backColor, 1, 0,
 
290
                   ps_global->ew_for_except_vars);
 
291
 
 
292
    if(cursorStyle[0] && !ps_global->VAR_CURSOR_STYLE
 
293
       || strucmp(ps_global->VAR_CURSOR_STYLE, cursorStyle))
 
294
      set_variable(V_CURSOR_STYLE, cursorStyle, 1, 0,
 
295
                   ps_global->ew_for_except_vars);
 
296
 
 
297
    /* Get new window size.  Compare to old.  The window may have just
 
298
     * moved, in which case we don't bother updating the size. */
 
299
    mswin_getscreensize(&newRows, &newCols);
 
300
    if (newRows == ttyo->screen_rows && newCols == ttyo->screen_cols)
 
301
            return (NO_OP_COMMAND);
 
302
 
 
303
    /* True resize. */
 
304
    ttyo->screen_rows = newRows;
 
305
    ttyo->screen_cols = newCols;
 
306
 
 
307
    if (ttyo->screen_rows > MAX_SCREEN_ROWS)
 
308
        ttyo->screen_rows = MAX_SCREEN_ROWS;
 
309
    if (ttyo->screen_cols > MAX_SCREEN_COLS)
 
310
        ttyo->screen_cols = MAX_SCREEN_COLS;
 
311
 
 
312
    return(KEY_RESIZE);
 
313
}
 
314
 
 
315
/*----------------------------------------------------------------------
 
316
        Move the cursor to the row and column number
 
317
 Input:  row number
 
318
         column number
 
319
 
 
320
 Result: Cursor moves
 
321
         internal position updated
 
322
  ----------------------------------------------------------------------*/
 
323
void
 
324
MoveCursor(int row, int col)
 
325
{
 
326
    /** move cursor to the specified row column on the screen.
 
327
        0,0 is the top left! **/
 
328
 
 
329
    if(ps_global->in_init_seq)
 
330
      return;
 
331
 
 
332
    /*
 
333
     * This little hack is here for screen readers, for example, a screen
 
334
     * reader associated with a braille display. If we flash the cursor off
 
335
     * and on in the same position, the reader will be drawn to it. Since we
 
336
     * are calling MoveCursor every time through the message viewing loops we
 
337
     * need to suppress the calls if they aren't really doing anything.
 
338
     * However, mswin_move actually does more than just move the cursor.
 
339
     * It also call FlushAccum(), which is necessary in some cases. For
 
340
     * example, in optionally_enter the user is typing characters in and
 
341
     * the FlushAccum() allows them to show up on the screen. The putblock
 
342
     * call is a quick hack to get the Flush_Accum() call, which is all
 
343
     * the putblock does when the arg is NULL.
 
344
     */
 
345
    if(row == _line && col == _col){
 
346
        mswin_putblock(NULL, 0);
 
347
        return;
 
348
    }
 
349
 
 
350
    mswin_move(row, col);
 
351
    _line = row;
 
352
    _col = col;
 
353
}
 
354
 
 
355
 
 
356
/*----------------------------------------------------------------------
 
357
    Write a character to the screen, keeping track of cursor position
 
358
 
 
359
 Input:  charater to write
 
360
 
 
361
 Result: character output
 
362
         cursor position variables updated
 
363
  ----------------------------------------------------------------------*/
 
364
void
 
365
Writewchar(UCS ucs)
 
366
{
 
367
    int width;
 
368
 
 
369
    if(ps_global->in_init_seq)
 
370
      return;
 
371
 
 
372
    switch(ucs){
 
373
      case LINE_FEED :
 
374
        _line = min(_line+1,ps_global->ttyo->screen_rows);
 
375
        _col =0;
 
376
        mswin_move(_line, _col);
 
377
        break;
 
378
 
 
379
      case RETURN :             /* move to column 0 */
 
380
        _col = 0;
 
381
        mswin_move(_line, _col);
 
382
 
 
383
      case BACKSPACE :          /* move back a space if not in column 0 */
 
384
        if(_col > 0)
 
385
          mswin_move(_line, --_col);
 
386
 
 
387
        break;
 
388
        
 
389
      case BELL :               /* ring the bell but don't advance _col */
 
390
        mswin_beep();           /* libpico call */
 
391
        break;
 
392
 
 
393
      case TAB:                 /* if a tab, output it */
 
394
        do
 
395
          mswin_putc(' ');
 
396
        while(((++_col)&0x07) != 0);
 
397
        break;
 
398
 
 
399
      default:
 
400
        /* pass_ctrl_chars is always 1 for Windows */
 
401
        width = wcellwidth(ucs);
 
402
        if(width < 0)
 
403
          mswin_putc('?');
 
404
        else{
 
405
            if(_col + width > ps_global->ttyo->screen_cols){
 
406
                _col = 0;
 
407
                if(_line + 1 < ps_global->ttyo->screen_rows)
 
408
                  _line++;
 
409
                mswin_move(_line, _col);
 
410
            }
 
411
            mswin_putc(ucs);
 
412
            _col += width;
 
413
        }
 
414
    }
 
415
 
 
416
    if(_col == ps_global->ttyo->screen_cols) {
 
417
          _col  = 0;
 
418
          if(_line + 1 < ps_global->ttyo->screen_rows)
 
419
            _line++;
 
420
 
 
421
          mswin_move(_line, _col);
 
422
    }
 
423
 
 
424
    return;
 
425
}
 
426
 
 
427
 
 
428
/*----------------------------------------------------------------------
 
429
      Printf style write directly to the terminal at current position
 
430
 
 
431
 Input: printf style control string
 
432
        number of printf style arguments
 
433
        up to three printf style arguments
 
434
 
 
435
 Result: Line written to the screen
 
436
  ----------------------------------------------------------------------*/
 
437
void
 
438
Write_to_screen(char *string)
 
439
{
 
440
    if(ps_global->in_init_seq)
 
441
      return;
 
442
 
 
443
    mswin_puts (string);
 
444
    
 
445
    /*
 
446
     * mswin_puts does not keep track of where we are. Simple fix is to
 
447
     * reset _line and _col to unknown so that the next MoveCursor will
 
448
     * do a real move. We could check for a simple string and actually
 
449
     * keep track. Is that useful? I don't think so.
 
450
     *
 
451
     * There are other places where we lose track, but by comparing with
 
452
     * the termout.unx code where we also lose track it would seem we don't
 
453
     * really need to keep track in those other cases.
 
454
     */
 
455
    _line  = FARAWAY;
 
456
    _col   = FARAWAY;
 
457
}
 
458
 
 
459
void
 
460
Write_to_screen_n(char *string, int n)
 
461
{
 
462
    if(ps_global->in_init_seq)
 
463
      return;
 
464
 
 
465
    mswin_puts_n (string, n);
 
466
    _line  = FARAWAY;
 
467
    _col   = FARAWAY;
 
468
}
 
469
 
 
470
 
 
471
/*----------------------------------------------------------------------
 
472
     Clear the terminal screen
 
473
  ----------------------------------------------------------------------*/
 
474
void
 
475
ClearScreen(void)
 
476
{
 
477
    _line = 0;                  /* clear leaves us at top... */
 
478
    _col  = 0;
 
479
 
 
480
    if(ps_global->in_init_seq)
 
481
      return;
 
482
 
 
483
    mark_status_unknown();
 
484
    mark_keymenu_dirty();
 
485
    mark_titlebar_dirty();
 
486
 
 
487
    mswin_move(0, 0);
 
488
    mswin_eeop();
 
489
}
 
490
 
 
491
/*----------------------------------------------------------------------
 
492
    Clear screen to end of line on current line
 
493
  ----------------------------------------------------------------------*/
 
494
void
 
495
CleartoEOLN(void)
 
496
{
 
497
    mswin_eeol();
 
498
}
 
499
 
 
500
 
 
501
/*----------------------------------------------------------------------
 
502
     function to output string such that it becomes icon text
 
503
 
 
504
   Args: s -- string to write
 
505
 
 
506
 Result: string indicated become our "icon" text
 
507
  ----*/
 
508
void
 
509
icon_text(char *s, int type)
 
510
{
 
511
    if(type == IT_MCLOSED)
 
512
      mswin_mclosedtext (s);
 
513
    else    /* IT_NEWMAIL */
 
514
      mswin_newmailtext (s);
 
515
}
 
516
 
 
517
/* Scroll stuff */
 
518
 
 
519
/*
 
520
 * Set the current position of the scroll bar.
 
521
 */
 
522
void
 
523
scroll_setpos(long newpos)
 
524
{
 
525
    mswin_setscrollpos (newpos);
 
526
}
 
527
 
 
528
/*
 
529
 * Set the range of the scroll bar.  
 
530
 * zero disables the scroll bar.
 
531
 */
 
532
void
 
533
scroll_setrange (long pagelen, long rangeend)
 
534
{
 
535
    if(rangeend < pagelen)
 
536
      mswin_setscrollrange (0L, 0L);
 
537
    else
 
538
      mswin_setscrollrange (pagelen, rangeend + pagelen - 1L);
 
539
}
 
540
 
 
541
void
 
542
EndScroll(void)
 
543
{
 
544
}
 
545
 
 
546
int
 
547
ScrollRegion(int lines)
 
548
{
 
549
    return(-1);
 
550
}
 
551
 
 
552
int
 
553
BeginScroll(int top, int bottom)
 
554
{
 
555
    static int __t, __b;
 
556
 
 
557
    __t = top;
 
558
    __b = bottom;
 
559
    return(-1);
 
560
}
 
561
 
 
562
 
 
563
/* Dialog stuff */
 
564
#define WINDOW_USER_DATA GWL_USERDATA
 
565
 
 
566
/*===========================================================================
 
567
 *
 
568
 * Dialog Data
 
569
 *
 
570
 * The following structures hold the state data for dialogs.
 
571
 */
 
572
typedef struct DLG_TYPEMAP {
 
573
    int         pineid;
 
574
    int         rsrcid;
 
575
} DLG_TYPEMAP;
 
576
 
 
577
typedef struct DLG_SORTDATA {
 
578
    DLG_SORTPARAM       *sortsel;       /* parameter structure. */
 
579
    int                 sortcount;      /* Number of different sorts. */
 
580
    DLG_TYPEMAP         types[20];      /* Map pine sort types to ctrl ids. */
 
581
} DLG_SORTDATA;
 
582
 
 
583
typedef struct DLG_LOGINDATA {
 
584
    NETMBX              *mb;
 
585
    LPTSTR               user;
 
586
    int                  userlen;
 
587
    LPTSTR               pwd;
 
588
    int                  pwdlen;
 
589
    int                  pwc;  /* set if we're using passfiles and we don't know user yet */
 
590
    int                  fixuser;
 
591
    int                  prespass;  /* if user wants to preserve the password */
 
592
    int                  rv;
 
593
} DLG_LOGINDATA;
 
594
 
 
595
typedef struct DLG_CONFIGDATA {
 
596
    char                *confpath;  /* UTF-8 path */
 
597
    int                  confpathlen;
 
598
    int                  setreg;
 
599
    int                  nopinerc;
 
600
    int                  rv;
 
601
} DLG_CONFIGDATA;
 
602
 
 
603
typedef struct installvars {
 
604
    char *pname;
 
605
    char *userid;
 
606
    char *domain;
 
607
    char *inboxpath;
 
608
    char *smtpserver;
 
609
    unsigned defmailclient:1;
 
610
    unsigned defnewsclient:1;
 
611
} INSTALLVARS_S;
 
612
 
 
613
typedef struct DLG_CONGIGVARSDATA {
 
614
    INSTALLVARS_S *ivars;
 
615
    int            rv;
 
616
} DLG_CONFIGVARSDATA;
 
617
 
 
618
typedef struct DLG_FLAGDATA {
 
619
    struct flag_table   *ftbl;
 
620
    int                 flagcount;
 
621
    HINSTANCE           hInstance;
 
622
    HWND                hTextWnd;
 
623
} DLG_FLAGDATA;
 
624
 
 
625
int  os_config_vars_dialog(INSTALLVARS_S *);
 
626
static void GetBtnPos (HWND, HWND, RECT *);
 
627
 
 
628
int
 
629
init_install_get_vars(void)
 
630
{
 
631
    INSTALLVARS_S ivars;
 
632
    struct pine *ps = ps_global;
 
633
    char *p;
 
634
 
 
635
    memset((void *)&ivars, 0, sizeof(INSTALLVARS_S));
 
636
    if(ps->vars[V_PERSONAL_NAME].main_user_val.p)
 
637
      ivars.pname = cpystr(ps->vars[V_PERSONAL_NAME].main_user_val.p);
 
638
    if(ps->vars[V_USER_ID].main_user_val.p)
 
639
      ivars.userid = cpystr(ps->vars[V_USER_ID].main_user_val.p);
 
640
    if(ps->vars[V_USER_DOMAIN].main_user_val.p)
 
641
      ivars.domain = cpystr(ps->vars[V_USER_DOMAIN].main_user_val.p);
 
642
    if(ps->vars[V_INBOX_PATH].main_user_val.p)
 
643
      ivars.inboxpath = cpystr(ps->vars[V_INBOX_PATH].main_user_val.p);
 
644
    else if(ps->prc && ps->prc->name && (*ps->prc->name == '{')
 
645
            && (p = strindex(ps->prc->name, '}'))){
 
646
        ivars.inboxpath = cpystr(ps->prc->name);
 
647
        if(p = strindex(ivars.inboxpath, '}'))
 
648
          *(p+1) = '\0';
 
649
    }
 
650
    if(ps->vars[V_SMTP_SERVER].main_user_val.l
 
651
        && *ps->vars[V_SMTP_SERVER].main_user_val.l)
 
652
      ivars.smtpserver = cpystr(ps->vars[V_SMTP_SERVER].main_user_val.l[0]);
 
653
    ivars.defmailclient = mswin_is_def_client(MSWR_SDC_MAIL);
 
654
    ivars.defnewsclient = mswin_is_def_client(MSWR_SDC_NEWS);
 
655
 
 
656
    if(os_config_vars_dialog(&ivars) == 0){
 
657
        set_variable(V_PERSONAL_NAME, ivars.pname, 0, 0, Main);
 
658
        set_variable(V_USER_ID, ivars.userid, 0, 0, Main);
 
659
        set_variable(V_USER_DOMAIN, ivars.domain, 0, 0, Main);
 
660
        set_variable(V_INBOX_PATH, ivars.inboxpath, 0, 0, Main);
 
661
        if(ivars.smtpserver){
 
662
            if(ps->vars[V_SMTP_SERVER].main_user_val.l){
 
663
                fs_give((void **)&ps->vars[V_SMTP_SERVER].main_user_val.l[0]);
 
664
                ps->vars[V_SMTP_SERVER].main_user_val.l[0] 
 
665
                  = cpystr(ivars.smtpserver);
 
666
                set_current_val(&ps->vars[V_SMTP_SERVER], TRUE, FALSE);
 
667
            }
 
668
            else {
 
669
                char *tstrlist[2];
 
670
 
 
671
                tstrlist[0] = ivars.smtpserver;
 
672
                tstrlist[1] = NULL;
 
673
                set_variable_list(V_SMTP_SERVER, tstrlist, 0, Main);
 
674
            }
 
675
        }
 
676
        write_pinerc(ps_global, Main, WRP_NONE);
 
677
        if(ivars.defmailclient)
 
678
          mswin_set_def_client(MSWR_SDC_MAIL);
 
679
        if(ivars.defnewsclient)
 
680
          mswin_set_def_client(MSWR_SDC_NEWS);
 
681
 
 
682
        /* Tell Windows that stuff has changed */
 
683
        if(ivars.defmailclient || ivars.defnewsclient)
 
684
          SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
 
685
                             (WPARAM)NULL, (LPARAM)NULL, 
 
686
                             SMTO_NORMAL, 1000, NULL);
 
687
    }
 
688
 
 
689
    if(ivars.pname)
 
690
      fs_give((void **)&ivars.pname);
 
691
    if(ivars.userid)
 
692
      fs_give((void **)&ivars.userid);
 
693
    if(ivars.domain)
 
694
      fs_give((void **)&ivars.domain);
 
695
    if(ivars.inboxpath)
 
696
      fs_give((void **)&ivars.inboxpath);
 
697
    if(ivars.smtpserver)
 
698
      fs_give((void **)&ivars.smtpserver);
 
699
    return 0;
 
700
}
 
701
 
 
702
/*
 
703
 * Show args dialog
 
704
 */
 
705
int
 
706
os_argsdialog (char **arg_text)
 
707
{
 
708
    DLGPROC     dlgprc;
 
709
    HINSTANCE   hInst;
 
710
    HWND        hWnd;
 
711
 
 
712
    hInst = (HINSTANCE) mswin_gethinstance ();  
 
713
    hWnd = (HWND) mswin_gethwnd ();
 
714
 
 
715
    mswin_killsplash();
 
716
 
 
717
    dlgprc = args_dialog_proc;
 
718
 
 
719
    DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_ARGLIST), hWnd,
 
720
                    dlgprc, (LPARAM) arg_text);
 
721
 
 
722
    return(1);
 
723
}
 
724
 
 
725
/*
 
726
 * Prompt for username and password
 
727
 */
 
728
int
 
729
os_login_dialog (NETMBX *mb, char *user_utf8, int userlen,
 
730
                 char *pwd_utf8, int pwdlen, int pwc, int fixuser, int *prespass)
 
731
{
 
732
    DLGPROC     dlgprc;
 
733
    HINSTANCE   hInst;
 
734
    HWND        hWnd;
 
735
    int         i;
 
736
    DLG_LOGINDATA  dlgpw;
 
737
    LPTSTR user_lptstr, pwd_lptstr;
 
738
    char *tuser_utf8, *tpwd_utf8;
 
739
 
 
740
    mswin_killsplash();
 
741
    hInst = (HINSTANCE) mswin_gethinstance ();  
 
742
    hWnd = (HWND) mswin_gethwnd ();
 
743
 
 
744
    dlgpw.mb = mb;
 
745
 
 
746
    dlgpw.user = (LPTSTR)fs_get(userlen*sizeof(TCHAR));
 
747
    user_lptstr = utf8_to_lptstr(user_utf8);
 
748
    _tcsncpy(dlgpw.user, user_lptstr, userlen - 1);
 
749
    dlgpw.user[userlen - 1] = '\0';
 
750
    fs_give((void **) &user_lptstr);
 
751
    dlgpw.userlen = userlen;
 
752
 
 
753
    dlgpw.pwd = (LPTSTR)fs_get(pwdlen*sizeof(TCHAR));
 
754
    pwd_lptstr = utf8_to_lptstr(pwd_utf8);
 
755
    _tcsncpy(dlgpw.pwd, pwd_lptstr, pwdlen - 1);
 
756
    dlgpw.pwd[pwdlen - 1] = '\0';
 
757
    fs_give((void **) &pwd_lptstr);
 
758
    dlgpw.pwdlen = pwdlen;
 
759
 
 
760
    dlgpw.fixuser = fixuser;
 
761
    dlgpw.pwc = pwc;
 
762
    dlgpw.rv = 0;
 
763
 
 
764
    dlgprc = login_dialog_proc;
 
765
 
 
766
    DialogBoxParam (hInst, MAKEINTRESOURCE (ps_global->install_flag
 
767
                                            ? IDD_LOGINDLG2 : IDD_LOGINDLG), 
 
768
                    NULL, dlgprc, (LPARAM)&dlgpw);
 
769
 
 
770
    if(dlgpw.rv == 0){
 
771
        tuser_utf8 = lptstr_to_utf8(dlgpw.user);
 
772
        if(tuser_utf8){
 
773
            strncpy(user_utf8, tuser_utf8, userlen - 1);
 
774
            user_utf8[userlen - 1] = '\0';
 
775
            fs_give((void **) &tuser_utf8);
 
776
        }
 
777
 
 
778
        tpwd_utf8 = lptstr_to_utf8(dlgpw.pwd);
 
779
        if(tpwd_utf8){
 
780
            strncpy(pwd_utf8, tpwd_utf8, pwdlen - 1);
 
781
            pwd_utf8[pwdlen - 1] = '\0';
 
782
            fs_give((void **) &tpwd_utf8);
 
783
        }
 
784
        if(prespass)
 
785
          (*prespass) = dlgpw.prespass;
 
786
    }
 
787
 
 
788
    return(dlgpw.rv);
 
789
}
 
790
 
 
791
/*
 
792
 * Select message flags.
 
793
 */
 
794
int
 
795
os_flagmsgdialog (struct flag_table *ftbl)
 
796
{
 
797
    DLGPROC     dlgprc;
 
798
    HINSTANCE   hInst;
 
799
    HWND        hWnd;
 
800
    int         i;
 
801
    DLG_FLAGDATA  dlgflag;
 
802
    int         rval;
 
803
 
 
804
    hInst = (HINSTANCE) mswin_gethinstance ();  
 
805
    hWnd = (HWND) mswin_gethwnd ();
 
806
 
 
807
    dlgflag.ftbl = ftbl;
 
808
    dlgflag.hInstance = hInst;
 
809
    dlgflag.hTextWnd  = hWnd;
 
810
 
 
811
    dlgprc = flag_dialog_proc;                             
 
812
        
 
813
    rval = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTFLAG), hWnd,
 
814
                dlgprc, (LPARAM)&dlgflag);
 
815
 
 
816
    return (rval);
 
817
}
 
818
 
 
819
/*
 
820
 * Select a sort type.
 
821
 */
 
822
 
 
823
int
 
824
os_sortdialog (DLG_SORTPARAM *sortsel)
 
825
{
 
826
    DLGPROC     dlgprc;
 
827
    HINSTANCE   hInst;
 
828
    HWND        hWnd;
 
829
    int         i;
 
830
    DLG_SORTDATA  dlgsort;
 
831
 
 
832
    hInst = (HINSTANCE) mswin_gethinstance ();  
 
833
    hWnd = (HWND) mswin_gethwnd ();
 
834
 
 
835
 
 
836
    /* Build a map of pine sort types to the resource types. */
 
837
    i = 0;
 
838
    dlgsort.types[i].pineid   = SortArrival;
 
839
    dlgsort.types[i++].rsrcid = IDC_SORTARRIVAL;
 
840
    dlgsort.types[i].pineid   = SortDate;
 
841
    dlgsort.types[i++].rsrcid = IDC_SORTDATE;
 
842
    dlgsort.types[i].pineid   = SortFrom;
 
843
    dlgsort.types[i++].rsrcid = IDC_SORTFROM;
 
844
    dlgsort.types[i].pineid   = SortSubject;
 
845
    dlgsort.types[i++].rsrcid = IDC_SORTSUBJECT;
 
846
    dlgsort.types[i].pineid   = SortSubject2;
 
847
    dlgsort.types[i++].rsrcid = IDC_SORTORDERSUB;
 
848
    dlgsort.types[i].pineid   = SortTo;
 
849
    dlgsort.types[i++].rsrcid = IDC_SORTTO;
 
850
    dlgsort.types[i].pineid   = SortCc;
 
851
    dlgsort.types[i++].rsrcid = IDC_SORTCC;
 
852
    dlgsort.types[i].pineid   = SortSize;
 
853
    dlgsort.types[i++].rsrcid = IDC_SORTSIZE;
 
854
    dlgsort.types[i].pineid   = SortThread;
 
855
    dlgsort.types[i++].rsrcid = IDC_SORTTHREAD;
 
856
    dlgsort.types[i].pineid   = SortScore;
 
857
    dlgsort.types[i++].rsrcid = IDC_SORTSCORE;
 
858
    dlgsort.sortcount = i;
 
859
    dlgsort.sortsel = sortsel;
 
860
 
 
861
    dlgprc = sort_dialog_proc;
 
862
 
 
863
    DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTSORT), hWnd,
 
864
                dlgprc, (LPARAM)&dlgsort);
 
865
 
 
866
    return(1);
 
867
}
 
868
 
 
869
 
 
870
/*
 
871
 * Dialog proc to handle index sort selection.
 
872
 * 
 
873
 * Configures the dialog box on init and retrieves the settings on exit.
 
874
 */    
 
875
BOOL CALLBACK  __export 
 
876
args_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
877
{
 
878
    BOOL ret = FALSE;
 
879
    long i, j, block_size;
 
880
    char **args_text;
 
881
    LPTSTR args_text_lptstr, args_block_lptstr;
 
882
 
 
883
    
 
884
    switch (uMsg) {
 
885
    case WM_INITDIALOG:
 
886
 
 
887
        args_text = (char **)lParam;
 
888
 
 
889
        /*
 
890
         * First convert char *'s over to one big block of
 
891
         * Unicode
 
892
         */
 
893
        i = 0;
 
894
        while(args_text && *args_text){
 
895
            i += strlen(*args_text++);
 
896
            i += 2;
 
897
        }
 
898
        block_size = i;
 
899
 
 
900
        args_block_lptstr = (LPTSTR)fs_get((block_size+1)*sizeof(TCHAR));
 
901
 
 
902
        args_text = (char **)lParam;
 
903
        i = 0;
 
904
        j = 0;
 
905
        while(args_text && *args_text){
 
906
            args_text_lptstr = utf8_to_lptstr(*args_text++);
 
907
            while(args_text_lptstr[i] && j < block_size){
 
908
                args_block_lptstr[j++] = args_text_lptstr[i++];
 
909
            }
 
910
            args_block_lptstr[j++] = '\r';
 
911
            args_block_lptstr[j++] = '\n';
 
912
            fs_give((void **) &args_text_lptstr);
 
913
            i = 0;
 
914
        }
 
915
        args_block_lptstr[j] = '\0';
 
916
 
 
917
        /* and replace everything selected with args_text */
 
918
        SendDlgItemMessage(hDlg, IDC_ARGTEXT, WM_SETTEXT, (WPARAM) 0,
 
919
                           (LPARAM) args_block_lptstr);
 
920
        fs_give((void **)&args_block_lptstr);
 
921
 
 
922
        return (1);
 
923
 
 
924
    case WM_CLOSE :
 
925
        ret = TRUE;
 
926
        EndDialog (hDlg, TRUE);
 
927
        break;
 
928
 
 
929
 
 
930
    case WM_COMMAND:
 
931
        switch (wParam) {
 
932
        case IDOK:
 
933
            ret = TRUE;
 
934
            EndDialog (hDlg, TRUE);
 
935
            break;
 
936
        }
 
937
        break;
 
938
        
 
939
 
 
940
    }
 
941
    return (ret);
 
942
}
 
943
 
 
944
/*
 
945
 * Dialog proc to handle login
 
946
 * 
 
947
 * Configures the dialog box on init and retrieves the settings on exit.
 
948
 */    
 
949
BOOL CALLBACK  __export 
 
950
login_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
951
{
 
952
    DLG_LOGINDATA *dlglogin;
 
953
    BOOL ret = FALSE;
 
954
    TCHAR tcbuf[1024];
 
955
    NETMBX *mb;
 
956
    LPTSTR  user, pwd;
 
957
    LPTSTR  host_lptstr;
 
958
 
 
959
    switch (uMsg) {
 
960
    case WM_INITDIALOG:
 
961
 
 
962
        dlglogin = (DLG_LOGINDATA *)lParam;
 
963
        mb = dlglogin->mb;
 
964
        user = dlglogin->user;
 
965
        pwd = dlglogin->pwd;
 
966
        SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlglogin);
 
967
 
 
968
        host_lptstr = utf8_to_lptstr(mb->host);
 
969
        _sntprintf(tcbuf, sizeof(tcbuf), TEXT("Host: %.100s%s"), host_lptstr,
 
970
                   !mb->sslflag && !mb->tlsflag ? TEXT(" (INSECURE)") : TEXT(""));
 
971
        fs_give((void **) &host_lptstr);
 
972
 
 
973
        if(mb->sslflag || mb->tlsflag)
 
974
          SetWindowText(hDlg, TEXT("Alpine Login  +"));
 
975
        else
 
976
          SetWindowText(hDlg, TEXT("Alpine Insecure Login"));
 
977
 
 
978
        if(dlglogin->pwc){
 
979
            EnableWindow(GetDlgItem(hDlg, IDC_RPASSWORD),0);
 
980
            EnableWindow(GetDlgItem(hDlg, IDC_RPWTEXT),0);
 
981
            EnableWindow(GetDlgItem(hDlg, IDC_PRESPASS),0);
 
982
        }
 
983
        if(mb->user && *mb->user){
 
984
            LPTSTR user_lptstr;
 
985
 
 
986
            user_lptstr = utf8_to_lptstr(mb->user);
 
987
            SetDlgItemText(hDlg, IDC_RLOGINE, user_lptstr);
 
988
            if((mb->user && *mb->user) || dlglogin->fixuser)
 
989
              EnableWindow(GetDlgItem(hDlg, IDC_RLOGINE), 0);
 
990
            fs_give((void **) &user_lptstr);
 
991
        }
 
992
        else if(user){
 
993
            SetDlgItemText(hDlg, IDC_RLOGINE, user);
 
994
            if(dlglogin->fixuser)
 
995
              EnableWindow(GetDlgItem(hDlg, IDC_RLOGINE), 0);
 
996
        }
 
997
        SetDlgItemText(hDlg, IDC_PROMPT, tcbuf);
 
998
        return (1);
 
999
 
 
1000
 
 
1001
    case WM_COMMAND:
 
1002
        dlglogin = (DLG_LOGINDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
 
1003
        switch (wParam) {
 
1004
        case IDOK:
 
1005
            /* Retrieve the new username/passwd. */
 
1006
            user = dlglogin->user;
 
1007
            pwd = dlglogin->pwd;
 
1008
            GetDlgItemText(hDlg, IDC_RLOGINE, user, dlglogin->userlen - 1);
 
1009
            GetDlgItemText(hDlg, IDC_RPASSWORD, pwd, dlglogin->pwdlen - 1);
 
1010
            user[dlglogin->userlen - 1] = '\0';
 
1011
            pwd[dlglogin->pwdlen - 1] = '\0';
 
1012
            dlglogin->prespass = (IsDlgButtonChecked(hDlg, IDC_PRESPASS) == BST_CHECKED);
 
1013
 
 
1014
            EndDialog (hDlg, LOWORD(wParam));
 
1015
            dlglogin->rv = 0;
 
1016
            ret = TRUE;
 
1017
            break;
 
1018
 
 
1019
        case IDCANCEL:
 
1020
            dlglogin->rv = 1;
 
1021
            ret = TRUE;
 
1022
            EndDialog (hDlg, LOWORD(wParam));
 
1023
            break;
 
1024
        }
 
1025
        break;
 
1026
    }
 
1027
    return (ret);
 
1028
}
 
1029
 
 
1030
/*
 
1031
 * Dialog proc to handle flag selection.
 
1032
 * 
 
1033
 * Configures the dialog box on init, adding buttons as needed for
 
1034
 * an unknown number of flags.
 
1035
 * Retrieves the settings on exit.
 
1036
 */    
 
1037
BOOL CALLBACK  __export 
 
1038
flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
1039
{
 
1040
    DLG_FLAGDATA        *dlgflag;
 
1041
    BOOL                ret = FALSE;
 
1042
    int                 i;
 
1043
    struct flag_table   *fp;
 
1044
    HWND                hRB[2], hBtn;
 
1045
    RECT                rb[2];
 
1046
    UINT                bheight, bwidth, bvertSpace;
 
1047
    UINT                btnOKHeight;
 
1048
    int                 base, line;
 
1049
    int                 bstate;
 
1050
    HFONT               btnFont;
 
1051
    
 
1052
    
 
1053
 
 
1054
    
 
1055
    switch (uMsg) {
 
1056
    case WM_INITDIALOG:
 
1057
        dlgflag = (DLG_FLAGDATA *)lParam;           
 
1058
        SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgflag);
 
1059
 
 
1060
        /* Count buttons */
 
1061
        dlgflag->flagcount = 0;
 
1062
        for (fp = dlgflag->ftbl; fp && fp->name; ++fp)
 
1063
                ++dlgflag->flagcount;
 
1064
 
 
1065
        /* Get the positions of the current buttons. */
 
1066
        for (i = 0; i < 2; ++i) {
 
1067
            hRB[i] = GetDlgItem (hDlg, IDC_FLAGCOL1 + i);
 
1068
            GetBtnPos (hDlg, hRB[i], &rb[i]);
 
1069
        }
 
1070
        bheight = rb[0].bottom - rb[0].top;
 
1071
        bwidth  = rb[0].right  - rb[0].left;
 
1072
        bvertSpace = bheight + 5;
 
1073
        btnFont = (HFONT) SendMessage (hRB[0], WM_GETFONT, 0, 0);
 
1074
 
 
1075
        for (i = 0; i < dlgflag->flagcount; ++i) {
 
1076
            LPTSTR fp_name_lptstr;
 
1077
 
 
1078
            fp = &dlgflag->ftbl[i];
 
1079
            
 
1080
            fp_name_lptstr = utf8_to_lptstr(fp->name);
 
1081
            if (i < 2) {
 
1082
                hBtn = hRB[i];
 
1083
                SetWindowText (hBtn, fp_name_lptstr);
 
1084
            }
 
1085
            else {
 
1086
                base = i % 2;
 
1087
                line = i / 2;
 
1088
                hBtn = CreateWindow (TEXT("BUTTON"), fp_name_lptstr,
 
1089
                        WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
 
1090
                        rb[base].left, rb[base].top + bvertSpace * line,
 
1091
                        bwidth, bheight, 
 
1092
                        hDlg, (HMENU)NULL, dlgflag->hInstance, NULL);
 
1093
                SetWindowLong (hBtn, GWL_ID, IDC_FLAGCOL1 + i);
 
1094
                SendMessage (hBtn, WM_SETFONT, (WPARAM)btnFont, 
 
1095
                                MAKELPARAM (0, 0));
 
1096
            }
 
1097
 
 
1098
            fs_give((void **) &fp_name_lptstr);
 
1099
            if (fp->ukn) 
 
1100
                SendMessage (hBtn, BM_SETSTYLE, 
 
1101
                        (WPARAM)(BS_CHECKBOX | BS_AUTO3STATE), 0);
 
1102
            SendMessage (hBtn, BM_SETCHECK, 
 
1103
                (WPARAM) fp->set == CMD_FLAG_UNKN ? 2 : fp->set ? 1 : 0,
 
1104
                0);
 
1105
            ShowWindow (hBtn, SW_SHOW);
 
1106
            EnableWindow (hBtn, TRUE);
 
1107
        }
 
1108
        
 
1109
        /* Position the OK and Cancel buttons. */
 
1110
        line = (dlgflag->flagcount + 1) / 2;
 
1111
        for (i = 0; i < 2; ++i) {
 
1112
            hRB[1] = GetDlgItem (hDlg, i == 0 ? IDOK : IDCANCEL);
 
1113
            GetBtnPos (hDlg, hRB[1], &rb[1]);
 
1114
            MoveWindow (hRB[1], rb[1].left, rb[0].top + bvertSpace * line,
 
1115
                    rb[1].right - rb[1].left, rb[1].bottom - rb[1].top, 
 
1116
                    FALSE);
 
1117
            btnOKHeight = rb[1].bottom - rb[1].top;
 
1118
        }
 
1119
        
 
1120
        
 
1121
        /* Resize whole dialog window. */
 
1122
        GetWindowRect (hDlg, &rb[1]);
 
1123
        rb[1].right -= rb[1].left;
 
1124
        rb[1].bottom = rb[0].top + bvertSpace * line + btnOKHeight + 10 + 
 
1125
                                GetSystemMetrics (SM_CYCAPTION);
 
1126
        MoveWindow (hDlg, rb[1].left, rb[1].top, rb[1].right,
 
1127
                rb[1].bottom, TRUE);
 
1128
        return (1);
 
1129
 
 
1130
 
 
1131
    case WM_COMMAND:
 
1132
        dlgflag = (DLG_FLAGDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
 
1133
        switch (wParam) {
 
1134
 
 
1135
        case IDOK:
 
1136
            /* Retrieve the button states. */
 
1137
            for (i = 0; i < dlgflag->flagcount; ++i) {
 
1138
                fp = &dlgflag->ftbl[i];
 
1139
                bstate = SendMessage (GetDlgItem (hDlg, IDC_FLAGCOL1 + i),
 
1140
                                        BM_GETCHECK, 0, 0);
 
1141
                switch (bstate) {
 
1142
                case 2:  fp->set = CMD_FLAG_UNKN;       break;
 
1143
                case 1:  fp->set = CMD_FLAG_SET;        break;
 
1144
                case 0:  fp->set = CMD_FLAG_CLEAR;      break;
 
1145
                }
 
1146
            }
 
1147
            EndDialog (hDlg, TRUE);
 
1148
            ret = TRUE;
 
1149
            break;
 
1150
 
 
1151
        case IDCANCEL:
 
1152
            EndDialog (hDlg, FALSE);
 
1153
            ret = TRUE;
 
1154
            break;
 
1155
        }
 
1156
        break;
 
1157
        
 
1158
 
 
1159
    }
 
1160
    return (ret);
 
1161
}
 
1162
 
 
1163
/*
 
1164
 * Dialog proc to handle index sort selection.
 
1165
 * 
 
1166
 * Configures the dialog box on init and retrieves the settings on exit.
 
1167
 */    
 
1168
BOOL CALLBACK  __export 
 
1169
sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
1170
{
 
1171
    DLG_SORTDATA *dlgsort;
 
1172
    BOOL ret = FALSE;
 
1173
    int cursort;
 
1174
    int i;
 
1175
 
 
1176
    
 
1177
    switch (uMsg) {
 
1178
    case WM_INITDIALOG:
 
1179
        dlgsort = (DLG_SORTDATA *)lParam;           
 
1180
        SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgsort);
 
1181
        
 
1182
        /* Set the reversed button state. */
 
1183
        CheckDlgButton (hDlg, IDC_SORTREVERSE, dlgsort->sortsel->reverse);
 
1184
 
 
1185
        /* Set the current sort type radio button.*/
 
1186
        cursort = IDC_SORTARRIVAL;
 
1187
        for (i = 0; i < dlgsort->sortcount; ++i) {
 
1188
            if (dlgsort->types[i].pineid == dlgsort->sortsel->cursort) {
 
1189
                cursort = dlgsort->types[i].rsrcid;
 
1190
                break;
 
1191
            }
 
1192
        }
 
1193
        CheckRadioButton (hDlg, IDC_SORTFIRSTBUTTON, IDC_SORTLASTBUTTON,
 
1194
                          cursort);
 
1195
 
 
1196
        EnableWindow (GetDlgItem (hDlg, IDC_GETHELP), 
 
1197
                                (dlgsort->sortsel->helptext != NULL));
 
1198
        return (1);
 
1199
 
 
1200
 
 
1201
    case WM_COMMAND:
 
1202
        dlgsort = (DLG_SORTDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
 
1203
        switch (wParam) {
 
1204
        case IDC_GETHELP:
 
1205
            if (dlgsort->sortsel->helptext)
 
1206
                mswin_showhelpmsg ((WINHAND)hDlg, dlgsort->sortsel->helptext);
 
1207
            ret = TRUE;
 
1208
            break;
 
1209
 
 
1210
        case IDOK:
 
1211
            dlgsort->sortsel->rval = 1;
 
1212
 
 
1213
            /* Retrieve the reverse sort state. */
 
1214
            dlgsort->sortsel->reverse = (IsDlgButtonChecked (hDlg, IDC_SORTREVERSE) == 1);
 
1215
 
 
1216
            /* Retrieve the new sort type. */
 
1217
            for (i = 0; i < dlgsort->sortcount; ++i) {
 
1218
                if (IsDlgButtonChecked (hDlg, dlgsort->types[i].rsrcid)) {
 
1219
                    dlgsort->sortsel->cursort = dlgsort->types[i].pineid;
 
1220
                    break;
 
1221
                }
 
1222
            }
 
1223
            EndDialog (hDlg, dlgsort->sortsel->rval);
 
1224
            ret = TRUE;
 
1225
            break;
 
1226
 
 
1227
        case IDCANCEL:
 
1228
            dlgsort->sortsel->rval = 0;
 
1229
            ret = TRUE;
 
1230
            EndDialog (hDlg, dlgsort->sortsel->rval);
 
1231
            break;
 
1232
        }
 
1233
        break;
 
1234
        
 
1235
 
 
1236
    }
 
1237
    return (ret);
 
1238
}
 
1239
 
 
1240
int
 
1241
os_config_vars_dialog (INSTALLVARS_S *ivars)
 
1242
{
 
1243
    DLGPROC     dlgprc;
 
1244
    HINSTANCE   hInst;
 
1245
    HWND        hWnd;
 
1246
    int         i;
 
1247
    DLG_CONFIGVARSDATA  dlgcv;
 
1248
 
 
1249
    mswin_killsplash();
 
1250
    hInst = (HINSTANCE) mswin_gethinstance ();  
 
1251
    hWnd = (HWND) mswin_gethwnd ();
 
1252
 
 
1253
    dlgcv.ivars = ivars;
 
1254
    dlgcv.rv = 0;
 
1255
 
 
1256
    dlgprc = config_vars_dialog_proc;
 
1257
 
 
1258
    DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_CFVARSDLG), NULL,
 
1259
                    dlgprc, (LPARAM)&dlgcv);
 
1260
 
 
1261
    return(dlgcv.rv);
 
1262
}
 
1263
 
 
1264
/*
 
1265
 * Dialog proc to handle login
 
1266
 * 
 
1267
 * Configures the dialog box on init and retrieves the settings on exit.
 
1268
 */    
 
1269
BOOL CALLBACK  __export 
 
1270
config_vars_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
1271
{
 
1272
    DLG_CONFIGVARSDATA *dlgcv;
 
1273
    BOOL ret = FALSE;
 
1274
    int usepop = 0;
 
1275
    char buf[2*MAXPATH+1], *p;
 
1276
    int buflen = 2*MAXPATH;
 
1277
#define TCBUFLEN (2*MAXPATH)
 
1278
    TCHAR tcbuf[TCBUFLEN+1];
 
1279
    LPTSTR tmp_lptstr;
 
1280
    char *u;
 
1281
 
 
1282
    switch (uMsg) {
 
1283
      case WM_INITDIALOG:
 
1284
        dlgcv = (DLG_CONFIGVARSDATA *)lParam;
 
1285
        SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgcv);
 
1286
        if(dlgcv->ivars->pname){
 
1287
            tmp_lptstr = utf8_to_lptstr(dlgcv->ivars->pname);
 
1288
            if(tmp_lptstr){
 
1289
                SetDlgItemText(hDlg, IDC_CFV_PNAME, tmp_lptstr);
 
1290
                fs_give((void **) &tmp_lptstr);
 
1291
            }
 
1292
        }
 
1293
 
 
1294
        if(dlgcv->ivars->userid && dlgcv->ivars->domain){
 
1295
            snprintf(buf, sizeof(buf), "%.*s@%.*s", MAXPATH, dlgcv->ivars->userid,
 
1296
                    MAXPATH, dlgcv->ivars->domain);
 
1297
            buf[buflen-1] = '\0';
 
1298
            tmp_lptstr = utf8_to_lptstr(buf);
 
1299
            if(tmp_lptstr){
 
1300
                SetDlgItemText(hDlg, IDC_CFV_EMAILADR, tmp_lptstr);
 
1301
                fs_give((void **) &tmp_lptstr);
 
1302
            }
 
1303
        }
 
1304
 
 
1305
        if(dlgcv->ivars->inboxpath){
 
1306
            char *mbx;
 
1307
 
 
1308
            mbx = dlgcv->ivars->inboxpath;
 
1309
            if(*mbx == '{' && (p = strindex(mbx, '}'))
 
1310
               && ((*(p+1) == '\0') || !strucmp(p+1, "inbox"))){
 
1311
                char srvbuf[MAXPATH+1], tuser[MAXPATH+1];
 
1312
                int i, j, k;
 
1313
 
 
1314
                srvbuf[0] = '\0';
 
1315
                tuser[0] = '\0';
 
1316
                strncpy(buf, mbx+1, min(buflen, (int)(p - (mbx+1))));
 
1317
                buf[min(buflen-1, (int)(p - (mbx+1)))] = '\0';
 
1318
                for(i = 0, j = 0; buf[i] && j < MAXPATH; i++){
 
1319
                    if(buf[i] == '/'){
 
1320
                        if(!struncmp("/user=", buf+i, 6)){
 
1321
                            i += 6;
 
1322
                            for(k = 0; k < MAXPATH && buf[i]
 
1323
                                  && buf[i] != '/'; i++)
 
1324
                              tuser[k++] = buf[i];
 
1325
                            tuser[k] = '\0';
 
1326
                            i--;
 
1327
                        }
 
1328
                        else if(!struncmp("/pop3", buf+i, 5)
 
1329
                                && (!*(buf+5) || (*(buf+5) == '/'))){
 
1330
                            usepop = 1;
 
1331
                            i += 4;
 
1332
                        }
 
1333
                        else
 
1334
                          srvbuf[j++] = buf[i];
 
1335
                    }
 
1336
                    else
 
1337
                      srvbuf[j++] = buf[i];
 
1338
                }
 
1339
                srvbuf[j] = '\0';
 
1340
                if(*srvbuf){
 
1341
                    tmp_lptstr = utf8_to_lptstr(srvbuf);
 
1342
                    if(tmp_lptstr){
 
1343
                        SetDlgItemText(hDlg, IDC_CFV_MSERVER, tmp_lptstr);
 
1344
                        fs_give((void **) &tmp_lptstr);
 
1345
                    }
 
1346
                }
 
1347
 
 
1348
                if(*tuser){
 
1349
                    tmp_lptstr = utf8_to_lptstr(tuser);
 
1350
                    if(tmp_lptstr){
 
1351
                        SetDlgItemText(hDlg, IDC_CFV_LOGIN, tmp_lptstr);
 
1352
                        fs_give((void **) &tmp_lptstr);
 
1353
                    }
 
1354
                }
 
1355
            }
 
1356
            else {
 
1357
                tmp_lptstr = utf8_to_lptstr(mbx);
 
1358
                if(tmp_lptstr){
 
1359
                    SetDlgItemText(hDlg, IDC_CFV_MSERVER, tmp_lptstr);
 
1360
                    fs_give((void **) &tmp_lptstr);
 
1361
                }
 
1362
 
 
1363
                if(*mbx != '{' && *mbx != '#')
 
1364
                  EnableWindow(GetDlgItem(hDlg, IDC_CFV_MSERVER), 0);
 
1365
            }
 
1366
        }
 
1367
        CheckRadioButton (hDlg, IDC_CFV_IMAP, IDC_CFV_POP3,
 
1368
                          usepop ? IDC_CFV_POP3 : IDC_CFV_IMAP);
 
1369
        if(dlgcv->ivars->smtpserver){
 
1370
            tmp_lptstr = utf8_to_lptstr(dlgcv->ivars->smtpserver);
 
1371
            if(tmp_lptstr){
 
1372
                SetDlgItemText(hDlg, IDC_CFV_SMTPSERVER, tmp_lptstr);
 
1373
                fs_give((void **) &tmp_lptstr);
 
1374
            }
 
1375
        }
 
1376
 
 
1377
        if(dlgcv->ivars->defmailclient)
 
1378
          CheckDlgButton(hDlg, IDC_CFV_DEFMAILER, BST_CHECKED);
 
1379
        if(dlgcv->ivars->defnewsclient)
 
1380
          CheckDlgButton(hDlg, IDC_CFV_DEFNEWSRDR, BST_CHECKED);
 
1381
        
 
1382
        return (1);
 
1383
        break;
 
1384
 
 
1385
      case WM_COMMAND:
 
1386
        dlgcv = (DLG_CONFIGVARSDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
 
1387
        switch (wParam) {
 
1388
          case IDOK:
 
1389
            /* personal name */
 
1390
            GetDlgItemText(hDlg, IDC_CFV_PNAME, tcbuf, TCBUFLEN);
 
1391
            tcbuf[TCBUFLEN] = '\0';
 
1392
            u = lptstr_to_utf8(tcbuf);
 
1393
            if(u){
 
1394
                removing_leading_and_trailing_white_space(u);
 
1395
                if(dlgcv->ivars->pname)
 
1396
                  fs_give((void **)&dlgcv->ivars->pname);
 
1397
 
 
1398
                if(*u){
 
1399
                    dlgcv->ivars->pname = u;
 
1400
                    u = NULL;
 
1401
                }
 
1402
 
 
1403
                if(u)
 
1404
                  fs_give((void **) &u);
 
1405
            }
 
1406
            
 
1407
            /* user-id and domain */
 
1408
            GetDlgItemText(hDlg, IDC_CFV_EMAILADR, tcbuf, TCBUFLEN);
 
1409
            tcbuf[TCBUFLEN] = '\0';
 
1410
            u = lptstr_to_utf8(tcbuf);
 
1411
            if(u){
 
1412
                removing_leading_and_trailing_white_space(u);
 
1413
                if(p = strindex(u, '@')){
 
1414
                    *(p++) = '\0';
 
1415
                    if(dlgcv->ivars->userid)
 
1416
                      fs_give((void **)&dlgcv->ivars->userid);
 
1417
 
 
1418
                    if(dlgcv->ivars->domain)
 
1419
                      fs_give((void **)&dlgcv->ivars->domain);
 
1420
 
 
1421
                    if(*u){
 
1422
                        dlgcv->ivars->userid = u;
 
1423
                        u = NULL;
 
1424
                    }
 
1425
 
 
1426
                    if(*p)
 
1427
                      dlgcv->ivars->domain = cpystr(p);
 
1428
                }
 
1429
                else{
 
1430
                    MessageBox(hDlg, TEXT("Invalid email address.  Should be username@domain"),
 
1431
                               TEXT("Alpine"), MB_ICONWARNING | MB_OK);
 
1432
                    return(TRUE);
 
1433
                }
 
1434
 
 
1435
                if(u)
 
1436
                  fs_give((void **) &u);
 
1437
            }
 
1438
 
 
1439
            /* inbox-path */
 
1440
            GetDlgItemText(hDlg, IDC_CFV_MSERVER, tcbuf, TCBUFLEN);
 
1441
            tcbuf[TCBUFLEN] = '\0';
 
1442
            u = lptstr_to_utf8(tcbuf);
 
1443
            if(u){
 
1444
                removing_leading_and_trailing_white_space(u);
 
1445
                if(*u == '{' || *u == '#'
 
1446
                   || !IsWindowEnabled(GetDlgItem(hDlg, IDC_CFV_MSERVER))){
 
1447
                    if(dlgcv->ivars->inboxpath)
 
1448
                      fs_give((void **)&dlgcv->ivars->inboxpath);
 
1449
 
 
1450
                    dlgcv->ivars->inboxpath = u;
 
1451
                    u = NULL;
 
1452
                }
 
1453
                else if(*u){
 
1454
                    char tsrvr[4*MAXPATH+1];
 
1455
                    int tsrvrlen = 4*MAXPATH;
 
1456
 
 
1457
                    if(dlgcv->ivars->inboxpath)
 
1458
                      fs_give((void **)&dlgcv->ivars->inboxpath);
 
1459
 
 
1460
                    snprintf(tsrvr, sizeof(tsrvr), "{%s%s", u,
 
1461
                            IsDlgButtonChecked(hDlg, IDC_CFV_POP3) 
 
1462
                            == BST_CHECKED ? "/pop3" : "");
 
1463
 
 
1464
                    if(u)
 
1465
                      fs_give((void **) &u);
 
1466
 
 
1467
                    GetDlgItemText(hDlg, IDC_CFV_LOGIN, tcbuf, TCBUFLEN);
 
1468
                    tcbuf[TCBUFLEN] = '\0';
 
1469
                    u = lptstr_to_utf8(tcbuf);
 
1470
                    if(u){
 
1471
                        removing_leading_and_trailing_white_space(u);
 
1472
                        if(*u){
 
1473
                            strncat(tsrvr, "/user=", tsrvrlen);
 
1474
                            strncat(tsrvr, u, tsrvrlen);
 
1475
                        }
 
1476
 
 
1477
                        strncat(tsrvr, "}inbox", tsrvrlen);
 
1478
                        tsrvr[tsrvrlen-1] = '\0';
 
1479
                        dlgcv->ivars->inboxpath = cpystr(tsrvr);
 
1480
                    }
 
1481
                }
 
1482
 
 
1483
                if(u)
 
1484
                  fs_give((void **) &u);
 
1485
            }
 
1486
 
 
1487
            /* smtp-server */
 
1488
            GetDlgItemText(hDlg, IDC_CFV_SMTPSERVER, tcbuf, TCBUFLEN);
 
1489
            tcbuf[TCBUFLEN] = '\0';
 
1490
            u = lptstr_to_utf8(tcbuf);
 
1491
            if(u){
 
1492
                removing_leading_and_trailing_white_space(u);
 
1493
                if(dlgcv->ivars->smtpserver)
 
1494
                  fs_give((void **)&dlgcv->ivars->smtpserver);
 
1495
 
 
1496
                if(*u){
 
1497
                    dlgcv->ivars->smtpserver = u;
 
1498
                    u = NULL;
 
1499
                }
 
1500
 
 
1501
                if(u)
 
1502
                  fs_give((void **) &u);
 
1503
            }
 
1504
 
 
1505
            dlgcv->ivars->defmailclient =
 
1506
              (IsDlgButtonChecked(hDlg, IDC_CFV_DEFMAILER)
 
1507
               == BST_CHECKED);
 
1508
            dlgcv->ivars->defnewsclient =
 
1509
              (IsDlgButtonChecked(hDlg, IDC_CFV_DEFNEWSRDR)
 
1510
               == BST_CHECKED);
 
1511
 
 
1512
            EndDialog (hDlg, LOWORD(wParam));
 
1513
            dlgcv->rv = 0;
 
1514
            ret = TRUE;
 
1515
            break;
 
1516
 
 
1517
        case IDCANCEL:
 
1518
            dlgcv->rv = 1;
 
1519
            ret = TRUE;
 
1520
            EndDialog (hDlg, LOWORD(wParam));
 
1521
            break;
 
1522
        }
 
1523
        break;
 
1524
        
 
1525
 
 
1526
    }
 
1527
    return (ret);
 
1528
}
 
1529
 
 
1530
/*
 
1531
 * Prompt for config location
 
1532
 */
 
1533
 
 
1534
int
 
1535
os_config_dialog (char *utf8_buf, int utf8_buflen,
 
1536
                  int *regset, int nopinerc)
 
1537
{
 
1538
    DLGPROC     dlgprc;
 
1539
    HINSTANCE   hInst;
 
1540
    HWND        hWnd;
 
1541
    int         i;
 
1542
    DLG_CONFIGDATA  dlgcfg;
 
1543
 
 
1544
    mswin_killsplash();
 
1545
    hInst = (HINSTANCE) mswin_gethinstance ();  
 
1546
    hWnd = (HWND) mswin_gethwnd ();
 
1547
 
 
1548
    dlgcfg.confpath = utf8_buf;
 
1549
    dlgcfg.confpathlen = utf8_buflen;
 
1550
    dlgcfg.setreg = 0;
 
1551
    dlgcfg.nopinerc = nopinerc;
 
1552
    dlgcfg.rv = 0;
 
1553
 
 
1554
    dlgprc = config_dialog_proc;
 
1555
 
 
1556
    DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_CONFIGDLG), NULL,
 
1557
                    dlgprc, (LPARAM)&dlgcfg);
 
1558
 
 
1559
    *regset = dlgcfg.setreg;
 
1560
    return(dlgcfg.rv);
 
1561
}
 
1562
 
 
1563
 
 
1564
/*
 
1565
 * Dialog proc to handle login
 
1566
 * 
 
1567
 * Configures the dialog box on init and retrieves the settings on exit.
 
1568
 */    
 
1569
BOOL CALLBACK  __export 
 
1570
config_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
1571
{
 
1572
    DLG_CONFIGDATA *dlgcfg;
 
1573
    BOOL ret = FALSE;
 
1574
    int checked, def_rem_fldr = 1, def_diff_fldr = 0;
 
1575
 
 
1576
    switch (uMsg) {
 
1577
    case WM_INITDIALOG:
 
1578
 
 
1579
        dlgcfg = (DLG_CONFIGDATA *)lParam;
 
1580
        SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgcfg);
 
1581
        if(ps_global->install_flag)
 
1582
          SetDlgItemText(hDlg, IDC_CONFTEXT, TEXT("Please specify where Alpine should create (or look for) your personal configuration file."));
 
1583
        SetDlgItemText(hDlg, IDC_CONFEFLDRNAME, TEXT("remote_pinerc"));
 
1584
        if(*dlgcfg->confpath){
 
1585
            if(dlgcfg->confpath[0] == '{'){
 
1586
                LPTSTR tfldr, p, tfldr2, p2, user;
 
1587
 
 
1588
                tfldr = utf8_to_lptstr((LPSTR)(dlgcfg->confpath+1));
 
1589
                if(p = _tcschr(tfldr, '}')){
 
1590
                    *p++ = '\0';
 
1591
                    if(_tcscmp(TEXT("remote_pinerc"), p)){
 
1592
                        SetDlgItemText(hDlg, IDC_CONFEFLDRNAME, p);
 
1593
                        def_diff_fldr = 1;
 
1594
                    }
 
1595
 
 
1596
                    tfldr2 = _tcsdup(tfldr);
 
1597
                    for(p = tfldr, p2 = tfldr2; *p; p++)
 
1598
                      if(*p == '/' && !_tcsnicmp(p, TEXT("/user="), 6)){
 
1599
                          p += 6;
 
1600
                          for(user = p; *p && *p != '/'; p++);
 
1601
                          if(*p){
 
1602
                              *p2++ = *p;
 
1603
                              *p = '\0';
 
1604
                          }
 
1605
                          else
 
1606
                            p--;
 
1607
                          SetDlgItemText(hDlg, IDC_CONFEUSERNAME, user);
 
1608
                      }
 
1609
                      else
 
1610
                        *p2++ = *p;
 
1611
                    *p2 = '\0';
 
1612
                    SetDlgItemText(hDlg, IDC_CONFESERVER, tfldr2);
 
1613
                    if(tfldr2)
 
1614
                      MemFree((void *)tfldr2);
 
1615
                }
 
1616
 
 
1617
                if(tfldr)
 
1618
                  fs_give((void **) &tfldr);
 
1619
            }
 
1620
            else{
 
1621
                LPTSTR local_file;
 
1622
 
 
1623
                local_file = utf8_to_lptstr((LPSTR)dlgcfg->confpath);
 
1624
                SetDlgItemText(hDlg, IDC_CONFEFN, local_file);
 
1625
                if(!dlgcfg->nopinerc)
 
1626
                  def_rem_fldr = 0;
 
1627
 
 
1628
                fs_give((void **) &local_file);
 
1629
            }
 
1630
        }
 
1631
        CheckRadioButton (hDlg, IDC_CONFRRADIO, IDC_CONFLRADIO,
 
1632
                          def_rem_fldr ? IDC_CONFRRADIO : IDC_CONFLRADIO);
 
1633
        if(def_rem_fldr){
 
1634
            EnableWindow(GetDlgItem(hDlg, IDC_CONFFNTXT), 0);
 
1635
            EnableWindow(GetDlgItem(hDlg, IDC_CONFEFN), 0);
 
1636
            EnableWindow(GetDlgItem(hDlg, IDC_CONFBROWSE), 0);
 
1637
            if(!def_diff_fldr){
 
1638
                CheckDlgButton(hDlg, IDC_CONFDFLTFLDR, BST_CHECKED);
 
1639
                EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 0);
 
1640
            }
 
1641
            EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 0);
 
1642
        }
 
1643
        else {
 
1644
            EnableWindow(GetDlgItem(hDlg, IDC_CONFSRVRTXT), 0);
 
1645
            EnableWindow(GetDlgItem(hDlg, IDC_CONFESERVER), 0);
 
1646
            EnableWindow(GetDlgItem(hDlg, IDC_CONFUNTXT), 0);
 
1647
            EnableWindow(GetDlgItem(hDlg, IDC_CONFEUSERNAME), 0);
 
1648
            CheckDlgButton(hDlg, IDC_CONFDFLTFLDR, BST_CHECKED);
 
1649
            EnableWindow(GetDlgItem(hDlg, IDC_CONFDFLTFLDR), 0);
 
1650
            EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 0);
 
1651
            EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 0);
 
1652
        }
 
1653
        if(ps_global->install_flag)
 
1654
          CheckDlgButton(hDlg, IDC_CONFDFLTSET, BST_CHECKED);
 
1655
 
 
1656
        return (1);
 
1657
 
 
1658
 
 
1659
    case WM_COMMAND:
 
1660
        dlgcfg = (DLG_CONFIGDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
 
1661
        switch (wParam) {
 
1662
        case IDC_CONFDFLTFLDR:
 
1663
          checked = (IsDlgButtonChecked(hDlg, IDC_CONFDFLTFLDR) == BST_CHECKED);
 
1664
          EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), checked ? 0 : 1);
 
1665
          EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), checked ? 0 : 1);
 
1666
          if(checked)
 
1667
            SetDlgItemText(hDlg, IDC_CONFEFLDRNAME, TEXT("remote_pinerc"));
 
1668
          break;
 
1669
        case IDC_CONFRRADIO:
 
1670
        case IDC_CONFLRADIO:
 
1671
            CheckRadioButton (hDlg, IDC_CONFRRADIO, IDC_CONFLRADIO, wParam);
 
1672
            EnableWindow(GetDlgItem(hDlg, IDC_CONFFNTXT), wParam == IDC_CONFRRADIO ? 0 : 1);
 
1673
            EnableWindow(GetDlgItem(hDlg, IDC_CONFEFN), wParam == IDC_CONFRRADIO ? 0 : 1);
 
1674
            EnableWindow(GetDlgItem(hDlg, IDC_CONFBROWSE), wParam == IDC_CONFRRADIO ? 0 : 1);
 
1675
            EnableWindow(GetDlgItem(hDlg, IDC_CONFSRVRTXT), wParam == IDC_CONFRRADIO ? 1 : 0);
 
1676
            EnableWindow(GetDlgItem(hDlg, IDC_CONFESERVER), wParam == IDC_CONFRRADIO ? 1 : 0);
 
1677
            EnableWindow(GetDlgItem(hDlg, IDC_CONFUNTXT), wParam == IDC_CONFRRADIO ? 1 : 0);
 
1678
            EnableWindow(GetDlgItem(hDlg, IDC_CONFEUSERNAME), wParam == IDC_CONFRRADIO ? 1 : 0);
 
1679
            EnableWindow(GetDlgItem(hDlg, IDC_CONFDFLTFLDR), wParam == IDC_CONFRRADIO ? 1 : 0);
 
1680
            if(wParam == IDC_CONFRRADIO && IsDlgButtonChecked(hDlg, IDC_CONFDFLTFLDR) == BST_UNCHECKED){
 
1681
                EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 1);
 
1682
                EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 1);
 
1683
            }
 
1684
            else if(wParam == IDC_CONFLRADIO){
 
1685
                EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 0);
 
1686
                EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 0);
 
1687
            }
 
1688
            break;
 
1689
        case IDC_CONFBROWSE:
 
1690
            if(1){
 
1691
                TCHAR fn[MAXPATH+1];
 
1692
                OPENFILENAME ofn;
 
1693
 
 
1694
                fn[0] = '\0';
 
1695
 
 
1696
                /* Set up the BIG STRUCTURE. see mswin.c */
 
1697
                memset (&ofn, 0, sizeof(ofn));
 
1698
                ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
 
1699
                ofn.hwndOwner = hDlg;
 
1700
                ofn.lpstrFilter = NULL;
 
1701
                ofn.lpstrCustomFilter = NULL;
 
1702
                ofn.nFilterIndex = 0;
 
1703
                ofn.lpstrFile = fn;
 
1704
                ofn.nMaxFile = MAXPATH;
 
1705
                ofn.lpstrFileTitle = NULL;
 
1706
                ofn.nMaxFileTitle = 0;
 
1707
                ofn.lpstrInitialDir = NULL;
 
1708
                ofn.lpstrTitle = TEXT("Select File");
 
1709
                ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
 
1710
                ofn.lpstrDefExt = NULL;
 
1711
 
 
1712
                if (GetOpenFileName (&ofn)) {
 
1713
                    SetDlgItemText(hDlg, IDC_CONFEFN, fn);
 
1714
                }
 
1715
            }
 
1716
            break;
 
1717
        case IDOK:
 
1718
            /* Retrieve the new username/passwd. */
 
1719
            if(IsDlgButtonChecked(hDlg, IDC_CONFDFLTSET) == BST_CHECKED)
 
1720
              dlgcfg->setreg = 1;
 
1721
            else
 
1722
              dlgcfg->setreg = 0;
 
1723
            if(IsDlgButtonChecked(hDlg, IDC_CONFRRADIO) == BST_CHECKED){
 
1724
                TCHAR lptstr_buf[MAXPATH+1];
 
1725
                char *utf8_srvr, *utf8_username, *utf8_fldrname;
 
1726
 
 
1727
                GetDlgItemText(hDlg, IDC_CONFESERVER, lptstr_buf, MAXPATH);
 
1728
                lptstr_buf[MAXPATH] = '\0';
 
1729
                utf8_srvr = lptstr_to_utf8(lptstr_buf);
 
1730
                removing_leading_and_trailing_white_space(utf8_srvr);
 
1731
                if(!*utf8_srvr){
 
1732
                    MessageBox(hDlg, TEXT("IMAP Server field empty"),
 
1733
                               TEXT("Alpine"), MB_ICONWARNING | MB_OK);
 
1734
                    if(utf8_srvr)
 
1735
                      fs_give((void **) &utf8_srvr);
 
1736
 
 
1737
                    return(TRUE);
 
1738
                }
 
1739
 
 
1740
                GetDlgItemText(hDlg, IDC_CONFEUSERNAME, lptstr_buf, MAXPATH);
 
1741
                lptstr_buf[MAXPATH] = '\0';
 
1742
                utf8_username = lptstr_to_utf8(lptstr_buf);
 
1743
                removing_leading_and_trailing_white_space(utf8_username);
 
1744
                if(IsDlgButtonChecked(hDlg, IDC_CONFDFLTFLDR) == BST_CHECKED){
 
1745
                    utf8_fldrname = cpystr("remote_pinerc");
 
1746
                }
 
1747
                else{
 
1748
                    GetDlgItemText(hDlg, IDC_CONFEFLDRNAME, lptstr_buf, MAXPATH);
 
1749
                    lptstr_buf[MAXPATH] = '\0';
 
1750
                    utf8_fldrname = lptstr_to_utf8(lptstr_buf);
 
1751
                    removing_leading_and_trailing_white_space(utf8_fldrname);
 
1752
                    if(!*utf8_fldrname){
 
1753
                        MessageBox(hDlg, TEXT("Configuration Folder Name field empty"),
 
1754
                                   TEXT("Alpine"), MB_ICONWARNING | MB_OK);
 
1755
                        if(utf8_srvr)
 
1756
                          fs_give((void **) &utf8_srvr);
 
1757
 
 
1758
                        if(utf8_username)
 
1759
                          fs_give((void **) &utf8_username);
 
1760
 
 
1761
                        if(utf8_fldrname)
 
1762
                          fs_give((void **) &utf8_fldrname);
 
1763
 
 
1764
                        return(TRUE);
 
1765
                    }
 
1766
                }
 
1767
                if((strlen(utf8_srvr) 
 
1768
                    + strlen(utf8_username)
 
1769
                    + strlen(utf8_fldrname)
 
1770
                    + 11) > dlgcfg->confpathlen){
 
1771
                    MessageBox(hDlg, TEXT("Config path too long"),
 
1772
                               TEXT("Alpine"), MB_ICONWARNING | MB_OK);
 
1773
                    if(utf8_srvr)
 
1774
                      fs_give((void **) &utf8_srvr);
 
1775
 
 
1776
                    if(utf8_username)
 
1777
                      fs_give((void **) &utf8_username);
 
1778
 
 
1779
                    if(utf8_fldrname)
 
1780
                      fs_give((void **) &utf8_fldrname);
 
1781
 
 
1782
                    return(TRUE);
 
1783
                }
 
1784
 
 
1785
                snprintf(dlgcfg->confpath, dlgcfg->confpathlen, "{%s%s%s}%s", utf8_srvr,
 
1786
                         *utf8_username ? "/user=" : "",
 
1787
                        utf8_username, utf8_fldrname);
 
1788
                if(utf8_srvr)
 
1789
                  fs_give((void **) &utf8_srvr);
 
1790
 
 
1791
                if(utf8_username)
 
1792
                  fs_give((void **) &utf8_username);
 
1793
 
 
1794
                if(utf8_fldrname)
 
1795
                  fs_give((void **) &utf8_fldrname);
 
1796
            }
 
1797
            else{
 
1798
                TCHAR lptstr_fn[MAXPATH+1];
 
1799
                char *utf8_fn;
 
1800
 
 
1801
                GetDlgItemText(hDlg, IDC_CONFEFN, lptstr_fn, MAXPATH);
 
1802
                lptstr_fn[MAXPATH] = '\0';
 
1803
                utf8_fn = lptstr_to_utf8(lptstr_fn);
 
1804
                removing_leading_and_trailing_white_space(utf8_fn);
 
1805
                if(!*utf8_fn){
 
1806
                    MessageBox(hDlg, TEXT("Configuration File Name field empty"),
 
1807
                               TEXT("Alpine"), MB_ICONWARNING | MB_OK);
 
1808
                    if(utf8_fn)
 
1809
                      fs_give((void **) &utf8_fn);
 
1810
 
 
1811
                    return(TRUE);
 
1812
                }
 
1813
 
 
1814
                if(strlen(utf8_fn) >= dlgcfg->confpathlen){
 
1815
                    MessageBox(hDlg, TEXT("Config path too long"),
 
1816
                               TEXT("Alpine"), MB_ICONWARNING | MB_OK);
 
1817
                    if(utf8_fn)
 
1818
                      fs_give((void **) &utf8_fn);
 
1819
 
 
1820
                    return(TRUE);
 
1821
                }
 
1822
 
 
1823
                strncpy(dlgcfg->confpath, utf8_fn, dlgcfg->confpathlen);
 
1824
                dlgcfg->confpath[dlgcfg->confpathlen-1] = '\0';
 
1825
                if(utf8_fn)
 
1826
                  fs_give((void **) &utf8_fn);
 
1827
            }
 
1828
 
 
1829
            EndDialog (hDlg, LOWORD(wParam));
 
1830
            dlgcfg->rv = 0;
 
1831
            ret = TRUE;
 
1832
            break;
 
1833
 
 
1834
        case IDCANCEL:
 
1835
            dlgcfg->rv = 1;
 
1836
            ret = TRUE;
 
1837
            EndDialog (hDlg, LOWORD(wParam));
 
1838
            break;
 
1839
        }
 
1840
        break;
 
1841
        
 
1842
 
 
1843
    }
 
1844
    return (ret);
 
1845
}
 
1846
 
 
1847
/*
 
1848
 * Get a button position in the parent's coordinate space.
 
1849
 */
 
1850
static void
 
1851
GetBtnPos (HWND hPrnt, HWND hWnd, RECT *r)
 
1852
{
 
1853
    GetWindowRect (hWnd, r);
 
1854
    ScreenToClient (hPrnt, (POINT *) r);
 
1855
    ScreenToClient (hPrnt, (POINT *) &r->right);
 
1856
}