From 2bf3e5820cbec3438f601d9be2fae35ad3e7537e Mon Sep 17 00:00:00 2001 From: tariq Date: Wed, 22 Mar 2006 14:15:28 +0000 Subject: [PATCH] fixed seg. fault when moving an entry to another group git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@63 b624d157-de02-0410-bad0-e51aec6abb33 --- src/dialogs/PasswordDlg.cpp | 2 +- src/main.cpp | 4 +- src/mainwindow.cpp | 144 +++++++++++++++++++----------------- src/mainwindow.h | 6 +- 4 files changed, 84 insertions(+), 72 deletions(-) diff --git a/src/dialogs/PasswordDlg.cpp b/src/dialogs/PasswordDlg.cpp index 9127ab8..28cec64 100755 --- a/src/dialogs/PasswordDlg.cpp +++ b/src/dialogs/PasswordDlg.cpp @@ -47,7 +47,7 @@ if(media.exists()){ } Combo_Dirs->setEditText(QString()); -if(config.RememberLastKey){ +if(config.RememberLastKey && !ChangeKeyMode){ switch(config.LastKeyType){ //case PASSWORD: setStatePasswordOnly(); break; //Password-Only is already the default case KEYFILE: setStateKeyFileOnly(); diff --git a/src/main.cpp b/src/main.cpp index 1c65073..b0fa778 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,7 +76,7 @@ QString ArgFile,ArgCfg,IniFilename; parseCmdLineArgs(argc,argv,ArgFile,ArgCfg); AppDir=app->applicationDirPath(); //Load Config -if(ArgCfg==""){ +if(ArgCfg==QString()){ if(!QDir(QDir::homeDirPath()+"/.keepass").exists()){ QDir conf(QDir::homeDirPath()); if(!conf.mkdir(".keepass")){ @@ -128,7 +128,7 @@ TrActive=TrFound; loadImages(); SecString::generateSessionKey(); int r=0; -KeepassMainWindow *mainWin = new KeepassMainWindow(); +KeepassMainWindow *mainWin = new KeepassMainWindow(ArgFile); if(mainWin->Start){ mainWin->show(); r=app->exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5cc97b2..9edc338 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -57,7 +57,7 @@ -KeepassMainWindow::KeepassMainWindow(QWidget *parent, Qt::WFlags flags):QMainWindow(parent,flags){ +KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,QWidget *parent, Qt::WFlags flags):QMainWindow(parent,flags){ Start=true; setupUi(this); setGeometry(geometry().x(),geometry().y(),config.MainWinWidth,config.MainWinHeight); @@ -76,75 +76,79 @@ KeepassMainWindow::KeepassMainWindow(QWidget *parent, Qt::WFlags flags):QMainWin setupConnections(); FileOpen=false; Clipboard=QApplication::clipboard(); - if(config.OpenLast && (config.LastFile!=QString()) ){ - QFileInfo file(config.LastFile); - if(file.exists()) - openDatabase(config.LastFile,true); - else - config.LastFile=QString(); - } + if(ArgFile!=QString()) + openDatabase(ArgFile,false); + else if(config.OpenLast && (config.LastFile!=QString()) ){ + QFileInfo file(config.LastFile); + if(file.exists()) + openDatabase(config.LastFile,true); + else + config.LastFile=QString(); + } } void KeepassMainWindow::setupConnections(){ - connect(FileNewAction, SIGNAL(triggered()), this, SLOT(OnFileNew())); - 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(FileImpPwmAction, SIGNAL(triggered()), this, SLOT(OnImportFromPwm())); - connect(FileImpKWalletXmlAction, SIGNAL(triggered()), this,SLOT(OnImportFromKWalletXml())); - connect(FileExpPlainTextAction,SIGNAL(triggered()),this,SLOT(OnExportToTxt())); - - connect(EditNewGroupAction, SIGNAL(triggered()), this, SLOT(OnEditNewGroup())); - connect(EditEditGroupAction, SIGNAL(triggered()), this, SLOT(OnEditEditGroup())); - connect(EditDeleteGroupAction, SIGNAL(triggered()), this, SLOT(OnEditDeleteGroup())); - connect(EditNewEntryAction, SIGNAL(triggered()), this, SLOT(OnEditNewEntry())); - connect(EditEditEntryAction, SIGNAL(triggered()), this, SLOT(OnEditEditEntry())); - connect(EditCloneEntryAction, SIGNAL(triggered()), this, SLOT(OnEditCloneEntry())); - connect(EditDeleteEntryAction, SIGNAL(triggered()), this, SLOT(OnEditDeleteEntry())); - connect(EditUsernameToClipboardAction, SIGNAL(triggered()), this, SLOT(OnEditUsernameToClipboard())); - connect(EditPasswordToClipboardAction, SIGNAL(triggered()), this, SLOT(OnEditPasswordToClipboard())); - connect(EditOpenUrlAction, SIGNAL(triggered()), this, SLOT(OnEditOpenUrl())); - connect(EditSaveAttachmentAction, SIGNAL(triggered()), this, SLOT(OnEditSaveAttachment())); - connect(EditSearchAction, SIGNAL(triggered()), this, SLOT(OnEditSearch())); - connect(EditGroupSearchAction, SIGNAL(triggered()), this, SLOT(OnEditGroupSearch())); - - 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(ViewColumnsTitleAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsUsernameAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsUrlAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsPasswordAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsCommentAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsExpireAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsCreationAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsLastChangeAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsLastAccessAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewColumnsAttachmentAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); - connect(ViewShowStatusbarAction,SIGNAL(toggled(bool)),statusBar(),SLOT(setVisible(bool))); - - connect(ExtrasSettingsAction,SIGNAL(triggered(bool)),this,SLOT(OnExtrasSettings())); - - connect(HelpAboutAction,SIGNAL(triggered()),this,SLOT(OnHelpAbout())); - - connect(GroupView,SIGNAL(entryDropped()),EntryView,SLOT(updateItems())); - connect(&ClipboardTimer, SIGNAL(timeout()), this, SLOT(OnClipboardTimeOut())); - connect(GroupView,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, - SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*))); - connect(GroupView,SIGNAL(itemExpanded(QTreeWidgetItem*)),this,SLOT(OnItemExpanded(QTreeWidgetItem*))); - connect(GroupView,SIGNAL(itemCollapsed(QTreeWidgetItem*)),this,SLOT(OnItemCollaped(QTreeWidgetItem*))); - connect(EntryView,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this, - SLOT(OnEntryItemDoubleClicked(QTreeWidgetItem*,int))); - connect(EntryView,SIGNAL(itemSelectionChanged()), this, SLOT(OnEntrySelectionChanged())); - connect(GroupView,SIGNAL(itemSelectionChanged()), this, SLOT(OnGroupSelectionChanged())); - connect(GroupView,SIGNAL(fileModified()),this,SLOT(OnFileModified())); - connect(QuickSearchEdit,SIGNAL(returnPressed()), this, SLOT(OnQuickSearch())); - connect(HideSearchResultsAction,SIGNAL(triggered()),this, SLOT(OnHideSearchGroup())); + connect(FileNewAction, SIGNAL(triggered()), this, SLOT(OnFileNew())); + 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(FileImpPwmAction, SIGNAL(triggered()), this, SLOT(OnImportFromPwm())); + connect(FileImpKWalletXmlAction, SIGNAL(triggered()), this,SLOT(OnImportFromKWalletXml())); + connect(FileExpPlainTextAction,SIGNAL(triggered()),this,SLOT(OnExportToTxt())); + + connect(EditNewGroupAction, SIGNAL(triggered()), this, SLOT(OnEditNewGroup())); + connect(EditEditGroupAction, SIGNAL(triggered()), this, SLOT(OnEditEditGroup())); + connect(EditDeleteGroupAction, SIGNAL(triggered()), this, SLOT(OnEditDeleteGroup())); + connect(EditNewEntryAction, SIGNAL(triggered()), this, SLOT(OnEditNewEntry())); + connect(EditEditEntryAction, SIGNAL(triggered()), this, SLOT(OnEditEditEntry())); + connect(EditCloneEntryAction, SIGNAL(triggered()), this, SLOT(OnEditCloneEntry())); + connect(EditDeleteEntryAction, SIGNAL(triggered()), this, SLOT(OnEditDeleteEntry())); + connect(EditUsernameToClipboardAction, SIGNAL(triggered()), this, SLOT(OnEditUsernameToClipboard())); + connect(EditPasswordToClipboardAction, SIGNAL(triggered()), this, SLOT(OnEditPasswordToClipboard())); + connect(EditOpenUrlAction, SIGNAL(triggered()), this, SLOT(OnEditOpenUrl())); + connect(EditSaveAttachmentAction, SIGNAL(triggered()), this, SLOT(OnEditSaveAttachment())); + connect(EditSearchAction, SIGNAL(triggered()), this, SLOT(OnEditSearch())); + connect(EditGroupSearchAction, SIGNAL(triggered()), this, SLOT(OnEditGroupSearch())); + + 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(ViewColumnsTitleAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsUsernameAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsUrlAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsPasswordAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsCommentAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsExpireAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsCreationAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsLastChangeAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsLastAccessAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewColumnsAttachmentAction,SIGNAL(toggled(bool)), this, SLOT(OnColumnVisibilityChanged(bool))); + connect(ViewShowStatusbarAction,SIGNAL(toggled(bool)),statusBar(),SLOT(setVisible(bool))); + + connect(ExtrasSettingsAction,SIGNAL(triggered(bool)),this,SLOT(OnExtrasSettings())); + + connect(HelpHandbookAction,SIGNAL(triggered()),this,SLOT(OnHelpHandbook())); + connect(HelpAboutAction,SIGNAL(triggered()),this,SLOT(OnHelpAbout())); + + connect(GroupView,SIGNAL(entryDropped()),EntryView,SLOT(updateItems())); + connect(this,SIGNAL(entryChanged()),EntryView,SLOT(updateItems()),Qt::QueuedConnection); + connect(&ClipboardTimer, SIGNAL(timeout()), this, SLOT(OnClipboardTimeOut())); + connect(GroupView,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, + SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + connect(GroupView,SIGNAL(itemExpanded(QTreeWidgetItem*)),this,SLOT(OnItemExpanded(QTreeWidgetItem*))); + connect(GroupView,SIGNAL(itemCollapsed(QTreeWidgetItem*)),this,SLOT(OnItemCollaped(QTreeWidgetItem*))); + connect(EntryView,SIGNAL(itemActivated(QTreeWidgetItem*,int)),this, + SLOT(OnEntryItemDoubleClicked(QTreeWidgetItem*,int))); + connect(EntryView,SIGNAL(itemSelectionChanged()), this, SLOT(OnEntrySelectionChanged())); + connect(GroupView,SIGNAL(itemSelectionChanged()), this, SLOT(OnGroupSelectionChanged())); + connect(GroupView,SIGNAL(fileModified()),this,SLOT(OnFileModified())); + connect(QuickSearchEdit,SIGNAL(returnPressed()), this, SLOT(OnQuickSearch())); + connect(HideSearchResultsAction,SIGNAL(triggered()),this, SLOT(OnHideSearchGroup())); } @@ -410,7 +414,7 @@ switch(dlg.exec()){ setStateFileModified(true); break; case 2: //entry moved to another group - EntryView->updateItems(currentGroup()->ID); + emit entryChanged(); //a direct call of updateItems() would cause a SegFault because of the TreeView base class slots setStateFileModified(true); break; } @@ -977,6 +981,10 @@ CAboutDialog dlg(this,"AboutDlg"); dlg.exec(); } +void KeepassMainWindow::OnHelpHandbook(){ +openBrowser(AppDir+"/../share/doc/keepass/index.html"); +} + void KeepassMainWindow::OnViewShowToolbar(bool show){ config.Toolbar=show; toolBar->setVisible(config.Toolbar); diff --git a/src/mainwindow.h b/src/mainwindow.h index 4b41880..80515aa 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -48,10 +48,13 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{ Q_OBJECT public: - KeepassMainWindow (QWidget *parent=0, Qt::WFlags flags=0); + KeepassMainWindow (const QString& ArgFile,QWidget *parent=0, Qt::WFlags flags=0); PwDatabase* db; bool Start; +signals: + void entryChanged(); + private slots: void OnFileNew(); void OnFileOpen(); @@ -90,6 +93,7 @@ private slots: void OnFileModified(); void OnExtrasSettings(); void OnHelpAbout(); + void OnHelpHandbook(); void OnItemExpanded(QTreeWidgetItem*); void OnItemCollaped(QTreeWidgetItem*); void OnHideSearchGroup();