File: mainwindow.cpp

package info (click to toggle)
bdbvu 0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 176 kB
  • ctags: 84
  • sloc: cpp: 528; makefile: 4
file content (109 lines) | stat: -rw-r--r-- 2,828 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
    Copyright (c) Ferruccio Barletta (ferruccio.barletta@gmail.com), 2010

    This file is part of BDBVu.

    BDBVu is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BDBVu is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with BDBVu.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    settings("Ferruccio Barletta", "bdbvu")
{
    ui->setupUi(this);
    ui->databaseType->setText("");
}

MainWindow::~MainWindow()
{
    db.close();
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

//
// slot: open a new database file using an open file dialog
//
void MainWindow::openFile()
{
    QString path = settings.value("path", QDir::homePath()).toString();
    QFileDialog ofd(this, tr("open BDB file"), path, tr("All Files (*)"));
    if (ofd.exec()) {
        // remember where we parked
        settings.setValue("path", ofd.directory().absolutePath());
        openFile(ofd.selectedFiles().first());
    }
}

void MainWindow::openFile(QString filename)
{
    db.close();
    try {
        db.open(filename.toLatin1());
    }
    catch (dbexception ex) {
        QMessageBox::critical(this, "BDBVu", ex.what());
    }
    ui->databaseSelector->clear();
    if (db.sdblist.length() > 0) {
        foreach (QString dbname, db.sdblist)
            ui->databaseSelector->addItem(dbname, dbname);
        selectDatabase(db.sdblist[0]);
    }
    else
        ui->databaseSelector->setEnabled(false);
}

//
//  slot: select a new sub-database
//
void MainWindow::selectDatabase(const QString& dbname) {
    db.opensubdb(dbname);
    ui->listWidget->clear();
    foreach (dbkey k, db.keylist) {
        QListWidgetItem *li = new QListWidgetItem(k.display);
        ui->listWidget->addItem(li);
    }
    ui->listWidget->setCurrentRow(0);
    ui->databaseType->setText(db.sdbtype);
}

//
//  slot: select a new sub-database key at index
//
void MainWindow::selectKey(int index)
{
    ui->textBrowser->clear();
    if (index != -1) {
        ui->textBrowser->append(db.getRecord(index));
    }
}