Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Copy to Clipboard for VersionInfo dialog #3318

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
134 changes: 97 additions & 37 deletions src/dialogs/VersionInfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QTreeWidget>
#include <QContextMenuEvent>
#include <QClipboard>

VersionInfoDialog::VersionInfoDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core())
Expand All @@ -17,10 +19,66 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)

// Get version information
fillVersionInfo();

// Setup context menu and actions
copyActionLeftTreewidget = new QAction(tr("Copy"), this);
copyActionLeftTreewidget->setIcon(QIcon(":/img/icons/copy.svg"));
copyActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::Copy);
copyActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

copyActionRightTreewidget = new QAction(tr("Copy"), this);
copyActionRightTreewidget->setIcon(QIcon(":/img/icons/copy.svg"));
copyActionRightTreewidget->setShortcut(QKeySequence::StandardKey::Copy);
copyActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

selAllActionLeftTreewidget = new QAction(tr("Select All"), this);
selAllActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll);
selAllActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

selAllActionRightTreewidget = new QAction(tr("Select All"), this);
selAllActionRightTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll);
selAllActionRightTreewidget->setShortcutContext(
Qt::ShortcutContext::WidgetWithChildrenShortcut);

connect(copyActionLeftTreewidget, &QAction::triggered, this,
[this]() { CopyTreeWidgetSelection(ui->leftTreeWidget); });

connect(copyActionRightTreewidget, &QAction::triggered, this,
[this]() { CopyTreeWidgetSelection(ui->rightTreeWidget); });

connect(selAllActionLeftTreewidget, &QAction::triggered, this,
[this]() { ui->leftTreeWidget->selectAll(); });

connect(selAllActionRightTreewidget, &QAction::triggered, this,
[this]() { ui->rightTreeWidget->selectAll(); });

ui->leftTreeWidget->addAction(copyActionLeftTreewidget);
ui->leftTreeWidget->addAction(selAllActionLeftTreewidget);

ui->rightTreeWidget->addAction(copyActionRightTreewidget);
ui->rightTreeWidget->addAction(selAllActionRightTreewidget);
}

VersionInfoDialog::~VersionInfoDialog() {}

void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
{
QString vinfo, row;

QTreeWidgetItemIterator it(t);

while (*it) {
if ((*it)->isSelected()) {
row = (*it)->text(KeyColumn) + " " + (*it)->text(ValueColumn) + "\n";
vinfo.append(row);
}
it++;
}

QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(vinfo.trimmed());
}

void VersionInfoDialog::fillVersionInfo()
{
RzCoreLocked core(Core());
Expand All @@ -45,17 +103,17 @@ void VersionInfoDialog::fillVersionInfo()

// Left tree
QTreeWidgetItem *addrItemL = new QTreeWidgetItem();
addrItemL->setText(0, "Address:");
addrItemL->setText(1, RzAddressString(sdb_num_get(sdb, "addr", 0)));
addrItemL->setText(KeyColumn, "Address:");
addrItemL->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "addr", 0)));
ui->leftTreeWidget->addTopLevelItem(addrItemL);

QTreeWidgetItem *offItemL = new QTreeWidgetItem();
offItemL->setText(0, "Offset:");
offItemL->setText(1, RzAddressString(sdb_num_get(sdb, "offset", 0)));
offItemL->setText(KeyColumn, "Offset:");
offItemL->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "offset", 0)));
ui->leftTreeWidget->addTopLevelItem(offItemL);

QTreeWidgetItem *entriesItemL = new QTreeWidgetItem();
entriesItemL->setText(0, "Entries:");
entriesItemL->setText(KeyColumn, "Entries:");
const ut64 num_entries = sdb_num_get(sdb, "num_entries", 0);
for (size_t i = 0; i < num_entries; ++i) {
auto key = QString("entry%0").arg(i);
Expand All @@ -64,8 +122,8 @@ void VersionInfoDialog::fillVersionInfo()
continue;
}
auto item = new QTreeWidgetItem();
item->setText(0, RzAddressString(i));
item->setText(1, value);
item->setText(KeyColumn, RzAddressString(i));
item->setText(ValueColumn, value);
entriesItemL->addChild(item);
}
ui->leftTreeWidget->addTopLevelItem(entriesItemL);
Expand All @@ -76,17 +134,17 @@ void VersionInfoDialog::fillVersionInfo()

// Right tree
QTreeWidgetItem *addrItemR = new QTreeWidgetItem();
addrItemR->setText(0, "Address:");
addrItemR->setText(1, RzAddressString(sdb_num_get(sdb, "addr", 0)));
addrItemR->setText(KeyColumn, "Address:");
addrItemR->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "addr", 0)));
ui->rightTreeWidget->addTopLevelItem(addrItemR);

QTreeWidgetItem *offItemR = new QTreeWidgetItem();
offItemR->setText(0, "Offset:");
offItemR->setText(1, RzAddressString(sdb_num_get(sdb, "offset", 0)));
offItemR->setText(KeyColumn, "Offset:");
offItemR->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "offset", 0)));
ui->rightTreeWidget->addTopLevelItem(offItemR);

QTreeWidgetItem *entriesItemR = new QTreeWidgetItem();
entriesItemR->setText(0, "Entries:");
entriesItemR->setText(KeyColumn, "Entries:");
for (size_t num_version = 0;; num_version++) {
auto path_version =
QString("bin/cur/info/versioninfo/verneed/version%0").arg(num_version);
Expand All @@ -96,8 +154,8 @@ void VersionInfoDialog::fillVersionInfo()
}
const char *filename = sdb_const_get(sdb, "file_name", 0);
auto *parentItem = new QTreeWidgetItem();
parentItem->setText(0, RzAddressString(sdb_num_get(sdb, "idx", 0)));
parentItem->setText(1,
parentItem->setText(KeyColumn, RzAddressString(sdb_num_get(sdb, "idx", 0)));
parentItem->setText(ValueColumn,
QString("Version: %0\t"
"File: %1")
.arg(QString::number(sdb_num_get(sdb, "vn_version", 0)),
Expand All @@ -113,14 +171,14 @@ void VersionInfoDialog::fillVersionInfo()
}

auto *childItem = new QTreeWidgetItem();
childItem->setText(0, RzAddressString(sdb_num_get(sdb, "idx", 0)));
childItem->setText(KeyColumn, RzAddressString(sdb_num_get(sdb, "idx", 0)));
QString childString =
QString("Name: %0\t"
"Flags: %1\t"
"Version: %2\t")
.arg(sdb_const_get(sdb, "name", 0), sdb_const_get(sdb, "flags", 0),
QString::number(sdb_num_get(sdb, "version", 0)));
childItem->setText(1, childString);
childItem->setText(ValueColumn, childString);
parentItem->addChild(childItem);
}
entriesItemR->addChild(parentItem);
Expand Down Expand Up @@ -160,48 +218,48 @@ void VersionInfoDialog::fillVersionInfo()
.arg(product_version_ls & 0xFFFF);

auto item = new QTreeWidgetItem();
item->setText(0, "Signature");
item->setText(1, RzHexString(sdb_num_get(sdb, "Signature", 0)));
item->setText(KeyColumn, "Signature");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "Signature", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "StrucVersion");
item->setText(1, RzHexString(sdb_num_get(sdb, "StrucVersion", 0)));
item->setText(KeyColumn, "StrucVersion");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "StrucVersion", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "FileVersion");
item->setText(1, file_version);
item->setText(KeyColumn, "FileVersion");
item->setText(ValueColumn, file_version);
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "ProductVersion");
item->setText(1, product_version);
item->setText(KeyColumn, "ProductVersion");
item->setText(ValueColumn, product_version);
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "FileFlagsMask");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileFlagsMask", 0)));
item->setText(KeyColumn, "FileFlagsMask");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileFlagsMask", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "FileFlags");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileFlags", 0)));
item->setText(KeyColumn, "FileFlags");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileFlags", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "FileOS");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileOS", 0)));
item->setText(KeyColumn, "FileOS");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileOS", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "FileType");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileType", 0)));
item->setText(KeyColumn, "FileType");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileType", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

item = new QTreeWidgetItem();
item->setText(0, "FileSubType");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileSubType", 0)));
item->setText(KeyColumn, "FileSubType");
item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileSubType", 0)));
ui->leftTreeWidget->addTopLevelItem(item);

// Adjust columns to content
Expand All @@ -227,13 +285,15 @@ void VersionInfoDialog::fillVersionInfo()
ut8 *key_utf16 = sdb_decode(sdb_const_get(sdb, "key", 0), &lenkey);
ut8 *val_utf16 = sdb_decode(sdb_const_get(sdb, "value", 0), &lenval);
item = new QTreeWidgetItem();
item->setText(0, QString::fromUtf16(reinterpret_cast<const ushort *>(key_utf16)));
item->setText(1, QString::fromUtf16(reinterpret_cast<const ushort *>(val_utf16)));
item->setText(KeyColumn,
QString::fromUtf16(reinterpret_cast<const ushort *>(key_utf16)));
item->setText(ValueColumn,
QString::fromUtf16(reinterpret_cast<const ushort *>(val_utf16)));
ui->rightTreeWidget->addTopLevelItem(item);
free(key_utf16);
free(val_utf16);
}
}
qhelpers::adjustColumns(ui->rightTreeWidget, 0);
}
}
}
13 changes: 12 additions & 1 deletion src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ class VersionInfoDialog : public QDialog
explicit VersionInfoDialog(QWidget *parent = nullptr);
~VersionInfoDialog();

enum Column { KeyColumn = 0, ValueColumn = 1 };

private slots:
void CopyTreeWidgetSelection(QTreeWidget *t);

protected:
QAction *copyActionLeftTreewidget = nullptr;
QAction *copyActionRightTreewidget = nullptr;
QAction *selAllActionLeftTreewidget = nullptr;
QAction *selAllActionRightTreewidget = nullptr;

private:
std::unique_ptr<Ui::VersionInfoDialog> ui;
CutterCore *core;

void fillVersionInfo();
};

#endif // VERSIONINFODIALOG_H
#endif // VERSIONINFODIALOG_H
14 changes: 13 additions & 1 deletion src/dialogs/VersionInfoDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="leftTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -103,6 +109,12 @@
</item>
<item>
<widget class="QTreeWidget" name="rightTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -139,4 +151,4 @@
</widget>
<resources/>
<connections/>
</ui>
</ui>
Loading