69
79
overlayofx.push_back("skrooge");
71
81
importOfxAction = new KAction(KIcon("document-import", NULL, overlayofx), i18n("Import &OFX..."), this);
72
connect(importOfxAction, SIGNAL(triggered(bool)), SLOT(importOfx()));
82
connect(importOfxAction, SIGNAL(triggered(bool)), SLOT(import()));
73
83
actionCollection()->addAction( QLatin1String("import_ofx"), importOfxAction );
74
84
imports->addAction(importOfxAction);
76
iParent->registedGlobalAction("import_ofx", importOfxAction);
86
if (parent) parent->registedGlobalAction("import_ofx", importOfxAction);
79
89
QStringList overlaycsv;
80
90
overlaycsv.push_back("text-csv");
82
92
importQifAction = new KAction(KIcon("document-import"), i18n("Import &QIF..."), this);
83
connect(importQifAction, SIGNAL(triggered(bool)), SLOT(importQif()));
93
connect(importQifAction, SIGNAL(triggered(bool)), SLOT(import()));
84
94
actionCollection()->addAction( QLatin1String("import_qif"), importQifAction );
85
95
imports->addAction(importQifAction);
87
iParent->registedGlobalAction("import_qif", importQifAction);
97
if (parent) parent->registedGlobalAction("import_qif", importQifAction);
90
100
importCsvAction = new KAction(KIcon("document-import", NULL, overlaycsv), i18n("Import &CSV..."), this);
91
connect(importCsvAction, SIGNAL(triggered(bool)), SLOT(importCsv()));
101
connect(importCsvAction, SIGNAL(triggered(bool)), SLOT(import()));
92
102
actionCollection()->addAction( QLatin1String("import_csv"), importCsvAction );
93
103
imports->addAction(importCsvAction);
95
iParent->registedGlobalAction("import_csv", importCsvAction);
105
if (parent) parent->registedGlobalAction("import_csv", importCsvAction);
98
108
importCsvUnitAction = new KAction(KIcon("document-import", NULL, overlaycsv), i18n("Import CSV &Unit..."), this);
99
connect(importCsvUnitAction, SIGNAL(triggered(bool)), SLOT(importCsvUnit()));
109
connect(importCsvUnitAction, SIGNAL(triggered(bool)), SLOT(import()));
100
110
actionCollection()->addAction( QLatin1String("import_csv_unit"), importCsvUnitAction );
101
111
imports->addAction(importCsvUnitAction);
103
iParent->registedGlobalAction("import_csv_unit", importCsvUnitAction);
113
if (parent) parent->registedGlobalAction("import_csv_unit", importCsvUnitAction);
106
116
KActionMenu* exports=new KActionMenu(KIcon("document-export"),i18n("Export"), this);
194
204
SKGTRACEIN(10, "SKGImportExportPlugin::refresh");
196
bool test=(currentBankDocument->getDatabase()!=NULL);
197
importQifAction->setEnabled(test);
198
importOfxAction->setEnabled(test);
199
importCsvAction->setEnabled(test);
200
exportQifAction->setEnabled(test);
201
exportCsvAction->setEnabled(test);
202
processingFoundTransfert->setEnabled(test);
203
processingBankPerfect->setEnabled(test);
204
processingBank->setEnabled(test);
206
if (currentBankDocument) {
207
bool test=(currentBankDocument->getDatabase()!=NULL);
208
if (importQifAction) importQifAction->setEnabled(test);
209
if (importOfxAction) importOfxAction->setEnabled(test);
210
if (importCsvAction) importCsvAction->setEnabled(test);
211
if (exportQifAction) exportQifAction->setEnabled(test);
212
if (exportCsvAction) exportCsvAction->setEnabled(test);
213
if (importCsvUnitAction) importCsvUnitAction->setEnabled(test);
214
if (processingFoundTransfert) processingFoundTransfert->setEnabled(test);
215
if (processingBankPerfect) processingBankPerfect->setEnabled(test);
216
if (processingBank) processingBank->setEnabled(test);
207
220
void SKGImportExportPlugin::close()
209
222
SKGTRACEIN(10, "SKGImportExportPlugin::close");
212
void SKGImportExportPlugin::importOfx()
215
SKGTRACEINRC(10, "SKGImportExportPlugin::importOfx",err);
216
import(SKGImportExportManager::OFX);
219
void SKGImportExportPlugin::importQif()
222
SKGTRACEINRC(10, "SKGImportExportPlugin::importQif",err);
223
import(SKGImportExportManager::QIF);
226
void SKGImportExportPlugin::importCsv()
229
SKGTRACEINRC(10, "SKGImportExportPlugin::importCsv",err);
230
import(SKGImportExportManager::CSV);
233
void SKGImportExportPlugin::importCsvUnit()
236
SKGTRACEINRC(10, "SKGImportExportPlugin::importCsvUnit",err);
237
import(SKGImportExportManager::CSVUNIT);
240
void SKGImportExportPlugin::import(SKGImportExportManager::ImportExportMode iMode)
225
void SKGImportExportPlugin::import()
243
228
SKGTRACEINRC(10, "SKGImportExportPlugin::import",err);
244
QString lastCodecUsed=currentBankDocument->getParameter("SKG_LAST_CODEC_USED_FOR_IMPORT");
245
if (lastCodecUsed.length()==0) lastCodecUsed=QTextCodec::codecForLocale()->name();
247
KEncodingFileDialog::Result result=KEncodingFileDialog::getOpenFileNamesAndEncoding(lastCodecUsed,
248
"kfiledialog:///IMPEXP",
249
iMode==SKGImportExportManager::CSV || iMode==SKGImportExportManager::CSVUNIT ?
250
"*.csv|"+i18n("CSV Files") :
251
iMode==SKGImportExportManager::OFX ? "*.ofx|"+i18n("OFX Files") : "*.qif|"+i18n("QIF Files") ,
253
QSet<QString> fileNames=result.fileNames.toSet();
254
QString codec=result.encoding;
256
int nbFiles=fileNames.count();
259
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
261
SKGBEGINPROGRESSTRANSACTION(*currentBankDocument, i18n("Import %1 with codec %2",
262
(iMode==SKGImportExportManager::CSV || iMode==SKGImportExportManager::CSVUNIT ? i18n("CSV") :
263
iMode==SKGImportExportManager::OFX ? i18n("OFX") : i18n("QIF")), codec), err, nbFiles);
265
if (err.isSucceeded()) err=currentBankDocument->setParameter("SKG_LAST_CODEC_USED_FOR_IMPORT", codec);
267
QSetIterator<QString> f(fileNames);
269
while (err.isSucceeded() && f.hasNext()) {
270
QString fileName=f.next();
271
SKGImportExportManager imp1((SKGDocumentBank*) currentBankDocument, iMode, fileName);
272
imp1.setCodec(codec);
273
err=imp1.importFile();
274
if (err.isFailed()) {
275
err.addError(ERR_FAIL, i18n("Import of [%1] failed", fileName));
277
err=SKGError(0, i18n("File [%1] successfully imported.", fileName));
229
if (currentBankDocument) {
230
QAction* sender=static_cast<QAction*> ( this->sender() );
231
SKGImportExportManager::ImportExportMode iMode=SKGImportExportManager::OFX;
233
if (sender==importQifAction) iMode=SKGImportExportManager::QIF;
234
else if (sender==importCsvAction) iMode=SKGImportExportManager::CSV;
235
else if (sender==importCsvUnitAction) iMode=SKGImportExportManager::CSVUNIT;
237
QString lastCodecUsed=currentBankDocument->getParameter("SKG_LAST_CODEC_USED_FOR_IMPORT");
238
if (lastCodecUsed.length()==0) lastCodecUsed=QTextCodec::codecForLocale()->name();
240
KEncodingFileDialog::Result result=KEncodingFileDialog::getOpenFileNamesAndEncoding(lastCodecUsed,
241
"kfiledialog:///IMPEXP",
242
iMode==SKGImportExportManager::CSV || iMode==SKGImportExportManager::CSVUNIT ?
243
"*.csv|"+i18n("CSV Files") :
244
iMode==SKGImportExportManager::OFX ? "*.ofx|"+i18n("OFX Files") : "*.qif|"+i18n("QIF Files") ,
246
QSet<QString> fileNames=result.fileNames.toSet();
247
QString codec=result.encoding;
249
int nbFiles=fileNames.count();
252
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
254
SKGBEGINPROGRESSTRANSACTION(*currentBankDocument, i18n("Import %1 with codec %2",
255
(iMode==SKGImportExportManager::CSV || iMode==SKGImportExportManager::CSVUNIT ? i18n("CSV") :
256
iMode==SKGImportExportManager::OFX ? i18n("OFX") : i18n("QIF")), codec), err, nbFiles);
258
if (err.isSucceeded()) err=currentBankDocument->setParameter("SKG_LAST_CODEC_USED_FOR_IMPORT", codec);
260
QSetIterator<QString> f(fileNames);
262
while (err.isSucceeded() && f.hasNext()) {
263
QString fileName=f.next();
264
SKGImportExportManager imp1((SKGDocumentBank*) currentBankDocument, iMode, fileName);
265
imp1.setCodec(codec);
266
err=imp1.importFile();
267
if (err.isFailed()) {
268
err.addError(ERR_FAIL, i18n("Import of [%1] failed", fileName));
270
err=SKGError(0, i18n("File [%1] successfully imported.", fileName));
273
if (err.isSucceeded()) err=currentBankDocument->stepForward(i);
280
if (err.isSucceeded()) err=currentBankDocument->stepForward(i);
284
QApplication::restoreOverrideCursor();
288
if (err.isSucceeded() && nbFiles>1) {
289
err=SKGError(0, i18n("%1 files successfully imported.", nbFiles));
293
parent->displayErrorMessage(err);
277
QApplication::restoreOverrideCursor();
281
if (err.isSucceeded() && nbFiles>1) {
282
err=SKGError(0, i18n("%1 files successfully imported.", nbFiles));
286
if (parent) parent->displayErrorMessage(err);
296
290
void SKGImportExportPlugin::exportCsv()
340
334
else err.addError(ERR_FAIL, i18n("Export of [%1] failed", fileName));
343
parent->displayErrorMessage(err);
337
if (parent) parent->displayErrorMessage(err);
346
340
void SKGImportExportPlugin::foundTransfer()
349
343
SKGTRACEINRC(10, "SKGImportExportPlugin::foundTransfer",err);
350
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
351
int NbOperationsMerged=0;
353
SKGBEGINTRANSACTION(*currentBankDocument, i18n("Find and group transfers"), err);
354
if (err.isSucceeded()) {
355
SKGImportExportManager imp1((SKGDocumentBank*) currentBankDocument, SKGImportExportManager::QIF, "");
356
err=imp1.findAndGroupTransfers(NbOperationsMerged);
344
if (currentBankDocument) {
345
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
346
int NbOperationsMerged=0;
348
SKGBEGINTRANSACTION(*currentBankDocument, i18n("Find and group transfers"), err);
349
if (err.isSucceeded()) {
350
SKGImportExportManager imp1((SKGDocumentBank*) currentBankDocument, SKGImportExportManager::QIF, "");
351
err=imp1.findAndGroupTransfers(NbOperationsMerged);
354
QApplication::restoreOverrideCursor();
357
if (err.isSucceeded()) err=SKGError(0, i18n("Document successfully processed. %1 operations merged.", NbOperationsMerged));
358
else err.addError(ERR_FAIL, i18n("Processing failed."));
361
if (parent) parent->displayErrorMessage(err);
359
QApplication::restoreOverrideCursor();
362
if (err.isSucceeded()) err=SKGError(0, i18n("Document successfully processed. %1 operations merged.", NbOperationsMerged));
363
else err.addError(ERR_FAIL, i18n("Processing failed."));
366
parent->displayErrorMessage(err);
369
365
void SKGImportExportPlugin::cleanBankPerfect()
372
368
SKGTRACEINRC(10, "SKGImportExportPlugin::cleanBankPerfect",err);
373
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
375
SKGBEGINTRANSACTION(*currentBankDocument, i18n("Clean BankPerfect's imports"), err);
376
if (err.isSucceeded()) {
377
SKGImportExportManager imp1((SKGDocumentBank*) currentBankDocument, SKGImportExportManager::QIF, "");
378
err=imp1.cleanBankPerfectImport();
369
if (currentBankDocument) {
370
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
372
SKGBEGINTRANSACTION(*currentBankDocument, i18n("Clean BankPerfect's imports"), err);
373
if (err.isSucceeded()) {
374
SKGImportExportManager imp1((SKGDocumentBank*) currentBankDocument, SKGImportExportManager::QIF, "");
375
err=imp1.cleanBankPerfectImport();
378
QApplication::restoreOverrideCursor();
381
if (err.isSucceeded()) err=SKGError(0, i18n("Document successfully cleaned."));
382
else err.addError(ERR_FAIL, i18n("Clean failed."));
385
if (parent) parent->displayErrorMessage(err);
381
QApplication::restoreOverrideCursor();
384
if (err.isSucceeded()) err=SKGError(0, i18n("Document successfully cleaned."));
385
else err.addError(ERR_FAIL, i18n("Clean failed."));
388
parent->displayErrorMessage(err);
391
389
void SKGImportExportPlugin::cleanBanks()