locationwidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qpushbutton.h>
00027 #include <qvbox.h>
00028
00029 #include <kabc/addressbook.h>
00030 #include <kaccelmanager.h>
00031 #include <kapplication.h>
00032 #include <kcombobox.h>
00033 #include <kdebug.h>
00034 #include <kdeversion.h>
00035 #include <kdialog.h>
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038
00039 #include "core.h"
00040 #include "locationconfig.h"
00041
00042 #include "locationwidget.h"
00043
00044 class LocationFactory : public KAB::ExtensionFactory
00045 {
00046 public:
00047 KAB::ExtensionWidget *extension( KAB::Core *core, QWidget *parent, const char *name )
00048 {
00049 return new LocationWidget( core, parent, name );
00050 }
00051
00052 KAB::ConfigureWidget *configureWidget( QWidget *parent, const char *name )
00053 {
00054 return new LocationConfigWidget( 0, parent, name );
00055 }
00056
00057 bool configureWidgetAvailable() { return true; }
00058
00059 QString identifier() const
00060 {
00061 return "contact_location";
00062 }
00063 };
00064
00065 extern "C" {
00066 void *init_libkaddrbk_location()
00067 {
00068 return ( new LocationFactory );
00069 }
00070 }
00071
00072 LocationWidget::LocationWidget( KAB::Core *core, QWidget *parent, const char *name )
00073 : KAB::ExtensionWidget( core, parent, name )
00074 {
00075 QGridLayout *topLayout = new QGridLayout( this, 2, 4, KDialog::marginHint(),
00076 KDialog::spacingHint() );
00077
00078 mURLTypeCombo = new KComboBox( this );
00079 topLayout->addWidget( mURLTypeCombo, 0, 0 );
00080
00081 QLabel *label = new QLabel( i18n( "Address type:" ), this );
00082 topLayout->addWidget( label, 0, 1 );
00083
00084 mAddressTypeCombo = new KComboBox( this );
00085 label->setBuddy( mAddressTypeCombo );
00086 topLayout->addWidget( mAddressTypeCombo, 0, 2 );
00087
00088 mLoadButton = new QPushButton( i18n( "Load..." ), this );
00089 mLoadButton->setEnabled( false );
00090 connect( mLoadButton, SIGNAL( clicked() ), SLOT( loadLocationPage() ) );
00091 topLayout->addWidget( mLoadButton, 0, 3 );
00092
00093 QVBox *panel = new QVBox( this );
00094 topLayout->addMultiCellWidget( panel, 1, 1, 0, 3 );
00095
00096 KAcceleratorManager::manage( this );
00097
00098 KConfig config( "kaddressbookrc" );
00099 config.setGroup( QString( "Extensions_%1" ).arg( identifier() ) );
00100
00101 mURLTypeCombo->insertStringList( config.readListEntry( "URLs" ) );
00102 }
00103
00104 LocationWidget::~LocationWidget()
00105 {
00106 }
00107
00108 void LocationWidget::contactsSelectionChanged()
00109 {
00110 mAddressList.clear();
00111
00112 int pos = mAddressTypeCombo->currentItem();
00113 mAddressTypeCombo->clear();
00114
00115 if ( contactsSelected() ) {
00116 KABC::Addressee::List list = selectedContacts();
00117 mAddressList = list[0].addresses();
00118 }
00119
00120 KABC::Address::List::Iterator it;
00121 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
00122 mAddressTypeCombo->insertItem( (*it).typeLabel( (*it).type() ) );
00123
00124 mAddressTypeCombo->setCurrentItem( pos );
00125
00126 mLoadButton->setEnabled( mAddressList.count() > 0 );
00127 }
00128
00129 QString LocationWidget::title() const
00130 {
00131 return i18n( "Location of Contact" );
00132 }
00133
00134 QString LocationWidget::identifier() const
00135 {
00136 return "contact_location";
00137 }
00138
00139 void LocationWidget::loadLocationPage()
00140 {
00141 if ( mURLTypeCombo->count() == 0 ) {
00142 KMessageBox::sorry( this, i18n( "You have to configure the location widget first!" ) );
00143 return;
00144 }
00145
00146 KURL url ( createUrl( mAddressList[ mAddressTypeCombo->currentItem() ] ));
00147 kapp->invokeBrowser( url.url() );
00148 }
00149
00150 QString LocationWidget::createUrl( const KABC::Address &addr )
00151 {
00161
00162 KConfig config( "kaddressbookrc" );
00163 config.setGroup( QString( "Extensions_%1" ).arg( identifier() ) );
00164 QString uid = config.readEntry( "UID",
00165 QDateTime::currentDateTime().toString() );
00166
00167 QString urlTemplate = config.readEntry( mURLTypeCombo->currentText() );
00168
00169 #if KDE_VERSION >= 319
00170 return urlTemplate.replace( "%s", addr.street() ).
00171 replace( "%r", addr.region() ).
00172 replace( "%l", addr.locality() ).
00173 replace( "%z", addr.postalCode() ).
00174 replace( "%c", addr.countryToISO( addr.country() ) ).
00175 replace( "%i", uid );
00176 #else
00177 return urlTemplate.replace( "%s", addr.street() ).
00178 replace( "%r", addr.region() ).
00179 replace( "%l", addr.locality() ).
00180 replace( "%z", addr.postalCode() ).
00181 replace( "%c", "" ).
00182 replace( "%i", uid );
00183 #endif
00184 }
00185
00186 #include "locationwidget.moc"
This file is part of the documentation for kaddressbook Library Version 3.2.2.