Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a541c48c authored by Laurent Montel's avatar Laurent Montel 😁

Split widget from dialog

parent da7471d1
......@@ -77,7 +77,8 @@ set(kdepim_addressline_blacklist_baloo_LIB_SRCS
addressline/blacklistbaloocompletion/blacklistbalooemailcompletiondialog.cpp
addressline/blacklistbaloocompletion/blacklistbalooemaillist.cpp
addressline/blacklistbaloocompletion/blacklistbalooemailsearchjob.cpp
addressline/blacklistbaloocompletion/blacklistbalooemailutil.cpp
addressline/blacklistbaloocompletion/blacklistbalooemailutil.cpp
addressline/blacklistbaloocompletion/blacklistbalooemailcompletionwidget.cpp
)
set(kdepim_LIB_SRCS
......
......@@ -21,6 +21,7 @@
#include "blacklistbalooemailcompletiondialog.h"
#include "blacklistbalooemailsearchjob.h"
#include "blacklistbalooemaillist.h"
#include "blacklistbalooemailcompletionwidget.h"
#include "blacklistbalooemailutil.h"
#include <KLocalizedString>
#include <QHBoxLayout>
......@@ -39,58 +40,9 @@ BlackListBalooEmailCompletionDialog::BlackListBalooEmailCompletionDialog(QWidget
setButtons( Ok|Cancel );
setDefaultButton( Ok );
setModal( true );
mBlackListWidget = new BlackListBalooEmailCompletionWidget(this);
setMainWidget(mBlackListWidget);
QWidget *mainWidget = new QWidget( this );
setMainWidget(mainWidget);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainWidget->setLayout(mainLayout);
QHBoxLayout *searchLayout = new QHBoxLayout;
mainLayout->addLayout(searchLayout);
//Add i18n in kf5
QLabel *lab = new QLabel(QLatin1String("Search email:"));
lab->setObjectName(QLatin1String("search_label"));
searchLayout->addWidget(lab);
mSearchLineEdit = new KLineEdit;
mSearchLineEdit->setFocus();
mSearchLineEdit->setClearButtonShown(true);
mSearchLineEdit->setTrapReturnKey(true);
mSearchLineEdit->setObjectName(QLatin1String("search_lineedit"));
connect(mSearchLineEdit, SIGNAL(returnPressed()), this, SLOT(slotSearch()));
searchLayout->addWidget(mSearchLineEdit);
//Add i18n in kf5
mSearchButton = new KPushButton(QLatin1String("Search"));
mSearchButton->setObjectName(QLatin1String("search_button"));
connect(mSearchButton, SIGNAL(clicked()), this, SLOT(slotSearch()));
mSearchButton->setEnabled(false);
searchLayout->addWidget(mSearchButton);
mEmailList = new BlackListBalooEmailList;
mEmailList->setObjectName(QLatin1String("email_list"));
mainLayout->addWidget(mEmailList);
QHBoxLayout *selectElementLayout = new QHBoxLayout;
mainLayout->addLayout(selectElementLayout);
//Add i18n in kf5
KPushButton *button = new KPushButton(QLatin1String("&Select"), this);
button->setObjectName(QLatin1String("select_email"));
connect(button, SIGNAL(clicked(bool)), this, SLOT(slotSelectEmails()));
selectElementLayout->addWidget(button);
//Add i18n in kf5
button = new KPushButton(QLatin1String("&Unselect"), this);
button->setObjectName(QLatin1String("unselect_email"));
connect(button, SIGNAL(clicked(bool)), this, SLOT(slotUnselectEmails()));
selectElementLayout->addWidget(button);
selectElementLayout->addStretch(1);
connect(mSearchLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSearchLineEditChanged(QString)));
connect(this, SIGNAL(okClicked()), this, SLOT(slotSave()));
readConfig();
}
......@@ -100,28 +52,9 @@ BlackListBalooEmailCompletionDialog::~BlackListBalooEmailCompletionDialog()
writeConfig();
}
void BlackListBalooEmailCompletionDialog::slotUnselectEmails()
{
Q_FOREACH(QListWidgetItem *item, mEmailList->selectedItems()) {
item->setCheckState(Qt::Unchecked);
}
}
void BlackListBalooEmailCompletionDialog::slotSelectEmails()
{
Q_FOREACH(QListWidgetItem *item, mEmailList->selectedItems()) {
item->setCheckState(Qt::Checked);
}
}
void BlackListBalooEmailCompletionDialog::setEmailBlackList(const QStringList &list)
{
mEmailList->setEmailBlackList(list);
}
void BlackListBalooEmailCompletionDialog::slotSearchLineEditChanged(const QString &text)
{
mSearchButton->setEnabled(text.trimmed().count() > 2);
mBlackListWidget->setEmailBlackList(list);
}
void BlackListBalooEmailCompletionDialog::readConfig()
......@@ -141,29 +74,7 @@ void BlackListBalooEmailCompletionDialog::writeConfig()
void BlackListBalooEmailCompletionDialog::slotSave()
{
const QHash<QString, bool> result = mEmailList->blackListItemChanged();
if (!result.isEmpty()) {
KSharedConfig::Ptr config = KSharedConfig::openConfig( QLatin1String("kpimbalooblacklist") );
KConfigGroup group( config, "AddressLineEdit" );
QStringList blackList = group.readEntry( "BalooBackList", QStringList() );
KPIM::BlackListBalooEmailUtil util;
util.initialBlackList(blackList);
util.newBlackList(result);
blackList = util.createNewBlackList();
group.writeEntry( "BalooBackList", blackList );
group.sync();
}
mBlackListWidget->save();
accept();
}
void BlackListBalooEmailCompletionDialog::slotSearch()
{
const QString searchEmail = mSearchLineEdit->text().trimmed();
if (searchEmail.length() > 2 ) {
KPIM::BlackListBalooEmailSearchJob *job = new KPIM::BlackListBalooEmailSearchJob(this);
job->setSearchEmail(searchEmail);
connect(job, SIGNAL(emailsFound(QStringList)), mEmailList, SLOT(slotEmailFound(QStringList)));
job->start();
}
}
......@@ -23,10 +23,8 @@
#include <KDialog>
#include "kdepim_export.h"
class KLineEdit;
class KPushButton;
namespace KPIM {
class BlackListBalooEmailList;
class BlackListBalooEmailCompletionWidget;
class KDEPIM_EXPORT BlackListBalooEmailCompletionDialog : public KDialog
{
Q_OBJECT
......@@ -38,17 +36,10 @@ public:
private slots:
void slotSave();
void slotSearch();
void slotSearchLineEditChanged(const QString &text);
void slotUnselectEmails();
void slotSelectEmails();
private:
void writeConfig();
void readConfig();
KLineEdit *mSearchLineEdit;
BlackListBalooEmailList *mEmailList;
KPushButton *mSearchButton;
BlackListBalooEmailCompletionWidget *mBlackListWidget;
};
}
......
/*
Copyright (c) 2015 Montel Laurent <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 "blacklistbalooemailcompletionwidget.h"
#include "blacklistbalooemaillist.h"
#include "blacklistbalooemailsearchjob.h"
#include "blacklistbalooemailutil.h"
#include <KLocalizedString>
#include <KLineEdit>
#include <KPushButton>
#include <QBoxLayout>
#include <QLabel>
#include <KConfigGroup>
using namespace KPIM;
BlackListBalooEmailCompletionWidget::BlackListBalooEmailCompletionWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QHBoxLayout *searchLayout = new QHBoxLayout;
mainLayout->addLayout(searchLayout);
//Add i18n in kf5
QLabel *lab = new QLabel(QLatin1String("Search email:"));
lab->setObjectName(QLatin1String("search_label"));
searchLayout->addWidget(lab);
mSearchLineEdit = new KLineEdit;
mSearchLineEdit->setFocus();
mSearchLineEdit->setClearButtonShown(true);
mSearchLineEdit->setTrapReturnKey(true);
mSearchLineEdit->setObjectName(QLatin1String("search_lineedit"));
connect(mSearchLineEdit, SIGNAL(returnPressed()), this, SLOT(slotSearch()));
searchLayout->addWidget(mSearchLineEdit);
//Add i18n in kf5
mSearchButton = new KPushButton(QLatin1String("Search"));
mSearchButton->setObjectName(QLatin1String("search_button"));
connect(mSearchButton, SIGNAL(clicked()), this, SLOT(slotSearch()));
mSearchButton->setEnabled(false);
searchLayout->addWidget(mSearchButton);
mEmailList = new BlackListBalooEmailList;
mEmailList->setObjectName(QLatin1String("email_list"));
mainLayout->addWidget(mEmailList);
QHBoxLayout *selectElementLayout = new QHBoxLayout;
mainLayout->addLayout(selectElementLayout);
//Add i18n in kf5
KPushButton *button = new KPushButton(QLatin1String("&Select"), this);
button->setObjectName(QLatin1String("select_email"));
connect(button, SIGNAL(clicked(bool)), this, SLOT(slotSelectEmails()));
selectElementLayout->addWidget(button);
//Add i18n in kf5
button = new KPushButton(QLatin1String("&Unselect"), this);
button->setObjectName(QLatin1String("unselect_email"));
connect(button, SIGNAL(clicked(bool)), this, SLOT(slotUnselectEmails()));
selectElementLayout->addWidget(button);
selectElementLayout->addStretch(1);
connect(mSearchLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSearchLineEditChanged(QString)));
}
BlackListBalooEmailCompletionWidget::~BlackListBalooEmailCompletionWidget()
{
}
void BlackListBalooEmailCompletionWidget::slotUnselectEmails()
{
Q_FOREACH(QListWidgetItem *item, mEmailList->selectedItems()) {
item->setCheckState(Qt::Unchecked);
}
}
void BlackListBalooEmailCompletionWidget::slotSelectEmails()
{
Q_FOREACH(QListWidgetItem *item, mEmailList->selectedItems()) {
item->setCheckState(Qt::Checked);
}
}
void BlackListBalooEmailCompletionWidget::slotSearchLineEditChanged(const QString &text)
{
mSearchButton->setEnabled(text.trimmed().count() > 2);
}
void BlackListBalooEmailCompletionWidget::slotSearch()
{
const QString searchEmail = mSearchLineEdit->text().trimmed();
if (searchEmail.length() > 2 ) {
KPIM::BlackListBalooEmailSearchJob *job = new KPIM::BlackListBalooEmailSearchJob(this);
job->setSearchEmail(searchEmail);
connect(job, SIGNAL(emailsFound(QStringList)), mEmailList, SLOT(slotEmailFound(QStringList)));
job->start();
}
}
void BlackListBalooEmailCompletionWidget::setEmailBlackList(const QStringList &list)
{
mEmailList->setEmailBlackList(list);
}
void BlackListBalooEmailCompletionWidget::save()
{
const QHash<QString, bool> result = mEmailList->blackListItemChanged();
if (!result.isEmpty()) {
KSharedConfig::Ptr config = KSharedConfig::openConfig( QLatin1String("kpimbalooblacklist") );
KConfigGroup group( config, "AddressLineEdit" );
QStringList blackList = group.readEntry( "BalooBackList", QStringList() );
KPIM::BlackListBalooEmailUtil util;
util.initialBlackList(blackList);
util.newBlackList(result);
blackList = util.createNewBlackList();
group.writeEntry( "BalooBackList", blackList );
group.sync();
}
}
/*
Copyright (c) 2015 Montel Laurent <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 BLACKLISTBALOOEMAILCOMPLETIONWIDGET_H
#define BLACKLISTBALOOEMAILCOMPLETIONWIDGET_H
#include <QWidget>
class KPushButton;
class KLineEdit;
namespace KPIM {
class BlackListBalooEmailList;
class BlackListBalooEmailCompletionWidget : public QWidget
{
Q_OBJECT
public:
explicit BlackListBalooEmailCompletionWidget(QWidget *parent=0);
~BlackListBalooEmailCompletionWidget();
void save();
void setEmailBlackList(const QStringList &list);
private slots:
void slotUnselectEmails();
void slotSelectEmails();
void slotSearchLineEditChanged(const QString &text);
void slotSearch();
private:
KLineEdit *mSearchLineEdit;
BlackListBalooEmailList *mEmailList;
KPushButton *mSearchButton;
};
}
#endif // BLACKLISTBALOOEMAILCOMPLETIONWIDGET_H
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