-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
132 lines (110 loc) · 4.9 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright (C) 2010 Bertjan Broeksema <broeksema@kde.org>
Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 <iostream>
#include <KAboutData>
#include <KApplication>
#include <KCmdLineArgs>
#include <calendarsupport/kcalprefs.h>
#include <akonadi/calendar/calendarsettings.h>
#include <Akonadi/Item>
#include <KCalCore/Event>
#include <KCalCore/Todo>
#include <KCalCore/Journal>
#include "korganizereditorconfig.h"
#include "incidencedialog.h"
#include "incidencedefaults.h"
using namespace IncidenceEditorNG;
int main( int argc, char **argv )
{
KAboutData about( "IncidenceEditorNGApp",
"korganizer",
ki18n( "KOrganizer" ),
"0.1",
ki18n( "KDE application to run the KOrganizer incidenceeditor." ),
KAboutData::License_LGPL,
ki18n( "(C) 2010 Bertjan Broeksema" ),
ki18n( "Run the KOrganizer incidenceeditor ng." ),
"http://kdepim.kde.org",
"kdepim@kde.org" );
about.addAuthor( ki18n( "Bertjan Broeksema" ), ki18n( "Author" ), "broeksema@kde.org" );
about.setProgramIconName( "korganizer" );
KCmdLineOptions options;
options.add( "new-event", ki18n( "Creates a new event" ) );
options.add( "new-todo", ki18n( "Creates a new todo" ) );
options.add( "new-journal", ki18n( "Creates a new journal" ) );
options.add( "+item",
ki18n( "Loads an existing item, or returns without doing anything "
"when the item is not an event or todo." ) );
KCmdLineArgs::addCmdLineOptions( options );
KCmdLineArgs::init( argc, argv, &about );
KApplication app;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
Akonadi::Item item( -1 );
IncidenceDefaults defaults;
// Set the full emails manually here, to avoid that we get dependencies on
// KCalPrefs all over the place.
defaults.setFullEmails( CalendarSupport::KCalPrefs::instance()->fullEmails() );
// NOTE: At some point this should be generalized. That is, we now use the
// freebusy url as a hack, but this assumes that the user has only one
// groupware account. Which doesn't have to be the case necessarily.
// This method should somehow depend on the calendar selected to which
// the incidence is added.
if ( CalendarSupport::KCalPrefs::instance()->useGroupwareCommunication() ) {
defaults.setGroupWareDomain(
KUrl( Akonadi::CalendarSettings::self()->freeBusyRetrieveUrl() ).host() );
}
if ( args->isSet( "new-event" ) ) {
std::cout << "Creating new event..." << std::endl;
KCalCore::Event::Ptr event( new KCalCore::Event );
defaults.setDefaults( event );
item.setPayload<KCalCore::Event::Ptr>( event );
} else if ( args->isSet( "new-todo" ) ) {
std::cout << "Creating new todo..." << std::endl;
KCalCore::Todo::Ptr todo( new KCalCore::Todo );
defaults.setDefaults( todo );
item.setPayload<KCalCore::Todo::Ptr>( todo );
} else if ( args->isSet( "new-journal" ) ) {
std::cout << "Creating new journal..." << std::endl;
KCalCore::Journal::Ptr journal( new KCalCore::Journal );
defaults.setDefaults( journal );
item.setPayload<KCalCore::Journal::Ptr>( journal );
} else if ( args->count() == 1 ) {
if ( argc == 2 ) {
bool ok = false;
qint64 id = QString( argv[1] ).toLongLong( &ok );
if ( !ok ) {
std::cerr << "Invalid akonadi item id given." << std::endl;
return 1;
}
item.setId( id );
std::cout << "Trying to load Akonadi Item " << QString::number( id ).toLatin1().data();
std::cout << "..." << std::endl;
} else {
std::cerr << "Invalid argument count." << std::endl << std::endl;
return 1;
}
} else {
std::cerr << "Invalid usage." << std::endl << std::endl;
return 1;
}
EditorConfig::setEditorConfig( new KOrganizerEditorConfig );
IncidenceDialog *dialog = new IncidenceDialog();
Akonadi::Collection collection( CalendarSupport::KCalPrefs::instance()->defaultCalendarId() );
if ( collection.isValid() )
dialog->selectCollection( collection );
dialog->load( item ); // The dialog will show up once the item is loaded.
return app.exec();
}