61fd44bec6
git-svn-id: svn://10.65.10.50/branches/R_10_00@23055 c028cbd2-c16b-5b4b-a496-9718f37d4682
841 lines
21 KiB
C++
Executable File
841 lines
21 KiB
C++
Executable File
#include <about.h>
|
||
#include <applicat.h>
|
||
#include <colors.h>
|
||
#include <dongle.h>
|
||
#include <extcdecl.h>
|
||
#include <isam.h>
|
||
#include <mask.h>
|
||
#include <modaut.h>
|
||
#include <printer.h>
|
||
#include <progind.h>
|
||
#include <urldefid.h>
|
||
#include <utility.h>
|
||
|
||
// Maschera scelta ditta
|
||
#include <bagn002.h>
|
||
|
||
#include <user.h>
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Metodi di accesso globali all'applicazione corrente
|
||
///////////////////////////////////////////////////////////
|
||
|
||
HIDDEN TApplication* _application = NULL;
|
||
|
||
// @doc EXTERNAL
|
||
|
||
// @func Ritorna l'applicazione in corso
|
||
//
|
||
// @rdesc Ritorna il reference all'applicazione in corso
|
||
TApplication& main_app()
|
||
{
|
||
CHECK(_application, "NULL application!");
|
||
return *_application;
|
||
}
|
||
|
||
// @doc INTERNAL
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Gestione dello sfondo della finestra principale
|
||
///////////////////////////////////////////////////////////
|
||
|
||
HIDDEN void paint_background(WINDOW win)
|
||
{
|
||
RCT r; xvt_vobj_get_client_rect(win, &r);
|
||
|
||
if (ADVANCED_GRAPHICS)
|
||
{
|
||
const int cy = r.bottom / 4;
|
||
RCT g = r; g.bottom = cy;
|
||
xvt_dwin_draw_gradient_linear(win, &g, MASK_LIGHT_COLOR, MASK_BACK_COLOR, 90);
|
||
g = r; g.top = cy;
|
||
xvt_dwin_draw_gradient_linear(win, &g, MASK_DARK_COLOR, MASK_LIGHT_COLOR, 90);
|
||
}
|
||
else
|
||
xvt_dwin_clear(win, MASK_DARK_COLOR);
|
||
|
||
int BIGY = 3*ROWY/2;
|
||
xvtil_set_font(win, XVT_FFN_TIMES, XVT_FS_BOLD | XVT_FS_ITALIC, BIGY);
|
||
|
||
const char* t = main_app().title();
|
||
int w = xvt_dwin_get_text_width(win, t, -1);
|
||
if (w > r.right)
|
||
{
|
||
BIGY = BIGY*r.right/w;
|
||
xvtil_set_font(win, XVT_FFN_TIMES, XVT_FS_BOLD | XVT_FS_ITALIC, BIGY);
|
||
w = xvt_dwin_get_text_width(win, t, -1);
|
||
}
|
||
|
||
int x = (r.right-w)/2, y = r.top+BIGY+ROWY;
|
||
if (ADVANCED_GRAPHICS)
|
||
{ // Disegna ombra
|
||
const int k = max(BIGY/24, 1);
|
||
xvt_dwin_set_fore_color(win, MASK_LIGHT_COLOR);
|
||
xvt_dwin_draw_text(win, x+k, y+k, t, -1);
|
||
}
|
||
xvt_dwin_set_fore_color(win, MASK_DARK_COLOR);
|
||
xvt_dwin_draw_text(win, x, y, t, -1);
|
||
|
||
xvtil_set_font(win, NULL, XVT_FS_NONE);
|
||
xvt_dwin_set_fore_color(win, PROMPT_COLOR);
|
||
|
||
TString spa; spa << dongle().product();
|
||
if (!xvt_sys_is_pda())
|
||
spa << " - " << dongle().reseller();
|
||
w = xvt_dwin_get_text_width(win, spa, -1);
|
||
x = (r.right-r.left-w)/2; y = r.bottom-CHARY;
|
||
xvt_dwin_draw_text(win, x, y, spa, -1);
|
||
|
||
if (ADVANCED_GRAPHICS)
|
||
{
|
||
/*
|
||
const int ix = xvt_vobj_get_attr(win, ATTR_ICON_WIDTH);
|
||
const int iy = xvt_vobj_get_attr(win, ATTR_ICON_HEIGHT);
|
||
xvt_dwin_draw_icon(win, r.right-ix-CHARY, r.bottom-iy-CHARY, ICON_RSRC);
|
||
xvt_dwin_draw_icon(win, CHARY, r.bottom-iy-CHARY, ICON_RSRC);
|
||
*/
|
||
RCT ir;
|
||
xvt_rect_set(&ir, CHARY, r.bottom-TOOL_SIZE-CHARY, TOOL_SIZE+CHARY, r.bottom-CHARY);
|
||
xvt_dwin_draw_icon_rect(win, &ir, ICON_RSRC);
|
||
xvt_rect_set(&ir, r.right-CHARY-TOOL_SIZE, r.bottom-TOOL_SIZE-CHARY, r.right-CHARY, r.bottom-CHARY);
|
||
xvt_dwin_draw_icon_rect(win, &ir, ICON_RSRC);
|
||
}
|
||
}
|
||
|
||
long TApplication::task_eh(WINDOW win, EVENT *ep)
|
||
{
|
||
switch (ep->type)
|
||
{
|
||
case E_CREATE:
|
||
if (_application->pre_create())
|
||
{
|
||
// Setta il vero menu principale se diverso dal default
|
||
const int meno = _application->argc() > 1 ? atoi(_application->argv(1)+1) : 0;
|
||
ignore_xvt_errors(TRUE);
|
||
MENU_ITEM* menu = xvt_res_get_menu(MENU_BAR_ID(meno));
|
||
ignore_xvt_errors(FALSE);
|
||
if (menu)
|
||
{
|
||
xvt_menu_set_tree(win, menu);
|
||
xvt_res_free_menu_tree(menu);
|
||
}
|
||
if (dictionary_active())
|
||
xvt_menu_translate_tree(win, dictionary_translate_menu_item);
|
||
|
||
// Setta la caption della task window
|
||
TString cap;
|
||
cap << _application->get_module_name() << " - " << dongle().product() << " - " << dongle().reseller();
|
||
xvt_vobj_set_title(win, cap);
|
||
|
||
// Carica colori e font
|
||
customize_controls(TRUE);
|
||
|
||
xvtil_create_statbar();
|
||
xvtil_statbar_set("");
|
||
|
||
do_events(); // strateggica non scancellare
|
||
}
|
||
break;
|
||
case E_UPDATE:
|
||
paint_background(win);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return _application->handler(win, ep);
|
||
}
|
||
|
||
void TApplication::dispatch_e_menu(MENU_TAG tag)
|
||
{
|
||
EVENT e; memset(&e, 0, sizeof(e));
|
||
e.type = E_COMMAND;
|
||
e.v.cmd.tag = tag;
|
||
xvt_win_post_event(TASK_WIN, &e);
|
||
}
|
||
|
||
long TApplication::handler(WINDOW win, EVENT* ep)
|
||
{
|
||
switch (ep->type)
|
||
{
|
||
case E_CREATE:
|
||
_create_ok = create();
|
||
if (_create_ok)
|
||
{
|
||
on_firm_change();
|
||
on_config_change();
|
||
return 1;
|
||
}
|
||
else
|
||
stop_run();
|
||
break;
|
||
case E_COMMAND:
|
||
switch(ep->v.cmd.tag)
|
||
{
|
||
case M_FILE_QUIT:
|
||
if (can_close())
|
||
stop_run();
|
||
break;
|
||
case M_FILE_PG_SETUP:
|
||
printer().set();
|
||
break;
|
||
case M_FILE_PREVIEW:
|
||
preview();
|
||
break;
|
||
case M_FILE_PRINT:
|
||
print();
|
||
break;
|
||
case M_FILE_NEW:
|
||
set_firm();
|
||
break;
|
||
case M_FILE_ABOUT:
|
||
about();
|
||
break;
|
||
case M_HELP_CONTENTS:
|
||
{
|
||
TFilename n = "campo";
|
||
TString4 module; module.strncpy(name(), 2);
|
||
if (module != "ba")
|
||
n.insert(module);
|
||
|
||
FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(n, &fs);
|
||
XVT_HELP_INFO hi = xvt_help_open_helpfile(&fs, 0);
|
||
xvt_help_process_event(hi, win, ep);
|
||
}
|
||
break;
|
||
case M_HELP_ONCONTEXT: // Ridirige l'help contestuale alla finestra corrente
|
||
{
|
||
WINDOW w = cur_win();
|
||
if (w != NULL_WIN && w != win)
|
||
dispatch_e_char(w, K_F1);
|
||
}
|
||
break;
|
||
case M_EDIT_CUT:
|
||
case M_EDIT_COPY:
|
||
case M_EDIT_PASTE:
|
||
{
|
||
// I comandi della clipboard vanno ridiretti alla finestra col focus
|
||
WINDOW w = xvt_scr_get_focus_vobj();
|
||
if (w == NULL_WIN) w = cur_win();
|
||
if (w != NULL_WIN && w != win) // Evito ciclo infinito
|
||
{
|
||
dispatch_event(w, *ep, true);
|
||
break;
|
||
}
|
||
}
|
||
// fall down to normal processing
|
||
default:
|
||
if (ep->v.cmd.tag > MAX_MENU_TAG)
|
||
{
|
||
WINDOW w = cur_win();
|
||
if (w != NULL_WIN && w != win)
|
||
dispatch_event(w, *ep, true);
|
||
}
|
||
else
|
||
{
|
||
if (ep->v.cmd.tag >= BAR_ITEM_ID(1))
|
||
{
|
||
if(!menu(ep->v.cmd.tag))
|
||
stop_run();
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
case E_CLOSE:
|
||
if (can_close())
|
||
stop_run();
|
||
else
|
||
return 1; // Divieto!
|
||
break;
|
||
case E_QUIT:
|
||
if (ep->v.query)
|
||
{
|
||
if (can_close())
|
||
xvt_app_allow_quit();
|
||
}
|
||
else
|
||
stop_run();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return 0L;
|
||
}
|
||
|
||
void TApplication::stop_run()
|
||
{
|
||
if (_savefirm)
|
||
prefix().set_codditta(_savefirm);
|
||
terminate();
|
||
|
||
xvt_app_destroy();
|
||
}
|
||
|
||
|
||
bool TApplication::add_menu(TString_array& menu, MENU_TAG id)
|
||
{
|
||
TTemp_window tw(TASK_WIN);
|
||
return tw.add_menu(menu,id,TRUE);
|
||
}
|
||
|
||
bool TApplication::remove_menu(MENU_TAG id)
|
||
{
|
||
TTemp_window tw(TASK_WIN);
|
||
return tw.remove_menu(id);
|
||
}
|
||
|
||
|
||
TApplication::TApplication()
|
||
: _god_vars(NULL),_savefirm(0), _running(FALSE), _create_ok(FALSE)
|
||
{
|
||
}
|
||
|
||
|
||
TApplication::~TApplication()
|
||
{
|
||
if (_god_vars != NULL)
|
||
delete _god_vars;
|
||
}
|
||
|
||
bool TApplication::create()
|
||
{ return true; }
|
||
|
||
|
||
bool TApplication::destroy()
|
||
{ return true; }
|
||
|
||
void TApplication::terminate()
|
||
{
|
||
close_all_dialogs();
|
||
|
||
if (_create_ok)
|
||
destroy(); // Distruzione files e maschere
|
||
|
||
do_events();
|
||
|
||
if (use_files())
|
||
{
|
||
_used_files.destroy();
|
||
free_global_vars(); // Distruzione variabili globali
|
||
}
|
||
|
||
printer_destroy();
|
||
|
||
dictionary_close();
|
||
|
||
xvt_help_close_helpfile(NULL_HELP_INFO);
|
||
|
||
customize_controls(FALSE); // Rilascio eventuali DLL
|
||
}
|
||
|
||
const char* TApplication::get_module_name() const
|
||
{
|
||
TString& module = ((TApplication*)this)->_module_name; // Fool the compiler
|
||
if (module.empty())
|
||
{
|
||
const TDongle& d = dongle();
|
||
const TString4 modname = _name.left(2);
|
||
const word aut = d.module_name2code(modname);
|
||
module = d.module_code2desc(aut);
|
||
bool ok = module.full();
|
||
if (ok && aut > 0 && check_autorization())
|
||
ok = has_module(aut) && dongle().login(modname);
|
||
|
||
if (!ok)
|
||
{
|
||
if (module.empty())
|
||
module = modname;
|
||
TToken_string em(extra_modules());
|
||
if (!em.empty_items())
|
||
{
|
||
ok = em == "*";
|
||
if (!ok)
|
||
{
|
||
FOR_EACH_TOKEN(em, cod)
|
||
{
|
||
const word codice = d.module_name2code(cod);
|
||
ok = has_module(codice) && dongle().login(cod);
|
||
if (ok)
|
||
{
|
||
module = d.module_code2desc(codice);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!ok)
|
||
{
|
||
error_box(FR("Il modulo '%s' non <20> autorizzato per l'utente %s"), (const char*)module, ((const char*)user()));
|
||
module.cut(0);
|
||
}
|
||
}
|
||
}
|
||
return module;
|
||
}
|
||
|
||
void TApplication::set_title(const char* t)
|
||
{
|
||
if (_title != t)
|
||
{
|
||
_title = t;
|
||
if (is_running())
|
||
{
|
||
xvt_dwin_invalidate_rect(TASK_WIN, NULL);
|
||
xvtil_statbar_set("");
|
||
}
|
||
}
|
||
}
|
||
|
||
void TApplication::set_perms()
|
||
{
|
||
_user_aut.set(ENDAUT, true); // Forza dimensioni corrette del bit array!
|
||
_user_aut.reset(); // disabilita tutto ...
|
||
_user_aut.set(0, true); // ... tranne la BASE
|
||
|
||
const TString& utente = user();
|
||
if (utente.full() && utente.compare(::dongle().administrator(), -1, 0) != 0)
|
||
{
|
||
int err = _iskeynotfound;
|
||
if (use_files())
|
||
{
|
||
TSystemisamfile users(LF_USER);
|
||
err = users.open_ex();
|
||
if (err == NOERR)
|
||
{
|
||
users.put(USR_USERNAME, utente);
|
||
err = users.read();
|
||
if (err == NOERR)
|
||
{
|
||
const TString& aut = users.get(USR_AUTSTR);
|
||
if (aut.full())
|
||
{
|
||
for (int i = aut.len()-1; i > 0; i--)
|
||
_user_aut.set(i, aut[i] == 'X');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (err != NOERR)
|
||
{
|
||
if (utente.compare("GUEST", -1, true) != 0)
|
||
warning_box(FR("Impossibile accedere ai permessi dell'utente %s"), (const char*)utente);
|
||
_user_aut.set(); // abilita tutto
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_user_aut.set(); // abilita tutto
|
||
}
|
||
}
|
||
|
||
// @doc EXTERNAL
|
||
|
||
// @mfunc Legge il parametro /uUTENTE e lo toglie dalla lista
|
||
void TApplication::check_parameters(
|
||
int & argc, // @parm Numero del parametro da controllare
|
||
char* argv[]) // @parm Array di paramentri da passare all'applicazione
|
||
|
||
// @comm Nel caso si identifichi che il paramentro <p argc> sia il nome dell'utente
|
||
// si setta la variabile col nome dell'utente, altrimenti l'utente diventa PRASSI,
|
||
// e si diminuisce di uno il numero di argomenti da passare.
|
||
{
|
||
if (argc > 1)
|
||
{
|
||
const TFixed_string u(argv[argc-1]);
|
||
if (u.starts_with("-u", true) || u.starts_with("/u", true))
|
||
{
|
||
TString16 usr = u.mid(2,16);
|
||
usr.upper();
|
||
user() = usr;
|
||
argc--;
|
||
}
|
||
}
|
||
}
|
||
|
||
bool TApplication::test_assistance_year(bool verbose) const
|
||
{
|
||
const int dongle_year = dongle().year_assist();
|
||
int app_year, dum1, dum2, dum3;
|
||
bool ok = TApplication::get_version_info(app_year, dum1, dum2, dum3);
|
||
if (ok)
|
||
{
|
||
ok = app_year <= dongle_year;
|
||
if (ok)
|
||
{
|
||
if (check_autorization())
|
||
{
|
||
Tdninst dninst; //queste 2 righe sono quelle da mettere nei programmi
|
||
ok = dninst.can_I_run(false, verbose);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (verbose)
|
||
error_box(TR("E' necessario rinnovare l'assistenza per l'anno in corso"));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (verbose)
|
||
error_box(TR("Impossibile determinare la versione dell'applicazione"));
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
// @doc EXTERNAL
|
||
|
||
// @mfunc Fa partire l'applicazione
|
||
void TApplication::run(
|
||
int argc, // @parm Numero deglia argomenti da passara all'applicazione
|
||
char* argv[], // @parm Argomenti da passare all'applicazione
|
||
const char* title) // @parm Titolo dell'applicazione
|
||
|
||
// @comm E' in questa fase che si controlla se esiste la chiave e' attaccata
|
||
{
|
||
// Devo metterla qui per far funzionare la TDongle::network_login
|
||
_application = this;
|
||
|
||
TFilename base(argv[0]);
|
||
base.ext(""); base.lower();
|
||
|
||
_title = title;
|
||
|
||
if (user().empty())
|
||
check_parameters(argc, argv);
|
||
|
||
_argc_ = argc;
|
||
_argv_ = (const char**)argv;
|
||
|
||
if (argc > 1 && argv[1][0] == '-')
|
||
_name = cmd2name(argv[0], argv[1]);
|
||
else
|
||
_name = cmd2name(argv[0]);
|
||
|
||
const int sn = get_serial_number();
|
||
if (sn > 0 && !test_assistance_year(true))
|
||
return;
|
||
|
||
if (use_files())
|
||
init_global_vars();
|
||
else
|
||
CGetPref();
|
||
|
||
set_perms();
|
||
|
||
const char* mod = get_module_name();
|
||
if (mod == NULL || *mod == '\0')
|
||
return;
|
||
|
||
XVT_CONFIG cfg; memset(&cfg, 0, sizeof(cfg));
|
||
cfg.menu_bar_ID = TASK_MENUBAR;
|
||
cfg.about_box_ID = 0;
|
||
cfg.base_appl_name = base.name();
|
||
cfg.appl_name = title;
|
||
cfg.taskwin_title = dongle().product();
|
||
|
||
int year, major, minor, patch;
|
||
if (TApplication::get_version_info(year, major, minor, patch))
|
||
{
|
||
TString16 ver; ver.format("%d %d.%d/%d", year, major, minor, patch);
|
||
xvt_vobj_set_attr(NULL_WIN, ATTR_APPL_VERSION_STRING, (long)(const char*)ver);
|
||
}
|
||
|
||
set_xvt_hooks();
|
||
|
||
_running = TRUE;
|
||
xvt_app_create(argc, argv, 0L, task_eh, &cfg);
|
||
}
|
||
|
||
bool TApplication::get_version_info(int& year, int& release, int& tag, int& patch)
|
||
{
|
||
const char* const VERSIONANDPATCH = "Don't cry for me Argentina.2121.11.00.0000.2132";
|
||
|
||
TToken_string vep(VERSIONANDPATCH, '.');
|
||
year = vep.get_int(1);
|
||
release = vep.get_int();
|
||
tag = vep.get_int();
|
||
patch = vep.get_int();
|
||
int checksum = vep.get_int();
|
||
|
||
bool valid = year >= 2091 && release > 0 && tag >= 0 && patch >= 0 &&
|
||
checksum == (year + release + tag + patch);
|
||
return valid;
|
||
}
|
||
|
||
// Risposta alla selezione Stampa del menu File
|
||
void TApplication::print()
|
||
{
|
||
#ifdef DBG
|
||
NFCHECK("Non saprei bene cosa stampare!");
|
||
#endif
|
||
enable_menu_item(M_FILE_PREVIEW, false);
|
||
enable_menu_item(M_FILE_PRINT, false);
|
||
}
|
||
|
||
void TApplication::preview()
|
||
{
|
||
TPrinter& p = printer();
|
||
const TPrtype oldmode = p.printtype();
|
||
p.set_printtype(screenvis);
|
||
print();
|
||
p.set_printtype(oldmode);
|
||
}
|
||
|
||
void TApplication::check_menu_item(MENU_TAG item, bool chk)
|
||
{
|
||
xvt_menu_set_item_checked(TASK_WIN, item, chk);
|
||
xvt_menu_update(TASK_WIN);
|
||
}
|
||
|
||
void TApplication::uncheck_menu_item(MENU_TAG item)
|
||
{
|
||
check_menu_item(item, false);
|
||
}
|
||
|
||
// @doc EXTERNAL
|
||
|
||
// @mfunc Permette di abilitare/disabilitare una voce di menu'
|
||
void TApplication::enable_menu_item(
|
||
MENU_TAG item, // @parm Voce del menu da abilitare/disabilitare
|
||
bool on) // @parm Operazione da svolgere sulla voce del menu
|
||
//
|
||
// @flag TRUE | Viene abilitata la voce del menu
|
||
// @flag FALSE| Viene disabilitata la voce del menu
|
||
{
|
||
xvt_menu_set_item_enabled(TASK_WIN, item, on);
|
||
xvt_menu_update(TASK_WIN);
|
||
}
|
||
|
||
bool TApplication::has_module(int module, int checktype) const
|
||
{
|
||
bool ok = dongle().active(module);
|
||
// Testa bit di attivazione dell'utente
|
||
if (ok && checktype != CHK_DONGLE)
|
||
ok = _user_aut[module];
|
||
return ok;
|
||
}
|
||
|
||
long TApplication::get_firm() const
|
||
{
|
||
if (!prefix_valid())
|
||
return ini_get_int(CONFIG_INSTALL, "Main", "Firm");
|
||
return prefix().get_codditta();
|
||
}
|
||
|
||
const char* TApplication::get_firm_dir() const
|
||
{
|
||
return format("%s%s", __ptprf, prefix().name());
|
||
}
|
||
|
||
bool TApplication::set_firm(long newfirm)
|
||
{
|
||
const long oldfirm = get_firm();
|
||
const bool interactive = newfirm <= 0;
|
||
|
||
if (interactive && firm_change_enabled())
|
||
{
|
||
TMask mask("bagn002");
|
||
TFilename pp(__ptprf); pp.cut(pp.len()-1);
|
||
mask.set(F_PATHPREF, pp);
|
||
|
||
mask.show(-2, extended_firm());
|
||
|
||
disable_menu_item(M_FILE_NEW);
|
||
const KEY k = mask.run();
|
||
enable_menu_item(M_FILE_NEW);
|
||
|
||
if (k == K_ENTER)
|
||
{
|
||
newfirm = mask.get_long(F_CODDITTA);
|
||
const int tipodir = mask.get_int(F_TIPO);
|
||
|
||
if (tipodir == 0 && !prefix().exist(newfirm) &&
|
||
!prefix().build_firm_data(newfirm))
|
||
return false;
|
||
if (tipodir > 0)
|
||
{
|
||
if (_savefirm == 0) _savefirm = oldfirm; // E' necessario ricordare la ditta ...
|
||
prefix().set(tipodir == 1 ? "com" : ""); // ... se si setta il prefix a com
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (interactive)
|
||
{
|
||
if (newfirm <= 0)
|
||
return false;
|
||
}
|
||
|
||
bool done = newfirm > 0 && prefix().set_codditta(newfirm);
|
||
if (done)
|
||
{
|
||
_savefirm = 0;
|
||
|
||
WINDOW w = cur_win();
|
||
if (w != NULL_WIN)
|
||
{
|
||
TWindow* win = (TWindow*) xvt_vobj_get_data(w);
|
||
win->on_firm_change();
|
||
}
|
||
xvtil_statbar_set("", true); // Aggiorna nome ditta nella barra
|
||
on_firm_change();
|
||
on_config_change();
|
||
}
|
||
|
||
return done;
|
||
}
|
||
|
||
// @doc EXTERNAL
|
||
|
||
// @mfunc Controlla se al programma corrente e' concesso cambiare ditta da menu.
|
||
//
|
||
// @rdesc Ritorna i seguenti valori:
|
||
//
|
||
// @flag TRUE | Se e' abilitata la voce di menu' per il cambio della ditta
|
||
// @flag FALSE | Se non e' possibile cambiare ditta da menu'
|
||
bool TApplication::firm_change_enabled() const
|
||
|
||
// @comm Praticamente controlla se e' stato lanciato da ba0 o dal program manager
|
||
{
|
||
return !dongle().demo();
|
||
}
|
||
|
||
void TApplication::on_firm_change()
|
||
{}
|
||
|
||
void TApplication::on_config_change()
|
||
{}
|
||
|
||
void TApplication::open_files(int logicnum, ...)
|
||
{
|
||
va_list marker;
|
||
va_start(marker, logicnum);
|
||
while (logicnum >= LF_USER && logicnum < LF_EXTERNAL)
|
||
{
|
||
if (_used_files.objptr(logicnum) == NULL)
|
||
_used_files.add(new TLocalisamfile(logicnum), logicnum);
|
||
logicnum = va_arg(marker, int);
|
||
}
|
||
va_end(marker);
|
||
}
|
||
|
||
bool TApplication::get_spotlite_path(TFilename& path) const
|
||
{
|
||
bool ok = dongle().active(RSAUT);
|
||
if (ok)
|
||
{
|
||
if (prefix_valid())
|
||
path = prefix().get_studio(); // Legge il persorso dello studio corrente
|
||
else
|
||
path = ini_get_string(CONFIG_INSTALL, "Main", "Study");
|
||
const TString80 study = path.name(); // Estrae il nome dello studio (senza percorso)
|
||
path.add("spotlite"); // Crea il nome standard della cartella per gli archivi
|
||
ok = path.exist(); // Controlla se esiste gia'
|
||
if (!ok)
|
||
{
|
||
make_dir("servers"); // Assicuiramoci che esista la cartella servers
|
||
TConfig ini("servers/servers.ini", "Spotlite");
|
||
for (int i = 0; ; i++)
|
||
{
|
||
const TString& s = ini.get("Study", NULL, i);
|
||
if (s.blank()) // NON e' mai stato configurato
|
||
{
|
||
ini.set("Study", study, NULL, TRUE, i);
|
||
ini.set("Data", path, NULL, TRUE, i);
|
||
ok = make_dir(path);
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
if (s.compare(study, -1, true) == 0) // E' gia' configurato
|
||
{
|
||
path = ini.get("Data", NULL, i);
|
||
ok = path.exist();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TApplication::get_next_pdf(int anno, long ditta, const char* codnum,
|
||
long numdoc, long codcf, TFilename& pdf) const
|
||
{
|
||
bool ok = get_spotlite_path(pdf);
|
||
if (ok)
|
||
{
|
||
if (anno <= 0)
|
||
{
|
||
const TDate oggi(TODAY);
|
||
anno = oggi.year();
|
||
}
|
||
pdf.add(format("%04d", anno));
|
||
if (!pdf.exist())
|
||
ok = xvt_fsys_mkdir(pdf) != 0;
|
||
}
|
||
if (ok)
|
||
{
|
||
if (ditta < 0)
|
||
ditta = get_firm();
|
||
pdf.add(format("%05ldA", ditta));
|
||
if (!pdf.exist())
|
||
ok = xvt_fsys_mkdir(pdf) != 0;
|
||
|
||
if (ok)
|
||
{
|
||
pdf.add(_name);
|
||
if (codnum == NULL || *codnum <= ' ')
|
||
codnum = "report";
|
||
pdf << '_' << codnum;
|
||
|
||
if (numdoc <= 0)
|
||
{
|
||
const struct tm& loc = *xvt_time_now();
|
||
pdf << format("_%02d%02d%02d%02d%02d",
|
||
loc.tm_mon, loc.tm_mday, loc.tm_hour, loc.tm_min, loc.tm_sec);
|
||
}
|
||
else
|
||
pdf << format("_%010ld", numdoc);
|
||
|
||
if (codcf > 0)
|
||
pdf << format("_%07ld", codcf);
|
||
|
||
pdf.ext("pdf");
|
||
}
|
||
}
|
||
|
||
return ok;
|
||
}
|
||
|
||
bool TApplication::get_next_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn,
|
||
TString& subj, TString& text, TToken_string& attach, short& ui) const
|
||
{
|
||
const bool ok = dongle().active(RSAUT);
|
||
ui = ok && to.blank() ? 0x1 : 0x0; // Forza finestra di dialogo in assenza di destinatario
|
||
return ok;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// The Skeleton application!
|
||
///////////////////////////////////////////////////////////
|
||
|
||
bool TSkeleton_application::create()
|
||
{
|
||
// dispatch_e_menu(BAR_ITEM_ID(1));
|
||
// return TApplication::create();
|
||
const bool ok = TApplication::create();
|
||
if (ok) dispatch_e_menu(BAR_ITEM_ID(1));
|
||
return ok;
|
||
}
|
||
|
||
bool TSkeleton_application::menu(MENU_TAG tag)
|
||
{
|
||
if (tag == BAR_ITEM_ID(1))
|
||
main_loop();
|
||
return false;
|
||
} |