Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/csv/import/csvwizard.cpp
Show All 36 Lines | |||||
37 | #include <KMessageBox> | 37 | #include <KMessageBox> | ||
38 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
39 | #include <KConfigGroup> | 39 | #include <KConfigGroup> | ||
40 | #include <KColorScheme> | 40 | #include <KColorScheme> | ||
41 | 41 | | |||
42 | // ---------------------------------------------------------------------------- | 42 | // ---------------------------------------------------------------------------- | ||
43 | // Project Includes | 43 | // Project Includes | ||
44 | 44 | | |||
45 | #include "csvimporterplugin.h" | | |||
46 | #include "csvutil.h" | | |||
47 | #include "convdate.h" | | |||
48 | #include "csvimporter.h" | 45 | #include "csvimporter.h" | ||
46 | #include "core/csvutil.h" | ||||
47 | #include "core/convdate.h" | ||||
48 | #include "core/csvimportercore.h" | ||||
49 | #include "investmentwizardpage.h" | 49 | #include "investmentwizardpage.h" | ||
50 | #include "bankingwizardpage.h" | 50 | #include "bankingwizardpage.h" | ||
51 | #include "priceswizardpage.h" | 51 | #include "priceswizardpage.h" | ||
52 | #include "icons/icons.h" | 52 | #include "icons/icons.h" | ||
53 | #include "ui_csvwizard.h" | 53 | #include "ui_csvwizard.h" | ||
54 | #include "ui_introwizardpage.h" | 54 | #include "ui_introwizardpage.h" | ||
55 | #include "ui_separatorwizardpage.h" | 55 | #include "ui_separatorwizardpage.h" | ||
56 | #include "ui_rowswizardpage.h" | 56 | #include "ui_rowswizardpage.h" | ||
57 | #include "ui_formatswizardpage.h" | 57 | #include "ui_formatswizardpage.h" | ||
58 | 58 | | |||
59 | using namespace Icons; | 59 | using namespace Icons; | ||
60 | 60 | | |||
61 | CSVWizard::CSVWizard(CsvImporterPlugin* plugin, CSVImporter* importer) : | 61 | CSVWizard::CSVWizard(CSVImporter *plugin, CSVImporterCore* importer) : | ||
62 | ui(new Ui::CSVWizard), | 62 | ui(new Ui::CSVWizard), | ||
63 | m_plugin(plugin), | 63 | m_plugin(plugin), | ||
64 | m_imp(importer), | 64 | m_imp(importer), | ||
65 | m_wiz(new QWizard) | 65 | m_wiz(new QWizard) | ||
66 | { | 66 | { | ||
67 | ui->setupUi(this); | 67 | ui->setupUi(this); | ||
68 | ui->tableView->setModel(m_imp->m_file->m_model); | 68 | ui->tableView->setModel(m_imp->m_file->m_model); | ||
69 | readWindowSize(CSVImporter::configFile()); | 69 | readWindowSize(CSVImporterCore::configFile()); | ||
70 | m_wiz->setWizardStyle(QWizard::ClassicStyle); | 70 | m_wiz->setWizardStyle(QWizard::ClassicStyle); | ||
71 | ui->horizontalLayout->addWidget(m_wiz); | 71 | ui->horizontalLayout->addWidget(m_wiz); | ||
72 | m_curId = -1; | 72 | m_curId = -1; | ||
73 | m_lastId = -1; | 73 | m_lastId = -1; | ||
74 | m_wiz->installEventFilter(this); // event filter for escape key presses | 74 | m_wiz->installEventFilter(this); // event filter for escape key presses | ||
75 | 75 | | |||
76 | m_wiz->button(QWizard::BackButton)->setIcon(Icons::get(Icon::ArrowLeft)); | 76 | m_wiz->button(QWizard::BackButton)->setIcon(Icons::get(Icon::ArrowLeft)); | ||
77 | m_wiz->button(QWizard::CancelButton)->setIcon(Icons::get(Icon::DialogCancel)); | 77 | m_wiz->button(QWizard::CancelButton)->setIcon(Icons::get(Icon::DialogCancel)); | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
135 | 135 | | |||
136 | void CSVWizard::showStage() | 136 | void CSVWizard::showStage() | ||
137 | { | 137 | { | ||
138 | QString str = ui->label_intro->text(); | 138 | QString str = ui->label_intro->text(); | ||
139 | ui->label_intro->setText(QString::fromLatin1("<b>%1</b>").arg(str)); | 139 | ui->label_intro->setText(QString::fromLatin1("<b>%1</b>").arg(str)); | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | void CSVWizard::readWindowSize(const KSharedConfigPtr& config) { | 142 | void CSVWizard::readWindowSize(const KSharedConfigPtr& config) { | ||
143 | KConfigGroup miscGroup(config, CSVImporter::m_confMiscName); | 143 | KConfigGroup miscGroup(config, CSVImporterCore::m_confMiscName); | ||
144 | m_initialWidth = miscGroup.readEntry(CSVImporter::m_miscSettingsConfName.value(ConfWidth), 800); | 144 | m_initialWidth = miscGroup.readEntry(CSVImporterCore::m_miscSettingsConfName.value(ConfWidth), 800); | ||
145 | m_initialHeight = miscGroup.readEntry(CSVImporter::m_miscSettingsConfName.value(ConfHeight), 400); | 145 | m_initialHeight = miscGroup.readEntry(CSVImporterCore::m_miscSettingsConfName.value(ConfHeight), 400); | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | void CSVWizard::saveWindowSize(const KSharedConfigPtr& config) { | 148 | void CSVWizard::saveWindowSize(const KSharedConfigPtr& config) { | ||
149 | KConfigGroup miscGroup(config, CSVImporter::m_confMiscName); | 149 | KConfigGroup miscGroup(config, CSVImporterCore::m_confMiscName); | ||
150 | m_initialHeight = this->geometry().height(); | 150 | m_initialHeight = this->geometry().height(); | ||
151 | m_initialWidth = this->geometry().width(); | 151 | m_initialWidth = this->geometry().width(); | ||
152 | miscGroup.writeEntry(CSVImporter::m_miscSettingsConfName.value(ConfWidth), m_initialWidth); | 152 | miscGroup.writeEntry(CSVImporterCore::m_miscSettingsConfName.value(ConfWidth), m_initialWidth); | ||
153 | miscGroup.writeEntry(CSVImporter::m_miscSettingsConfName.value(ConfHeight), m_initialHeight); | 153 | miscGroup.writeEntry(CSVImporterCore::m_miscSettingsConfName.value(ConfHeight), m_initialHeight); | ||
154 | miscGroup.sync(); | 154 | miscGroup.sync(); | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | void CSVWizard::slotIdChanged(int id) | 157 | void CSVWizard::slotIdChanged(int id) | ||
158 | { | 158 | { | ||
159 | QString txt; | 159 | QString txt; | ||
160 | m_lastId = m_curId; | 160 | m_lastId = m_curId; | ||
161 | m_curId = id; | 161 | m_curId = id; | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | 296 | if (object == this->m_wiz) { | |||
303 | } | 303 | } | ||
304 | } | 304 | } | ||
305 | return false; | 305 | return false; | ||
306 | } | 306 | } | ||
307 | 307 | | |||
308 | void CSVWizard::slotClose() | 308 | void CSVWizard::slotClose() | ||
309 | { | 309 | { | ||
310 | m_imp->m_profile->m_lastUsedDirectory = m_imp->m_file->m_inFileName; | 310 | m_imp->m_profile->m_lastUsedDirectory = m_imp->m_file->m_inFileName; | ||
311 | m_imp->m_profile->writeSettings(CSVImporter::configFile()); | 311 | m_imp->m_profile->writeSettings(CSVImporterCore::configFile()); | ||
312 | m_imp->profilesAction(m_imp->m_profile->type(), ProfileAction::UpdateLastUsed, m_imp->m_profile->m_profileName, m_imp->m_profile->m_profileName); | 312 | m_imp->profilesAction(m_imp->m_profile->type(), ProfileAction::UpdateLastUsed, m_imp->m_profile->m_profileName, m_imp->m_profile->m_profileName); | ||
313 | close(); | 313 | close(); | ||
314 | } | 314 | } | ||
315 | 315 | | |||
316 | void CSVWizard::fileDialogClicked() | 316 | void CSVWizard::fileDialogClicked() | ||
317 | { | 317 | { | ||
318 | m_imp->profileFactory(m_pageIntro->m_profileType, m_pageIntro->ui->m_profiles->currentText()); | 318 | m_imp->profileFactory(m_pageIntro->m_profileType, m_pageIntro->ui->m_profiles->currentText()); | ||
319 | bool profileExists = m_imp->m_profile->readSettings(CSVImporter::configFile()); | 319 | bool profileExists = m_imp->m_profile->readSettings(CSVImporterCore::configFile()); | ||
320 | 320 | | |||
321 | if (!m_fileName.isEmpty()) { | 321 | if (!m_fileName.isEmpty()) { | ||
322 | if (!m_imp->m_file->getInFileName(m_fileName)) { | 322 | if (!m_imp->m_file->getInFileName(m_fileName)) { | ||
323 | if (!m_imp->m_file->getInFileName(m_imp->m_profile->m_lastUsedDirectory)) { | 323 | if (!m_imp->m_file->getInFileName(m_imp->m_profile->m_lastUsedDirectory)) { | ||
324 | return; | 324 | return; | ||
325 | } | 325 | } | ||
326 | } | 326 | } | ||
327 | } else if (!m_imp->m_file->getInFileName(m_imp->m_profile->m_lastUsedDirectory)) | 327 | } else if (!m_imp->m_file->getInFileName(m_imp->m_profile->m_lastUsedDirectory)) | ||
328 | return; | 328 | return; | ||
329 | 329 | | |||
330 | saveWindowSize(CSVImporter::configFile()); | 330 | saveWindowSize(CSVImporterCore::configFile()); | ||
331 | m_imp->m_file->readFile(m_imp->m_profile); | 331 | m_imp->m_file->readFile(m_imp->m_profile); | ||
332 | m_imp->m_file->setupParser(m_imp->m_profile); | 332 | m_imp->m_file->setupParser(m_imp->m_profile); | ||
333 | 333 | | |||
334 | m_skipSetup = m_pageIntro->ui->m_skipSetup->isChecked(); | 334 | m_skipSetup = m_pageIntro->ui->m_skipSetup->isChecked(); | ||
335 | 335 | | |||
336 | switch(m_imp->m_profile->type()) { | 336 | switch(m_imp->m_profile->type()) { | ||
337 | case Profile::Investment: | 337 | case Profile::Investment: | ||
338 | if (!m_pageInvestment) { | 338 | if (!m_pageInvestment) { | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 431 | foreach (const auto column, columns) { | |||
438 | // all comboboxes are set to 0 so set them to -1 | 438 | // all comboboxes are set to 0 so set them to -1 | ||
439 | column->setCurrentIndex(-1); | 439 | column->setCurrentIndex(-1); | ||
440 | // enable widgets after their initialization | 440 | // enable widgets after their initialization | ||
441 | column->blockSignals(false); | 441 | column->blockSignals(false); | ||
442 | } | 442 | } | ||
443 | } | 443 | } | ||
444 | 444 | | |||
445 | //------------------------------------------------------------------------------------------------------- | 445 | //------------------------------------------------------------------------------------------------------- | ||
446 | IntroPage::IntroPage(CSVWizard *dlg, CSVImporter *imp) : | 446 | IntroPage::IntroPage(CSVWizard *dlg, CSVImporterCore *imp) : | ||
447 | CSVWizardPage(dlg, imp), | 447 | CSVWizardPage(dlg, imp), | ||
448 | ui(new Ui::IntroPage) | 448 | ui(new Ui::IntroPage) | ||
449 | { | 449 | { | ||
450 | ui->setupUi(this); | 450 | ui->setupUi(this); | ||
451 | } | 451 | } | ||
452 | 452 | | |||
453 | IntroPage::~IntroPage() | 453 | IntroPage::~IntroPage() | ||
454 | { | 454 | { | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 530 | switch (action) { | |||
546 | case ProfileAction::Remove: | 546 | case ProfileAction::Remove: | ||
547 | if (m_profiles.value(cbIndex) != cbText) // user changed name of the profile and tries to remove it | 547 | if (m_profiles.value(cbIndex) != cbText) // user changed name of the profile and tries to remove it | ||
548 | return; | 548 | return; | ||
549 | break; | 549 | break; | ||
550 | default: | 550 | default: | ||
551 | break; | 551 | break; | ||
552 | } | 552 | } | ||
553 | 553 | | |||
554 | if (CSVImporter::profilesAction(m_profileType, action, m_profiles.value(cbIndex), cbText)) { | 554 | if (CSVImporterCore::profilesAction(m_profileType, action, m_profiles.value(cbIndex), cbText)) { | ||
555 | switch (action) { | 555 | switch (action) { | ||
556 | case ProfileAction::Add: | 556 | case ProfileAction::Add: | ||
557 | m_profiles.append(cbText); | 557 | m_profiles.append(cbText); | ||
558 | ui->m_profiles->addItem(cbText); | 558 | ui->m_profiles->addItem(cbText); | ||
559 | ui->m_profiles->setCurrentIndex(m_profiles.count() - 1); | 559 | ui->m_profiles->setCurrentIndex(m_profiles.count() - 1); | ||
560 | KMessageBox::information(m_dlg, | 560 | KMessageBox::information(m_dlg, | ||
561 | i18n("<center>Profile <b>%1</b> has been added.</center>", cbText)); | 561 | i18n("<center>Profile <b>%1</b> has been added.</center>", cbText)); | ||
562 | break; | 562 | break; | ||
Show All 33 Lines | 584 | { | |||
596 | } | 596 | } | ||
597 | } | 597 | } | ||
598 | 598 | | |||
599 | void IntroPage::profileTypeChanged(const Profile profileType, bool toggled) | 599 | void IntroPage::profileTypeChanged(const Profile profileType, bool toggled) | ||
600 | { | 600 | { | ||
601 | if (!toggled) | 601 | if (!toggled) | ||
602 | return; | 602 | return; | ||
603 | 603 | | |||
604 | KConfigGroup profilesGroup(CSVImporter::configFile(), CSVImporter::m_confProfileNames); | 604 | KConfigGroup profilesGroup(CSVImporterCore::configFile(), CSVImporterCore::m_confProfileNames); | ||
605 | m_profileType = profileType; | 605 | m_profileType = profileType; | ||
606 | QString profileTypeStr; | 606 | QString profileTypeStr; | ||
607 | switch (m_profileType) { | 607 | switch (m_profileType) { | ||
608 | case Profile::Banking: | 608 | case Profile::Banking: | ||
609 | ui->m_profilesInvest->setChecked(false); | 609 | ui->m_profilesInvest->setChecked(false); | ||
610 | ui->m_profilesStockPrices->setChecked(false); | 610 | ui->m_profilesStockPrices->setChecked(false); | ||
611 | ui->m_profilesCurrencyPrices->setChecked(false); | 611 | ui->m_profilesCurrencyPrices->setChecked(false); | ||
612 | break; | 612 | break; | ||
Show All 10 Lines | |||||
623 | case Profile::CurrencyPrices: | 623 | case Profile::CurrencyPrices: | ||
624 | ui->m_profilesBank->setChecked(false); | 624 | ui->m_profilesBank->setChecked(false); | ||
625 | ui->m_profilesInvest->setChecked(false); | 625 | ui->m_profilesInvest->setChecked(false); | ||
626 | ui->m_profilesStockPrices->setChecked(false); | 626 | ui->m_profilesStockPrices->setChecked(false); | ||
627 | break; | 627 | break; | ||
628 | default: | 628 | default: | ||
629 | break; | 629 | break; | ||
630 | } | 630 | } | ||
631 | profileTypeStr = CSVImporter::m_profileConfPrefix.value(m_profileType); | 631 | profileTypeStr = CSVImporterCore::m_profileConfPrefix.value(m_profileType); | ||
632 | 632 | | |||
633 | m_profiles = profilesGroup.readEntry(profileTypeStr, QStringList()); | 633 | m_profiles = profilesGroup.readEntry(profileTypeStr, QStringList()); | ||
634 | int priorProfile = profilesGroup.readEntry(CSVImporter::m_confPriorName + profileTypeStr, 0); | 634 | int priorProfile = profilesGroup.readEntry(CSVImporterCore::m_confPriorName + profileTypeStr, 0); | ||
635 | ui->m_profiles->clear(); | 635 | ui->m_profiles->clear(); | ||
636 | ui->m_profiles->addItems(m_profiles); | 636 | ui->m_profiles->addItems(m_profiles); | ||
637 | ui->m_profiles->setCurrentIndex(priorProfile); | 637 | ui->m_profiles->setCurrentIndex(priorProfile); | ||
638 | ui->m_profiles->setEnabled(true); | 638 | ui->m_profiles->setEnabled(true); | ||
639 | ui->m_add->setEnabled(true); | 639 | ui->m_add->setEnabled(true); | ||
640 | } | 640 | } | ||
641 | 641 | | |||
642 | void IntroPage::slotBankRadioToggled(bool toggled) | 642 | void IntroPage::slotBankRadioToggled(bool toggled) | ||
Show All 11 Lines | 653 | { | |||
654 | profileTypeChanged(Profile::CurrencyPrices, toggled); | 654 | profileTypeChanged(Profile::CurrencyPrices, toggled); | ||
655 | } | 655 | } | ||
656 | 656 | | |||
657 | void IntroPage::slotStockPricesRadioToggled(bool toggled) | 657 | void IntroPage::slotStockPricesRadioToggled(bool toggled) | ||
658 | { | 658 | { | ||
659 | profileTypeChanged(Profile::StockPrices, toggled); | 659 | profileTypeChanged(Profile::StockPrices, toggled); | ||
660 | } | 660 | } | ||
661 | 661 | | |||
662 | SeparatorPage::SeparatorPage(CSVWizard *dlg, CSVImporter *imp) : | 662 | SeparatorPage::SeparatorPage(CSVWizard *dlg, CSVImporterCore *imp) : | ||
663 | CSVWizardPage(dlg, imp), | 663 | CSVWizardPage(dlg, imp), | ||
664 | ui(new Ui::SeparatorPage) | 664 | ui(new Ui::SeparatorPage) | ||
665 | { | 665 | { | ||
666 | ui->setupUi(this); | 666 | ui->setupUi(this); | ||
667 | connect(ui->m_encoding, SIGNAL(currentIndexChanged(int)), this, SLOT(encodingChanged(int))); | 667 | connect(ui->m_encoding, SIGNAL(currentIndexChanged(int)), this, SLOT(encodingChanged(int))); | ||
668 | connect(ui->m_fieldDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(fieldDelimiterChanged(int))); | 668 | connect(ui->m_fieldDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(fieldDelimiterChanged(int))); | ||
669 | connect(ui->m_textDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(textDelimiterChanged(int))); | 669 | connect(ui->m_textDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(textDelimiterChanged(int))); | ||
670 | } | 670 | } | ||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Line(s) | |||||
822 | 822 | | |||
823 | void SeparatorPage::cleanupPage() | 823 | void SeparatorPage::cleanupPage() | ||
824 | { | 824 | { | ||
825 | // On completion with error force use of 'Back' button. | 825 | // On completion with error force use of 'Back' button. | ||
826 | // ...to allow resetting of 'Skip setup' | 826 | // ...to allow resetting of 'Skip setup' | ||
827 | m_dlg->m_pageIntro->initializePage(); // Need to show button(QWizard::CustomButton1) not 'NextButton' | 827 | m_dlg->m_pageIntro->initializePage(); // Need to show button(QWizard::CustomButton1) not 'NextButton' | ||
828 | } | 828 | } | ||
829 | 829 | | |||
830 | RowsPage::RowsPage(CSVWizard *dlg, CSVImporter *imp) : | 830 | RowsPage::RowsPage(CSVWizard *dlg, CSVImporterCore *imp) : | ||
831 | CSVWizardPage(dlg, imp), | 831 | CSVWizardPage(dlg, imp), | ||
832 | ui(new Ui::RowsPage) | 832 | ui(new Ui::RowsPage) | ||
833 | { | 833 | { | ||
834 | ui->setupUi(this); | 834 | ui->setupUi(this); | ||
835 | connect(ui->m_startLine, SIGNAL(valueChanged(int)), this, SLOT(startRowChanged(int)));; | 835 | connect(ui->m_startLine, SIGNAL(valueChanged(int)), this, SLOT(startRowChanged(int)));; | ||
836 | connect(ui->m_endLine, SIGNAL(valueChanged(int)), this, SLOT(endRowChanged(int))); | 836 | connect(ui->m_endLine, SIGNAL(valueChanged(int)), this, SLOT(endRowChanged(int))); | ||
837 | } | 837 | } | ||
838 | 838 | | |||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 916 | if (val < m_imp->m_profile->m_startLine) { | |||
919 | return; | 919 | return; | ||
920 | } | 920 | } | ||
921 | m_imp->m_profile->m_trailerLines = m_imp->m_file->m_rowCount - val; | 921 | m_imp->m_profile->m_trailerLines = m_imp->m_file->m_rowCount - val; | ||
922 | m_imp->m_profile->m_endLine = val; | 922 | m_imp->m_profile->m_endLine = val; | ||
923 | m_dlg->markUnwantedRows(); | 923 | m_dlg->markUnwantedRows(); | ||
924 | } | 924 | } | ||
925 | 925 | | |||
926 | 926 | | |||
927 | FormatsPage::FormatsPage(CSVWizard *dlg, CSVImporter *imp) : | 927 | FormatsPage::FormatsPage(CSVWizard *dlg, CSVImporterCore *imp) : | ||
928 | CSVWizardPage(dlg, imp), | 928 | CSVWizardPage(dlg, imp), | ||
929 | ui(new Ui::FormatsPage) | 929 | ui(new Ui::FormatsPage) | ||
930 | { | 930 | { | ||
931 | ui->setupUi(this); | 931 | ui->setupUi(this); | ||
932 | connect(ui->m_dateFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(dateFormatChanged(int))); | 932 | connect(ui->m_dateFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(dateFormatChanged(int))); | ||
933 | connect(ui->m_decimalSymbol, SIGNAL(currentIndexChanged(int)), this, SLOT(decimalSymbolChanged(int))); | 933 | connect(ui->m_decimalSymbol, SIGNAL(currentIndexChanged(int)), this, SLOT(decimalSymbolChanged(int))); | ||
934 | } | 934 | } | ||
935 | 935 | | |||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |