20 #include "messageviewer/globalsettings_base.h"
23 #include <KLocalizedString>
26 #include <KDateTimeEdit>
27 #include <KTimeComboBox>
29 #include <QHBoxLayout>
33 #include <KDateComboBox>
35 #include <Akonadi/CollectionComboBox>
36 #include <KPushButton>
38 #include <incidenceeditor-ng/incidencedialogfactory.h>
39 #include <incidenceeditor-ng/incidencedialog.h>
42 namespace MessageViewer {
46 using namespace MessageViewer;
64 mEventEdit =
new KLineEdit;
65 mEventEdit->setClearButtonShown(
true);
67 mEventEdit->setFocus();
68 connect(mEventEdit, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
75 mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
76 mCollectionCombobox->setMinimumWidth(250);
77 mCollectionCombobox->setMimeTypeFilter(
QStringList() << KCalCore::Event::eventMimeType() );
78 mCollectionCombobox->setObjectName(
QLatin1String(
"akonadicombobox"));
79 #ifndef QT_NO_ACCESSIBILITY
80 mCollectionCombobox->setAccessibleDescription( i18n(
"Calendar where the new event will be stored.") );
82 mCollectionCombobox->setToolTip( i18n(
"Calendar where the new event will be stored.") );
84 connect(mCollectionCombobox, SIGNAL(currentIndexChanged(
int)), SLOT(slotCollectionChanged(
int)));
85 connect(mCollectionCombobox, SIGNAL(activated(
int)), SLOT(slotCollectionChanged(
int)));
93 lab =
new QLabel(i18n(
"Start:"));
95 KDateTime currentDateTime = KDateTime::currentDateTime(KDateTime::LocalZone);
100 #ifndef QT_NO_ACCESSIBILITY
103 connect(mStartDateTimeEdit, SIGNAL(dateTimeChanged(KDateTime)),
104 this, SLOT(slotStartDateTimeChanged(KDateTime)));
110 lab =
new QLabel(i18n(
"End:"));
114 mEndDateTimeEdit->
setDateTime(currentDateTime.addSecs(3600));
115 #ifndef QT_NO_ACCESSIBILITY
118 connect(mEndDateTimeEdit, SIGNAL(dateTimeChanged(KDateTime)),
119 this, SLOT(slotEndDateTimeChanged(KDateTime)));
132 mSaveButton =
new KPushButton(KIcon(
QLatin1String(
"appointment-new")), i18n(
"&Save"));
134 mSaveButton->setEnabled(
false);
135 #ifndef QT_NO_ACCESSIBILITY
136 mSaveButton->setAccessibleDescription(i18n(
"Create new event and close this widget."));
138 connect(mSaveButton, SIGNAL(clicked(
bool)),
this, SLOT(slotReturnPressed()));
141 mOpenEditorButton =
new KPushButton(i18n(
"Open &editor..."));
142 #ifndef QT_NO_ACCESSIBILITY
143 mOpenEditorButton->setAccessibleDescription(i18n(
"Open event editor, where more details can be changed."));
145 mOpenEditorButton->setObjectName(
QLatin1String(
"open-editor-button"));
146 mOpenEditorButton->setEnabled(
false);
147 connect(mOpenEditorButton, SIGNAL(clicked(
bool)),
this, SLOT(slotOpenEditor()));
150 KPushButton *btn =
new KPushButton(KStandardGuiItem::cancel());
152 #ifndef QT_NO_ACCESSIBILITY
153 btn->setAccessibleDescription(i18n(
"Close the widget for creating new events."));
161 mCollectionCombobox->installEventFilter(
this);
171 const Akonadi::Collection col = mCollectionCombobox->currentCollection();
173 if (col.isValid() && col.id() != MessageViewer::GlobalSettingsBase::self()->lastEventSelectedFolder()) {
174 MessageViewer::GlobalSettingsBase::self()->setLastEventSelectedFolder(col.id());
175 MessageViewer::GlobalSettingsBase::self()->writeConfig();
179 void EventEdit::slotUpdateButtons(
const QString &subject)
182 const bool collectionComboboxEmpty = (mCollectionCombobox->count() < 1);
183 mSaveButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty);
184 mOpenEditorButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty);
189 mEventEdit->setFocus();
190 KDateTime currentDateTime = KDateTime::currentDateTime(KDateTime::LocalZone);
192 mEndDateTimeEdit->
setDateTime(currentDateTime.addSecs(3600));
196 void EventEdit::readConfig()
198 const qint64
id = MessageViewer::GlobalSettingsBase::self()->lastEventSelectedFolder();
200 mCollectionCombobox->setDefaultCollection(Akonadi::Collection(
id));
209 void EventEdit::slotCollectionChanged(
int )
216 if (mCollection != value) {
229 if (mMessage != value) {
231 const KMime::Headers::Subject *
const subject = mMessage ? mMessage->subject(
false) : 0;
233 mEventEdit->setText(i18n(
"Reply to \"%1\"", subject->asUnicodeString()));
234 mEventEdit->selectAll();
235 mEventEdit->setFocus();
248 mMessage = KMime::Message::Ptr();
253 void EventEdit::slotReturnPressed()
256 kDebug()<<
" Message is null";
259 const Akonadi::Collection
collection = mCollectionCombobox->currentCollection();
260 if (!collection.isValid()) {
261 kDebug()<<
" Collection is not valid";
265 const KDateTime dtstart = mStartDateTimeEdit->
dateTime();
266 const KDateTime dtend = mEndDateTimeEdit->
dateTime();
267 if (!dtstart.isValid() || !dtend.isValid()) {
268 qDebug()<<
" date is not valid !";
272 if (!mEventEdit->text().trimmed().isEmpty()) {
273 KCalCore::Event::Ptr
event(
new KCalCore::Event );
274 event->setDtStart(dtstart);
275 event->setDtEnd(dtend);
276 event->setSummary(mEventEdit->text());
289 const bool shortCutOverride = (e->
type() == QEvent::ShortcutOverride);
290 if (shortCutOverride ) {
292 if (kev->
key() == Qt::Key_Escape) {
296 }
else if ( kev->
key() == Qt::Key_Enter ||
297 kev->
key() == Qt::Key_Return ||
298 kev->
key() == Qt::Key_Space) {
300 if (
object == mCollectionCombobox) {
301 mCollectionCombobox->showPopup();
309 void EventEdit::slotEndDateTimeChanged(
const KDateTime &newDateTime)
311 if (!newDateTime.isValid()) {
314 KDateTime currentDateTime = KDateTime::currentDateTime(KDateTime::LocalZone);
315 if (newDateTime.date() > currentDateTime.date()) {
316 KDateTime newDateDate = newDateTime;
317 newDateDate.setTime(
QTime(0, 0, 0));
322 void EventEdit::slotStartDateTimeChanged(
const KDateTime &newDateTime)
324 if (!newDateTime.isValid()) {
328 if (mEndDateTimeEdit->
date() == newDateTime.date() && mEndDateTimeEdit->
time() < newDateTime.time()) {
329 mEndDateTimeEdit->
setTime(newDateTime.time());
331 if (mEndDateTimeEdit->
date() < newDateTime.date()) {
332 mEndDateTimeEdit->
setDate(newDateTime.date());
339 void EventEdit::slotOpenEditor()
341 KCalCore::Attachment::Ptr attachment(
new KCalCore::Attachment(mMessage->encodedContent().toBase64(), KMime::Message::mimeType()));
342 const KMime::Headers::Subject *
const subject = mMessage->subject(
false);
344 attachment->setLabel(subject->asUnicodeString());
346 KCalCore::Event::Ptr
event(
new KCalCore::Event);
347 event->setSummary(mEventEdit->text());
348 event->setDtStart(mStartDateTimeEdit->
dateTime());
349 event->setDtEnd(mEndDateTimeEdit->
dateTime());
351 event->addAttachment(attachment);
354 item.setPayload<KCalCore::Event::Ptr>(
event);
355 item.setMimeType(KCalCore::Event::eventMimeType());
357 IncidenceEditorNG::IncidenceDialog *dlg = IncidenceEditorNG::IncidenceDialogFactory::create(
true, KCalCore::IncidenceBase::TypeEvent, 0,
this);
void addSpacing(int size)
Akonadi::Collection collection() const
KMime::Message::Ptr message() const
bool eventFilter(QObject *object, QEvent *e)
void createEvent(const KCalCore::Event::Ptr &event, const Akonadi::Collection &collection)
MESSAGEVIEWER_EXPORT QAbstractItemModel * _k_eventEditStubModel
void installEventFilter(QObject *filterObj)
void setObjectName(const QString &name)
virtual bool eventFilter(QObject *watched, QEvent *event)
void setMargin(int margin)
void messageChanged(const KMime::Message::Ptr &msg)
#define MESSAGEVIEWER_EXPORT
EventEdit(QWidget *parent=0)
void collectionChanged(const Akonadi::Collection &col)
void setCollection(const Akonadi::Collection &value)
void addStretch(int stretch)
void setMessage(const KMime::Message::Ptr &value)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSpacing(int spacing)
void addLayout(QLayout *layout, int stretch)