Add Entry (qt4)

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@24 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent aeeba6a916
commit aa615d2ed6
  1. 2
      src/Database.cpp
  2. 9
      src/PwManager.cpp
  3. 1
      src/PwManager.h
  4. 3
      src/lib/EntryView.cpp
  5. 2
      src/lib/GroupView.cpp
  6. 20
      src/mainwindow.cpp
  7. 2
      src/mainwindow.h

@ -27,7 +27,7 @@ GroupID=0;
Creation=QDateTime::currentDateTime(); Creation=QDateTime::currentDateTime();
LastMod=QDateTime::currentDateTime(); LastMod=QDateTime::currentDateTime();
LastAccess=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; BinaryDataLength=0;
pBinaryData=NULL; pBinaryData=NULL;
} }

@ -309,6 +309,12 @@ return true;
} }
void PwDatabase::addEntry(CEntry* NewEntry){
CEntry *entry=addEntry();
*entry=*NewEntry;
}
CEntry* PwDatabase::addEntry(){ CEntry* PwDatabase::addEntry(){
CEntry NewEntry; CEntry NewEntry;
if(Entries.size()==0){ if(Entries.size()==0){
@ -316,7 +322,7 @@ if(Entries.size()==0){
getRandomBytes(&NewEntry.ID,16,1,false); getRandomBytes(&NewEntry.ID,16,1,false);
} }
else { else {
NewEntry.sID=(*(Entries.end()-1)).sID+1; NewEntry.sID=Entries.back().sID+1;
while(1){ while(1){
bool used=false; bool used=false;
getRandomBytes(&NewEntry.ID,16,1,false); getRandomBytes(&NewEntry.ID,16,1,false);
@ -846,7 +852,6 @@ for(i=GroupIndex+1; i<Groups.size(); i++){
if(Groups[i].Level<=group->Level)break; if(Groups[i].Level<=group->Level)break;
} }
NumChilds=i-GroupIndex-1; NumChilds=i-GroupIndex-1;
qDebug("NUMCHILDS=%i\n",NumChilds);
//delete entries //delete entries
for(i=GroupIndex; i<=GroupIndex+NumChilds; i++){ for(i=GroupIndex; i<=GroupIndex+NumChilds; i++){
for(int j=0; j<Entries.size();){ for(int j=0; j<Entries.size();){

@ -66,6 +66,7 @@ public:
void deleteEntry(CEntry* pEntry); void deleteEntry(CEntry* pEntry);
void moveEntry(CEntry* pEntry,CGroup* pDstGroup); void moveEntry(CEntry* pEntry,CGroup* pDstGroup);
CEntry* addEntry(); CEntry* addEntry();
void addEntry(CEntry* NewEntry);
void merge(PwDatabase* db2); void merge(PwDatabase* db2);
bool isParentGroup(CGroup* Group,CGroup* PotenialParent); bool isParentGroup(CGroup* Group,CGroup* PotenialParent);
QString getError(); //get first error QString getError(); //get first error

@ -36,6 +36,7 @@ header()->setResizeMode(QHeaderView::Stretch);
void KeepassEntryView::updateItems(){ void KeepassEntryView::updateItems(){
clear(); clear();
Items.clear();
if(!db)return; if(!db)return;
EntryViewItem *tmp=NULL; EntryViewItem *tmp=NULL;
for(int i=0;i<db->Entries.size();i++){ for(int i=0;i<db->Entries.size();i++){
@ -72,9 +73,11 @@ for(int i=0;i<db->Entries.size();i++){
tmp->setText(j++,entry->BinaryDesc);} tmp->setText(j++,entry->BinaryDesc);}
Items.back()->setIcon(0,EntryIcons[entry->ImageID]); Items.back()->setIcon(0,EntryIcons[entry->ImageID]);
} }
setCurrentGroup(CurrentGroup);
} }
void KeepassEntryView::setCurrentGroup(uint id){ void KeepassEntryView::setCurrentGroup(uint id){
CurrentGroup=id;
for(int i=0; i<Items.size();i++){ for(int i=0; i<Items.size();i++){
setItemHidden(Items[i],(Items[i]->pEntry->GroupID != id)); setItemHidden(Items[i],(Items[i]->pEntry->GroupID != id));

@ -164,8 +164,6 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
drag->setMimeData(mimeData); drag->setMimeData(mimeData);
drag->setPixmap(DragPixmap); drag->setPixmap(DragPixmap);
drag->start(); drag->start();
} }
void KeepassGroupView::updateItems(){ void KeepassGroupView::updateItems(){

@ -82,6 +82,7 @@ void KeepassMainWindow::setupConnections(){
connect(EditNewGroupAction, SIGNAL(triggered()), this, SLOT(OnEditNewGroup())); connect(EditNewGroupAction, SIGNAL(triggered()), this, SLOT(OnEditNewGroup()));
connect(EditEditGroupAction, SIGNAL(triggered()), this, SLOT(OnEditEditGroup())); connect(EditEditGroupAction, SIGNAL(triggered()), this, SLOT(OnEditEditGroup()));
connect(EditDeleteGroupAction, SIGNAL(triggered()), this, SLOT(OnEditDeleteGroup())); connect(EditDeleteGroupAction, SIGNAL(triggered()), this, SLOT(OnEditDeleteGroup()));
connect(EditNewEntryAction, SIGNAL(triggered()), this, SLOT(OnEditNewEntry()));
connect(GroupView,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, connect(GroupView,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this,
SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*))); SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
@ -265,7 +266,7 @@ default: Q_ASSERT(false);
} }
void KeepassMainWindow::setStateEntrySelected(SelectionState s){ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EntrySelection=NONE; EntrySelection=s;
switch(EntrySelection){ switch(EntrySelection){
case NONE: case NONE:
EditPasswordToClipboardAction->setEnabled(false); EditPasswordToClipboardAction->setEnabled(false);
@ -414,3 +415,20 @@ db->deleteGroup(pGroup);
GroupView->updateItems(); GroupView->updateItems();
setStateFileModified(true); 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<GroupViewItem*>(GroupView->selectedItems()[0])->pGroup;
}

@ -64,6 +64,7 @@ private slots:
void OnEditNewGroup(); void OnEditNewGroup();
void OnEditEditGroup(); void OnEditEditGroup();
void OnEditDeleteGroup(); void OnEditDeleteGroup();
void OnEditNewEntry();
void OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*); void OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*);
void OnEntryItemDoubleClicked(QTreeWidgetItem* item,int column); void OnEntryItemDoubleClicked(QTreeWidgetItem* item,int column);
void OnEntrySelectionChanged(); void OnEntrySelectionChanged();
@ -84,6 +85,7 @@ private:
void openDatabase(QString filename); void openDatabase(QString filename);
bool closeDatabase(); bool closeDatabase();
void editEntry(CEntry* pEntry); void editEntry(CEntry* pEntry);
inline CGroup* currentGroup();