Files correlati : f90.exe Commento : - F9 ARCHIVIAZIONE SOSTITUTIVA: - Aggiunto caricamento file per movimenti cartacei
218 lines
6.1 KiB
C++
218 lines
6.1 KiB
C++
#include "f90.h"
|
|
#include "applicat.h"
|
|
#include "automask.h"
|
|
#include "f90300a.h"
|
|
#include "urldefid.h"
|
|
#include "utility.h"
|
|
#include <vector>
|
|
#include <set>
|
|
|
|
#define INI_ESTENSIONI "DOCUMENTI_EXT"
|
|
|
|
#define F_ADDRGROUP 101
|
|
#define F_ADDRESS 102
|
|
#define F_DIRECTORY 103
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TGestione_doc_cartacei_f9_msk
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
#define TAutomask TMask
|
|
|
|
class TImport_msk : public TAutomask
|
|
{
|
|
friend class TGestione_doc_cartacei_f9_msk;
|
|
|
|
static bool addr_handler(TMask_field& field, KEY key);
|
|
static bool dir_handler(TMask_field& field, KEY key);
|
|
static bool ok_handler(TMask_field& field, KEY key);
|
|
|
|
#ifndef TAutomask
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
|
#endif
|
|
public:
|
|
TImport_msk();
|
|
};
|
|
|
|
bool TImport_msk::addr_handler(TMask_field& field, KEY key)
|
|
{
|
|
if (field.dirty() && key != K_TAB)
|
|
field.set("");
|
|
return true;
|
|
}
|
|
|
|
bool TImport_msk::dir_handler(TMask_field& field, KEY key)
|
|
{
|
|
if(field.dirty() && key != K_TAB)
|
|
field.set("");
|
|
return true;
|
|
}
|
|
|
|
bool TImport_msk::ok_handler(TMask_field& field, KEY key)
|
|
{
|
|
field.mask().send_key(K_ENTER, DLG_OK);
|
|
return true;
|
|
}
|
|
|
|
TImport_msk::TImport_msk() : TAutomask("Apri...", 0, 78, 10)
|
|
{
|
|
add_button_tool(DLG_OK, "Conferma", TOOL_OK);
|
|
add_button_tool(DLG_NULL, "", 0);
|
|
add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT);
|
|
|
|
add_groupbox(F_ADDRGROUP, 0, "", 1, 0, 76, 6, "");
|
|
add_static( DLG_NULL, 0, "@BInserire percorso file.", 2, 1);
|
|
add_string( F_ADDRESS, 0, "Apri: ", 2, 2, 255, "B", 64).set_selector('F', EMPTY_STRING);
|
|
add_static( DLG_NULL, 0, "@BOppure, inserire percorso cartella per inserimento multiplo.", 2, 3);
|
|
add_string( F_DIRECTORY, 0, "Apri da:", 2, 4, 255, "B", 64).set_selector('D', EMPTY_STRING);
|
|
|
|
TMask::set_handler(F_ADDRESS, addr_handler);
|
|
TMask::set_handler(F_DIRECTORY, dir_handler);
|
|
}
|
|
|
|
#undef TAutomask
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TGestione_doc_cartacei_f9_msk
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class TGestione_doc_cartacei_f9_msk : public TAutomask
|
|
{
|
|
std::unique_ptr<TImport_msk> _import_msk;
|
|
std::unique_ptr<std::set<std::string>> _extensions;
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
|
|
|
void fill(); /* todo */
|
|
static TToken_string& get_valid_extensions(); /* */
|
|
void load_dir(const TString& dir); /* Carica i file della cartella specificata, controllandone l'estensione. */
|
|
void load_extensions(); /* Lazy initialization for _extensions. */
|
|
void load_file(const TFilename& file); /* Carica singolo file. */
|
|
void open_import_win(); /* Esegue la maschera di importazione files (Lazy initilization). */
|
|
bool verify_extension(const TFilename& file); /* Verifica che l'estensione del file sia valida. */
|
|
|
|
public:
|
|
TGestione_doc_cartacei_f9_msk() : TAutomask("f90300a") { }
|
|
};
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
if(e == se_query_add || e == se_query_del || e == se_query_modify)
|
|
return false;
|
|
|
|
if (o.dlg() == B_IMPORT && e == fe_button)
|
|
open_import_win();
|
|
|
|
return true;
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::fill()
|
|
{
|
|
// todo
|
|
}
|
|
|
|
TToken_string& TGestione_doc_cartacei_f9_msk::get_valid_extensions()
|
|
{
|
|
static TToken_string ext(ini_get_string(CONFIG_DITTA, "F9", "DOCUMENTI_EXT"), ',');
|
|
if (ext.items() == 0)
|
|
{
|
|
ext = ".pdf, .doc, .docx, .xls, .xlsx, .jpg, .jpeg, .png";
|
|
ini_set_string(CONFIG_DITTA, "F9", INI_ESTENSIONI, ext);
|
|
}
|
|
ext.replace(" ", "");
|
|
return ext;
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::load_dir(const TString& dir)
|
|
{
|
|
TFilename path(dir);
|
|
TString_array flist;
|
|
//bool* lookup_t = new bool[flist.items()];
|
|
path.add("*.*"); // Qualsiasi file con estensione, controllo dopo.
|
|
list_files(path, flist);
|
|
FOR_EACH_ARRAY_ROW(flist, nr, file)
|
|
{
|
|
TFilename f(*file);
|
|
if (verify_extension(f))
|
|
load_file(f);
|
|
}
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::load_extensions()
|
|
{
|
|
if (_extensions == nullptr)
|
|
{
|
|
_extensions = std::make_unique<std::set<std::string>>();
|
|
TToken_string& ext = get_valid_extensions();
|
|
for (int i = 0; i < ext.items(); ++i)
|
|
{
|
|
TString e = ext.get(i);
|
|
if (!e.empty())
|
|
{
|
|
if (e.starts_with("."))
|
|
e.ltrim(1);
|
|
_extensions->insert(std::string(e));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::load_file(const TFilename& file)
|
|
{
|
|
// todo
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::open_import_win()
|
|
{
|
|
if(_import_msk == nullptr)
|
|
_import_msk = make_unique<TImport_msk>();
|
|
while(_import_msk->run() == K_ENTER)
|
|
{
|
|
const TString& file = _import_msk->get(F_ADDRESS);
|
|
const TString& dir = _import_msk->get(F_DIRECTORY);
|
|
if(file.empty())
|
|
load_dir(dir);
|
|
else
|
|
{
|
|
TFilename f(file);
|
|
if (verify_extension(f))
|
|
load_file(f);
|
|
else
|
|
warning_box("Questo file e' in un formato non accettato.");
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::verify_extension(const TFilename& file)
|
|
{
|
|
load_extensions();
|
|
return _extensions->find(file.ext()) != _extensions->end();
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TGestione_doc_cartacei_f9_app
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class TGestione_doc_cartacei_f9_app : public TSkeleton_application
|
|
{
|
|
void main_loop() override
|
|
{
|
|
TGestione_doc_cartacei_f9_msk msk;
|
|
while (msk.run() == K_ENTER)
|
|
{ }
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
int f90300(const int argc, char* argv[])
|
|
{
|
|
TGestione_doc_cartacei_f9_app app;
|
|
app.run(argc, argv, "Gestione documenti cartacei");
|
|
return 0;
|
|
}
|