1 /*
2 * This file is part of XForms.
3 *
4 * XForms is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1, or
7 * (at your option) any later version.
8 *
9 * XForms is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with XForms; see the file COPYING. If not, write to
16 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17 * MA 02111-1307, USA.
18 */
19
20
21 /*
22 * test of fl_get_dirlist() and its kin.
23 *
24 * This file is part of xforms package
25 * T.C. Zhao and M. Overmars (1997)
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "include/forms.h"
33 #include <time.h>
34 #include <stdlib.h>
35 #include "fd/fbtest_gui.h"
36
37
38 /***************************************
39 ***************************************/
40
41 static void
fill_browser(FL_OBJECT * ob)42 fill_browser( FL_OBJECT * ob )
43 {
44 FD_fbform *fdui = ( FD_fbform * ) ob->form->fdui;
45 int nfiles = 0;
46 const FL_Dirlist *dl = fl_get_dirlist( ".", "*", &nfiles, 0 );
47 const FL_Dirlist *ds;
48 const FL_Dirlist *dlend = dl + nfiles;
49 char buf[ 2048 ];
50
51 fl_freeze_form( ob->form );
52 sprintf( buf,"Total %d files", nfiles );
53 fl_set_object_label( fdui->total, buf );
54 fl_clear_browser( fdui->browser );
55
56 for ( ds = dl; dl < dlend; dl++ )
57 {
58 sprintf( buf, "%-10s\t\t%5ldK\t%s", dl->name, dl->dl_size >> 10,
59 ctime( &dl->dl_mtime ) + 3 );
60 fl_addto_browser_chars( fdui->browser, buf );
61 }
62
63 fl_unfreeze_form( ob->form );
64
65 fl_free_dirlist( ( FL_Dirlist * ) ds );
66 }
67
68
69 /* callbacks and freeobj handles for form fbform */
70
71 /***************************************
72 ***************************************/
73
74 void
sort_method_cb(FL_OBJECT * ob,long data)75 sort_method_cb( FL_OBJECT * ob,
76 long data )
77 {
78 fl_set_dirlist_sort( data );
79 fill_browser( ob );
80 }
81
82
83 /***************************************
84 ***************************************/
85
86 void
done_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)87 done_cb( FL_OBJECT * ob FL_UNUSED_ARG,
88 long data FL_UNUSED_ARG )
89 {
90 fl_finish( );
91 exit( 0 );
92 }
93
94
95 /***************************************
96 ***************************************/
97
98 int
main(int argc,char * argv[])99 main( int argc,
100 char * argv[ ] )
101 {
102 FD_fbform *fd_fbform;
103
104 fl_initialize( &argc, argv, 0, 0, 0 );
105 fd_fbform = create_form_fbform( );
106 fl_set_browser_fontstyle( fd_fbform->browser, FL_FIXED_STYLE );
107
108 /* fill-in form initialization code */
109
110 fill_browser( fd_fbform->browser );
111
112 /* show the first form */
113
114 fl_show_form( fd_fbform->fbform, FL_PLACE_CENTERFREE, FL_FULLBORDER,
115 "fbform" );
116
117 fl_do_forms( );
118
119 return 0;
120 }
121
122
123 /*
124 * Local variables:
125 * tab-width: 4
126 * indent-tabs-mode: nil
127 * End:
128 */
129