Commit eda66329 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add code to import calendar

parent 2eafae82
......@@ -26,6 +26,7 @@ evolutionv3/evolutionv3importdata.cpp
evolutionv3/evolutionsettings.cpp
evolutionv3/evolutioncalendar.cpp
evolutionv3/evolutionaddressbook.cpp
evolutionv3/evolutionutil.cpp
evolutionv2/evolutionv2importdata.cpp
evolutionv1/evolutionv1importdata.cpp
opera/operaimportdata.cpp
......
......@@ -16,14 +16,78 @@
*/
#include "evolutioncalendar.h"
#include "evolutionutil.h"
EvolutionCalendar::EvolutionCalendar(const QString& file,ImportWizard *parent)
#include <KDebug>
#include <QFile>
#include <QDebug>
#include <QDomDocument>
#include <QDomElement>
EvolutionCalendar::EvolutionCalendar(const QString& filename,ImportWizard *parent)
:AbstractCalendar(parent)
{
//TODO
//Read gconf file
QFile file(filename);
if ( !file.open( QIODevice::ReadOnly ) ) {
qDebug()<<" We can't open file"<<filename;
return;
}
QDomDocument doc;
if ( !EvolutionUtil::loadInDomDocument( &file, doc ) )
return;
QDomElement config = doc.documentElement();
if ( config.isNull() ) {
kDebug() << "No config found";
return;
}
for ( QDomElement e = config.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() ) {
const QString tag = e.tagName();
if ( tag == QLatin1String( "entry" ) ) {
if ( e.hasAttribute( "name" ) ) {
const QString attr = e.attribute("name");
if ( attr == QLatin1String( "sources" ) ) {
readCalendar(e);
} else {
qDebug()<<" attr unknown "<<attr;
}
}
}
}
}
EvolutionCalendar::~EvolutionCalendar()
{
}
void EvolutionCalendar::readCalendar(const QDomElement &calendar)
{
for ( QDomElement calendarConfig = calendar.firstChildElement(); !calendarConfig.isNull(); calendarConfig = calendarConfig.nextSiblingElement() ) {
if(calendarConfig.tagName() == QLatin1String("li")) {
const QDomElement stringValue = calendarConfig.firstChildElement();
extractCalendarInfo(stringValue.text());
}
}
}
void EvolutionCalendar::extractCalendarInfo(const QString& info)
{
qDebug()<<" info "<<info;
//Read QDomElement
QDomDocument cal;
if ( !EvolutionUtil::loadInDomDocument( info, cal ) )
return;
QDomElement domElement = cal.documentElement();
if ( domElement.isNull() ) {
kDebug() << "Account not found";
return;
}
for ( QDomElement e = domElement.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() ) {
const QString tag = e.tagName();
qDebug()<<" EvolutionCalendar::extractCalendarInfo tag :"<<tag;
}
}
......@@ -20,6 +20,8 @@
#include "abstractcalendar.h"
class QDomElement;
class ImportWizard;
class EvolutionCalendar : public AbstractCalendar
......@@ -27,6 +29,9 @@ class EvolutionCalendar : public AbstractCalendar
public:
explicit EvolutionCalendar(const QString &file, ImportWizard *parent);
~EvolutionCalendar();
private:
void readCalendar(const QDomElement &calendar);
void extractCalendarInfo(const QString& info);
};
#endif // EVOLUTIONCALENDAR_H
......@@ -16,6 +16,7 @@
*/
#include "evolutionsettings.h"
#include "evolutionutil.h"
#include <kpimidentities/identity.h>
......@@ -41,7 +42,7 @@ EvolutionSettings::EvolutionSettings( const QString& filename, ImportWizard *par
return;
}
QDomDocument doc;
if ( !loadInDomDocument( &file, doc ) )
if ( !EvolutionUtil::loadInDomDocument( &file, doc ) )
return;
QDomElement config = doc.documentElement();
......@@ -74,33 +75,6 @@ EvolutionSettings::~EvolutionSettings()
{
}
bool EvolutionSettings::loadInDomDocument( QFile *file, QDomDocument & doc )
{
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return false;
}
return true;
}
bool EvolutionSettings::loadInDomDocument( const QString &file, QDomDocument & doc )
{
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return false;
}
return true;
}
void EvolutionSettings::readSignatures(const QDomElement &account)
{
for ( QDomElement signatureConfig = account.firstChildElement(); !signatureConfig.isNull(); signatureConfig = signatureConfig.nextSiblingElement() ) {
......@@ -115,7 +89,7 @@ void EvolutionSettings::extractSignatureInfo( const QString&info )
{
qDebug()<<" signature info "<<info;
QDomDocument signature;
if ( !loadInDomDocument( info, signature ) )
if ( !EvolutionUtil::loadInDomDocument( info, signature ) )
return;
QDomElement domElement = signature.documentElement();
......@@ -177,7 +151,7 @@ void EvolutionSettings::extractAccountInfo(const QString& info)
qDebug()<<" info "<<info;
//Read QDomElement
QDomDocument account;
if ( !loadInDomDocument( info, account ) )
if ( !EvolutionUtil::loadInDomDocument( info, account ) )
return;
QDomElement domElement = account.documentElement();
......
......@@ -43,9 +43,6 @@ private:
QString getAuthMethod( const QString& path, bool & found);
void addAuth(QMap<QString, QVariant>& settings, const QString & argument, const QString& userName);
bool loadInDomDocument( QFile *file, QDomDocument & doc );
bool loadInDomDocument( const QString &file, QDomDocument & doc );
QMap<QString, KPIMIdentities::Signature> mMapSignature;
};
......
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, 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 "evolutionutil.h"
#include <KDebug>
#include <QDomDocument>
#include <QFile>
bool EvolutionUtil::loadInDomDocument( QFile *file, QDomDocument & doc )
{
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return false;
}
return true;
}
bool EvolutionUtil::loadInDomDocument( const QString &file, QDomDocument & doc )
{
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return false;
}
return true;
}
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, 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 EVOLUTIONUTIL_H
#define EVOLUTIONUTIL_H
#include <QString>
class QFile;
class QDomDocument;
namespace EvolutionUtil {
bool loadInDomDocument( QFile *file, QDomDocument & doc );
bool loadInDomDocument( const QString &file, QDomDocument & doc );
}
#endif // EVOLUTIONUTIL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment