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());
23 void show_logfile(string const & logfile, bool show_if_empty);
25 const int LEN_PHONE = 20;
26 const int LEN_NAME = 25;
28 /* Global Variables */
31 string global_sendcmd;
34 FD_xsendfax * fd_xsendfax;
35 FD_phonebook * fd_phonebook;
36 FD_logfile * fd_logfile;
39 bool send_fax(string const & fname, string const & sendcmd)
41 // I put FAXCMD here to see if I can get rid of some strange errors. (Lgb)
42 string FAXCMD = "sendfax -n -h '$$Host' -c '$$Comment' -x '$$Enterprise' -d '$$Name'@'$$Phone' '$$FName'";
43 string title = _("Fax File: ");
48 path = OnlyPath(fname);
49 if (path.empty() || path == "./")
50 filename = GetCWD() + "/" + fname;
55 global_sendcmd = FAXCMD;
57 global_sendcmd = sendcmd;
59 fd_xsendfax = create_form_xsendfax();
60 fd_phonebook = create_form_phonebook();
61 fd_logfile = create_form_logfile();
63 // Make sure the close box doesn't kill LyX when being pressed. (RvdK)
64 fl_set_form_atclose(fd_xsendfax->xsendfax, CancelCloseBoxCB, 0);
65 fl_set_form_atclose(fd_phonebook->phonebook, CancelCloseBoxCB, 0);
66 fl_set_form_atclose(fd_logfile->logfile, CancelCloseBoxCB, 0);
69 string phone_book_name;
70 if (lyxrc.phone_book.empty()) {
71 phone_book_name = "phonebook";
73 phone_book_name = lyxrc.phone_book;
74 phone_book= FileSearch(user_lyxdir, phone_book_name);
75 if (phone_book.empty())
76 phone_book = AddName(user_lyxdir, phone_book_name);
78 fl_set_browser_fontsize(fd_phonebook->browser, FL_NORMAL_SIZE);
79 fl_set_browser_fontstyle(fd_phonebook->browser, FL_FIXED_STYLE);
80 fl_load_browser(fd_phonebook->browser, phone_book.c_str());
82 title += OnlyFilename(fname);
84 /* show the first form */
85 fl_show_form(fd_xsendfax->xsendfax,
86 FL_PLACE_MOUSE, FL_FULLBORDER, title.c_str());
90 if (obj == fd_xsendfax->Button_Cancel)
92 else if (obj == fd_xsendfax->Button_Send) {
93 if (button_send(fname, global_sendcmd))
95 } else if (obj == fd_xsendfax->Button_Apply) {
96 button_send(fname, global_sendcmd);
97 } else if (obj == fd_xsendfax->Button_SPhone) {
98 cb_select_phoneno(0, 0);
101 fl_hide_form(fd_xsendfax->xsendfax);
107 bool button_send(string const & fname, string const & sendcmd)
109 string name = fl_get_input(fd_xsendfax->Input_Name);
110 string phone = fl_get_input(fd_xsendfax->Input_Phone);
111 string enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
112 string comment = fl_get_input(fd_xsendfax->Input_Comment);
113 string host = GetEnv("FAX_SERVER");
117 string logfile = TmpFileName(OnlyPath(fname), "FAX");
118 string cmd = sendcmd + " >";
119 cmd += logfile + " 2>";
121 cmd = subst(cmd, "$$Host", host);
122 cmd = subst(cmd, "$$Comment", comment);
123 cmd = subst(cmd, "$$Enterprise", enterprise);
124 cmd = subst(cmd, "$$Name", name);
125 cmd = subst(cmd, "$$Phone", phone);
126 cmd = subst(cmd, "$$FName", fname);
127 lyxerr << "CMD: " << cmd << endl;
128 Systemcalls one(Systemcalls::System, cmd);
129 show_logfile(logfile, false);
130 lyx::unlink(logfile);
135 void cb_hide_form(FL_OBJECT * ob, long)
137 fl_hide_form(ob->form);
141 void cb_select_phoneno(FL_OBJECT *, long)
143 int n = fl_get_browser_maxline(fd_phonebook->browser);
145 fl_hide_form(fd_phonebook->phonebook);
146 char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
147 if (!n || strstr(line, _("Empty Phonebook"))) {
148 fl_clear_browser(fd_phonebook->browser);
151 int i = fl_get_browser(fd_phonebook->browser);
152 line = fl_get_browser_line(fd_phonebook->browser, i);
155 char * buf = new char [strlen(line)+1];
158 for(i = LEN_PHONE; (i > 0) && (buf[i] == ' '); --i)
161 for(i = LEN_PHONE + LEN_NAME + 1; (i > LEN_PHONE) && (buf[i] == ' '); --i)
164 fl_set_input(fd_xsendfax->Input_Phone, buf);
165 fl_set_input(fd_xsendfax->Input_Name, buf+LEN_PHONE+1);
166 fl_set_input(fd_xsendfax->Input_Enterprise, buf+LEN_PHONE+LEN_NAME+2);
171 void cb_add_phoneno(FL_OBJECT *, long )
173 char const * phone = fl_get_input(fd_xsendfax->Input_Phone);
178 char const * name = fl_get_input(fd_xsendfax->Input_Name);
179 char const * enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
181 char * buf = new char [50 + strlen(enterprise)];
183 sprintf(buf, "%-*.*s %-*.*s %s",
184 LEN_PHONE, LEN_PHONE, phone,
185 LEN_NAME, LEN_NAME, name,
187 int n = fl_get_browser_maxline(fd_phonebook->browser);
189 char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
190 if (strstr(line, _("Empty Phonebook"))) {
191 fl_clear_browser(fd_phonebook->browser);
197 char const * line = fl_get_browser_line(fd_phonebook->browser, i);
198 if (!strncmp(buf, line, 46))
202 fl_addto_browser(fd_phonebook->browser, buf);
203 fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
209 void cb_delete_phoneno(FL_OBJECT *, long )
211 char const * phone = fl_get_input(fd_xsendfax->Input_Phone);
216 char const * name = fl_get_input(fd_xsendfax->Input_Name);
217 char const * enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
219 char * buf = new char [50+strlen(enterprise)];
221 sprintf(buf, "%-*.*s %-*.*s %s",
222 LEN_PHONE, LEN_PHONE, phone,
223 LEN_NAME, LEN_NAME, name,
225 int n = fl_get_browser_maxline(fd_phonebook->browser);
227 char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
228 if (strstr(line, _("Empty Phonebook"))) {
229 fl_clear_browser(fd_phonebook->browser);
235 char const * line = fl_get_browser_line(fd_phonebook->browser, i);
236 if (!strncmp(buf, line, 46))
240 fl_delete_browser_line(fd_phonebook->browser, i);
241 fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
247 void cb_save_phoneno(FL_OBJECT *, long )
249 FILE * fp = ::fopen(phone_book.c_str(), "w");
251 WriteAlert(_("Error!"), _("Cannot open phone book: "), phone_book);
254 int n = fl_get_browser_maxline(fd_phonebook->browser);
256 char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
257 if (strstr(line, _("Empty Phonebook"))) {
258 fl_clear_browser(fd_phonebook->browser);
264 char const * line = fl_get_browser_line(fd_phonebook->browser, i);
265 fprintf(fp, "%s\n", line);
268 fl_set_object_label(fd_xsendfax->pb_save, _("Save"));
269 fl_redraw_form(fd_xsendfax->xsendfax);
274 void show_logfile(string const & logfile, bool show_if_empty)
278 if (!fl_load_browser(fd_logfile->browser, logfile.c_str())) {
281 fl_add_browser_line(fd_logfile->browser,
282 _("NO OR EMPTY LOGFILE!"));
284 if (fd_logfile->logfile->visible) {
285 fl_raise_form(fd_logfile->logfile);
287 fl_show_form(fd_logfile->logfile,
288 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
289 _("Message-Window"));
294 void FaxLogfileCloseCB(FL_OBJECT *, long)
296 fl_hide_form(fd_logfile->logfile);
300 void FaxCancelCB(FL_OBJECT *, long)
302 fl_hide_form(fd_xsendfax->xsendfax);
306 void FaxApplyCB(FL_OBJECT *, long)
308 button_send(filename, global_sendcmd);
312 void FaxSendCB(FL_OBJECT *, long)
314 if (button_send(filename, global_sendcmd))
319 void FaxOpenPhonebookCB(FL_OBJECT *, long)
321 int n = fl_get_browser_maxline(fd_phonebook->browser);
324 fl_addto_browser(fd_phonebook->browser, _("@L@b@cEmpty Phonebook"));
325 fl_show_form(fd_phonebook->phonebook, FL_PLACE_MOUSE, FL_FULLBORDER,