Commit 8dfd4a10 authored by Laurent Montel's avatar Laurent Montel 😁

Split code

parent 036cf112
......@@ -24,6 +24,8 @@ include_directories(
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
set(libmailcommon_filter_SRCS
filter/kmfilteraccountlist.cpp
filter/kmfilterlistbox.cpp
filter/filterselectiondialog.cpp
filter/filterconverter/filterconverttosieve.cpp
filter/filterconverter/filterconverttosieveresultdialog.cpp
......
......@@ -17,7 +17,7 @@
*/
#include "filteractionmissingargumentdialog.h"
#include "kmfilterdialog.h"
#include "kmfilteraccountlist.h"
#include "folderrequester.h"
#include "kernel/mailkernel.h"
#include "util/mailutil.h"
......@@ -361,7 +361,7 @@ FilterActionMissingAccountDialog::FilterActionMissingAccountDialog( const QStrin
filtername ) );
label->setWordWrap(true);
lay->addWidget( label );
mAccountList = new MailCommon::AccountList( this );
mAccountList = new MailCommon::KMFilterAccountList( this );
mAccountList->applyOnAccount( lstAccount );
lay->addWidget( mAccountList );
readConfig();
......
......@@ -35,7 +35,7 @@ class QModelIndex;
namespace MailCommon {
class FolderRequester;
class AccountList;
class KMFilterAccountList;
}
namespace KPIMIdentities {
......@@ -141,7 +141,7 @@ public:
private:
void readConfig();
void writeConfig();
MailCommon::AccountList *mAccountList;
MailCommon::KMFilterAccountList *mAccountList;
};
class FilterActionMissingTagDialog : public KDialog
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
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 "kmfilteraccountlist.h"
#include "mailfilter.h"
#include "util/mailutil.h"
#include <Akonadi/AgentInstance>
#include <Akonadi/AgentType>
#include <KLocalizedString>
#include <QHeaderView>
using namespace MailCommon;
KMFilterAccountList::KMFilterAccountList( QWidget *parent )
: QTreeWidget( parent )
{
setColumnCount( 2 );
QStringList headerNames;
headerNames << i18n( "Account Name" ) << i18n( "Type" );
setHeaderItem( new QTreeWidgetItem( headerNames ) );
setAllColumnsShowFocus( true );
setFrameStyle( QFrame::WinPanel + QFrame::Sunken );
setSortingEnabled( false );
setRootIsDecorated( false );
setSortingEnabled( true );
sortByColumn( 0, Qt::AscendingOrder );
header()->setMovable( false );
}
KMFilterAccountList::~KMFilterAccountList()
{
}
void KMFilterAccountList::updateAccountList( MailCommon::MailFilter *filter )
{
clear();
QTreeWidgetItem *top = 0;
// Block the signals here, otherwise we end up calling
// slotApplicableAccountsChanged(), which will read the incomplete item
// state and write that back to the filter
blockSignals( true );
const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances();
const int nbAccount = lst.count();
for ( int i = 0; i <nbAccount; ++i ) {
const Akonadi::AgentInstance agent = lst.at( i );
QTreeWidgetItem *listItem = new QTreeWidgetItem( this, top );
listItem->setText( 0, agent.name() );
listItem->setText( 1, agent.type().name() );
listItem->setText( 2, agent.identifier() );
if ( filter ) {
listItem->setCheckState( 0,
filter->applyOnAccount( agent.identifier() ) ?
Qt::Checked :
Qt::Unchecked );
}
top = listItem;
}
blockSignals( false );
// make sure our hidden column is really hidden (Qt tends to re-show it)
hideColumn( 2 );
resizeColumnToContents( 0 );
resizeColumnToContents( 1 );
top = topLevelItem( 0 );
if ( top ) {
setCurrentItem( top );
}
}
void KMFilterAccountList::applyOnAccount( MailCommon::MailFilter *filter )
{
QTreeWidgetItemIterator it( this );
while ( QTreeWidgetItem *item = *it ) {
const QString id = item->text( 2 );
filter->setApplyOnAccount( id, item->checkState( 0 ) == Qt::Checked );
++it;
}
}
void KMFilterAccountList::applyOnAccount( const QStringList &lstAccount )
{
clear();
QTreeWidgetItem *top = 0;
// Block the signals here, otherwise we end up calling
// slotApplicableAccountsChanged(), which will read the incomplete item
// state and write that back to the filter
blockSignals( true );
const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances();
const int nbAccount = lst.count();
for ( int i = 0; i <nbAccount; ++i ) {
const Akonadi::AgentInstance agent = lst.at( i );
QTreeWidgetItem *listItem = new QTreeWidgetItem( this, top );
listItem->setText( 0, agent.name() );
listItem->setText( 1, agent.type().name() );
listItem->setText( 2, agent.identifier() );
listItem->setCheckState( 0, lstAccount.contains( agent.identifier() ) ?
Qt::Checked : Qt::Unchecked );
top = listItem;
}
blockSignals( false );
// make sure our hidden column is really hidden (Qt tends to re-show it)
hideColumn( 2 );
resizeColumnToContents( 0 );
resizeColumnToContents( 1 );
top = topLevelItem( 0 );
if ( top ) {
setCurrentItem( top );
}
}
QStringList KMFilterAccountList::selectedAccount()
{
QStringList lstAccount;
QTreeWidgetItemIterator it( this );
while ( QTreeWidgetItem *item = *it ) {
if ( item->checkState( 0 ) == Qt::Checked ) {
lstAccount << item->text( 2 );
}
++it;
}
return lstAccount;
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
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 KMFILTERACCOUNTLIST_H
#define KMFILTERACCOUNTLIST_H
#include <QTreeWidget>
namespace MailCommon {
class MailFilter;
class KMFilterAccountList : public QTreeWidget
{
public:
explicit KMFilterAccountList( QWidget *parent );
~KMFilterAccountList();
void updateAccountList( MailCommon::MailFilter *filter );
void applyOnAccount( MailCommon::MailFilter *filter );
void applyOnAccount( const QStringList &lst );
QStringList selectedAccount();
};
}
#endif // KMFILTERACCOUNTLIST_H
This diff is collapsed.
......@@ -51,237 +51,12 @@ namespace MailCommon {
class SearchPatternEdit;
class FilterActionWidgetLister;
class FolderRequester;
class KMFilterAccountList;
class KMFilterListBox;
}
class KJob;
/**
* This is a complex widget that is used to manipulate a mail program's filter
* list. It consists of an internal list of filters, which is a deep
* copy of the list KMFilterMgr manages, a QListBox displaying that list,
* and a few buttons used to create new filters, delete them, rename them
* and change the order of filters.
*
* It does not provide means to change the actual filter (besides the name),
* but relies on auxiliary widgets (SearchPatternEdit and KMFilterActionEdit)
* to do that.
*
* Communication with this widget is quite easy: simply create an instance,
* connect the signals filterSelected, resetWidgets and applyWidgets with
* a slot that does the right thing and there you go...
*
* This widget will operate on it's own copy of the filter list as
* long as you don't call slotApplyFilterChanges. It will then
* transfer the altered filter list back to KMFilterMgr.
*
* @short A complex widget that allows managing a list of MailCommon::MailFilter's.
* @author Marc Mutz <mutz@kde.org>, based upon work by Stefan Taferner <taferner@kde.org>.
* @see MailCommon::MailFilter KMFilterDialog KMFilterActionEdit SearchPatternEdit
*/
namespace MailCommon {
class AccountList : public QTreeWidget
{
public:
explicit AccountList( QWidget *parent );
~AccountList();
void updateAccountList( MailCommon::MailFilter *filter );
void applyOnAccount( MailCommon::MailFilter *filter );
void applyOnAccount( const QStringList &lst );
QStringList selectedAccount();
};
class MAILCOMMON_EXPORT KMFilterListBox : public QGroupBox
{
Q_OBJECT
public:
/**
* Constructor.
*/
explicit KMFilterListBox( const QString &title, QWidget *parent = 0 );
/**
* Destructor.
*/
~KMFilterListBox();
/**
* Called from KMFilterDialog. Creates a new filter and presets
* the first rule with "field equals value". It's there mainly to
* support "rapid filter creation" from a context menu. You should
* instead call KMFilterMgr::createFilter.
* @see KMFilterMgr::createFilter KMFilterDialog::createFilter
*/
void createFilter( const QByteArray &field, const QString &value );
/**
* Loads the filter list and selects the first filter. Should be
* called when all signals are connected properly. If createDummyFilter
* is true, an empty filter is created to improve the usability of the
* dialog in case no filter has been defined so far.
*/
void loadFilterList( bool createDummyFilter );
void insertFilter( MailCommon::MailFilter *aFilter );
void appendFilter( MailCommon::MailFilter *aFilter );
/**
* Returns a list of _copies_ of the current list of filters.
* The list owns the contents and thus the caller needs to clean them up.
* @param closeAfterSaving If true user is given option to continue editing
* after being warned about invalid filters. Otherwise, user is just warned.
*/
QList<MailCommon::MailFilter *> filtersForSaving( bool closeAfterSaving ) const;
QStringList selectedFilterId( SearchRule::RequiredPart &requiredPart, const QString& resource ) const;
signals:
/**
* Emitted when a new filter has been selected by the user or if the
* current filter has changed after a 'new' or 'delete' operation.
*/
void filterSelected( MailCommon::MailFilter *filter );
/**
* Emitted when this widget wants the edit widgets to let go of
* their filter reference. Everyone holding a reference to a filter
* should update it from the contents of the widgets used to edit
* it and set their internal reference to 0.
*/
void resetWidgets();
/**
* Emitted when this widget wants the edit widgets to apply the changes
* to the current filter.
*/
void applyWidgets();
/**
* Emitted when the user decides to continue editing after being warned
* about invalid filters.
*/
void abortClosing() const;
/**
* Emitted when a new filter is created.
*/
void filterCreated();
/**
* Emitted when a filter is deleted.
*/
void filterRemoved( const QList<MailCommon::MailFilter *> &filter );
/**
* Emitted when a filter is updated (e.g. renamed).
*/
void filterUpdated( MailCommon::MailFilter *filter );
/**
* Emitted whenever the order in which the filters are displayed is changed.
*/
void filterOrderAltered();
public slots:
/**
* Called when the name of a filter might have changed (e.g. through
* changing the first rule in SearchPatternEdit). Updates the corresponding
* entry in the listbox and (if necessary) auto-names the filter.
*/
void slotUpdateFilterName();
/**
* Called when the user clicks either 'Apply' or 'OK' in
* KMFilterDialog. Updates the filter list in the FilterManager.
*/
void slotApplyFilterChanges( KDialog::ButtonCode );
protected slots:
/**
* Called when the user clicks on a filter in the filter list.
* Calculates the corresponding filter and emits the filterSelected signal.
*/
void slotSelected( int aIdx );
/**
* Called when the user clicks the 'New' button.
* Creates a new empty filter just before the current one.
*/
void slotNew();
/**
* Called when the user clicks the 'Copy' button. Creates a copy
* of the current filter and inserts it just before the current one.
*/
void slotCopy();
/**
* Called when the user clicks the 'Delete' button. Deletes the
* current filter.
*/
void slotDelete();
/**
* Called when the user clicks the 'Up' button. Moves the current
* filter up one line.
*/
void slotUp();
/**
* Called when the user clicks the 'Down' button. Moves the current
* filter down one line.
*/
void slotDown();
/**
* Called when the user clicks the 'Rename' button. Pops up a
* dialog prompting to enter the new name.
*/
void slotRename();
void slotRowsMoved( const QModelIndex &, int, int, const QModelIndex &, int );
/**
* Called when the user clicks the 'Top' button. Moves the current
* filter to top.
*/
void slotTop();
/**
* Called when the user clicks the 'Bottom' button. Moves the current
* filter to bottom.
*/
void slotBottom();
void slotFilterEnabledChanged( QListWidgetItem *item );
void slotSelectionChanged();
protected:
/** The listbox displaying the filter list. */
QListWidget *mListWidget;
/** The various action buttons. */
QPushButton *mBtnNew;
QPushButton *mBtnCopy;
QPushButton *mBtnDelete;
QPushButton *mBtnUp;
QPushButton *mBtnDown;
QPushButton *mBtnRename;
QPushButton *mBtnTop;
QPushButton *mBtnBottom;
private:
void enableControls();
bool itemIsValid( QListWidgetItem *item ) const;
QList<QListWidgetItem*> selectedFilter();
void swapNeighbouringFilters( int untouchedOne, int movedOne );
};
/**
* The filter dialog. This is a non-modal dialog used to manage the filters.
* It should only be called through KMFilterMgr::openDialog. The dialog
......@@ -336,6 +111,7 @@ private:
* @author Marc Mutz <mutz@kde.org>, based upon work by Stefan Taferner <taferner@kde.org>.
* @see MailCommon::MailFilter KMFilterActionEdit SearchPatternEdit KMFilterListBox
*/
namespace MailCommon {
class MAILCOMMON_EXPORT KMFilterDialog : public KDialog
{
Q_OBJECT
......@@ -355,10 +131,7 @@ public:
* KMFilterListBox::createFilter. You should instead call
* KMFilterMgr::createFilter.
*/
void createFilter( const QByteArray &field, const QString &value )
{
mFilterList->createFilter( field, value );
}
void createFilter( const QByteArray &field, const QString &value );
public slots:
/**
......@@ -458,7 +231,7 @@ protected:
QRadioButton *mApplyOnForAll, *mApplyOnForTraditional, *mApplyOnForChecked;
/** ListView that shows the accounts in the advanced tab */
AccountList *mAccountList;
KMFilterAccountList *mAccountList;
QCheckBox *mStopProcessingHere;
QCheckBox *mConfigureShortcut;
......@@ -475,19 +248,6 @@ protected:
bool mIgnoreFilterUpdates;
};
class QListWidgetFilterItem : public QListWidgetItem
{
public:
explicit QListWidgetFilterItem( const QString &text, QListWidget *parent = 0 );
~QListWidgetFilterItem();
void setFilter( MailCommon::MailFilter *filter );
MailCommon::MailFilter *filter();
private:
MailCommon::MailFilter *mFilter;
};
}
#endif /*kmfilterdialog_h*/
This diff is collapsed.
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
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 KMFILTERLISTBOX_H
#define KMFILTERLISTBOX_H
#include "mailcommon_export.h"
#include "search/searchpattern.h"
#include <KDialog>
#include <QGroupBox>
#include <QListWidgetItem>
class QListWidget;
class QPushButton;
class QModelIndex;
/**
* This is a complex widget that is used to manipulate a mail program's filter
* list. It consists of an internal list of filters, which is a deep
* copy of the list KMFilterMgr manages, a QListBox displaying that list,
* and a few buttons used to create new filters, delete them, rename them
* and change the order of filters.
*
* It does not provide means to change the actual filter (besides the name),
* but relies on auxiliary widgets (SearchPatternEdit and KMFilterActionEdit)
* to do that.
*
* Communication with this widget is quite easy: simply create an instance,
* connect the signals filterSelected, resetWidgets and applyWidgets with
* a slot that does the right thing and there you go...
*
* This widget will operate on it's own copy of the filter list as
* long as you don't call slotApplyFilterChanges. It will then
* transfer the altered filter list back to KMFilterMgr.
*
* @short A complex widget that allows managing a list of MailCommon::MailFilter's.
* @author Marc Mutz <mutz@kde.org>, based upon work by Stefan Taferner <taferner@kde.org>.
* @see MailCommon::MailFilter KMFilterDialog KMFilterActionEdit SearchPatternEdit
*/
namespace MailCommon {
class MailFilter;
class QListWidgetFilterItem : public QListWidgetItem
{
public:
explicit QListWidgetFilterItem( const QString &text, QListWidget *parent = 0 );
~QListWidgetFilterItem();
void setFilter( MailCommon::MailFilter *filter );
MailCommon::MailFilter *filter();
private:
MailCommon::MailFilter *mFilter;
};
class MAILCOMMON_EXPORT KMFilterListBox : public QGroupBox
{
Q_OBJECT
public:
/**
* Constructor.
*/
explicit KMFilterListBox( const QString &title, QWidget *parent = 0 );
/**
* Destructor.
*/
~KMFilterListBox();
/**
* Called from KMFilterDialog. Creates a new filter and presets
* the first rule with "field equals value". It's there mainly to
* support "rapid filter creation" from a context menu. You should
* instead call KMFilterMgr::createFilter.
* @see KMFilterMgr::createFilter KMFilterDialog::createFilter
*/
void createFilter( const QByteArray &field, const QString &value );
/**
* Loads the filter list and selects the first filter. Should be
* called when all signals are connected properly. If createDummyFilter
* is true, an empty filter is created to improve the usability of the
* dialog in case no filter has been defined so far.
*/
void loadFilterList( bool createDummyFilter );
void insertFilter( MailCommon::MailFilter *aFilter );
void appendFilter( MailCommon::MailFilter *aFilter );
/**
* Returns a list of _copies_ of the current list of filters.
* The list owns the contents and thus the caller needs to clean them up.
* @param closeAfterSaving If true user is given option to continue editing
* after being warned about invalid filters. Otherwise, user is just warned.
*/
QList<MailCommon::MailFilter *> filtersForSaving( bool closeAfterSaving ) const;
QStringList selectedFilterId( SearchRule::RequiredPart &requiredPart, const QString& resource ) const;
signals:
/**
* Emitted when a new filter has been selected by the user or if the
* current filter has changed after a 'new' or 'delete' operation.
*/
void filterSelected( MailCommon::MailFilter *filter );
/**
* Emitted when this widget wants the edit widgets to let go of
* their filter reference. Everyone holding a reference to a filter
* should update it from the contents of the widgets used to edit
* it and set their internal reference to 0.