From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kabc/Makefile.am | 5 + kabc/README | 1 + kabc/frontend/Makefile.am | 10 + kabc/frontend/main.cpp | 20 + kabc/frontend/mainWindow.ui | 1409 ++++++++++++++++++++ kabc/frontend/mainWindow.ui.h | 658 +++++++++ kabc/kabc2mutt/Makefile.am | 13 + kabc/kabc2mutt/README | 19 + kabc/kabc2mutt/kabc2mutt.cpp | 160 +++ kabc/kabc2mutt/kabc2mutt.h | 56 + kabc/kabc2mutt/main.cpp | 80 ++ kabc/kabcdistlistupdater/Makefile.am | 12 + kabc/kabcdistlistupdater/kabcdistlistupdater.cpp | 95 ++ .../kabcdistlistupdater.desktop | 21 + 14 files changed, 2559 insertions(+) create mode 100644 kabc/Makefile.am create mode 100644 kabc/README create mode 100644 kabc/frontend/Makefile.am create mode 100644 kabc/frontend/main.cpp create mode 100644 kabc/frontend/mainWindow.ui create mode 100644 kabc/frontend/mainWindow.ui.h create mode 100644 kabc/kabc2mutt/Makefile.am create mode 100644 kabc/kabc2mutt/README create mode 100644 kabc/kabc2mutt/kabc2mutt.cpp create mode 100644 kabc/kabc2mutt/kabc2mutt.h create mode 100644 kabc/kabc2mutt/main.cpp create mode 100644 kabc/kabcdistlistupdater/Makefile.am create mode 100644 kabc/kabcdistlistupdater/kabcdistlistupdater.cpp create mode 100644 kabc/kabcdistlistupdater/kabcdistlistupdater.desktop (limited to 'kabc') diff --git a/kabc/Makefile.am b/kabc/Makefile.am new file mode 100644 index 000000000..252d071ae --- /dev/null +++ b/kabc/Makefile.am @@ -0,0 +1,5 @@ +if compile_newdistrlists +KABCDISTLISTUPDATER=kabcdistlistupdater +endif + +SUBDIRS = kabc2mutt $(KABCDISTLISTUPDATER) diff --git a/kabc/README b/kabc/README new file mode 100644 index 000000000..96fcd6fe5 --- /dev/null +++ b/kabc/README @@ -0,0 +1 @@ +This directory contains test code for kabc. diff --git a/kabc/frontend/Makefile.am b/kabc/frontend/Makefile.am new file mode 100644 index 000000000..c7a413fcc --- /dev/null +++ b/kabc/frontend/Makefile.am @@ -0,0 +1,10 @@ +INCLUDES = -I$(includedir)/kabc $(all_includes) + +METASOURCES = AUTO + +bin_PROGRAMS = kabcfrontend + +kabcfrontend_LDFLAGS = $(all_libraries) $(KDE_RPATH) +kabcfrontend_LDADD = -lkabc $(LIB_KDECORE) +kabcfrontend_SOURCES = main.cpp mainWindow.ui + diff --git a/kabc/frontend/main.cpp b/kabc/frontend/main.cpp new file mode 100644 index 000000000..797c9198a --- /dev/null +++ b/kabc/frontend/main.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include + +#include "mainWindow.h" + +int main( int argc, char ** argv ) +{ + KAboutData aboutData("testkabc",I18N_NOOP("TestKabc"),"0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + + KApplication app; + + MainWindow *w = new MainWindow; + w->show(); + app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); + return app.exec(); +} diff --git a/kabc/frontend/mainWindow.ui b/kabc/frontend/mainWindow.ui new file mode 100644 index 000000000..be9996c55 --- /dev/null +++ b/kabc/frontend/mainWindow.ui @@ -0,0 +1,1409 @@ + +MainWindow + + + MainWindow + + + + 0 + 0 + 570 + 534 + + + + KABC Frontend + + + + unnamed + + + + + Name + + + true + + + true + + + + + UID + + + true + + + true + + + + mAddresseeList + + + + 7 + 7 + 1 + 0 + + + + StyledPanel + + + Sunken + + + AllColumns + + + + + TabWidget2 + + + + 7 + 7 + 2 + 0 + + + + Top + + + Rounded + + + + tab + + + &General + + + + unnamed + + + 11 + + + 6 + + + + mNameEdit + + + + + TextLabel1 + + + Name: + + + + + TextLabel1_2 + + + URL: + + + + + mUrlEdit + + + + + mAdditionalNameEdit + + + + + mSuffixEdit + + + + + mGivenNameEdit + + + + + mPrefixEdit + + + + + mFamilyNameEdit + + + + + mFormattedNameEdit + + + + + mNickNameEdit + + + + + TextLabel7 + + + Nickname: + + + + + TextLabel5 + + + Honorific suffixes: + + + + + TextLabel3_2 + + + Family name: + + + + + TextLabel4 + + + Additional names: + + + + + TextLabel6 + + + Given name: + + + + + TextLabel1_3 + + + Honorific prefixes: + + + + + TextLabel8 + + + Formatted name: + + + + + TextLabel15 + + + Sort string: + + + + + mSortStringEdit + + + + + TextLabel11 + + + Role: + + + + + TextLabel12 + + + Organization: + + + + + TextLabel10 + + + Title: + + + + + mTitleEdit + + + + + mRoleEdit + + + + + mOrganizationEdit + + + + + Spacer1 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + tab + + + Phone && &Mail + + + + unnamed + + + + GroupBox1 + + + &Phone + + + + unnamed + + + 11 + + + 6 + + + + TextLabel2_3 + + + Id: + + + + + mPhoneIdCombo + + + + + PushButton3 + + + Remove + + + + + PushButton4 + + + New + + + + + mPhoneNumberEdit + + + + + TextLabel1_5 + + + Number: + + + + + ButtonGroup2 + + + Type + + + + unnamed + + + 11 + + + 6 + + + + mPhoneWorkCheck + + + Work + + + + + mPhonePrefCheck + + + Pref + + + + + mPhoneHomeCheck + + + Home + + + + + mPhoneCellCheck + + + Cell + + + + + mPhoneFaxCheck + + + Fax + + + + + mPhoneBbsCheck + + + BBS + + + + + mPhoneCarCheck + + + Car + + + + + mPhoneVideoCheck + + + Video + + + + + mPhoneIsdnCheck + + + ISDN + + + + + mPhoneVoiceCheck + + + Voice + + + + + mPhonePcsCheck + + + PCS + + + + + mPhoneModemCheck + + + Modem + + + + + mPhonePagerCheck + + + Pager + + + + + mPhoneMsgCheck + + + Msg + + + + + + + + + GroupBox2 + + + Ema&il + + + + unnamed + + + 11 + + + 6 + + + + PushButton7 + + + &New + + + + + PushButton5 + + + &Edit + + + + + PushButton6 + + + &Remove + + + + + Spacer2 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + Address + + + true + + + true + + + + mEmailListView + + + AllColumns + + + + + + + + + tab + + + A&ddress + + + + unnamed + + + + TextLabel16 + + + Id: + + + + + TextLabel1_4 + + + Post office box: + + + + + TextLabel2_2 + + + Extended: + + + + + TextLabel3_3 + + + Street: + + + + + TextLabel4_2 + + + Locality: + + + + + mAddressPostOfficeBoxEdit + + + + + mAddressExtendedEdit + + + + + mAddressStreetEdit + + + + + mAddressLocalityEdit + + + + + mAddressRegionEdit + + + + + TextLabel5_2 + + + Region: + + + + + TextLabel7_2 + + + Country: + + + + + TextLabel6_2 + + + Postal code: + + + + + mAddressLabelEdit + + + + + TextLabel13 + + + Label: + + + + + mAddressPostalCodeEdit + + + + + mAddressCountryEdit + + + + + ButtonGroup1 + + + Type + + + + unnamed + + + 11 + + + 6 + + + + mAddressDomCheck + + + Dom + + + + + mAddressIntlCheck + + + Intl + + + + + mAddressParcelCheck + + + Parcel + + + + + mAddressPostalCheck + + + Postal + + + + + mAddressHomeCheck + + + Home + + + + + mAddressPrefCheck + + + Pref + + + + + mAddressWorkCheck + + + Work + + + + + + + PushButton1 + + + &New + + + + + PushButton2 + + + &Remove + + + + + mAddressIdCombo + + + + + + + tab + + + &Special + + + + unnamed + + + 11 + + + 6 + + + + mNoteEdit + + + + + TextLabel14 + + + Note: + + + + + GroupBox2_2 + + + Categories + + + + unnamed + + + 11 + + + 6 + + + + + Name + + + true + + + true + + + + mCategoryListView + + + AllColumns + + + + + Spacer2_2 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + PushButton6_2 + + + &Remove + + + + + PushButton5_2 + + + &Edit + + + + + PushButton7_2 + + + &New + + + + + + + + + tab + + + &Custom + + + + unnamed + + + 11 + + + 6 + + + + GroupBox2_2_2 + + + Custom Entries + + + + unnamed + + + 11 + + + 6 + + + + + App + + + true + + + true + + + + + Name + + + true + + + true + + + + + Value + + + true + + + true + + + + mCustomListView + + + AllColumns + + + + + PushButton7_2_2 + + + &New + + + + + PushButton5_2_2 + + + &Edit + + + + + PushButton6_2_2 + + + &Remove + + + + + Spacer2_2_2 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + + + + + menubar + + + + + + + + + + + + + + + + + Toolbar_3 + + + Toolbar_3 + + + + + + + + + open + + + image0 + + + Action + + + &Open + + + Open Address Book + + + + + save + + + image1 + + + Action + + + &Save + + + Save Address Book + + + + + addressee_new + + + Action + + + &New + + + New Addressee + + + + + addressee_remove + + + Action + + + &Remove + + + Remove Addressee + + + + + dump + + + Dump + + + &Dump + + + Dump Addressbook + + + + + open_std + + + Open Standard Addressbook + + + Open Standard &Addressbook + + + + + + 789cad92cf0ac2300cc6ef7d8ab0dc866c6eb231101f41f12888873673e8610a3a0f22bebbfdb3d6ced583e09742f3f54792429bc6b0592f214ed9b5e3dd91800efc02717d6bdbfb76b778b028cf41ae12b268c2a2040856e7d35ee528739c6a294bca56b32a33b656960a2aa950962bdb48192aac6d1add36a87f1094d2fb2731a7a856b81b7e23e8886dee0143900b2ed0c9bb1b0aeec580f880ff548343bd6b10c9534f42c0cd19013b670cfa9a003024047a1200b6463d898b5a87fe4e4928a2e79cbd00444d9e3f + + + 789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523232520022330543251d2e253d856405bffcbc54105b19c856360003103711c4b530b63084709340dc64d364a36453103705ca35837093c1dc9424b31430570f2b00cb2863015099c444e5242400e49026930c1446372d3919a607c8275206610fed641291fd9f8822830688925146350e9b0c6e17d0500614dd7aa830052c93a2870d2ad55a7301002caeaa93 + + + + + mAddresseeList + selectionChanged(QListViewItem*) + MainWindow + updateAddressee(QListViewItem*) + + + save + activated() + MainWindow + fileSave() + + + open + activated() + MainWindow + fileOpen() + + + addressee_remove + activated() + MainWindow + removeEntry() + + + addressee_new + activated() + MainWindow + newEntry() + + + PushButton1 + clicked() + MainWindow + newAddress() + + + PushButton2 + pressed() + MainWindow + removeAddress() + + + mAddressIdCombo + activated(int) + MainWindow + updateAddress(int) + + + dump + activated() + MainWindow + dumpAddressBook() + + + PushButton3 + clicked() + MainWindow + removePhoneNumber() + + + PushButton4 + clicked() + MainWindow + newPhoneNumber() + + + PushButton5 + clicked() + MainWindow + editEmail() + + + PushButton7 + clicked() + MainWindow + newEmail() + + + PushButton6 + clicked() + MainWindow + removeEmail() + + + mPhoneIdCombo + activated(int) + MainWindow + updatePhone(int) + + + PushButton7_2 + clicked() + MainWindow + newCategory() + + + PushButton5_2 + clicked() + MainWindow + editCategory() + + + PushButton6_2 + clicked() + MainWindow + removeCategory() + + + PushButton7_2_2 + clicked() + MainWindow + newCustom() + + + PushButton5_2_2 + clicked() + MainWindow + editCustom() + + + PushButton6_2_2 + clicked() + MainWindow + removeCustom() + + + open_std + activated() + MainWindow + fileOpenStd() + + + + mAddresseeList + TabWidget2 + mNameEdit + mUrlEdit + mFormattedNameEdit + mPrefixEdit + mGivenNameEdit + mAdditionalNameEdit + mFamilyNameEdit + mSuffixEdit + mNickNameEdit + mSortStringEdit + mTitleEdit + mRoleEdit + mOrganizationEdit + mEmailListView + PushButton7 + PushButton5 + PushButton6 + mPhoneIdCombo + PushButton3 + PushButton4 + mPhoneNumberEdit + mPhoneFaxCheck + mPhoneCarCheck + mPhoneIsdnCheck + mPhoneVoiceCheck + mPhoneHomeCheck + mPhoneCellCheck + mPhonePcsCheck + mPhoneModemCheck + mPhoneWorkCheck + mPhoneVideoCheck + mPhonePagerCheck + mPhoneMsgCheck + mPhonePrefCheck + mPhoneBbsCheck + mAddressIdCombo + PushButton2 + PushButton1 + mAddressPrefCheck + mAddressHomeCheck + mAddressParcelCheck + mAddressDomCheck + mAddressWorkCheck + mAddressPostalCheck + mAddressIntlCheck + mAddressPostOfficeBoxEdit + mAddressExtendedEdit + mAddressStreetEdit + mAddressLocalityEdit + mAddressRegionEdit + mAddressPostalCodeEdit + mAddressCountryEdit + mAddressLabelEdit + mCategoryListView + PushButton7_2 + PushButton5_2 + PushButton6_2 + mNoteEdit + mCustomListView + PushButton7_2_2 + PushButton5_2_2 + PushButton6_2_2 + + + resourcefile.h + addressbook.h + mainWindow.ui.h + + + class AddresseeItem + + + KABC::ResourceFile *mResourceFile + AddresseeItem *mCurrentItem + KABC::AddressBook *mAddressBook + QString mCurrentAddress + QString mCurrentPhone + + + init() + destroy() + fileSave() + fileOpen() + loadAddressBook( const QString & fileName ) + updateAddressee( QListViewItem * item ) + readAddressee( const KABC::Addressee & a ) + writeAddressee( const KABC::Addressee & addressee ) + newEntry() + removeEntry() + updateAddress( int id ) + writeAddress( const KABC::Address & address ) + writeAddress( const QString & id ) + readAddress( const KABC::Address & a ) + readAddress( const QString & id ) + updatePhone( int id ) + writePhone( const KABC::PhoneNumber & phoneNumber ) + writePhone( const QString & id ) + readPhone( const KABC::PhoneNumber & p ) + readPhone( const QString & id ) + newAddress() + removeAddress() + dumpAddressBook() + newEmail() + editEmail() + removeEmail() + newPhoneNumber() + removePhoneNumber() + newCategory() + editCategory() + removeCategory() + editCustom() + newCustom() + removeCustom() + addressBookChanged() + addressBookLocked() + addressBookUnlocked() + fileOpenStd() + + + diff --git a/kabc/frontend/mainWindow.ui.h b/kabc/frontend/mainWindow.ui.h new file mode 100644 index 000000000..e6a024743 --- /dev/null +++ b/kabc/frontend/mainWindow.ui.h @@ -0,0 +1,658 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use Qt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ + +#include +#include +#include + +#include +#include + +#include + +using namespace KABC; + +class AddresseeItem : public QListViewItem +{ + public: + AddresseeItem( QListView *parent, const Addressee &a ) : + QListViewItem( parent, a.realName(), a.uid() ), mAddressee( a ) {} + + void setAddressee( const Addressee &a ) { mAddressee = a; } + Addressee &addressee() { return mAddressee; } + + private: + Addressee mAddressee; +}; + +void MainWindow::init() +{ + mAddressBook = KABC::StdAddressBook::self( true ); + + mCurrentItem = 0; + + mEmailListView->header()->hide(); + mCategoryListView->header()->hide(); + + connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), + SLOT( addressBookChanged() ) ); + connect( mAddressBook, SIGNAL( addressBookLocked( AddressBook * ) ), + SLOT( addressBookLocked() ) ); + connect( mAddressBook, SIGNAL( addressBookUnlocked( AddressBook * ) ), + SLOT( addressBookUnlocked() ) ); +} + +void MainWindow::destroy() +{ + delete mAddressBook; +} + +void MainWindow::fileSave() +{ + updateAddressee( mAddresseeList->selectedItem() ); + + StdAddressBook::save(); +} + +void MainWindow::fileOpen() +{ + QString fileName = QFileDialog::getOpenFileName(); + + loadAddressBook( fileName ); +} + +void MainWindow::loadAddressBook( const QString &fileName ) +{ + kdDebug() << "loadAddressBook(): '" << fileName << "'" << endl; + + mAddresseeList->clear(); + mCurrentItem = 0; + mCurrentAddress = QString::null; + readAddressee( Addressee() ); + + KABC::AddressBook::Iterator it; + for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { + new AddresseeItem( mAddresseeList, (*it) ); + } +} + +void MainWindow::updateAddressee( QListViewItem *item ) +{ + AddresseeItem *addresseeItem = dynamic_cast( item ); + if ( !addresseeItem ) return; + + if (mCurrentItem ) { + writeAddress( mCurrentAddress ); + writePhone( mCurrentPhone ); + Addressee a = writeAddressee( mCurrentItem->addressee() ); + mCurrentItem->setAddressee( a ); + mAddressBook->insertAddressee( a ); + } + mCurrentItem = addresseeItem; + + readAddressee( addresseeItem->addressee() ); + updateAddress( mAddressIdCombo->currentItem() ); + updatePhone( mPhoneIdCombo->currentItem() ); +} + + +void MainWindow::readAddressee( const KABC::Addressee &a ) +{ + kdDebug() << "MainWindow::readAddressee(): " << a.name() << endl; + + mNameEdit->setText( a.name() ); + mUrlEdit->setText( a.url().url() ); + mAdditionalNameEdit->setText( a.additionalName() ); + mSuffixEdit->setText( a.suffix() ); + mGivenNameEdit->setText( a.givenName() ); + mPrefixEdit->setText( a.prefix() ); + mFamilyNameEdit->setText( a.familyName() ); + mFormattedNameEdit->setText( a.formattedName() ); + mNickNameEdit->setText( a.nickName() ); + mSortStringEdit->setText( a.sortString() ); + mTitleEdit->setText( a.title() ); + mRoleEdit->setText( a.role() ); + mOrganizationEdit->setText( a.organization() ); + mNoteEdit->setText( a.note() ); +// mLabelEdit->setText( a.label() ); + + mEmailListView->clear(); + QStringList emails = a.emails(); + QStringList::ConstIterator it3; + for( it3 = emails.begin(); it3 != emails.end(); ++it3 ) { + new QListViewItem( mEmailListView, *it3 ); + } + + mCategoryListView->clear(); + QStringList categories = a.categories(); + QStringList::ConstIterator it4; + for( it4 = categories.begin(); it4 != categories.end(); ++it4 ) { + new QListViewItem( mCategoryListView, *it4 ); + } + + mCustomListView->clear(); + QStringList customs = a.customs(); + QStringList::ConstIterator it5; + for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { + int posDash = (*it5).find( "-" ); + int posColon = (*it5).find( ":" ); + + QString app = (*it5).left( posDash ); + QString cname = (*it5).mid( posDash + 1, posColon - posDash - 1 ); + QString value = (*it5).mid( posColon + 1 ); + + new QListViewItem( mCustomListView, app, cname, value ); + } + + Address::List addresses = a.addresses(); + mAddressIdCombo->clear(); + Address::List::ConstIterator it; + for( it = addresses.begin(); it != addresses.end(); ++it ) { + mAddressIdCombo->insertItem( (*it).id() ); + } + if ( mAddressIdCombo->count() > 0 ) mCurrentAddress = mAddressIdCombo->currentText(); + else mCurrentAddress = QString::null; + readAddress( mCurrentAddress ); + + mPhoneIdCombo->clear(); + PhoneNumber::List pl = a.phoneNumbers(); + PhoneNumber::List::ConstIterator it2; + for( it2 = pl.begin(); it2 != pl.end(); ++it2) { + mPhoneIdCombo->insertItem( (*it2).id() ); + } + if ( mPhoneIdCombo->count() > 0 ) mCurrentPhone = mPhoneIdCombo->currentText(); + readPhone( mCurrentPhone ); +} + +KABC::Addressee MainWindow::writeAddressee( const KABC::Addressee &addressee ) +{ + Addressee a( addressee ); + a.setName( mNameEdit->text() ); + if ( !mUrlEdit->text().isEmpty() ) { + a.setUrl( KURL( mUrlEdit->text() ) ); + } + + a.setAdditionalName( mAdditionalNameEdit->text() ); + a.setSuffix( mSuffixEdit->text() ); + a.setGivenName( mGivenNameEdit->text() ); + a.setPrefix( mPrefixEdit->text() ); + a.setFamilyName( mFamilyNameEdit->text() ); + a.setFormattedName( mFormattedNameEdit->text() ); + a.setNickName( mNickNameEdit->text() ); + a.setSortString( mSortStringEdit->text() ); + a.setTitle( mTitleEdit->text() ); + a.setRole( mRoleEdit->text() ); + a.setOrganization( mOrganizationEdit->text() ); + a.setNote( mNoteEdit->text() ); +// a.setLabel( mLabelEdit->text() ); + + kdDebug() << "MainWindow::writeAddressee()" << endl; + a.dump(); + + return a; +} + +void MainWindow::newEntry() +{ + bool ok = false; + QString name = KInputDialog::getText( i18n("New Address Book Entry"), + i18n("Please enter name:"), + QString::null, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + Addressee a; + a.setName( name ); + mAddressBook->insertAddressee( a ); + + new AddresseeItem( mAddresseeList, a ); +} + +void MainWindow::removeEntry() +{ + AddresseeItem *item = dynamic_cast(mAddresseeList->selectedItem()); + if ( item ) { + mAddressBook->removeAddressee( item->addressee() ); + delete item; + mCurrentItem = 0; + } +} + + +void MainWindow::updateAddress( int id ) +{ + if( !mCurrentItem ) return; + + writeAddress( mCurrentAddress ); + if ( mAddressIdCombo->count() > 0 ) { + mCurrentAddress = mAddressIdCombo->text( id ); + } else { + mCurrentAddress = QString::null; + } + readAddress( mCurrentAddress ); +} + +KABC::Address MainWindow::writeAddress( const KABC::Address &address ) +{ + Address a( address ); + + a.setPostOfficeBox( mAddressPostOfficeBoxEdit->text() ); + a.setExtended( mAddressExtendedEdit->text() ); + a.setStreet( mAddressStreetEdit->text() ); + a.setLocality( mAddressLocalityEdit->text() ); + a.setRegion( mAddressRegionEdit->text() ); + a.setLabel( mAddressLabelEdit->text() ); + a.setPostalCode( mAddressPostalCodeEdit->text() ); + a.setCountry( mAddressCountryEdit->text() ); + + int type = 0; + if ( mAddressDomCheck->isChecked() ) type |= Address::Dom; + if ( mAddressIntlCheck->isChecked() ) type |= Address::Intl; + if ( mAddressParcelCheck->isChecked() ) type |= Address::Parcel; + if ( mAddressPostalCheck->isChecked() ) type |= Address::Postal; + if ( mAddressHomeCheck->isChecked() ) type |= Address::Home; + if ( mAddressPrefCheck->isChecked() ) type |= Address::Pref; + if ( mAddressWorkCheck->isChecked() ) type |= Address::Work; + a.setType( type ); + + return a; +} + +void MainWindow::writeAddress( const QString &id ) +{ + if ( !mCurrentItem ) return; + + if ( id.isEmpty() ) return; + + Address address; + address.setId( id ); + address = writeAddress( address ); + + mCurrentItem->addressee().insertAddress( address ); +} + +void MainWindow::readAddress( const KABC::Address &a ) +{ + mAddressPostOfficeBoxEdit->setText( a.postOfficeBox() ); + mAddressExtendedEdit->setText( a.extended() ); + mAddressStreetEdit->setText( a.street() ); + mAddressLocalityEdit->setText( a.locality() ); + mAddressRegionEdit->setText( a.region() ); + mAddressLabelEdit->setText( a.label() ); + mAddressPostalCodeEdit->setText( a.postalCode() ); + mAddressCountryEdit->setText( a.country() ); + + int type = a.type(); + if ( type & Address::Dom ) mAddressDomCheck->setChecked( true ); + else mAddressDomCheck->setChecked( false ); + if ( type & Address::Intl ) mAddressIntlCheck->setChecked( true ); + else mAddressIntlCheck->setChecked( false ); + if ( type & Address::Parcel ) mAddressParcelCheck->setChecked( true ); + else mAddressParcelCheck->setChecked( false ); + if ( type & Address::Postal ) mAddressPostalCheck->setChecked( true ); + else mAddressPostalCheck->setChecked( false ); + if ( type & Address::Home ) mAddressHomeCheck->setChecked( true ); + else mAddressHomeCheck->setChecked( false ); + if ( type & Address::Pref ) mAddressPrefCheck->setChecked( true ); + else mAddressPrefCheck->setChecked( false ); + if ( type & Address::Work ) mAddressWorkCheck->setChecked( true ); + else mAddressWorkCheck->setChecked( false ); +} + +void MainWindow::readAddress( const QString &id ) +{ + if ( !mCurrentItem || id.isEmpty() ) { + readAddress( Address() ); + return; + } + + Address address = mCurrentItem->addressee().findAddress( id ); + readAddress( address ); +} + +void MainWindow::updatePhone( int id ) +{ + if( !mCurrentItem ) return; + + writePhone( mCurrentPhone ); + if ( mPhoneIdCombo->count() > 0 ) { + mCurrentPhone = mPhoneIdCombo->text( id ); + } else { + mCurrentPhone = QString::null; + } + readPhone( mCurrentPhone ); +} + +KABC::PhoneNumber MainWindow::writePhone( const KABC::PhoneNumber &phoneNumber ) +{ + PhoneNumber p( phoneNumber ); + + p.setNumber( mPhoneNumberEdit->text() ); + + int type = 0; + if ( mPhoneMsgCheck->isChecked() ) type |= PhoneNumber::Msg; + if ( mPhoneVoiceCheck->isChecked() ) type |= PhoneNumber::Voice; + if ( mPhoneFaxCheck->isChecked() ) type |= PhoneNumber::Fax; + if ( mPhoneCellCheck->isChecked() ) type |= PhoneNumber::Cell; + if ( mPhoneHomeCheck->isChecked() ) type |= PhoneNumber::Home; + if ( mPhonePrefCheck->isChecked() ) type |= PhoneNumber::Pref; + if ( mPhoneWorkCheck->isChecked() ) type |= PhoneNumber::Work; + if ( mPhoneVideoCheck->isChecked() ) type |= PhoneNumber::Video; + if ( mPhoneBbsCheck->isChecked() ) type |= PhoneNumber::Bbs; + if ( mPhoneModemCheck->isChecked() ) type |= PhoneNumber::Modem; + if ( mPhoneCarCheck->isChecked() ) type |= PhoneNumber::Car; + if ( mPhoneIsdnCheck->isChecked() ) type |= PhoneNumber::Isdn; + if ( mPhonePcsCheck->isChecked() ) type |= PhoneNumber::Pcs; + if ( mPhonePagerCheck->isChecked() ) type |= PhoneNumber::Pager; + p.setType( type ); + + return p; +} + +void MainWindow::writePhone( const QString &id ) +{ + if ( !mCurrentItem ) return; + + if ( id.isEmpty() ) return; + + PhoneNumber p; + p.setId( id ); + p = writePhone( p ); + + mCurrentItem->addressee().insertPhoneNumber( p ); +} + +void MainWindow::readPhone( const KABC::PhoneNumber &p ) +{ + mPhoneNumberEdit->setText( p.number() ); + + int type = p.type(); + if ( type & PhoneNumber::Msg ) mPhoneMsgCheck->setChecked( true ); + else mPhoneMsgCheck->setChecked( false ); + if ( type & PhoneNumber::Voice ) mPhoneVoiceCheck->setChecked( true ); + else mPhoneVoiceCheck->setChecked( false ); + if ( type & PhoneNumber::Fax ) mPhoneFaxCheck->setChecked( true ); + else mPhoneFaxCheck->setChecked( false ); + if ( type & PhoneNumber::Cell ) mPhoneCellCheck->setChecked( true ); + else mPhoneCellCheck->setChecked( false ); + if ( type & PhoneNumber::Home ) mPhoneHomeCheck->setChecked( true ); + else mPhoneHomeCheck->setChecked( false ); + if ( type & PhoneNumber::Pref ) mPhonePrefCheck->setChecked( true ); + else mPhonePrefCheck->setChecked( false ); + if ( type & PhoneNumber::Work ) mPhoneWorkCheck->setChecked( true ); + else mPhoneWorkCheck->setChecked( false ); + if ( type & PhoneNumber::Video ) mPhoneVideoCheck->setChecked( true ); + else mPhoneVideoCheck->setChecked( false ); + if ( type & PhoneNumber::Bbs ) mPhoneBbsCheck->setChecked( true ); + else mPhoneBbsCheck->setChecked( false ); + if ( type & PhoneNumber::Modem ) mPhoneModemCheck->setChecked( true ); + else mPhoneModemCheck->setChecked( false ); + if ( type & PhoneNumber::Car ) mPhoneCarCheck->setChecked( true ); + else mPhoneCarCheck->setChecked( false ); + if ( type & PhoneNumber::Isdn ) mPhoneIsdnCheck->setChecked( true ); + else mPhoneIsdnCheck->setChecked( false ); + if ( type & PhoneNumber::Pcs ) mPhonePcsCheck->setChecked( true ); + else mPhonePcsCheck->setChecked( false ); + if ( type & PhoneNumber::Pager ) mPhonePagerCheck->setChecked( true ); + else mPhonePagerCheck->setChecked( false ); +} + +void MainWindow::readPhone( const QString &id ) +{ + if ( !mCurrentItem || id.isEmpty() ) { + readPhone( PhoneNumber() ); + return; + } + + PhoneNumber p = mCurrentItem->addressee().findPhoneNumber( id ); + readPhone( p ); +} + + +void MainWindow::newAddress() +{ + if( !mCurrentItem ) return; + + Address address; + mCurrentItem->addressee().insertAddress( address ); + + mAddressIdCombo->insertItem( address.id() ); +} + +void MainWindow::removeAddress() +{ + if ( !mCurrentItem ) return; + + QString id = mAddressIdCombo->currentText(); + if ( id.isEmpty() ) return; + + Address address; + address.setId( id ); + mCurrentItem->addressee().removeAddress( address ); + + readAddressee( mCurrentItem->addressee() ); +} + + +void MainWindow::dumpAddressBook() +{ + mAddressBook->dump(); +} + + +void MainWindow::newEmail() +{ + if ( !mCurrentItem ) return; + + bool ok = false; + QString name = KInputDialog::getText( i18n("New Email Address"), + i18n("Please enter email address:"), + QString::null, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + new QListViewItem( mEmailListView, name ); + mCurrentItem->addressee().insertEmail( name ); +} + +void MainWindow::editEmail() +{ + if ( !mCurrentItem ) return; + + QListViewItem *item = mEmailListView->selectedItem(); + if( !item ) return; + + QString oldName = item->text( 0 ); + + bool ok = false; + QString name = KInputDialog::getText( i18n("Edit Email Address"), + i18n("Please enter new email address:"), + oldName, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + item->setText( 0, name ); + mCurrentItem->addressee().removeEmail( oldName ); + mCurrentItem->addressee().insertEmail( name ); +} + +void MainWindow::removeEmail() +{ + if ( !mCurrentItem ) return; + + QListViewItem *item = mEmailListView->selectedItem(); + if( !item ) return; + + mCurrentItem->addressee().removeEmail( item->text( 0 ) ); + delete item; +} + +void MainWindow::newPhoneNumber() +{ + if ( !mCurrentItem ) return; + + PhoneNumber p; + mCurrentItem->addressee().insertPhoneNumber( p ); + + mPhoneIdCombo->insertItem( p.id() ); +} + +void MainWindow::removePhoneNumber() +{ + if ( !mCurrentItem ) return; + + QString id = mPhoneIdCombo->currentText(); + if ( id.isEmpty() ) return; + + PhoneNumber p; + p.setId( id ); + mCurrentItem->addressee().removePhoneNumber( p ); + + readAddressee( mCurrentItem->addressee() ); +} + + +void MainWindow::newCategory() +{ + if ( !mCurrentItem ) return; + + bool ok = false; + QString name = KInputDialog::getText( i18n("New Category"), + i18n("Please enter category name:"), + QString::null, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + new QListViewItem( mCategoryListView, name ); + mCurrentItem->addressee().insertCategory( name ); +} + +void MainWindow::editCategory() +{ + if ( !mCurrentItem ) return; + + QListViewItem *item = mCategoryListView->selectedItem(); + if( !item ) return; + + QString oldName = item->text( 0 ); + + bool ok = false; + QString name = KInputDialog::getText( i18n("Edit Category"), + i18n("Please enter new category name:"), + oldName, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + item->setText( 0, name ); + mCurrentItem->addressee().removeCategory( oldName ); + mCurrentItem->addressee().insertCategory( name ); +} + +void MainWindow::removeCategory() +{ + if ( !mCurrentItem ) return; + + QListViewItem *item = mCategoryListView->selectedItem(); + if( !item ) return; + + mCurrentItem->addressee().removeCategory( item->text( 0 ) ); + delete item; +} + + +void MainWindow::editCustom() +{ + if ( !mCurrentItem ) return; + + QListViewItem *item = mCustomListView->selectedItem(); + if( !item ) return; + + QString oldName = item->text( 0 ) + "-" + item->text( 1 ) + ":" + + item->text( 2 ); + + bool ok = false; + QString name = KInputDialog::getText( i18n("New Custom Entry"), + i18n("Please enter custom entry.\n" + "Format: APP-NAME:VALUE"), + oldName, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + int posDash = name.find( "-" ); + int posColon = name.find( ":" ); + + QString app = name.left( posDash ); + QString cname = name.mid( posDash + 1, posColon - posDash - 1 ); + QString value = name.mid( posColon + 1 ); + + item->setText( 0, app ); + item->setText( 1, cname ); + item->setText( 2, value ); + + mCurrentItem->addressee().removeCustom( app, cname ); + mCurrentItem->addressee().insertCustom( app, cname, value ); +} + +void MainWindow::newCustom() +{ + if ( !mCurrentItem ) return; + + bool ok = false; + QString name = KInputDialog::getText( i18n("New Custom Entry"), + i18n("Please enter custom entry.\n" + "Format: APP-NAME:VALUE"), + QString::null, &ok, + this ); + if ( !ok || name.isEmpty() ) return; + + int posDash = name.find( "-" ); + int posColon = name.find( ":" ); + + QString app = name.left( posDash ); + QString cname = name.mid( posDash + 1, posColon - posDash - 1 ); + QString value = name.mid( posColon + 1 ); + + new QListViewItem( mCustomListView, app, cname, value ); + + mCurrentItem->addressee().insertCustom( app, cname, value ); +} + +void MainWindow::removeCustom() +{ + if ( !mCurrentItem ) return; + + QListViewItem *item = mCustomListView->selectedItem(); + if( !item ) return; + + mCurrentItem->addressee().removeCustom( item->text( 0 ), item->text( 1 ) ); + delete item; +} + +void MainWindow::addressBookChanged() +{ + QMessageBox::warning( this, i18n("Address Book Changed"), + i18n("The address book has changed on disk."), + i18n("Reload") ); + loadAddressBook( "dummy" ); +} + +void MainWindow::addressBookLocked() +{ + kdDebug() << "AddressBook locked()" << endl; +} + +void MainWindow::addressBookUnlocked() +{ + kdDebug() << "AddressBook unlocked()" << endl; +} + + +void MainWindow::fileOpenStd() +{ + loadAddressBook( StdAddressBook::fileName() ); +} diff --git a/kabc/kabc2mutt/Makefile.am b/kabc/kabc2mutt/Makefile.am new file mode 100644 index 000000000..f8a201cfd --- /dev/null +++ b/kabc/kabc2mutt/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(includedir)/kabc $(all_includes) + +METASOURCES = AUTO + +bin_PROGRAMS = kabc2mutt + +kabc2mutt_LDFLAGS = $(all_libraries) $(KDE_RPATH) +kabc2mutt_LDADD = -lkabc $(LIB_KDECORE) +kabc2mutt_SOURCES = kabc2mutt.cpp main.cpp + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kabc2mutt.pot + diff --git a/kabc/kabc2mutt/README b/kabc/kabc2mutt/README new file mode 100644 index 000000000..5d82fdfec --- /dev/null +++ b/kabc/kabc2mutt/README @@ -0,0 +1,19 @@ +KAbc2Mutt +----------- + +kabc2mutt is a small programm to make the email addresses, stored in +kaddressbook, available in mutt. +You only have to add the following line to your .muttrc + + source "kabc2mutt |" + +You can also configure mutt to query kabc2mutt when typing a substring +of an email address (see the docu for query_command). +To do this, add the following line to your .muttrc + + set query_command = "kabc2mutt --query '%s' --format query" + +Have fun with it + +Ciao, +Tobias diff --git a/kabc/kabc2mutt/kabc2mutt.cpp b/kabc/kabc2mutt/kabc2mutt.cpp new file mode 100644 index 000000000..84f4626bb --- /dev/null +++ b/kabc/kabc2mutt/kabc2mutt.cpp @@ -0,0 +1,160 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include + +#include + +#include "kabc2mutt.h" + +static std::ostream & operator<< ( std::ostream &os, const QString &s ); + +KABC2Mutt::KABC2Mutt( QObject *parent, const char *name ) + : QObject( parent, name ), mFormat( Aliases ), + mIgnoreCase( false ), mAllAddresses( false ), + mAlternateKeyFormat( false ), + mAddressBook( 0 ) +{ +} + +void KABC2Mutt::run() +{ + mAddressBook = KABC::StdAddressBook::self( true ); + KABC::StdAddressBook::setAutomaticSave( false ); + + connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), + this, SLOT( loadingFinished() ) ); +} + +void KABC2Mutt::loadingFinished() +{ + // print addressees + KABC::AddressBook::ConstIterator iaddr; + for ( iaddr = mAddressBook->begin(); iaddr != mAddressBook->end(); ++iaddr ) { + const QString name = (*iaddr).givenName() + ' ' + (*iaddr).familyName(); + if ( !mQuery.isEmpty() ) { + bool match = (name.find(mQuery, 0, mIgnoreCase) > -1) || + ((*iaddr).preferredEmail().find( mQuery, 0, mIgnoreCase ) > -1 ); + if ( !match ) + continue; + } + + const QStringList &allAddresses = (*iaddr).emails(); + QStringList::const_iterator from, to; + bool multiple = false; + + if ( mAllAddresses ) { + // use all entries + multiple = allAddresses.size() > 1; + from = allAddresses.begin(); + to = allAddresses.end(); + } else { + // use only the first entry, the one returned by preferredEmail() + from = to = allAddresses.begin(); // start with empty list + if ( to != allAddresses.end() ) + ++to; + } + + size_t index = 0; + if ( mFormat == Aliases ) { + static const QChar space = QChar( ' ' ); + static const QChar underscore = QChar( '_' ); + + QString key; + if ( !mAlternateKeyFormat ) + key = (*iaddr).givenName().left( 3 ) + (*iaddr).familyName().left( 3 ); + else + if ( !(*iaddr).familyName().isEmpty() ) + key = (*iaddr).givenName().left( 1 ).lower() + + (*iaddr).familyName().lower().replace( space, underscore ); + else + key = (*iaddr).givenName().lower().replace( space, underscore ); + + while ( from != to ) { + std::cout << "alias " << key; + if ( index ) + std::cout << index; + std::cout << '\t' << name << " <" << (*from) << '>' << std::endl; + ++index; + ++from; + } + + if ( !(*iaddr).nickName().isEmpty() ) { + std::cout << "alias " + << (*iaddr).nickName().lower().replace( space, underscore ) + << '\t' << name << " <" + << (*iaddr).preferredEmail() << '>' << std::endl; + } + } else { + while ( from != to ) { + std::cout << (*from) << '\t' << name; + if ( multiple ) { + if ( index ) + std::cout << "\t#" << index; + else + std::cout << '\t' << i18n( "preferred" ); + ++index; + } + std::cout << std::endl; + ++from; + } + } + } + + // print all distribution lists + KABC::DistributionListManager manager( mAddressBook ); + manager.load(); + + QStringList dists = manager.listNames(); + for ( QStringList::Iterator iaddr = dists.begin(); iaddr != dists.end(); ++iaddr ) { + KABC::DistributionList *list = manager.list( *iaddr ); + if ( list ) { + if ( !mQuery.isEmpty() ) { + bool match = ((*iaddr).find(mQuery) > -1); + if ( !match ) + continue; + } + + QStringList emails = list->emails(); + if ( emails.isEmpty() ) + continue; + + if ( mFormat == Aliases ) { + std::cout << "alias " << (*iaddr).replace( QRegExp( " " ), "_" ) + << '\t' << emails.join( "," ) << std::endl; + } else { + std::cout << emails.join( "," ) << '\t' << (*iaddr) << '\t' << std::endl; + } + } + } + + kapp->quit(); +} + +static std::ostream & operator<< ( std::ostream &os, const QString &s ) +{ + os << s.local8Bit().data(); + return os; +} + +#include "kabc2mutt.moc" diff --git a/kabc/kabc2mutt/kabc2mutt.h b/kabc/kabc2mutt/kabc2mutt.h new file mode 100644 index 000000000..65f4d06f4 --- /dev/null +++ b/kabc/kabc2mutt/kabc2mutt.h @@ -0,0 +1,56 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef KABC2MUTT_H +#define KABC2MUTT_H + +#include + +class KABC2Mutt : public QObject +{ + Q_OBJECT + + public: + + enum Format { Aliases, Query }; + + KABC2Mutt( QObject *parent, const char *name = 0 ); + + void setQuery( const QString &query ) { mQuery = query; } + void setFormat( Format format ) { mFormat = format; } + void setIgnoreCase( bool ignoreCase ) { mIgnoreCase = ignoreCase; } + void setAllAddresses( bool allAddresses ) { mAllAddresses = allAddresses; } + void setAlternateKeyFormat( bool alternateKeyFormat ) { mAlternateKeyFormat = alternateKeyFormat; } + + void run(); + + private slots: + void loadingFinished(); + + private: + QString mQuery; + Format mFormat; + bool mIgnoreCase; + bool mAllAddresses; + bool mAlternateKeyFormat; + + KABC::AddressBook *mAddressBook; +}; + +#endif diff --git a/kabc/kabc2mutt/main.cpp b/kabc/kabc2mutt/main.cpp new file mode 100644 index 000000000..8da8f5491 --- /dev/null +++ b/kabc/kabc2mutt/main.cpp @@ -0,0 +1,80 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include + +#include "kabc2mutt.h" + +static const char version[] = "0.2"; +static const char appName[] = "kabc2mutt"; +static const char programName[] = I18N_NOOP( "kabc2mutt" ); +static const char description[] = I18N_NOOP( "kabc - mutt converter" ); + +static KCmdLineOptions k2moptions[] = +{ + { "query ", I18N_NOOP( "Only show contacts where name or address matches " ), 0 }, + { "format ", I18N_NOOP( "Default format is 'alias'. 'query' returns emailname, as needed by mutt's query_command" ), "alias" }, + { "alternate-key-format", I18N_NOOP( "Default key format is 'JohDoe', this option turns it into 'jdoe'" ), 0 }, + { "ignore-case", I18N_NOOP( "Make queries case insensitive" ), 0 }, + { "all-addresses", I18N_NOOP( "Return all mail addresses, not just the preferred one" ), 0}, + KCmdLineLastOption +}; + + +int main( int argc, char **argv ) +{ + KApplication::disableAutoDcopRegistration(); + KCmdLineArgs::init( argc, argv, appName, programName, description, version ); + KCmdLineArgs::addCmdLineOptions( k2moptions ); + + KApplication app( false, false ); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + KABC2Mutt *object = new KABC2Mutt( 0 ); + + // Handle --format option + object->setFormat( (args->getOption("format") == "query") ? KABC2Mutt::Query : KABC2Mutt::Aliases ); + + // Handle --alternate-key-format option + object->setAlternateKeyFormat( args->isSet( "alternate-key-format" ) ); + + // Handle --all-addresses option + object->setAllAddresses( args->isSet( "all-addresses" ) ); + + // Handle --query option + const QString subString = QString::fromLocal8Bit( args->getOption( "query" ) ); + if ( !subString.isEmpty() ) { + // Mutt wants a first line with some status message on it + // See http://mutt.org/doc/manual/manual-4.html#ss4.5 + std::cout << i18n( "Searching KDE addressbook" ).latin1() << std::endl; + } + object->setQuery( subString ); + + // Handle --ignore-case option + object->setIgnoreCase( !args->isSet( "ignore-case" ) ); + + object->run(); + + return app.exec(); +} diff --git a/kabc/kabcdistlistupdater/Makefile.am b/kabc/kabcdistlistupdater/Makefile.am new file mode 100644 index 000000000..6de9a5c01 --- /dev/null +++ b/kabc/kabcdistlistupdater/Makefile.am @@ -0,0 +1,12 @@ +INCLUDES = -I$(includedir)/kabc -I$(top_srcdir) $(all_includes) + +METASOURCES = AUTO + +bin_PROGRAMS = kabcdistlistupdater + +kabcdistlistupdater_LDFLAGS = $(all_libraries) $(KDE_RPATH) +kabcdistlistupdater_LDADD = $(LIB_KABC) $(top_builddir)/libkdepim/libkdepim.la +kabcdistlistupdater_SOURCES = kabcdistlistupdater.cpp + +autostart_DATA = kabcdistlistupdater.desktop +autostartdir = $(datadir)/autostart diff --git a/kabc/kabcdistlistupdater/kabcdistlistupdater.cpp b/kabc/kabcdistlistupdater/kabcdistlistupdater.cpp new file mode 100644 index 000000000..012ce4d15 --- /dev/null +++ b/kabc/kabcdistlistupdater/kabcdistlistupdater.cpp @@ -0,0 +1,95 @@ +/* + This file is part of libkabc. + Copyright (c) 2008 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static const KCmdLineOptions options[] = +{ + { "disable-autostart", "Disable automatic startup on login", 0 }, + KCmdLineLastOption +}; + +void convertDistributionLists() +{ + KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); + const QMap entryMap = cfg.entryMap( "DistributionLists" ); + + if ( entryMap.isEmpty() ) // nothing to convert + return; + + QMapConstIterator it; + for ( it = entryMap.begin(); it != entryMap.end(); ++it ) { + const QString listName = it.key(); + const QStringList entries = QStringList::split( ',', it.data(), true ); + + KPIM::DistributionList distList; + distList.setUid( KApplication::randomString( 10 ) ); + distList.setName( listName ); + + if ( entries.count() > 1 ) { + for ( uint i = 0; i < entries.count(); i += 2 ) { + const QString uid = entries[ i ]; + const QString preferredEMail = entries[ i + 1 ]; + + distList.insertEntry( uid, preferredEMail ); + } + } + + KABC::StdAddressBook::self()->insertAddressee( distList ); + } + + KABC::StdAddressBook::self()->save(); +} + +int main( int argc, char **argv ) +{ + KApplication::disableAutoDcopRegistration(); + + KAboutData aboutData( "kabcdistlistupdater", "Converter tool for distribution lists", "0.1" ); + aboutData.addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" ); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app( false, false ); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + if ( args->isSet( "disable-autostart" ) ) { + kdDebug() << "Disable autostart." << endl; + + KConfig *config = app.config(); + config->setGroup( "Startup" ); + config->writeEntry( "EnableAutostart", false ); + } + + convertDistributionLists(); +} + diff --git a/kabc/kabcdistlistupdater/kabcdistlistupdater.desktop b/kabc/kabcdistlistupdater/kabcdistlistupdater.desktop new file mode 100644 index 000000000..3bea0152a --- /dev/null +++ b/kabc/kabcdistlistupdater/kabcdistlistupdater.desktop @@ -0,0 +1,21 @@ +# KDE Config File +[Desktop Entry] +Name=kabcdistlistupdater +Name[nl]=kabcdistlijstbijwerker +Exec=kabcdistlistupdater --disable-autostart +Icon=misc +Type=Application +Comment=Tool to update the old distribution lists to the new ones. +Comment[ca]=Eina per actualitzar les llistes de distribució antigues a les noves. +Comment[es]=Herramienta para actualizar las antiguas listas de distribución al nuevo formato. +Comment[et]=Tööriist vanade postiloendite uuendamiseks uue vormi kohaselt. +Comment[nds]=Warktüüch, dat ole Verdeellisten to niege opfrischt +Comment[nl]=Hulpmiddel om de oude distributielijsten bij te werken tot de nieuwe. +Comment[sk]=Nástroj na aktualizáciu starých ditribučných zoznamov na nové. +Comment[sr]=Алат за ажурирање старих дистрибуционих листи новима. +Comment[sr@Latn]=Алат за ажурирање старих дистрибуционих листи новима. +Comment[sv]=Verktyg för att uppdatera gamla distributionslistor till nya. +Terminal=false +NoDisplay=true +X-KDE-autostart-condition=kabcdistlistupdaterrc:Startup:EnableAutostart:true +OnlyShowIn=KDE; -- cgit v1.2.1