Introduce new icon metastream to store custom icon id independent from the number of built-in icons

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@211 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 17 years ago
parent f91a09dabb
commit d34b93f62d
  1. 147
      src/Kdb3Database.cpp
  2. 3
      src/Kdb3Database.h
  3. 2
      src/lib/EntryView.cpp

@ -95,17 +95,22 @@ bool Kdb3Database::parseMetaStream(const StdEntry& entry){
parseGroupTreeStateMetaStream(entry.Binary); parseGroupTreeStateMetaStream(entry.Binary);
return true; return true;
} }
else if(entry.Comment=="KPX_CUSTOM_ICONS_4"){
if(entry.Comment=="KPX_CUSTOM_ICONS_3"){
parseCustomIconsMetaStream(entry.Binary); parseCustomIconsMetaStream(entry.Binary);
return true; return true;
} }
else if(entry.Comment=="KPX_CUSTOM_ICONS_3"){
if(entry.Comment=="KPX_CUSTOM_ICONS_2") parseCustomIconsMetaStreamV3(entry.Binary);
return parseCustomIconsMetaStreamV2(entry.Binary); return true;
}
if(entry.Comment=="KPX_CUSTOM_ICONS") else if(entry.Comment=="KPX_CUSTOM_ICONS_2"){
return parseCustomIconsMetaStreamV1(entry.Binary); qDebug("Removed old CuIcMeSt v2");
return true;
}
else if(entry.Comment=="KPX_CUSTOM_ICONS"){
qDebug("Removed old CuIcMeSt v1");
return true;
}
return false; //unknown MetaStream return false; //unknown MetaStream
} }
@ -121,20 +126,65 @@ bool Kdb3Database::isMetaStream(StdEntry& p){
return true; return true;
} }
void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){
bool Kdb3Database::parseCustomIconsMetaStreamV1(const QByteArray& dta){ //Rev 4 (KeePassX 0.3.2)
Q_UNUSED(dta) quint32 NumIcons,NumEntries,NumGroups,offset;
qDebug("Removed old CuIcMeSt v1"); memcpyFromLEnd32(&NumIcons,dta.data());
return true; memcpyFromLEnd32(&NumEntries,dta.data()+4);
} memcpyFromLEnd32(&NumGroups,dta.data()+8);
offset=12;
bool Kdb3Database::parseCustomIconsMetaStreamV2(const QByteArray& dta){ CustomIcons.clear();
Q_UNUSED(dta) for(int i=0;i<NumIcons;i++){
qDebug("Removed old CuIcMeSt v2"); CustomIcons << QPixmap();
return true; quint32 Size;
memcpyFromLEnd32(&Size,dta.data()+offset);
if(offset+Size > dta.size()){
CustomIcons.clear();
qWarning("Discarded metastream KPX_CUSTOM_ICONS_4 because of a parsing error.");
return;
}
offset+=4;
if(!CustomIcons.back().loadFromData((const unsigned char*)dta.data()+offset,Size,"PNG")){
CustomIcons.clear();
qWarning("Discarded metastream KPX_CUSTOM_ICONS_4 because of a parsing error.");
return;
}
offset+=Size;
if(offset > dta.size()){
CustomIcons.clear();
qWarning("Discarded metastream KPX_CUSTOM_ICONS_4 because of a parsing error.");
return;
}
}
for(int i=0;i<NumEntries;i++){
quint32 Icon;
KpxUuid EntryUuid;
EntryUuid.fromRaw(dta.data()+offset);
offset+=16;
memcpyFromLEnd32(&Icon,dta.data()+offset);
offset+=4;
StdEntry* entry=getEntry(EntryUuid);
if(entry){
entry->OldImage=entry->Image;
entry->Image=Icon+BUILTIN_ICONS;
}
}
for(int i=0;i<NumGroups;i++){
quint32 GroupId,Icon;
memcpyFromLEnd32(&GroupId,dta.data()+offset);
offset+=4;
memcpyFromLEnd32(&Icon,dta.data()+offset);
offset+=4;
StdGroup* Group=getGroup(GroupId);
if(Group){
Group->OldImage=Group->Image;
Group->Image=Icon+BUILTIN_ICONS;
}
}
return;
} }
void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){ void Kdb3Database::parseCustomIconsMetaStreamV3(const QByteArray& dta){
//Rev 3 //Rev 3
quint32 NumIcons,NumEntries,NumGroups,offset; quint32 NumIcons,NumEntries,NumGroups,offset;
memcpyFromLEnd32(&NumIcons,dta.data()); memcpyFromLEnd32(&NumIcons,dta.data());
@ -149,17 +199,20 @@ void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){
if(offset+Size > dta.size()){ if(offset+Size > dta.size()){
CustomIcons.clear(); CustomIcons.clear();
qWarning("Discarded metastream KPX_CUSTOM_ICONS_3 because of a parsing error."); qWarning("Discarded metastream KPX_CUSTOM_ICONS_3 because of a parsing error.");
return;} return;
}
offset+=4; offset+=4;
if(!CustomIcons.back().loadFromData((const unsigned char*)dta.data()+offset,Size,"PNG")){ if(!CustomIcons.back().loadFromData((const unsigned char*)dta.data()+offset,Size,"PNG")){
CustomIcons.clear(); CustomIcons.clear();
qWarning("Discarded metastream KPX_CUSTOM_ICONS_3 because of a parsing error."); qWarning("Discarded metastream KPX_CUSTOM_ICONS_3 because of a parsing error.");
return;} return;
}
offset+=Size; offset+=Size;
if(offset > dta.size()){ if(offset > dta.size()){
CustomIcons.clear(); CustomIcons.clear();
qWarning("Discarded metastream KPX_CUSTOM_ICONS_3 because of a parsing error."); qWarning("Discarded metastream KPX_CUSTOM_ICONS_3 because of a parsing error.");
return;} return;
}
} }
for(int i=0;i<NumEntries;i++){ for(int i=0;i<NumEntries;i++){
quint32 Icon; quint32 Icon;
@ -171,7 +224,10 @@ void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){
StdEntry* entry=getEntry(EntryUuid); StdEntry* entry=getEntry(EntryUuid);
if(entry){ if(entry){
entry->OldImage=entry->Image; entry->OldImage=entry->Image;
entry->Image=Icon; if (Icon>=65)
entry->Image=Icon+4; // Since v0.3.2 the BUILTIN_ICONS number has increased by 4
else
entry->Image=Icon;
} }
} }
for(int i=0;i<NumGroups;i++){ for(int i=0;i<NumGroups;i++){
@ -184,6 +240,10 @@ void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){
if(Group){ if(Group){
Group->OldImage=Group->Image; Group->OldImage=Group->Image;
Group->Image=Icon; Group->Image=Icon;
if (Group->Image>=65)
Group->Image=Icon+4; // Since v0.3.2 the BUILTIN_ICONS number has increased by 4
else
Group->Image=Icon;
} }
} }
return; return;
@ -1305,13 +1365,21 @@ void Kdb3Database::createCustomIconsMetaStream(StdEntry* e){
e->BinaryDesc="bin-stream"; e->BinaryDesc="bin-stream";
e->Title="Meta-Info"; e->Title="Meta-Info";
e->Username="SYSTEM"; e->Username="SYSTEM";
e->Comment="KPX_CUSTOM_ICONS_3"; e->Comment="KPX_CUSTOM_ICONS_4";
e->Url="$"; e->Url="$";
e->OldImage=0; e->OldImage=0;
if(Groups.size())e->GroupId=Groups[0].Id; if(Groups.size())e->GroupId=Groups[0].Id;
int Size=12; int Size=12;
quint32 NumEntries=Entries.size(); quint32 NumEntries=0;
quint32 NumGroups=Groups.size(); for(quint32 i=0;i<Entries.size();i++){
if (Entries[i].Image>=BUILTIN_ICONS)
NumEntries++;
}
quint32 NumGroups=0;
for(quint32 i=0;i<Groups.size();i++){
if (Groups[i].Image>=BUILTIN_ICONS)
NumGroups++;
}
Size+=8*NumGroups+20*NumEntries; Size+=8*NumGroups+20*NumEntries;
Size+=CustomIcons.size()*1000; // 1KB Size+=CustomIcons.size()*1000; // 1KB
e->Binary.reserve(Size); e->Binary.reserve(Size);
@ -1333,19 +1401,24 @@ void Kdb3Database::createCustomIconsMetaStream(StdEntry* e){
e->Binary.append(QByteArray::fromRawData(ImgSizeBin,4)); e->Binary.append(QByteArray::fromRawData(ImgSizeBin,4));
e->Binary.append(png); e->Binary.append(png);
} }
for(quint32 i=0;i<Entries.size();i++){ for(quint32 i=0;i<Entries.size();i++){
char Bin[20]; if (Entries[i].Image>=BUILTIN_ICONS){
Entries[i].Uuid.toRaw(Bin); char Bin[20];
quint32 id=Entries[i].Image; Entries[i].Uuid.toRaw(Bin);
memcpyToLEnd32(Bin+16,&id); quint32 id=Entries[i].Image-BUILTIN_ICONS;
e->Binary.append(QByteArray::fromRawData(Bin,20)); memcpyToLEnd32(Bin+16,&id);
e->Binary.append(QByteArray::fromRawData(Bin,20));
}
} }
for(quint32 i=0;i<Groups.size();i++){ for(quint32 i=0;i<Groups.size();i++){
char Bin[8]; if (Groups[i].Image>=BUILTIN_ICONS){
memcpyToLEnd32(Bin,&Groups[i].Id); char Bin[8];
quint32 id=Groups[i].Image; memcpyToLEnd32(Bin,&Groups[i].Id);
memcpyToLEnd32(Bin+4,&id); quint32 id=Groups[i].Image-BUILTIN_ICONS;
e->Binary.append(QByteArray::fromRawData(Bin,8)); memcpyToLEnd32(Bin+4,&id);
e->Binary.append(QByteArray::fromRawData(Bin,8));
}
} }
} }

@ -203,8 +203,7 @@ private:
bool isMetaStream(StdEntry& Entry); bool isMetaStream(StdEntry& Entry);
bool parseMetaStream(const StdEntry& Entry); bool parseMetaStream(const StdEntry& Entry);
void parseCustomIconsMetaStream(const QByteArray& data); void parseCustomIconsMetaStream(const QByteArray& data);
bool parseCustomIconsMetaStreamV1(const QByteArray& data); void parseCustomIconsMetaStreamV3(const QByteArray& data);
bool parseCustomIconsMetaStreamV2(const QByteArray& data);
void parseGroupTreeStateMetaStream(const QByteArray& data); void parseGroupTreeStateMetaStream(const QByteArray& data);
void createCustomIconsMetaStream(StdEntry* e); void createCustomIconsMetaStream(StdEntry* e);
void createGroupTreeStateMetaStream(StdEntry* e); void createGroupTreeStateMetaStream(StdEntry* e);

@ -236,6 +236,8 @@ void KeepassEntryView::OnNewEntry(){
Items.back()->EntryHandle=NewEntry; Items.back()->EntryHandle=NewEntry;
updateEntry(Items.back()); updateEntry(Items.back());
emit fileModified(); emit fileModified();
if (header()->isSortIndicatorShown())
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
} }
} }