SVN_SILENT made messages (.desktop file)
[kdepim.git] / incidenceeditor-ng / main.cpp
blobd240b19f1879b95dd78a4a76216a485863d60416
1 /*
2 Copyright (C) 2010 Bertjan Broeksema <broeksema@kde.org>
3 Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <iostream>
22 #include <k4aboutdata.h>
23 #include <KApplication>
24 #include <KCmdLineArgs>
26 #include <calendarsupport/kcalprefs.h>
27 #include <akonadi/calendar/calendarsettings.h>
29 #include <Item>
30 #include <KCalCore/Event>
31 #include <KCalCore/Todo>
32 #include <KCalCore/Journal>
34 #include "korganizereditorconfig.h"
35 #include "incidencedialog.h"
36 #include "incidencedefaults.h"
38 using namespace IncidenceEditorNG;
40 int main(int argc, char **argv)
42 K4AboutData about("IncidenceEditorNGApp",
43 "korganizer",
44 ki18n("KOrganizer"),
45 "0.1",
46 ki18n("KDE application to run the KOrganizer incidenceeditor."),
47 K4AboutData::License_LGPL,
48 ki18n("(C) 2010 Bertjan Broeksema"),
49 ki18n("Run the KOrganizer incidenceeditor ng."),
50 "http://kdepim.kde.org",
51 "kdepim@kde.org");
52 about.addAuthor(ki18n("Bertjan Broeksema"), ki18n("Author"), "broeksema@kde.org");
53 about.setProgramIconName("korganizer");
55 KCmdLineOptions options;
56 options.add("new-event", ki18n("Creates a new event"));
57 options.add("new-todo", ki18n("Creates a new todo"));
58 options.add("new-journal", ki18n("Creates a new journal"));
59 options.add("+item",
60 ki18n("Loads an existing item, or returns without doing anything "
61 "when the item is not an event or todo."));
63 KCmdLineArgs::addCmdLineOptions(options);
64 KCmdLineArgs::init(argc, argv, &about);
65 KApplication app;
67 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
68 Akonadi::Item item(-1);
70 IncidenceDefaults defaults;
71 // Set the full emails manually here, to avoid that we get dependencies on
72 // KCalPrefs all over the place.
73 defaults.setFullEmails(CalendarSupport::KCalPrefs::instance()->fullEmails());
74 // NOTE: At some point this should be generalized. That is, we now use the
75 // freebusy url as a hack, but this assumes that the user has only one
76 // groupware account. Which doesn't have to be the case necessarily.
77 // This method should somehow depend on the calendar selected to which
78 // the incidence is added.
79 if (CalendarSupport::KCalPrefs::instance()->useGroupwareCommunication()) {
80 defaults.setGroupWareDomain(
81 QUrl(Akonadi::CalendarSettings::self()->freeBusyRetrieveUrl()).host());
84 if (args->isSet("new-event")) {
85 std::cout << "Creating new event..." << std::endl;
86 KCalCore::Event::Ptr event(new KCalCore::Event);
87 defaults.setDefaults(event);
88 item.setPayload<KCalCore::Event::Ptr>(event);
89 } else if (args->isSet("new-todo")) {
90 std::cout << "Creating new todo..." << std::endl;
91 KCalCore::Todo::Ptr todo(new KCalCore::Todo);
92 defaults.setDefaults(todo);
93 item.setPayload<KCalCore::Todo::Ptr>(todo);
94 } else if (args->isSet("new-journal")) {
95 std::cout << "Creating new journal..." << std::endl;
96 KCalCore::Journal::Ptr journal(new KCalCore::Journal);
97 defaults.setDefaults(journal);
98 item.setPayload<KCalCore::Journal::Ptr>(journal);
99 } else if (args->count() == 1) {
100 if (argc == 2) {
101 bool ok = false;
102 qint64 id = QString(argv[1]).toLongLong(&ok);
103 if (!ok) {
104 std::cerr << "Invalid akonadi item id given." << std::endl;
105 return 1;
108 item.setId(id);
109 std::cout << "Trying to load Akonadi Item " << QString::number(id).toLatin1().data();
110 std::cout << "..." << std::endl;
111 } else {
112 std::cerr << "Invalid argument count." << std::endl << std::endl;
113 return 1;
115 } else {
116 std::cerr << "Invalid usage." << std::endl << std::endl;
117 return 1;
120 EditorConfig::setEditorConfig(new KOrganizerEditorConfig);
122 IncidenceDialog *dialog = new IncidenceDialog();
124 Akonadi::Collection collection(CalendarSupport::KCalPrefs::instance()->defaultCalendarId());
126 if (collection.isValid()) {
127 dialog->selectCollection(collection);
130 dialog->load(item); // The dialog will show up once the item is loaded.
132 return app.exec();