|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005-2007 by Tarek Saidi *
|
|
|
|
* tarek.saidi@arcor.de *
|
|
|
|
* *
|
|
|
|
* This program 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; version 2 of the License. *
|
|
|
|
* *
|
|
|
|
* This program 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 this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QStatusBar>
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "lib/AutoType.h"
|
|
|
|
#include "lib/FileDialogs.h"
|
|
|
|
#include "import/Import_PwManager.h"
|
|
|
|
#include "import/Import_KWalletXml.h"
|
|
|
|
#include "import/Import_KeePassX_Xml.h"
|
|
|
|
#include "export/Export_Txt.h"
|
|
|
|
#include "export/Export_KeePassX_Xml.h"
|
|
|
|
|
|
|
|
#include "dialogs/dialogs.h"
|
|
|
|
|
|
|
|
Import_KeePassX_Xml import_KeePassX_Xml;
|
|
|
|
Import_PwManager import_PwManager;
|
|
|
|
Import_KWalletXml import_KWalletXml;
|
|
|
|
Export_Txt export_Txt;
|
|
|
|
Export_KeePassX_Xml export_KeePassX_Xml;
|
|
|
|
|
|
|
|
|
|
|
|
KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,bool ArgMin,bool ArgLock,QWidget *parent, Qt::WFlags flags) :QMainWindow(parent,flags){
|
|
|
|
ShutingDown=false;
|
|
|
|
IsLocked=false;
|
|
|
|
InUnLock=false;
|
|
|
|
unlockDlg=NULL;
|
|
|
|
db=NULL;
|
|
|
|
setupUi(this);
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
setUnifiedTitleAndToolBarOnMac(true);
|
|
|
|
#endif
|
|
|
|
#ifdef AUTOTYPE
|
|
|
|
AutoType::MainWin=this;
|
|
|
|
#endif
|
|
|
|
#ifdef GLOBAL_AUTOTYPE
|
|
|
|
AutoType::registerGlobalShortcut(config->globalShortcut());
|
|
|
|
#endif
|
|
|
|
setWindowModified(false);
|
|
|
|
setGeometry(config->mainWindowGeometry(geometry()));
|
|
|
|
VSplitter->restoreState(config->vSplitterPos());
|
|
|
|
HSplitter->restoreState(config->hSplitterPos());
|
|
|
|
SysTray=new QSystemTrayIcon(this);
|
|
|
|
setupToolbar();
|
|
|
|
setupIcons();
|
|
|
|
setStateFileOpen(false);
|
|
|
|
setupMenus();
|
|
|
|
DetailView->setVisible(config->showEntryDetails());
|
|
|
|
StatusBarGeneral=new QLabel(tr("Ready"),statusBar());
|
|
|
|
StatusBarSelection=new QLabel(statusBar());
|
|
|
|
statusBar()->addWidget(StatusBarGeneral,15);
|
|
|
|
statusBar()->addWidget(StatusBarSelection,85);
|
|
|
|
statusBar()->setVisible(config->showStatusbar());
|
|
|
|
|
|
|
|
NormalCentralWidget=QMainWindow::centralWidget();
|
|
|
|
LockedCentralWidget=new QWidget(this);
|
|
|
|
WorkspaceLockedWidget.setupUi(LockedCentralWidget);
|
|
|
|
LockedCentralWidget->setVisible(false);
|
|
|
|
|
|
|
|
setupConnections();
|
|
|
|
|
|
|
|
bool showWindow=true;
|
|
|
|
FileOpen=false;
|
|
|
|
if(!ArgFile.isEmpty()){
|
|
|
|
QString f = QDir::cleanPath(QDir::current().absoluteFilePath(ArgFile));
|
|
|
|
showWindow = !ArgMin;
|
|
|
|
if (ArgLock)
|
|
|
|
fakeOpenDatabase(f);
|
|
|
|
else
|
|
|
|
openDatabase(f,false);
|
|
|
|
}
|
|
|
|
else if(config->openLastFile() && !config->lastFile().isEmpty()){
|
|
|
|
QFileInfo file(config->lastFile());
|
|
|
|
if(file.exists()){
|
|
|
|
QString f = QDir::cleanPath(QDir::current().absoluteFilePath(config->lastFile()));
|
|
|
|
showWindow = !config->startMinimized();
|
|
|
|
if (config->startLocked())
|
|
|
|
fakeOpenDatabase(f);
|
|
|
|
else
|
|
|
|
openDatabase(f,true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
config->setLastFile(QString());
|
|
|
|
}
|
|
|
|
else if (ArgLock){
|
|
|
|
showWindow = false;
|
|
|
|
}
|
|
|
|
// TODO HelpBrowser
|
|
|
|
/*HelpBrowser = new QAssistantClient(QString(),this);
|
|
|
|
HelpBrowser->setArguments(QStringList()<< "-profile" << "share/keepass/doc/keepassx.adp");*/
|
|
|
|
|
|
|
|
createBookmarkActions();
|
|
|
|
|
|
|
|
if (showWindow)
|
|
|
|
show();
|
|
|
|
else if (!config->showSysTrayIcon())
|
|
|
|
showMinimized();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setupConnections(){
|
|
|
|
connect(FileNewAction, SIGNAL(triggered()), this, SLOT(OnFileNewKdb()));
|
|
|
|
connect(FileOpenAction, SIGNAL(triggered()), this, SLOT(OnFileOpen()));
|
|
|
|
connect(FileCloseAction, SIGNAL(triggered()), this, SLOT(OnFileClose()));
|
|
|
|
connect(FileSaveAction, SIGNAL(triggered()), this, SLOT(OnFileSave()));
|
|
|
|
connect(FileSaveAsAction, SIGNAL(triggered()), this, SLOT(OnFileSaveAs()));
|
|
|
|
connect(FileSettingsAction, SIGNAL(triggered()), this, SLOT(OnFileSettings()));
|
|
|
|
connect(FileChangeKeyAction, SIGNAL(triggered()), this, SLOT(OnFileChangeKey()));
|
|
|
|
connect(FileExitAction, SIGNAL(triggered()), this, SLOT(OnFileExit()));
|
|
|
|
connect(FileUnLockWorkspaceAction,SIGNAL(triggered()), this, SLOT(OnUnLockWorkspace()));
|
|
|
|
connect(menuImport,SIGNAL(triggered(QAction*)),this,SLOT(OnImport(QAction*)));
|
|
|
|
connect(menuExport,SIGNAL(triggered(QAction*)),this,SLOT(OnExport(QAction*)));
|
|
|
|
connect(menuBookmarks,SIGNAL(triggered(QAction*)),this,SLOT(OnBookmarkTriggered(QAction*)));
|
|
|
|
|
|
|
|
connect(EditNewGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnNewGroup()));
|
|
|
|
connect(EditEditGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnEditGroup()));
|
|
|
|
connect(EditDeleteGroupAction, SIGNAL(triggered()), GroupView, SLOT(OnDeleteGroup()));
|
|
|
|
connect(EditNewEntryAction, SIGNAL(triggered()), EntryView, SLOT(OnNewEntry()));
|
|
|
|
connect(EditEditEntryAction, SIGNAL(triggered()), EntryView, SLOT(OnEditEntry()));
|
|
|
|
connect(EditCloneEntryAction, SIGNAL(triggered()), EntryView, SLOT(OnCloneEntry()));
|
|
|
|
connect(EditDeleteEntryAction, SIGNAL(triggered()), EntryView, SLOT(OnDeleteEntry()));
|
|
|
|
connect(EditUsernameToClipboardAction, SIGNAL(triggered()), EntryView, SLOT(OnUsernameToClipboard()));
|
|
|
|
connect(EditPasswordToClipboardAction, SIGNAL(triggered()), EntryView, SLOT(OnPasswordToClipboard()));
|
|
|
|
connect(EditOpenUrlAction, SIGNAL(triggered()), EntryView, SLOT(OnEditOpenUrl()));
|
|
|
|
connect(EditSaveAttachmentAction, SIGNAL(triggered()),EntryView, SLOT(OnSaveAttachment()));
|
|
|
|
connect(EditSearchAction, SIGNAL(triggered()), this, SLOT(OnSearch()));
|
|
|
|
connect(EditGroupSearchAction, SIGNAL(triggered()), this, SLOT(OnGroupSearch()));
|
|
|
|
#ifdef AUTOTYPE
|
|
|
|
connect(EditAutoTypeAction,SIGNAL(triggered()),EntryView,SLOT(OnAutoType()));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
connect(ViewShowToolbarAction,SIGNAL(toggled(bool)),this,SLOT(OnViewShowToolbar(bool)));
|
|
|
|
connect(ViewShowEntryDetailsAction,SIGNAL(toggled(bool)),this,SLOT(OnViewShowEntryDetails(bool)));
|
|
|
|
connect(ViewHidePasswordsAction,SIGNAL(toggled(bool)), this, SLOT(OnUsernPasswVisibilityChanged(bool)));
|
|
|
|
connect(ViewHideUsernamesAction,SIGNAL(toggled(bool)), this, SLOT(OnUsernPasswVisibilityChanged(bool)));
|
|
|
|
|
|
|
|
connect(menuColumns,SIGNAL(triggered(QAction*)),this,SLOT(OnColumnVisibilityChanged(QAction*)));
|
|
|
|
connect(ViewToolButtonSize16Action,SIGNAL(toggled(bool)), this, SLOT(OnViewToolbarIconSize16(bool)));
|
|
|
|
connect(ViewToolButtonSize22Action,SIGNAL(toggled(bool)), this, SLOT(OnViewToolbarIconSize22(bool)));
|
|
|
|
connect(ViewToolButtonSize28Action,SIGNAL(toggled(bool)), this, SLOT(OnViewToolbarIconSize28(bool)));
|
|
|
|
connect(ViewShowStatusbarAction,SIGNAL(toggled(bool)),statusBar(),SLOT(setVisible(bool)));
|
|
|
|
|
|
|
|
connect(ExtrasSettingsAction,SIGNAL(triggered(bool)),this,SLOT(OnExtrasSettings()));
|
|
|
|
connect(ExtrasPasswordGenAction,SIGNAL(triggered(bool)),this,SLOT(OnExtrasPasswordGen()));
|
|
|
|
connect(ExtrasShowExpiredEntriesAction,SIGNAL(triggered(bool)),this,SLOT(OnExtrasShowExpiredEntries()));
|
|
|
|
//connect(ExtrasTrashCanAction,SIGNAL(triggered(bool)),this,SLOT(OnExtrasTrashCan())); //TODO ExtrasTrashCan
|
|
|
|
|
|
|
|
//connect(HelpHandbookAction,SIGNAL(triggered()),this,SLOT(OnHelpHandbook())); //TODO Handbook
|
|
|
|
connect(HelpAboutAction,SIGNAL(triggered()),this,SLOT(OnHelpAbout()));
|
|
|
|
|
|
|
|
connect(EntryView,SIGNAL(itemActivated(QTreeWidgetItem*,int)),EntryView,SLOT(OnEntryActivated(QTreeWidgetItem*,int)));
|
|
|
|
connect(QuickSearchEdit,SIGNAL(returnPressed()), this, SLOT(OnQuickSearch()));
|
|
|
|
connect(GroupView,SIGNAL(groupChanged(IGroupHandle*)),EntryView,SLOT(OnGroupChanged(IGroupHandle*)));
|
|
|
|
connect(GroupView,SIGNAL(groupChanged(IGroupHandle*)),this,SLOT(OnGroupSelectionChanged(IGroupHandle*)));
|
|
|
|
connect(GroupView,SIGNAL(fileModified()),this,SLOT(OnFileModified()));
|
|
|
|
connect(EntryView,SIGNAL(fileModified()),this,SLOT(OnFileModified()));
|
|
|
|
connect(EntryView,SIGNAL(selectionChanged(SelectionState)),this,SLOT(OnEntryChanged(SelectionState)));
|
|
|
|
connect(GroupView,SIGNAL(searchResultsSelected()),EntryView,SLOT(OnShowSearchResults()));
|
|
|
|
connect(GroupView,SIGNAL(searchResultsSelected()),this,SLOT(OnShowSearchResults()));
|
|
|
|
connect(GroupView,SIGNAL(entriesDropped()),EntryView,SLOT(removeDragItems()));
|
|
|
|
connect(HideSearchResultsAction,SIGNAL(triggered()),GroupView,SLOT(OnHideSearchResults()));
|
|
|
|
|
|
|
|
connect(SysTray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(OnSysTrayActivated(QSystemTrayIcon::ActivationReason)));
|
|
|
|
connect(DetailView,SIGNAL(anchorClicked(const QUrl&)),this,SLOT(OnDetailViewUrlClicked(const QUrl&)));
|
|
|
|
connect(WorkspaceLockedWidget.Button_Unlock,SIGNAL(clicked()),this,SLOT(OnUnLockWorkspace()));
|
|
|
|
connect(WorkspaceLockedWidget.Button_CloseDatabase,SIGNAL(clicked()),this,SLOT(OnLockClose()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setupToolbar(){
|
|
|
|
toolBar=new QToolBar(this);
|
|
|
|
toolBar->setMovable(false);
|
|
|
|
addToolBar(toolBar);
|
|
|
|
toolBar->setIconSize(QSize(config->toolbarIconSize(),config->toolbarIconSize()));
|
|
|
|
ViewShowToolbarAction=toolBar->toggleViewAction();
|
|
|
|
toolBar->addAction(FileNewAction);
|
|
|
|
toolBar->addAction(FileOpenAction);
|
|
|
|
toolBar->addAction(FileSaveAction);
|
|
|
|
toolBar->addSeparator();
|
|
|
|
toolBar->addAction(EditNewEntryAction);
|
|
|
|
toolBar->addAction(EditEditEntryAction);
|
|
|
|
toolBar->addAction(EditDeleteEntryAction);
|
|
|
|
toolBar->addSeparator();
|
|
|
|
toolBar->addAction(EditUsernameToClipboardAction);
|
|
|
|
toolBar->addAction(EditPasswordToClipboardAction);
|
|
|
|
toolBar->addSeparator();
|
|
|
|
toolBar->addAction(FileUnLockWorkspaceAction);
|
|
|
|
toolBar->addSeparator();
|
|
|
|
QuickSearchEdit=new QLineEdit(toolBar);
|
|
|
|
QuickSearchEdit->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
|
|
|
toolBar->addWidget(QuickSearchEdit);
|
|
|
|
toolBar->setVisible(config->showToolbar());
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setupIcons(){
|
|
|
|
setWindowIcon(getIcon("keepassx"));
|
|
|
|
FileNewAction->setIcon(getIcon("filenew"));
|
|
|
|
FileOpenAction->setIcon(getIcon("fileopen"));
|
|
|
|
FileSaveAction->setIcon(getIcon("filesave"));
|
|
|
|
FileSaveAsAction->setIcon(getIcon("filesaveas"));
|
|
|
|
FileCloseAction->setIcon(getIcon("fileclose"));
|
|
|
|
FileSettingsAction->setIcon(getIcon("dbsettings"));
|
|
|
|
FileUnLockWorkspaceAction->setIcon(getIcon("lock"));
|
|
|
|
FileExitAction->setIcon(getIcon("exit"));
|
|
|
|
EditNewEntryAction->setIcon(getIcon("newentry"));
|
|
|
|
EditEditEntryAction->setIcon(getIcon("editentry"));
|
|
|
|
EditDeleteEntryAction->setIcon(getIcon("deleteentry"));
|
|
|
|
EditUsernameToClipboardAction->setIcon(getIcon("copyusername"));
|
|
|
|
EditPasswordToClipboardAction->setIcon(getIcon("copypwd"));
|
|
|
|
EditCloneEntryAction->setIcon(getIcon("cloneentry"));
|
|
|
|
EditOpenUrlAction->setIcon(getIcon("openurl"));
|
|
|
|
EditSaveAttachmentAction->setIcon(getIcon("filesave"));
|
|
|
|
EditNewGroupAction->setIcon(getIcon("newgroup"));
|
|
|
|
EditEditGroupAction->setIcon(getIcon("editgroup"));
|
|
|
|
EditDeleteGroupAction->setIcon(getIcon("deletegroup"));
|
|
|
|
EditSearchAction->setIcon(getIcon("dbsearch"));
|
|
|
|
EditGroupSearchAction->setIcon(getIcon("groupsearch"));
|
|
|
|
ExtrasShowExpiredEntriesAction->setIcon(getIcon("expired"));
|
|
|
|
ExtrasPasswordGenAction->setIcon(getIcon("generator"));
|
|
|
|
//ExtrasTrashCanAction->setIcon(getIcon("trashcan")); //TODO ExtrasTrashCan
|
|
|
|
ExtrasSettingsAction->setIcon(getIcon("appsettings"));
|
|
|
|
#ifdef AUTOTYPE
|
|
|
|
EditAutoTypeAction->setIcon(getIcon("autotype"));
|
|
|
|
#else
|
|
|
|
EditAutoTypeAction->setVisible(false);
|
|
|
|
#endif
|
|
|
|
//HelpHandbookAction->setIcon(getIcon("manual")); //TODO Handbook
|
|
|
|
HelpAboutAction->setIcon(getIcon("help"));
|
|
|
|
menuBookmarks->menuAction()->setIcon(getIcon("bookmark_folder"));
|
|
|
|
AddThisAsBookmarkAction->setIcon(getIcon("bookmark_this"));
|
|
|
|
AddBookmarkAction->setIcon(getIcon("bookmark_add"));
|
|
|
|
ManageBookmarksAction->setIcon(getIcon("bookmark"));
|
|
|
|
SysTray->setIcon(getIcon("keepassx_large"));
|
|
|
|
if(config->showSysTrayIcon())
|
|
|
|
SysTray->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setupMenus(){
|
|
|
|
GroupView->ContextMenu->addAction(EditNewGroupAction);
|
|
|
|
GroupView->ContextMenu->addAction(EditEditGroupAction);
|
|
|
|
GroupView->ContextMenu->addAction(EditDeleteGroupAction);
|
|
|
|
GroupView->ContextMenu->addSeparator();
|
|
|
|
GroupView->ContextMenu->addAction(EditNewEntryAction);
|
|
|
|
GroupView->ContextMenu->addSeparator();
|
|
|
|
GroupView->ContextMenu->addAction(EditGroupSearchAction);
|
|
|
|
GroupView->ContextMenuSearchGroup->addAction(HideSearchResultsAction);
|
|
|
|
|
|
|
|
EntryView->ContextMenu->addAction(EditUsernameToClipboardAction);
|
|
|
|
EntryView->ContextMenu->addAction(EditPasswordToClipboardAction);
|
|
|
|
EntryView->ContextMenu->addAction(EditOpenUrlAction);
|
|
|
|
EntryView->ContextMenu->addAction(EditSaveAttachmentAction);
|
|
|
|
#ifdef AUTOTYPE
|
|
|
|
EntryView->ContextMenu->addAction(EditAutoTypeAction);
|
|
|
|
#endif
|
|
|
|
EntryView->ContextMenu->addSeparator();
|
|
|
|
EntryView->ContextMenu->addAction(EditNewEntryAction);
|
|
|
|
EntryView->ContextMenu->addAction(EditEditEntryAction);
|
|
|
|
EntryView->ContextMenu->addAction(EditCloneEntryAction);
|
|
|
|
EntryView->ContextMenu->addAction(EditDeleteEntryAction);
|
|
|
|
|
|
|
|
ViewShowToolbarAction->setText(tr("Show Toolbar"));
|
|
|
|
ViewMenu->insertAction(ViewShowEntryDetailsAction,ViewShowToolbarAction);
|
|
|
|
ViewShowToolbarAction->setChecked(config->showToolbar());
|
|
|
|
ViewShowEntryDetailsAction->setChecked(config->showEntryDetails());
|
|
|
|
ViewHidePasswordsAction->setChecked(config->hidePasswords());
|
|
|
|
ViewHideUsernamesAction->setChecked(config->hideUsernames());
|
|
|
|
ViewColumnsTitleAction->setChecked(EntryView->Columns[0]);
|
|
|
|
ViewColumnsUsernameAction->setChecked(EntryView->Columns[1]);
|
|
|
|
ViewColumnsUrlAction->setChecked(EntryView->Columns[2]);
|
|
|
|
ViewColumnsPasswordAction->setChecked(EntryView->Columns[3]);
|
|
|
|
ViewColumnsCommentAction->setChecked(EntryView->Columns[4]);
|
|
|
|
ViewColumnsExpireAction->setChecked(EntryView->Columns[5]);
|
|
|
|
ViewColumnsCreationAction->setChecked(EntryView->Columns[6]);
|
|
|
|
ViewColumnsLastChangeAction->setChecked(EntryView->Columns[7]);
|
|
|
|
ViewColumnsLastAccessAction->setChecked(EntryView->Columns[8]);
|
|
|
|
ViewColumnsAttachmentAction->setChecked(EntryView->Columns[9]);
|
|
|
|
ViewColumnsGroupAction->setChecked(EntryView->Columns[10]);
|
|
|
|
ViewShowStatusbarAction->setChecked(config->showStatusbar());
|
|
|
|
|
|
|
|
switch(config->toolbarIconSize()){
|
|
|
|
case 16: ViewToolButtonSize16Action->setChecked(true); break;
|
|
|
|
case 22: ViewToolButtonSize22Action->setChecked(true); break;
|
|
|
|
case 28: ViewToolButtonSize28Action->setChecked(true); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysTrayMenu = new QMenu(APP_DISPLAY_NAME,this);
|
|
|
|
SysTrayMenu->addAction(FileUnLockWorkspaceAction);
|
|
|
|
SysTrayMenu->addSeparator();
|
|
|
|
SysTrayMenu->addAction(FileExitAction);
|
|
|
|
SysTray->setContextMenu(SysTrayMenu);
|
|
|
|
SysTray->setToolTip(QString("%1 %2 - %3").arg(APP_DISPLAY_NAME, APP_SHORT_FUNC, (IsLocked) ? tr("Locked") : tr("Unlocked")));
|
|
|
|
|
|
|
|
#define _add_import(name){\
|
|
|
|
QAction* import=new QAction(this);\
|
|
|
|
import->setData(qVariantFromValue(dynamic_cast<QObject*>(&name)));\
|
|
|
|
import->setText(name.title());\
|
|
|
|
menuImport->addAction(import);}
|
|
|
|
|
|
|
|
#define _add_export(name){\
|
|
|
|
QAction* Export=new QAction(this);\
|
|
|
|
Export->setData(qVariantFromValue(dynamic_cast<QObject*>(&name)));\
|
|
|
|
Export->setText(name.title());\
|
|
|
|
menuExport->addAction(Export);}
|
|
|
|
|
|
|
|
_add_import(import_KeePassX_Xml)
|
|
|
|
_add_import(import_PwManager)
|
|
|
|
_add_import(import_KWalletXml)
|
|
|
|
_add_export(export_Txt);
|
|
|
|
_add_export(export_KeePassX_Xml);
|
|
|
|
|
|
|
|
FileNewAction->setShortcut(tr("Ctrl+N"));
|
|
|
|
FileOpenAction->setShortcut(tr("Ctrl+O"));
|
|
|
|
FileCloseAction->setShortcut(tr("Ctrl+W"));
|
|
|
|
FileSaveAction->setShortcut(tr("Ctrl+S"));
|
|
|
|
FileUnLockWorkspaceAction->setShortcut(tr("Ctrl+L"));
|
|
|
|
FileExitAction->setShortcut(tr("Ctrl+Q"));
|
|
|
|
EditNewGroupAction->setShortcut(tr("Ctrl+G"));
|
|
|
|
EditPasswordToClipboardAction->setShortcut(tr("Ctrl+C"));
|
|
|
|
EditUsernameToClipboardAction->setShortcut(tr("Ctrl+B"));
|
|
|
|
EditOpenUrlAction->setShortcut(tr("Ctrl+U"));
|
|
|
|
EditNewEntryAction->setShortcut(tr("Ctrl+Y"));
|
|
|
|
EditEditEntryAction->setShortcut(tr("Ctrl+E"));
|
|
|
|
EditDeleteEntryAction->setShortcut(tr("Ctrl+D"));
|
|
|
|
EditCloneEntryAction->setShortcut(tr("Ctrl+K"));
|
|
|
|
EditSearchAction->setShortcut(tr("Ctrl+F"));
|
|
|
|
ExtrasPasswordGenAction->setShortcut(tr("Ctrl+P"));
|
|
|
|
ExtrasShowExpiredEntriesAction->setShortcut(tr("Ctrl+X"));
|
|
|
|
#ifdef AUTOTYPE
|
|
|
|
EditAutoTypeAction->setShortcut(tr("Ctrl+V"));
|
|
|
|
#endif
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
FileSaveAsAction->setShortcut(tr("Shift+Ctrl+S"));
|
|
|
|
EditGroupSearchAction->setShortcut(tr("Shift+Ctrl+F"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//ExtrasTrashCanAction->setVisible(false); //TODO For KP 2.x only
|
|
|
|
menuBookmarks->menuAction()->setVisible(config->featureBookmarks());
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setupDatabaseConnections(IDatabase* DB){
|
|
|
|
ICustomIcons* CustomIconsDb=dynamic_cast<ICustomIcons*>(DB);
|
|
|
|
if(CustomIconsDb){
|
|
|
|
connect(CustomIconsDb,SIGNAL(iconsModified()),this,SLOT(OnFileModified()));
|
|
|
|
connect(CustomIconsDb,SIGNAL(iconsModified()),EntryView,SLOT(updateIcons()));
|
|
|
|
connect(CustomIconsDb,SIGNAL(iconsModified()),GroupView,SLOT(updateIcons()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){
|
|
|
|
if (!QFile::exists(filename)){
|
|
|
|
QMessageBox::critical(this,tr("Error")
|
|
|
|
,tr("The database file does not exist."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!IsAuto){
|
|
|
|
config->setLastKeyLocation(QString());
|
|
|
|
config->setLastKeyType(PASSWORD);
|
|
|
|
}
|
|
|
|
db=dynamic_cast<IDatabase*>(new Kdb3Database());
|
|
|
|
PasswordDialog::DlgFlags flags=PasswordDialog::Flag_None;
|
|
|
|
if(IsAuto)
|
|
|
|
flags = PasswordDialog::Flag_Auto;
|
|
|
|
PasswordDialog dlg(this,PasswordDialog::Mode_Ask,flags,filename);
|
|
|
|
if (InUnLock){
|
|
|
|
dlg.setWindowModality(Qt::WindowModal);
|
|
|
|
unlockDlg = &dlg;
|
|
|
|
}
|
|
|
|
bool rejected = (dlg.exec()==PasswordDialog::Exit_Cancel);
|
|
|
|
if (InUnLock)
|
|
|
|
unlockDlg = NULL;
|
|
|
|
if (rejected)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(dlg.selectedBookmark()!=QString())
|
|
|
|
filename=dlg.selectedBookmark();
|
|
|
|
|
|
|
|
GroupView->db=db;
|
|
|
|
EntryView->db=db;
|
|
|
|
setupDatabaseConnections(db);
|
|
|
|
QString err;
|
|
|
|
StatusBarGeneral->setText(tr("Loading Database..."));
|
|
|
|
db->setKey(dlg.password(),dlg.keyFile());
|
|
|
|
if(db->load(filename)==true){
|
|
|
|
if (IsLocked)
|
|
|
|
resetLock();
|
|
|
|
saveLastFilename(filename);
|
|
|
|
setWindowTitle(QString("%1[*] - KeePassX").arg(filename));
|
|
|
|
GroupView->createItems();
|
|
|
|
EntryView->showGroup(NULL);
|
|
|
|
setStateFileOpen(true);
|
|
|
|
setStateFileModified(false);
|
|
|
|
currentFile = filename;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
StatusBarGeneral->setText(tr("Loading Failed"));
|
|
|
|
QString error=db->getError();
|
|
|
|
if(error.isEmpty())error=tr("Unknown error while loading database.");
|
|
|
|
QMessageBox::critical(this,tr("Error"),
|
|
|
|
QString("%1\n%2").arg(tr("The following error occured while opening the database:"))
|
|
|
|
.arg(error));
|
|
|
|
if(db->isKeyError()){
|
|
|
|
delete db;
|
|
|
|
return openDatabase(filename,IsAuto);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
delete db;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusBarGeneral->setText(tr("Ready"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::fakeOpenDatabase(const QString& filename){
|
|
|
|
if (!QFile::exists(filename)){
|
|
|
|
QMessageBox::critical(this,tr("Error")
|
|
|
|
,tr("The database file does not exist."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
config->setLastFile(filename);
|
|
|
|
currentFile = filename;
|
|
|
|
setLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KeepassMainWindow::closeDatabase(bool lock){
|
|
|
|
Q_ASSERT(FileOpen);
|
|
|
|
Q_ASSERT(db!=NULL);
|
|
|
|
if(ModFlag){
|
|
|
|
if(config->autoSave()){
|
|
|
|
if(!OnFileSave()) return false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
QMessageBox::StandardButton r=QMessageBox::question(this,tr("Save modified file?"),
|
|
|
|
tr("The current file was modified. Do you want\nto save the changes?"),
|
|
|
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes);
|
|
|
|
if(r==QMessageBox::Cancel) return false; //Cancel
|
|
|
|
if(r==QMessageBox::Yes) //Yes (Save file)
|
|
|
|
if(!OnFileSave()) return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db->close();
|
|
|
|
delete db;
|
|
|
|
db=NULL;
|
|
|
|
EntryView->db=NULL;
|
|
|
|
EntryView->clear();
|
|
|
|
EntryView->Items.clear();
|
|
|
|
GroupView->db=NULL;
|
|
|
|
GroupView->clear();
|
|
|
|
GroupView->Items.clear();
|
|
|
|
SearchResults.clear();
|
|
|
|
if (lock)
|
|
|
|
IsLocked = true;
|
|
|
|
setStateFileOpen(false);
|
|
|
|
if (!lock){
|
|
|
|
setWindowTitle(APP_DISPLAY_NAME);
|
|
|
|
currentFile.clear();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KeepassMainWindow::OnFileNewKdb(){
|
|
|
|
IDatabase* db_new=dynamic_cast<IDatabase*>(new Kdb3Database());
|
|
|
|
db_new->create();
|
|
|
|
PasswordDialog dlg(this,PasswordDialog::Mode_Set,PasswordDialog::Flag_None,"New Database");
|
|
|
|
if(dlg.exec()==PasswordDialog::Exit_Ok){
|
|
|
|
if(FileOpen)
|
|
|
|
if(!closeDatabase())return;
|
|
|
|
if (IsLocked)
|
|
|
|
resetLock();
|
|
|
|
db=db_new;
|
|
|
|
db->setKey(dlg.password(),dlg.keyFile());
|
|
|
|
setWindowTitle(QString("[%1][*] - KeePassX").arg(tr("new")));
|
|
|
|
GroupView->db=db;
|
|
|
|
EntryView->db=db;
|
|
|
|
GroupView->createItems();
|
|
|
|
EntryView->showGroup(NULL);
|
|
|
|
setStateFileOpen(true);
|
|
|
|
setStateFileModified(true);
|
|
|
|
FileOpen=true;
|
|
|
|
setupDatabaseConnections(db);
|
|
|
|
setStateGroupSelected(NONE);
|
|
|
|
setStateEntrySelected(NONE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
delete db_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Kxdb
|
|
|
|
/*
|
|
|
|
void KeepassMainWindow::OnFileNewKxdb(){
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
void KeepassMainWindow::OnFileOpen(){
|
|
|
|
/*QFileDialog FileDlg(this,tr("Open Database..."),QDir::homePath());
|
|
|
|
FileDlg.setFilters(QStringList()<< tr("KeePass Databases (*.kdb)")<< tr("All Files (*)"));
|
|
|
|
FileDlg.setFileMode(QFileDialog::ExistingFile);
|
|
|
|
FileDlg.setAcceptMode(QFileDialog::AcceptOpen);
|
|
|
|
if(!FileDlg.exec())return;
|
|
|
|
if(!FileDlg.selectedFiles().size())return;*/
|
|
|
|
QString filename=KpxFileDialogs::openExistingFile(this,"MainWindow_FileOpen",
|
|
|
|
tr("Open Database..."),QStringList()<<tr("KeePass Databases (*.kdb)")<< tr("All Files (*)"));
|
|
|
|
if(filename.isEmpty())return;
|
|
|
|
if(FileOpen)
|
|
|
|
if(!closeDatabase())return;
|
|
|
|
openDatabase(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::OnFileClose(){
|
|
|
|
if (IsLocked)
|
|
|
|
OnLockClose();
|
|
|
|
else
|
|
|
|
closeDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setStateFileOpen(bool IsOpen){
|
|
|
|
FileOpen=IsOpen;
|
|
|
|
FileSaveAction->setEnabled(IsOpen);
|
|
|
|
FileSaveAsAction->setEnabled(IsOpen);
|
|
|
|
FileCloseAction->setEnabled(IsOpen||IsLocked);
|
|
|
|
FileSettingsAction->setEnabled(IsOpen);
|
|
|
|
FileChangeKeyAction->setEnabled(IsOpen);
|
|
|
|
EditSearchAction->setEnabled(IsOpen);
|
|
|
|
GroupView->setEnabled(IsOpen);
|
|
|
|
EntryView->setEnabled(IsOpen);
|
|
|
|
DetailView->setEnabled(IsOpen);
|
|
|
|
QuickSearchEdit->setEnabled(IsOpen);
|
|
|
|
ExtrasShowExpiredEntriesAction->setEnabled(IsOpen);
|
|
|
|
AddThisAsBookmarkAction->setEnabled(IsOpen);
|
|
|
|
FileUnLockWorkspaceAction->setEnabled(IsOpen||IsLocked);
|
|
|
|
|
|
|
|
if(!IsOpen){
|
|
|
|
EditNewGroupAction->setEnabled(false);
|
|
|
|
EditEditGroupAction->setEnabled(false);
|
|
|
|
EditDeleteGroupAction->setEnabled(false);
|
|
|
|
EditPasswordToClipboardAction->setEnabled(false);
|
|
|
|
EditUsernameToClipboardAction->setEnabled(false);
|
|
|
|
EditOpenUrlAction->setEnabled(false);
|
|
|
|
EditSaveAttachmentAction->setEnabled(false);
|
|
|
|
EditNewEntryAction->setEnabled(false);
|
|
|
|
EditEditEntryAction->setEnabled(false);
|
|
|
|
EditCloneEntryAction->setEnabled(false);
|
|
|
|
EditDeleteEntryAction->setEnabled(false);
|
|
|
|
EditGroupSearchAction->setEnabled(false);
|
|
|
|
#ifdef AUTOTYPE
|
|
|
|
EditAutoTypeAction->setEnabled(false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*else{
|
|
|
|
OnGroupSelectionChanged();
|
|
|
|
OnEntrySelectionChanged();
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KeepassMainWindow::setStateFileModified(bool mod){
|
|
|
|
if(!FileOpen){
|
|
|
|
FileSaveAction->setIcon(getIcon("filesave"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ModFlag=mod;
|
|
|
|
if(mod)
|
|
|
|
FileSaveAction->setIcon(getIcon("filesave"));
|
|
|
|
else
|
|
|
|
FileSaveAction->setIcon(getIcon("filesavedisabled"));
|
|
|
|
setWindowModified(mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeepassMainWindow::setStateGroupSelected(SelectionState s){
|
|
|
|
GroupSelection=s;
|
|
|
|
switch(GroupSelection){
|
|
|
|
case NONE:
|
|
|
|
EditNewGroupAction->setEnabled(true);
|
|
|
|
EditEditGroupAction->setEnabled(false);
|
|
|
|
EditDeleteGroupAction->setEnabled(false);
|
|
|
|
EditGroupSearchAction->setEnabled(false);
|
|
|
|
EditNewEntryAction->setEnabled(false);
|
|
|
|
break;
|
|
|
|
case SINGLE:
|
|
|
|
EditNewGroupAction->setEnabled(true);
|
|
|
|
EditEditGroupAction->setEnabled(true);
|
|
|
|
EditDeleteGroupAction->setEnabled(true);
|
|
|
|
EditGroupSearchAction->setEnabled(true);
|
|
|
|
EditNewEntryAction->setEnabled(true);
|
|
|
|
break;
|
|
|
|
case SEARCHGROUP:
|
|