-rw-r--r-- | kabc/field.cpp | 8 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 16 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.cpp | 11 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.h | 3 |
4 files changed, 20 insertions, 18 deletions
diff --git a/kabc/field.cpp b/kabc/field.cpp index bc2e176..e27970e 100644 --- a/kabc/field.cpp +++ b/kabc/field.cpp @@ -168,196 +168,196 @@ QString Field::label() return Addressee::businessPhoneLabel(); case FieldImpl::MobilePhone: return Addressee::mobilePhoneLabel(); case FieldImpl::HomeFax: return Addressee::homeFaxLabel(); case FieldImpl::BusinessFax: return Addressee::businessFaxLabel(); case FieldImpl::CarPhone: return Addressee::carPhoneLabel(); case FieldImpl::Isdn: return Addressee::isdnLabel(); case FieldImpl::Pager: return Addressee::pagerLabel(); case FieldImpl::Email: return Addressee::emailLabel(); case FieldImpl::Mailer: return Addressee::mailerLabel(); case FieldImpl::Title: return Addressee::titleLabel(); case FieldImpl::Role: return Addressee::roleLabel(); case FieldImpl::Organization: return Addressee::organizationLabel(); case FieldImpl::Note: return Addressee::noteLabel(); case FieldImpl::Url: return Addressee::urlLabel(); case FieldImpl::Resource: return Addressee::resourceLabel(); case FieldImpl::CustomField: return mImpl->label(); default: return i18n("Unknown Field"); } } int Field::category() { return mImpl->category(); } QString Field::categoryLabel( int category ) { switch ( category ) { case All: return i18n("All"); case Frequent: return i18n("Frequent"); case Address: return i18n("Address"); case Email: return i18n("Email"); case Personal: return i18n("Personal"); case Organization: return i18n("Organization"); case CustomCategory: return i18n("Custom"); default: return i18n("Undefined"); } } QString Field::value( const KABC::Addressee &a ) { switch ( mImpl->fieldId() ) { case FieldImpl::FormattedName: return a.formattedName(); case FieldImpl::FamilyName: return a.familyName(); case FieldImpl::GivenName: return a.givenName(); case FieldImpl::AdditionalName: return a.additionalName(); case FieldImpl::Prefix: return a.prefix(); case FieldImpl::Suffix: return a.suffix(); case FieldImpl::NickName: return a.nickName(); case FieldImpl::Mailer: return a.mailer(); case FieldImpl::Title: return a.title(); case FieldImpl::Role: return a.role(); case FieldImpl::Organization: return a.organization(); case FieldImpl::Note: return a.note(); case FieldImpl::Email: return a.preferredEmail(); case FieldImpl::Birthday: if ( a.birthday().isValid() ) { //the generated code had the following format: return a.birthday().date().toString( Qt::ISODate ); // But Qt::IsoDate was not specified. - QString _oldFormat = KGlobal::locale()->dateFormat(); - KGlobal::locale()->setDateFormat("%Y-%m-%d"); // = Qt::ISODate - QString dt = KGlobal::locale()->formatDate(a.birthday().date(), false); - KGlobal::locale()->setDateFormat(_oldFormat); +// QString _oldFormat = KGlobal::locale()->dateFormat(); +// KGlobal::locale()->setDateFormat("%Y-%m-%d"); // = Qt::ISODate + QString dt = KGlobal::locale()->formatDate(a.birthday().date(), false, KLocale::ISODate); +// KGlobal::locale()->setDateFormat(_oldFormat); return dt; } else return QString::null; case FieldImpl::Url: return a.url().prettyURL(); //US case FieldImpl::Resource: return a.resource()->resourceName(); case FieldImpl::HomePhone: return a.phoneNumber( PhoneNumber::Home ).number(); case FieldImpl::BusinessPhone: return a.phoneNumber( PhoneNumber::Work ).number(); case FieldImpl::MobilePhone: return a.phoneNumber( PhoneNumber::Cell ).number(); case FieldImpl::HomeFax: return a.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ).number(); case FieldImpl::BusinessFax: return a.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ).number(); case FieldImpl::CarPhone: return a.phoneNumber( PhoneNumber::Car ).number(); case FieldImpl::Isdn: return a.phoneNumber( PhoneNumber::Isdn ).number(); case FieldImpl::Pager: return a.phoneNumber( PhoneNumber::Pager ).number(); case FieldImpl::HomeAddressStreet: return a.address( Address::Home ).street(); case FieldImpl::HomeAddressLocality: return a.address( Address::Home ).locality(); case FieldImpl::HomeAddressRegion: return a.address( Address::Home ).region(); case FieldImpl::HomeAddressPostalCode: return a.address( Address::Home ).postalCode(); case FieldImpl::HomeAddressCountry: return a.address( Address::Home ).country(); case FieldImpl::BusinessAddressStreet: return a.address( Address::Work ).street(); case FieldImpl::BusinessAddressLocality: return a.address( Address::Work ).locality(); case FieldImpl::BusinessAddressRegion: return a.address( Address::Work ).region(); case FieldImpl::BusinessAddressPostalCode: return a.address( Address::Work ).postalCode(); case FieldImpl::BusinessAddressCountry: return a.address( Address::Work ).country(); case FieldImpl::CustomField: return a.custom( mImpl->app(), mImpl->key() ); default: return QString::null; } } bool Field::setValue( KABC::Addressee &a, const QString &value ) { switch ( mImpl->fieldId() ) { case FieldImpl::FormattedName: a.setFormattedName( value ); return true; case FieldImpl::FamilyName: a.setFamilyName( value ); return true; case FieldImpl::GivenName: a.setGivenName( value ); return true; case FieldImpl::AdditionalName: a.setAdditionalName( value ); return true; case FieldImpl::Prefix: a.setPrefix( value ); return true; case FieldImpl::Suffix: a.setSuffix( value ); return true; case FieldImpl::NickName: a.setNickName( value ); return true; case FieldImpl::Mailer: a.setMailer( value ); return true; case FieldImpl::Title: a.setTitle( value ); return true; case FieldImpl::Role: a.setRole( value ); return true; case FieldImpl::Organization: a.setOrganization( value ); return true; case FieldImpl::Note: a.setNote( value ); return true; case FieldImpl::Birthday: //US //the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? { diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 3b2a6b7..a7d271f 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp @@ -4,296 +4,306 @@ 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> //US #include "formatfactory.h" //US #include <qpe/qpeapplication.h> #include <opie/ocontactaccess.h> #include <opie/ocontactaccessbackend_xml.h> #include "resource.h" #include "resourceopieconfig.h" #include "stdaddressbook.h" #include "opieconverter.h" #include "resourceopie.h" using namespace KABC; extern "C" { void *init_microkabc_opie() { return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); } } ResourceOpie::ResourceOpie( const KConfig *config ) : Resource( config ), mConverter (0) { QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; KConfig *cfg = (KConfig *)config; if ( cfg ) { fileName = cfg->readEntry( "FileName", fileName ); } // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); init( fileName ); } ResourceOpie::ResourceOpie( const QString &fileName ) : Resource( 0 ) { // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); init( fileName ); } void ResourceOpie::init( const QString &fileName ) { /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); */ //US opie addressbook is always readonly - setReadOnly( true ); +//US setReadOnly( true ); setFileName( fileName ); } ResourceOpie::~ResourceOpie() { if (mConverter != 0) delete mConverter; } void ResourceOpie::writeConfig( KConfig *config ) { //US opie addressbook is always readonly - setReadOnly( true ); +//US setReadOnly( true ); Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceOpie::requestSaveTicket() { kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; if ( !addressBook() ) return 0; if ( !lock( mFileName ) ) { kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" << mFileName << "'" << endl; return 0; } return createTicket( this ); } bool ResourceOpie::doOpen() { // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); /*US QFile file( mFileName ); if ( !file.exists() ) { // try to create the file bool ok = file.open( IO_WriteOnly ); if ( ok ) file.close(); return ok; } else { if ( !file.open( IO_ReadWrite ) ) return false; if ( file.size() == 0 ) { file.close(); return true; } //US bool ok = mFormat->checkFormat( &file ); bool ok = true; file.close(); return ok; } */ qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); return true; } void ResourceOpie::doClose() { // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); } bool ResourceOpie::load() { // qDebug("ResourceOpie::load() %s", mFileName.latin1()); kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); if ( !access ) { qDebug("Unable to load file() %s", mFileName.latin1()); addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); return false; } access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available + bool res = false; if (mConverter == 0) + { mConverter = new OpieConverter(); + res = mConverter->init(); + if ( !res ) + { + qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); + addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) ); + delete access; + return false; + } + } OContactAccess::List::Iterator it; OContactAccess::List allList = access->allRecords(); - bool res = false; for ( it = allList.begin(); it != allList.end(); ++it ) { OContact c = (*it); KABC::Addressee addressee; res = mConverter->opieToAddressee( c, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } // qDebug("found %s", c.fullName().latin1()); } delete access; // it seems so, that deletion of access deletes backend as well //delete backend; return true; } bool ResourceOpie::save( Ticket *ticket ) { qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); /*US qDebug("ResourceOpie::save %s", mFileName.latin1()); kdDebug(5700) << "ResourceOpie::save()" << endl; // create backup file QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); */ /*US we use a simpler method to create a backupfile (void) KSaveFile::backupFile( mFileName, QString::null ,extension ); KSaveFile saveFile( mFileName ); bool ok = false; if ( saveFile.status() == 0 && saveFile.file() ) { mFormat->saveAll( addressBook(), this, saveFile.file() ); ok = saveFile.close(); } */ /*US //US ToDo: write backupfile QFile info; info.setName( mFileName ); bool ok = info.open( IO_WriteOnly ); if ( ok ) { //US mFormat->saveAll( addressBook(), this, &info ); info.close(); ok = true; } else { } if ( !ok ) addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); delete ticket; unlock( mFileName ); return ok; qDebug("ResourceOpie::save has to be changed"); */ return true; } bool ResourceOpie::lock( const QString &fileName ) { qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); /*US // qDebug("ResourceOpie::lock() %s", fileName.latin1()); kdDebug(5700) << "ResourceOpie::lock()" << endl; QString fn = fileName; //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp("/"), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; diff --git a/kabc/plugins/opie/resourceopieconfig.cpp b/kabc/plugins/opie/resourceopieconfig.cpp index f4cc4f9..eef9cc9 100644 --- a/kabc/plugins/opie/resourceopieconfig.cpp +++ b/kabc/plugins/opie/resourceopieconfig.cpp @@ -1,112 +1,107 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qlabel.h> #include <qlayout.h> #include <kdebug.h> #include <klocale.h> #include <kstandarddirs.h> #include <kdialog.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include "resourceopie.h" //US #include <qpe/qpeapplication.h> //US #include "stdaddressbook.h" #include "resourceopieconfig.h" using namespace KABC; ResourceOpieConfig::ResourceOpieConfig( QWidget* parent, const char* name ) : ConfigWidget( parent, name ) { //qDebug("ResourceFileConfig::ResourceFileConfig"); QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0, KDialog::spacingHint() ); QLabel *label = new QLabel( i18n( "Location:" ), this ); mFileNameEdit = new KURLRequester( this ); connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), SLOT( checkFilePermissions( const QString & ) ) ); mainLayout->addWidget( label, 0, 0 ); mainLayout->addWidget( mFileNameEdit, 0, 1 ); - -//US mInEditMode = false; -} -/*US -void ResourceOpieConfig::setEditMode( bool value ) -{ - mInEditMode = value; } -*/ void ResourceOpieConfig::loadSettings( KRES::Resource *res ) { //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); ResourceOpie *resource = (ResourceOpie*)( res ); if ( !resource ) { kdDebug(5700) << "ResourceOpieConfig::loadSettings(): cast failed" << endl; return; } mFileNameEdit->setURL( resource->fileName() ); if ( mFileNameEdit->url().isEmpty() ) mFileNameEdit->setURL( QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml" ); + + //US Opie resources are ReadOnly by definition + emit setPersistentReadOnly( true ); } void ResourceOpieConfig::saveSettings( KRES::Resource *res ) { //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); ResourceOpie *resource = (ResourceOpie*)( res ); if ( !resource ) { kdDebug(5700) << "ResourceOpieConfig::saveSettings(): cast failed" << endl; return; } resource->setFileName( mFileNameEdit->url() ); } void ResourceOpieConfig::checkFilePermissions( const QString& fileName ) { // If file exist but is not writeable... /*US if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); */ } //US #include "resourceopieconfig.moc" diff --git a/kabc/plugins/opie/resourceopieconfig.h b/kabc/plugins/opie/resourceopieconfig.h index 533b7f4..8cc192c 100644 --- a/kabc/plugins/opie/resourceopieconfig.h +++ b/kabc/plugins/opie/resourceopieconfig.h @@ -1,61 +1,58 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef RESOURCEOPIECONFIG_H #define RESOURCEOPIECONFIG_H #include <kurlrequester.h> #include <kresources/configwidget.h> namespace KABC { class ResourceOpieConfig : public KRES::ConfigWidget { Q_OBJECT public: ResourceOpieConfig( QWidget* parent = 0, const char* name = 0 ); -//US void setEditMode( bool value ); - public slots: void loadSettings( KRES::Resource *resource ); void saveSettings( KRES::Resource *resource ); protected slots: void checkFilePermissions( const QString& fileName ); private: KURLRequester* mFileNameEdit; -//US bool mInEditMode; }; } #endif |