#include #include #include #include #include #include #include #include #include #include #include #include // Maschera scelta ditta #include #include /////////////////////////////////////////////////////////// // Finestra informazioni /////////////////////////////////////////////////////////// class TInfo_mask : public TArray_sheet { protected: virtual bool get_cell_colors(int row, int col, COLOR& fore, COLOR& back) const; public: void add_row(const char* prompt, const char* value, int err = 0); void add_row(const char* prompt, unsigned long value, int err = 0); TInfo_mask(); }; bool TInfo_mask::get_cell_colors(int r, int c, COLOR& fore, COLOR& back) const { const int err = ((TArray_sheet*)this)->row(r).get_int(2); if (err > 0) { fore = NORMAL_COLOR; back = err == 1 ? REQUIRED_BACK_COLOR : FOCUS_BACK_COLOR; } return TArray_sheet::get_cell_colors(r, c, fore, back); } void TInfo_mask::add_row(const char* prompt, const char* value, int err) { TToken_string* r = new TToken_string; r->add(prompt); r->add(value); r->add(err); add(r); } void TInfo_mask::add_row(const char* prompt, unsigned long value, int err) { TString16 str; str.format("%lu", value); add_row(prompt, str); } TInfo_mask::TInfo_mask() : TArray_sheet(-1, -1, 78, 18, "Informazioni", "@16|@60") { const word ser_no = dongle().number(); int year = 2008, release = 10, tag = 0, patch = 1; TString80 versione = "2008.10.00 Patch 0001"; if (main_app().get_version_info(year, release, tag, patch)) versione.format("%d.%02d.%02d Patch %04d", year, release, tag, patch); TString80 stros, strwx; xvt_sys_get_version(stros.get_buffer(), strwx.get_buffer(), stros.size()); TString arg; for (int a = 0; a < main_app().argc(); a++) arg << main_app().argv(a) << ' '; arg.trim(); arg.lower(); TConfig campoini(CONFIG_INSTALL, "Main"); TConfig userini(CONFIG_GUI, "Printer"); TString prot; const TDongleHardware dhw = dongle().hardware(); switch (dhw) { case _dongle_hardlock: prot = "Hardlock"; break; case _dongle_eutron : prot = "Eutron"; break; case _dongle_network : prot = campoini.get("Dongle", "Server"); break; default : prot = TR("Nessuna"); break; } const int type = campoini.get_int("Type"); const char* tipo = NULL; switch (type) { case 1: tipo = TR("Postazione singola"); break; case 2: tipo = TR("Server"); break; case 3: tipo = TR("Client"); break; default: if (campoini.get_bool("TestDatabase")) { if (dhw == _dongle_network) tipo = TR("Server"); else tipo = TR("Server o Postazione singola"); } else tipo = TR("Client"); break; } TFilename temp; temp.tempdir(); TString strdb; DB_version(strdb.get_buffer(), strdb.size()); add_row(TR("Versione"), versione); add_row(TR("Protezione"), prot); add_row(TR("N. di serie"), ser_no, ser_no < 0); add_row(TR("Assistenza"), dongle().year_assist()); add_row(TR("Installazione"), tipo); add_row(TR("Sistema"), stros); add_row(TR("Libreria GUI"), strwx); add_row(TR("Libreria DB"), strdb); add_row(TR("Utente"), user()); add_row(TR("Studio"), firm2dir(-1)); add_row(TR("Ditta"), campoini.get("Firm", "Main")); if (prefix_valid()) { const TFirm& f = prefix().firm(); add_row(TR("Ragione Sociale"), f.ragione_sociale()); add_row(TR("Valuta"), f.codice_valuta()); } add_row(TR("Programma"), arg); add_row(TR("Config locale"), campoini.name(), campoini.name().find(' ') >= 0); add_row(TR("Config utente"), userini.name(), userini.name().find(' ') >= 0); add_row(TR("File temporanei"), temp, temp.find(' ') >= 0); const long mbfree = xvt_fsys_get_disk_free_space(firm2dir(-1), 'M'); add_row(TR("Spazio su disco"), mbfree, mbfree < 512); TString printer(userini.get("Name", "Printer")); if (printer.blank()) printer = "Nessuna"; add_row(TR("Stampante"), printer, printer.len() < 32); } /////////////////////////////////////////////////////////// // 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); const 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); 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, NORMAL_COLOR); const TString 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(NULL_WIN, ATTR_ICON_WIDTH); const int iy = xvt_vobj_get_attr(NULL_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); } } long TApplication::task_eh(WINDOW win, EVENT *ep) { switch (ep->type) { case E_CREATE: if (_application->pre_create()) { #ifdef _DEMO_ { const TString16 dname(encode("DATA")); const TString16 hname(encode("ORA")); TConfig c(CONFIG_INSTALL, "Main"); TDate data(decode(c.get(dname))); TDate oggi(TODAY); real remaining_time(decode(c.get(hname))); main_app()._start_time = time(NULL); if (data < oggi) { data = oggi; c.set(dname, encode(data)); c.set(hname, encode("120.00")); } else if (data == oggi) { if (remaining_time <= ZERO) exit(0); } else exit(0); } #endif // 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(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().reseller(); TTemp_window tw(win); tw.set_caption(cap); // Carica colori e font customize_controls(TRUE); xvtil_create_statbar(); xvtil_statbar_set(""); do_events(); // strateggicca 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_PRINT: print(); break; case M_FILE_NEW: set_firm(); break; case M_FILE_ABOUT: about(); break; case M_HELP_CONTENTS: case M_HELP_SEARCH: case M_HELP_HELPONHELP: { TFilename n = "campo"; TString16 module = name(); module.cut(2); if (module != "ba") n.insert(module); FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC)); strcpy(fs.name, n); XVT_HELP_INFO hi = xvt_help_open_helpfile(&fs, 0); xvt_help_process_event(hi, win, ep); } break; 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(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); #ifdef _DEMO_ { const TString16 hname(encode("ORA")); TConfig c(CONFIG_INSTALL, "Main"); real remaining_time(decode(c.get(hname))); if (name() != "ba0100") { time_t wt = time(NULL); int delay = (int) (wt - _start_time); if (delay < 0) remaining_time = ZERO; else remaining_time -= (delay / 60.0); c.set(hname, encode(remaining_time.string())); } else message_box(TR("Questo e' un programma dimostrativo.\nOggi rimangono %s minuti di utilizzo."), remaining_time.string(3, 0)); } #endif 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 word aut = dongle().module_name2code(_name.left(2)); module = dongle().module_code2desc(aut); bool ok = module.full(); if (ok && check_autorization()) ok = has_module(aut); if (!ok) { if (module.empty()) module = "Tools"; TToken_string em(extra_modules()); if (!em.empty_items()) { if (em != "*") { FOR_EACH_TOKEN(em, cod) { if (has_module(atoi(cod))) { ok = TRUE; break; } } } else ok = TRUE; } if (!ok) { error_box(TR("Il modulo '%s' non e' autorizzato per l'utente %s"), (const char*)module, ((const char*)user())); module.cut(0); } } } return module; } void TApplication::set_perms() { _user_aut.reset(); // disabilita tutto ... _user_aut.set(0, true); // ... tranne la BASE const TString& utente = user(); if (utente.full()) { if (utente == ::dongle().administrator()) { _user_aut.set(ENDAUT, true); _user_aut.set(); // abilita tutto } else { int err = _iskeynotfound; if (use_files()) { TLocalisamfile users(LF_USER); users.put(USR_USERNAME, utente); err = users.read(); if (err == NOERR) { const TString& aut = users.get(USR_AUTSTR); if (aut.blank()) { _user_aut.reset(); // disabilita tutto ... _user_aut.set(0, true); // ... tranne la BASE } else { for (int i = aut.len()-1; i > 0; i--) _user_aut.set(i, aut[i] == 'X'); } } } if (err != NOERR && utente == "GUEST") { _user_aut.set(ENDAUT, true); _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

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)) { TString80 usr = u.mid(2); usr.upper(); user() = usr; argc--; } } } bool TApplication::test_assistance_year() const { #ifndef _DEMO_ 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; return ok; #else return TRUE; #endif // _DEMO_ } // @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 { CHECK(_application == NULL, "Sorry, multitasking not implemented"); // 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]); if (use_files()) init_global_vars(); else CGetPref(); const int sn = get_serial_number(); if (sn > 0 && !test_assistance_year()) { error_box(TR("E' necessario attivare il contratto di assistenza per l'anno in corso")); return; } set_perms(); const char* mod = get_module_name(); if (mod == NULL || *mod == '\0') return; XVT_CONFIG 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 = "CAMPO"; 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.2008.10.00.0000.2018"; 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 >= 2008 && release > 0 && tag >= 0 && patch >= 0 && checksum == (year + release + tag + patch); return valid; } // About box: risposta alla opzione Informazioni del menu File void TApplication::about() const { TInfo_mask info; info.run(); } // Risposta alla selezione Stampa del menu File void TApplication::print() { #ifdef DBG NFCHECK("Non saprei bene cosa stampare!"); #endif } 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 { #ifdef _DEMO_ bool ok = true; #else bool ok = dongle().active(module); #endif // Testa bit di attivazione dell'utente if (ok && checktype != CHK_DONGLE && module != EEAUT) ok = _user_aut[module]; return ok; } long TApplication::get_firm() const { 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; #ifndef _DEMO_ if (interactive) { 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; } } } #endif if (interactive) { if (newfirm <= 0) return newfirm > 0; } else { if (newfirm == oldfirm || newfirm <= 0) return newfirm > 0; } if (prefix().test(newfirm)) { prefix().set_codditta(newfirm); _savefirm = 0; WINDOW w = cur_win(); if (w != NULL_WIN) { TWindow * win = (TWindow *) xvt_vobj_get_data(w); win->on_firm_change(); } on_firm_change(); on_config_change(); } return TRUE; } // @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 { #ifdef _DEMO_ return false; #else return true; #endif } 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); } } bool TApplication::get_spotlite_path(TFilename& path) const { bool ok = dongle().active(RSAUT); if (ok) { path = prefix().get_studio(); // Legge il persorso dello studio corrente const TString16 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) { 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, bool& ui) const { bool ok = dongle().active(RSAUT) && dongle().active(EEAUT); ui = ok && to.blank(); return ok; } /////////////////////////////////////////////////////////// // The Skeleton application! /////////////////////////////////////////////////////////// bool TSkeleton_application::create() { dispatch_e_menu(BAR_ITEM(1)); return TApplication::create(); } bool TSkeleton_application::menu(MENU_TAG tag) { if (tag == BAR_ITEM(1)) main_loop(); return FALSE; }