Commit b125bb68 authored by Allen Winter's avatar Allen Winter
Browse files

follow the NoteEditDialog to CalendarSupport

parent 9e634f9e
......@@ -72,7 +72,7 @@ set(KDEPIM_APPS_LIB_VERSION_LIB "5.14.40")
set(PIMCOMMON_LIB_VERSION_LIB "5.14.40")
set(LIBKDEPIM_LIB_VERSION_LIB "5.14.40")
set(LIBINCIDENCEEDITOR_LIB_VERSION_LIB "5.14.40")
set(CALENDARSUPPORT_LIB_VERSION_LIB "5.14.40")
set(CALENDARSUPPORT_LIB_VERSION_LIB "5.14.41")
set(EVENTVIEW_LIB_VERSION_LIB "5.14.40")
find_package(KF5AkonadiSearch "5.14.40" CONFIG REQUIRED)
......
add_definitions(-DTRANSLATION_DOMAIN=\"korganizer\")
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(BUILD_TESTING)
add_subdirectory(tests)
......@@ -19,11 +17,10 @@ add_subdirectory(kconf_update)
########### next target ###############
set(korganizer_userfeedback_LIB)
if (TARGET KUserFeedbackWidgets)
if(TARGET KUserFeedbackWidgets)
set(korganizer_userfeedback_LIB KUserFeedbackWidgets)
endif()
set(korganizer_common_SRCS)
ecm_qt_declare_logging_category(korganizer_common_SRCS HEADER korganizer_debug.h IDENTIFIER KORGANIZER_LOG CATEGORY_NAME org.kde.pim.korganizer
DESCRIPTION "korganizer (korganizer)"
......@@ -31,7 +28,6 @@ ecm_qt_declare_logging_category(korganizer_common_SRCS HEADER korganizer_debug.h
EXPORT KORGANIZER
)
set(korganizer_SRCS
main.cpp
korganizer.cpp
......@@ -119,7 +115,6 @@ install(TARGETS
DESTINATION ${KDE_INSTALL_PLUGINDIR}
)
########### next target ###############
set(korganizer_core_LIB_SRCS
......@@ -157,7 +152,7 @@ install(TARGETS
########### next target ###############
set(korganizerprivate_userfeedback_SRCS)
if (TARGET KUserFeedbackWidgets)
if(TARGET KUserFeedbackWidgets)
set(korganizerprivate_userfeedback_SRCS ${korganizerprivate_userfeedback_SRCS}
userfeedback/userfeedbackmanager.cpp
userfeedback/korganizeruserfeedbackprovider.cpp
......@@ -187,7 +182,6 @@ set(korganizerprivate_LIB_SRCS
kodaymatrix.cpp
kodialogmanager.cpp
koeventpopupmenu.cpp
dialog/noteeditdialog.cpp
koeventview.cpp
dialog/koeventviewerdialog.cpp
koglobals.cpp
......@@ -208,8 +202,6 @@ set(korganizerprivate_LIB_SRCS
views/whatsnextview/kowhatsnextview.cpp
)
qt5_add_resources(korganizerprivate_LIB_SRCS korganizer.qrc)
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/qrc_korganizer.cpp PROPERTY SKIP_AUTOMOC ON)
......@@ -251,7 +243,6 @@ qt5_add_dbus_interfaces(korganizerprivate_LIB_SRCS
add_library(korganizerprivate ${korganizerprivate_LIB_SRCS})
generate_export_header(korganizerprivate BASE_NAME korganizerprivate)
target_link_libraries(korganizerprivate
PUBLIC
KF5::PimCommonAkonadi
......
......@@ -26,7 +26,7 @@ target_link_libraries(testkodaymatrix_us
Qt5::Test
)
set(koeventpopupmenutest_SRCS ../koeventpopupmenu.cpp ../kocorehelper.cpp ../dialog/noteeditdialog.cpp ../korganizer_debug.cpp)
set(koeventpopupmenutest_SRCS ../koeventpopupmenu.cpp ../kocorehelper.cpp ../korganizer_debug.cpp)
set(koeventpopupmenutest_LIBS Qt5::Test
Qt5::Gui
Qt5::Core
......@@ -42,22 +42,3 @@ set(koeventpopupmenutest_LIBS Qt5::Test
korganizerprivate
)
add_akonadi_isolated_test_advanced(koeventpopupmenutest.cpp "${koeventpopupmenutest_SRCS}" "${koeventpopupmenutest_LIBS}")
add_executable(noteeditdialogtest noteeditdialogtest.cpp ../dialog/noteeditdialog.cpp ../korganizer_debug.cpp)
add_test(NAME noteeditdialogtest COMMAND noteeditdialogtest)
ecm_mark_as_test(noteeditdialogtest)
target_link_libraries(noteeditdialogtest
Qt5::Test
Qt5::Gui
Qt5::Core
KF5::Mime
KF5::AkonadiCore
KF5::AkonadiCalendar
KF5::AkonadiNotes
KF5::CalendarCore
KF5::IncidenceEditor
KF5::CalendarSupport
KF5::AkonadiWidgets
korganizer_core
korganizerprivate
)
......@@ -17,9 +17,10 @@
#include "koeventpopupmenutest.h"
#include "koeventpopupmenu.h"
#include "dialog/noteeditdialog.h"
#include <CalendarSupport/Utils>
#include <Akonadi/Notes/NoteUtils>
#include <CalendarSupport/NoteEditDialog>
#include <IncidenceEditor/IncidenceDialog>
#include <IncidenceEditor/IncidenceEditor-Ng>
......@@ -27,7 +28,6 @@
#include <QStandardPaths>
#include <QTest>
KoEventPopupMenuTest::KoEventPopupMenuTest(QObject *parent)
: QObject(parent)
{
......@@ -49,8 +49,8 @@ void KoEventPopupMenuTest::createEventFromEvent()
QAction *createevent = menu.findChild<QAction *>(QStringLiteral("createevent"));
createevent->trigger();
IncidenceEditorNG::IncidenceDialog *dlg = menu.findChild<IncidenceEditorNG::IncidenceDialog *>(QStringLiteral(
"incidencedialog"));
IncidenceEditorNG::IncidenceDialog *dlg =
menu.findChild<IncidenceEditorNG::IncidenceDialog *>(QStringLiteral("incidencedialog"));
QVERIFY(!dlg);
}
......@@ -69,8 +69,8 @@ void KoEventPopupMenuTest::createTodoFromTodo()
QAction *createtodo = menu.findChild<QAction *>(QStringLiteral("createtodo"));
createtodo->trigger();
IncidenceEditorNG::IncidenceDialog *dlg = menu.findChild<IncidenceEditorNG::IncidenceDialog *>(QStringLiteral(
"incidencedialog"));
IncidenceEditorNG::IncidenceDialog *dlg =
menu.findChild<IncidenceEditorNG::IncidenceDialog *>(QStringLiteral("incidencedialog"));
QVERIFY(!dlg);
}
......@@ -169,10 +169,10 @@ void KoEventPopupMenuTest::createNoteFromEvent()
menu.setCalendar(calendar);
menu.showIncidencePopup(item, QDate());
QAction *createnote = menu.findChild<QAction *>(QStringLiteral("createnote"));
NoteEditDialog *noteedit = menu.findChild<NoteEditDialog *>();
CalendarSupport::NoteEditDialog *noteedit = menu.findChild<CalendarSupport::NoteEditDialog *>();
QVERIFY(!noteedit);
createnote->trigger();
noteedit = menu.findChild<NoteEditDialog *>();
noteedit = menu.findChild<CalendarSupport::NoteEditDialog *>();
QVERIFY(noteedit);
Akonadi::NoteUtils::NoteMessageWrapper note(noteedit->note());
QCOMPARE(note.title(), summary);
......@@ -208,10 +208,10 @@ void KoEventPopupMenuTest::createNoteFromTodo()
menu.showIncidencePopup(item, QDate());
QAction *createnote = menu.findChild<QAction *>(QStringLiteral("createnote"));
NoteEditDialog *noteedit = menu.findChild<NoteEditDialog *>();
CalendarSupport::NoteEditDialog *noteedit = menu.findChild<CalendarSupport::NoteEditDialog *>();
QVERIFY(!noteedit);
createnote->trigger();
noteedit = menu.findChild<NoteEditDialog *>();
noteedit = menu.findChild<CalendarSupport::NoteEditDialog *>();
QVERIFY(noteedit);
Akonadi::NoteUtils::NoteMessageWrapper note(noteedit->note());
QCOMPARE(note.title(), summary);
......
/*
* Copyright (c) 2014 Sandro Knauß <knauss@kolabsys.com>
*
* 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.
*
* As a special exception, permission is given to link this program
* with any edition of Qt, and distribute the resulting executable,
* without including the source code for Qt in the source distribution.
*/
#include "noteeditdialog.h"
#include "korganizer_debug.h"
#include <AkonadiWidgets/CollectionComboBox>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <KPIMTextEdit/RichTextEditor>
#include <KPIMTextEdit/RichTextEditorWidget>
QAbstractItemModel *NoteEditDialog::_k_noteEditStubModel = nullptr;
NoteEditDialog::NoteEditDialog(QWidget *parent)
: QDialog(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(i18nc("@title:window", "Create Note"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainWidget);
connect(buttonBox, &QDialogButtonBox::accepted, this, &NoteEditDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
mainLayout->addWidget(buttonBox);
buttonBox->button(QDialogButtonBox::Cancel)->setText(i18nc("@action:button",
"Cancel"));
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setObjectName(QStringLiteral("save-button"));
mOkButton->setDefault(true);
mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
mOkButton->setText(i18nc("@action:button", "Save"));
mOkButton->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-notes")));
mOkButton->setEnabled(false);
QGridLayout *layout = new QGridLayout(mainWidget);
layout->setContentsMargins(0, 0, 0, 0);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->setContentsMargins(0, 0, 0, 0);
hbox->setSpacing(2);
mNoteTitle = new QLineEdit;
mNoteTitle->setClearButtonEnabled(true);
mNoteTitle->setObjectName(QStringLiteral("notetitle"));
mNoteTitle->setFocus();
connect(mNoteTitle, &QLineEdit::textChanged, this, &NoteEditDialog::slotUpdateButtons);
mCollectionCombobox = new Akonadi::CollectionComboBox(_k_noteEditStubModel);
mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
mCollectionCombobox->setMinimumWidth(250);
mCollectionCombobox->setMimeTypeFilter(QStringList() << Akonadi::NoteUtils::noteMimeType());
mCollectionCombobox->setObjectName(QStringLiteral("akonadicombobox"));
#ifndef QT_NO_ACCESSIBILITY
mCollectionCombobox->setAccessibleDescription(i18n(
"Calendar where the new note will be stored."));
#endif
mCollectionCombobox->setToolTip(i18n("Calendar where the new note will be stored."));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
connect(mCollectionCombobox,
QOverload<int>::of(
&Akonadi::CollectionComboBox::currentIndexChanged), this,
&NoteEditDialog::slotCollectionChanged);
#else
connect(mCollectionCombobox,
QOverload<int, const QString &>::of(
&Akonadi::CollectionComboBox::currentIndexChanged), this,
&NoteEditDialog::slotCollectionChanged);
#endif
connect(mCollectionCombobox, QOverload<int>::of(
&Akonadi::CollectionComboBox::activated), this,
&NoteEditDialog::slotCollectionChanged);
mNoteText = new KPIMTextEdit::RichTextEditorWidget(parent);
mNoteText->setObjectName(QStringLiteral("notetext"));
connect(
mNoteText->editor(), &KPIMTextEdit::RichTextEditor::textChanged, this,
&NoteEditDialog::slotUpdateButtons);
//First line
hbox->addWidget(mNoteTitle);
hbox->addSpacing(5);
hbox->addWidget(mCollectionCombobox);
QLabel *lab = new QLabel(i18n("Title:"), this);
layout->addWidget(lab, 0, 0);
layout->addLayout(hbox, 0, 1);
//Second Line
lab = new QLabel(i18n("Text:"), this);
layout->addWidget(lab, 1, 0);
layout->setAlignment(lab, Qt::AlignTop);
layout->addWidget(mNoteText, 1, 1);
readConfig();
}
NoteEditDialog::~NoteEditDialog()
{
disconnect(
mNoteText->editor(), &KPIMTextEdit::RichTextEditor::textChanged, this,
&NoteEditDialog::slotUpdateButtons);
writeConfig();
}
void NoteEditDialog::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "NoteEditDialog");
const QSize size = group.readEntry("Size", QSize(500, 300));
if (size.isValid()) {
resize(size);
}
}
void NoteEditDialog::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "NoteEditDialog");
group.writeEntry("Size", size());
group.sync();
}
void NoteEditDialog::slotUpdateButtons()
{
if (mNoteTitle->text().trimmed().isEmpty() && mNoteText->isEmpty()) {
mOkButton->setEnabled(false);
} else {
mOkButton->setEnabled(true);
}
}
Akonadi::Collection NoteEditDialog::collection() const
{
return mCollection;
}
void NoteEditDialog::slotCollectionChanged(int index)
{
Q_UNUSED(index);
setCollection(mCollectionCombobox->currentCollection());
}
void NoteEditDialog::setCollection(const Akonadi::Collection &value)
{
if (mCollection != value) {
mCollection = value;
Q_EMIT collectionChanged(mCollection);
}
}
void NoteEditDialog::accept()
{
QDialog::accept();
const Akonadi::Collection collection = mCollectionCombobox->currentCollection();
if (!collection.isValid()) {
qCDebug(KORGANIZER_LOG) << " Collection is not valid";
return;
}
if (mNoteTitle->text().isEmpty() && mNoteText->isEmpty()) {
qCDebug(KORGANIZER_LOG) << " empty note do not save it";
return;
}
Akonadi::NoteUtils::NoteMessageWrapper note(mItem.payload<KMime::Message::Ptr>());
note.setTitle(mNoteTitle->text());
if (mNoteText->acceptRichText()) {
note.setText(mNoteText->editor()->toHtml(), Qt::RichText);
} else {
note.setText(mNoteText->editor()->toPlainText(), Qt::PlainText);
}
mItem.setPayload<KMime::Message::Ptr>(note.message());
Q_EMIT createNote(mItem, collection);
}
void NoteEditDialog::load(const Akonadi::Item &item)
{
mItem = item;
Akonadi::NoteUtils::NoteMessageWrapper note(item.payload<KMime::Message::Ptr>());
mNoteText->editor()->setHtml(note.text());
if (note.textFormat() == Qt::RichText) {
mNoteText->setAcceptRichText(true);
} else {
mNoteText->setAcceptRichText(false);
}
mNoteTitle->setText(note.title());
}
KMime::Message::Ptr NoteEditDialog::note() const
{
if (mItem.hasPayload<KMime::Message::Ptr>()) {
return mItem.payload<KMime::Message::Ptr>();
} else {
return KMime::Message::Ptr();
}
}
/*
* Copyright (c) 2014 Sandro Knauß <knauss@kolabsys.com>
*
* 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.
*
* As a special exception, permission is given to link this program
* with any edition of Qt, and distribute the resulting executable,
* without including the source code for Qt in the source distribution.
*/
#ifndef NOTEEDITDIALOG_H
#define NOTEEDITDIALOG_H
#include <QDialog>
#include <AkonadiCore/Collection>
#include <AkonadiCore/Item>
#include <Akonadi/Notes/NoteUtils>
#include <KMime/KMimeMessage>
class QLineEdit;
class QPushButton;
class QAbstractItemModel;
namespace KPIMTextEdit {
class RichTextEditorWidget;
}
namespace Akonadi {
class CollectionComboBox;
}
class NoteEditDialog : public QDialog
{
Q_OBJECT
public:
explicit NoteEditDialog(QWidget *parent = nullptr);
~NoteEditDialog() override;
Q_REQUIRED_RESULT Akonadi::Collection collection() const;
void setCollection(const Akonadi::Collection &value);
void load(const Akonadi::Item &item);
Q_REQUIRED_RESULT KMime::Message::Ptr note() const;
//Used for tests
static QAbstractItemModel *_k_noteEditStubModel;
public Q_SLOTS:
void accept() override;
private Q_SLOTS:
void slotCollectionChanged(int);
void slotUpdateButtons();
Q_SIGNALS:
void createNote(const Akonadi::Item &note, const Akonadi::Collection &collection);
void collectionChanged(const Akonadi::Collection &col);
private:
void readConfig();
void writeConfig();
Akonadi::Collection mCollection;
Akonadi::Item mItem;
QLineEdit *mNoteTitle = nullptr;
QPushButton *mOkButton = nullptr;
KPIMTextEdit::RichTextEditorWidget *mNoteText = nullptr;
Akonadi::CollectionComboBox *mCollectionCombobox = nullptr;
};
#endif // NOTEEDITDIALOG_H
......@@ -24,29 +24,24 @@
*/
#include "koeventpopupmenu.h"
#include "actionmanager.h"
#include "kocorehelper.h"
#include "koglobals.h"
#include "dialog/noteeditdialog.h"
#include "korganizer_debug.h"
#include "actionmanager.h" // needed for finding the schedule_forward action
#include <AkonadiCore/ItemCreateJob>
#include <Akonadi/Notes/NoteUtils>
#include <CalendarSupport/KCalPrefs>
#include <CalendarSupport/Utils>
#include <CalendarSupport/CalPrinter>
#include <CalendarSupport/CalPrintDefaultPlugins>
#include <CalendarSupport/NoteEditDialog>
#include <CalendarSupport/Utils>
#include <KCalendarCore/CalFormat>
#include <KCalendarCore/Incidence>
#include <Akonadi/Notes/NoteUtils>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/ItemCreateJob>
#include <KActionCollection> // needed for finding the schedule_forward action
#include <KActionCollection>
#include <KMime/Message>
#include "korganizer_debug.h"
#include <KCalendarCore/CalFormat>
#include <IncidenceEditor/IncidenceDialogFactory>
#include <IncidenceEditor/IncidenceDialog>
#include <IncidenceEditor/IncidenceDialogFactory>
#include<QCoreApplication>
KOEventPopupMenu::KOEventPopupMenu(const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent)
: QMenu(parent)
......@@ -278,12 +273,10 @@ void KOEventPopupMenu::slotPrint()
void KOEventPopupMenu::print(bool preview)
{
KOCoreHelper helper;
CalendarSupport::CalPrinter printer(this, mCalendar, true);
connect(this, &KOEventPopupMenu::configChanged, &printer,
&CalendarSupport::CalPrinter::updateConfig);
//Item::List selectedIncidences;
KCalendarCore::Incidence::List selectedIncidences;
Q_ASSERT(mCurrentIncidence.hasPayload<KCalendarCore::Incidence::Ptr>());
selectedIncidences.append(mCurrentIncidence.payload<KCalendarCore::Incidence::Ptr>());
......@@ -414,8 +407,9 @@ void KOEventPopupMenu::createNote()
newNoteItem.setMimeType(Akonadi::NoteUtils::noteMimeType());
newNoteItem.setPayload(note.message());
NoteEditDialog *noteedit = new NoteEditDialog(this);
connect(noteedit, &NoteEditDialog::createNote, this, &KOEventPopupMenu::slotCreateNote);
CalendarSupport::NoteEditDialog *noteedit = new CalendarSupport::NoteEditDialog(this);
connect(noteedit, &CalendarSupport::NoteEditDialog::createNote,
this, &KOEventPopupMenu::slotCreateNote);
noteedit->load(newNoteItem);
noteedit->show();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment