1 /***************************************************************************
2 componentchooseremail.cpp
4 copyright : (C) 2002 by Joseph Wenninger
6 ***************************************************************************/
8 /***************************************************************************
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 *
14 ***************************************************************************/
16 #include "componentchooseremail.h"
17 #include <QtDBus/QtDBus>
18 #include <kemailsettings.h>
20 #include <kopenwithdialog.h>
21 #include <kstandarddirs.h>
24 #include <sys/types.h>
28 CfgEmailClient::CfgEmailClient(QWidget
*parent
)
29 : QWidget(parent
), Ui::EmailClientConfig_UI(), CfgPlugin()
33 pSettings
= new KEMailSettings();
35 connect(kmailCB
, SIGNAL(toggled(bool)), SLOT(configChanged()) );
36 connect(txtEMailClient
, SIGNAL(textChanged(const QString
&)), SLOT(configChanged()) );
38 connect(chkRunTerminal
, SIGNAL(clicked()), SLOT(configChanged()) );
40 chkRunTerminal
->hide();
42 connect(btnSelectEmail
, SIGNAL(clicked()), SLOT(selectEmailClient()) );
45 CfgEmailClient::~CfgEmailClient() {
49 void CfgEmailClient::defaults()
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"));
69 void CfgEmailClient::configChanged()
74 void CfgEmailClient::selectEmailClient()
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");
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
);