summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2020-12-08 19:16:29 +0100
committerAnne Jan Brouwer <brouwer@annejan.com>2020-12-08 19:16:29 +0100
commitf47db79eb566bfe8ed6fca5b31e29bcce0ccdd74 (patch)
treef320f5807795c63a960ed2434ff0a449ba2d1d1d /src
parentea1906e042c1e45042208942ea70986c5ba82e9c (diff)
Qt6 compatibility
Diffstat (limited to 'src')
-rw-r--r--src/executor.cpp8
-rw-r--r--src/imitatepass.cpp15
-rw-r--r--src/keygendialog.cpp17
-rw-r--r--src/mainwindow.cpp12
-rw-r--r--src/pass.cpp10
-rw-r--r--src/qtpass.cpp20
-rw-r--r--src/realpass.cpp9
-rw-r--r--src/storemodel.cpp7
-rw-r--r--src/usersdialog.cpp20
9 files changed, 63 insertions, 55 deletions
diff --git a/src/executor.cpp b/src/executor.cpp
index 0790683b..a4e91bb4 100644
--- a/src/executor.cpp
+++ b/src/executor.cpp
@@ -1,7 +1,9 @@
#include "executor.h"
#include <QCoreApplication>
#include <QDir>
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QTextCodec>
+#endif
#ifdef QT_DEBUG
#include "debughelper.h"
@@ -131,11 +133,13 @@ void Executor::execute(int id, const QString &workDir, const QString &app,
* If this fails (which is likely if it is not actually UTF-8)
* it will then fall back to Qt's decoding function, which
* will try based on BOM and if that fails fall back to local encoding.
+ * This should not be needed in Qt6
*
* @param in input data
* @return Input bytes decoded to string
*/
static QString decodeAssumingUtf8(QByteArray in) {
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::ConverterState state;
QString out = codec->toUnicode(in.constData(), in.size(), &state);
@@ -143,6 +147,10 @@ static QString decodeAssumingUtf8(QByteArray in) {
return out;
codec = QTextCodec::codecForUtfText(in);
return codec->toUnicode(in);
+#else
+ auto converter = QStringDecoder(QStringDecoder::Utf8);
+ return converter(in);
+#endif
}
/**
diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp
index 641ed546..ed926ba0 100644
--- a/src/imitatepass.cpp
+++ b/src/imitatepass.cpp
@@ -1,6 +1,7 @@
#include "imitatepass.h"
#include "qtpasssettings.h"
#include <QDirIterator>
+#include <QRegularExpression>
#include <utility>
#ifdef QT_DEBUG
@@ -111,7 +112,7 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) {
if (!overwrite)
executeGit(GIT_ADD, {"add", pgit(file)});
QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(file);
- path.replace(QRegExp("\\.gpg$"), "");
+ path.replace(QRegularExpression("\\.gpg$"), "");
QString msg =
QString(overwrite ? "Edit" : "Add") + " for " + path + " using QtPass.";
GitCommit(file, msg);
@@ -200,7 +201,7 @@ void ImitatePass::Init(QString path, const QList<UserInfo> &users) {
if (addFile)
executeGit(GIT_ADD, {"add", pgit(gpgIdFile)});
QString commitPath = gpgIdFile;
- commitPath.replace(QRegExp("\\.gpg$"), "");
+ commitPath.replace(QRegularExpression("\\.gpg$"), "");
GitCommit(gpgIdFile, "Added " + commitPath + " using QtPass.");
}
reencryptPath(path);
@@ -267,9 +268,9 @@ void ImitatePass::reencryptPath(const QString &dir) {
QStringList actualKeys;
keys += err;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- QStringList key = keys.split(QRegExp("[\r\n]"), Qt::SkipEmptyParts);
+ QStringList key = keys.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
#else
- QStringList key = keys.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QStringList key = keys.split(QRegularExpression("[\r\n]"), QString::SkipEmptyParts);
#endif
QListIterator<QString> itr(key);
while (itr.hasNext()) {
@@ -322,7 +323,7 @@ void ImitatePass::reencryptPath(const QString &dir) {
{"add", pgit(fileName)});
QString path =
QDir(QtPassSettings::getPassStore()).relativeFilePath(fileName);
- path.replace(QRegExp("\\.gpg$"), "");
+ path.replace(QRegularExpression("\\.gpg$"), "");
exec.executeBlocking(QtPassSettings::getGitExecutable(),
{"commit", pgit(fileName), "-m",
"Edit for " + path + " using QtPass."});
@@ -402,9 +403,9 @@ void ImitatePass::Move(const QString src, const QString dest,
executeGit(GIT_MOVE, args);
QString relSrc = QDir(QtPassSettings::getPassStore()).relativeFilePath(src);
- relSrc.replace(QRegExp("\\.gpg$"), "");
+ relSrc.replace(QRegularExpression("\\.gpg$"), "");
QString relDest = QDir(QtPassSettings::getPassStore()).relativeFilePath(destFile);
- relDest.replace(QRegExp("\\.gpg$"), "");
+ relDest.replace(QRegularExpression("\\.gpg$"), "");
QString message = QString("Moved for %1 to %2 using QtPass.");
message = message.arg(relSrc).arg(relDest);
GitCommit("", message);
diff --git a/src/keygendialog.cpp b/src/keygendialog.cpp
index e8abe389..a7661865 100644
--- a/src/keygendialog.cpp
+++ b/src/keygendialog.cpp
@@ -3,6 +3,7 @@
#include "qprogressindicator.h"
#include "ui_keygendialog.h"
#include <QMessageBox>
+#include <QRegularExpression>
#ifdef QT_DEBUG
#include "debughelper.h"
@@ -84,12 +85,12 @@ void KeygenDialog::replace(const QString &key, const QString &value) {
QStringList clear;
QString expert = ui->plainTextEdit->toPlainText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- QStringList lines = expert.split(QRegExp("[\r\n]"), Qt::SkipEmptyParts);
+ QStringList lines = expert.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
#else
- QStringList lines = expert.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QStringList lines = expert.split(QRegularExpression("[\r\n]"), QString::SkipEmptyParts);
#endif
foreach (QString line, lines) {
- line.replace(QRegExp(key + ":.*"), key + ": " + value);
+ line.replace(QRegularExpression(key + ":.*"), key + ": " + value);
if (key == "Passphrase")
line.replace("%no-protection", "Passphrase: " + value);
clear.append(line);
@@ -106,9 +107,9 @@ void KeygenDialog::no_protection(bool enable) {
QStringList clear;
QString expert = ui->plainTextEdit->toPlainText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- QStringList lines = expert.split(QRegExp("[\r\n]"), Qt::SkipEmptyParts);
+ QStringList lines = expert.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
#else
- QStringList lines = expert.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QStringList lines = expert.split(QRegularExpression("[\r\n]"), QString::SkipEmptyParts);
#endif
foreach (QString line, lines) {
bool remove = false;
@@ -140,10 +141,8 @@ void KeygenDialog::done(int r) {
}
// check email
- QRegExp mailre(R"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)");
- mailre.setCaseSensitivity(Qt::CaseInsensitive);
- mailre.setPatternSyntax(QRegExp::RegExp);
- if (!mailre.exactMatch(ui->email->text())) {
+ QRegularExpression mailre(QRegularExpression::anchoredPattern(R"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)"), QRegularExpression::CaseInsensitiveOption);
+ if (!mailre.match(ui->email->text()).hasMatch()) {
QMessageBox::critical(
this, tr("Invalid email"),
tr("The email address you typed is not a valid email address."));
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 036fba12..ca71822c 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -48,7 +48,7 @@ MainWindow::MainWindow(const QString &searchText, QWidget *parent)
m_qtPass = new QtPass(this);
// register shortcut ctrl/cmd + Q to close the main window
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
+ new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this, SLOT(close()));
// register shortcut ctrl/cmd + C to copy the currently selected password
new QShortcut(QKeySequence(QKeySequence::StandardKey::Copy), this,
SLOT(copyPasswordFromTreeview()));
@@ -306,7 +306,7 @@ QString MainWindow::getFile(const QModelIndex &index, bool forPass) {
QString filePath = model.filePath(proxyModel.mapToSource(index));
if (forPass) {
filePath = QDir(QtPassSettings::getPassStore()).relativeFilePath(filePath);
- filePath.replace(QRegExp("\\.gpg$"), "");
+ filePath.replace(QRegularExpression("\\.gpg$"), "");
}
return filePath;
}
@@ -522,9 +522,9 @@ void MainWindow::onTimeoutSearch() {
deselect();
}
- query.replace(QRegExp(" "), ".*");
- QRegExp regExp(query, Qt::CaseInsensitive);
- proxyModel.setFilterRegExp(regExp);
+ query.replace(QRegularExpression(" "), ".*");
+ QRegularExpression regExp(query, QRegularExpression::CaseInsensitiveOption);
+ proxyModel.setFilterRegularExpression(regExp);
ui->treeView->setRootIndex(proxyModel.mapFromSource(
model.setRootPath(QtPassSettings::getPassStore())));
@@ -1120,7 +1120,7 @@ void MainWindow::addToGridLayout(int position, const QString &field,
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
line->setObjectName(trimmedField);
trimmedValue.replace(
- QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
+ QRegularExpression("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
R"(<a href="\1">\1</a>)");
line->setText(trimmedValue);
line->setReadOnly(true);
diff --git a/src/pass.cpp b/src/pass.cpp
index d7f4a8ca..9b2594ec 100644
--- a/src/pass.cpp
+++ b/src/pass.cpp
@@ -85,7 +85,7 @@ QString Pass::Generate_b(unsigned int length, const QString &charset) {
// TODO(bezet): try-catch here(2 statuses to merge o_O)
if (exec.executeBlocking(QtPassSettings::getPwgenExecutable(), args,
&passwd) == 0)
- passwd.remove(QRegExp("[\\n\\r]"));
+ passwd.remove(QRegularExpression("[\\n\\r]"));
else {
passwd.clear();
#ifdef QT_DEBUG
@@ -140,9 +140,9 @@ QList<UserInfo> Pass::listKeys(QStringList keystrings, bool secret) {
0)
return users;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- QStringList keys = p_out.split(QRegExp("[\r\n]"), Qt::SkipEmptyParts);
+ QStringList keys = p_out.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
#else
- QStringList keys = p_out.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QStringList keys = p_out.split(QRegularExpression("[\r\n]"), QString::SkipEmptyParts);
#endif
UserInfo current_user;
foreach (QString key, keys) {
@@ -156,8 +156,8 @@ QList<UserInfo> Pass::listKeys(QStringList keystrings, bool secret) {
current_user.key_id = props[4];
current_user.name = props[9].toUtf8();
current_user.validity = props[1][0].toLatin1();
- current_user.created.setTime_t(props[5].toUInt());
- current_user.expiry.setTime_t(props[6].toUInt());
+ current_user.created.setSecsSinceEpoch(props[5].toUInt());
+ current_user.expiry.setSecsSinceEpoch(props[6].toUInt());
} else if (current_user.name.isEmpty() && props[0] == "uid") {
current_user.name = props[9];
} else if ((props[0] == "fpr") && props[9].endsWith(current_user.key_id)) {
diff --git a/src/qtpass.cpp b/src/qtpass.cpp
index eb0030c7..7590d711 100644
--- a/src/qtpass.cpp
+++ b/src/qtpass.cpp
@@ -267,9 +267,9 @@ void QtPass::processErrorExit(int exitCode, const QString &p_error) {
if (!p_error.isEmpty()) {
QString output;
QString error = p_error;
- error.replace(QRegExp("<"), "&lt;");
- error.replace(QRegExp(">"), "&gt;");
- error.replace(QRegExp(" "), "&nbsp;");
+ error.replace(QRegularExpression("<"), "&lt;");
+ error.replace(QRegularExpression(">"), "&gt;");
+ error.replace(QRegularExpression(" "), "&nbsp;");
if (exitCode == 0) {
// https://github.com/IJHack/qtpass/issues/111
output = "<span style=\"color: darkgray;\">" + error + "</span><br />";
@@ -278,9 +278,9 @@ void QtPass::processErrorExit(int exitCode, const QString &p_error) {
}
output.replace(
- QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
+ QRegularExpression("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
R"(<a href="\1">\1</a>)");
- output.replace(QRegExp("\n"), "<br />");
+ output.replace(QRegularExpression("\n"), "<br />");
m_mainWindow->flashText(output, false, true);
}
@@ -335,14 +335,14 @@ void QtPass::passShowHandlerFinished(QString output) {
void QtPass::showInTextBrowser(QString output, QString prefix,
QString postfix) {
- output.replace(QRegExp("<"), "&lt;");
- output.replace(QRegExp(">"), "&gt;");
- output.replace(QRegExp(" "), "&nbsp;");
+ output.replace(QRegularExpression("<"), "&lt;");
+ output.replace(QRegularExpression(">"), "&gt;");
+ output.replace(QRegularExpression(" "), "&nbsp;");
output.replace(
- QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
+ QRegularExpression("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
R"(<a href="\1">\1</a>)");
- output.replace(QRegExp("\n"), "<br />");
+ output.replace(QRegularExpression("\n"), "<br />");
output = prefix + output + postfix;
m_mainWindow->flashText(output, false, true);
diff --git a/src/realpass.cpp b/src/realpass.cpp
index 7e3dcf87..321cd3a3 100644
--- a/src/realpass.cpp
+++ b/src/realpass.cpp
@@ -3,6 +3,7 @@
#include <QDir>
#include <QFileInfo>
+#include <QRegularExpression>
#include <utility>
using namespace Enums;
@@ -116,10 +117,10 @@ void RealPass::Move(const QString src, const QString dest, const bool force) {
// remove the .gpg because pass will not work
if (srcFileInfo.isFile() && srcFileInfo.suffix() == "gpg") {
- passSrc.replace(QRegExp("\\.gpg$"), "");
+ passSrc.replace(QRegularExpression("\\.gpg$"), "");
}
if (destFileInfo.isFile() && destFileInfo.suffix() == "gpg") {
- passDest.replace(QRegExp("\\.gpg$"), "");
+ passDest.replace(QRegularExpression("\\.gpg$"), "");
}
QStringList args;
@@ -156,10 +157,10 @@ void RealPass::Copy(const QString src, const QString dest, const bool force) {
// remove the .gpg because pass will not work
if (srcFileInfo.isFile() && srcFileInfo.suffix() == "gpg") {
- passSrc.replace(QRegExp("\\.gpg$"), "");
+ passSrc.replace(QRegularExpression("\\.gpg$"), "");
}
if (destFileInfo.isFile() && destFileInfo.suffix() == "gpg") {
- passDest.replace(QRegExp("\\.gpg$"), "");
+ passDest.replace(QRegularExpression("\\.gpg$"), "");
}
QStringList args;
args << "cp";
diff --git a/src/storemodel.cpp b/src/storemodel.cpp
index adc0690b..a5bfda55 100644
--- a/src/storemodel.cpp
+++ b/src/storemodel.cpp
@@ -2,6 +2,7 @@
#include "qtpasssettings.h"
#include <QDebug>
+#include <QRegularExpression>
#include <QMessageBox>
#include <QMimeData>
#include <utility>
@@ -67,8 +68,8 @@ bool StoreModel::ShowThis(const QModelIndex index) const {
QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
QString path = fs->filePath(useIndex);
path = QDir(store).relativeFilePath(path);
- path.replace(QRegExp("\\.gpg$"), "");
- retVal = path.contains(filterRegExp());
+ path.replace(QRegularExpression("\\.gpg$"), "");
+ retVal = path.contains(filterRegularExpression());
}
return retVal;
}
@@ -100,7 +101,7 @@ QVariant StoreModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
QString name = initial_value.toString();
- name.replace(QRegExp("\\.gpg$"), "");
+ name.replace(QRegularExpression("\\.gpg$"), "");
initial_value.setValue(name);
}
diff --git a/src/usersdialog.cpp b/src/usersdialog.cpp
index 786144e5..e8ca418e 100644
--- a/src/usersdialog.cpp
+++ b/src/usersdialog.cpp
@@ -4,7 +4,7 @@
#include <QCloseEvent>
#include <QKeyEvent>
#include <QMessageBox>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QWidget>
#include <utility>
@@ -136,27 +136,25 @@ void UsersDialog::itemChange(QListWidgetItem *item) {
* @param filter
*/
void UsersDialog::populateList(const QString &filter) {
- QRegExp nameFilter("*" + filter + "*");
- nameFilter.setPatternSyntax(QRegExp::Wildcard);
- nameFilter.setCaseSensitivity(Qt::CaseInsensitive);
+ QRegularExpression nameFilter(QRegularExpression::wildcardToRegularExpression("*" + filter + "*"), QRegularExpression::CaseInsensitiveOption);
ui->listWidget->clear();
if (!m_userList.isEmpty()) {
for (auto &user : m_userList) {
- if (filter.isEmpty() || nameFilter.exactMatch(user.name)) {
+ if (filter.isEmpty() || nameFilter.match(user.name).hasMatch()) {
if (!user.isValid() && !ui->checkBox->isChecked())
continue;
- if (user.expiry.toTime_t() > 0 &&
+ if (user.expiry.toSecsSinceEpoch() > 0 &&
user.expiry.daysTo(QDateTime::currentDateTime()) > 0 &&
!ui->checkBox->isChecked())
continue;
QString userText = user.name + "\n" + user.key_id;
- if (user.created.toTime_t() > 0) {
+ if (user.created.toSecsSinceEpoch() > 0) {
userText += " " + tr("created") + " " +
- user.created.toString(Qt::SystemLocaleShortDate);
+ user.created.toString(QLocale::system().toString(QDate::currentDate(), QLocale::ShortFormat));
}
- if (user.expiry.toTime_t() > 0)
+ if (user.expiry.toSecsSinceEpoch() > 0)
userText += " " + tr("expires") + " " +
- user.expiry.toString(Qt::SystemLocaleShortDate);
+ user.expiry.toString(QLocale::system().toString(QDate::currentDate(), QLocale::ShortFormat));
auto *item = new QListWidgetItem(userText, ui->listWidget);
item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked);
item->setData(Qt::UserRole, QVariant::fromValue(&user));
@@ -170,7 +168,7 @@ void UsersDialog::populateList(const QString &filter) {
} else if (!user.isValid()) {
item->setBackground(QColor(164, 0, 0));
item->setForeground(Qt::white);
- } else if (user.expiry.toTime_t() > 0 &&
+ } else if (user.expiry.toSecsSinceEpoch() > 0 &&
user.expiry.daysTo(QDateTime::currentDateTime()) > 0) {
item->setForeground(QColor(164, 0, 0));
} else if (!user.fullyValid()) {