19 #include "messageviewer/globalsettings_base.h"
21 #include <KLocalizedString>
24 #include <KPushButton>
25 #include <KMessageWidget>
27 #include <QHBoxLayout>
32 #include <Akonadi/CollectionComboBox>
34 #include <incidenceeditor-ng/incidencedialog.h>
35 #include <incidenceeditor-ng/incidencedialogfactory.h>
38 namespace MessageViewer {
42 using namespace MessageViewer;
53 mMsgWidget->setCloseButtonVisible(
true);
54 mMsgWidget->setMessageType(KMessageWidget::Positive);
56 mMsgWidget->setWordWrap(
true);
57 mMsgWidget->setVisible(
false);
68 mNoteEdit =
new KLineEdit;
69 mNoteEdit->setClearButtonShown(
true);
71 mNoteEdit->setFocus();
73 connect(mNoteEdit, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
79 mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
80 mCollectionCombobox->setMinimumWidth(250);
81 mCollectionCombobox->setMimeTypeFilter(
QStringList() << KCalCore::Todo::todoMimeType() );
82 mCollectionCombobox->setObjectName(
QLatin1String(
"akonadicombobox"));
83 #ifndef QT_NO_ACCESSIBILITY
84 mCollectionCombobox->setAccessibleDescription( i18n(
"Todo list where the new task will be stored.") );
86 mCollectionCombobox->setToolTip( i18n(
"Todo list where the new task will be stored.") );
87 connect(mCollectionCombobox, SIGNAL(currentIndexChanged(
int)), SLOT(slotCollectionChanged(
int)));
88 connect(mCollectionCombobox, SIGNAL(activated(
int)), SLOT(slotCollectionChanged(
int)));
97 mSaveButton =
new KPushButton(KIcon(
QLatin1String(
"task-new")), i18n(
"&Save"));
99 mSaveButton->setEnabled(
false);
100 #ifndef QT_NO_ACCESSIBILITY
101 mSaveButton->setAccessibleDescription(i18n(
"Create new todo and close this widget."));
103 connect(mSaveButton, SIGNAL(clicked(
bool)),
this, SLOT(slotReturnPressed()));
106 mOpenEditorButton =
new KPushButton(i18n(
"Open &editor..."));
107 mOpenEditorButton->setObjectName(
QLatin1String(
"open-editor-button"));
108 #ifndef QT_NO_ACCESSIBILITY
109 mOpenEditorButton->setAccessibleDescription(i18n(
"Open todo editor, where more details can be changed."));
111 mOpenEditorButton->setEnabled(
false);
112 connect(mOpenEditorButton, SIGNAL(clicked(
bool)),
this, SLOT(slotOpenEditor()));
115 KPushButton *btn =
new KPushButton(KStandardGuiItem::cancel());
117 #ifndef QT_NO_ACCESSIBILITY
118 btn->setAccessibleDescription(i18n(
"Close the widget for creating new todos."));
126 mCollectionCombobox->installEventFilter(
this);
135 void TodoEdit::updateButtons(
const QString &subject)
138 const bool collectionComboboxEmpty = (mCollectionCombobox->count() < 1);
139 mSaveButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty);
140 mOpenEditorButton->setEnabled(subjectIsNotEmpty && !collectionComboboxEmpty);
145 mNoteEdit->setFocus();
151 const Akonadi::Collection col = mCollectionCombobox->currentCollection();
153 if (col.isValid() && col.id() != MessageViewer::GlobalSettingsBase::self()->lastSelectedFolder()) {
154 MessageViewer::GlobalSettingsBase::self()->setLastSelectedFolder(col.id());
155 MessageViewer::GlobalSettingsBase::self()->writeConfig();
159 void TodoEdit::readConfig()
161 const qint64
id = MessageViewer::GlobalSettingsBase::self()->lastSelectedFolder();
163 mCollectionCombobox->setDefaultCollection(Akonadi::Collection(
id));
172 void TodoEdit::slotCollectionChanged(
int )
179 if (mCollection != value) {
192 if (mMessage != value) {
194 const KMime::Headers::Subject *
const subject = mMessage ? mMessage->subject(
false) : 0;
196 mNoteEdit->setText(i18n(
"Reply to \"%1\"", subject->asUnicodeString()));
197 mNoteEdit->selectAll();
198 mNoteEdit->setFocus();
211 mMessage = KMime::Message::Ptr();
217 void TodoEdit::slotReturnPressed()
220 kDebug()<<
" Message is null";
223 const Akonadi::Collection
collection = mCollectionCombobox->currentCollection();
224 if (!collection.isValid()) {
225 kDebug()<<
" Collection is not valid";
229 if (!mNoteEdit->text().trimmed().isEmpty()) {
230 mMsgWidget->setText(i18nc(
"%1 is summary of the todo, %2 is name of the folder in which it is stored",
231 "New todo '%1' was added to task list '%2'", mNoteEdit->text(), collection.displayName()));
232 KCalCore::Todo::Ptr todo(
new KCalCore::Todo );
233 todo->setSummary(mNoteEdit->text());
239 mMsgWidget->animatedShow();
249 const bool shortCutOverride = (e->
type() == QEvent::ShortcutOverride);
250 if (shortCutOverride || e->
type() == QEvent::KeyPress ) {
252 if (kev->
key() == Qt::Key_Escape) {
256 }
else if ( kev->
key() == Qt::Key_Enter ||
257 kev->
key() == Qt::Key_Return ||
258 kev->
key() == Qt::Key_Space) {
260 if ( shortCutOverride ) {
263 if (
object == mCollectionCombobox) {
264 mCollectionCombobox->showPopup();
272 void TodoEdit::slotOpenEditor()
274 const KMime::Headers::Subject *
const subject = mMessage->subject(
false);
275 IncidenceEditorNG::IncidenceDialog *dlg = IncidenceEditorNG::IncidenceDialogFactory::createTodoEditor(
281 false, mCollection,
false,
this);
286 void TodoEdit::slotTextEdited(
const QString &subject)
288 updateButtons(subject);
289 if (mMsgWidget->isVisible()) {
TodoEdit(QWidget *parent=0)
void messageChanged(const KMime::Message::Ptr &msg)
void setCollection(const Akonadi::Collection &value)
void addSpacing(int size)
void installEventFilter(QObject *filterObj)
void collectionChanged(const Akonadi::Collection &col)
bool eventFilter(QObject *object, QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void setMargin(int margin)
#define MESSAGEVIEWER_EXPORT
void addStretch(int stretch)
void setMessage(const KMime::Message::Ptr &value)
KMime::Message::Ptr message() const
MESSAGEVIEWER_EXPORT QAbstractItemModel * _k_todoEditStubModel
QString fromLatin1(const char *str, int size)
void createTodo(const KCalCore::Todo::Ptr &todo, const Akonadi::Collection &collection)
Akonadi::Collection collection() const
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)