summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
authorzautrix <zautrix>2004-10-23 06:49:54 (UTC)
committer zautrix <zautrix>2004-10-23 06:49:54 (UTC)
commit65989e4ab454f228fb6cd2fa532145ed54366701 (patch) (side-by-side diff)
treea93a8cd6ef806dd5b6c38e8792a6e007b9e5e413 /kabc/plugins
parent0f0dc54f0edc8c4ec5b320118c82fa5150591fed (diff)
downloadkdepimpi-65989e4ab454f228fb6cd2fa532145ed54366701.zip
kdepimpi-65989e4ab454f228fb6cd2fa532145ed54366701.tar.gz
kdepimpi-65989e4ab454f228fb6cd2fa532145ed54366701.tar.bz2
statusmessage added topwm.fixed initialization problem.changed sring in translation
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp2
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.h2
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp2
-rw-r--r--kabc/plugins/qtopia/resourceqtopiaconfig.cpp3
4 files changed, 0 insertions, 9 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index 106596f..39d366b 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -1,170 +1,168 @@
/*
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$
*/
//US
#include "kglobal.h"
#include "klocale.h"
#include "qtopiaconverter.h"
#include <qfile.h>
#include <qdir.h>
#include <qtextstream.h>
//#include <.h>
-//#include <qpe/categories.h>
#include <libkdepim/ksyncprofile.h>
-//US #include <qpe/categoryselect.h>
using namespace KABC;
QtopiaConverter::QtopiaConverter()
{
m_edit = 0;
}
QtopiaConverter::~QtopiaConverter()
{
deinit();
}
bool QtopiaConverter::init()
{
QString fn = QDir::homeDirPath() +"/Settings/Categories.xml";
m_edit = new CategoryEdit( fn);
return true;
}
void QtopiaConverter::deinit()
{
if (m_edit)
{
delete m_edit;
m_edit = 0;
}
}
QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app )
{
startover:
QStringList dummy;
QValueList<OpieCategories>::ConstIterator catIt;
QValueList<OpieCategories> categories = m_edit->categories();
bool found = false;
for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) {
/* skip empty category name */
if ( (*listIt).isEmpty() ) continue;
found = false;
for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
/*
* We currently do not take app into account
* if name matches and the id isn't already in dummy we'll add it
*/
if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name
found= true;
dummy << (*catIt).id();
}
}
/* if not found and the category is not empty
*
* generate a new category and start over again
* ugly goto to reiterate
*/
if ( !found && !(*listIt).isEmpty() ){
m_edit->addCategory( app, (*listIt) ); // generate a new category
goto startover;
}
}
return dummy.join(";");
}
// FROM TT timeconversion.cpp GPLed
QDate QtopiaConverter::fromString( const QString &datestr )
{
if (datestr.isEmpty() )
return QDate();
int monthPos = datestr.find('.');
int yearPos = datestr.find('.', monthPos+1 );
if ( monthPos == -1 || yearPos == -1 ) {
return QDate();
}
int d = datestr.left( monthPos ).toInt();
int m = datestr.mid( monthPos+1, yearPos - monthPos - 1 ).toInt();
int y = datestr.mid( yearPos+1 ).toInt();
QDate date ( y,m,d );
return date;
}
QDate QtopiaConverter::dateFromString( const QString& s )
{
QDate date;
if ( s.isEmpty() )
return date;
// Be backward compatible to old Opie format:
// Try to load old format. If it fails, try new ISO-Format!
date = fromString ( s );
if ( date.isValid() )
return date;
// Read ISO-Format (YYYYMMDD)
int year = s.mid(0, 4).toInt();
int month = s.mid(4,2).toInt();
int day = s.mid(6,2).toInt();
// do some quick sanity checking
if ( year < 1900 || year > 3000 )
return date;
if ( month < 0 || month > 12 )
return date;
if ( day < 0 || day > 31 )
return date;
date.setYMD( year, month, day );
if ( !date.isValid() )
return QDate();
return date;
}
QString QtopiaConverter::dateToString( const QDate &d )
{
if ( d.isNull() || !d.isValid() )
return QString::null;
diff --git a/kabc/plugins/qtopia/qtopiaconverter.h b/kabc/plugins/qtopia/qtopiaconverter.h
index d318ded..cb5b433 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.h
+++ b/kabc/plugins/qtopia/qtopiaconverter.h
@@ -1,132 +1,130 @@
/*
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 KABC_QTOPIACONVERTER_H
#define KABC_QTOPIACONVERTER_H
#include <qstring.h>
#include "addressee.h"
-//#include <qpe/pim/contact.h>
-//#include <qpe/quuid.h>
#include <xml/qdom.h>
class Categories;
namespace KABC {
class OpieCategories {
public:
//friend class KSync::OpieSocket;
friend bool operator== ( const OpieCategories &a, const OpieCategories &b );
OpieCategories();
OpieCategories(const QString &id, const QString &name, const QString &app );
OpieCategories(const OpieCategories & );
~OpieCategories() {};
OpieCategories &operator=(const OpieCategories & );
QString id()const;
QString name()const;
QString app()const;
private:
QString m_name;
QString m_app;
QString m_id;
};
class CategoryEdit {
public:
CategoryEdit();
CategoryEdit(const QString &fileName);
~CategoryEdit();
void save(const QString&) const;
int addCategory( const QString &name, int id = 0 );
int addCategory(const QString &appName, const QString &name, int id = 0);
void parse( const QString &fileName );
QString categoryById(const QString &id, const QString &app )const;
QStringList categoriesByIds( const QStringList& ids, const QString& app );
void clear();
QValueList<OpieCategories> categories()const { return m_categories; };
private:
/**
* this function will be used internally to update the kde categories...
*/
void updateKDE( const QString& app, const QStringList& categories );
QMap<int, bool> ids; // from tt Qtopia::UidGen
QValueList<OpieCategories> m_categories;
};
class QtopiaConverter
{
public:
/**
* Constructor.
*/
QtopiaConverter();
/**
* Destructor.
*/
virtual ~QtopiaConverter();
bool init();
void deinit();
/**
* Converts a vcard string to an addressee.
*
* @param contact The qtopia contact.
* @param addr The addressee.
*/
bool qtopiaToAddressee( const QDomElement& el, Addressee &adr );
/**
* Converts an addressee to a vcard string.
*
* @param addr The addressee.
* @param contact The qtopia contact.
*/
bool addresseeToQtopia( const Addressee &ab, QTextStream *stream );
private:
QString categoriesToNumber( const QStringList &list, const QString &app );
QString escape( const QString& s){ return s;};
CategoryEdit *m_edit;
QDate fromString( const QString& );
QDate dateFromString( const QString& );
QString dateToString( const QDate& );
};
}
#endif
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 4ee3c3c..95fa541 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -1,175 +1,173 @@
/*
This file is part of libkabc.
Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qfileinfo.h>
#include <qregexp.h>
//US #include <qtimer.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
//US #include <ksavefile.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
-#include <qpe/pim/addressbookaccess.h>
-
#include "resourceqtopiaconfig.h"
#include "stdaddressbook.h"
#include "qtopiaconverter.h"
#include "resourceqtopia.h"
using namespace KABC;
extern "C"
{
void *init_microkabc_qtopia()
{
return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>();
}
}
ResourceQtopia::ResourceQtopia( const KConfig *config )
: Resource( config ), mConverter (0)
{
// we can not choose the filename. Therefore use the default to display
QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
init( fileName );
}
ResourceQtopia::ResourceQtopia( const QString &fileName )
: Resource( 0 )
{
init( fileName );
}
void ResourceQtopia::init( const QString &fileName )
{
#ifdef _USE_DIRWATCH_
connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
#endif
setFileName( fileName );
}
ResourceQtopia::~ResourceQtopia()
{
if (mConverter != 0)
delete mConverter;
}
void ResourceQtopia::writeConfig( KConfig *config )
{
Resource::writeConfig( config );
}
Ticket *ResourceQtopia::requestSaveTicket()
{
kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
if ( !addressBook() ) return 0;
if ( !lock( fileName() ) ) {
kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
<< fileName() << "'" << endl;
return 0;
}
return createTicket( this );
}
bool ResourceQtopia::doOpen()
{
qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
if (mConverter == 0)
{
mConverter = new QtopiaConverter();
bool res = mConverter->init();
if ( !res )
{
QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
qDebug(msg);
return false;
}
}
return true;
}
void ResourceQtopia::doClose()
{
qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
// it seems so, that deletion of access deletes backend as well
//delete backend;
return;
}
bool ResourceQtopia::load()
{
QFile file( fileName() );
if ( !file.open(IO_ReadOnly ) ) {
return false;
}
QDomDocument doc("mydocument" );
if ( !doc.setContent( &file ) ) {
file.close();
return false;
}
bool res;
QDomElement docElem = doc.documentElement( );
QDomNode n = docElem.firstChild();
while ( !n.isNull() ) {
QDomElement e = n.toElement();
if ( !e.isNull() ) {
if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) {
QDomNode no = e.firstChild();
while ( !no.isNull() ) {
QDomElement el = no.toElement();
if ( !el.isNull() ) {
KABC::Addressee addressee;
res = mConverter->qtopiaToAddressee( el, addressee );
if ( !addressee.isEmpty() && res )
diff --git a/kabc/plugins/qtopia/resourceqtopiaconfig.cpp b/kabc/plugins/qtopia/resourceqtopiaconfig.cpp
index b2310c4..0505d0b 100644
--- a/kabc/plugins/qtopia/resourceqtopiaconfig.cpp
+++ b/kabc/plugins/qtopia/resourceqtopiaconfig.cpp
@@ -1,110 +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 "resourceqtopia.h"
-//US #include <qpe/qpeapplication.h>
-
-//US #include "stdaddressbook.h"
#include "resourceqtopiaconfig.h"
using namespace KABC;
ResourceQtopiaConfig::ResourceQtopiaConfig( QWidget* parent, const char* name )
: ConfigWidget( parent, name )
{
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 );
}
void ResourceQtopiaConfig::loadSettings( KRES::Resource *res )
{
//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
ResourceQtopia *resource = (ResourceQtopia*)( res );
if ( !resource ) {
kdDebug(5700) << "ResourceQtopiaConfig::loadSettings(): cast failed" << endl;
return;
}
mFileNameEdit->setURL( resource->fileName() );
if ( mFileNameEdit->url().isEmpty() )
mFileNameEdit->setURL( QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml" );
//US Qtopia resources are ReadOnly by definition
emit setPersistentReadOnly( true );
//US we can not choose the filename for the qtopia backend => make it readonly.
mFileNameEdit->setEnabled( false );
}
void ResourceQtopiaConfig::saveSettings( KRES::Resource *res )
{
//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
ResourceQtopia *resource = (ResourceQtopia*)( res );
if ( !resource ) {
kdDebug(5700) << "ResourceQtopiaConfig::saveSettings(): cast failed" << endl;
return;
}
resource->setFileName( mFileNameEdit->url() );
}
void ResourceQtopiaConfig::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"