Adapt to c++utilities v5
This commit is contained in:
parent
f113197b62
commit
f863fb474c
|
@ -114,18 +114,20 @@ set(REQUIRED_ICONS
|
|||
window-close)
|
||||
|
||||
# find c++utilities
|
||||
find_package(c++utilities 4.10.0 REQUIRED)
|
||||
set(CONFIGURATION_PACKAGE_SUFFIX ""
|
||||
CACHE STRING "sets the suffix for find_package() calls to packages configured via c++utilities")
|
||||
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED)
|
||||
use_cpp_utilities()
|
||||
|
||||
# apply basic configuration
|
||||
include(BasicConfig)
|
||||
|
||||
# find qtutilities
|
||||
find_package(qtutilities 5.11.0 REQUIRED)
|
||||
find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX} 6.0.0 REQUIRED)
|
||||
use_qt_utilities()
|
||||
|
||||
# find passwordfile
|
||||
find_package(passwordfile 4.0.0 REQUIRED)
|
||||
find_package(passwordfile${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED)
|
||||
use_password_file()
|
||||
|
||||
# require at least Qt 5.8 for the Qt Quick GUI
|
||||
|
|
16
cli/cli.cpp
16
cli/cli.cpp
|
@ -9,7 +9,6 @@
|
|||
#include <c++utilities/application/commandlineutils.h>
|
||||
#include <c++utilities/conversion/stringconversion.h>
|
||||
#include <c++utilities/io/ansiescapecodes.h>
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
|
||||
#if defined(PLATFORM_UNIX)
|
||||
#include <unistd.h>
|
||||
|
@ -260,10 +259,9 @@ void InteractiveCli::openFile(const string &file, PasswordFileOpenFlags openFlag
|
|||
} catch (const CryptoException &) {
|
||||
m_o << "error occured when decrypting file \"" << file << "\"" << endl;
|
||||
throw;
|
||||
} catch (...) {
|
||||
const char *what = catchIoFailure();
|
||||
} catch (const std::ios_base::failure &) {
|
||||
m_o << "IO error occured when opening file \"" << file << "\"" << endl;
|
||||
throw ios_base::failure(what);
|
||||
throw;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
if (*e.what() != 0) {
|
||||
|
@ -312,10 +310,9 @@ void InteractiveCli::saveFile()
|
|||
} catch (const CryptoException &) {
|
||||
m_o << "error occured when encrypting file \"" << m_file.path() << "\"" << endl;
|
||||
throw;
|
||||
} catch (...) {
|
||||
const char *what = catchIoFailure();
|
||||
} catch (const std::ios_base::failure &) {
|
||||
m_o << "IO error occured when saving file \"" << m_file.path() << "\"" << endl;
|
||||
throw ios_base::failure(what);
|
||||
throw;
|
||||
}
|
||||
} catch (const exception &e) {
|
||||
if (*e.what() != 0) {
|
||||
|
@ -341,10 +338,9 @@ void InteractiveCli::createFile(const string &file)
|
|||
m_file.generateRootEntry();
|
||||
m_currentEntry = m_file.rootEntry();
|
||||
m_o << "file \"" << file << "\" created and opened" << endl;
|
||||
} catch (...) {
|
||||
const char *what = catchIoFailure();
|
||||
} catch (const std::ios_base::failure &) {
|
||||
m_o << "IO error occured when creating file \"" << file << "\"" << endl;
|
||||
throw ios_base::failure(what);
|
||||
throw;
|
||||
}
|
||||
} catch (const exception &e) {
|
||||
if (*e.what() != 0) {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <qtutilities/settingsdialog/settingsdialog.h>
|
||||
|
||||
#include <c++utilities/conversion/stringconversion.h>
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
#include <c++utilities/io/path.h>
|
||||
|
||||
#include <QActionGroup>
|
||||
|
@ -425,17 +424,15 @@ bool MainWindow::openFile(const QString &path, PasswordFileOpenFlags openFlags)
|
|||
m_file.setPath(path.toStdString());
|
||||
try {
|
||||
m_file.open(m_openFlags = openFlags);
|
||||
} catch (...) {
|
||||
// catch std::ios_base::failure
|
||||
const char *const ioError = catchIoFailure();
|
||||
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
// try read-only
|
||||
if (!(m_openFlags & PasswordFileOpenFlags::ReadOnly)) {
|
||||
return openFile(path, m_openFlags | PasswordFileOpenFlags::ReadOnly);
|
||||
}
|
||||
|
||||
// show error message
|
||||
const QString errmsg = tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(ioError));
|
||||
const QString errmsg
|
||||
= tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(failure.what()));
|
||||
m_ui->statusBar->showMessage(errmsg, 5000);
|
||||
QMessageBox::critical(this, QApplication::applicationName(), errmsg);
|
||||
return false;
|
||||
|
@ -480,9 +477,9 @@ bool MainWindow::openFile(const QString &path, PasswordFileOpenFlags openFlags)
|
|||
m_file.load();
|
||||
} catch (const CryptoException &e) {
|
||||
msg = tr("The file couldn't be decrypted.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(e.what()));
|
||||
} catch (...) {
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
try {
|
||||
msg = QString::fromLocal8Bit(catchIoFailure());
|
||||
msg = QString::fromLocal8Bit(failure.what());
|
||||
} catch (const runtime_error &e) {
|
||||
msg = tr("Unable to parse the file. %1").arg(QString::fromLocal8Bit(e.what()));
|
||||
}
|
||||
|
@ -544,9 +541,9 @@ void MainWindow::createFile(const QString &path, const QString &password)
|
|||
try {
|
||||
m_openFlags = PasswordFileOpenFlags::Default;
|
||||
m_file.create();
|
||||
} catch (...) {
|
||||
catchIoFailure();
|
||||
QMessageBox::critical(this, QApplication::applicationName(), tr("The file <i>%1</i> couldn't be created.").arg(path));
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
QMessageBox::critical(this, QApplication::applicationName(),
|
||||
tr("The file <i>%1</i> couldn't be created: %2").arg(path, QString::fromLocal8Bit(failure.what())));
|
||||
return;
|
||||
}
|
||||
m_file.generateRootEntry();
|
||||
|
@ -742,8 +739,8 @@ bool MainWindow::askForCreatingFile()
|
|||
try {
|
||||
m_file.create();
|
||||
updateWindowTitle();
|
||||
} catch (...) {
|
||||
QMessageBox::critical(this, QApplication::applicationName(), QString::fromLocal8Bit(catchIoFailure()));
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
QMessageBox::critical(this, QApplication::applicationName(), QString::fromLocal8Bit(failure.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -830,9 +827,9 @@ bool MainWindow::saveFile()
|
|||
if (m_ui->actionAlwaysCreateBackup->isChecked()) {
|
||||
try {
|
||||
m_file.doBackup();
|
||||
} catch (...) {
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
const QString message(
|
||||
tr("The backup file couldn't be created because in IO error occured: %1").arg(QString::fromLocal8Bit(catchIoFailure())));
|
||||
tr("The backup file couldn't be created because in IO error occured: %1").arg(QString::fromLocal8Bit(failure.what())));
|
||||
QMessageBox::critical(this, QApplication::applicationName(), message);
|
||||
m_ui->statusBar->showMessage(message, 7000);
|
||||
return false;
|
||||
|
@ -865,8 +862,8 @@ bool MainWindow::saveFile()
|
|||
m_file.save(saveOptions());
|
||||
} catch (const CryptoException &ex) {
|
||||
msg = tr("The password list couldn't be saved due to encryption failure.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(ex.what()));
|
||||
} catch (...) {
|
||||
msg = QString::fromLocal8Bit(catchIoFailure());
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
msg = QString::fromLocal8Bit(failure.what());
|
||||
}
|
||||
// show status
|
||||
if (!msg.isEmpty()) {
|
||||
|
@ -900,8 +897,8 @@ void MainWindow::exportFile()
|
|||
QString errmsg;
|
||||
try {
|
||||
m_file.exportToTextfile(targetPath.toStdString());
|
||||
} catch (...) {
|
||||
errmsg = tr("The password list couldn't be exported. %1").arg(QString::fromLocal8Bit(catchIoFailure()));
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
errmsg = tr("The password list couldn't be exported. %1").arg(QString::fromLocal8Bit(failure.what()));
|
||||
}
|
||||
if (errmsg.isEmpty()) {
|
||||
m_ui->statusBar->showMessage(tr("The password list has been exported."), 5000);
|
||||
|
|
1
main.cpp
1
main.cpp
|
@ -7,6 +7,7 @@
|
|||
#endif
|
||||
|
||||
#include "resources/config.h"
|
||||
#include "resources/qtconfig.h"
|
||||
|
||||
#include <passwordfile/util/openssl.h>
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
#include <passwordfile/io/entry.h>
|
||||
#include <passwordfile/io/parsingexception.h>
|
||||
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
|
@ -246,8 +244,7 @@ QVariant EntryModel::data(const QModelIndex &index, int role) const
|
|||
// FIXME: make conversion to QByteArray more efficient
|
||||
const auto str(ss.str());
|
||||
return QByteArray(str.data(), str.size());
|
||||
} catch (...) {
|
||||
IoUtilities::catchIoFailure();
|
||||
} catch (const std::ios_base::failure &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -318,9 +315,8 @@ bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
|||
} catch (const Io::ParsingException &parsingError) {
|
||||
cerr << "EntryModel::setData: parsing exception: " << parsingError.what() << endl;
|
||||
return false;
|
||||
} catch (...) {
|
||||
const char *const errorMessage(IoUtilities::catchIoFailure());
|
||||
cerr << "EntryModel::setData: IO exception: " << errorMessage << endl;
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
cerr << "EntryModel::setData: IO exception: " << failure.what() << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <qtutilities/misc/dialogutils.h>
|
||||
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
#include <c++utilities/io/nativefilestream.h>
|
||||
#include <c++utilities/io/path.h>
|
||||
|
||||
|
@ -155,7 +154,7 @@ void Controller::load(const QString &filePath)
|
|||
} catch (const runtime_error &e) {
|
||||
emit fileError(tr("A parsing error occured when opening the file: ") + QString::fromLocal8Bit(e.what()), QStringLiteral("load"));
|
||||
} catch (...) {
|
||||
emitIoError(tr("loading"));
|
||||
emitFileError(tr("loading"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +171,7 @@ void Controller::create(const QString &filePath)
|
|||
}
|
||||
m_file.create();
|
||||
} catch (...) {
|
||||
emitIoError(tr("creating"));
|
||||
emitFileError(tr("creating"));
|
||||
}
|
||||
|
||||
m_file.generateRootEntry();
|
||||
|
@ -187,7 +186,7 @@ void Controller::close()
|
|||
m_file.close();
|
||||
resetFileStatus();
|
||||
} catch (...) {
|
||||
emitIoError(tr("closing"));
|
||||
emitFileError(tr("closing"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,7 +220,7 @@ void Controller::save()
|
|||
return;
|
||||
}
|
||||
|
||||
m_file.fileStream().openFromFileDescriptor(newFileDescriptor, ios_base::out | ios_base::trunc | ios_base::binary);
|
||||
m_file.fileStream().open(newFileDescriptor, ios_base::out | ios_base::trunc | ios_base::binary);
|
||||
m_file.write(flags);
|
||||
} else {
|
||||
#endif
|
||||
|
@ -236,7 +235,7 @@ void Controller::save()
|
|||
} catch (const runtime_error &e) {
|
||||
emit fileError(tr("An internal error occured when saving the file: ") + QString::fromLocal8Bit(e.what()), QStringLiteral("save"));
|
||||
} catch (...) {
|
||||
emitIoError(tr("saving"));
|
||||
emitFileError(tr("saving"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,10 +272,10 @@ void Controller::handleFileSelectionAcceptedDescriptor(const QString &nativeUrl,
|
|||
try {
|
||||
qDebug() << "Opening fd for native url: " << nativeUrl;
|
||||
m_file.setPath(fileName.toStdString());
|
||||
m_file.fileStream().openFromFileDescriptor(fileDescriptor, ios_base::in | ios_base::binary);
|
||||
m_file.fileStream().open(fileDescriptor, ios_base::in | ios_base::binary);
|
||||
m_file.opened();
|
||||
} catch (...) {
|
||||
emitIoError(tr("opening from native file descriptor"));
|
||||
emitFileError(tr("opening from native file descriptor"));
|
||||
}
|
||||
emit filePathChanged(m_filePath = m_fileName = fileName);
|
||||
handleFileSelectionAccepted(QString(), existing);
|
||||
|
@ -424,11 +423,13 @@ void Controller::setFileOpen(bool fileOpen)
|
|||
}
|
||||
}
|
||||
|
||||
void Controller::emitIoError(const QString &when)
|
||||
void Controller::emitFileError(const QString &when)
|
||||
{
|
||||
try {
|
||||
const auto *const msg = catchIoFailure();
|
||||
emit fileError(tr("An IO error occured when %1 the file %2: ").arg(when, m_filePath) + QString::fromLocal8Bit(msg), QStringLiteral("load"));
|
||||
throw;
|
||||
} catch (const std::ios_base::failure &failure) {
|
||||
emit fileError(
|
||||
tr("An IO error occured when %1 the file %2: ").arg(when, m_filePath) + QString::fromLocal8Bit(failure.what()), QStringLiteral("load"));
|
||||
} catch (const exception &e) {
|
||||
emit fileError(tr("An unknown exception occured when %1 the file %2: ").arg(when, m_filePath) + QString::fromLocal8Bit(e.what()),
|
||||
QStringLiteral("load"));
|
||||
|
|
|
@ -136,7 +136,7 @@ private:
|
|||
void resetFileStatus();
|
||||
void updateWindowTitle();
|
||||
void setFileOpen(bool fileOpen);
|
||||
void emitIoError(const QString &when);
|
||||
void emitFileError(const QString &when);
|
||||
QModelIndex ensureSourceEntryIndex(const QModelIndex &entryIndexMaybeFromFilterModel) const;
|
||||
|
||||
QSettings &m_settings;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#endif
|
||||
|
||||
#include "resources/config.h"
|
||||
#include "resources/qtconfig.h"
|
||||
|
||||
// enable inline helper functions for Qt Quick provided by qtutilities
|
||||
#define QT_UTILITIES_GUI_QTQUICK
|
||||
|
|
Loading…
Reference in New Issue