Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/qif/export/kexportdlg.cpp
- This file was moved from kmymoney/dialogs/kexportdlg.cpp.
Show All 22 Lines | |||||
23 | // QT Headers | 23 | // QT Headers | ||
24 | 24 | | |||
25 | #include <QLabel> | 25 | #include <QLabel> | ||
26 | #include <QPixmap> | 26 | #include <QPixmap> | ||
27 | #include <QList> | 27 | #include <QList> | ||
28 | #include <QUrl> | 28 | #include <QUrl> | ||
29 | #include <QPushButton> | 29 | #include <QPushButton> | ||
30 | #include <QIcon> | 30 | #include <QIcon> | ||
31 | #include <QFileDialog> | ||||
31 | 32 | | |||
32 | // ---------------------------------------------------------------------------- | 33 | // ---------------------------------------------------------------------------- | ||
33 | // KDE Headers | 34 | // KDE Headers | ||
34 | 35 | | |||
35 | #include <kmessagebox.h> | 36 | #include <kmessagebox.h> | ||
36 | #include <kconfiggroup.h> | 37 | #include <kconfiggroup.h> | ||
37 | #include <KGuiItem> | 38 | #include <KGuiItem> | ||
38 | #include <KStandardGuiItem> | 39 | #include <KStandardGuiItem> | ||
39 | #include <KSharedConfig> | 40 | #include <KSharedConfig> | ||
40 | #include <KLocalizedString> | 41 | #include <KLocalizedString> | ||
41 | 42 | | |||
42 | // ---------------------------------------------------------------------------- | 43 | // ---------------------------------------------------------------------------- | ||
43 | // Project Headers | 44 | // Project Headers | ||
44 | 45 | | |||
45 | #include "mymoneycategory.h" | 46 | #include "mymoneycategory.h" | ||
46 | #include "mymoneyqifprofileeditor.h" | | |||
47 | #include "mymoneyfile.h" | 47 | #include "mymoneyfile.h" | ||
48 | #include "kmymoneyaccountcombo.h" | 48 | #include "kmymoneyaccountcombo.h" | ||
49 | #include "kmymoneyutils.h" | 49 | #include "kmymoneyutils.h" | ||
50 | #include "models.h" | 50 | #include "models.h" | ||
51 | #include <icons/icons.h> | 51 | #include <icons/icons.h> | ||
52 | 52 | | |||
53 | using namespace Icons; | 53 | using namespace Icons; | ||
54 | 54 | | |||
Show All 16 Lines | 57 | { | |||
71 | KGuiItem::assign(m_qbuttonOk, okButtenItem); | 71 | KGuiItem::assign(m_qbuttonOk, okButtenItem); | ||
72 | 72 | | |||
73 | KGuiItem browseButtenItem(i18n("&Browse..."), | 73 | KGuiItem browseButtenItem(i18n("&Browse..."), | ||
74 | QIcon::fromTheme(g_Icons[Icon::DocumentOpen]), | 74 | QIcon::fromTheme(g_Icons[Icon::DocumentOpen]), | ||
75 | i18n("Select filename"), | 75 | i18n("Select filename"), | ||
76 | i18n("Use this to select a filename to export to")); | 76 | i18n("Use this to select a filename to export to")); | ||
77 | KGuiItem::assign(m_qbuttonBrowse, browseButtenItem); | 77 | KGuiItem::assign(m_qbuttonBrowse, browseButtenItem); | ||
78 | 78 | | |||
79 | KGuiItem newButtenItem(i18nc("New profile", "&New..."), | | |||
80 | QIcon::fromTheme(g_Icons[Icon::DocumentNew]), | | |||
81 | i18n("Create a new profile"), | | |||
82 | i18n("Use this to open the profile editor")); | | |||
83 | KGuiItem::assign(m_profileEditorButton, newButtenItem); | | |||
84 | | ||||
85 | | ||||
86 | // connect the buttons to their functionality | 79 | // connect the buttons to their functionality | ||
87 | connect(m_qbuttonBrowse, SIGNAL(clicked()), this, SLOT(slotBrowse())); | 80 | connect(m_qbuttonBrowse, &QAbstractButton::clicked, this, &KExportDlg::slotBrowse); | ||
88 | connect(m_profileEditorButton, SIGNAL(clicked()), this, SLOT(slotNewProfile())); | 81 | connect(m_qbuttonOk, &QAbstractButton::clicked, this, &KExportDlg::slotOkClicked); | ||
89 | connect(m_qbuttonOk, SIGNAL(clicked()), this, SLOT(slotOkClicked())); | 82 | connect(m_qbuttonCancel, &QAbstractButton::clicked, this, &QDialog::reject); | ||
90 | connect(m_qbuttonCancel, SIGNAL(clicked()), this, SLOT(reject())); | | |||
91 | 83 | | |||
92 | // connect the change signals to the check slot and perform initial check | 84 | // connect the change signals to the check slot and perform initial check | ||
93 | connect(m_qlineeditFile, SIGNAL(textChanged(QString)), this, SLOT(checkData())); | 85 | connect(m_qlineeditFile, SIGNAL(textChanged(QString)), this, SLOT(checkData())); | ||
94 | connect(m_qcheckboxAccount, SIGNAL(toggled(bool)), this, SLOT(checkData())); | 86 | connect(m_qcheckboxAccount, SIGNAL(toggled(bool)), this, SLOT(checkData())); | ||
95 | connect(m_qcheckboxCategories, SIGNAL(toggled(bool)), this, SLOT(checkData())); | 87 | connect(m_qcheckboxCategories, SIGNAL(toggled(bool)), this, SLOT(checkData())); | ||
96 | connect(m_accountComboBox, SIGNAL(accountSelected(QString)), this, SLOT(checkData(QString))); | 88 | connect(m_accountComboBox, SIGNAL(accountSelected(QString)), this, SLOT(checkData(QString))); | ||
97 | connect(m_profileComboBox, SIGNAL(activated(int)), this, SLOT(checkData())); | 89 | connect(m_profileComboBox, SIGNAL(activated(int)), this, SLOT(checkData())); | ||
98 | connect(m_kmymoneydateStart, SIGNAL(dateChanged(QDate)), this, SLOT(checkData())); | 90 | connect(m_kmymoneydateStart, SIGNAL(dateChanged(QDate)), this, SLOT(checkData())); | ||
99 | connect(m_kmymoneydateEnd, SIGNAL(dateChanged(QDate)), this, SLOT(checkData())); | 91 | connect(m_kmymoneydateEnd, SIGNAL(dateChanged(QDate)), this, SLOT(checkData())); | ||
100 | 92 | | |||
101 | checkData(QString()); | 93 | checkData(QString()); | ||
102 | } | 94 | } | ||
103 | 95 | | |||
104 | KExportDlg::~KExportDlg() | 96 | KExportDlg::~KExportDlg() | ||
105 | { | 97 | { | ||
106 | } | 98 | } | ||
107 | 99 | | |||
108 | void KExportDlg::slotBrowse() | 100 | void KExportDlg::slotBrowse() | ||
109 | { | 101 | { | ||
110 | QString newName(QFileDialog::getSaveFileName(this, QString(), QString(), QLatin1String("*.QIF"))); | 102 | auto newName(QFileDialog::getSaveFileName(this, QString(), QString(), QLatin1String("*.QIF"))); | ||
111 | KMyMoneyUtils::appendCorrectFileExt(newName, QLatin1String("qif")); | 103 | if (!newName.endsWith(QLatin1String(".qif"), Qt::CaseInsensitive)) | ||
104 | newName.append(QLatin1String(".qif")); | ||||
112 | if (!newName.isEmpty()) | 105 | if (!newName.isEmpty()) | ||
113 | m_qlineeditFile->setText(newName); | 106 | m_qlineeditFile->setText(newName); | ||
114 | } | 107 | } | ||
115 | 108 | | |||
116 | void KExportDlg::slotNewProfile() | | |||
117 | { | | |||
118 | QPointer<MyMoneyQifProfileEditor> editor = new MyMoneyQifProfileEditor(true, this); | | |||
119 | editor->setObjectName("QIF Profile Editor"); | | |||
120 | if (editor->exec()) { | | |||
121 | m_profileComboBox->setCurrentIndex(m_profileComboBox->findText(editor->selectedProfile(), Qt::MatchExactly)); | | |||
122 | loadProfiles(); | | |||
123 | } | | |||
124 | delete editor; | | |||
125 | } | | |||
126 | | ||||
127 | void KExportDlg::loadProfiles(const bool selectLast) | 109 | void KExportDlg::loadProfiles(const bool selectLast) | ||
128 | { | 110 | { | ||
129 | // Creating an editor object here makes sure that | | |||
130 | // we have at least the default profile available | | |||
131 | MyMoneyQifProfileEditor* edit = new MyMoneyQifProfileEditor(true, 0); | | |||
132 | edit->slotOk(); | | |||
133 | delete edit; | | |||
134 | | ||||
135 | QString current = m_profileComboBox->currentText(); | 111 | QString current = m_profileComboBox->currentText(); | ||
136 | 112 | | |||
137 | m_profileComboBox->clear(); | 113 | m_profileComboBox->clear(); | ||
138 | 114 | | |||
139 | QStringList list; | 115 | QStringList list; | ||
140 | KSharedConfigPtr config = KSharedConfig::openConfig(); | 116 | KSharedConfigPtr config = KSharedConfig::openConfig(); | ||
141 | KConfigGroup grp = config->group("Profiles"); | 117 | KConfigGroup grp = config->group("Profiles"); | ||
142 | 118 | | |||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 154 | { | |||
187 | kconfig->sync(); | 163 | kconfig->sync(); | ||
188 | } | 164 | } | ||
189 | 165 | | |||
190 | void KExportDlg::checkData(const QString& accountId) | 166 | void KExportDlg::checkData(const QString& accountId) | ||
191 | { | 167 | { | ||
192 | bool okEnabled = false; | 168 | bool okEnabled = false; | ||
193 | 169 | | |||
194 | if (!m_qlineeditFile->text().isEmpty()) { | 170 | if (!m_qlineeditFile->text().isEmpty()) { | ||
195 | QString strFile(m_qlineeditFile->text()); | 171 | auto strFile(m_qlineeditFile->text()); | ||
196 | if (KMyMoneyUtils::appendCorrectFileExt(strFile, QString("qif"))) | 172 | if (!strFile.endsWith(QLatin1String(".qif"), Qt::CaseInsensitive)) | ||
173 | strFile.append(QLatin1String(".qif")); | ||||
197 | m_qlineeditFile->setText(strFile); | 174 | m_qlineeditFile->setText(strFile); | ||
198 | } | 175 | } | ||
199 | 176 | | |||
200 | MyMoneyAccount account; | 177 | MyMoneyAccount account; | ||
201 | if (!accountId.isEmpty()) { | 178 | if (!accountId.isEmpty()) { | ||
202 | MyMoneyFile* file = MyMoneyFile::instance(); | 179 | MyMoneyFile* file = MyMoneyFile::instance(); | ||
203 | account = file->account(accountId); | 180 | account = file->account(accountId); | ||
204 | if (m_lastAccount != accountId) { | 181 | if (m_lastAccount != accountId) { | ||
Show All 23 Lines | |||||
228 | m_qbuttonOk->setEnabled(okEnabled); | 205 | m_qbuttonOk->setEnabled(okEnabled); | ||
229 | } | 206 | } | ||
230 | 207 | | |||
231 | void KExportDlg::loadAccounts() | 208 | void KExportDlg::loadAccounts() | ||
232 | { | 209 | { | ||
233 | auto filterProxyModel = new AccountNamesFilterProxyModel(this); | 210 | auto filterProxyModel = new AccountNamesFilterProxyModel(this); | ||
234 | filterProxyModel->addAccountGroup(QVector<MyMoneyAccount::_accountTypeE> {MyMoneyAccount::Asset, MyMoneyAccount::Liability}); | 211 | filterProxyModel->addAccountGroup(QVector<MyMoneyAccount::_accountTypeE> {MyMoneyAccount::Asset, MyMoneyAccount::Liability}); | ||
235 | auto const model = Models::instance()->accountsModel(); | 212 | auto const model = Models::instance()->accountsModel(); | ||
213 | model->load(); | ||||
236 | filterProxyModel->init(model, model->getColumns()); | 214 | filterProxyModel->init(model, model->getColumns()); | ||
237 | filterProxyModel->sort(AccountsModel::Account); | 215 | filterProxyModel->sort(AccountsModel::Account); | ||
238 | m_accountComboBox->setModel(filterProxyModel); | 216 | m_accountComboBox->setModel(filterProxyModel); | ||
239 | } | 217 | } | ||
240 | 218 | | |||
241 | QString KExportDlg::accountId() const | 219 | QString KExportDlg::accountId() const | ||
242 | { | 220 | { | ||
243 | return m_lastAccount; | 221 | return m_lastAccount; | ||
244 | } | 222 | } |