62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
|
#include "mainwindow.h"
|
||
|
#include "ui_mainwindow.h"
|
||
|
|
||
|
#include "../qbolt.h"
|
||
|
|
||
|
#include <QFileDialog>
|
||
|
#include <QMessageBox>
|
||
|
|
||
|
MainWindow::MainWindow(QWidget *parent) :
|
||
|
QMainWindow(parent),
|
||
|
ui(new Ui::MainWindow)
|
||
|
{
|
||
|
ui->setupUi(this);
|
||
|
}
|
||
|
|
||
|
MainWindow::~MainWindow()
|
||
|
{
|
||
|
delete ui;
|
||
|
}
|
||
|
|
||
|
static QString GetError(GoInterface err) {
|
||
|
if (err.v == nullptr) {
|
||
|
return ""; // no error
|
||
|
}
|
||
|
|
||
|
GoString gs = Error_Error(err);
|
||
|
return QString::fromUtf8(gs.p, gs.n);
|
||
|
}
|
||
|
|
||
|
void MainWindow::on_actionOpen_database_triggered()
|
||
|
{
|
||
|
QString file = QFileDialog::getOpenFileName(this, tr("Select bolt database..."));
|
||
|
if (! file.length()) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
auto opts = Bolt_Options_New_Readonly();
|
||
|
|
||
|
QByteArray filePathBytes(file.toUtf8());
|
||
|
GoString filePathGS = {filePathBytes.data(), filePathBytes.length()};
|
||
|
|
||
|
auto open_ret = Bolt_Open(filePathGS, 0444, opts);
|
||
|
if (open_ret.r1.v != nullptr) {
|
||
|
QMessageBox qmb;
|
||
|
qmb.setText(tr("Error opening database: %s").arg(GetError(open_ret.r1)));
|
||
|
qmb.exec();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// do something
|
||
|
|
||
|
// close database
|
||
|
|
||
|
auto err = Bolt_Close(open_ret.r0);
|
||
|
if (err.v != nullptr) {
|
||
|
QMessageBox qmb;
|
||
|
qmb.setText(tr("Error closing database: %s").arg(GetError(err)));
|
||
|
qmb.exec();
|
||
|
return;
|
||
|
}
|
||
|
}
|