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"
19 bool sendfax(string const &fname, string const &sendcmd);
20 bool button_send(string const &fname, string const &sendcmd = string());
21 void show_logfile(string logfile, bool show_if_empty);
23 const int LEN_PHONE = 20;
24 const int LEN_NAME = 25;
26 /* Global Variables */
29 string global_sendcmd;
32 FD_xsendfax *fd_xsendfax;
33 FD_phonebook *fd_phonebook;
34 FD_logfile *fd_logfile;
36 bool send_fax(string const &fname, string const &sendcmd)
38 // I put FAXCMD here to see if I can get rid of some strange errors. (Lgb)
39 string FAXCMD = "sendfax -n -h '$$Host' -c '$$Comment' -x '$$Enterprise' -d '$$Name'@'$$Phone' '$$FName'";
40 string title = _("Fax File: ");
45 path= OnlyPath(fname);
46 if (path.empty() || path == "./")
47 filename = GetCWD() + "/" + fname;
52 global_sendcmd = FAXCMD;
54 global_sendcmd = sendcmd;
56 fd_xsendfax = create_form_xsendfax();
57 fd_phonebook = create_form_phonebook();
58 fd_logfile = create_form_logfile();
60 // Make sure the close box doesn't kill LyX when being pressed. (RvdK)
61 fl_set_form_atclose(fd_xsendfax->xsendfax, CancelCloseBoxCB, 0);
62 fl_set_form_atclose(fd_phonebook->phonebook, CancelCloseBoxCB, 0);
63 fl_set_form_atclose(fd_logfile->logfile, CancelCloseBoxCB, 0);
66 string phone_book_name;
67 if (lyxrc.phone_book.empty()) {
68 phone_book_name = "phonebook";
70 phone_book_name = lyxrc.phone_book;
71 phone_book= FileSearch(user_lyxdir, phone_book_name);
72 if (phone_book.empty())
73 phone_book = AddName(user_lyxdir, phone_book_name);
75 fl_set_browser_fontsize(fd_phonebook->browser, FL_NORMAL_SIZE);
76 fl_set_browser_fontstyle(fd_phonebook->browser, FL_FIXED_STYLE);
77 fl_load_browser(fd_phonebook->browser, phone_book.c_str());
79 title += OnlyFilename(fname);
81 /* show the first form */
82 fl_show_form(fd_xsendfax->xsendfax, FL_PLACE_MOUSE, FL_FULLBORDER, title.c_str());
86 if (obj == fd_xsendfax->Button_Cancel)
88 else if (obj == fd_xsendfax->Button_Send) {
89 if (button_send(fname, global_sendcmd))
91 } else if (obj == fd_xsendfax->Button_Apply) {
92 button_send(fname, global_sendcmd);
93 } else if (obj == fd_xsendfax->Button_SPhone) {
94 cb_select_phoneno(0, 0);
97 fl_hide_form(fd_xsendfax->xsendfax);
103 bool button_send(string const &fname, string const &sendcmd)
106 name = fl_get_input(fd_xsendfax->Input_Name),
107 phone = fl_get_input(fd_xsendfax->Input_Phone),
108 enterprise = fl_get_input(fd_xsendfax->Input_Enterprise),
109 comment = fl_get_input(fd_xsendfax->Input_Comment),
110 host = GetEnv("FAX_SERVER"),
116 logfile = TmpFileName(OnlyPath(fname), "FAX");
117 cmd = sendcmd + " >";
118 cmd += logfile + " 2>";
120 cmd = subst(cmd, "$$Host", host);
121 cmd = subst(cmd, "$$Comment", comment);
122 cmd = subst(cmd, "$$Enterprise", enterprise);
123 cmd = subst(cmd, "$$Name", name);
124 cmd = subst(cmd, "$$Phone", phone);
125 cmd = subst(cmd, "$$FName", fname);
126 lyxerr << "CMD: " << cmd << endl;
127 Systemcalls one(Systemcalls::System, cmd);
128 show_logfile(logfile, false);
129 remove(logfile.c_str());
134 void cb_hide_form(FL_OBJECT *ob, long)
136 fl_hide_form(ob->form);
140 void cb_select_phoneno(FL_OBJECT *, long)
144 n= fl_get_browser_maxline(fd_phonebook->browser);
148 fl_hide_form(fd_phonebook->phonebook);
149 line = fl_get_browser_line(fd_phonebook->browser, 1);
150 if (!n || strstr(line, _("Empty Phonebook"))) {
151 fl_clear_browser(fd_phonebook->browser);
154 i = fl_get_browser(fd_phonebook->browser);
155 line = fl_get_browser_line(fd_phonebook->browser, i);
158 char *buf = new char [strlen(line)+1];
161 for(i = LEN_PHONE; (i > 0) && (buf[i] == ' '); --i)
164 for(i = LEN_PHONE + LEN_NAME + 1; (i > LEN_PHONE) && (buf[i] == ' '); --i)
167 fl_set_input(fd_xsendfax->Input_Phone, buf);
168 fl_set_input(fd_xsendfax->Input_Name, buf+LEN_PHONE+1);
169 fl_set_input(fd_xsendfax->Input_Enterprise, buf+LEN_PHONE+LEN_NAME+2);
174 void cb_add_phoneno(FL_OBJECT *, long )
179 *name = fl_get_input(fd_xsendfax->Input_Name),
180 *phone = fl_get_input(fd_xsendfax->Input_Phone),
181 *enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
188 char * buf = new char [50 + strlen(enterprise)];
190 sprintf(buf, "%-*.*s %-*.*s %s",
191 LEN_PHONE, LEN_PHONE, phone,
192 LEN_NAME, LEN_NAME, name,
194 n = fl_get_browser_maxline(fd_phonebook->browser);
196 line = fl_get_browser_line(fd_phonebook->browser, 1);
197 if (strstr(line, _("Empty Phonebook"))) {
198 fl_clear_browser(fd_phonebook->browser);
202 for(i = 1; i <= n; ++i) {
203 line = fl_get_browser_line(fd_phonebook->browser, i);
204 if (!strncmp(buf, line, 46))
208 fl_addto_browser(fd_phonebook->browser, buf);
209 fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
215 void cb_delete_phoneno(FL_OBJECT *, long )
220 *name = fl_get_input(fd_xsendfax->Input_Name),
221 *phone = fl_get_input(fd_xsendfax->Input_Phone),
222 *enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
228 char *buf = new char [50+strlen(enterprise)];
229 sprintf(buf, "%-*.*s %-*.*s %s",
230 LEN_PHONE, LEN_PHONE, phone,
231 LEN_NAME, LEN_NAME, name,
233 n = fl_get_browser_maxline(fd_phonebook->browser);
235 line = fl_get_browser_line(fd_phonebook->browser, 1);
236 if (strstr(line, _("Empty Phonebook"))) {
237 fl_clear_browser(fd_phonebook->browser);
241 for(i = 1; i <= n; ++i) {
242 line = fl_get_browser_line(fd_phonebook->browser, i);
243 if (!strncmp(buf, line, 46))
247 fl_delete_browser_line(fd_phonebook->browser, i);
248 fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
254 void cb_save_phoneno(FL_OBJECT *, long )
263 if (!(fp = fopen(phone_book.c_str(), "w"))) {
264 WriteAlert(_("Error!"), _("Cannot open phone book: "), phone_book);
267 n = fl_get_browser_maxline(fd_phonebook->browser);
269 line = fl_get_browser_line(fd_phonebook->browser, 1);
270 if (strstr(line, _("Empty Phonebook"))) {
271 fl_clear_browser(fd_phonebook->browser);
275 for(i = 1; i <= n; ++i) {
276 line = fl_get_browser_line(fd_phonebook->browser, i);
277 fprintf(fp, "%s\n", line);
280 fl_set_object_label(fd_xsendfax->pb_save, _("Save"));
281 fl_redraw_form(fd_xsendfax->xsendfax);
284 void show_logfile(string logfile, bool show_if_empty)
288 if (!fl_load_browser(fd_logfile->browser, logfile.c_str())) {
291 fl_add_browser_line(fd_logfile->browser,
292 _("NO OR EMPTY LOGFILE!"));
294 if (fd_logfile->logfile->visible) {
295 fl_raise_form(fd_logfile->logfile);
297 fl_show_form(fd_logfile->logfile,
298 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
299 _("Message-Window"));
303 void FaxLogfileCloseCB(FL_OBJECT *, long)
305 fl_hide_form(fd_logfile->logfile);
308 void FaxCancelCB(FL_OBJECT *, long)
310 fl_hide_form(fd_xsendfax->xsendfax);
313 void FaxApplyCB(FL_OBJECT *, long)
315 button_send(filename, global_sendcmd);
318 void FaxSendCB(FL_OBJECT *, long)
320 if (button_send(filename, global_sendcmd))
324 void FaxOpenPhonebookCB(FL_OBJECT *, long)
327 n= fl_get_browser_maxline(fd_phonebook->browser);
330 fl_addto_browser(fd_phonebook->browser, _("@L@b@cEmpty Phonebook"));
331 fl_show_form(fd_phonebook->phonebook, FL_PLACE_MOUSE, FL_FULLBORDER,