1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cstdlib>
|
1999-09-27 18:44:28 +00:00
|
|
|
#include FORMS_H_LOCATION
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_sendfax.h"
|
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "lyxrc.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/syscall.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* Prototypes */
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
bool sendfax(string const & fname, string const & sendcmd);
|
|
|
|
bool button_send(string const & fname, string const & sendcmd = string());
|
|
|
|
|
|
|
|
static
|
|
|
|
void show_logfile(string const & logfile, bool show_if_empty);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
const int LEN_PHONE = 20;
|
|
|
|
const int LEN_NAME = 25;
|
|
|
|
|
|
|
|
/* Global Variables */
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string phone_book;
|
|
|
|
string global_sendcmd;
|
|
|
|
string filename;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
FD_xsendfax * fd_xsendfax;
|
|
|
|
FD_phonebook * fd_phonebook;
|
|
|
|
FD_logfile * fd_logfile;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
bool send_fax(string const & fname, string const & sendcmd)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// I put FAXCMD here to see if I can get rid of some strange errors. (Lgb)
|
1999-10-02 16:21:10 +00:00
|
|
|
string FAXCMD = "sendfax -n -h '$$Host' -c '$$Comment' -x '$$Enterprise' -d '$$Name'@'$$Phone' '$$FName'";
|
|
|
|
string title = _("Fax File: ");
|
|
|
|
string path;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (fname.empty())
|
|
|
|
return false;
|
2000-08-03 21:17:52 +00:00
|
|
|
path = OnlyPath(fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (path.empty() || path == "./")
|
|
|
|
filename = GetCWD() + "/" + fname;
|
|
|
|
else
|
|
|
|
filename = fname;
|
|
|
|
|
|
|
|
if (sendcmd.empty())
|
|
|
|
global_sendcmd = FAXCMD;
|
|
|
|
else
|
|
|
|
global_sendcmd = sendcmd;
|
|
|
|
|
|
|
|
fd_xsendfax = create_form_xsendfax();
|
|
|
|
fd_phonebook = create_form_phonebook();
|
|
|
|
fd_logfile = create_form_logfile();
|
|
|
|
|
|
|
|
// Make sure the close box doesn't kill LyX when being pressed. (RvdK)
|
1999-10-02 16:21:10 +00:00
|
|
|
fl_set_form_atclose(fd_xsendfax->xsendfax, CancelCloseBoxCB, 0);
|
|
|
|
fl_set_form_atclose(fd_phonebook->phonebook, CancelCloseBoxCB, 0);
|
|
|
|
fl_set_form_atclose(fd_logfile->logfile, CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/* init Phone-Book */
|
1999-10-02 16:21:10 +00:00
|
|
|
string phone_book_name;
|
2000-03-12 10:35:05 +00:00
|
|
|
if (lyxrc.phone_book.empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
phone_book_name = "phonebook";
|
|
|
|
} else
|
2000-03-12 10:35:05 +00:00
|
|
|
phone_book_name = lyxrc.phone_book;
|
1999-11-15 12:01:38 +00:00
|
|
|
phone_book= FileSearch(user_lyxdir, phone_book_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (phone_book.empty())
|
1999-11-15 12:01:38 +00:00
|
|
|
phone_book = AddName(user_lyxdir, phone_book_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
fl_set_browser_fontsize(fd_phonebook->browser, FL_NORMAL_SIZE);
|
|
|
|
fl_set_browser_fontstyle(fd_phonebook->browser, FL_FIXED_STYLE);
|
|
|
|
fl_load_browser(fd_phonebook->browser, phone_book.c_str());
|
|
|
|
|
|
|
|
title += OnlyFilename(fname);
|
|
|
|
|
|
|
|
/* show the first form */
|
2000-08-03 21:17:52 +00:00
|
|
|
fl_show_form(fd_xsendfax->xsendfax,
|
|
|
|
FL_PLACE_MOUSE, FL_FULLBORDER, title.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
while(true) {
|
|
|
|
obj = fl_do_forms();
|
1999-11-15 12:01:38 +00:00
|
|
|
if (obj == fd_xsendfax->Button_Cancel)
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-11-15 12:01:38 +00:00
|
|
|
else if (obj == fd_xsendfax->Button_Send) {
|
|
|
|
if (button_send(fname, global_sendcmd))
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-11-15 12:01:38 +00:00
|
|
|
} else if (obj == fd_xsendfax->Button_Apply) {
|
|
|
|
button_send(fname, global_sendcmd);
|
|
|
|
} else if (obj == fd_xsendfax->Button_SPhone) {
|
|
|
|
cb_select_phoneno(0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fl_hide_form(fd_xsendfax->xsendfax);
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
bool button_send(string const & fname, string const & sendcmd)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
string name = fl_get_input(fd_xsendfax->Input_Name);
|
|
|
|
string phone = fl_get_input(fd_xsendfax->Input_Phone);
|
|
|
|
string enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
|
|
|
|
string comment = fl_get_input(fd_xsendfax->Input_Comment);
|
|
|
|
string host = GetEnv("FAX_SERVER");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (phone.empty())
|
|
|
|
return false;
|
2000-08-03 21:17:52 +00:00
|
|
|
string logfile = TmpFileName(OnlyPath(fname), "FAX");
|
|
|
|
string cmd = sendcmd + " >";
|
1999-09-27 18:44:28 +00:00
|
|
|
cmd += logfile + " 2>";
|
|
|
|
cmd += logfile;
|
1999-10-26 23:33:30 +00:00
|
|
|
cmd = subst(cmd, "$$Host", host);
|
|
|
|
cmd = subst(cmd, "$$Comment", comment);
|
|
|
|
cmd = subst(cmd, "$$Enterprise", enterprise);
|
|
|
|
cmd = subst(cmd, "$$Name", name);
|
|
|
|
cmd = subst(cmd, "$$Phone", phone);
|
|
|
|
cmd = subst(cmd, "$$FName", fname);
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "CMD: " << cmd << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
Systemcalls one(Systemcalls::System, cmd);
|
1999-11-15 12:01:38 +00:00
|
|
|
show_logfile(logfile, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
remove(logfile.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
void cb_hide_form(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
fl_hide_form(ob->form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cb_select_phoneno(FL_OBJECT *, long)
|
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
int n = fl_get_browser_maxline(fd_phonebook->browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
fl_hide_form(fd_phonebook->phonebook);
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (!n || strstr(line, _("Empty Phonebook"))) {
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_clear_browser(fd_phonebook->browser);
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 21:17:52 +00:00
|
|
|
int i = fl_get_browser(fd_phonebook->browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
line = fl_get_browser_line(fd_phonebook->browser, i);
|
|
|
|
if (!line)
|
|
|
|
return;
|
2000-08-03 21:17:52 +00:00
|
|
|
char * buf = new char [strlen(line)+1];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
strcpy(buf, line);
|
2000-01-24 18:34:46 +00:00
|
|
|
for(i = LEN_PHONE; (i > 0) && (buf[i] == ' '); --i)
|
1999-09-27 18:44:28 +00:00
|
|
|
;
|
2000-01-24 18:34:46 +00:00
|
|
|
buf[i + 1] = 0;
|
|
|
|
for(i = LEN_PHONE + LEN_NAME + 1; (i > LEN_PHONE) && (buf[i] == ' '); --i)
|
1999-09-27 18:44:28 +00:00
|
|
|
;
|
2000-01-24 18:34:46 +00:00
|
|
|
buf[i + 1] = 0;
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_set_input(fd_xsendfax->Input_Phone, buf);
|
|
|
|
fl_set_input(fd_xsendfax->Input_Name, buf+LEN_PHONE+1);
|
|
|
|
fl_set_input(fd_xsendfax->Input_Enterprise, buf+LEN_PHONE+LEN_NAME+2);
|
1999-09-27 18:44:28 +00:00
|
|
|
delete [] buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cb_add_phoneno(FL_OBJECT *, long )
|
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * phone = fl_get_input(fd_xsendfax->Input_Phone);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!strlen(phone))
|
|
|
|
return;
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * name = fl_get_input(fd_xsendfax->Input_Name);
|
|
|
|
char const * enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
|
|
|
|
|
2000-01-24 18:34:46 +00:00
|
|
|
char * buf = new char [50 + strlen(enterprise)];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
sprintf(buf, "%-*.*s %-*.*s %s",
|
|
|
|
LEN_PHONE, LEN_PHONE, phone,
|
|
|
|
LEN_NAME, LEN_NAME, name,
|
1999-09-27 18:44:28 +00:00
|
|
|
enterprise);
|
2000-08-03 21:17:52 +00:00
|
|
|
int n = fl_get_browser_maxline(fd_phonebook->browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (n) {
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (strstr(line, _("Empty Phonebook"))) {
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_clear_browser(fd_phonebook->browser);
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 21:17:52 +00:00
|
|
|
int i = 1;
|
|
|
|
for(; i <= n; ++i) {
|
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, i);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (!strncmp(buf, line, 46))
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i > n) {
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_addto_browser(fd_phonebook->browser, buf);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
|
|
|
|
}
|
|
|
|
delete[] buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cb_delete_phoneno(FL_OBJECT *, long )
|
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * phone = fl_get_input(fd_xsendfax->Input_Phone);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!strlen(phone))
|
|
|
|
return;
|
2000-08-03 21:17:52 +00:00
|
|
|
|
|
|
|
char const * name = fl_get_input(fd_xsendfax->Input_Name);
|
|
|
|
char const * enterprise = fl_get_input(fd_xsendfax->Input_Enterprise);
|
|
|
|
|
|
|
|
char * buf = new char [50+strlen(enterprise)];
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
sprintf(buf, "%-*.*s %-*.*s %s",
|
|
|
|
LEN_PHONE, LEN_PHONE, phone,
|
|
|
|
LEN_NAME, LEN_NAME, name,
|
1999-09-27 18:44:28 +00:00
|
|
|
enterprise);
|
2000-08-03 21:17:52 +00:00
|
|
|
int n = fl_get_browser_maxline(fd_phonebook->browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (n) {
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (strstr(line, _("Empty Phonebook"))) {
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_clear_browser(fd_phonebook->browser);
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 21:17:52 +00:00
|
|
|
int i = 1;
|
|
|
|
for(; i <= n; ++i) {
|
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, i);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (!strncmp(buf, line, 46))
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i <= n) {
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_delete_browser_line(fd_phonebook->browser, i);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_label(fd_xsendfax->pb_save, _("Save (needed)"));
|
|
|
|
}
|
|
|
|
delete[] buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cb_save_phoneno(FL_OBJECT *, long )
|
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
FILE * fp = fopen(phone_book.c_str(), "w");
|
|
|
|
if (!fp) {
|
1999-11-15 12:01:38 +00:00
|
|
|
WriteAlert(_("Error!"), _("Cannot open phone book: "), phone_book);
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-08-03 21:17:52 +00:00
|
|
|
int n = fl_get_browser_maxline(fd_phonebook->browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (n) {
|
2000-08-03 21:17:52 +00:00
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, 1);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (strstr(line, _("Empty Phonebook"))) {
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_clear_browser(fd_phonebook->browser);
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-08-03 21:17:52 +00:00
|
|
|
int i = 1;
|
|
|
|
for(; i <= n; ++i) {
|
|
|
|
char const * line = fl_get_browser_line(fd_phonebook->browser, i);
|
1999-11-15 12:01:38 +00:00
|
|
|
fprintf(fp, "%s\n", line);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
fl_set_object_label(fd_xsendfax->pb_save, _("Save"));
|
|
|
|
fl_redraw_form(fd_xsendfax->xsendfax);
|
|
|
|
}
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
void show_logfile(string const & logfile, bool show_if_empty)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (logfile.empty())
|
|
|
|
return;
|
1999-11-15 12:01:38 +00:00
|
|
|
if (!fl_load_browser(fd_logfile->browser, logfile.c_str())) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!show_if_empty)
|
|
|
|
return;
|
|
|
|
fl_add_browser_line(fd_logfile->browser,
|
|
|
|
_("NO OR EMPTY LOGFILE!"));
|
|
|
|
}
|
|
|
|
if (fd_logfile->logfile->visible) {
|
|
|
|
fl_raise_form(fd_logfile->logfile);
|
|
|
|
} else {
|
|
|
|
fl_show_form(fd_logfile->logfile,
|
1999-11-15 12:01:38 +00:00
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Message-Window"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void FaxLogfileCloseCB(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
fl_hide_form(fd_logfile->logfile);
|
|
|
|
}
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void FaxCancelCB(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
fl_hide_form(fd_xsendfax->xsendfax);
|
|
|
|
}
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void FaxApplyCB(FL_OBJECT *, long)
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
button_send(filename, global_sendcmd);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void FaxSendCB(FL_OBJECT *, long)
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
if (button_send(filename, global_sendcmd))
|
|
|
|
FaxCancelCB(0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void FaxOpenPhonebookCB(FL_OBJECT *, long)
|
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
int n = fl_get_browser_maxline(fd_phonebook->browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!n)
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_addto_browser(fd_phonebook->browser, _("@L@b@cEmpty Phonebook"));
|
|
|
|
fl_show_form(fd_phonebook->phonebook, FL_PLACE_MOUSE, FL_FULLBORDER,
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Phonebook"));
|
|
|
|
}
|