Commit c97530d3 authored by Luis Ángel Fernández Fernández's avatar Luis Ángel Fernández Fernández Committed by Rolf Eike Beer
Browse files

ask the user before overwriting files when exporting keys

Now when the user wants to export the public key to a file and that file
already exists the user is asked about overwriting the file.

BUG:283215
REVIEW:102786
CCMAIL:laffdez@gmail.com
parent f00af52e
/***************************************************************************
keyexport.cpp - description
-------------------
begin : Thu Jul 4 2002
copyright : (C) 2002 by Jean-Baptiste Mardelle
email : bj@altern.org
***************************************************************************/
/*
* Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
* Copyright (C) 2007,2011 Rolf Eike Beer <kde@opensource.sf-tec.de>
* Copyright (C) 2011 Luis Ángel Fernández Fernández <laffdez@gmail.com>
*/
/***************************************************************************
* *
......@@ -15,19 +13,39 @@
* *
***************************************************************************/
#include "keyexport.h"
#include <KMessageBox>
KeyExport::KeyExport(QWidget *parent, const QStringList &keyservers)
: KDialog(parent),
Ui_KeyExport()
{
setupUi(this);
setMainWidget(widget);
setCaption(i18n("Public Key Export"));
setButtons(KDialog::Ok | KDialog::Cancel);
setDefaultButton(KDialog::Ok);
newFilename->setWindowTitle(i18n("Save File"));
newFilename->setMode(KFile::File);
if (!keyservers.isEmpty()) {
checkServer->setEnabled(true);
destServer->addItems(keyservers);
}
}
KeyExport::KeyExport(QWidget* parent, const QStringList& keyservers)
: QWidget(parent), Ui_KeyExport()
void KeyExport::accept()
{
setupUi(this);
if (checkFile->isChecked()) {
if (QFile::exists(newFilename->url().path().simplified())) {
const QString message = i18n("Overwrite existing file %1?", newFilename->url().fileName());
int result = KMessageBox::warningContinueCancel(this, message, QString(), KStandardGuiItem::overwrite());
if (KMessageBox::Cancel == result)
return;
}
}
if (keyservers.size() > 0)
{
checkServer->setEnabled(true);
destServer->addItems(keyservers);
}
QDialog::accept();
}
#include "keyexport.moc"
/***************************************************************************
keyexport.h - description
-------------------
begin : Thu Jul 4 2002
copyright : (C) 2002 by Jean-Baptiste Mardelle
email : bj@altern.org
***************************************************************************/
/*
* Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
* Copyright (C) 2007,2008,2009,2010,2011 Rolf Eike Beer <kde@opensource.sf-tec.de>
* Copyright (C) 2011 Luis Ángel Fernández Fernández <laffdez@gmail.com>
*/
/***************************************************************************
* *
......@@ -21,13 +19,18 @@
#include "ui_keyexport.h"
#include <QStringList>
#include <KDialog>
class KeyExport : public QWidget, public Ui_KeyExport
class KeyExport : public KDialog, public Ui_KeyExport
{
Q_OBJECT
Q_OBJECT
public:
explicit KeyExport(QWidget* parent = 0, const QStringList& keyservers = QStringList());
explicit KeyExport(QWidget *parent = 0, const QStringList &keyservers = QStringList());
protected:
virtual void accept();
};
#endif
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KeyExport</class>
<widget class="QWidget" name="KeyExport" >
<property name="geometry" >
<widget class="QWidget" name="KeyExport">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
......@@ -9,141 +10,147 @@
<height>411</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" >
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="buttonGroup2" >
<property name="title" >
<string/>
</property>
<layout class="QVBoxLayout" >
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="checkMail" >
<property name="text" >
<string comment="Export a key via email" >Email</string>
<widget class="QGroupBox" name="buttonGroup2">
<property name="title">
<string/>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QRadioButton" name="checkMail">
<property name="text">
<string comment="Export a key via email">Email</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkClipboard">
<property name="text">
<string>Clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkServer">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Key server:</string>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="destServer">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkFile">
<property name="text">
<string>File:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="newFilename">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkClipboard" >
<property name="text" >
<string>Clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkServer" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Key server:</string>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="destServer" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkFile" >
<property name="text" >
<string>File:</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="newFilename" >
<property name="enabled" >
<bool>true</bool>
<widget class="QGroupBox" name="buttonGroup3">
<property name="title">
<string>Export Settings</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QRadioButton" name="checkAttrAll">
<property name="text">
<string>Export everything</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkAttrPhoto">
<property name="text">
<string>Do not export attributes (photo ids)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkAttrClean">
<property name="text">
<string comment="@option:radio Exports the smallest key possible. Maps to export-minimal option of gpg">Clean key</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>602</width>
<height>108</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="buttonGroup3" >
<property name="title" >
<string>Export Settings</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QRadioButton" name="checkAttrAll" >
<property name="text" >
<string>Export everything</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkAttrPhoto" >
<property name="text" >
<string>Do not export attributes (photo ids)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="checkAttrClean" >
<property name="text" >
<string comment="@option:radio Exports the smallest key possible. Maps to export-minimal option of gpg" >Clean key</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>602</width>
<height>91</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<includes>
<include location="local" >kpushbutton.h</include>
<include location="local">kpushbutton.h</include>
</includes>
<resources/>
<connections>
......@@ -153,11 +160,11 @@
<receiver>destServer</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>72</x>
<y>69</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>95</x>
<y>106</y>
</hint>
......@@ -169,11 +176,11 @@
<receiver>newFilename</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>39</x>
<y>133</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>48</x>
<y>159</y>
</hint>
......
/*
* Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
* Copyright (C) 2007,2008,2009,2010,2011 Rolf Eike Beer <kde@opensource.sf-tec.de>
* Copyright (C) 2011 Luis Ángel Fernández Fernández <laffdez@gmail.com>
*/
/***************************************************************************
......@@ -1493,7 +1494,7 @@ void KeysManager::slotexport()
if (ndlist.count() == 1) {
sname = ndlist.at(0)->getEmail().section(QLatin1Char( '@' ), 0, 0).section(QLatin1Char( '.' ), 0, 0);
if (sname.isEmpty())
sname = ndlist.at(0)->getName().section(QLatin1Char( ' ' ), 0, 0);
sname = ndlist.at(0)->getName().section(QLatin1Char(' '), 0, 0);
} else
sname = QLatin1String( "keyring" );
......@@ -1505,12 +1506,6 @@ void KeysManager::slotexport()
sname.append(QLatin1String( ".asc" ));
sname.prepend(QDir::homePath() + QLatin1Char( '/' ));
KDialog *dial = new KDialog(this );
dial->setCaption( i18n("Public Key Export") );
dial->setButtons( KDialog::Ok | KDialog::Cancel );
dial->setDefaultButton( KDialog::Ok );
dial->setModal( true );
QStringList serverList(KGpgSettings::keyServers());
serverList.replaceInStrings(QRegExp( QLatin1String( " .*") ), QLatin1String( "" ) ); // Remove kde 3.5 (Default) tag.
if (!serverList.isEmpty()) {
......@@ -1519,19 +1514,14 @@ void KeysManager::slotexport()
serverList.prepend(defaultServer);
}
KeyExport *page = new KeyExport(dial, serverList);
QPointer<KeyExport> page = new KeyExport(this, serverList);
dial->setMainWidget(page);
page->newFilename->setUrl(sname);
page->newFilename->setWindowTitle(i18n("Save File"));
page->newFilename->setMode(KFile::File);
if (!m_online)
page->checkServer->setEnabled(false);
page->show();
if (dial->exec() == QDialog::Accepted) {
if (page->exec() == QDialog::Accepted) {
// export to file
QString exportAttr;
......@@ -1577,7 +1567,7 @@ void KeysManager::slotexport()
}
}
delete dial;
delete page;
}
void KeysManager::slotExportFinished(int result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment