~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/smtpconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
Import upstream version 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Kscd - A simple cd player for the KDE Project
 
3
 *
 
4
 * $Id: smtpconfig.cpp,v 1.10.2.1 2001/09/19 22:26:11 pfeiffer Exp $
 
5
 *
 
6
 * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu
 
7
 * Copyrithg (c) 2001 Dirk F�rsterling milliByte@gmx.net
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2, or (at your option)
 
12
 * any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
22
 *
 
23
 */
 
24
 
 
25
#include <klocale.h>
 
26
#include <kapp.h>
 
27
 
 
28
#include <smtpconfig.h>
 
29
 
 
30
#include <qlayout.h>
 
31
#include <qfontmetrics.h>
 
32
 
 
33
#include <kemailsettings.h>
 
34
#include <kmessagebox.h>
 
35
 
 
36
SMTPConfig::SMTPConfig(QWidget *parent, const char *name, struct SMTPConfigData *_configData)
 
37
    : QDialog(parent, name)
 
38
{
 
39
    configData = _configData;
 
40
    QFontMetrics fm ( font() );
 
41
    kes = new KEMailSettings();
 
42
 
 
43
    kes->setProfile( configData->mailProfile );
 
44
    configData->serverHost = kes->getSetting( KEMailSettings::OutServer );
 
45
    configData->serverPort = "25";
 
46
    configData->senderAddress = kes->getSetting( KEMailSettings::EmailAddress );
 
47
    configData->senderReplyTo = kes->getSetting( KEMailSettings::ReplyToAddress );
 
48
    // Don't accept obviously bogus settings.
 
49
    if( (configData->serverHost == "") || (!configData->senderAddress.contains("@")))
 
50
      {
 
51
        configData->enabled = false;
 
52
      }
 
53
    
 
54
 
 
55
    QBoxLayout * lay1 = new QVBoxLayout ( this, 10 );
 
56
    mainBox = new QGroupBox(this, "mainBox");
 
57
    lay1->addWidget ( mainBox );
 
58
 
 
59
    QBoxLayout * lay2 = new QVBoxLayout ( mainBox, 10 );
 
60
    enableCB = new QCheckBox(i18n("Enable submission via SMTP"), mainBox, "enableCB");
 
61
    lay2->addWidget ( enableCB );
 
62
    enableCB->setChecked(configData->enabled);
 
63
    connect(enableCB, SIGNAL(clicked()), this, SLOT(enableClicked()));
 
64
 
 
65
    QGridLayout * glay = new QGridLayout ( lay2, 2, 4, 5 );
 
66
    glay->setColStretch ( 1, 1 );
 
67
 
 
68
    mailProfileLabel = new QLabel(i18n("Current E-Mail Profile"), mainBox, "mailProfileLabel");
 
69
    glay->addWidget ( mailProfileLabel, 0, 0 );
 
70
    mailProfileCombo = new KComboBox( FALSE, mainBox, "mailProfileCombo" );
 
71
    glay->addMultiCellWidget( mailProfileCombo, 0,0, 1,3);
 
72
    mailProfileCombo->insertStringList(kes->profiles());
 
73
    mailProfileCombo->setEnabled(configData->enabled);
 
74
    connect(mailProfileCombo, SIGNAL(activated(const QString &)), this, SLOT(mailProfileChanged(const QString &)));
 
75
    // *yuck*
 
76
    int i = 0;
 
77
    for( i=0; i < mailProfileCombo->count(); i++ )
 
78
      {
 
79
        if( configData->mailProfile == mailProfileCombo->text(i) )
 
80
          {
 
81
            mailProfileCombo->setCurrentItem( i );
 
82
          }
 
83
      }
 
84
 
 
85
    serverHostLabel = new QLabel(i18n("SMTP Address:Port"), mainBox, "serverHostLabel");
 
86
    glay->addWidget ( serverHostLabel, 1, 0 );
 
87
    serverHostEdit = new QLineEdit(mainBox, "serverHostEdit");
 
88
    glay->addWidget ( serverHostEdit, 1, 1 );
 
89
    serverHostEdit->setText(configData->serverHost);
 
90
    serverHostEdit->setEnabled(configData->enabled);
 
91
    serverPortLabel = new QLabel(":", mainBox, "serverPortLabel");
 
92
    glay->addWidget ( serverPortLabel, 1, 2 );
 
93
    serverPortEdit = new QLineEdit(mainBox, "serverPortEdit");
 
94
    serverPortEdit->setFixedWidth ( 5 * fm.maxWidth() );
 
95
    glay->addWidget ( serverPortEdit, 1, 3 );
 
96
    serverPortEdit->setGeometry(475, 40, 45, 25);
 
97
    serverPortEdit->setText(configData->serverPort);
 
98
    serverPortEdit->setEnabled(configData->enabled);
 
99
    serverPortEdit->setReadOnly( true );
 
100
 
 
101
    senderAddressLabel = new QLabel(i18n("Your Email Address"), mainBox, "senderAddressLabel");
 
102
    glay->addWidget ( senderAddressLabel, 2, 0 );
 
103
    senderAddressEdit = new QLineEdit(mainBox, "senderAddressEdit");
 
104
    glay->addMultiCellWidget ( senderAddressEdit, 2,2, 1,3 );
 
105
    senderAddressEdit->setText(configData->senderAddress);
 
106
    senderAddressEdit->setEnabled(configData->enabled);
 
107
    senderAddressEdit->setReadOnly( true );
 
108
 
 
109
    senderReplyToLabel = new QLabel(i18n("Your Reply Address"), mainBox, "senderReplyToLabel");
 
110
    glay->addWidget ( senderReplyToLabel, 3, 0 );
 
111
    senderReplyToEdit = new QLineEdit(mainBox, "senderReplyToEdit");
 
112
    glay->addMultiCellWidget ( senderReplyToEdit, 3,3, 1,3 );
 
113
    senderReplyToEdit->setText(configData->senderReplyTo);
 
114
    senderReplyToEdit->setEnabled(configData->enabled);
 
115
    senderReplyToEdit->setReadOnly( true );
 
116
    
 
117
    lay1->addStretch ( 1 );
 
118
}
 
119
 
 
120
void SMTPConfig::commitData(void)
 
121
{
 
122
    configData->enabled = enableCB->isChecked();
 
123
    configData->serverHost = serverHostEdit->text();
 
124
    kes->setSetting( KEMailSettings::OutServer, serverHostEdit->text() );
 
125
    configData->serverPort = serverPortEdit->text();
 
126
    configData->senderAddress = senderAddressEdit->text();
 
127
    configData->senderReplyTo = senderReplyToEdit->text();
 
128
    configData->mailProfile = mailProfileCombo->currentText();
 
129
    if( enableCB->isChecked() && ((configData->serverHost == "") ||
 
130
                                  (!configData->senderAddress.contains("@"))))
 
131
      {
 
132
        KMessageBox::sorry(this, i18n("freedb submissions via SMTP have been disabled\n"
 
133
                                      "because the E-Mail profile you selected is\n"
 
134
                                      "incomplete. Please review your E-Mail settings\n"
 
135
                                      "and try again."), i18n("freedb submissions disabled"));
 
136
        configData->enabled = false;
 
137
      } 
 
138
} // commitData
 
139
 
 
140
void SMTPConfig::enableClicked(void)
 
141
{
 
142
    bool c;
 
143
 
 
144
    c = enableCB->isChecked();
 
145
    mailProfileCombo->setEnabled(c);
 
146
    serverHostEdit->setEnabled(c);
 
147
    serverPortEdit->setEnabled(c);
 
148
    senderAddressEdit->setEnabled(c);
 
149
    senderReplyToEdit->setEnabled(c);
 
150
} // enableClicked
 
151
 
 
152
void SMTPConfig::mailProfileChanged( const QString &name )
 
153
{
 
154
    kes->setProfile( name );
 
155
    configData->serverHost = kes->getSetting( KEMailSettings::OutServer );
 
156
    configData->senderAddress = kes->getSetting( KEMailSettings::EmailAddress );
 
157
    configData->senderReplyTo = kes->getSetting( KEMailSettings::ReplyToAddress );
 
158
    serverHostEdit->setText( configData->serverHost );
 
159
    senderAddressEdit->setText( configData->senderAddress );
 
160
    senderReplyToEdit->setText( configData->senderReplyTo );
 
161
} // mailProfileChanged
 
162
 
 
163
#include <smtpconfig.moc>