4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
40 #define ENTRY_DEVICE 0
41 #define ENTRY_DIRECTORY 1
42 #define ENTRY_CUSTOM 999
43 #define CUSTOMENTRY_DIRTREE 1
44 #define CUSTOMENTRY_BUFFERLIST 2
45 #define CUSTOMENTRY_USER 3
55 PRINTDIR_FILEREQUESTER
,
60 PRINTDIR_NUM_GADGETS
};
63 printdir_size_gadget
[]={
64 {RO_Type
,OBJECT_GADGET
},
65 {RO_GadgetType
,GADGET_CHECK
},
66 {RO_GadgetID
,PRINTDIR_SIZE
},
70 {RO_TextNum
,STR_SIZE
},
71 {RO_TextPos
,TEXTPOS_RIGHT
},
75 printdir_date_gadget
[]={
76 {RO_Type
,OBJECT_GADGET
},
77 {RO_GadgetType
,GADGET_CHECK
},
78 {RO_GadgetID
,PRINTDIR_DATE
},
82 {RO_TextNum
,STR_DATE
},
83 {RO_TextPos
,TEXTPOS_RIGHT
},
87 printdir_protection_gadget
[]={
88 {RO_Type
,OBJECT_GADGET
},
89 {RO_GadgetType
,GADGET_CHECK
},
90 {RO_GadgetID
,PRINTDIR_PROTECTION
},
95 {RO_TextNum
,STR_PROTECTION
},
96 {RO_TextPos
,TEXTPOS_RIGHT
},
100 printdir_comment_gadget
[]={
101 {RO_Type
,OBJECT_GADGET
},
102 {RO_GadgetType
,GADGET_CHECK
},
103 {RO_GadgetID
,PRINTDIR_COMMENT
},
108 {RO_TextNum
,STR_COMMENT
},
109 {RO_TextPos
,TEXTPOS_RIGHT
},
112 printdir_filetype_gadget
[]={
113 {RO_Type
,OBJECT_GADGET
},
114 {RO_GadgetType
,GADGET_CHECK
},
115 {RO_GadgetID
,PRINTDIR_FILETYPE
},
119 {RO_TextNum
,STR_FILETYPE
},
120 {RO_TextPos
,TEXTPOS_RIGHT
},
124 printdir_printer_gadget
[]={
125 {RO_Type
,OBJECT_GADGET
},
126 {RO_GadgetType
,GADGET_RADIO
},
127 {RO_GadgetID
,PRINTDIR_PRINTER
},
131 {RO_TextNum
,STR_PRINTER
},
132 {RO_TextPos
,TEXTPOS_RIGHT
},
136 printdir_file_gadget
[]={
137 {RO_Type
,OBJECT_GADGET
},
138 {RO_GadgetType
,GADGET_RADIO
},
139 {RO_GadgetID
,PRINTDIR_FILE
},
143 {RO_TextNum
,STR_FILE
},
144 {RO_TextPos
,TEXTPOS_RIGHT
},
147 printdir_filerequester_gadget
[]={
148 {RO_Type
,OBJECT_GADGET
},
149 {RO_GadgetType
,GADGET_TINYGLASS
},
150 {RO_GadgetID
,PRINTDIR_FILEREQUESTER
},
158 {RO_HighRecess
,TRUE
},
160 printdir_filestring_gadget
[]={
161 {RO_Type
,OBJECT_GADGET
},
162 {RO_GadgetType
,GADGET_STRING
},
163 {RO_GadgetID
,PRINTDIR_FILESTRING
},
174 printdir_print_gadget
[]={
175 {RO_Type
,OBJECT_GADGET
},
176 {RO_GadgetType
,GADGET_BOOLEAN
},
177 {RO_GadgetID
,PRINTDIR_PRINT
},
183 {RO_TextNum
,STR_PRINT
},
184 {RO_TextPos
,TEXTPOS_CENTER
},
185 {RO_HighRecess
,TRUE
},
187 printdir_exit_gadget
[]={
188 {RO_Type
,OBJECT_GADGET
},
189 {RO_GadgetType
,GADGET_BOOLEAN
},
190 {RO_GadgetID
,PRINTDIR_EXIT
},
198 {RO_TextNum
,STR_EXIT
},
199 {RO_TextPos
,TEXTPOS_CENTER
},
200 {RO_HighRecess
,TRUE
},
203 printdir_print_text
[]={
204 {RO_Type
,OBJECT_TEXT
},
206 {RO_TextNum
,STR_PRINT_DOT
},
209 printdir_output_text
[]={
210 {RO_Type
,OBJECT_TEXT
},
213 {RO_TextNum
,STR_OUTPUT_TO
},
216 *printdir_gadgets
[]={
217 printdir_size_gadget
,
218 printdir_date_gadget
,
219 printdir_protection_gadget
,
220 printdir_comment_gadget
,
221 printdir_filetype_gadget
,
222 printdir_printer_gadget
,
223 printdir_file_gadget
,
224 printdir_filerequester_gadget
,
225 printdir_filestring_gadget
,
226 printdir_print_gadget
,
227 printdir_exit_gadget
,
230 int printdir_string(struct RequesterBase
*,BPTR
,char *);
232 void do_printdir(vis
,portname
,wind
)
237 struct RequesterBase printdirreq
;
238 struct IntuiMessage
*msg
;
239 struct Window
*window
;
240 struct Gadget
*gadgets
[PRINTDIR_NUM_GADGETS
];
244 struct StringExtend stringex
;
245 struct Requester busyreq
;
246 char *printdir_filestring_buffer
;
249 printdirreq
.rb_width
=40;
250 printdirreq
.rb_height
=8;
251 printdirreq
.rb_flags
=0;
253 fill_out_req(&printdirreq
,vis
);
255 printdirreq
.rb_privateflags
=0;
256 printdirreq
.rb_screenname
=NULL
;
258 if (printdirreq
.rb_screen
&& !(vis
->vi_flags
&VISF_BORDERS
)) {
259 printdirreq
.rb_flags
|=RBF_STRINGS
;
260 printdirreq
.rb_title
=NULL
;
263 printdirreq
.rb_flags
|=RBF_BORDERS
|RBF_CLOSEGAD
|RBF_STRINGS
;
264 printdirreq
.rb_title
=string_table
[STR_PRINTDIR
];
267 printdirreq
.rb_widthfine
=45;
268 printdirreq
.rb_heightfine
=45;
269 printdirreq
.rb_leftoffset
=13;
270 printdirreq
.rb_topoffset
=3;
272 printdirreq
.rb_extend
=&stringex
;
273 printdirreq
.rb_idcmpflags
=0;
274 printdirreq
.rb_string_table
=string_table
;
277 stringex
.Pens
[a
]=vis
->vi_stringcol
[a
];
278 stringex
.ActivePens
[a
]=vis
->vi_activestringcol
[a
];
280 stringex
.InitialModes
=0;
281 stringex
.EditHook
=NULL
;
282 stringex
.WorkBuffer
=NULL
;
283 for (a
=0;a
<4;a
++) stringex
.Reserved
[a
]=0;
285 if (!(window
=OpenRequester(&printdirreq
)) ||
286 !(addreqgadgets(&printdirreq
,printdir_gadgets
,gadgets
)) ||
287 !(AddRequesterObject(&printdirreq
,printdir_print_text
)) ||
288 !(AddRequesterObject(&printdirreq
,printdir_output_text
))) {
289 CloseRequester(&printdirreq
);
293 RefreshRequesterObject(&printdirreq
,NULL
);
295 printdir_filestring_buffer
=
296 ((struct StringInfo
*)gadgets
[PRINTDIR_FILESTRING
]->SpecialInfo
)->Buffer
;
298 read_printdir_env(&printflags
,&a
,printdir_filestring_buffer
);
300 gadgets
[PRINTDIR_PRINTER
]->Flags
&=~GFLG_SELECTED
;
301 gadgets
[PRINTDIR_FILE
]->Flags
|=GFLG_SELECTED
;
304 if (printflags
&(1<<a
)) gadgets
[a
]->Flags
|=GFLG_SELECTED
;
305 else gadgets
[a
]->Flags
&=~GFLG_SELECTED
;
308 RefreshGList(gadgets
[0],window
,NULL
,-1);
311 while (msg
=(struct IntuiMessage
*)GetMsg(window
->UserPort
)) {
312 class=msg
->Class
; code
=msg
->Code
;
313 iaddress
=msg
->IAddress
;
314 ReplyMsg((struct Message
*)msg
);
317 case IDCMP_GADGETDOWN
:
318 gadgetid
=((struct Gadget
*)iaddress
)->GadgetID
;
322 case PRINTDIR_PRINTER
:
323 gadgets
[PRINTDIR_PRINTER
]->Flags
|=GFLG_SELECTED
;
324 gadgets
[PRINTDIR_FILE
]->Flags
&=~GFLG_SELECTED
;
325 RefreshGList(gadgets
[PRINTDIR_PRINTER
],window
,NULL
,2);
329 gadgets
[PRINTDIR_PRINTER
]->Flags
&=~GFLG_SELECTED
;
330 gadgets
[PRINTDIR_FILE
]->Flags
|=GFLG_SELECTED
;
331 RefreshGList(gadgets
[PRINTDIR_PRINTER
],window
,NULL
,2);
337 gadgetid
=((struct Gadget
*)iaddress
)->GadgetID
;
341 case PRINTDIR_FILEREQUESTER
:
342 if (!(get_file_byrequest(gadgets
[PRINTDIR_FILESTRING
],window
,1)))
344 case PRINTDIR_FILESTRING
:
345 RefreshStrGad(gadgets
[PRINTDIR_FILESTRING
],window
);
346 if (gadgets
[PRINTDIR_PRINTER
]->Flags
&GFLG_SELECTED
) {
347 gadgets
[PRINTDIR_PRINTER
]->Flags
&=~GFLG_SELECTED
;
348 gadgets
[PRINTDIR_FILE
]->Flags
|=GFLG_SELECTED
;
349 RefreshGList(gadgets
[PRINTDIR_PRINTER
],window
,NULL
,2);
357 if (gadgets
[a
]->Flags
&GFLG_SELECTED
) printflags
|=1<<a
;
360 InitRequester(&busyreq
);
361 busyreq
.Flags
=NOISYREQ
;
362 Request(&busyreq
,window
);
363 SetBusyPointer(window
);
365 printdirectory(&printdirreq
,
367 (gadgets
[PRINTDIR_PRINTER
]->Flags
&GFLG_SELECTED
)?"PRT:":
368 printdir_filestring_buffer
,wind
);
369 gadgetid
=PRINTDIR_EXIT
;
371 EndRequest(&busyreq
,window
);
378 if (gadgetid
!=PRINTDIR_EXIT
) break;
380 case IDCMP_VANILLAKEY
:
381 if (code
!=0x1b) break;
383 case IDCMP_CLOSEWINDOW
:
385 SetBusyPointer(window
);
388 if (gadgets
[a
]->Flags
&GFLG_SELECTED
) printflags
|=1<<a
;
390 save_printdir_env(printflags
,
391 (gadgets
[PRINTDIR_PRINTER
]->Flags
&GFLG_SELECTED
)?1:0,
392 printdir_filestring_buffer
);
394 CloseRequester(&printdirreq
);
398 Wait(1<<window
->UserPort
->mp_SigBit
);
402 void printdirectory(reqbase
,portname
,flags
,output
,wind
)
403 struct RequesterBase
*reqbase
;
409 struct PrintDirData pddata
;
410 char buf
[256],pbuf
[128];
415 if (!(dopus_message(DOPUSMSG_GETPRINTDIR
,(APTR
)&pddata
,portname
)))
419 if (out
=Open(output
,MODE_NEWFILE
)) break;
420 if (!(check_error(reqbase
,string_table
[STR_UNABLE_TO_OPEN_OUTPUT
],0)))
425 if (!(printdir_string(reqbase
,out
,pddata
.titlebuf
))) {
430 while (pddata
.entry
) {
431 if (check_print_abort(reqbase
)) {
435 if (!pddata
.onlysel
|| pddata
.entry
->selected
) {
436 switch (pddata
.entry
->type
) {
438 if (pddata
.entry
->comment
&&
439 !(printdir_string(reqbase
,out
,pddata
.entry
->comment
))) abort
=1;
442 lsprintf(buf
,"%-32s",pddata
.entry
->name
);
443 if (pddata
.entry
->comment
) strcat(buf
,pddata
.entry
->comment
);
444 if (!(printdir_string(reqbase
,out
,buf
))) abort
=1;
447 lsprintf(buf
,"%-30s",pddata
.entry
->name
);
449 if (pddata
.entry
->type
<=ENTRY_FILE
) {
450 lsprintf(pbuf
,"%7ld",pddata
.entry
->size
);
453 else strcat(buf
," Dir");
457 strcat(buf
,pddata
.entry
->protbuf
);
461 strcat(buf
,pddata
.entry
->datebuf
);
463 if (flags
&PD_TYPE
&& pddata
.entry
->description
) {
465 strcat(buf
,pddata
.entry
->description
);
468 if (!(printdir_string(reqbase
,out
,buf
))) {
472 if (flags
&PD_COMM
&& pddata
.entry
->comment
) {
473 StrCombine(buf
,": ",pddata
.entry
->comment
,256);
474 if (!(printdir_string(reqbase
,out
,buf
))) abort
=1;
480 pddata
.entry
=pddata
.entry
->next
;
482 if (!abort
) Write(out
,"\n",1);
487 int printdir_string(reqbase
,file
,string
)
488 struct RequesterBase
*reqbase
;
496 if ((Write(file
,string
,len
))==len
) {
500 if (!(check_error(reqbase
,string_table
[STR_ERROR_PRINTING_DIR
],0)))
505 void save_printdir_env(flags
,printer
,filename
)
511 if (file
=Open("env:DOpus_printdir.prefs",MODE_NEWFILE
)) {
512 Write(file
,(char *)&flags
,sizeof(int));
513 Write(file
,(char *)&printer
,sizeof(int));
514 Write(file
,filename
,strlen(filename
)+1);
519 void read_printdir_env(flags
,printer
,filename
)
525 if (file
=Open("env:DOpus_printdir.prefs",MODE_OLDFILE
)) {
526 Read(file
,(char *)flags
,sizeof(int));
527 Read(file
,(char *)printer
,sizeof(int));
528 Read(file
,filename
,256);