add more spacing
[personal-kdebase.git] / runtime / kcontrol / componentchooser / componentchooseremail.cpp
blob42f138b9b281b26274f69c81886511ce54c9a486
1 /***************************************************************************
2 componentchooseremail.cpp
3 -------------------
4 copyright : (C) 2002 by Joseph Wenninger
5 email : jowenn@kde.org
6 ***************************************************************************/
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License verstion 2 as *
12 * published by the Free Software Foundation *
13 * *
14 ***************************************************************************/
16 #include "componentchooseremail.h"
17 #include <QtDBus/QtDBus>
18 #include <kemailsettings.h>
19 #include <QCheckBox>
20 #include <kopenwithdialog.h>
21 #include <kstandarddirs.h>
23 // for chmod:
24 #include <sys/types.h>
25 #include <sys/stat.h>
28 CfgEmailClient::CfgEmailClient(QWidget *parent)
29 : QWidget(parent), Ui::EmailClientConfig_UI(), CfgPlugin()
31 setupUi( this );
33 pSettings = new KEMailSettings();
35 connect(kmailCB, SIGNAL(toggled(bool)), SLOT(configChanged()) );
36 connect(txtEMailClient, SIGNAL(textChanged(const QString&)), SLOT(configChanged()) );
37 #ifdef Q_OS_UNIX
38 connect(chkRunTerminal, SIGNAL(clicked()), SLOT(configChanged()) );
39 #else
40 chkRunTerminal->hide();
41 #endif
42 connect(btnSelectEmail, SIGNAL(clicked()), SLOT(selectEmailClient()) );
45 CfgEmailClient::~CfgEmailClient() {
46 delete pSettings;
49 void CfgEmailClient::defaults()
51 load(0);
54 void CfgEmailClient::load(KConfig *)
56 QString emailClient = pSettings->getSetting(KEMailSettings::ClientProgram);
57 bool useKMail = (emailClient.isEmpty());
59 kmailCB->setChecked(useKMail);
60 otherCB->setChecked(!useKMail);
61 txtEMailClient->setText(emailClient);
62 txtEMailClient->setFixedHeight(txtEMailClient->sizeHint().height());
63 chkRunTerminal->setChecked((pSettings->getSetting(KEMailSettings::ClientTerminal) == "true"));
65 emit changed(false);
69 void CfgEmailClient::configChanged()
71 emit changed(true);
74 void CfgEmailClient::selectEmailClient()
76 KUrl::List urlList;
77 KOpenWithDialog dlg(urlList, i18n("Select preferred email client:"), QString(), this);
78 // hide "Do not &close when command exits" here, we don't need it for a mail client
79 dlg.hideNoCloseOnExit();
80 if (dlg.exec() != QDialog::Accepted) return;
81 QString client = dlg.text();
83 // get the preferred Terminal Application
84 KConfigGroup confGroup( KGlobal::config(), QLatin1String("General") );
85 QString preferredTerminal = confGroup.readPathEntry("TerminalApplication", QLatin1String("konsole"));
86 preferredTerminal += QLatin1String(" -e ");
88 int len = preferredTerminal.length();
89 bool b = client.left(len) == preferredTerminal;
90 if (b) client = client.mid(len);
91 if (!client.isEmpty())
93 chkRunTerminal->setChecked(b);
94 txtEMailClient->setText(client);
99 void CfgEmailClient::save(KConfig *)
101 if (kmailCB->isChecked())
103 pSettings->setSetting(KEMailSettings::ClientProgram, QString());
104 pSettings->setSetting(KEMailSettings::ClientTerminal, "false");
106 else
108 pSettings->setSetting(KEMailSettings::ClientProgram, txtEMailClient->text());
109 pSettings->setSetting(KEMailSettings::ClientTerminal, (chkRunTerminal->isChecked()) ? "true" : "false");
112 // insure proper permissions -- contains sensitive data
113 QString cfgName(KGlobal::dirs()->findResource("config", "emails"));
114 if (!cfgName.isEmpty())
115 ::chmod(QFile::encodeName(cfgName), 0600);
116 QDBusMessage message = QDBusMessage::createSignal("/Component", "org.kde.Kcontrol", "KDE_emailSettingsChanged" );
117 QDBusConnection::sessionBus().send(message);
118 emit changed(false);