summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Ángel Fernández Fernández <laffdez@gmail.com>2011-10-21 19:54:52 (GMT)
committerRolf Eike Beer <kde@opensource.sf-tec.de>2011-10-21 20:57:19 (GMT)
commitc97530d36fc24221b8ce99abd54b79ebfff495fb (patch)
treef80b99444f06d152e77ac46aacbda9084e8e2e66
parentf00af52e57a8710b6ed326c15e2a2793781c4830 (diff)
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
-rw-r--r--keyexport.cpp50
-rw-r--r--keyexport.h23
-rw-r--r--keyexport.ui231
-rw-r--r--keysmanager.cpp20
4 files changed, 171 insertions, 153 deletions
diff --git a/keyexport.cpp b/keyexport.cpp
index 06f6ce4..136577e 100644
--- a/keyexport.cpp
+++ b/keyexport.cpp
@@ -1,10 +1,8 @@
-/***************************************************************************
- 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"
diff --git a/keyexport.h b/keyexport.h
index 43fece2..45c9dbc 100644
--- a/keyexport.h
+++ b/keyexport.h
@@ -1,10 +1,8 @@
-/***************************************************************************
- 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
diff --git a/keyexport.ui b/keyexport.ui
index 951a46c..931de49 100644
--- a/keyexport.ui
+++ b/keyexport.ui
@@ -1,7 +1,8 @@
-<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>
diff --git a/keysmanager.cpp b/keysmanager.cpp
index e48ee3d..498a64e 100644
--- a/keysmanager.cpp
+++ b/keysmanager.cpp
@@ -1,6 +1,7 @@
/*
* 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)