5 #include FORMS_H_LOCATION
7 #include "lyx_sendfax.h"
10 #include "support/filetools.h"
11 #include "lyx_gui_misc.h" // CancelCloseBoxCB
12 #include "support/syscall.h"
17 bool sendfax(string const &fname, string const &sendcmd);
18 bool button_send(string const &fname, string const &sendcmd = string());
19 void show_logfile(string logfile, bool show_if_empty);
21 const int LEN_PHONE = 20;
22 const int LEN_NAME = 25;
24 /* Global Variables */
27 string global_sendcmd;
30 FD_xsendfax *fd_xsendfax;
31 FD_phonebook *fd_phonebook;
32 FD_logfile *fd_logfile;
34 bool send_fax(string const &fname, string const &sendcmd)
36 // I put FAXCMD here to see if I can get rid of some strange errors. (Lgb)
37 string FAXCMD = "sendfax -n -h '$$Host' -c '$$Comment' -x '$$Enterprise' -d '$$Name'@'$$Phone' '$$FName'";
38 string title = _("Fax File: ");
44 if (path.empty() || path == "./")
45 filename = GetCWD() + "/" + fname;
50 global_sendcmd = FAXCMD;
52 global_sendcmd = sendcmd;
54 fd_xsendfax = create_form_xsendfax();
55 fd_phonebook = create_form_phonebook();
56 fd_logfile = create_form_logfile();
58 // Make sure the close box doesn't kill LyX when being pressed. (RvdK)
59 fl_set_form_atclose(fd_xsendfax->xsendfax, CancelCloseBoxCB, 0);
60 fl_set_form_atclose(fd_phonebook->phonebook, CancelCloseBoxCB, 0);
61 fl_set_form_atclose(fd_logfile->logfile, CancelCloseBoxCB, 0);
64 string phone_book_name;
65 if (lyxrc->phone_book.empty()) {
66 phone_book_name = "phonebook";
68 phone_book_name = lyxrc->phone_book;
69 phone_book=FileSearch(user_lyxdir,phone_book_name);
70 if (phone_book.empty())
71 phone_book = AddName(user_lyxdir,phone_book_name);
73 fl_set_browser_fontsize(fd_phonebook->browser, FL_NORMAL_SIZE);
74 fl_set_browser_fontstyle(fd_phonebook->browser, FL_FIXED_STYLE);
75 fl_load_browser(fd_phonebook->browser, phone_book.c_str());
77 title += OnlyFilename(fname);
79 /* show the first form */
80 fl_show_form(fd_xsendfax->xsendfax,FL_PLACE_MOUSE,FL_FULLBORDER,title.c_str());
84 if (obj==fd_xsendfax->Button_Cancel)
86 else if (obj==fd_xsendfax->Button_Send) {
87 if (button_send(fname,global_sendcmd))
89 } else if (obj==fd_xsendfax->Button_Apply) {
90 button_send(fname,global_sendcmd);
91 } else if (obj==fd_xsendfax->Button_SPhone) {
92 cb_select_phoneno(0,0);
95 fl_hide_form(fd_xsendfax->xsendfax);
101 bool button_send(string const &fname, string const &sendcmd)
104 name = fl_get_input(fd_xsendfax->Input_Name),
105 phone = fl_get_input(fd_xsendfax->Input_Phone),
106 enterprise = fl_get_input(fd_xsendfax->Input_Enterprise),
107 comment = fl_get_input(fd_xsendfax->Input_Comment),
108 host = GetEnv("FAX_SERVER"),
114 logfile = TmpFileName(OnlyPath(fname),"FAX");
115 cmd = sendcmd + " >";
116 cmd += logfile + " 2>";
118 subst(cmd, "$$Host",host);
119 subst(cmd, "$$Comment",comment);
120 subst(cmd, "$$Enterprise",enterprise);
121 subst(cmd, "$$Name",name);
122 subst(cmd, "$$Phone",phone);
123 subst(cmd, "$$FName",fname);
124 lyxerr << "CMD: " << cmd << endl;
125 Systemcalls one(Systemcalls::System, cmd);
126 show_logfile(logfile,false);
127 remove(logfile.c_str());
132 void cb_hide_form(FL_OBJECT *ob, long)
134 fl_hide_form(ob->form);
138 void cb_select_phoneno(FL_OBJECT *, long)
142 n=fl_get_browser_maxline(fd_phonebook->browser);
146 fl_hide_form(fd_phonebook->phonebook);
147 line = fl_get_browser_line(fd_phonebook->browser, 1);
148 if (!n || strstr(line,_("Empty Phonebook"))) {
149 fl_clear_browser(fd_phonebook->browser);
152 i = fl_get_browser(fd_phonebook->browser);
153 line = fl_get_browser_line(fd_phonebook->browser, i);
156 char *buf = new char [strlen(line)+1];
159 for(i = LEN_PHONE;(i>0) && (buf[i]==' ');i--)
162 for(i = LEN_PHONE+LEN_NAME+1;(i>LEN_PHONE) && (buf[i]==' ');i--)
165 fl_set_input(fd_xsendfax->Input_Phone,buf);
166 fl_set_input(fd_xsendfax->Input_Name,buf+LEN_PHONE+1);
167 fl_set_input(fd_xsendfax->Input_Enterprise,buf+LEN_PHONE+LEN_NAME+2);
172 void cb_add_phoneno(FL_OBJECT *, long )
177 *name = fl_get_input(fd_xsendfax->Input_Name),
178 *phone = fl_get_input(fd_xsendfax->Input_Phone),
179 *enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
186 char *buf = new char [50+strlen(enterprise)];
188 sprintf(buf,"%-*.*s %-*.*s %s",
189 LEN_PHONE,LEN_PHONE,phone,
190 LEN_NAME,LEN_NAME,name,
192 n = fl_get_browser_maxline(fd_phonebook->browser);
194 line = fl_get_browser_line(fd_phonebook->browser, 1);
195 if (strstr(line,_("Empty Phonebook"))) {
196 fl_clear_browser(fd_phonebook->browser);
200 for(i = 1; i <= n; i++) {
201 line = fl_get_browser_line(fd_phonebook->browser, i);
202 if (!strncmp(buf,line,46))
206 fl_addto_browser(fd_phonebook->browser,buf);
207 fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
213 void cb_delete_phoneno(FL_OBJECT *, long )
218 *name = fl_get_input(fd_xsendfax->Input_Name),
219 *phone = fl_get_input(fd_xsendfax->Input_Phone),
220 *enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
226 char *buf = new char [50+strlen(enterprise)];
227 sprintf(buf,"%-*.*s %-*.*s %s",
228 LEN_PHONE,LEN_PHONE,phone,
229 LEN_NAME,LEN_NAME,name,
231 n = fl_get_browser_maxline(fd_phonebook->browser);
233 line = fl_get_browser_line(fd_phonebook->browser, 1);
234 if (strstr(line,_("Empty Phonebook"))) {
235 fl_clear_browser(fd_phonebook->browser);
240 line = fl_get_browser_line(fd_phonebook->browser, i);
241 if (!strncmp(buf,line,46))
245 fl_delete_browser_line(fd_phonebook->browser,i);
246 fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
252 void cb_save_phoneno(FL_OBJECT *, long )
261 if (!(fp = fopen(phone_book.c_str(),"w"))) {
262 WriteAlert(_("Error!"),_("Cannot open phone book: "),phone_book);
265 n = fl_get_browser_maxline(fd_phonebook->browser);
267 line = fl_get_browser_line(fd_phonebook->browser, 1);
268 if (strstr(line,_("Empty Phonebook"))) {
269 fl_clear_browser(fd_phonebook->browser);
274 line = fl_get_browser_line(fd_phonebook->browser, i);
275 fprintf(fp,"%s\n",line);
278 fl_set_object_label(fd_xsendfax->pb_save, _("Save"));
279 fl_redraw_form(fd_xsendfax->xsendfax);
282 void show_logfile(string logfile, bool show_if_empty)
286 if (!fl_load_browser(fd_logfile->browser,logfile.c_str())) {
289 fl_add_browser_line(fd_logfile->browser,
290 _("NO OR EMPTY LOGFILE!"));
292 if (fd_logfile->logfile->visible) {
293 fl_raise_form(fd_logfile->logfile);
295 fl_show_form(fd_logfile->logfile,
296 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
297 _("Message-Window"));
301 void FaxLogfileCloseCB(FL_OBJECT *, long)
303 fl_hide_form(fd_logfile->logfile);
306 void FaxCancelCB(FL_OBJECT *, long)
308 fl_hide_form(fd_xsendfax->xsendfax);
311 void FaxApplyCB(FL_OBJECT *, long)
313 button_send(filename,global_sendcmd);
316 void FaxSendCB(FL_OBJECT *, long)
318 if (button_send(filename,global_sendcmd))
322 void FaxOpenPhonebookCB(FL_OBJECT *, long)
325 n=fl_get_browser_maxline(fd_phonebook->browser);
328 fl_addto_browser(fd_phonebook->browser,_("@L@b@cEmpty Phonebook"));
329 fl_show_form(fd_phonebook->phonebook,FL_PLACE_MOUSE,FL_FULLBORDER,