fixed d'n'd drawing errors in group view (dirty work-around),

implemented correct UUIDs for entries

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@97 b624d157-de02-0410-bad0-e51aec6abb33
master
tarek_saidi 19 years ago
parent 9b6f3c8fce
commit c980d277f2
  1. 3
      changelog
  2. 9
      src/Database.cpp
  3. 13
      src/Database.h
  4. 40
      src/PwManager.cpp
  5. 12
      src/lib/GroupView.cpp
  6. 8
      src/main.cpp

@ -4,6 +4,9 @@
-fixed crash when parsing config file under Win32 -fixed crash when parsing config file under Win32
-fixed loss of entry icons when saving a database which was not created -fixed loss of entry icons when saving a database which was not created
with KeePassX (no KPX_CUSTOM_ICONS metastream) with KeePassX (no KPX_CUSTOM_ICONS metastream)
-removed all old Qt3 support dependecies
-implemented correct UUID management for entries
-fixed drawing errors when performing drag and drop operations in group view
-when there is no translation installed for the system's country preference but -when there is no translation installed for the system's country preference but
one for the same language the program will now use it one for the same language the program will now use it
-when canceling the file dialog for the opening of an existing database a already -when canceling the file dialog for the opening of an existing database a already

@ -22,9 +22,12 @@
#include "lib/random.h" #include "lib/random.h"
KpxUuid::KpxUuid(){ KpxUuid::KpxUuid(){
generate(); Data.fill(0,16);
} }
KpxUuid::KpxUuid(const void* src){
fromRaw(src);
}
void KpxUuid::generate(){ void KpxUuid::generate(){
char uuid[16]; char uuid[16];
@ -54,11 +57,11 @@ QString KpxUuid::toString()const{
.arg(hex.mid(20,12)); .arg(hex.mid(20,12));
} }
void KpxUuid::toRaw(void* dst){ void KpxUuid::toRaw(void* dst)const{
memcpy(dst,Data.data(),16); memcpy(dst,Data.data(),16);
} }
void KpxUuid::fromRaw(void* src){ void KpxUuid::fromRaw(const void* src){
Data=QByteArray((char*)src,16); Data=QByteArray((char*)src,16);
} }

@ -33,15 +33,16 @@ extern const QDateTime Date_Never;
class KpxUuid{ class KpxUuid{
public: public:
KpxUuid(); KpxUuid();
bool operator==(const KpxUuid&) const; KpxUuid(const void* src);
bool operator!=(const KpxUuid&) const; void generate();
QString toString() const; QString toString() const;
const unsigned char* data()const const unsigned char* data()const
{return (const unsigned char*) Data.data();} {return (const unsigned char*) Data.data();}
void toRaw(void* dst); void toRaw(void* dst)const;
void fromRaw(void* src); void fromRaw(const void* src);
bool operator==(const KpxUuid&) const;
bool operator!=(const KpxUuid&) const;
private: private:
void generate();
QByteArray Data; QByteArray Data;
}; };
@ -59,7 +60,7 @@ class CEntry{
public: public:
CEntry(); CEntry();
~CEntry(); ~CEntry();
quint8 ID[16]; KpxUuid Uuid;
quint32 sID; quint32 sID;
quint32 GroupID; quint32 GroupID;
quint32 ImageID; quint32 ImageID;

@ -484,19 +484,12 @@ return true;
CEntry* PwDatabase::addEntry(CEntry* NewEntry){ CEntry* PwDatabase::addEntry(CEntry* NewEntry){
if(Entries.size()==0){ if(Entries.size()==0){
NewEntry->sID=0; NewEntry->sID=0;
getRandomBytes(&NewEntry->ID,16,1,false); NewEntry->Uuid.generate();
} }
else{ else{
NewEntry->sID=Entries.back().sID+1; NewEntry->sID=Entries.back().sID+1;
while(1){ NewEntry->Uuid.generate();
bool used=false; }
getRandomBytes(&NewEntry->ID,16,1,false);
for(int j=0;j<Entries.size();j++){
int k;
for(k=0;k<16;k++){if(Entries[j].ID[k]!=NewEntry->ID[k])k=0;break;}
if(k==15)used=true;}
if(used==false)break;
}}
Entries.push_back(*NewEntry); Entries.push_back(*NewEntry);
return &Entries.back(); return &Entries.back();
} }
@ -506,19 +499,12 @@ CEntry* PwDatabase::addEntry(){
CEntry NewEntry; CEntry NewEntry;
if(Entries.size()==0){ if(Entries.size()==0){
NewEntry.sID=0; NewEntry.sID=0;
getRandomBytes(&NewEntry.ID,16,1,false); NewEntry.Uuid.generate();
} }
else{ else{
NewEntry.Uuid.generate();
NewEntry.sID=Entries.back().sID+1; NewEntry.sID=Entries.back().sID+1;
while(1){ }
bool used=false;
getRandomBytes(&NewEntry.ID,16,1,false);
for(int j=0;j<Entries.size();j++){
int k;
for(k=0;k<16;k++){if(Entries[j].ID[k]!=NewEntry.ID[k])k=0;break;}
if(k==15)used=true;}
if(used==false)break;
}}
Entries.push_back(NewEntry); Entries.push_back(NewEntry);
return &Entries.back(); return &Entries.back();
} }
@ -612,12 +598,10 @@ entry->GroupID=dst->ID;
CEntry* PwDatabase::cloneEntry(CEntry* entry){ CEntry* PwDatabase::cloneEntry(CEntry* entry){
CEntry *Dolly=addEntry(); CEntry *Dolly=addEntry();
quint8 ID[16];
quint32 sid=Dolly->sID; quint32 sid=Dolly->sID;
memcpy(ID,Dolly->ID,16);
*Dolly=*entry; *Dolly=*entry;
Dolly->sID=sid; Dolly->sID=sid;
memcpy(Dolly->ID,ID,16); Dolly->Uuid.generate();
return Dolly; return Dolly;
} }
@ -685,7 +669,7 @@ switch(FieldType)
// Ignore field // Ignore field
break; break;
case 0x0001: case 0x0001:
memcpy(ID, pData, 16); Uuid=KpxUuid(pData);
break; break;
case 0x0002: case 0x0002:
memcpyFromLEnd32(&GroupID, (char*)pData); memcpyFromLEnd32(&GroupID, (char*)pData);
@ -894,7 +878,7 @@ for(int i = 0; i < Entries.size(); i++){
FieldType = 0x0001; FieldSize = 16; FieldType = 0x0001; FieldSize = 16;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2; memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4; memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
memcpy(buffer+pos, &Entries[i].ID, 16); pos += 16; Entries[i].Uuid.toRaw(buffer+pos); pos += 16;
FieldType = 0x0002; FieldSize = 4; FieldType = 0x0002; FieldSize = 4;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2; memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
@ -982,7 +966,7 @@ for(int i = 0; i < MetaStreams.size(); i++){
FieldType = 0x0001; FieldSize = 16; FieldType = 0x0001; FieldSize = 16;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2; memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4; memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
memcpy(buffer+pos, &MetaStreams[i]->ID, 16); pos += 16; MetaStreams[i]->Uuid.toRaw(buffer+pos); pos += 16;
FieldType = 0x0002; FieldSize = 4; FieldType = 0x0002; FieldSize = 4;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2; memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
@ -1528,8 +1512,8 @@ void assertGroupsEq(KPTestResults& results, CGroup* left, CGroup* right){
void assertEntriesEq(KPTestResults& results, CEntry* left, CEntry* right){ void assertEntriesEq(KPTestResults& results, CEntry* left, CEntry* right){
unsigned long size = 0; unsigned long size = 0;
kp_assert(results, memcmp(left->ID, right->ID, sizeof(left->ID)) == 0); kp_assert(results, left->Uuid==right->Uuid);
size += sizeof(left->ID); size += sizeof(left->Uuid);
kp_assert(results, left->sID == right->sID); kp_assert(results, left->sID == right->sID);
size += sizeof(left->sID); size += sizeof(left->sID);

@ -74,6 +74,7 @@ if(LastHoverItem){
LastHoverItem->setFont(0,f); LastHoverItem->setFont(0,f);
} }
QLine LastMarker=InsertionMarker;
InsertionMarker=QLine(); InsertionMarker=QLine();
if(isSearchResultGroup(item)) if(isSearchResultGroup(item))
event->setAccepted(false); event->setAccepted(false);
@ -117,7 +118,15 @@ else{
LastHoverItem=NULL; LastHoverItem=NULL;
} }
} }
if(!LastMarker.isNull()){
///@FIXME
//this is a very dirty work-around to force a redraw of items at the last marker position
//should be replaced!!!
GroupViewItem* i=(GroupViewItem*)itemAt(0,LastMarker.y1());
if(i)i->setFont(0,i->font(0));
i=(GroupViewItem*)itemAt(0,LastMarker.y1()-1);
if(i)i->setFont(0,i->font(0));
}
update(); update();
} }
@ -268,6 +277,7 @@ QPen pen(QColor(100,100,100));
pen.setWidth(2); pen.setWidth(2);
pen.setStyle(Qt::DotLine); pen.setStyle(Qt::DotLine);
painter.setPen(pen); painter.setPen(pen);
qDebug("UPDATE: (%i,%i) %ix%i",event->rect().x(),event->rect().y(),event->rect().width(),event->rect().height());
if(!InsertionMarker.isNull()){ if(!InsertionMarker.isNull()){
painter.drawLine(InsertionMarker); painter.drawLine(InsertionMarker);
} }

@ -35,7 +35,6 @@
#include "PwmConfig.h" #include "PwmConfig.h"
#include "PwManager.h" #include "PwManager.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "Database.h"
using namespace std; using namespace std;
#ifdef Q_WS_X11 #ifdef Q_WS_X11
@ -83,13 +82,6 @@ bool loadTranslation(QTranslator* tr,const QString& prefix,const QString& Locale
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
for(int i=0;i<100;i++){
KpxUuid id;
cout << (const char*)id.toString().toAscii() << endl;
}
QApplication* app=new QApplication(argc,argv); QApplication* app=new QApplication(argc,argv);
QString ArgFile,ArgCfg,ArgLang,IniFilename; QString ArgFile,ArgCfg,ArgLang,IniFilename;
parseCmdLineArgs(argc,argv,ArgFile,ArgCfg,ArgLang); parseCmdLineArgs(argc,argv,ArgFile,ArgCfg,ArgLang);