Compare commits

...

34 Commits

Author SHA1 Message Date
mappu 6008ae44a2 doc: rename image directory for teafolio 2021-04-12 18:03:05 +12:00
mappu 99096b2360 doc/README: add v1.0.2 changelog 2021-04-12 18:01:46 +12:00
mappu 0e92459779 no-op merge with legacy-codesite branch 2021-04-12 17:52:00 +12:00
mappu a13eaaf523 make: upx doesn't support current mxe mingw/qt linked binaries 2021-04-12 17:44:38 +12:00
mappu dca8d277d3 make: option to build windows binary in docker 2021-04-12 17:44:17 +12:00
mappu 15c739c0b9 squash 2021-04-12 17:43:59 +12:00
mappu fc2da972ef dummy-data: fix build for renamed bbolt package 2021-04-12 17:07:16 +12:00
mappu e45eea7111 makefile: remove 'hg export' function 2021-04-12 17:04:40 +12:00
mappu 1e62d79c07 doc: delete TODO.txt (issues now being tracked in Gitea)
The new issue tracker is at https://git.ivysaur.me/code.ivysaur.me/qbolt/issues
2021-04-12 17:04:27 +12:00
mappu c74c5ae5c0 doc: move README/TODO to top-level directory 2021-04-12 17:00:49 +12:00
mappu b0092c4a6e vendor: switch bolt implementation to etcd-io/bbolt v1.3.5 2021-04-12 17:00:40 +12:00
mappu 5ce6368c4a qt: fix missing -lpthread on Debian Bullseye 2021-04-12 16:54:06 +12:00
mappu 3e7e54da4b go: add go.mod file for bolt dependency 2021-04-12 16:53:57 +12:00
mappu 9f80d687b2 hg2git: replace hgignore/hgtags files 2021-04-12 16:53:43 +12:00
mappu 96411e877f bump all versions to 1.0.2 2017-06-19 21:04:40 +12:00
mappu ac7e078c02 Added tag release-1.0.1 for changeset 0528a0ab20b6 2017-06-19 21:04:23 +12:00
mappu e13314f5dc 1.0.1 meta 2017-06-19 21:04:17 +12:00
mappu b50c3e738a doc: update features list in readme 2017-06-19 21:02:42 +12:00
mappu 54ad6015b7 more binary correctness 2017-06-19 20:53:50 +12:00
mappu 40e84ac230 dummy-data: change to generate binary names 2017-06-19 20:45:26 +12:00
mappu 767eaa0a47 add fallback display for non-printable characters 2017-06-19 20:42:51 +12:00
mappu bb594e768c doc: update readme 2017-06-19 20:42:42 +12:00
mappu 516bd99c4d doc: update TODO 2017-06-19 20:28:33 +12:00
mappu 571bfcf4b6 one more preservation for previous 2017-06-19 20:27:52 +12:00
mappu 26f7a11d80 preserve the binary content of keys and bucket names during edit operations 2017-06-19 20:27:05 +12:00
mappu 6fb8d1ba0c commit all archived files 2017-06-19 00:00:00 +00:00
mappu 21588021d3 doc: update TODO 2017-05-25 20:00:10 +12:00
mappu 7441e0c15b option to open database as read-only 2017-05-25 19:59:53 +12:00
mappu 142f3f6bf4 track screenshot of qbolt on windows 2017-05-25 19:54:35 +12:00
mappu 19ddb1c956 select parent when deleting bucket (maybe fixes a crash?) 2017-05-25 19:53:35 +12:00
mappu 97467eae4d add icon for win32 binary 2017-05-25 19:50:11 +12:00
mappu 17c37b6568 bump dist version to 1.0.1 2017-05-21 18:23:41 +12:00
mappu 57237ef2e8 Added tag release-1.0.0 for changeset 74cacbbe8f6c 2017-05-21 18:23:29 +12:00
mappu 8d8374be24 initial meta commit 2017-05-21 00:00:00 +00:00
24 changed files with 220 additions and 119 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
build-qbolt-*
dummy-data/dummy-data*
*.pro.user$
build/

View File

@ -1,5 +0,0 @@
mode:regexp
^build-qbolt-
^dummy-data/dummy-data$
\.pro\.user$
^build/

View File

@ -1,7 +1,7 @@
export PATH := /usr/lib/mxe/usr/bin:$(PATH)
GOFLAGS := -ldflags='-s -w' -gcflags='-trimpath=$(CURDIR)' -asmflags='-trimpath=$(CURDIR)'
VERSION := 1.0.0
VERSION := 1.0.2
.PHONY: all libs dist clean
@ -15,7 +15,6 @@ libs: \
dist: \
build/dist/qbolt-${VERSION}-win32.zip \
build/dist/qbolt-${VERSION}-src.tar.gz \
build/dist/qbolt-${VERSION}-linux_amd64.tar.xz
clean:
@ -51,18 +50,23 @@ build/dist/qbolt-${VERSION}-linux_amd64.tar.xz: build/linux/qbolt
build/win32/release/qbolt.exe: build/win32/qbolt.a qbolt/*
cd build/win32 && i686-w64-mingw32.static-qmake-qt5 ../../qbolt/qbolt.pro && make
# Dockerized Windows build
.PHONY: build-docker-build-environment
build-docker-build-environment:
cd docker && docker build -t win32-cross-qt-mxe:latest -f win32-cross-qt-mxe.Dockerfile
.PHONY: build-windows-in-docker
build-windows-in-docker:
docker run --rm -v $(CURDIR):/qbolt win32-cross-qt-mxe:latest /bin/sh -c 'cd /qbolt && make build/win32/release/qbolt.exe'
# Windows distribution
build/win32/dist/qbolt.exe: build/win32/release/qbolt.exe
mkdir -p build/win32/dist
cp build/win32/release/qbolt.exe build/win32/dist/qbolt.exe
upx --lzma build/win32/dist/qbolt.exe
# upx --lzma build/win32/dist/qbolt.exe
build/dist/qbolt-${VERSION}-win32.zip: build/win32/dist/qbolt.exe
mkdir -p build/dist
zip -0 -j build/dist/qbolt-${VERSION}-win32.zip build/win32/dist/qbolt.exe
# Source code archives
build/dist/qbolt-${VERSION}-src.tar.gz:
hg archive build/dist/qbolt-${VERSION}-src.tar.gz

49
README.md Normal file
View File

@ -0,0 +1,49 @@
# qbolt
A graphical database manager for BoltDB.
QBolt allows you to graphically view and edit the content of Bolt databases.
The project consists of two parts; a C binding (CGo) for the embeddable Bolt database engine, and a graphical interface built in C++/Qt that links to it.
Written in C++ (Qt), Golang (CGo)
## Features
- Open existing database or create new database
- Option to open database as readonly for concurrent use
- Create, list, edit and delete keys and buckets (including nested buckets)
- Safe for use with arbitrary binary key/bucket names (new ones created in UTF-8)
- View database and bucket statistics
- 100% Bolt compatibility via the real codebase
- Tested working on both Windows and Linux
## License
Source code content of `qbolt-x.x.x-src.tar.gz` is released under the ISC license.
BoltDB is released under the MIT license.
The Windows binary is released under LGPL-3+ owing to the static copy of Qt.
## See also
- BoltDB https://github.com/boltdb/bolt
## Changelog
2020-04-12 1.0.2
- Rebuild artefacts with etcd-io/bbolt v1.3.5, go 1.15, Qt 5.15, and new GCC versions
- Switch from hg to Git
- Use Go modules
- Add support for building Windows binary in Docker
- [⬇ Download here](https://git.ivysaur.me/code.ivysaur.me/qbolt/releases/tag/v1.0.2)
2017-06-19 1.0.1
- Feature: Option to open database as read-only
- Fix an issue with support for bucket names and keys not surviving UTF-8 roundtrips (now binary-clean)
- Fix an issue with crashing when deleting a bucket other than the selected one
- Fix a cosmetic issue with application icon on Windows
- [⬇ Download here](https://git.ivysaur.me/code.ivysaur.me/qbolt/releases/tag/v1.0.1)
2017-05-21 1.0.0
- Initial public release
- [⬇ Download here](https://git.ivysaur.me/code.ivysaur.me/qbolt/releases/tag/v1.0.0)

View File

@ -1,31 +0,0 @@
A graphical database manager for BoltDB.
QBolt allows you to graphically view and edit the content of Bolt databases.
The project consists of two parts; a C binding (CGo) for the embeddable Bolt database engine, and a graphical interface built in C++/Qt that links to it.
Written in C++ (Qt), Golang (CGo)
=FEATURES=
- Open existing database or create new database
- Supports nested buckets
- Create and edit keys
- View database and bucket statistics
- 100% Bolt compatibility via the real codebase
- Tested working on both Windows and Linux
=LICENSE=
Source code content of `qbolt-x.x.x-src.tar.gz` is released under the ISC license.
BoltDB is released under the MIT license.
The Windows binary is released under LGPL-3+ owing to the static copy of Qt.
=SEE ALSO=
- BoltDB https://github.com/boltdb/bolt
=CHANGELOG=
2017-05-21 1.0.0
- Initial public release

View File

@ -1,9 +0,0 @@
- Extra option to open read-only (allows concurrent access)
- Reduce unnecessary memory copies between QString/QByteArray
- Convert from item-based to model-based Qt widgets - needs deep integration with Bolt cursors...
- Remove dependence on UTF-8-encoded keys

BIN
doc/image0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 90 KiB

View File

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -0,0 +1,13 @@
FROM debian:bullseye
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -qyy gnupg2 golang-go ca-certificates
RUN DEBIAN_FRONTEND=noninteractive \
echo "deb https://pkg.mxe.cc/repos/apt buster main" >/etc/apt/sources.list.d/mxeapt.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 86B72ED9 && \
apt-get update && \
apt-get install -qyy mxe-i686-w64-mingw32.static-qt5 && \
apt-get clean
ENV PATH=/usr/lib/mxe/usr/bin:$PATH

View File

@ -1,15 +1,18 @@
package main
import (
"fmt"
//"fmt"
"math/rand"
"os"
"github.com/boltdb/bolt"
bolt "github.com/boltdb/bolt"
)
func random_name() string {
return fmt.Sprintf("%08x-%08x-%08x", rand.Int63(), rand.Int63(), rand.Int63())
ret := make([]byte, 12)
rand.Read(ret)
return string(ret)
//return fmt.Sprintf("%08x-%08x-%08x", rand.Int63(), rand.Int63(), rand.Int63())
}
func fill_bucket(tx *bolt.Tx, bucket *bolt.Bucket) error {

7
go.mod Normal file
View File

@ -0,0 +1,7 @@
module code.ivysaur.me/qbolt
go 1.15
require github.com/boltdb/bolt v1.3.1
replace github.com/boltdb/bolt => go.etcd.io/bbolt v1.3.5

5
go.sum Normal file
View File

@ -0,0 +1,5 @@
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -8,7 +8,7 @@ import (
"os"
"time"
"github.com/boltdb/bolt"
bolt "github.com/boltdb/bolt"
)
const (
@ -26,9 +26,11 @@ func GetMagic() int64 {
}
//export Bolt_Open
func Bolt_Open(path string) (ObjectReference, *C.char, int) {
func Bolt_Open(readOnly bool, path string) (ObjectReference, *C.char, int) {
opts := *bolt.DefaultOptions
opts.Timeout = 10 * time.Second
opts.ReadOnly = readOnly
ptrDB, err := bolt.Open(path, os.FileMode(0644), &opts)
if err != nil {
errMsg := err.Error()

View File

@ -7,12 +7,12 @@ BoltDB::BoltDB()
}
BoltDB* BoltDB::createFrom(QString filePath, QString &errorOut)
BoltDB* BoltDB::createFrom(QString filePath, bool readOnly, QString &errorOut)
{
QByteArray filePathBytes(filePath.toUtf8());
GoString filePathGS = Interop::toGoString_WeakRef(&filePathBytes);
auto open_ret = ::Bolt_Open(filePathGS);
auto open_ret = ::Bolt_Open(readOnly, filePathGS);
if (open_ret.r2 != 0) {
errorOut = QString::fromUtf8(open_ret.r1, open_ret.r2);
free(open_ret.r1);
@ -45,27 +45,27 @@ static bool handleTriple(int r0, char* r1, int64_t r2, QString& errorOut) {
}
}
bool BoltDB::addBucket(QStringList bucketPath, QByteArray bucketName, QString& errorOut)
bool BoltDB::addBucket(const QList<QByteArray>& bucketPath, QByteArray bucketName, QString& errorOut)
{
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
GoString bucketNameGS = Interop::toGoString_WeakRef(&bucketName);
auto resp = ::Bolt_CreateBucket(this->gmsDbRef, browse.slice, bucketNameGS);
return handleTriple(resp.r0, resp.r1, resp.r2, errorOut);
}
bool BoltDB::deleteBucket(QStringList bucketPath, QByteArray bucketName, QString& errorOut)
bool BoltDB::deleteBucket(const QList<QByteArray>& bucketPath, QByteArray bucketName, QString& errorOut)
{
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
GoString bucketNameGS = Interop::toGoString_WeakRef(&bucketName);
auto resp = ::Bolt_DeleteBucket(this->gmsDbRef, browse.slice, bucketNameGS);
return handleTriple(resp.r0, resp.r1, resp.r2, errorOut);
}
bool BoltDB::setItem(QStringList bucketPath, QByteArray keyName, QByteArray value, QString& errorOut)
bool BoltDB::setItem(const QList<QByteArray>& bucketPath, QByteArray keyName, QByteArray value, QString& errorOut)
{
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
GoString keyNameGS = Interop::toGoString_WeakRef(&keyName);
GoString valueGS = Interop::toGoString_WeakRef(&value);
auto resp = ::Bolt_SetItem(this->gmsDbRef, browse.slice, keyNameGS, valueGS);
@ -73,9 +73,9 @@ bool BoltDB::setItem(QStringList bucketPath, QByteArray keyName, QByteArray valu
return handleTriple(resp.r0, resp.r1, resp.r2, errorOut);
}
bool BoltDB::deleteItem(QStringList bucketPath, QByteArray keyName, QString& errorOut)
bool BoltDB::deleteItem(const QList<QByteArray>& bucketPath, QByteArray keyName, QString& errorOut)
{
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
GoString keyNameGS = Interop::toGoString_WeakRef(&keyName);
auto resp = ::Bolt_DeleteItem(this->gmsDbRef, browse.slice, keyNameGS);
@ -89,20 +89,20 @@ bool BoltDB::listBucketsAtRoot(QString& errorOut, NameReciever cb)
return pumpNext(listJob, errorOut, cb);
}
bool BoltDB::listBuckets(QStringList bucketPath, QString& errorOut, NameReciever cb)
bool BoltDB::listBuckets(const QList<QByteArray>& bucketPath, QString& errorOut, NameReciever cb)
{
if (bucketPath.size() == 0) {
return listBucketsAtRoot(errorOut, cb);
}
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
auto listJob = ::Bolt_ListBuckets(this->gmsDbRef, browse.slice);
return pumpNext(listJob, errorOut, cb);
}
bool BoltDB::listKeys(QStringList bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb)
bool BoltDB::listKeys(const QList<QByteArray>& bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb)
{
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
auto listJob = ::Bolt_ListItems(this->gmsDbRef, browse.slice);
return pumpNext(listJob, errorOut, [=](QByteArray b) {
// First 8 bytes are little-endian uint64 len
@ -111,9 +111,9 @@ bool BoltDB::listKeys(QStringList bucketPath, QString& errorOut, std::function<v
});
}
bool BoltDB::getData(QStringList bucketPath, QByteArray key, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError)
bool BoltDB::getData(const QList<QByteArray>& bucketPath, QByteArray key, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError)
{
GoSliceManagedWrapper browse(&bucketPath);
GoSliceManagedWrapper browse(bucketPath);
GoString keyGS = Interop::toGoString_WeakRef(&key);
auto resp = ::Bolt_GetItem(this->gmsDbRef, browse.slice, keyGS);
@ -185,9 +185,9 @@ bool BoltDB::getStatsJSON(std::function<void(QByteArray)> onSuccess, std::functi
}
}
bool BoltDB::getBucketStatsJSON(QStringList bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError)
bool BoltDB::getBucketStatsJSON(const QList<QByteArray>& bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError)
{
GoSliceManagedWrapper sliceWrapper(&bucketPath);
GoSliceManagedWrapper sliceWrapper(bucketPath);
auto statresp = Bolt_BucketStats(this->gmsDbRef, sliceWrapper.slice);
if (statresp.r0 == ERROR_AND_STOP_CALLING) {

View File

@ -14,27 +14,27 @@ protected:
GoInt64 gmsDbRef;
public:
static BoltDB* createFrom(QString filePath, QString &errorOut);
static BoltDB* createFrom(QString filePath, bool readOnly, QString &errorOut);
bool listBucketsAtRoot(QString& errorOut, NameReciever cb);
bool listBuckets(QStringList bucketPath, QString& errorOut, NameReciever cb);
bool listBuckets(const QList<QByteArray>& bucketPath, QString& errorOut, NameReciever cb);
bool addBucket(QStringList bucketPath, QByteArray bucketName, QString& errorOut);
bool addBucket(const QList<QByteArray>& bucketPath, QByteArray bucketName, QString& errorOut);
bool deleteBucket(QStringList bucketPath, QByteArray bucketName, QString& errorOut);
bool deleteBucket(const QList<QByteArray>& bucketPath, QByteArray bucketName, QString& errorOut);
bool setItem(QStringList bucketPath, QByteArray keyName, QByteArray value, QString& errorOut);
bool setItem(const QList<QByteArray>& bucketPath, QByteArray keyName, QByteArray value, QString& errorOut);
bool deleteItem(QStringList bucketPath, QByteArray keyName, QString& errorOut);
bool deleteItem(const QList<QByteArray>& bucketPath, QByteArray keyName, QString& errorOut);
bool listKeys(QStringList bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb);
bool listKeys(const QList<QByteArray>& bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb);
bool getData(QStringList bucketPath, QByteArray key, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
bool getData(const QList<QByteArray>& bucketPath, QByteArray key, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
bool getStatsJSON(std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
bool getBucketStatsJSON(QStringList bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
bool getBucketStatsJSON(const QList<QByteArray>& bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
~BoltDB();

View File

@ -17,22 +17,22 @@ int64_t Interop::GetMagic() {
//
GoSliceManagedWrapper::GoSliceManagedWrapper(QStringList *qsl) :
GoSliceManagedWrapper::GoSliceManagedWrapper(const QList<QByteArray>& qsl) :
rawStrings(),
slice(),
strings(nullptr)
{
rawStrings.reserve(qsl->size());
strings = new GoString[qsl->size()];
rawStrings.reserve(qsl.size());
strings = new GoString[qsl.size()];
for (int i = 0; i < qsl->size(); ++i) {
rawStrings.push_back( qsl->at(i).toUtf8() );
for (int i = 0; i < qsl.size(); ++i) {
rawStrings.push_back( qsl.at(i) );
strings[i].p = rawStrings[i].data();
strings[i].n = rawStrings[i].size();
}
slice.data = static_cast<void*>(strings);
slice.len = qsl->size(); // * sizeof(GoString);
slice.len = qsl.size(); // * sizeof(GoString);
slice.cap = slice.len;
}

View File

@ -9,7 +9,7 @@ class GoSliceManagedWrapper {
Q_DISABLE_COPY(GoSliceManagedWrapper)
public:
GoSliceManagedWrapper(QStringList *qsl);
GoSliceManagedWrapper(const QList<QByteArray>& qsl);
~GoSliceManagedWrapper();
protected:
QList<QByteArray> rawStrings;

View File

@ -35,6 +35,8 @@ MainWindow::~MainWindow()
}
static const int BdbPointerRole = Qt::UserRole + 1;
static const int BinaryDataRole = Qt::UserRole + 2;
#define SET_BDB(top, bdb) top->setData(0, BdbPointerRole, QVariant::fromValue<void*>(static_cast<void*>(bdb)))
#define GET_BDB(top) static_cast<BoltDB*>( top->data(0, BdbPointerRole).value<void*>() )
@ -42,7 +44,7 @@ void MainWindow::on_actionNew_database_triggered()
{
QString file = QFileDialog::getSaveFileName(this, tr("Save new bolt database as..."));
if (file.length()) {
openDatabase(file);
openDatabase(file, false);
}
}
@ -50,15 +52,23 @@ void MainWindow::on_actionOpen_database_triggered()
{
QString file = QFileDialog::getOpenFileName(this, tr("Select bolt database..."));
if (file.length()) {
openDatabase(file);
openDatabase(file, false);
}
}
void MainWindow::openDatabase(QString file)
void MainWindow::on_actionOpen_database_as_read_only_triggered()
{
QString file = QFileDialog::getOpenFileName(this, tr("Select bolt database..."));
if (file.length()) {
openDatabase(file, true);
}
}
void MainWindow::openDatabase(QString file, bool readOnly)
{
// Open
QString error;
auto *bdb = BoltDB::createFrom(file, error);
auto *bdb = BoltDB::createFrom(file, readOnly, error);
if (bdb == nullptr) {
QMessageBox qmb;
qmb.setText(tr("Error opening database: %1").arg(error));
@ -78,12 +88,38 @@ void MainWindow::openDatabase(QString file)
ui->bucketTree->expandItem(top);
}
static const QString getDisplayName(const QByteArray &qba) {
// FIXME the formatting isn't so great when control characters, etc. are used
// A C-style escape display, or the unicode-replacement-character would be preferable
QString ret(QString::fromUtf8(qba));
bool allPrintable = true;
for (auto i = ret.begin(), e = ret.end(); i != e; ++i) {
if (! i->isPrint()) {
allPrintable = false;
break;
}
}
if (allPrintable) {
return ret; // fine
}
// Some of the characters weren't printable.
// Build up a replacement string
QString replacement;
for (auto i = ret.begin(), e = ret.end(); i != e; ++i) {
replacement += i->isPrint() ? *i : QStringLiteral("\\u{%1}").arg(i->unicode());
}
return replacement;
}
void MainWindow::refreshBucketTree(QTreeWidgetItem* itm)
{
QTreeWidgetItem *top = itm;
QStringList browsePath;
QList<QByteArray> browsePath;
while(top->parent() != nullptr) {
browsePath.push_front(top->text(0));
browsePath.push_front(top->data(0, BinaryDataRole).toByteArray());
top = top->parent();
}
@ -100,7 +136,8 @@ void MainWindow::refreshBucketTree(QTreeWidgetItem* itm)
error,
[=](QByteArray qba){
QTreeWidgetItem *child = new QTreeWidgetItem();
child->setText(0, QString::fromUtf8(qba));
child->setText(0, getDisplayName(qba));
child->setData(0, BinaryDataRole, qba);
child->setIcon(0, QIcon(":/rsrc/table.png"));
itm->addChild(child);
@ -215,10 +252,10 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
ui->stackedWidget->setCurrentWidget(ui->bucketPage);
ui->bucketPropertiesArea->clear();
QStringList browse;
QList<QByteArray> browse;
QTreeWidgetItem *top = current;
while (top->parent() != nullptr) {
browse.push_front(top->text(0));
browse.push_front(top->data(0, BinaryDataRole).toByteArray());
top = top->parent();
}
auto *bdb = GET_BDB(top);
@ -242,14 +279,15 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
}
}
void MainWindow::refreshData(BoltDB *bdb, QStringList browse)
void MainWindow::refreshData(BoltDB *bdb, const QList<QByteArray>& browse)
{
// Load the data tab
ui->bucketData->clear();
QString err;
bool ok = bdb->listKeys(browse, err, [=](QByteArray name, int64_t dataLen) {
auto *itm = new QTreeWidgetItem();
itm->setText(0, QString::fromUtf8(name));
itm->setText(0, getDisplayName(name));
itm->setData(0, BinaryDataRole, name);
itm->setText(1, QString("%1").arg(dataLen));
ui->bucketData->addTopLevelItem(itm);
});
@ -275,14 +313,14 @@ void MainWindow::on_actionClear_selection_triggered()
return; \
} \
QTreeWidgetItem* top = itm; \
QStringList browse; \
QList<QByteArray> browse; \
while(top->parent() != nullptr) { \
browse.push_front(top->text(0)); \
browse.push_front(top->data(0, BinaryDataRole).toByteArray()); \
top = top->parent(); \
} \
auto *bdb = GET_BDB(top);
void MainWindow::openEditor(BoltDB *bdb, QStringList saveAs, QByteArray saveAsKey, QByteArray currentContent)
void MainWindow::openEditor(BoltDB *bdb, const QList<QByteArray>& saveAs, QByteArray saveAsKey, QByteArray currentContent)
{
auto iw = new ItemWindow();
iw->ContentArea()->setPlainText(QString::fromUtf8(currentContent));
@ -312,15 +350,15 @@ void MainWindow::on_bucketData_doubleClicked(const QModelIndex &index)
// Get item key
auto model = index.model();
QString key = model->data(model->index(index.row(), 0), 0).toString();
const QByteArray& key = model->data(model->index(index.row(), 0), BinaryDataRole).toByteArray();
// DB lookup
bdb->getData(
browse,
key.toUtf8(),
key,
[=](QByteArray content) {
openEditor(bdb, browse, key.toUtf8(), content);
openEditor(bdb, browse, key, content);
},
[=](QString error) {
QMessageBox qmb;
@ -361,17 +399,27 @@ void MainWindow::on_actionDelete_bucket_triggered()
GET_ITM_TOP_BROWSE_BDB;
// Prompt for confirmation
QString bucketToDelete = itm->text(0);
if (QMessageBox::question(this, tr("Delete bucket"), tr("Are you sure you want to remove the bucket '%1'?").arg(bucketToDelete), QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes) {
const QByteArray& bucketToDelete = itm->data(0, BinaryDataRole).toByteArray();
if (
QMessageBox::question(
this,
tr("Delete bucket"),
tr("Are you sure you want to remove the bucket '%1'?").arg(getDisplayName(bucketToDelete)),
QMessageBox::Yes,
QMessageBox::Cancel
) != QMessageBox::Yes
) {
return;
}
QTreeWidgetItem* parent = itm->parent();
// One level down
browse.pop_back();
QString err;
if (! bdb->deleteBucket(browse, bucketToDelete.toUtf8(), err)) {
if (! bdb->deleteBucket(browse, bucketToDelete, err)) {
QMessageBox qmb;
qmb.setText(tr("Error removing bucket: %1").arg(err));
qmb.exec();
@ -379,9 +427,9 @@ void MainWindow::on_actionDelete_bucket_triggered()
}
// Refresh bucket list
refreshBucketTree(itm->parent()); // sub-tree only
ui->bucketTree->expandItem(itm->parent());
refreshBucketTree(parent); // sub-tree only
ui->bucketTree->expandItem(parent);
ui->bucketTree->setCurrentItem(parent);
}
void MainWindow::on_AddDataButton_clicked()
@ -414,7 +462,7 @@ void MainWindow::on_DeleteDataButton_clicked()
QString err;
for (int i = selection.length(); i-->0;) {
if (! bdb->deleteItem(browse, selection[i]->text(0).toUtf8(), err)) {
if (! bdb->deleteItem(browse, selection[i]->data(0, BinaryDataRole).toByteArray(), err)) {
QMessageBox qmb;
qmb.setText(tr("Error removing item: %1").arg(err));
qmb.exec();

View File

@ -51,11 +51,13 @@ private slots:
void on_bucketData_itemSelectionChanged();
void on_actionOpen_database_as_read_only_triggered();
protected:
void openDatabase(QString file);
void openDatabase(QString file, bool readOnly);
void refreshBucketTree(QTreeWidgetItem* top);
void refreshData(BoltDB *bdb, QStringList browse);
void openEditor(BoltDB *bdb, QStringList saveAs, QByteArray saveAsKey, QByteArray currentContent);
void refreshData(BoltDB *bdb, const QList<QByteArray>& browse);
void openEditor(BoltDB *bdb, const QList<QByteArray>& saveAs, QByteArray saveAsKey, QByteArray currentContent);
private:
Ui::MainWindow *ui;

View File

@ -278,6 +278,7 @@
</property>
<addaction name="actionNew_database"/>
<addaction name="actionOpen_database"/>
<addaction name="actionOpen_database_as_read_only"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
@ -395,6 +396,11 @@
<string>Add bucket...</string>
</property>
</action>
<action name="actionOpen_database_as_read_only">
<property name="text">
<string>Open database as read-only...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View File

@ -20,10 +20,13 @@ win32: {
DEFINES += CGO_WINDOWS
QMAKE_LIBS += $$_PRO_FILE_PWD_/../build/win32/qbolt.a
QMAKE_LIBS += -lntdll
RC_ICONS = rsrc/qbolt.ico
}
linux: {
QMAKE_LIBS += $$_PRO_FILE_PWD_/../build/linux/qbolt.a
QMAKE_LIBS += -lpthread
}
SOURCES += main.cpp\

BIN
qbolt/rsrc/qbolt.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB