diff --git a/mailmerge/tests/CMakeLists.txt b/mailmerge/tests/CMakeLists.txt index 12de5844d..727d36322 100644 --- a/mailmerge/tests/CMakeLists.txt +++ b/mailmerge/tests/CMakeLists.txt @@ -3,7 +3,7 @@ include_directories( ) # convenience macro to add qtest unit tests macro(add_kmail_unittest _source) - set(_test ${_source} ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp) + set(_test ${_source} ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp ../widgets/csvwidget.cpp) get_filename_component(_name ${_source} NAME_WE) kde4_add_unit_test(${_name} TESTNAME kmail-${_name} ${_test}) target_link_libraries( ${_name} @@ -18,7 +18,7 @@ endmacro () add_kmail_unittest( mailmergewidgettest.cpp ) -set(mailmergewidget_gui_SRCS mailmergewidgettest_gui.cpp ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp) +set(mailmergewidget_gui_SRCS mailmergewidgettest_gui.cpp ../widgets/mailmergewidget.cpp ../widgets/attachmentlistwidget.cpp ../widgets/csvwidget.cpp) kde4_add_executable(mailmergewidget_gui TEST ${mailmergewidget_gui_SRCS}) target_link_libraries(mailmergewidget_gui ${QT_QTCORE_LIBRARY} @@ -30,13 +30,13 @@ target_link_libraries(mailmergewidget_gui # Convenience macro to add unit tests. -macro( kmail_mailmerge _source ) - set( _test ${_source} ) +macro( kmail_mailmerge _source _additionalsource) + set( _test ${_source} ${_additionalsource}) get_filename_component( _name ${_source} NAME_WE ) kde4_add_unit_test( ${_name} TESTNAME kmailmailmerge-${_name} ${_test} ) - target_link_libraries( ${_name} ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ) + target_link_libraries( ${_name} ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS} ) endmacro() -kmail_mailmerge(addressbookwidgettest.cpp) - +kmail_mailmerge(addressbookwidgettest.cpp "") +kmail_mailmerge(csvwidgettest.cpp "../widgets/csvwidget.cpp") diff --git a/mailmerge/tests/csvwidgettest.cpp b/mailmerge/tests/csvwidgettest.cpp new file mode 100644 index 000000000..53f612386 --- /dev/null +++ b/mailmerge/tests/csvwidgettest.cpp @@ -0,0 +1,45 @@ +/* + Copyright (c) 2015 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + 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 +*/ + +#include "csvwidgettest.h" +#include "../widgets/csvwidget.h" +#include +#include +#include +CsvWidgetTest::CsvWidgetTest(QObject *parent) + : QObject(parent) +{ + +} + +CsvWidgetTest::~CsvWidgetTest() +{ + +} + +void CsvWidgetTest::shouldHaveDefaultValue() +{ + MailMerge::CsvWidget w; + + QLabel *lab = qFindChild(&w, QLatin1String("label")); + QVERIFY(lab); + + KUrlRequester *urlrequester = qFindChild(&w, QLatin1String("cvsurlrequester")); + QVERIFY(urlrequester); +} + +QTEST_KDEMAIN(CsvWidgetTest, GUI) diff --git a/mailmerge/tests/csvwidgettest.h b/mailmerge/tests/csvwidgettest.h new file mode 100644 index 000000000..71c2d906d --- /dev/null +++ b/mailmerge/tests/csvwidgettest.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2015 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + 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 +*/ + +#ifndef CSVWIDGETTEST_H +#define CSVWIDGETTEST_H + +#include + +class CsvWidgetTest : public QObject +{ + Q_OBJECT +public: + explicit CsvWidgetTest(QObject *parent = 0); + ~CsvWidgetTest(); + +private Q_SLOTS: + void shouldHaveDefaultValue(); +}; + +#endif // CSVWIDGETTEST_H diff --git a/mailmerge/widgets/csvwidget.cpp b/mailmerge/widgets/csvwidget.cpp new file mode 100644 index 000000000..880691e80 --- /dev/null +++ b/mailmerge/widgets/csvwidget.cpp @@ -0,0 +1,56 @@ +/* + Copyright (c) 2015 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + 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 +*/ + +#include "csvwidget.h" + +#include +#include +#include +#include + +using namespace MailMerge; + +CsvWidget::CsvWidget(QWidget *parent) + : QWidget(parent) +{ + QVBoxLayout *csvWidgetLayout = new QVBoxLayout; + csvWidgetLayout->setMargin(0); + setLayout(csvWidgetLayout); + + QLabel *lab = new QLabel(i18n("Path:")); + lab->setObjectName(QLatin1String("label")); + csvWidgetLayout->addWidget(lab); + mCvsUrlRequester = new KUrlRequester; + mCvsUrlRequester->setObjectName(QLatin1String("cvsurlrequester")); + csvWidgetLayout->addWidget(mCvsUrlRequester); +} + +CsvWidget::~CsvWidget() +{ + +} + +void CsvWidget::setPath(const KUrl &path) +{ + mCvsUrlRequester->setUrl(path); +} + +KUrl CsvWidget::path() const +{ + return mCvsUrlRequester->url(); +} + diff --git a/mailmerge/widgets/csvwidget.h b/mailmerge/widgets/csvwidget.h new file mode 100644 index 000000000..6be4f0ae7 --- /dev/null +++ b/mailmerge/widgets/csvwidget.h @@ -0,0 +1,41 @@ +/* + Copyright (c) 2015 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + 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 +*/ + +#ifndef CSVWIDGET_H +#define CSVWIDGET_H + +#include + +class KUrlRequester; +class KUrl; +namespace MailMerge { +class CsvWidget : public QWidget +{ + Q_OBJECT +public: + explicit CsvWidget(QWidget *parent=0); + ~CsvWidget(); + + void setPath(const KUrl &path); + KUrl path() const; + +private: + KUrlRequester *mCvsUrlRequester; +}; +} + +#endif // CSVWIDGET_H diff --git a/mailmerge/widgets/mailmergewidget.cpp b/mailmerge/widgets/mailmergewidget.cpp index b43d62ba3..7f524d92c 100644 --- a/mailmerge/widgets/mailmergewidget.cpp +++ b/mailmerge/widgets/mailmergewidget.cpp @@ -16,6 +16,7 @@ */ #include "mailmergewidget.h" +#include "../widgets/csvwidget.h" #include "attachmentlistwidget.h" @@ -62,18 +63,10 @@ MailMergeWidget::MailMergeWidget(QWidget *parent) addressBookWidget->setLayout(addressBookWidgetLayout); mStackedWidget->addWidget(addressBookWidget); - QWidget *csvWidget = new QWidget; - csvWidget->setObjectName(QLatin1String("csvwidget")); - QVBoxLayout *csvWidgetLayout = new QVBoxLayout; - csvWidgetLayout->setMargin(0); - csvWidget->setLayout(csvWidgetLayout); + mCsvWidget = new MailMerge::CsvWidget; + mCsvWidget->setObjectName(QLatin1String("cvswidget")); - lab = new QLabel(i18n("Path:")); - csvWidgetLayout->addWidget(lab); - mCvsUrlRequester = new KUrlRequester; - csvWidgetLayout->addWidget(mCvsUrlRequester); - - mStackedWidget->addWidget(csvWidget); + mStackedWidget->addWidget(mCsvWidget); lab = new QLabel(i18n("Attachment:")); vbox->addWidget(lab); diff --git a/mailmerge/widgets/mailmergewidget.h b/mailmerge/widgets/mailmergewidget.h index 976c55ba1..11ad0f2c1 100644 --- a/mailmerge/widgets/mailmergewidget.h +++ b/mailmerge/widgets/mailmergewidget.h @@ -25,6 +25,7 @@ class QStackedWidget; class KUrlRequester; namespace MailMerge { +class CsvWidget; class AttachmentListWidget; class MailMergeWidget : public QWidget { @@ -48,7 +49,7 @@ private: KComboBox *mSource; QStackedWidget *mStackedWidget; AttachmentListWidget *mAttachment; - KUrlRequester *mCvsUrlRequester; + MailMerge::CsvWidget *mCsvWidget; }; } #endif // MAILMERGEWIDGET_H