|
|
@ -78,12 +78,12 @@ KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,bool ArgMin,bool Arg |
|
|
|
setStateFileOpen(false); |
|
|
|
setStateFileOpen(false); |
|
|
|
setupMenus(); |
|
|
|
setupMenus(); |
|
|
|
DetailView->setVisible(config->showEntryDetails()); |
|
|
|
DetailView->setVisible(config->showEntryDetails()); |
|
|
|
statusbarState = 0; |
|
|
|
StatusBarGeneral=new QLabel(statusBar()); |
|
|
|
StatusBarGeneral=new QLabel(tr("Ready"),statusBar()); |
|
|
|
|
|
|
|
//StatusBarSelection=new QLabel(statusBar());
|
|
|
|
//StatusBarSelection=new QLabel(statusBar());
|
|
|
|
statusBar()->addWidget(StatusBarGeneral,15); |
|
|
|
statusBar()->addWidget(StatusBarGeneral,15); |
|
|
|
//statusBar()->addWidget(StatusBarSelection,85);
|
|
|
|
//statusBar()->addWidget(StatusBarSelection,85);
|
|
|
|
statusBar()->setVisible(config->showStatusbar()); |
|
|
|
statusBar()->setVisible(config->showStatusbar()); |
|
|
|
|
|
|
|
setStatusBarMsg(StatusBarReady); |
|
|
|
|
|
|
|
|
|
|
|
NormalCentralWidget=QMainWindow::centralWidget(); |
|
|
|
NormalCentralWidget=QMainWindow::centralWidget(); |
|
|
|
LockedCentralWidget=new QWidget(this); |
|
|
|
LockedCentralWidget=new QWidget(this); |
|
|
@ -398,19 +398,27 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbReadOnly = false; |
|
|
|
|
|
|
|
|
|
|
|
if (QFile::exists(filename+".lock")){ |
|
|
|
if (QFile::exists(filename+".lock")){ |
|
|
|
QMessageBox::StandardButton buttonPressed = QMessageBox::question( |
|
|
|
QMessageBox msgBox(this); |
|
|
|
this, |
|
|
|
msgBox.setIcon(QMessageBox::Question); |
|
|
|
tr("Database locked"), |
|
|
|
msgBox.setWindowTitle(tr("Database locked")); |
|
|
|
tr("The database you are trying to open is locked.\n" |
|
|
|
msgBox.setText(tr("The database you are trying to open is locked.\n" |
|
|
|
"This means that either someone else has opened the file or KeePassX crashed last time it opened the database.\n\n" |
|
|
|
"This means that either someone else has opened the file or KeePassX crashed last time it opened the database.\n\n" |
|
|
|
"Do you want to open it anyway?" |
|
|
|
"Do you want to open it anyway?" |
|
|
|
), |
|
|
|
)); |
|
|
|
QMessageBox::Yes|QMessageBox::No, |
|
|
|
msgBox.addButton(QMessageBox::Yes); |
|
|
|
QMessageBox::No |
|
|
|
msgBox.addButton(QMessageBox::No); |
|
|
|
); |
|
|
|
QPushButton* readOnlyButton = new QPushButton(tr("Open read-only"), &msgBox); |
|
|
|
if (buttonPressed != QMessageBox::Yes) |
|
|
|
msgBox.addButton(readOnlyButton, QMessageBox::AcceptRole); |
|
|
|
|
|
|
|
msgBox.setDefaultButton(readOnlyButton); |
|
|
|
|
|
|
|
msgBox.exec(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!msgBox.clickedButton() || msgBox.clickedButton() == msgBox.button(QMessageBox::No)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
else if (msgBox.clickedButton() == readOnlyButton) |
|
|
|
|
|
|
|
dbReadOnly = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!IsAuto){ |
|
|
|
if(!IsAuto){ |
|
|
@ -439,18 +447,18 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){ |
|
|
|
EntryView->db=db; |
|
|
|
EntryView->db=db; |
|
|
|
setupDatabaseConnections(db); |
|
|
|
setupDatabaseConnections(db); |
|
|
|
QString err; |
|
|
|
QString err; |
|
|
|
statusbarState = 1; |
|
|
|
setStatusBarMsg(StatusBarLoading); |
|
|
|
StatusBarGeneral->setText(tr("Loading Database...")); |
|
|
|
|
|
|
|
db->setKey(dlg.password(),dlg.keyFile()); |
|
|
|
db->setKey(dlg.password(),dlg.keyFile()); |
|
|
|
if(db->load(filename)){ |
|
|
|
|
|
|
|
if (!QFile::exists(filename+".lock")){ |
|
|
|
if (!dbReadOnly && !QFile::exists(filename+".lock")){ |
|
|
|
QFile lock(filename+".lock"); |
|
|
|
QFile lock(filename+".lock"); |
|
|
|
if (!lock.open(QIODevice::WriteOnly)){ |
|
|
|
if (!lock.open(QIODevice::WriteOnly)){ |
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Couldn't create database lock file.")); |
|
|
|
setStatusBarMsg(StatusBarReadOnlyLock); |
|
|
|
return false; |
|
|
|
dbReadOnly = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(db->load(filename, dbReadOnly)){ |
|
|
|
if (IsLocked) |
|
|
|
if (IsLocked) |
|
|
|
resetLock(); |
|
|
|
resetLock(); |
|
|
|
currentFile = filename; |
|
|
|
currentFile = filename; |
|
|
@ -462,8 +470,7 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){ |
|
|
|
setStateFileModified(static_cast<Kdb3Database*>(db)->hasPasswordEncodingChanged()); |
|
|
|
setStateFileModified(static_cast<Kdb3Database*>(db)->hasPasswordEncodingChanged()); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
else{ |
|
|
|
statusbarState = 2; |
|
|
|
setStatusBarMsg(StatusBarLoadingFailed); |
|
|
|
StatusBarGeneral->setText(tr("Loading Failed")); |
|
|
|
|
|
|
|
QString error=db->getError(); |
|
|
|
QString error=db->getError(); |
|
|
|
if(error.isEmpty())error=tr("Unknown error while loading database."); |
|
|
|
if(error.isEmpty())error=tr("Unknown error while loading database."); |
|
|
|
QMessageBox::critical(this,tr("Error"), |
|
|
|
QMessageBox::critical(this,tr("Error"), |
|
|
@ -478,8 +485,8 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
statusbarState = 0; |
|
|
|
if (statusbarState != StatusBarReadOnlyLock) |
|
|
|
StatusBarGeneral->setText(tr("Ready")); |
|
|
|
setStatusBarMsg(StatusBarReady); |
|
|
|
inactivityCounter = 0; |
|
|
|
inactivityCounter = 0; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -509,10 +516,15 @@ bool KeepassMainWindow::closeDatabase(bool lock){ |
|
|
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes); |
|
|
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes); |
|
|
|
if(r==QMessageBox::Cancel) return false; //Cancel
|
|
|
|
if(r==QMessageBox::Cancel) return false; //Cancel
|
|
|
|
if(r==QMessageBox::Yes){ //Yes (Save file)
|
|
|
|
if(r==QMessageBox::Yes){ //Yes (Save file)
|
|
|
|
|
|
|
|
if (dbReadOnly) { |
|
|
|
|
|
|
|
if(!OnFileSaveAs()) return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
if(!OnFileSave()) return false; |
|
|
|
if(!OnFileSave()) return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
db->close(); |
|
|
|
db->close(); |
|
|
|
delete db; |
|
|
|
delete db; |
|
|
|
db=NULL; |
|
|
|
db=NULL; |
|
|
@ -1028,6 +1040,14 @@ void KeepassMainWindow::closeEvent(QCloseEvent* e){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(FileOpen && !closeDatabase()){ |
|
|
|
|
|
|
|
ShutingDown=false; |
|
|
|
|
|
|
|
e->ignore(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e->accept(); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef GLOBAL_AUTOTYPE |
|
|
|
#ifdef GLOBAL_AUTOTYPE |
|
|
|
autoType->unregisterGlobalShortcut(); |
|
|
|
autoType->unregisterGlobalShortcut(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -1040,19 +1060,8 @@ void KeepassMainWindow::closeEvent(QCloseEvent* e){ |
|
|
|
config->setHSplitterPos(HSplitter->saveState()); |
|
|
|
config->setHSplitterPos(HSplitter->saveState()); |
|
|
|
config->setShowStatusbar(statusBar()->isVisible()); |
|
|
|
config->setShowStatusbar(statusBar()->isVisible()); |
|
|
|
|
|
|
|
|
|
|
|
if(FileOpen){ |
|
|
|
|
|
|
|
if(!closeDatabase()){ |
|
|
|
|
|
|
|
ShutingDown=false; |
|
|
|
|
|
|
|
e->ignore(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
e->accept(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
e->accept(); |
|
|
|
|
|
|
|
delete SysTray; |
|
|
|
delete SysTray; |
|
|
|
QCoreApplication::quit(); |
|
|
|
QApplication::quit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void KeepassMainWindow::hideEvent(QHideEvent* event){ |
|
|
|
void KeepassMainWindow::hideEvent(QHideEvent* event){ |
|
|
@ -1101,17 +1110,7 @@ void KeepassMainWindow::OnExtrasSettings(){ |
|
|
|
else { |
|
|
|
else { |
|
|
|
setWindowTitle(APP_DISPLAY_NAME); |
|
|
|
setWindowTitle(APP_DISPLAY_NAME); |
|
|
|
} |
|
|
|
} |
|
|
|
switch (statusbarState) { |
|
|
|
setStatusBarMsg(statusbarState); |
|
|
|
case 0: |
|
|
|
|
|
|
|
StatusBarGeneral->setText(tr("Ready")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
StatusBarGeneral->setText(tr("Loading Database...")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
StatusBarGeneral->setText(tr("Loading Failed")); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EntryView->setAlternatingRowColors(config->alternatingRowColors()); |
|
|
|
EntryView->setAlternatingRowColors(config->alternatingRowColors()); |
|
|
@ -1409,3 +1408,25 @@ void KeepassMainWindow::createBookmarkActions(){ |
|
|
|
menuBookmarks->addAction(action); |
|
|
|
menuBookmarks->addAction(action); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KeepassMainWindow::setStatusBarMsg(StatusBarMsg statusBarMsg) { |
|
|
|
|
|
|
|
QString text; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (statusBarMsg) { |
|
|
|
|
|
|
|
case StatusBarReady: |
|
|
|
|
|
|
|
text = tr("Ready"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case StatusBarLoading: |
|
|
|
|
|
|
|
text = tr("Loading Database..."); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case StatusBarLoadingFailed: |
|
|
|
|
|
|
|
text = tr("Loading Failed"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case StatusBarReadOnlyLock: |
|
|
|
|
|
|
|
text = tr("Couldn't create lock file. Opening the database read-only."); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statusbarState = statusBarMsg; |
|
|
|
|
|
|
|
StatusBarGeneral->setText(text); |
|
|
|
|
|
|
|
} |
|
|
|