Improve Copy&Paste behavior: Accept Ctrl-V and MousePaste on MainWindow

This commit is contained in:
Christian Hohnstaedt 2017-07-14 17:22:21 +02:00
parent ac780d3e77
commit f12c3ca8aa
3 changed files with 31 additions and 16 deletions

View File

@ -7,6 +7,7 @@
#include <signal.h>
#include <QApplication>
#include <QClipboard>
#include <QTranslator>
#include <QTextCodec>
#include <QDir>
@ -146,9 +147,9 @@ bool XCA_application::eventFilter(QObject *watched, QEvent *ev)
static int mctr;
QMouseEvent *me;
QStringList l;
XcaTreeView *treeview;
int key;
(void)watched;
switch (ev->type()) {
case QEvent::FileOpen:
l << static_cast<QFileOpenEvent *>(ev)->file();
@ -169,6 +170,19 @@ bool XCA_application::eventFilter(QObject *watched, QEvent *ev)
entropy.add(key);
}
break;
case QEvent::MouseButtonPress:
me = static_cast<QMouseEvent *>(ev);
treeview = watched ?
dynamic_cast<XcaTreeView*>(watched->parent()) : NULL;
if ((watched == mainw || treeview) &&
me->button() == Qt::MidButton &&
QApplication::clipboard()->supportsSelection())
{
mainw->pastePem();
return true;
}
break;
default:
break;
}

View File

@ -46,18 +46,13 @@ pki_base *pki_multi::pull()
/* General PEM loader */
static pki_base *pkiByPEM(QString text, int *skip)
{
int pos;
pos = text.indexOf(BEGIN);
if (pos <0) {
if (skip)
*skip = text.length() - (sizeof(BEGIN)-1);
return NULL;
}
if (skip) {
int pos = text.indexOf(BEGIN);
if (skip)
*skip = pos;
if (pos) /* if we are not at the beginning, retry */
return NULL;
}
if (pos < 0)
return NULL;
text = text.remove(0, pos + sizeof(BEGIN)-1);
if (text.startsWith(PEM_STRING_X509_OLD D5) ||
@ -113,7 +108,7 @@ void pki_multi::fromPEMbyteArray(QByteArray &ba, QString name)
for (;;) {
try {
item = pkiByPEM(QString::fromLatin1(ba), &startpos);
if (!item || startpos < 0)
if (!item)
break;
ba.remove(0, startpos);
item->fromPEMbyteArray(ba, name);

View File

@ -390,12 +390,13 @@ void MainWindow::pastePem()
ui.button->setText(tr("Import PEM data"));
input->setWindowTitle(XCA_TITLE);
textbox->setPlainText(text);
if (input->exec())
if (input->exec()) {
text = textbox->toPlainText();
if (!text.isEmpty())
pastePem(text);
}
delete input;
if (!text.isEmpty())
pastePem(text);
}
void MainWindow::initToken()
@ -1018,6 +1019,11 @@ void MainWindow::keyPressEvent(QKeyEvent *e)
XCA_application::tableFont.setPointSize(siz -1);
}
break;
case Qt::Key_V:
if (e->modifiers() == Qt::ControlModifier) {
pastePem();
break;
}
default:
QMainWindow::keyPressEvent(e);
return;