Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/editpersonaldatadlg.cpp
Context not available. | |||||
3 | ------------------- | 3 | ------------------- | ||
---|---|---|---|---|---|
4 | copyright : (C) 2000 by Michael Edwardes | 4 | copyright : (C) 2000 by Michael Edwardes | ||
5 | email : mte@users.sourceforge.net | 5 | email : mte@users.sourceforge.net | ||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
6 | ***************************************************************************/ | 7 | ***************************************************************************/ | ||
7 | 8 | | |||
8 | /*************************************************************************** | 9 | /*************************************************************************** | ||
Context not available. | |||||
30 | // ---------------------------------------------------------------------------- | 31 | // ---------------------------------------------------------------------------- | ||
31 | // Project Includes | 32 | // Project Includes | ||
32 | #include "mymoneycontact.h" | 33 | #include "mymoneycontact.h" | ||
33 | #include "ui_editpersonaldatadlgdecl.h" | 34 | #include "ui_editpersonaldatadlg.h" | ||
34 | 35 | | |||
35 | struct EditPersonalDataDlg::Private { | 36 | class EditPersonalDataDlgPrivate | ||
36 | Private() : m_contact(0) {} | 37 | { | ||
37 | Ui::EditPersonalDataDlgDecl ui; | 38 | Q_DISABLE_COPY(EditPersonalDataDlgPrivate) | ||
38 | MyMoneyContact *m_contact; | 39 | Q_DECLARE_PUBLIC(EditPersonalDataDlg) | ||
40 | | ||||
41 | public: | ||||
42 | EditPersonalDataDlgPrivate(EditPersonalDataDlg *qq) : | ||||
43 | q_ptr(qq), | ||||
44 | ui(new Ui::EditPersonalDataDlg) | ||||
45 | { | ||||
46 | } | ||||
47 | | ||||
48 | ~EditPersonalDataDlgPrivate() | ||||
49 | { | ||||
50 | delete m_contact; | ||||
51 | delete ui; | ||||
52 | } | ||||
53 | | ||||
54 | void init(const QString& title) | ||||
55 | { | ||||
56 | Q_Q(EditPersonalDataDlg); | ||||
57 | m_contact = new MyMoneyContact(q); | ||||
58 | ui->setupUi(q); | ||||
59 | q->setModal(true); | ||||
60 | | ||||
61 | if (!title.isEmpty()) | ||||
62 | q->setWindowTitle(title); | ||||
63 | | ||||
64 | ui->kabcBtn->setEnabled(m_contact->ownerExists()); | ||||
65 | ui->userNameEdit->setFocus(); | ||||
66 | | ||||
67 | q->connect(ui->buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject); | ||||
68 | q->connect(ui->buttonBox, &QDialogButtonBox::accepted, q, &EditPersonalDataDlg::okClicked); | ||||
69 | q->connect(ui->kabcBtn, &QAbstractButton::clicked, q, &EditPersonalDataDlg::loadFromAddressBook); | ||||
70 | } | ||||
71 | | ||||
72 | EditPersonalDataDlg *q_ptr; | ||||
73 | Ui::EditPersonalDataDlg *ui; | ||||
74 | MyMoneyContact *m_contact; | ||||
75 | QString userNameText; | ||||
76 | QString userStreetText; | ||||
77 | QString userTownText; | ||||
78 | QString userCountyText; | ||||
79 | QString userPostcodeText; | ||||
80 | QString userTelephoneText; | ||||
81 | QString userEmailText; | ||||
39 | }; | 82 | }; | ||
40 | 83 | | |||
41 | EditPersonalDataDlg::EditPersonalDataDlg(QWidget *parent, const QString& title) | 84 | | ||
42 | : QDialog(parent), d(new Private) | 85 | EditPersonalDataDlg::EditPersonalDataDlg(QWidget *parent, const QString& title) : | ||
86 | QDialog(parent), | ||||
87 | d_ptr(new EditPersonalDataDlgPrivate(this)) | ||||
43 | { | 88 | { | ||
44 | d->m_contact = new MyMoneyContact(this); | 89 | Q_D(EditPersonalDataDlg); | ||
45 | d->ui.setupUi(this); | 90 | d->init(title); | ||
46 | setModal(true); | | |||
47 | init(title); | | |||
48 | } | 91 | } | ||
49 | 92 | | |||
50 | EditPersonalDataDlg::EditPersonalDataDlg(QString userName, QString userStreet, | 93 | EditPersonalDataDlg::EditPersonalDataDlg(QString userName, | ||
51 | QString userTown, QString userCounty, QString userPostcode, QString userTelephone, | 94 | QString userStreet, | ||
52 | QString userEmail, QWidget *parent, const QString& title) | 95 | QString userTown, | ||
53 | : QDialog(parent), d(new Private) | 96 | QString userCounty, | ||
97 | QString userPostcode, | ||||
98 | QString userTelephone, | ||||
99 | QString userEmail, | ||||
100 | QWidget *parent, | ||||
101 | const QString& title) : | ||||
102 | QDialog(parent), | ||||
103 | d_ptr(new EditPersonalDataDlgPrivate(this)) | ||||
54 | { | 104 | { | ||
55 | d->m_contact = new MyMoneyContact(this); | 105 | Q_D(EditPersonalDataDlg); | ||
56 | d->ui.setupUi(this); | 106 | d->init(title); | ||
57 | setModal(true); | 107 | d->ui->userNameEdit->setText(userName); | ||
58 | d->ui.userNameEdit->setText(userName); | 108 | d->ui->streetEdit->setText(userStreet); | ||
59 | d->ui.streetEdit->setText(userStreet); | 109 | d->ui->townEdit->setText(userTown); | ||
60 | d->ui.townEdit->setText(userTown); | 110 | d->ui->countyEdit->setText(userCounty); | ||
61 | d->ui.countyEdit->setText(userCounty); | 111 | d->ui->postcodeEdit->setText(userPostcode); | ||
62 | d->ui.postcodeEdit->setText(userPostcode); | 112 | d->ui->telephoneEdit->setText(userTelephone); | ||
63 | d->ui.telephoneEdit->setText(userTelephone); | 113 | d->ui->emailEdit->setText(userEmail); | ||
64 | d->ui.emailEdit->setText(userEmail); | | |||
65 | | ||||
66 | init(title); | | |||
67 | } | 114 | } | ||
68 | 115 | | |||
69 | void EditPersonalDataDlg::init(const QString& title) | 116 | QString EditPersonalDataDlg::userName() const | ||
70 | { | 117 | { | ||
71 | if (!title.isEmpty()) | 118 | Q_D(const EditPersonalDataDlg); | ||
72 | setWindowTitle(title); | 119 | return d->userNameText; | ||
120 | } | ||||
73 | 121 | | |||
74 | d->ui.kabcBtn->setEnabled(d->m_contact->ownerExists()); | 122 | QString EditPersonalDataDlg::userStreet() const | ||
75 | d->ui.userNameEdit->setFocus(); | 123 | { | ||
124 | Q_D(const EditPersonalDataDlg); | ||||
125 | return d->userStreetText; | ||||
126 | } | ||||
76 | 127 | | |||
77 | connect(d->ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | 128 | QString EditPersonalDataDlg::userTown() const | ||
78 | connect(d->ui.buttonBox, SIGNAL(accepted()), this, SLOT(okClicked())); | 129 | { | ||
79 | connect(d->ui.kabcBtn, SIGNAL(clicked()), this, SLOT(loadFromAddressBook())); | 130 | Q_D(const EditPersonalDataDlg); | ||
131 | return d->userTownText; | ||||
132 | } | ||||
133 | | ||||
134 | QString EditPersonalDataDlg::userCountry() const | ||||
135 | { | ||||
136 | Q_D(const EditPersonalDataDlg); | ||||
137 | return d->userCountyText; | ||||
138 | } | ||||
139 | | ||||
140 | QString EditPersonalDataDlg::userPostcode() const | ||||
141 | { | ||||
142 | Q_D(const EditPersonalDataDlg); | ||||
143 | return d->userPostcodeText; | ||||
144 | } | ||||
145 | | ||||
146 | QString EditPersonalDataDlg::userTelephone() const | ||||
147 | { | ||||
148 | Q_D(const EditPersonalDataDlg); | ||||
149 | return d->userTelephoneText; | ||||
150 | } | ||||
151 | | ||||
152 | QString EditPersonalDataDlg::userEmail() const | ||||
153 | { | ||||
154 | Q_D(const EditPersonalDataDlg); | ||||
155 | return d->userEmailText; | ||||
80 | } | 156 | } | ||
81 | 157 | | |||
82 | EditPersonalDataDlg::~EditPersonalDataDlg() | 158 | EditPersonalDataDlg::~EditPersonalDataDlg() | ||
83 | { | 159 | { | ||
160 | Q_D(EditPersonalDataDlg); | ||||
84 | delete d; | 161 | delete d; | ||
85 | } | 162 | } | ||
86 | 163 | | |||
87 | void EditPersonalDataDlg::okClicked() | 164 | void EditPersonalDataDlg::okClicked() | ||
88 | { | 165 | { | ||
89 | userNameText = d->ui.userNameEdit->text(); | 166 | Q_D(EditPersonalDataDlg); | ||
90 | userStreetText = d->ui.streetEdit->text(); | 167 | d->userNameText = d->ui->userNameEdit->text(); | ||
91 | userTownText = d->ui.townEdit->text(); | 168 | d->userStreetText = d->ui->streetEdit->text(); | ||
92 | userCountyText = d->ui.countyEdit->text(); | 169 | d->userTownText = d->ui->townEdit->text(); | ||
93 | userPostcodeText = d->ui.postcodeEdit->text(); | 170 | d->userCountyText = d->ui->countyEdit->text(); | ||
94 | userTelephoneText = d->ui.telephoneEdit->text(); | 171 | d->userPostcodeText = d->ui->postcodeEdit->text(); | ||
95 | userEmailText = d->ui.emailEdit->text(); | 172 | d->userTelephoneText = d->ui->telephoneEdit->text(); | ||
173 | d->userEmailText = d->ui->emailEdit->text(); | ||||
96 | 174 | | |||
97 | accept(); | 175 | accept(); | ||
98 | } | 176 | } | ||
99 | 177 | | |||
100 | void EditPersonalDataDlg::loadFromAddressBook() | 178 | void EditPersonalDataDlg::loadFromAddressBook() | ||
101 | { | 179 | { | ||
102 | d->ui.userNameEdit->setText(d->m_contact->ownerFullName()); | 180 | Q_D(EditPersonalDataDlg); | ||
103 | d->ui.emailEdit->setText(d->m_contact->ownerEmail()); | 181 | d->ui->userNameEdit->setText(d->m_contact->ownerFullName()); | ||
104 | if (d->ui.emailEdit->text().isEmpty()) { | 182 | d->ui->emailEdit->setText(d->m_contact->ownerEmail()); | ||
183 | if (d->ui->emailEdit->text().isEmpty()) { | ||||
105 | KMessageBox::sorry(this, i18n("Unable to load data, because no contact has been associated with the owner of the standard address book."), i18n("Address book import")); | 184 | KMessageBox::sorry(this, i18n("Unable to load data, because no contact has been associated with the owner of the standard address book."), i18n("Address book import")); | ||
106 | return; | 185 | return; | ||
107 | } | 186 | } | ||
108 | d->ui.kabcBtn->setEnabled(false); | 187 | d->ui->kabcBtn->setEnabled(false); | ||
109 | connect(d->m_contact, SIGNAL(contactFetched(ContactData)), this, SLOT(slotContactFetched(ContactData))); | 188 | connect(d->m_contact, &MyMoneyContact::contactFetched, this, &EditPersonalDataDlg::slotContactFetched); | ||
110 | d->m_contact->fetchContact(d->ui.emailEdit->text()); | 189 | d->m_contact->fetchContact(d->ui->emailEdit->text()); | ||
111 | } | 190 | } | ||
112 | 191 | | |||
113 | void EditPersonalDataDlg::slotContactFetched(const ContactData &identity) | 192 | void EditPersonalDataDlg::slotContactFetched(const ContactData &identity) | ||
114 | { | 193 | { | ||
115 | d->ui.telephoneEdit->setText(identity.phoneNumber); | 194 | Q_D(EditPersonalDataDlg); | ||
195 | d->ui->telephoneEdit->setText(identity.phoneNumber); | ||||
116 | QString sep; | 196 | QString sep; | ||
117 | if (!identity.country.isEmpty() && !identity.region.isEmpty()) | 197 | if (!identity.country.isEmpty() && !identity.region.isEmpty()) | ||
118 | sep = " / "; | 198 | sep = " / "; | ||
119 | d->ui.countyEdit->setText(QString("%1%2%3").arg(identity.country, sep, identity.region)); | 199 | d->ui->countyEdit->setText(QString("%1%2%3").arg(identity.country, sep, identity.region)); | ||
120 | d->ui.postcodeEdit->setText(identity.postalCode); | 200 | d->ui->postcodeEdit->setText(identity.postalCode); | ||
121 | d->ui.townEdit->setText(identity.locality); | 201 | d->ui->townEdit->setText(identity.locality); | ||
122 | d->ui.streetEdit->setText(identity.street); | 202 | d->ui->streetEdit->setText(identity.street); | ||
123 | d->ui.kabcBtn->setEnabled(true); | 203 | d->ui->kabcBtn->setEnabled(true); | ||
124 | } | 204 | } | ||
125 | 205 | | |||
Context not available. |