summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <kde@opensource.sf-tec.de>2012-03-07 18:39:59 (GMT)
committerRolf Eike Beer <kde@opensource.sf-tec.de>2012-03-07 18:55:16 (GMT)
commitfa5e306040bb977f38da6732d6a10330ed10d6b4 (patch)
treed1efed43ebfad56d5bb97c0a8d9e01360b287010
parent092be7e2df9c7d013463f96ff7d187027fed20b3 (diff)
make operations on UTF-8 text in editor work
Signing, verifying, and encrypting were previously broken. This will very likely break any text that is not UTF-8 encoded, but I doubt that the editor can currently handle that anyway. BUG:295397
-rw-r--r--editor/kgpgtextedit.cpp26
-rw-r--r--editor/kgpgtextedit.h3
-rw-r--r--kgpgtextinterface.cpp30
-rw-r--r--transactions/kgpgtextorfiletransaction.cpp2
4 files changed, 15 insertions, 46 deletions
diff --git a/editor/kgpgtextedit.cpp b/editor/kgpgtextedit.cpp
index 1cc44f3..6d090e3 100644
--- a/editor/kgpgtextedit.cpp
+++ b/editor/kgpgtextedit.cpp
@@ -16,7 +16,6 @@
#include <QDragEnterEvent>
#include <QTextStream>
-#include <QTextCodec>
#include <QDropEvent>
#include <QFile>
@@ -245,15 +244,6 @@ void KgpgTextEdit::slotVerify(const QString &message)
interface->verifyText(message.mid(posstart, posend - posstart));
}
-bool KgpgTextEdit::checkForUtf8(const QString &text)
-{
- // try to guess if the decrypted text uses utf-8 encoding
- QTextCodec *codec = QTextCodec::codecForLocale();
- if (!codec->canEncode(text))
- return true;
- return false;
-}
-
void KgpgTextEdit::slotDecryptDone(int result)
{
KGpgDecrypt *decr = qobject_cast<KGpgDecrypt *>(sender());
@@ -265,9 +255,7 @@ void KgpgTextEdit::slotDecryptDone(int result)
}
if (result == KGpgTransaction::TS_OK) {
-#ifdef __GNUC__
-#warning FIXME choose codec
-#endif
+ // FIXME choose codec
setPlainText(decr->decryptedText().join(QLatin1String("\n")) + QLatin1Char('\n'));
} else if (result != KGpgTransaction::TS_USER_ABORTED) {
KMessageBox::detailedSorry(this, i18n("Decryption failed."), decr->getMessages().join( QLatin1String( "\n" )));
@@ -301,16 +289,8 @@ void KgpgTextEdit::slotSignUpdate(const QString &content)
return;
}
- if (checkForUtf8(content))
- {
- setPlainText(QString::fromUtf8(content.toAscii()));
- emit resetEncoding(true);
- }
- else
- {
- setPlainText(content);
- emit resetEncoding(false);
- }
+ setPlainText(content);
+ emit resetEncoding(false);
}
void KgpgTextEdit::slotVerifySuccess(const QString &content, const QString &log)
diff --git a/editor/kgpgtextedit.h b/editor/kgpgtextedit.h
index 1663595..f540833 100644
--- a/editor/kgpgtextedit.h
+++ b/editor/kgpgtextedit.h
@@ -55,9 +55,6 @@ protected:
void dragEnterEvent(QDragEnterEvent *e);
void dropEvent(QDropEvent *e);
-private:
- bool checkForUtf8(const QString &text);
-
private slots:
void slotEncodeUpdate(int result);
void slotSignUpdate(const QString &content);
diff --git a/kgpgtextinterface.cpp b/kgpgtextinterface.cpp
index 3746c01..e0c3006 100644
--- a/kgpgtextinterface.cpp
+++ b/kgpgtextinterface.cpp
@@ -204,17 +204,13 @@ KGpgTextInterface::~KGpgTextInterface()
void
KGpgTextInterface::signText(const QString &text, const QString &userid, const QStringList &options)
{
- QTextCodec *codec = QTextCodec::codecForLocale();
- if (codec->canEncode(text))
- d->m_message = text;
- else
- d->m_message =QLatin1String( text.toUtf8() );
+ d->m_message = text;
*d->m_process << options;
*d->m_process << QLatin1String( "--clearsign" ) << QLatin1String( "-u" ) << userid;
- connect(d->m_process, SIGNAL(lineReadyStandardOutput()), this, SLOT(signTextProcess()));
+ connect(d->m_process, SIGNAL(readReady()), SLOT(signTextProcess()));
connect(d->m_process, SIGNAL(processExited()), this, SLOT(signTextFin()));
d->m_process->start();
}
@@ -223,26 +219,27 @@ KGpgTextInterface::signText(const QString &text, const QString &userid, const QS
void
KGpgTextInterface::signTextProcess()
{
- QByteArray line;
+ QString line;
- while (d->m_process->readLineStandardOutput(&line)) {
+ while (d->m_process->readln(line, true) >= 0) {
if (line.startsWith("[GNUPG:]")) {
if (line.contains( "USERID_HINT" )) {
- d->updateIDs(line);
+ d->updateIDs(line.toAscii());
} else if (line.contains( "BAD_PASSPHRASE" )) {
d->m_message.fill(QLatin1Char( 'x' ));
d->m_message.clear();
d->m_badpassword = true;
} else if (line.contains( "GOOD_PASSPHRASE" )) {
- d->m_process->write(d->m_message.toAscii());
+ d->m_process->write(d->m_message.toUtf8());
d->m_process->closeWriteChannel();
d->m_message.clear();
} else if (line.contains( "passphrase.enter" )) {
if (d->gpgPassphrase())
return;
}
- } else
- d->m_message +=QLatin1String( line ) + QLatin1Char( '\n' );
+ } else {
+ d->m_message += line + QLatin1Char('\n');
+ }
}
}
//krazy:endcond=strings
@@ -262,11 +259,7 @@ KGpgTextInterface::signTextFin()
void
KGpgTextInterface::verifyText(const QString &text)
{
- QTextCodec *codec = QTextCodec::codecForLocale();
- if (codec->canEncode(text))
- d->m_message = text;
- else
- d->m_message = QLatin1String( text.toUtf8() );
+ d->m_message.clear();
*d->m_process << QLatin1String( "--verify" );
@@ -274,8 +267,7 @@ KGpgTextInterface::verifyText(const QString &text)
connect(d->m_process, SIGNAL(processExited()), this, SLOT(verifyTextFin()));
d->m_process->start();
- d->m_process->write(d->m_message.toAscii());
- d->m_message.clear();
+ d->m_process->write(text.toUtf8());
d->m_process->closeWriteChannel();
}
diff --git a/transactions/kgpgtextorfiletransaction.cpp b/transactions/kgpgtextorfiletransaction.cpp
index ee5f3e6..e2796d0 100644
--- a/transactions/kgpgtextorfiletransaction.cpp
+++ b/transactions/kgpgtextorfiletransaction.cpp
@@ -92,7 +92,7 @@ KGpgTextOrFileTransaction::postStart()
{
if (!m_text.isEmpty()){
GPGProc *proc = getProcess();
- proc->write(m_text.toAscii());
+ proc->write(m_text.toUtf8());
proc->closeWriteChannel();
}
}