mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
Fix opening new database, while another one is open
Avoid crashes by checking for model being set. Thoroughly close previous database before opening a new one. Drop changeDB() function and replace by init_database.
This commit is contained in:
parent
6f8a543761
commit
e4f9dd6389
@ -180,16 +180,6 @@ void MainWindow::init_menu()
|
||||
setItemEnabled(Database.isOpen());
|
||||
}
|
||||
|
||||
int MainWindow::changeDB(QString fname)
|
||||
{
|
||||
if (fname.isEmpty())
|
||||
return 1;
|
||||
close_database();
|
||||
if (!database_model::isRemoteDB(fname))
|
||||
homedir = QFileInfo(fname).canonicalPath();
|
||||
return init_database(fname);
|
||||
}
|
||||
|
||||
void MainWindow::update_history_menu()
|
||||
{
|
||||
QStringList hist = history.get();
|
||||
@ -212,7 +202,7 @@ void MainWindow::update_history_menu()
|
||||
|
||||
void MainWindow::open_database(QAction* a)
|
||||
{
|
||||
changeDB(a->data().toString());
|
||||
init_database(a->data().toString());
|
||||
}
|
||||
|
||||
void MainWindow::new_database()
|
||||
@ -225,7 +215,7 @@ void MainWindow::new_database()
|
||||
// in Qt's OS X file open dialog,
|
||||
// the filename actually ends with that extension.
|
||||
// Otherwise usability breaks in jarring ways.
|
||||
changeDB(getFullFilename(fname, selectedFilter));
|
||||
init_database(getFullFilename(fname, selectedFilter));
|
||||
}
|
||||
|
||||
void MainWindow::load_database()
|
||||
@ -233,7 +223,7 @@ void MainWindow::load_database()
|
||||
load_db l;
|
||||
QString fname = QFileDialog::getOpenFileName(this, l.caption, homedir,
|
||||
l.filter);
|
||||
changeDB(fname);
|
||||
init_database(fname);
|
||||
}
|
||||
|
||||
void MainWindow::setOptions()
|
||||
|
||||
@ -551,6 +551,7 @@ void MainWindow::openRemoteSqlDB()
|
||||
enum open_result MainWindow::init_database(const QString &name,
|
||||
const Passwd &pass)
|
||||
{
|
||||
close_database();
|
||||
try {
|
||||
Database.open(name, pass);
|
||||
return init_database();
|
||||
@ -567,6 +568,10 @@ enum open_result MainWindow::init_database()
|
||||
{
|
||||
if (!Database.isOpen())
|
||||
return open_abort;
|
||||
|
||||
if (!database_model::isRemoteDB(Database.name()))
|
||||
homedir = QFileInfo(Database.name()).canonicalPath();
|
||||
|
||||
setItemEnabled(true);
|
||||
dbindex->setText(tr("Database") + ": " +
|
||||
compressFilename(Database.name()));
|
||||
@ -623,13 +628,13 @@ void MainWindow::close_database()
|
||||
.arg(tabView->currentIndex());
|
||||
|
||||
history.addEntry(Database.name());
|
||||
foreach(XcaTreeView *v, views)
|
||||
v->setModel(NULL);
|
||||
Database.close();
|
||||
|
||||
setItemEnabled(false);
|
||||
dbindex->clear();
|
||||
update_history_menu();
|
||||
foreach(XcaTreeView *v, views)
|
||||
v->setModel(NULL);
|
||||
enableTokenMenu(pkcs11::libraries.loaded());
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +79,6 @@ class MainWindow: public QMainWindow, public Ui::MainWindow
|
||||
NIDlist *read_nidlist(QString name);
|
||||
QLabel *statusLabel;
|
||||
QString homedir;
|
||||
int changeDB(QString fname);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void update_history_menu();
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ OpenDb::OpenDb(QWidget *parent, const QString &db)
|
||||
if (database_model::isRemoteDB(db)) {
|
||||
setupDatabaseName(db);
|
||||
sqlite = false;
|
||||
show_connection_settings = false;
|
||||
show_connection_settings = true;
|
||||
} else if (hasSqLite() && !db.isEmpty()) {
|
||||
dbName->setText(db);
|
||||
sqlite = true;
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
bool XcaProxyModel::lessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
db_base *db = (db_base *)sourceModel();
|
||||
db_base *db = dynamic_cast<db_base *>(sourceModel());
|
||||
if (!db)
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
|
||||
@ -51,6 +51,8 @@ bool XcaProxyModel::lessThan(const QModelIndex &left,
|
||||
bool XcaProxyModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
if (!sourceModel())
|
||||
return false;
|
||||
QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
return sourceModel()->data(idx, Qt::UserRole).toBool();
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ void XcaTreeView::setModel(QAbstractItemModel *model)
|
||||
|
||||
basemodel = dynamic_cast<db_base*>(model);
|
||||
proxy->setSourceModel(model);
|
||||
QTreeView::setModel(proxy);
|
||||
QTreeView::setModel(model ? proxy : NULL);
|
||||
|
||||
if (basemodel) {
|
||||
setRootIsDecorated(basemodel->treeViewMode());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user