summaryrefslogtreecommitdiffstats
path: root/kcontrol/crypto/certexport.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kcontrol/crypto/certexport.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kcontrol/crypto/certexport.cpp')
-rw-r--r--kcontrol/crypto/certexport.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/kcontrol/crypto/certexport.cpp b/kcontrol/crypto/certexport.cpp
new file mode 100644
index 000000000..7c31bb84b
--- /dev/null
+++ b/kcontrol/crypto/certexport.cpp
@@ -0,0 +1,148 @@
+/**
+ * certexport.cpp
+ *
+ * Copyright (c) 2001 George Staikos <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "certexport.h"
+#include <qpushbutton.h>
+#include <klineedit.h>
+#include <kfiledialog.h>
+#include <qradiobutton.h>
+#include <qvbuttongroup.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+#include <ksslall.h>
+
+
+KCertExport::KCertExport(QWidget *parent, const char *name)
+ : KDialog(parent, name, true) {
+QGridLayout *grid = new QGridLayout(this, 9, 6, marginHint(), spacingHint());
+
+ setCaption(i18n("X509 Certificate Export"));
+
+ QVButtonGroup *bg = new QVButtonGroup(i18n("Format"), this);
+ _pem = new QRadioButton(i18n("&PEM"), bg);
+ _netscape = new QRadioButton(i18n("&Netscape"), bg);
+ _der = new QRadioButton(i18n("&DER/ASN1"), bg);
+ _text = new QRadioButton(i18n("&Text"), bg);
+ grid->addMultiCellWidget(bg, 0, 4, 0, 3);
+ _pem->setChecked(true);
+
+ grid->addMultiCellWidget(new QLabel(i18n("Filename:"), this), 5, 5, 0, 3);
+
+ _filename = new KLineEdit(this);
+ grid->addMultiCellWidget(_filename, 6, 6, 0, 4);
+ connect(_filename, SIGNAL(textChanged(const QString &)), this, SLOT(slotTextChanged(const QString &)));
+ connect(_filename, SIGNAL(returnPressed()), this, SLOT(slotExport()));
+
+ _choose = new QPushButton("...", this);
+ grid->addWidget(_choose, 6, 5);
+ connect(_choose, SIGNAL(clicked()), this, SLOT(slotChoose()));
+
+ _export = new QPushButton(i18n("&Export"), this);
+ grid->addWidget(_export, 8, 4);
+ connect(_export, SIGNAL(clicked()), this, SLOT(slotExport()));
+ _export->setEnabled(false);
+
+ _cancel = new QPushButton(i18n("&Cancel"), this);
+ grid->addWidget(_cancel, 8, 5);
+ connect(_cancel, SIGNAL(clicked()), this, SLOT(reject()));
+}
+
+
+KCertExport::~KCertExport() {
+
+}
+
+
+void KCertExport::setCertificate(KSSLCertificate *c) {
+ _c = c;
+}
+
+
+void KCertExport::slotExport() {
+QByteArray cert;
+QString certt;
+
+ if (_filename->text().isEmpty()) return;
+
+ if (!_c) {
+ KMessageBox::sorry(this, i18n("Internal error. Please report to [email protected]."), i18n("SSL"));
+ return;
+ }
+
+ if (_der->isChecked()) {
+ cert = _c->toDer();
+ } else if (_pem->isChecked()) {
+ cert = _c->toPem();
+ } else if (_text->isChecked()) {
+ certt = _c->toText();
+ } else { // netscape
+ cert = _c->toNetscape();
+ }
+
+ if ((!_text->isChecked() && cert.size() <= 0) && certt.isEmpty()) {
+ KMessageBox::error(this, i18n("Error converting the certificate into the requested format."), i18n("SSL"));
+ reject();
+ return;
+ }
+
+ QFile outFile(_filename->text());
+
+ if (!outFile.open(IO_WriteOnly)) {
+ KMessageBox::error(this, i18n("Error opening file for output."), i18n("SSL"));
+ reject();
+ return;
+ }
+
+ if (_text->isChecked())
+ outFile.writeBlock(certt.local8Bit(), certt.length());
+ else outFile.writeBlock(cert);
+
+ outFile.close();
+
+accept();
+}
+
+
+void KCertExport::slotChoose() {
+ //QString newFile = KFileDialog::getSaveFileName("::x509save", i18n("*.pem|Privacy Enhanced Mail Format\n*.der|DER/ASN1 Format"));
+ QString newFile = KFileDialog::getSaveFileName(QString::null, "application/x-x509-ca-cert");
+
+ // Dunno about this one yet
+ // \n*.ncert|Netscape certificate files");
+
+ if (!newFile.isEmpty()) _filename->setText(newFile);
+}
+
+
+void KCertExport::slotTextChanged(const QString& x) {
+ _export->setEnabled(!x.isEmpty());
+}
+
+
+#include "certexport.moc"
+