Commit 81d3c173 authored by Tobias Koenig's avatar Tobias Koenig
Browse files

coding style cleanup

svn path=/trunk/KDE/kdepim/runtime/; revision=1193081
parent 01780e89
......@@ -18,92 +18,64 @@
*/
#include "configdialog.h"
#include "settings.h"
#include <KConfigDialogManager>
#include "settings.h"
//#include <akonadi/collectionmodel.h>
//#include <akonadi/collectionview.h>
//#include <akonadi/collectionfilterproxymodel.h>
#include <Akonadi/Collection>
#include <Akonadi/CollectionFetchJob>
#include <Akonadi/CollectionRequester>
#include <KConfigDialogManager>
#include <KMime/Message>
using namespace Akonadi;
ConfigDialog::ConfigDialog(QWidget * parent) :
KDialog( parent )
ConfigDialog::ConfigDialog( QWidget *parent )
: KDialog( parent )
{
ui.setupUi( mainWidget() );
mManager = new KConfigDialogManager( this, Settings::self() );
mManager->updateWidgets();
ui.outboxSelector->setMimeTypeFilter( QStringList() << QLatin1String( "message/rfc822" ) );
// collection has no name if I skip the fetch job and just do Collection c(id)
CollectionFetchJob *job = new CollectionFetchJob( Collection( Settings::self()->outbox() ), CollectionFetchJob::Base );
if( job->exec() )
{
Collection::List cs = job->collections();
if( !cs.empty() )
ui.outboxSelector->setCollection( cs.first() );
}
ui.sentMailSelector->setMimeTypeFilter( QStringList() << QLatin1String( "message/rfc822" ) );
job = new CollectionFetchJob( Collection( Settings::self()->sentMail() ), CollectionFetchJob::Base );
if( job->exec() )
{
Collection::List cs = job->collections();
if( !cs.empty() )
ui.sentMailSelector->setCollection( cs.first() );
}
// mCollectionView = new Akonadi::CollectionView( w );
// mCollectionView->setSelectionMode( QAbstractItemView::SingleSelection );
// connect( mCollectionView, SIGNAL(clicked(QModelIndex)),
// this, SLOT(collectionActivated(QModelIndex)) );
// l->addWidget( mCollectionView );
//
// mCollectionModel = new Akonadi::CollectionModel( this );
// Akonadi::CollectionFilterProxyModel *sortModel = new Akonadi::CollectionFilterProxyModel( this );
// sortModel->setDynamicSortFilter( true );
// sortModel->setSortCaseSensitivity( Qt::CaseInsensitive );
// sortModel->addMimeTypeFilter( "message/rfc822" );
// sortModel->setSourceModel( mCollectionModel );
// mCollectionView->setModel( sortModel );
connect( this, SIGNAL(okClicked()),
this, SLOT(save()) );
mUi.setupUi( mainWidget() );
mManager = new KConfigDialogManager( this, Settings::self() );
mManager->updateWidgets();
ui.outboxSelector->setMimeTypeFilter( QStringList() << KMime::Message::mimeType() );
// collection has no name if I skip the fetch job and just do Collection c(id)
CollectionFetchJob *job = new CollectionFetchJob( Collection( Settings::self()->outbox() ), CollectionFetchJob::Base );
if ( job->exec() ) {
const Collection::List collections = job->collections();
if ( !collections.isEmpty() )
ui.outboxSelector->setCollection( collections.first() );
}
ui.sentMailSelector->setMimeTypeFilter( QStringList() << KMime::Message::mimeType() );
job = new CollectionFetchJob( Collection( Settings::self()->sentMail() ), CollectionFetchJob::Base );
if ( job->exec() ) {
const Collection::List collections = job->collections();
if ( !collections.isEmpty() )
ui.sentMailSelector->setCollection( collections.first() );
}
connect( this, SIGNAL( okClicked() ), this, SLOT( save() ) );
}
void ConfigDialog::save()
{
mManager->updateSettings();
// QModelIndex index = mCollectionView->currentIndex();
// if ( index.isValid() )
// {
// const Akonadi::Collection col = index.model()->data( index, Akonadi::CollectionModel::CollectionRole ).value<Akonadi::Collection>();
// if ( col.isValid() )
// {
// kDebug() << "Collection" << col.id() << "selected";
// Settings::self()->setOutbox( col.id() );
// }
// }
const Collection outbox = ui.outboxSelector->collection();
if ( outbox.isValid() )
{
kDebug() << "Collection" << outbox.id() << "selected for outbox.";
Settings::self()->setOutbox( outbox.id() );
}
const Collection sentMail = ui.sentMailSelector->collection();
if ( sentMail.isValid() )
{
kDebug() << "Collection" << sentMail.id() << "selected for sentMail.";
Settings::self()->setSentMail( sentMail.id() );
}
Settings::self()->writeConfig();
mManager->updateSettings();
const Collection outbox = ui.outboxSelector->collection();
if ( outbox.isValid() ) {
kDebug() << "Collection" << outbox.id() << "selected for outbox.";
Settings::self()->setOutbox( outbox.id() );
}
const Collection sentMail = ui.sentMailSelector->collection();
if ( sentMail.isValid() ) {
kDebug() << "Collection" << sentMail.id() << "selected for sentMail.";
Settings::self()->setSentMail( sentMail.id() );
}
Settings::self()->writeConfig();
}
#include "configdialog.moc"
......@@ -24,22 +24,21 @@
#include "ui_settings.h"
class KConfigDialogManager;
class ConfigDialog : public KDialog
{
Q_OBJECT
public:
ConfigDialog( QWidget *parent = 0 );
private slots:
private Q_SLOTS:
void save();
private:
Ui::ConfigDialog ui;
Ui::ConfigDialog mUi;
KConfigDialogManager *mManager;
};
#endif
......@@ -21,26 +21,26 @@
#include "maildispatcheragent.h"
//#include "configdialog.h"
#include "maildispatcheragentadaptor.h"
#include "outboxqueue.h"
#include "sendjob.h"
#include "settings.h"
#include "settingsadaptor.h"
#include "maildispatcheragentadaptor.h"
#include <QtDBus/QDBusConnection>
#include <QTimer>
#include <akonadi/agentfactory.h>
#include <akonadi/dbusconnectionpool.h>
#include <akonadi/itemfetchscope.h>
#include <KDebug>
#include <KLocalizedString>
#include <KWindowSystem>
#include <KIcon>
#include <KNotification>
#include <KIconLoader>
#include <akonadi/agentfactory.h>
#include <akonadi/dbusconnectionpool.h>
#include <Akonadi/ItemFetchScope>
#include <KLocalizedString>
#include <KMime/Message>
#include <KNotification>
#include <KWindowSystem>
#include <QtCore/QTimer>
#include <QtDBus/QDBusConnection>
#ifdef KDEPIM_STATIC_LIBS
extern bool ___MailTransport____INIT();
......@@ -58,11 +58,11 @@ class MailDispatcherAgent::Private
{
public:
Private( MailDispatcherAgent *parent )
: q( parent )
, currentJob( 0 )
, aborting( false )
, sendingInProgress( false )
, sentAnything( false )
: q( parent ),
currentJob( 0 ),
aborting( false ),
sendingInProgress( false ),
sentAnything( false )
{
}
......@@ -83,7 +83,7 @@ class MailDispatcherAgent::Private
// slots:
void abort();
void dispatch();
void itemFetched( Item &item );
void itemFetched( const Item &item );
void queueError( const QString &message );
void sendPercent( KJob *job, unsigned long percent );
void sendResult( KJob *job );
......@@ -94,22 +94,23 @@ class MailDispatcherAgent::Private
void MailDispatcherAgent::Private::abort()
{
if( !q->isOnline() ) {
if ( !q->isOnline() ) {
kDebug() << "Offline. Ignoring call.";
return;
}
if( aborting ) {
if ( aborting ) {
kDebug() << "Already aborting.";
return;
}
if( !sendingInProgress && queue->isEmpty() ) {
if ( !sendingInProgress && queue->isEmpty() ) {
kDebug() << "MDA is idle.";
Q_ASSERT( q->status() == AgentBase::Idle );
} else {
kDebug() << "Aborting...";
aborting = true;
if( currentJob ) {
if ( currentJob ) {
currentJob->abort();
}
// Further SendJobs will mark remaining items in the queue as 'aborted'.
......@@ -120,13 +121,13 @@ void MailDispatcherAgent::Private::dispatch()
{
Q_ASSERT( queue );
if( !q->isOnline() || sendingInProgress ) {
if ( !q->isOnline() || sendingInProgress ) {
kDebug() << "Offline or busy. See you later.";
return;
}
if( !queue->isEmpty() ) {
if( !sentAnything ) {
if ( !queue->isEmpty() ) {
if ( !sentAnything ) {
sentAnything = true;
sentItemsSize = 0;
emit q->percent( 0 );
......@@ -139,30 +140,30 @@ void MailDispatcherAgent::Private::dispatch()
queue->fetchOne(); // will trigger itemFetched
} else {
kDebug() << "Empty queue.";
if( aborting ) {
if ( aborting ) {
// Finished marking messages as 'aborted'.
aborting = false;
sentAnything = false;
emit q->status( AgentBase::Idle, i18n( "Sending canceled." ) );
QTimer::singleShot( 3000, q, SLOT(emitStatusReady()) );
QTimer::singleShot( 3000, q, SLOT( emitStatusReady() ) );
} else {
if( sentAnything ) {
if ( sentAnything ) {
// Finished sending messages in queue.
sentAnything = false;
emit q->percent( 100 );
emit q->status( AgentBase::Idle, i18n( "Finished sending messages." ) );
const QPixmap pix = KIcon("mail-folder-outbox").pixmap( KIconLoader::SizeSmall, KIconLoader::SizeSmall );
KNotification *notify = new KNotification("emailsent");
const QPixmap pixmap = KIcon( "mail-folder-outbox" ).pixmap( KIconLoader::SizeSmall, KIconLoader::SizeSmall );
KNotification *notify = new KNotification( "emailsent" );
notify->setComponentData( q->componentData() );
notify->setPixmap( pix );
notify->setPixmap( pixmap );
notify->setText( i18nc("Notification when the email was sent", "E-mail successfully sent" ) );
notify->sendEvent();
} else {
// Empty queue.
emit q->status( AgentBase::Idle, i18n( "No items in queue." ) );
}
QTimer::singleShot( 3000, q, SLOT(emitStatusReady()) );
QTimer::singleShot( 3000, q, SLOT( emitStatusReady() ) );
}
}
}
......@@ -189,13 +190,16 @@ MailDispatcherAgent::MailDispatcherAgent( const QString &id )
DBusConnectionPool::threadConnection().registerService( QLatin1String( "org.freedesktop.Akonadi.MailDispatcherAgent" ) );
d->queue = new OutboxQueue( this );
connect( d->queue, SIGNAL( newItems() ), this, SLOT( dispatch() ) );
connect( d->queue, SIGNAL( itemReady( Akonadi::Item& ) ),
this, SLOT( itemFetched( Akonadi::Item& ) ) );
connect( d->queue, SIGNAL(error(QString)), this, SLOT(queueError(QString)) );
connect( this, SIGNAL(itemProcessed(Akonadi::Item,bool)),
d->queue, SLOT(itemProcessed(Akonadi::Item,bool)) );
connect( this, SIGNAL(abortRequested()), this, SLOT(abort()) );
connect( d->queue, SIGNAL( newItems() ),
this, SLOT( dispatch() ) );
connect( d->queue, SIGNAL( itemReady( const Akonadi::Item& ) ),
this, SLOT( itemFetched( const Akonadi::Item& ) ) );
connect( d->queue, SIGNAL( error( const QString& ) ),
this, SLOT( queueError( const QString& ) ) );
connect( this, SIGNAL( itemProcessed( Akonadi::Item, bool ) ),
d->queue, SLOT( itemProcessed( Akonadi::Item, bool ) ) );
connect( this, SIGNAL( abortRequested() ),
this, SLOT( abort() ) );
}
MailDispatcherAgent::~MailDispatcherAgent()
......@@ -212,7 +216,7 @@ void MailDispatcherAgent::configure( WId windowId )
void MailDispatcherAgent::doSetOnline( bool online )
{
Q_ASSERT( d->queue );
if( online ) {
if ( online ) {
kDebug() << "Online. Dispatching messages.";
emit status( AgentBase::Idle, i18n( "Online, sending messages in queue." ) );
QTimer::singleShot( 0, this, SLOT( dispatch() ) );
......@@ -228,7 +232,7 @@ void MailDispatcherAgent::doSetOnline( bool online )
AgentBase::doSetOnline( online );
}
void MailDispatcherAgent::Private::itemFetched( Item &item )
void MailDispatcherAgent::Private::itemFetched( const Item &item )
{
kDebug() << "Fetched item" << item.id() << "; creating SendJob.";
Q_ASSERT( sendingInProgress );
......@@ -238,14 +242,18 @@ void MailDispatcherAgent::Private::itemFetched( Item &item )
emit q->itemDispatchStarted();
currentJob = new SendJob( item, q );
if( aborting ) {
if ( aborting ) {
currentJob->setMarkAborted();
}
q->status( AgentBase::Running, i18nc( "Message with given subject is being sent.", "Sending: ") + item.payload<KMime::Message::Ptr>()->subject()->asUnicodeString() );
q->status( AgentBase::Running, i18nc( "Message with given subject is being sent.", "Sending: %1",
item.payload<KMime::Message::Ptr>()->subject()->asUnicodeString() ) );
connect( currentJob, SIGNAL( result( KJob* ) ),
q, SLOT( sendResult( KJob* ) ) );
connect( currentJob, SIGNAL(percent(KJob*,unsigned long)),
q, SLOT(sendPercent(KJob*,unsigned long)) );
q, SLOT( sendResult( KJob* ) ) );
connect( currentJob, SIGNAL( percent( KJob*, unsigned long ) ),
q, SLOT( sendPercent( KJob*, unsigned long ) ) );
currentJob->start();
}
......@@ -255,7 +263,7 @@ void MailDispatcherAgent::Private::queueError( const QString &message )
// FIXME figure out why this does not set the status to Broken, etc.
}
void MailDispatcherAgent::Private::sendPercent( KJob *job, unsigned long percent )
void MailDispatcherAgent::Private::sendPercent( KJob *job, unsigned long )
{
Q_ASSERT( sendingInProgress );
Q_ASSERT( job == currentJob );
......@@ -266,18 +274,18 @@ void MailDispatcherAgent::Private::sendPercent( KJob *job, unsigned long percent
// Give the transport 80% of the weight, and move-to-sendmail 20%.
const double transportWeight = 0.8;
Q_UNUSED( percent );
int perc = 100 * ( sentItemsSize + job->processedAmount( KJob::Bytes ) * transportWeight )
/ ( sentItemsSize + currentItem.size() + queue->totalSize() );
const int percent = 100 * ( sentItemsSize + job->processedAmount( KJob::Bytes ) * transportWeight )
/ ( sentItemsSize + currentItem.size() + queue->totalSize() );
kDebug() << "sentItemsSize" << sentItemsSize
<< "this job processed" << job->processedAmount( KJob::Bytes )
<< "queue totalSize" << queue->totalSize()
<< "total total size (sent+current+queue)" << ( sentItemsSize + currentItem.size() + queue->totalSize() )
<< "new percentage" << perc << "old percentage" << q->progress();
<< "this job processed" << job->processedAmount( KJob::Bytes )
<< "queue totalSize" << queue->totalSize()
<< "total total size (sent+current+queue)" << ( sentItemsSize + currentItem.size() + queue->totalSize() )
<< "new percentage" << percent << "old percentage" << q->progress();
if( perc != q->progress() ) {
if ( percent != q->progress() ) {
// The progress can decrease too, if messages got added to the queue.
emit q->percent( perc );
emit q->percent( percent );
}
// It is possible that the number of queued messages has changed.
......@@ -298,7 +306,7 @@ void MailDispatcherAgent::Private::sendResult( KJob *job )
emit q->itemProcessed( currentItem, !job->error() );
currentItem = Item();
if( job->error() ) {
if ( job->error() ) {
// The SendJob gave the item an ErrorAttribute, so we don't have to
// do anything.
kDebug() << "Sending failed. error:" << job->errorString();
......@@ -313,7 +321,7 @@ void MailDispatcherAgent::Private::sendResult( KJob *job )
void MailDispatcherAgent::Private::emitStatusReady()
{
if( q->status() == AgentBase::Idle ) {
if ( q->status() == AgentBase::Idle ) {
// If still idle after aborting, clear 'aborted' status.
emit q->status( AgentBase::Idle, i18n( "Ready to dispatch messages." ) );
}
......@@ -325,5 +333,4 @@ AKONADI_AGENT_FACTORY( MailDispatcherAgent, akonadi_maildispatcher_agent )
AKONADI_AGENT_MAIN( MailDispatcherAgent)
#endif
#include "maildispatcheragent.moc"
......@@ -22,17 +22,19 @@
#define MAILDISPATCHERAGENT_H
#include <Akonadi/AgentBase>
#include <Akonadi/Collection>
#include <Akonadi/Item>
namespace Akonadi {
class Item;
}
/**
* This agent dispatches mail put into the outbox collection.
* @short This agent dispatches mail put into the outbox collection.
*/
class MailDispatcherAgent : public Akonadi::AgentBase
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Akonadi.MailDispatcherAgent")
Q_CLASSINFO( "D-Bus Interface", "org.freedesktop.Akonadi.MailDispatcherAgent" )
public:
MailDispatcherAgent( const QString &id );
......@@ -43,7 +45,7 @@ class MailDispatcherAgent : public Akonadi::AgentBase
Q_SIGNALS:
/**
Emitted when the MDA has attempted to send an item.
* Emitted when the MDA has attempted to send an item.
*/
void itemProcessed( const Akonadi::Item &item, bool result );
......@@ -56,17 +58,18 @@ class MailDispatcherAgent : public Akonadi::AgentBase
virtual void doSetOnline( bool online );
private:
//@cond PRIVATE
class Private;
Private* const d;
Q_PRIVATE_SLOT( d, void abort() )
Q_PRIVATE_SLOT( d, void dispatch() )
Q_PRIVATE_SLOT( d, void itemFetched( Akonadi::Item& ) )
Q_PRIVATE_SLOT( d, void queueError( QString ) )
Q_PRIVATE_SLOT( d, void itemFetched( const Akonadi::Item& ) )
Q_PRIVATE_SLOT( d, void queueError( const QString& ) )
Q_PRIVATE_SLOT( d, void sendPercent( KJob*, unsigned long ) )
Q_PRIVATE_SLOT( d, void sendResult( KJob* ) )
Q_PRIVATE_SLOT( d, void emitStatusReady() )
//@endcond
};
#endif // MAILDISPATCHERAGENT_H
......@@ -52,9 +52,9 @@ class OutboxQueue::Private
{
public:
Private( OutboxQueue *qq )
: q( qq )
, outbox( -1 )
, futureTimer( 0 )
: q( qq ),
outbox( -1 ),
futureTimer( 0 )
{
}
......@@ -97,7 +97,6 @@ class OutboxQueue::Private
void itemMoved( const Item &item, const Collection &source, const Collection &dest );
void itemRemoved( const Item &item );
void itemProcessed( const Item &item, bool result );
};
......@@ -115,17 +114,17 @@ void OutboxQueue::Private::initQueue()
void OutboxQueue::Private::addIfComplete( const Item &item )
{
if( ignore.contains( item.id() ) ) {
if ( ignore.contains( item.id() ) ) {
kDebug() << "Item" << item.id() << "is ignored.";
return;
}
if( queue.contains( item ) ) {
if ( queue.contains( item ) ) {
kDebug() << "Item" << item.id() << "already in queue!";
return;
}
if( item.remoteId().isEmpty() ) {
if ( item.remoteId().isEmpty() ) {
kDebug() << "Item" << item.id() << "has an empty remoteId.";
// HACK:
// This probably means that it hasn't yet been stored on disk by the
......@@ -134,63 +133,67 @@ void OutboxQueue::Private::addIfComplete( const Item &item )
return;
}
if( !item.hasAttribute<AddressAttribute>() ) {
if ( !item.hasAttribute<AddressAttribute>() ) {
kWarning() << "Item" << item.id() << "does not have the required attribute Address.";
return;
}
if( !item.hasAttribute<DispatchModeAttribute>() ) {
if ( !item.hasAttribute<DispatchModeAttribute>() ) {
kWarning() << "Item" << item.id() << "does not have the required attribute DispatchMode.";
return;
}
if( !item.hasAttribute<SentBehaviourAttribute>() ) {
if ( !item.hasAttribute<SentBehaviourAttribute>() ) {
kWarning() << "Item" << item.id() << "does not have the required attribute SentBehaviour.";
return;
}
if( !item.hasAttribute<TransportAttribute>() ) {
if ( !item.hasAttribute<TransportAttribute>() ) {
kWarning() << "Item" << item.id() << "does not have the required attribute Transport.";
return;
}
if( !item.hasFlag( "queued" ) ) {
if ( !item.hasFlag( "queued" ) ) {
kDebug() << "Item" << item.id() << "has no 'queued' flag.";
return;
}
const DispatchModeAttribute *mA = item.attribute<DispatchModeAttribute>();
Q_ASSERT( mA );
if( mA->dispatchMode() == DispatchModeAttribute::Manual ) {
const DispatchModeAttribute *dispatchModeAttribute = item.attribute<DispatchModeAttribute>();
Q_ASSERT( dispatchModeAttribute );
if ( dispatchModeAttribute->dispatchMode() == DispatchModeAttribute::Manual ) {
kDebug() << "Item" << item.id() << "is queued to be sent manually.";
return;
}
const TransportAttribute *tA = item.attribute<TransportAttribute>();
Q_ASSERT( tA );
if( tA->transport() == 0 ) {
const TransportAttribute *transportAttribute = item.attribute<TransportAttribute>();
Q_ASSERT( transportAttribute );
if ( transportAttribute->transport() == 0 ) {
kWarning() << "Item" << item.id() << "has invalid transport.";
return;
}
const SentBehaviourAttribute *sA = item.attribute<SentBehaviourAttribute>();
Q_ASSERT( sA );
if( sA->sentBehaviour() == SentBehaviourAttribute::MoveToCollection &&
!sA->moveToCollection().isValid() ) {
const SentBehaviourAttribute *sentBehaviourAttribute = item.attribute<SentBehaviourAttribute>();
Q_ASSERT( sentBehaviourAttribute );
if ( sentBehaviourAttribute->sentBehaviour() == SentBehaviourAttribute::MoveToCollection &&
!sentBehaviourAttribute->moveToCollection().isValid() ) {
kWarning() << "Item" << item.id() << "has invalid sent-mail collection.";
return;
}
// This check requires fetchFullPayload. -> slow (?)
/*
if( !item.hasPayload<KMime::Message::Ptr>() ) {
if ( !item.hasPayload<KMime::Message::Ptr>() ) {
kWarning() << "Item" << item.id() << "does not have KMime::Message::Ptr payload.";
return;
}
*/