Commit 2e6c721d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move in pimcommon. bye bye libkdepimakonadi

parent 0aac1b42
Pipeline #23734 passed with stage
in 13 minutes and 46 seconds
......@@ -50,15 +50,6 @@ find_package(KF5AkonadiContact ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Contacts ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5Ldap ${KLDAP_LIB_VERSION} CONFIG REQUIRED)
option(FORCE_DISABLE_AKONADI_SEARCH "Disable features and API that require akonadi-search, e.g. because xapian isn't available" OFF)
if (NOT FORCE_DISABLE_AKONADI_SEARCH)
find_package(KF5AkonadiSearch ${AKONADISEARCH_LIB_VERSION} CONFIG REQUIRED)
set_package_properties(KF5AkonadiSearch PROPERTIES DESCRIPTION "The Akonadi Search libraries" URL "https://www.kde.org" TYPE REQUIRED PURPOSE "Provides search capabilities in KMail and Akonadi")
endif()
set(DISABLE_AKONADI_SEARCH ${FORCE_DISABLE_AKONADI_SEARCH})
configure_file(config-akonadi-search.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config-akonadi-search.h)
option(BUILD_DESIGNERPLUGIN "Build plugin for Qt Designer" ON)
add_feature_info(DESIGNERPLUGIN ${BUILD_DESIGNERPLUGIN} "Build plugin for Qt Designer")
......
#cmakedefine01 DISABLE_AKONADI_SEARCH
......@@ -11,7 +11,5 @@ irc: akonadi
libraries:
- qmake: Libkdepim
cmake: "KF5::Libkdepim"
- qmake: LibkdepimAkonadi
cmake: "KF5::LibkdepimAkonadi"
cmakename: KF5Libkdepim
......@@ -5,4 +5,3 @@ if(BUILD_TESTING)
endif()
add_subdirectory(libkdepim)
add_subdirectory(libkdepimakonadi)
......@@ -8,7 +8,6 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX LIBKDEPIM
if (BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(misc/autotests)
add_subdirectory(addressline/autotests/)
add_subdirectory(progresswidget/autotests/)
add_subdirectory(progresswidget/tests/)
endif()
......@@ -41,19 +40,11 @@ set(kdepim_multiplyingline_LIB_SRCS
multiplyingline/multiplyinglineview_p.cpp
)
set(kdepim_addressline_LIB_SRCS
addressline/recentaddress/recentaddresswidget.cpp
addressline/recentaddress/recentaddresses.cpp
addressline/addresslineedit/addresseelineeditutil.cpp
)
set(kdepim_LIB_SRCS
${kdepim_progresswidget_LIB_SRCS}
${kdepim_widgets_LIB_SRCS}
${kdepim_misc_LIB_SRCS}
${kdepim_multiplyingline_LIB_SRCS}
${kdepim_addressline_LIB_SRCS}
prefs/kprefsdialog.cpp
)
ecm_qt_declare_logging_category(kdepim_LIB_SRCS HEADER libkdepim_debug.h IDENTIFIER LIBKDEPIM_LOG CATEGORY_NAME org.kde.pim.libkdepim
......@@ -149,25 +140,6 @@ ecm_generate_headers(libkdepim_Camelcasemultiline_HEADERS
RELATIVE multiplyingline
)
ecm_generate_headers(libkdepim_Camelcaserecentaddress_HEADERS
HEADER_NAMES
RecentAddresses
REQUIRED_HEADERS libkdepim_recentaddress_HEADERS
PREFIX Libkdepim
RELATIVE addressline/recentaddress/
)
ecm_generate_headers(libkdepim_Camelcaseaddressline_HEADERS
HEADER_NAMES
AddresseeLineEditUtil
REQUIRED_HEADERS libkdepim_addressline_HEADERS
PREFIX Libkdepim
RELATIVE addressline/addresslineedit/
)
ecm_generate_pri_file(BASE_NAME Libkdepim
LIB_NAME KF5Libkdepim
DEPS "" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/Libkdepim
......@@ -180,8 +152,6 @@ install(FILES
${libkdepim_Camelcasemisc_HEADERS}
${libkdepim_Camelcasepref_HEADERS}
${libkdepim_Camelcasemultiline_HEADERS}
${libkdepim_Camelcaserecentaddress_HEADERS}
${libkdepim_Camelcaseaddressline_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/Libkdepim
COMPONENT Devel
)
......@@ -194,8 +164,6 @@ install(FILES
${libkdepim_widgets_HEADERS}
${libkdepim_pref_HEADERS}
${libkdepim_multiline_HEADERS}
${libkdepim_recentaddress_HEADERS}
${libkdepim_addressline_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/libkdepim
COMPONENT Devel
)
......
/*
Copyright (C) 2016-2020 Laurent Montel <montel@kde.org>
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 "addresseelineeditutil.h"
#include <QRegularExpression>
#include <QUrl>
QString KPIM::AddresseeLineEditUtil::adaptPasteMails(const QString &str)
{
QString newText = str;
// remove newlines in the to-be-pasted string
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList lines = newText.split(QRegularExpression(QStringLiteral("\r?\n")), QString::SkipEmptyParts);
#else
QStringList lines = newText.split(QRegularExpression(QStringLiteral("\r?\n")), Qt::SkipEmptyParts);
#endif
QStringList::iterator end(lines.end());
for (QStringList::iterator it = lines.begin(); it != end; ++it) {
// remove trailing commas and whitespace
(*it).remove(QRegularExpression(QStringLiteral(",?\\s*$")));
}
newText = lines.join(QLatin1String(", "));
if (newText.startsWith(QLatin1String("mailto:"))) {
const QUrl url(newText);
newText = url.path();
} else if (newText.contains(QLatin1String(" at "))) {
// Anti-spam stuff
newText.replace(QStringLiteral(" at "), QStringLiteral("@"));
newText.replace(QStringLiteral(" dot "), QStringLiteral("."));
} else if (newText.contains(QLatin1String("(at)"))) {
newText.replace(QRegularExpression(QStringLiteral("\\s*\\(at\\)\\s*")), QStringLiteral("@"));
}
return newText;
}
/*
Copyright (C) 2016-2020 Laurent Montel <montel@kde.org>
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.
*/
#ifndef ADDRESSEELINEEDITUTIL_H
#define ADDRESSEELINEEDITUTIL_H
#include <QString>
#include "kdepim_export.h"
namespace KPIM {
/**
* @brief The AddresseeLineEditUtil class
* @author Laurent Montel <montel@kde.org>
*/
class KDEPIM_EXPORT AddresseeLineEditUtil
{
public:
static QString adaptPasteMails(const QString &str);
};
}
#endif // ADDRESSEELINEEDITUTIL_H
macro(add_libkdepim_addressline_unittest _name)
ecm_add_test(${ARGN}
TEST_NAME ${_name}
NAME_PREFIX "libkdepim-addressline-"
LINK_LIBRARIES Qt5::Test
KF5::Contacts
Qt5::Widgets
KF5::LibkdepimAkonadi
Qt5::DBus
KF5::Codecs
KF5::ConfigCore
KF5::Completion
KF5::I18n
KF5::WidgetsAddons
)
endmacro()
add_libkdepim_addressline_unittest(recentaddresswidgettest
recentaddresswidgettest.cpp
)
add_libkdepim_addressline_unittest(addresseelineeditutiltest
addresseelineeditutiltest.cpp
)
/*
Copyright (C) 2016-2020 Laurent Montel <montel@kde.org>
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 "addresseelineeditutiltest.h"
#include "../addresslineedit/addresseelineeditutil.h"
#include <QTest>
AddresseeLineEditUtilTest::AddresseeLineEditUtilTest(QObject *parent)
: QObject(parent)
{
}
AddresseeLineEditUtilTest::~AddresseeLineEditUtilTest()
{
}
void AddresseeLineEditUtilTest::shouldAdaptPasteMails_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::newRow("empty") << QString() << QString();
QTest::newRow("onemail") << QStringLiteral("foo@kde.org") << QStringLiteral("foo@kde.org");
QTest::newRow("onemailwithat") << QStringLiteral("foo (at) kde.org") << QStringLiteral("foo@kde.org");
QTest::newRow("text") << QStringLiteral("fookde.org") << QStringLiteral("fookde.org");
QTest::newRow("onemailwithdot") << QStringLiteral("foo at kde dot org") << QStringLiteral("foo@kde.org");
QTest::newRow("mailto") << QStringLiteral("mailto:foo@kde.org") << QStringLiteral("foo@kde.org");
QTest::newRow("multimail") << QStringLiteral("foo@kde.org,\r\n bla@kde.org,blo@kde.org") << QStringLiteral("foo@kde.org, bla@kde.org,blo@kde.org");
QTest::newRow("multimail-2") << QStringLiteral("foo@kde.org,\r\n bla@kde.org,blo@kde.org, ") << QStringLiteral("foo@kde.org, bla@kde.org,blo@kde.org");
QTest::newRow("multimail-3") << QStringLiteral("foo@kde.org,\r\n bla@kde.org,blo@kde.org,\n") << QStringLiteral("foo@kde.org, bla@kde.org,blo@kde.org");
QTest::newRow("multimail-4") << QStringLiteral("foo@kde.org,\r\n bla@kde.org,blo@kde.org, \n") << QStringLiteral("foo@kde.org, bla@kde.org,blo@kde.org");
QTest::newRow("multimail-5") << QStringLiteral("foo (at) kde.org,\r\n bla (at) kde.org,blo (at) kde.org") << QStringLiteral("foo@kde.org, bla@kde.org,blo@kde.org");
QTest::newRow("multimail-6") << QStringLiteral("mailto:foo@kde.org,\r\n bla@kde.org,blo@kde.org") << QStringLiteral("foo@kde.org, bla@kde.org,blo@kde.org");
QTest::newRow("multimail-7") << QStringLiteral("bla <foo@kde.org>,\r\n bli <bla@kde.org>,blo <blo@kde.org>") << QStringLiteral("bla <foo@kde.org>, bli <bla@kde.org>,blo <blo@kde.org>");
QTest::newRow("multimail-8") << QStringLiteral("\"bla, v\" <foo@kde.org>,\r\n \"bli, u\" <bla@kde.org>,\"blo, k\" <blo@kde.org>") << QStringLiteral(
"\"bla, v\" <foo@kde.org>, \"bli, u\" <bla@kde.org>,\"blo, k\" <blo@kde.org>");
}
void AddresseeLineEditUtilTest::shouldAdaptPasteMails()
{
QFETCH(QString, input);
QFETCH(QString, output);
QCOMPARE(KPIM::AddresseeLineEditUtil::adaptPasteMails(input), output);
}
QTEST_MAIN(AddresseeLineEditUtilTest)
/*
Copyright (C) 2016-2020 Laurent Montel <montel@kde.org>
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.
*/
#ifndef ADDRESSEELINEEDITUTILTEST_H
#define ADDRESSEELINEEDITUTILTEST_H
#include <QObject>
class AddresseeLineEditUtilTest : public QObject
{
Q_OBJECT
public:
explicit AddresseeLineEditUtilTest(QObject *parent = nullptr);
~AddresseeLineEditUtilTest();
private Q_SLOTS:
void shouldAdaptPasteMails_data();
void shouldAdaptPasteMails();
};
#endif // ADDRESSEELINEEDITUTILTEST_H
/*
Copyright (c) 2015-2020 Laurent Montel <montel@kde.org>
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 "recentaddresswidgettest.h"
#include "../recentaddress/recentaddresswidget.h"
#include <QLineEdit>
#include <QToolButton>
#include <QListWidget>
#include <QTest>
#include <qtestmouse.h>
RecentAddressWidgetTest::RecentAddressWidgetTest(QObject *parent)
: QObject(parent)
{
}
RecentAddressWidgetTest::~RecentAddressWidgetTest()
{
}
void RecentAddressWidgetTest::shouldHaveDefaultValue()
{
KPIM::RecentAddressWidget w;
QLineEdit *lineedit = w.findChild<QLineEdit *>(QStringLiteral("line_edit"));
QVERIFY(lineedit);
QVERIFY(lineedit->isClearButtonEnabled());
QVERIFY(lineedit->text().isEmpty());
QToolButton *newButton = w.findChild<QToolButton *>(QStringLiteral("new_button"));
QVERIFY(newButton);
QToolButton *removeButton = w.findChild<QToolButton *>(QStringLiteral("remove_button"));
QVERIFY(removeButton);
QVERIFY(!removeButton->isEnabled());
QListWidget *listview = w.findChild<QListWidget *>(QStringLiteral("list_view"));
QVERIFY(listview);
QCOMPARE(listview->count(), 0);
}
void RecentAddressWidgetTest::shouldAddAddresses()
{
KPIM::RecentAddressWidget w;
QListWidget *listview = w.findChild<QListWidget *>(QStringLiteral("list_view"));
QCOMPARE(listview->count(), 0);
QStringList lst;
lst << QStringLiteral("foo");
lst << QStringLiteral("foo1");
lst << QStringLiteral("foo2");
w.setAddresses(lst);
QCOMPARE(listview->count(), lst.count());
//Clear list before to add
w.setAddresses(lst);
QCOMPARE(listview->count(), lst.count());
}
void RecentAddressWidgetTest::shouldInformThatItWasChanged()
{
KPIM::RecentAddressWidget w;
QVERIFY(!w.wasChanged());
QLineEdit *lineedit = w.findChild<QLineEdit *>(QStringLiteral("line_edit"));
lineedit->setText(QStringLiteral("foo"));
QToolButton *newButton = w.findChild<QToolButton *>(QStringLiteral("new_button"));
QVERIFY(newButton);
QVERIFY(newButton->isEnabled());
QTest::mouseClick(newButton, Qt::LeftButton);
QVERIFY(w.wasChanged());
QListWidget *listview = w.findChild<QListWidget *>(QStringLiteral("list_view"));
QCOMPARE(listview->count(), 1);
}
void RecentAddressWidgetTest::shouldNotAddMultiSameLine()
{
KPIM::RecentAddressWidget w;
QLineEdit *lineedit = w.findChild<QLineEdit *>(QStringLiteral("line_edit"));
QToolButton *newButton = w.findChild<QToolButton *>(QStringLiteral("new_button"));
QListWidget *listview = w.findChild<QListWidget *>(QStringLiteral("list_view"));
QCOMPARE(listview->count(), 0);
lineedit->setText(QStringLiteral("foo"));
QVERIFY(newButton->isEnabled());
QTest::mouseClick(newButton, Qt::LeftButton);
QCOMPARE(listview->count(), 1);
QTest::mouseClick(newButton, Qt::LeftButton);
QCOMPARE(listview->count(), 1);
}
void RecentAddressWidgetTest::shouldNotAddEmptyLine()
{
KPIM::RecentAddressWidget w;
QLineEdit *lineedit = w.findChild<QLineEdit *>(QStringLiteral("line_edit"));
QToolButton *newButton = w.findChild<QToolButton *>(QStringLiteral("new_button"));
QListWidget *listview = w.findChild<QListWidget *>(QStringLiteral("list_view"));
QCOMPARE(listview->count(), 0);
QVERIFY(lineedit->text().isEmpty());
QVERIFY(!newButton->isEnabled());
QTest::mouseClick(newButton, Qt::LeftButton);
QCOMPARE(listview->count(), 0);
QTest::mouseClick(newButton, Qt::LeftButton);
QCOMPARE(listview->count(), 0);
lineedit->setText(QStringLiteral("foo"));
QTest::mouseClick(newButton, Qt::LeftButton);
QCOMPARE(listview->count(), 1);
}
void RecentAddressWidgetTest::shouldDisableAddButton()
{
KPIM::RecentAddressWidget w;
QLineEdit *lineedit = w.findChild<QLineEdit *>(QStringLiteral("line_edit"));
QToolButton *newButton = w.findChild<QToolButton *>(QStringLiteral("new_button"));
lineedit->setText(QStringLiteral("foo"));
QVERIFY(newButton->isEnabled());
lineedit->clear();
QVERIFY(!newButton->isEnabled());
}
QTEST_MAIN(RecentAddressWidgetTest)
/*
Copyright (c) 2015-2020 Laurent Montel <montel@kde.org>
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.
*/
#ifndef RECENTADDRESSWIDGETTEST_H
#define RECENTADDRESSWIDGETTEST_H
#include <QObject>
class RecentAddressWidgetTest : public QObject
{
Q_OBJECT
public:
explicit RecentAddressWidgetTest(QObject *parent = nullptr);
~RecentAddressWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddAddresses();
void shouldInformThatItWasChanged();
void shouldNotAddMultiSameLine();
void shouldNotAddEmptyLine();
void shouldDisableAddButton();
};
#endif // RECENTADDRESSWIDGETTEST_H
/*
*
* Copyright (c) 2001-2003 Carsten Pfeiffer <pfeiffer@kde.org>
* Copyright (c) 2003 Zack Rusin <zack@kde.org>
*
* KMail 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.
*
* KMail 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
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of this program with any edition of
* the Qt library by Trolltech AS, Norway (or with modified versions
* of Qt that use the same license as Qt), and distribute linked
* combinations including the two. You must obey the GNU General
* Public License in all respects for all of the code used other than
* Qt. If you modify this file, you may extend this exception to
* your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from
* your version.
*/
#include "recentaddresses.h"
#include <KEmailAddress>
#include <KConfig>
#include <KConfigGroup>
#include "libkdepim_debug.h"
#include <KSharedConfig>
#include <QCoreApplication>
using namespace KPIM;
RecentAddresses *s_self = nullptr;
void deleteGlobalRecentAddresses()
{
delete s_self;
s_self = nullptr;
}
RecentAddresses *RecentAddresses::self(KConfig *config)
{
if (!s_self) {
s_self = new RecentAddresses(config);
qAddPostRoutine(deleteGlobalRecentAddresses);
}
return s_self;
}
bool RecentAddresses::exists()
{
return s_self != nullptr;
}
RecentAddresses::RecentAddresses(KConfig *config)
{
if (!config) {
load(KSharedConfig::openConfig().data());
} else {
load(config);
}
}
RecentAddresses::~RecentAddresses()
{
}
void RecentAddresses::load(KConfig *config)
{
QStringList addresses;
QString name;
QString email;
m_addresseeList.clear();
KConfigGroup cg(config, "General");
m_maxCount = cg.readEntry("Maximum Recent Addresses", 200);
addresses = cg.readEntry("Recent Addresses", QStringList());