1/*
2 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3 Copyright (c) 2007 KovoKs <kovoks@kovoks.nl>
4 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
5
6 Based on KMail code by:
7 Copyright (c) 2001-2002 Michael Haeckel <haeckel@kde.org>
8
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or (at your
12 option) any later version.
13
14 This library is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
17 License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to the
21 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301, USA.
23*/
24
25#include "transportconfigdialog.h"
26#include "transport.h"
27#include "transportconfigwidget.h"
28#include "transportmanager.h"
29#include "transporttype.h"
30#include "sendmailconfigwidget.h"
31#include "smtpconfigwidget.h"
32
33#include <QLabel>
34#include <QString>
35
36#include <KDebug>
37#include <KLocalizedString>
38
39using namespace MailTransport;
40
41class MailTransport::TransportConfigDialog::Private
42{
43 public:
44 Private( TransportConfigDialog *qq )
45 : transport( 0 ), configWidget( 0 ), q( qq )
46 {
47 }
48
49 Transport *transport;
50 QWidget *configWidget;
51 TransportConfigDialog *q;
52
53 // slots
54 void okClicked();
55 void slotTextChanged( const QString &text );
56};
57
58void TransportConfigDialog::Private::okClicked()
59{
60 if ( TransportConfigWidget *w = dynamic_cast<TransportConfigWidget*>( configWidget ) ) {
61 // It is not an Akonadi transport.
62 w->apply();
63 transport->writeConfig();
64 }
65}
66
67void TransportConfigDialog::Private::slotTextChanged( const QString &text )
68{
69 q->enableButtonOk( !text.isEmpty() );
70}
71
72TransportConfigDialog::TransportConfigDialog( Transport *transport, QWidget *parent )
73 : KDialog( parent ), d( new Private( this ) )
74{
75 Q_ASSERT( transport );
76 d->transport = transport;
77 setButtons( Ok|Cancel );
78 bool pathIsEmpty = false;
79 switch ( transport->type() ) {
80 case Transport::EnumType::SMTP:
81 {
82 d->configWidget = new SMTPConfigWidget( transport, this );
83 break;
84 }
85 case Transport::EnumType::Sendmail:
86 {
87 SendmailConfigWidget *sendMailWidget = new SendmailConfigWidget( transport, this );
88 d->configWidget = sendMailWidget;
89 connect( sendMailWidget, SIGNAL(enableButtonOk(bool)),
90 this, SLOT(enableButtonOk(bool)) );
91 pathIsEmpty = sendMailWidget->pathIsEmpty();
92 break;
93 }
94 case Transport::EnumType::Akonadi:
95 {
96 kWarning() << "Tried to configure an Akonadi transport.";
97 d->configWidget = new QLabel( i18n( "This outgoing account cannot be configured." ), this );
98 break;
99 }
100 default:
101 {
102 Q_ASSERT( false );
103 d->configWidget = 0;
104 break;
105 }
106 }
107 setMainWidget( d->configWidget );
108
109 connect( this, SIGNAL(okClicked()), this, SLOT(okClicked()) );
110 enableButtonOk( !pathIsEmpty );
111}
112
113TransportConfigDialog::~TransportConfigDialog()
114{
115 delete d;
116}
117
118#include "moc_transportconfigdialog.cpp"
119