Skip to content

Commit

Permalink
Improve error messages (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverous authored Feb 25, 2023
1 parent f2eafe5 commit cf40431
Show file tree
Hide file tree
Showing 18 changed files with 394 additions and 383 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- uses: DoozyX/[email protected]
with:
source: 'src include'
clangFormatVersion: 13
clangFormatVersion: 15
12 changes: 6 additions & 6 deletions include/bootentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Device_path
{

template <class Type>
inline bool register_json_reader();
#define REGISTER_JSON_READER(type) static const bool is_##type##_json_reader_registered = register_json_reader<type>()
inline bool registerJSONReader();
#define REGISTER_JSON_READER(type) static const bool is_##type##_json_reader_registered = registerJSONReader<type>()

#if defined(_MSC_VER)
#pragma warning(push)
Expand Down Expand Up @@ -466,7 +466,7 @@ inline auto &JSON_readers()
}

template <class Type>
inline bool register_json_reader()
inline bool registerJSONReader()
{
auto key = QString("%1/%2").arg(Type::TYPE).arg(Type::SUBTYPE);
if(JSON_readers().find(key) != JSON_readers().end())
Expand Down Expand Up @@ -514,12 +514,12 @@ class BootEntry
static std::optional<BootEntry> fromJSON(const QJsonObject &obj);
QJsonObject toJSON() const;

QString format_file_path(bool refresh = true) const;
QString formatFilePath(bool refresh = true) const;

bool change_optional_data_format(OptionalDataFormat format);
bool changeOptionalDataFormat(OptionalDataFormat format);

private:
QByteArray get_raw_optional_data() const;
QByteArray getRawOptionalData() const;
};

#if defined(_MSC_VER)
Expand Down
12 changes: 6 additions & 6 deletions include/bootentrywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class BootEntryWidget: public QWidget
BootEntryWidget &operator=(const BootEntryWidget &) = delete;
~BootEntryWidget() override;

void set_index(const quint32 index);
void set_description(const QString &description);
void set_file_path(const QString &file_path);
void set_data(const QString &data);
bool get_next_boot() const;
void set_next_boot(bool next_boot);
void setIndex(const quint32 index);
void setDescription(const QString &description);
void setFilePath(const QString &file_path);
void setData(const QString &data);
bool getNextBoot() const;
void setNextBoot(bool next_boot);
};
2 changes: 2 additions & 0 deletions include/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ inline tstring to_tstring(const Type &value)

}

// clang-format off
#ifndef DEFINE_ENUM_FLAG_OPERATORS
#define DEFINE_ENUM_FLAG_OPERATORS(T) \
inline T operator~(T a) { return static_cast<T>(~static_cast<std::underlying_type<T>::type>(a)); } \
inline T operator|(T a, T b) { return static_cast<T>(static_cast<std::underlying_type<T>::type>(a) | static_cast<std::underlying_type<T>::type>(b)); } \
inline T operator&(T a, T b) { return static_cast<T>(static_cast<std::underlying_type<T>::type>(a) & static_cast<std::underlying_type<T>::type>(b)); }
#endif
// clang-format on

const int HEX_BASE = 16;

Expand Down
2 changes: 1 addition & 1 deletion include/driveinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DriveInfo
quint64 size = 0;

public:
static QVector<DriveInfo> get_all(bool refresh = false);
static QVector<DriveInfo> getAll(bool refresh = false);

bool operator<(const DriveInfo &info) const { return name < info.name; }
};
Expand Down
16 changes: 8 additions & 8 deletions include/efiboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ struct Load_option
#endif

typedef std::function<bool(const efi_guid_t &, const std::tstring_view)> Filter_fn;
typedef std::function<const void *(const void *, const size_t)> Advance_fn;
typedef std::function<const void *(const void *, size_t)> Advance_fn;
typedef std::function<size_t(const void *)> Size_fn;
typedef std::function<void(size_t, size_t)> Progress_fn;

Expand All @@ -349,7 +349,7 @@ template <class Type = Raw_data>
std::optional<std::vector<Type>> deserialize_list(const void *data, size_t data_size);

template <class Type = Raw_data>
std::optional<std::vector<Type>> deserialize_list(const void *data, size_t data_size, Size_fn get_element_size, Advance_fn get_next_element);
std::optional<std::vector<Type>> deserialize_list_ex(const void *data, size_t data_size, Size_fn get_element_size, Advance_fn get_next_element);

template <class Type = Raw_data>
size_t serialize(Raw_data &output, const Type &value);
Expand Down Expand Up @@ -471,7 +471,7 @@ inline size_t serialize(Raw_data &output, const std::u16string &value)
}

template <class Type>
inline std::optional<std::vector<Type>> deserialize_list(const void *data, size_t data_size, Size_fn get_element_size, Advance_fn get_next_element)
inline std::optional<std::vector<Type>> deserialize_list_ex(const void *data, size_t data_size, Size_fn get_element_size, Advance_fn get_next_element)
{
std::vector<Type> values;
const void *data_end = static_cast<const void *>(static_cast<const uint8_t *>(data) + data_size);
Expand All @@ -497,7 +497,7 @@ inline std::optional<std::vector<Type>> deserialize_list(const void *data, size_
template <class Type>
inline std::optional<std::vector<Type>> deserialize_list(const void *data, size_t data_size)
{
return deserialize_list<Type>(
return deserialize_list_ex<Type>(
data, data_size,
[](const void *) -> size_t
{
Expand Down Expand Up @@ -532,7 +532,7 @@ inline std::optional<Device_path::End_instance> deserialize(const void *data, si
if(dp->subtype != Device_path::End_instance::SUBTYPE)
return std::nullopt;

Device_path::End_instance value;
Device_path::End_instance value{};
return {value};
}

Expand Down Expand Up @@ -562,7 +562,7 @@ inline std::optional<Device_path::End_entire> deserialize(const void *data, size
if(dp->subtype != Device_path::End_entire::SUBTYPE)
return std::nullopt;

Device_path::End_entire value;
Device_path::End_entire value{};
return {value};
}

Expand Down Expand Up @@ -592,14 +592,14 @@ inline std::optional<Load_option> deserialize(const void *data, size_t data_size
uint16_t device_path_size = efi_loadopt_pathlen(load_option, ssize);
efidp device_path = efi_loadopt_path(load_option, ssize);

auto file_path = deserialize_list<Device_path::ANY>(
auto file_path = deserialize_list_ex<Device_path::ANY>(
device_path, device_path_size,
[](const void *ptr) -> size_t
{
auto size = efidp_node_size(static_cast<const_efidp>(ptr));
return reinterpret_cast<size_t &>(size);
},
[](const void *ptr, const size_t bytes_left) -> const void *
[](const void *ptr, size_t bytes_left) -> const void *
{
const_efidp dp = static_cast<const_efidp>(ptr);
ssize_t size = efidp_node_size(dp);
Expand Down
8 changes: 4 additions & 4 deletions include/efibooteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public slots:
void importJSONEFIData(const QJsonObject &input);
void importRawEFIData(const QJsonObject &input);

void show_error(const QString &message, const QString &details = "");
void showError(const QString &message, const QString &details);
template <class Receiver, typename Slot>
void show_confirmation(const QString &message, const QMessageBox::StandardButtons &buttons, const QMessageBox::StandardButton &confirmation_button, Receiver confirmation_context, Slot confirmation_slot);
void showConfirmation(const QString &message, const QMessageBox::StandardButtons &buttons, const QMessageBox::StandardButton &confirmation_button, Receiver confirmation_context, Slot confirmation_slot);

void show_progress_bar(size_t step, size_t total, const QString &details = "");
void hide_progress_bar();
void showProgressBar(size_t step, size_t total, const QString &details);
void hideProgressBar();
};
1 change: 1 addition & 0 deletions include/qwidgetitemdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ bool QWidgetItemDelegate<Widget, Item>::editorEvent(QEvent *event, QAbstractItem
result = handleWidgetDelegateEventResult(event, model, option, index, event_handler, result);

event_handler.setParent(nullptr);
(void)result;
}

return QStyledItemDelegate::editorEvent(event, model, option, index);
Expand Down
10 changes: 5 additions & 5 deletions src/bootentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ auto BootEntry::toEFIBootLoadOption() const -> EFIBoot::Load_option
EFIBoot::Load_option load_option;
load_option.description = description.toStdU16String();
{
auto bytes = get_raw_optional_data();
auto bytes = getRawOptionalData();
auto begin = reinterpret_cast<const EFIBoot::Raw_data::value_type *>(bytes.constData());
std::copy(begin, std::next(begin, bytes.size()), std::back_inserter(load_option.optional_data));
}
Expand Down Expand Up @@ -118,7 +118,7 @@ auto BootEntry::toJSON() const -> QJsonObject
return load_option;
}

auto BootEntry::format_file_path(bool refresh) const -> QString
auto BootEntry::formatFilePath(bool refresh) const -> QString
{
if(file_path.empty())
return {};
Expand All @@ -140,13 +140,13 @@ auto BootEntry::format_file_path(bool refresh) const -> QString
return file_path_str;
}

auto BootEntry::change_optional_data_format(BootEntry::OptionalDataFormat format) -> bool
auto BootEntry::changeOptionalDataFormat(BootEntry::OptionalDataFormat format) -> bool
{
if(format == optional_data_format)
return true;

QTextCodec *codec = nullptr;
auto bytes = get_raw_optional_data();
auto bytes = getRawOptionalData();
QTextCodec::ConverterState state;
QString temp_optional_data;
switch(static_cast<OptionalDataFormat>(format))
Expand Down Expand Up @@ -187,7 +187,7 @@ auto BootEntry::change_optional_data_format(BootEntry::OptionalDataFormat format
return true;
}

auto BootEntry::get_raw_optional_data() const -> QByteArray
auto BootEntry::getRawOptionalData() const -> QByteArray
{
QByteArray bytes;
std::unique_ptr<QTextEncoder> encoder = nullptr;
Expand Down
14 changes: 7 additions & 7 deletions src/bootentrydelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

void BootEntryDelegate::setupWidgetFromItem(Widget &widget, const Item &item) const
{
widget.set_index(item->index);
widget.set_description(item->description);
widget.set_data(item->optional_data);
widget.set_file_path(item->format_file_path(false));
widget.set_next_boot(item->is_next_boot);
widget.setIndex(item->index);
widget.setDescription(item->description);
widget.setData(item->optional_data);
widget.setFilePath(item->formatFilePath(false));
widget.setNextBoot(item->is_next_boot);
}

auto BootEntryDelegate::handleWidgetDelegateEventResult(const QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &, const QModelIndex &index, const Widget &widget, bool result) const -> bool
Expand All @@ -18,10 +18,10 @@ auto BootEntryDelegate::handleWidgetDelegateEventResult(const QEvent *event, QAb
return result;

auto item = index.data().value<const BootEntry *>();
if(widget.get_next_boot() != item->is_next_boot)
if(widget.getNextBoot() != item->is_next_boot)
{
auto entries_list_model = static_cast<BootEntryListModel *>(model);
entries_list_model->setNextBootEntry(index, widget.get_next_boot());
entries_list_model->setNextBootEntry(index, widget.getNextBoot());
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/bootentryform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void BootEntryForm::optionalDataFormatChanged(int format)

bool success = entries_list_model->changeData(current_index, [&](BootEntry &entry)
{
bool result = entry.change_optional_data_format(static_cast<BootEntry::OptionalDataFormat>(format));
bool result = entry.changeOptionalDataFormat(static_cast<BootEntry::OptionalDataFormat>(format));
if(result)
ui->optional_data_text->setPlainText(entry.optional_data);

Expand Down
12 changes: 6 additions & 6 deletions src/bootentrywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ BootEntryWidget::~BootEntryWidget()
{
}

void BootEntryWidget::set_index(const quint32 index)
void BootEntryWidget::setIndex(const quint32 index)
{
ui->index->setText(toHex(index, 4));
}

void BootEntryWidget::set_description(const QString &description)
void BootEntryWidget::setDescription(const QString &description)
{
ui->description->setText(description);
ui->description->setStatusTip(description);
setStatusTip(description);
setToolTip(description);
}

void BootEntryWidget::set_file_path(const QString &file_path)
void BootEntryWidget::setFilePath(const QString &file_path)
{
ui->file_path->setText(file_path);
ui->file_path->setStatusTip(file_path);
}

void BootEntryWidget::set_data(const QString &_data)
void BootEntryWidget::setData(const QString &_data)
{
ui->data->setText(_data);
ui->data->setStatusTip(_data);
}

auto BootEntryWidget::get_next_boot() const -> bool
auto BootEntryWidget::getNextBoot() const -> bool
{
return ui->next_boot->isChecked();
}

void BootEntryWidget::set_next_boot(bool next_boot)
void BootEntryWidget::setNextBoot(bool next_boot)
{
ui->next_boot->setChecked(next_boot);
}
2 changes: 1 addition & 1 deletion src/devicepathdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void DevicePathDialog::setUnknownForm(const Device_path::Unknown &unknown)
void DevicePathDialog::refreshDiskCombo(bool force)
{
ui->disk_combo->clear();
const auto drives = DriveInfo::get_all(force);
const auto drives = DriveInfo::getAll(force);
for(const auto &drive: drives)
{
QVariant item;
Expand Down
10 changes: 5 additions & 5 deletions src/devicepathproxylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ auto DevicePathProxyListModel::setData(const QModelIndex &index, const QVariant
boot_entry_list_model->changeData(boot_entry_index, [&index, &value](BootEntry &entry)
{
entry.file_path[index.row()] = *value.value<const Device_path::ANY *>();
entry.format_file_path();
entry.formatFilePath();
return true; });

emit dataChanged(index, index, {role});
Expand All @@ -66,7 +66,7 @@ auto DevicePathProxyListModel::insertRows(int row, int count, const QModelIndex
for(int c = 0; c < count; ++c)
entry.file_path.insert(static_cast<decltype(entry.file_path)::size_type>(row) + c, {});

entry.format_file_path();
entry.formatFilePath();
return true; });
endInsertRows();
return true;
Expand All @@ -80,7 +80,7 @@ auto DevicePathProxyListModel::removeRows(int row, int count, const QModelIndex
for(int c = 0; c < count; ++c)
entry.file_path.removeAt(row);

entry.format_file_path();
entry.formatFilePath();
return true; });
endRemoveRows();
return true;
Expand All @@ -94,7 +94,7 @@ auto DevicePathProxyListModel::moveRows(const QModelIndex &sourceParent, int sou
for(int c = 0; c < count; ++c)
entry.file_path.move(sourceRow, static_cast<decltype(entry.file_path)::size_type>(destinationChild) + (sourceRow < destinationChild ? 0 : c));

entry.format_file_path();
entry.formatFilePath();
return true; });
endMoveRows();
return true;
Expand All @@ -106,7 +106,7 @@ void DevicePathProxyListModel::clear()
boot_entry_list_model->changeData(boot_entry_index, [](BootEntry &entry)
{
entry.file_path.clear();
entry.format_file_path();
entry.formatFilePath();
return true; });
endResetModel();
}
2 changes: 1 addition & 1 deletion src/driveinfo.darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "compat.h"
#include "driveinfo.h"

auto DriveInfo::get_all(bool refresh) -> QVector<DriveInfo>
auto DriveInfo::getAll(bool refresh) -> QVector<DriveInfo>
{
if(!refresh && !all.empty())
return all;
Expand Down
2 changes: 1 addition & 1 deletion src/driveinfo.linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "compat.h"
#include "driveinfo.h"

auto DriveInfo::get_all(bool refresh) -> QVector<DriveInfo>
auto DriveInfo::getAll(bool refresh) -> QVector<DriveInfo>
{
if(!refresh && !all.empty())
return all;
Expand Down
2 changes: 1 addition & 1 deletion src/driveinfo.win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "compat.h"
#include "driveinfo.h"

QVector<DriveInfo> DriveInfo::get_all(bool refresh)
QVector<DriveInfo> DriveInfo::getAll(bool refresh)
{
if(!refresh && !all.empty())
return all;
Expand Down
Loading

0 comments on commit cf40431

Please sign in to comment.