52
52
#include " texttemplate.h"
53
53
#include " htmlview.h"
54
54
#include " addressselectordialog.h"
55
+ #include " addressprovider.h"
55
56
57
+ #include " kcontacts/vcardconverter.h"
56
58
57
59
// ################################################################################
58
60
@@ -169,40 +171,53 @@ void PrefsDialog::whoIsMeTab()
169
171
topFrame->setIcon (QIcon::fromTheme ( " user-identity" ) );
170
172
171
173
QVBoxLayout *vboxLay = new QVBoxLayout;
172
- // vboxLay->setSpacing( spacingHint() );
173
174
174
- QLabel *label;
175
- label = new QLabel (i18n (" Select the identity of the sending entity of documents. That's <b>your companies</b> address." ));
175
+ QLabel *label = new QLabel (i18n (" Select the identity of the sending entity of documents. That's <b>your companies</b> address." ));
176
176
label->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed );
177
177
vboxLay->addWidget ( label );
178
178
179
- QVBoxLayout *butLay = new QVBoxLayout ;
180
- butLay-> addStretch ( 1 );
179
+ _tabWidget = new QTabWidget ;
180
+ vboxLay-> addWidget (_tabWidget );
181
181
182
+ // == Tab that displays the Addressbook widget
183
+ QWidget *w = new QWidget;
184
+ QVBoxLayout *t1Lay = new QVBoxLayout;
182
185
mIdentityView = new HtmlView;
183
- QString home = QString::fromLatin1 (qgetenv (" KRAFT_HOME" ));
184
- QString idFile = QString (" %1/reports/images/identity.png" ).arg (home);
185
- QFileInfo fi (idFile);
186
+ mIdentityView ->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
186
187
187
- if (! fi.exists () ) {
188
- QString idFile = QStandardPaths::locate (QStandardPaths::GenericDataLocation, " kraft/reports/images/identity.png" );
189
- fi.setFile (idFile);
190
- fi.refresh ();
191
-
192
- if ( fi.exists () ) {
193
- idFile = fi.path ();
194
- }
195
- } else {
196
- idFile = fi.path ();
188
+ const QString idFile = DefaultProvider::self ()->locateFile (" reports/images/identity.png" );
189
+ if ( !idFile.isEmpty () ) {
190
+ QFileInfo fi (idFile);
191
+ mIdentityView ->setBaseUrl (fi.path ());
197
192
}
198
- mIdentityView ->setBaseUrl (idFile);
199
193
200
- butLay->addWidget (mIdentityView );
194
+ t1Lay->addWidget (mIdentityView );
195
+ QHBoxLayout *butLay = new QHBoxLayout;
196
+ butLay->addStretch ( 1 );
201
197
_pbChangeIdentity = new QPushButton (i18n (" Select Identity..." ));
202
198
connect ( _pbChangeIdentity, SIGNAL (clicked ()), SLOT (slotChangeIdentity ()) );
203
199
butLay->addWidget (_pbChangeIdentity);
204
-
205
- vboxLay->addLayout ( butLay );
200
+ t1Lay->addLayout ( butLay );
201
+
202
+ w->setLayout (t1Lay);
203
+ _tabWidget->insertTab (0 , w, i18n (" From AddressBook" ));
204
+
205
+ // == Tab that displays the manual widget
206
+ QWidget *w1 = new QWidget;
207
+ ui.setupUi (w1);
208
+ _tabWidget->insertTab (1 , w1, QIcon (), i18n (" Manual Entry" ));
209
+ ui.nameLabel ->setText ( KContacts::Addressee::formattedNameLabel () );
210
+ ui.orgLabel ->setText ( KContacts::Addressee::organizationLabel ());
211
+ ui.streetLabel ->setText (KContacts::Addressee::businessAddressStreetLabel ());
212
+ ui.postCodeLabel ->setText (KContacts::Addressee::businessAddressPostalCodeLabel ());
213
+ ui.cityLabel ->setText (KContacts::Addressee::businessAddressLocalityLabel ());
214
+ ui.phoneLabel ->setText (KContacts::Addressee::businessPhoneLabel ());
215
+ ui.faxLabel ->setText (KContacts::Addressee::businessFaxLabel ());
216
+ ui.mobileLabel ->setText (KContacts::Addressee::mobilePhoneLabel ());
217
+ ui.emailLabel ->setText (KContacts::Addressee::emailLabel ());
218
+ ui.websiteLabel ->setText (KContacts::Addressee::urlLabel ());
219
+
220
+ _tabWidget->insertTab (1 , w1, i18n (" Manual Address" ));
206
221
207
222
topWidget->setLayout ( vboxLay );
208
223
@@ -213,10 +228,9 @@ void PrefsDialog::slotChangeIdentity()
213
228
AddressSelectorDialog dialog (this );
214
229
215
230
if ( dialog.exec () ) {
216
- Addressee identity = dialog.addressee ();
217
- if ( ! identity.isEmpty () ) {
218
- setMyIdentity (identity, true );
219
- emit newOwnIdentity (identity.uid (), identity);
231
+ _newIdentity = dialog.addressee ();
232
+ if ( ! _newIdentity.isEmpty () ) {
233
+ setMyIdentity (_newIdentity, true );
220
234
}
221
235
}
222
236
}
@@ -361,6 +375,58 @@ void PrefsDialog::readConfig()
361
375
mCbDefaultTaxType ->setCurrentIndex ( KraftSettings::self ()->defaultTaxType ()-1 );
362
376
}
363
377
378
+ void PrefsDialog::writeIdentity ()
379
+ {
380
+ /*
381
+ * Save either the manually added address, or the Addressbook-ID
382
+ * If the user fills in the manual form, the addressbook ID is removed.
383
+ * FIXME: The handling of the ownIdentity should be refactored to its
384
+ * own class.
385
+ */
386
+
387
+ if (_tabWidget->currentIndex () == 1 /* manually entered */ ) {
388
+ KContacts::Addressee add;
389
+ add.setFormattedName (ui.leName ->text ());
390
+ add.setOrganization (ui.leOrganization ->text ());
391
+ KContacts::Address workAddress;
392
+
393
+ workAddress.setStreet (ui.leStreet ->text ());
394
+ workAddress.setPostalCode (ui.lePostcode ->text ());
395
+ workAddress.setLocality (ui.leCity ->text ());
396
+ workAddress.setType (KContacts::Address::Work);
397
+ add.insertAddress (workAddress);
398
+
399
+ add.insertPhoneNumber (PhoneNumber (ui.lePhone ->text (), KContacts::PhoneNumber::Work));
400
+ add.insertPhoneNumber (PhoneNumber (ui.leFax ->text (), KContacts::PhoneNumber::Fax));
401
+ add.insertPhoneNumber (PhoneNumber (ui.leMobile ->text (), KContacts::PhoneNumber::Cell));
402
+ ResourceLocatorUrl resUrl;
403
+ resUrl.setUrl (QUrl (ui.leWebsite ->text ()));
404
+ add.setUrl (resUrl);
405
+ add.insertEmail (ui.leEmail ->text (), true /* prefered */ );
406
+
407
+ VCardConverter vcc;
408
+ QByteArray vcard = vcc.createVCard (add);
409
+
410
+ QString file = QStandardPaths::writableLocation ( QStandardPaths::AppDataLocation );
411
+ file += " /myidentity.vcd" ;
412
+ QFile f ( file );
413
+ if (f.open (QIODevice::WriteOnly | QIODevice::Text)) {
414
+ f.write (vcard);
415
+ f.close ();
416
+ qDebug () << " Saved own identity to " << file;
417
+
418
+ KraftSettings::self ()->setUserName ( QString::null );
419
+ KraftSettings::self ()->setUserUid ( QString::null );
420
+ KraftSettings::self ()->save ();
421
+ }
422
+ } else { /* AddressBook */
423
+ KraftSettings::self ()->setUserName ( _newIdentity.name () );
424
+ KraftSettings::self ()->setUserUid ( _newIdentity.uid () );
425
+ KraftSettings::self ()->save ();
426
+ }
427
+ emit newOwnIdentity (_newIdentity.uid (), _newIdentity);
428
+ }
429
+
364
430
void PrefsDialog::writeConfig ()
365
431
{
366
432
KraftSettings::self ()->setShowDocumentLocale ( mCbDocLocale ->isChecked () );
@@ -386,12 +452,28 @@ void PrefsDialog::accept()
386
452
mPrefsUnits ->save ();
387
453
writeTaxes ();
388
454
writeConfig ();
455
+ writeIdentity ();
389
456
QDialog::accept ();
390
457
}
391
458
392
459
#define IDENTITY_TAG (X ) QLatin1String(X)
393
460
#define QL1 (X ) QLatin1String(X)
394
461
462
+ void PrefsDialog::fillManualIdentityForm (const KContacts::Addressee& addressee)
463
+ {
464
+ ui.leName ->setText (addressee.formattedName ());
465
+ ui.leStreet ->setText (addressee.address (Address::Work).street ());
466
+ ui.leCity ->setText (addressee.address (Address::Work).locality ());
467
+ ui.lePostcode ->setText (addressee.address (Address::Work).postalCode ());
468
+
469
+ ui.leEmail ->setText (addressee.preferredEmail ());
470
+ ui.leFax ->setText (addressee.phoneNumber (PhoneNumber::Fax).number ());
471
+ ui.leOrganization ->setText (addressee.organization ());
472
+ ui.lePhone ->setText (addressee.phoneNumber (PhoneNumber::Work).number ());
473
+ ui.leMobile ->setText (addressee.phoneNumber (PhoneNumber::Cell).number ());
474
+ ui.leWebsite ->setText (addressee.url ().url ().toDisplayString ());
475
+ }
476
+
395
477
void PrefsDialog::setMyIdentity ( const KContacts::Addressee& addressee, bool backendUp )
396
478
{
397
479
// Note: This code is stolen from DocDigestDetailView::slotShowDocDetails
@@ -415,14 +497,28 @@ void PrefsDialog::setMyIdentity( const KContacts::Addressee& addressee, bool bac
415
497
tmpl.setValue (QL1 (" NO_IDENTITY_WRN" ), i18n (" <p><b>Kraft Addressbook Integration down.</b></p>"
416
498
" <p>The address book backend is not up and running.</p>"
417
499
" <p>Please check your addressbook integration setup.</p>" ));
500
+ }
501
+
502
+ if ( addressee.isEmpty () ) {
503
+ addressBookInfo = i18n (" The identity is not listed in an address book." );
504
+ tmpl.createDictionary (QL1 (" NO_IDENTITY" ));
505
+ tmpl.setValue (QL1 (" NO_IDENTITY_WRN" ), i18n (" <p><b>Kraft does not know your identity.</b></p>"
506
+ " <p>Please pick one from the address books by clicking on the Button below.</p>"
507
+ " <p>Not having an identity selected can make your documents look incomplete.</p>" ));
418
508
} else {
419
- if ( addressee.isEmpty () ) {
420
- addressBookInfo = i18n (" The identity is not listed in an address book." );
421
- tmpl.createDictionary (QL1 (" NO_IDENTITY" ));
422
- tmpl.setValue (QL1 (" NO_IDENTITY_WRN" ), i18n (" <p><b>Kraft does not know your identity.</b></p>"
423
- " <p>Please pick one from the address books by clicking on the Button below.</p>"
424
- " <p>Not having an identity selected can make your documents look incomplete.</p>" ));
509
+ const QString origin = addressee.custom ( CUSTOM_ADDRESS_MARKER );
510
+ if ( origin.isEmpty () || origin == " manual" ) {
511
+ // it is an manually added address.
512
+ fillManualIdentityForm (addressee);
513
+ _tabWidget->setTabIcon (1 , QIcon::fromTheme (" checkmark" ));
514
+ _tabWidget->setTabIcon (0 , QIcon ());
515
+ _tabWidget->setCurrentIndex (1 );
425
516
} else {
517
+ _tabWidget->setTabIcon (0 , QIcon::fromTheme (" checkmark" ));
518
+ _tabWidget->setTabIcon (1 , QIcon ());
519
+ _tabWidget->setCurrentIndex (0 );
520
+
521
+ // it is an address from the address book
426
522
addressBookInfo = i18n (" Your identity can be found in the address books." );
427
523
tmpl.createDictionary (QL1 (" IDENTITY" ));
428
524
tmpl.setValue ( QL1 (" IDENTITY" ), IDENTITY_TAG (" IDENTITY_NAME" ), addressee.realName () );
0 commit comments