From aa615d2ed61372adf6a00d15f3452a766d1184c8 Mon Sep 17 00:00:00 2001 From: tariq Date: Wed, 25 Jan 2006 10:30:19 +0000 Subject: [PATCH] Add Entry (qt4) git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@24 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Database.cpp | 2 +- src/PwManager.cpp | 9 +++++++-- src/PwManager.h | 1 + src/lib/EntryView.cpp | 3 +++ src/lib/GroupView.cpp | 2 -- src/mainwindow.cpp | 24 +++++++++++++++++++++--- src/mainwindow.h | 2 ++ 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index 037b7df..345966a 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -27,7 +27,7 @@ GroupID=0; Creation=QDateTime::currentDateTime(); LastMod=QDateTime::currentDateTime(); LastAccess=QDateTime::currentDateTime(); -Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); +Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); //Never BinaryDataLength=0; pBinaryData=NULL; } diff --git a/src/PwManager.cpp b/src/PwManager.cpp index d600182..edc81cb 100755 --- a/src/PwManager.cpp +++ b/src/PwManager.cpp @@ -309,6 +309,12 @@ return true; } +void PwDatabase::addEntry(CEntry* NewEntry){ +CEntry *entry=addEntry(); +*entry=*NewEntry; +} + + CEntry* PwDatabase::addEntry(){ CEntry NewEntry; if(Entries.size()==0){ @@ -316,7 +322,7 @@ if(Entries.size()==0){ getRandomBytes(&NewEntry.ID,16,1,false); } else { - NewEntry.sID=(*(Entries.end()-1)).sID+1; + NewEntry.sID=Entries.back().sID+1; while(1){ bool used=false; getRandomBytes(&NewEntry.ID,16,1,false); @@ -846,7 +852,6 @@ for(i=GroupIndex+1; iLevel)break; } NumChilds=i-GroupIndex-1; -qDebug("NUMCHILDS=%i\n",NumChilds); //delete entries for(i=GroupIndex; i<=GroupIndex+NumChilds; i++){ for(int j=0; jsetResizeMode(QHeaderView::Stretch); void KeepassEntryView::updateItems(){ clear(); +Items.clear(); if(!db)return; EntryViewItem *tmp=NULL; for(int i=0;iEntries.size();i++){ @@ -72,9 +73,11 @@ for(int i=0;iEntries.size();i++){ tmp->setText(j++,entry->BinaryDesc);} Items.back()->setIcon(0,EntryIcons[entry->ImageID]); } +setCurrentGroup(CurrentGroup); } void KeepassEntryView::setCurrentGroup(uint id){ +CurrentGroup=id; for(int i=0; ipEntry->GroupID != id)); diff --git a/src/lib/GroupView.cpp b/src/lib/GroupView.cpp index 13531ff..1158d8a 100644 --- a/src/lib/GroupView.cpp +++ b/src/lib/GroupView.cpp @@ -164,8 +164,6 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){ drag->setMimeData(mimeData); drag->setPixmap(DragPixmap); drag->start(); - - } void KeepassGroupView::updateItems(){ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index db041a7..39e80d2 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -82,11 +82,12 @@ void KeepassMainWindow::setupConnections(){ 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(GroupView,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, - SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*))); connect(EntryView,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this, - SLOT(OnEntryItemDoubleClicked(QTreeWidgetItem*,int))); + SLOT(OnEntryItemDoubleClicked(QTreeWidgetItem*,int))); connect(EntryView,SIGNAL(itemSelectionChanged()), this, SLOT(OnEntrySelectionChanged())); connect(GroupView,SIGNAL(itemSelectionChanged()), this, SLOT(OnGroupSelectionChanged())); } @@ -265,7 +266,7 @@ default: Q_ASSERT(false); } void KeepassMainWindow::setStateEntrySelected(SelectionState s){ -EntrySelection=NONE; +EntrySelection=s; switch(EntrySelection){ case NONE: EditPasswordToClipboardAction->setEnabled(false); @@ -413,4 +414,21 @@ CGroup *pGroup=static_cast(GroupView->selectedItems()[0])->pGrou db->deleteGroup(pGroup); GroupView->updateItems(); setStateFileModified(true); +} + +void KeepassMainWindow::OnEditNewEntry(){ +CEntry NewEntry; +NewEntry.GroupID=currentGroup()->ID; +CEditEntryDlg dlg(db,&NewEntry,this,"EditEntryDialog",true); +if(dlg.exec()){ + db->addEntry(&NewEntry); + EntryView->updateItems(); + setStateFileModified(true); +} + +} + +CGroup* KeepassMainWindow::currentGroup(){ +Q_ASSERT(GroupView->selectedItems().size()); +return static_cast(GroupView->selectedItems()[0])->pGroup; } \ No newline at end of file diff --git a/src/mainwindow.h b/src/mainwindow.h index 2a4d4a8..90d4e91 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -64,6 +64,7 @@ private slots: void OnEditNewGroup(); void OnEditEditGroup(); void OnEditDeleteGroup(); + void OnEditNewEntry(); void OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*); void OnEntryItemDoubleClicked(QTreeWidgetItem* item,int column); void OnEntrySelectionChanged(); @@ -84,6 +85,7 @@ private: void openDatabase(QString filename); bool closeDatabase(); void editEntry(CEntry* pEntry); + inline CGroup* currentGroup();