Skip to content

Commit

Permalink
refactor: replace QString::asprintf() with QString::arg()
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Oct 28, 2024
1 parent 83e5a60 commit f598bfc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
30 changes: 13 additions & 17 deletions helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ QList<QPair<QString, QString>> convert_device_path_attrs(QEFIDevicePath *dp)
QList<quint32> addrs = dpADR->addresses();
for (int i = 0; i < addrs.size(); i++) {
list << qMakePair<QString, QString>(
QString::asprintf("Address %d:", i + 1),
QStringLiteral("Address %1:").arg(i + 1),
QString::number(addrs[i])
);
}
Expand Down Expand Up @@ -389,16 +389,10 @@ QList<QPair<QString, QString>> convert_device_path_attrs(QEFIDevicePath *dp)
dynamic_cast<QEFIDevicePathMessageIPv4Addr *>(dp);
QEFIIPv4Address local = dpMessage->localIPv4Address();
list << qMakePair<QString, QString>("Local IP",
QString::asprintf("%d.%d.%d.%d", local.address[0],
local.address[1],
local.address[2],
local.address[3]));
convert_ipv4_to_string(&local));
QEFIIPv4Address remote = dpMessage->remoteIPv4Address();
list << qMakePair<QString, QString>("Remote IP",
QString::asprintf("%d.%d.%d.%d", remote.address[0],
remote.address[1],
remote.address[2],
remote.address[3]));
convert_ipv4_to_string(&remote));
list << qMakePair<QString, QString>("Local Port",
QString::number(dpMessage->localPort()));
list << qMakePair<QString, QString>("Remote Port",
Expand All @@ -409,16 +403,10 @@ QList<QPair<QString, QString>> convert_device_path_attrs(QEFIDevicePath *dp)
dpMessage->staticIPAddress() ? "Yes" : " No");
QEFIIPv4Address gw = dpMessage->gateway();
list << qMakePair<QString, QString>("Gateway IP",
QString::asprintf("%d.%d.%d.%d", gw.address[0],
gw.address[1],
gw.address[2],
gw.address[3]));
convert_ipv4_to_string(&gw));
QEFIIPv4Address netmask = dpMessage->netmask();
list << qMakePair<QString, QString>("Netmask",
QString::asprintf("%d.%d.%d.%d", netmask.address[0],
netmask.address[1],
netmask.address[2],
netmask.address[3]));
convert_ipv4_to_string(&netmask));
}
break;
case QEFIDevicePathMessageSubType::MSG_IPv6:
Expand Down Expand Up @@ -1301,6 +1289,14 @@ QList<QPair<QString, enum QEFIDPEditType>> convert_device_path_types(QEFIDeviceP
return list;
}

QString convert_ipv4_to_string(const QEFIIPv4Address *ipv4) {
const auto addr = ipv4->address;
return QStringLiteral("%d.%d.%d.%d").arg(addr[0])
.arg(addr[1])
.arg(addr[2])
.arg(addr[3]);
}

QList<quint8> enum_device_path_subtype(QEFIDevicePathType type)
{
QList<quint8> res;
Expand Down
3 changes: 2 additions & 1 deletion helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum QEFIDPEditType {
EditType_UUID
};
QList<QPair<QString, enum QEFIDPEditType>> convert_device_path_types(QEFIDevicePath *dp);
QString convert_ipv4_to_string(const QEFIIPv4Address *ipv4);
QList<quint8> enum_device_path_subtype(QEFIDevicePathType type);

#endif // HELPERS_H
#endif // HELPERS_H
4 changes: 2 additions & 2 deletions qefientrydetailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ QEFIEntryDetailBriefView::QEFIEntryDetailBriefView(
m_briefLayout = new QFormLayout(this);

m_briefLayout->addRow("ID:",
new QLabel(QString::asprintf("Boot%04X ", entry.id())));
new QLabel(QStringLiteral("Boot%1 ").arg(entry.id(), 4, 16, QLatin1Char('0'))));
m_briefLayout->addRow("Name:", new QLabel(entry.name()));

QEFILoadOption *loadOption = entry.loadOption();
Expand Down Expand Up @@ -62,7 +62,7 @@ QEFIEntryDetailView::QEFIEntryDetailView(QEFIEntry &entry, QWidget *parent)
// Add a tab to display each DP
for (int i = 0; i < dpList.size(); i++) {
m_tab->addTab(new QEFIEntryDPDetailView(dpList[i].get(), m_tab),
QString::asprintf("DP %d", i + 1));
QStringLiteral("DP %1").arg(i + 1));
}
}
m_topLevelLayout->addWidget(m_tab);
Expand Down
5 changes: 3 additions & 2 deletions qefientrydpdetailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ QEFIEntryDPDetailView::QEFIEntryDPDetailView(QEFIDevicePath *dp, QWidget *parent
convert_device_path_subtype_to_name(dp->type(), dp->subType()))
);
m_topLevelLayout->addRow(QStringLiteral(""),
new QLabel(QString::asprintf("%02X %02X",
dp->type(), dp->subType()))
new QLabel(QStringLiteral("%1 %1")
.arg(dp->type(), 2, 16, QLatin1Char('0'))
.arg(dp->subType(), 2, 16, QLatin1Char('0')))
);
// Parse device path and add more properties
QList<QPair<QString, QString>> attrs = convert_device_path_attrs(dp);
Expand Down
6 changes: 3 additions & 3 deletions qefientrystaticlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void QEFIEntryStaticList::load()
m_entries.clear();
for (int i = 0; i < data.size() / 2; i++, order_num++) {
quint16 order_id = qFromLittleEndian<quint16>(*order_num);
QString name = QString::asprintf("Boot%04X", order_id);
QString name = QStringLiteral("Boot%1").arg(order_id, 4, 16, QLatin1Char('0'));
QByteArray boot_data = qefi_get_variable(g_efiUuid,
name);
QEFILoadOption *loadOption = new QEFILoadOption(boot_data);
Expand Down Expand Up @@ -147,7 +147,7 @@ bool QEFIEntryStaticList::setBootVisibility(
if (visible) attribute |= 0x00000001;
else attribute &= 0xFFFFFFFE;

QString name = QString::asprintf("Boot%04X", bootID);
QString name = QStringLiteral("Boot%1").arg(bootID, 4, 16, QLatin1Char('0'));
bootData[3] = (attribute >> 24);
bootData[2] = ((attribute >> 16) & 0xFF);
bootData[1] = ((attribute >> 8) & 0xFF);
Expand Down Expand Up @@ -191,7 +191,7 @@ bool QEFIEntryStaticList::updateBootEntry(const quint16 bootID, const QByteArray
m_loadOptions.insert(bootID, loadOption);

// Write the data
QString name = QString::asprintf("Boot%04X", bootID);
QString name = QStringLiteral("Boot%1").arg(bootID, 4, 16, QLatin1Char('0'));
qefi_set_variable(g_efiUuid,
name, data);

Expand Down
5 changes: 3 additions & 2 deletions qefientryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void QEFIEntryView::exportClicked(bool checked)
exportFile.commit();
#else
QFileDialog::saveFileContent(data,
QString::asprintf("Boot%04X.bin", m_order[m_selectedItemIndex]));
QStringLiteral("Boot%1.bin").arg(m_order[m_selectedItemIndex], 4, 16, QLatin1Char('0')));
#endif
}
}
Expand All @@ -362,7 +362,8 @@ void QEFIEntryView::contextMenuEvent(QContextMenuEvent *event)
if (m_selectedItemIndex >= 0 || m_selectedItemIndex < m_order.size()) {
QListWidgetItem *currentItem = m_entries->itemAt(event->pos());
if (currentItem != nullptr) {
menu.addSection(QString::asprintf("Boot%04X", m_order[m_selectedItemIndex]));
menu.addSection(QStringLiteral("Boot%1").arg(m_order[m_selectedItemIndex],
4, 16, QLatin1Char('0')));

QEFIEntry &entry = m_entryItems[m_order[m_selectedItemIndex]];
connect(menu.addAction(entry.isActive() ?
Expand Down

0 comments on commit f598bfc

Please sign in to comment.