sudo aptitude install kdelibs5-dev kdepimlibs5-dev libboost-dev
PROJECT(add-todo)
find_package(KDE4 REQUIRED) # KDE4
find_package(KdepimLibs REQUIRED) # KDE PIM
include(KDE4Defaults)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDEPIMLIBS_INCLUDE_DIR} ${KDE4_INCLUDES})
set (CMAKE_CXX_FLAGS "-fexceptions" )
kde4_add_executable(add-todo add_todo.cpp) #
target_link_libraries(add-todo ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_AKONADI_LIBS} ${KDEPIMLIBS_KCAL_LIBS}) #
* This source code was highlighted with Source Code Highlighter .
#ifndef ADD_TODO_H
#define ADD_TODO_H
#include <QCoreApplication>
#include <KJob>
class AddTodo : public QCoreApplication {
Q_OBJECT
public :
AddTodo( int argc, char ** argv );
public slots:
void collectionsFetched( KJob * job ); // ,
void todoCreated( KJob * job ); // ,
};
#endif // ADD_TODO_H
* This source code was highlighted with Source Code Highlighter .
#include "add_todo.h"
#include <QTextStream>
static QTextStream out ( stdout ); //
AddTodo::AddTodo( int argc, char ** argv ) : QCoreApplication( argc, argv ) {
out << "Application started" << endl;
}
void AddTodo::collectionsFetched( KJob * job ) {
}
void AddTodo::todoCreated( KJob * job ) {
}
int main( int argc, char ** argv ) {
AddTodo app( argc, argv ); //
return app.exec(); //
}
mkdir build
cd build
cmake ..
make
#include <QStringList>
#include <Akonadi/Collection>
#include <Akonadi/CollectionFetchJob>
using namespace Akonadi;
static QString todoMimeType( "text/calendar" ); // MIME-
* This source code was highlighted with Source Code Highlighter .
CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::FirstLevel, this ); //
connect( job, SIGNAL(result(KJob*)), this , SLOT(collectionsFetched(KJob*)) ); //
out << "Collections fetched" << endl;
if ( job->error() ) {
out << "Error occurred: " << job->errorText() << endl;
exit( -1 );
return ;
}
const CollectionFetchJob * fetchJob = qobject_cast<CollectionFetchJob*>( job ); //
const Collection * selectedCollection = 0; //
foreach ( const Collection & collection, fetchJob->collections() ) {
out << "Name: " << collection.name(); //
if ( collection.contentMimeTypes().contains( todoMimeType ) ) { // ,
selectedCollection = &collection;
break ;
}
}
if ( !selectedCollection ) { // ,
out << "Error occurred: no valid collection found" << endl;
exit( -1 );
return ;
}
//
* This source code was highlighted with Source Code Highlighter .
#include <Akonadi/Item>
#include <Akonadi/ItemCreateJob>
#include <kcal/todo.h>
#include <boost/shared_ptr.hpp>
KDateTime dueDate = KDateTime::fromString( arguments()[2], "%d.%m.%Y" ); //
if ( !dueDate.isValid() ) { // ,
out << "Error occured: invalid date '" << arguments()[2] << "'" << endl;
exit( -2 );
}
KCal::Todo::Ptr todo( new KCal::Todo() );
todo->setSummary( arguments()[1] ); //
todo->setDtDue( dueDate ); //
todo->setPercentComplete( 0 ); //
todo->setHasStartDate( false ); //
todo->setHasDueDate( true ); //
Item item( todoMimeType );
item.setPayload<KCal::Todo::Ptr>( todo );
ItemCreateJob * itemCreateJob = new ItemCreateJob( item, *selectedCollection, this ); //
connect( itemCreateJob, SIGNAL(result(KJob*)), this , SLOT(todoCreated(KJob*)) ); //
* This source code was highlighted with Source Code Highlighter .
if ( job->error() ) {
out << "Error occurred: " << job->errorText() << endl;
exit( -1 );
return ;
}
out << "TODO created" << endl;
quit();
* This source code was highlighted with Source Code Highlighter .
if ( argc < 3 ) { //
out << "Usage: add-todo [text] [date]" << endl;
return -2;
}
* This source code was highlighted with Source Code Highlighter .
./add-todo "Something" 21.01.2010
Source: https://habr.com/ru/post/81336/
All Articles