Commit 8da1d9d5 authored by Volker Krause's avatar Volker Krause
Browse files

Add item append job.

svn path=/trunk/KDE/kdepim/libakonadi/; revision=545269
parent e7b0b0a7
......@@ -23,6 +23,7 @@ set( akonadi_LIB_SRC
collectionrenamejob.cpp
collectionselectjob.cpp
collectionview.cpp
itemappendjob.cpp
messagecollection.cpp
messagecollectionmodel.cpp
message.cpp
......@@ -52,6 +53,7 @@ install_files( /include/libakonadi FILES
collectionrenamejob.h
collectionselectjob.h
collectionview.h
itemappendjob.h
messagecollection.h
messagecollectionmodel.h
message.h
......
......@@ -105,7 +105,7 @@ class AKONADI_EXPORT CollectionModel : public QAbstractItemModel
Add a new collection to the model and try to save it into the backend.
@param parent The parent model index.
@param name The name of the new collection.
@returns flase on immediate error.
@returns false on immediate error.
*/
bool createCollection( const QModelIndex &parent, const QString &name );
......
/*
Copyright (c) 2006 Volker Krause <volker.krause@rwth-aachen.de>
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 "itemappendjob.h"
#include <QDebug>
using namespace PIM;
class PIM::ItemAppendJobPrivate
{
public:
QByteArray path;
QByteArray data;
QByteArray mimetype;
QByteArray tag;
};
PIM::ItemAppendJob::ItemAppendJob( const QByteArray &path, const QByteArray & data, const QByteArray & mimetype, QObject * parent ) :
Job( parent ),
d( new ItemAppendJobPrivate )
{
d->path = path;
d->data = data;
d->mimetype = mimetype;
}
PIM::ItemAppendJob::~ ItemAppendJob( )
{
delete d;
}
void PIM::ItemAppendJob::doStart()
{
d->tag = newTag();
writeData( d->tag + " APPEND " + d->path + " () {" + QByteArray::number( d->data.size() ) + "}" );
}
void PIM::ItemAppendJob::handleResponse( const QByteArray & tag, const QByteArray & data )
{
if ( tag == d->tag ) {
if ( !data.startsWith( "OK" ) )
setError( Unknown );
emit done( this );
return;
}
if ( tag == "+" ) { // ready for literal data
writeData( d->data );
return;
}
qDebug() << "unhandled response in item append job: " << tag << data;
}
#include "itemappendjob.moc"
/*
Copyright (c) 2006 Volker Krause <volker.krause@rwth-aachen.de>
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.
*/
#ifndef PIM_ITEMAPPENDJOB_H
#define PIM_ITEMAPPENDJOB_H
#include "job.h"
namespace PIM {
class ItemAppendJobPrivate;
/**
Creates a new PIM item on the backend.
Can be used as base class for type specific append jobs.
*/
class AKONADI_EXPORT ItemAppendJob : public Job
{
Q_OBJECT
public:
/**
Create a new item append job.
@param path Destination path.
@param data The raw data of the PIM item. Must be using CRLF!
@param mimetype The mimetype of the PIM item.
@param parent The parent object.
*/
ItemAppendJob( const QByteArray &path, const QByteArray &data, const QByteArray &mimetype, QObject *parent = 0 );
/**
Deletes this job.
*/
virtual ~ItemAppendJob();
protected:
virtual void doStart();
virtual void handleResponse( const QByteArray &tag, const QByteArray &data );
private:
ItemAppendJobPrivate *d;
};
}
#endif
......@@ -4,7 +4,7 @@ if(KDE4_BUILD_TESTS)
include_directories(
${CMAKE_SOURCE_DIR}/libakonadi
${CMAKE_SOURCE_DIR}/libakonadi/tests
)
......@@ -28,7 +28,16 @@ kde4_add_executable(messagebrowser RUN_UNINSTALLED ${messagebrowser_SRCS})
target_link_libraries(messagebrowser akonadi ${KDE4_KDECORE_LIBS} )
########### install files ###############
########### next target ###############
set(itemdumper_SRCS itemdumper.cpp )
kde4_automoc(${itemdumper_SRCS})
kde4_add_executable(itemdumper RUN_UNINSTALLED ${itemdumper_SRCS})
target_link_libraries(itemdumper akonadi ${KDE4_KDECORE_LIBS} )
endif(KDE4_BUILD_TESTS)
/*
Copyright (c) 2006 Volker Krause <volker.krause@rwth-aachen.de>
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 "itemdumper.h"
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <kapplication.h>
#include <kcmdlineargs.h>
using namespace PIM;
ItemDumper::ItemDumper( const QByteArray &path, const QByteArray &filename, const QByteArray &mimetype )
{
QFile f( filename );
Q_ASSERT( f.open(QIODevice::ReadOnly) );
QByteArray data = f.readAll();
f.close();
ItemAppendJob *job = new ItemAppendJob( path, data, mimetype, this );
connect( job, SIGNAL(done(PIM::Job*)), SLOT(done(PIM::Job*)) );
job->start();
}
void ItemDumper::done( PIM::Job * job )
{
if ( job->error() ) {
qWarning() << "Error while creating item: " << job->errorText();
} else {
qDebug() << "Done!";
}
job->deleteLater();
qApp->quit();
}
static KCmdLineOptions options[] =
{
{ "path <argument>", "IMAP destination path", 0 },
{ "mimetype <argument>", "Source mimetype", 0 },
{ "file <argument>", "Source file", 0 },
KCmdLineLastOption
};
int main( int argc, char** argv )
{
KCmdLineArgs::init( argc, argv, "test", "Test" ,"test app" ,"1.0" );
KCmdLineArgs::addCmdLineOptions( options );
KApplication app;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QByteArray path = args->getOption( "path" );
QByteArray mimetype = args->getOption( "mimetype" );
QByteArray file = args->getOption( "file" );
ItemDumper d( path, file, mimetype );
return app.exec();
}
#include "itemdumper.moc"
/*
Copyright (c) 2006 Volker Krause <volker.krause@rwth-aachen.de>
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.
*/
#ifndef ITEMDUMPER_H
#define ITEMDUMPER_H
#include <libakonadi/itemappendjob.h>
class ItemDumper : public QObject
{
Q_OBJECT
public:
ItemDumper( const QByteArray &path, const QByteArray &filename, const QByteArray &mimetype );
private slots:
void done(PIM::Job* job);
};
#endif
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