-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
incidencedialogfactory.cpp
130 lines (107 loc) · 5.47 KB
/
incidencedialogfactory.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
/*
Copyright (C) 2010 Bertjan Broeksema <broeksema@kde.org>
Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
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 "incidencedialogfactory.h"
#include "incidencedialog.h"
#include "incidencedefaults.h"
#include <KCalCore/Event>
#include <KCalCore/Todo>
#include <Akonadi/Item>
#include <Akonadi/Calendar/IncidenceChanger>
using namespace IncidenceEditorNG;
using namespace KCalCore;
IncidenceDialog *IncidenceDialogFactory::create( bool needsSaving,
KCalCore::IncidenceBase::IncidenceType type,
Akonadi::IncidenceChanger *changer,
QWidget *parent, Qt::WindowFlags flags )
{
switch ( type ) {
case KCalCore::IncidenceBase::TypeEvent: // Fall through
case KCalCore::IncidenceBase::TypeTodo:
case KCalCore::IncidenceBase::TypeJournal:
{
IncidenceDialog *dialog = new IncidenceDialog( changer, parent, flags );
// needs to be save to akonadi?, apply button should be turned on if so.
dialog->setInitiallyDirty( needsSaving/* mInitiallyDirty */ );
return dialog;
}
default:
return 0;
}
}
IncidenceDialog * IncidenceDialogFactory::createTodoEditor( const QString &summary,
const QString &description,
const QStringList &attachments,
const QStringList &attendees,
const QStringList &attachmentMimetypes,
const QStringList &attachmentLabels,
bool inlineAttachment,
Akonadi::Collection defaultCollection,
bool cleanupAttachmentTempFiles,
QWidget *parent, Qt::WindowFlags flags )
{
IncidenceDefaults defaults =
IncidenceDefaults::minimalIncidenceDefaults( cleanupAttachmentTempFiles );
// if attach or attendee list is empty, these methods don't do anything, so
// it's safe to call them in every case
defaults.setAttachments( attachments, attachmentMimetypes, attachmentLabels, inlineAttachment );
defaults.setAttendees( attendees );
Todo::Ptr todo( new Todo );
defaults.setDefaults( todo );
todo->setSummary( summary );
todo->setDescription( description );
Akonadi::Item item;
item.setPayload( todo );
IncidenceDialog *dialog = create( true, /* no need for, we're not editing an existing to-do */
KCalCore::Incidence::TypeTodo,
0,
parent, flags );
dialog->selectCollection( defaultCollection );
dialog->load( item );
return dialog;
}
IncidenceDialog * IncidenceDialogFactory::createEventEditor( const QString &summary,
const QString &description,
const QStringList &attachments,
const QStringList &attendees,
const QStringList &attachmentMimetypes,
const QStringList &attachmentLabels,
bool inlineAttachment,
Akonadi::Collection defaultCollection,
bool cleanupAttachmentTempFiles,
QWidget *parent, Qt::WindowFlags flags )
{
IncidenceDefaults defaults =
IncidenceDefaults::minimalIncidenceDefaults( cleanupAttachmentTempFiles );
// if attach or attendee list is empty, these methods don't do anything, so
// it's safe to call them in every case
defaults.setAttachments( attachments, attachmentMimetypes, attachmentLabels, inlineAttachment );
defaults.setAttendees( attendees );
Event::Ptr event( new Event );
defaults.setDefaults( event );
event->setSummary( summary );
event->setDescription( description );
Akonadi::Item item;
item.setPayload( event );
IncidenceDialog *dialog =
create( false, // not needed for saving, as we're not editing an existing incidence
KCalCore::Incidence::TypeEvent,
0,
parent, flags );
dialog->selectCollection( defaultCollection );
dialog->load( item );
return dialog;
}