changed metastream format for custom icons

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@68 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 18 years ago
parent baac763ff0
commit 2dddd37814
  1. 1
      src/Database.h
  2. 60
      src/PwManager.cpp
  3. 1
      src/PwManager.h
  4. 2
      src/dialogs/EditEntryDlg.cpp
  5. 2
      src/dialogs/EditGroupDlg.cpp
  6. 31
      src/dialogs/SelectIconDlg.cpp
  7. 5
      src/dialogs/SelectIconDlg.h
  8. 42
      src/forms/EditGroupDlg.ui
  9. 4
      src/forms/SelectIconDlg.ui

@ -119,6 +119,7 @@ public:
virtual QPixmap& icon(int index)=0;
virtual int numIcons()=0;
virtual void addIcon(const QPixmap& icon)=0;
virtual void removeIcon(int Id)=0;
Q_UINT32 CryptoAlgorithmus;
Q_UINT32 KeyEncRounds;

@ -252,10 +252,11 @@ return false; //unknown MetaStreams
}
bool PwDatabase::parseCustomIconsMetaStream(const QByteArray& dta){
Q_UINT32 NumIcons,NumEntries,offset;
Q_UINT32 NumIcons,NumEntries,NumGroups,offset;
memcpyFromLEnd32(&NumIcons,dta.data());
memcpyFromLEnd32(&NumEntries,dta.data()+4);
offset=8;
memcpyFromLEnd32(&NumGroups,dta.data()+8);
offset=12;
CustomIcons.clear();
for(int i=0;i<NumIcons;i++){
CustomIcons << QPixmap();
@ -281,6 +282,14 @@ for(int i=0;i<NumEntries;i++){
offset+=4;
Entries[Entry].ImageID=Icon;
}
for(int i=0;i<NumGroups;i++){
Q_UINT32 Group,Icon;
memcpyFromLEnd32(&Group,dta.data()+offset);
offset+=4;
memcpyFromLEnd32(&Icon,dta.data()+offset);
offset+=4;
Groups[Group].ImageID=Icon;
}
return true;
}
@ -291,18 +300,18 @@ e->UserName="SYSTEM";
e->Additional="KPX_CUSTOM_ICONS";
e->URL="$";
e->ImageID=0;
int Size=8;
Q_UINT32 NumEntries=0;
for(int i=0;i<Entries.size();i++){
if(Entries[i].ImageID >= BUILTIN_ICONS){ Size+=8; NumEntries++;}
}
int Size=12;
Q_UINT32 NumEntries=Entries.size();
Q_UINT32 NumGroups=Groups.size();
Size+=8*(NumEntries+NumGroups);
Size+=CustomIcons.size()*1000; // 1KB
e->BinaryData.reserve(Size);
e->BinaryData.resize(8);
e->BinaryData.resize(12);
Q_UINT32 NumIcons=CustomIcons.size();
memcpyToLEnd32(e->BinaryData.data(),&NumIcons);
memcpyToLEnd32(e->BinaryData.data()+4,&NumEntries);
memcpyToLEnd32(e->BinaryData.data()+8,&NumGroups);
for(int i=0;i<CustomIcons.size();i++){
Q_UINT32 ImgSize;
char ImgSizeBin[4];
@ -316,16 +325,19 @@ for(int i=0;i<CustomIcons.size();i++){
e->BinaryData.append(png);
}
for(Q_UINT32 i=0;i<Entries.size();i++){
if(Entries[i].ImageID >= BUILTIN_ICONS){
char Bin[8];
memcpyToLEnd32(Bin,&i);
Q_UINT32 id=Entries[i].ImageID-BUILTIN_ICONS;
Q_UINT32 id=Entries[i].ImageID;
memcpyToLEnd32(Bin+4,&id);
e->BinaryData.append(QByteArray::fromRawData(Bin,8));
}
for(Q_UINT32 i=0;i<Groups.size();i++){
char Bin[8];
memcpyToLEnd32(Bin,&i);
Q_UINT32 id=Groups[i].ImageID;
memcpyToLEnd32(Bin+4,&id);
e->BinaryData.append(QByteArray::fromRawData(Bin,8));
}
}
}
@ -346,6 +358,24 @@ CustomIcons << icon;
emit modified();
}
void PwDatabase::removeIcon(int id){
id-=BUILTIN_ICONS;
if(id < 0 ) return;
if(id >= CustomIcons.size()) return;
CustomIcons.removeAt(id); // .isNull()==true
for(int i=0;i<Entries.size();i++){
if(Entries[i].ImageID == id+BUILTIN_ICONS)
Entries[i].ImageID=0;
if(Entries[i].ImageID>id+BUILTIN_ICONS)
Entries[i].ImageID--;
}
for(int i=0;i<Groups.size();i++){
if(Groups[i].ImageID == id+BUILTIN_ICONS)
Groups[i].ImageID=0;
if(Groups[i].ImageID>id+BUILTIN_ICONS)
Groups[i].ImageID--;
}
}
void PwDatabase::transformKey(Q_UINT8* src,Q_UINT8* dst,Q_UINT8* KeySeed,int rounds){
Q_UINT8* tmp=new Q_UINT8[32];
@ -818,7 +848,9 @@ for(int i=0; i < Groups.size(); i++){
FieldType = 0x0007; FieldSize = 4;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
memcpyToLEnd32(buffer+pos, &Groups[i].ImageID); pos += 4;
Q_UINT32 ImgID=Groups[i].ImageID;
if(ImgID>=BUILTIN_ICONS)ImgID=0;
memcpyToLEnd32(buffer+pos, &ImgID); pos += 4;
FieldType = 0x0008; FieldSize = 2;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;

@ -83,6 +83,7 @@ public:
QPixmap& icon(int index);
int numIcons();
void addIcon(const QPixmap& icon);
void removeIcon(int Id);
QList<CGroup>Groups;
QList<CEntry>Entries;

@ -146,7 +146,7 @@ int i;
for(i=0;i!=db->numGroups();i++){
tmp="";
for(int j=0;j<db->group(i).Level;j++)tmp+=" ";
Combo_Group->insertItem(EntryIcons[db->group(i).ImageID],
Combo_Group->insertItem(db->icon(db->group(i).ImageID),
tmp+db->group(i).Name,i);
}
Combo_Group->setCurrentItem(db->getGroupIndex(entry->GroupID));

@ -66,7 +66,7 @@ done(0);
void CEditGroupDialog::OnIconDlg(){
CSelectIconDlg dlg(db,this);
CSelectIconDlg dlg(db,IconID,this);
int r=dlg.exec();
if(r!=-1){
ComboIconPicker->clear();

@ -28,16 +28,19 @@
CSelectIconDlg::CSelectIconDlg(Database* database,QWidget* parent,const char* name, bool modal, Qt::WFlags fl):QDialog(parent,name,modal,fl){
CSelectIconDlg::CSelectIconDlg(Database* database,int CurrentID,QWidget* parent,const char* name, bool modal, Qt::WFlags fl):QDialog(parent,name,modal,fl){
setupUi(this);
db=database;
connect(Button_AddIcon, SIGNAL(clicked()), this, SLOT(OnAddIcon()));
connect(Button_PickIcon, SIGNAL(clicked()), this, SLOT(OnPickIcon()));
connect(Button_Cancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
CtxMenu=new QMenu(this);
DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete"));
CustomIconsModified=false;
connect(Button_AddIcon, SIGNAL(clicked()), this, SLOT(OnAddIcon()));
connect(Button_PickIcon, SIGNAL(clicked()), this, SLOT(OnPickIcon()));
connect(Button_Cancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
connect(DeleteAction,SIGNAL(triggered()),this,SLOT(OnDelete()));
connect(List,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this,SLOT(OnSelectionChanged(QListWidgetItem*,QListWidgetItem*)));
updateView();
List->setCurrentItem(List->item(CurrentID));
}
void CSelectIconDlg::updateView(){
@ -47,14 +50,16 @@ for(int i=0; i<db->numIcons(); i++){
if(i<BUILTIN_ICONS)
List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),QString::number(i)));
else
List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),"["+QString::number(i)+"]"));
if(!db->icon(i).isNull())
List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),"["+QString::number(i)+"]"));
item->setData(32,i);
}
}
void CSelectIconDlg::OnAddIcon(){
QStringList filenames=QFileDialog::getOpenFileNames(this,tr("Add Icons..."),QDir::homePath());
QStringList filenames=QFileDialog::getOpenFileNames(this,tr("Add Icons..."),QDir::homePath(),tr("Images (%1)")
.arg("*.png *.jpeg *.jpg *.bmp *.gif *.bpm *.pgm *.ppm *.xbm *xpm"));
QStringList errors;
for(int i=0;i<filenames.size();i++){
QPixmap icon;
@ -67,6 +72,7 @@ if(errors.size())
QMessageBox::warning(this,tr("Error"),tr("An error occured while loading the icon(s):\n"));
CustomIconsModified=true;
updateView();
List->setCurrentItem(List->item(List->count()-1));
}
void CSelectIconDlg::contextMenuEvent(QContextMenuEvent *event){
@ -82,10 +88,23 @@ event->accept();
CtxMenu->popup(event->globalPos());
}
void CSelectIconDlg::OnDelete(){
db->removeIcon(List->currentItem()->data(32).toInt());
updateView();
}
void CSelectIconDlg::OnPickIcon(){
done(List->currentItem()->data(32).toInt());
}
void CSelectIconDlg::OnCancel(){
done(-1);
}
void CSelectIconDlg::OnSelectionChanged(QListWidgetItem* cur,QListWidgetItem* prev){
Button_PickIcon->setEnabled(cur);
}

@ -31,14 +31,15 @@
class CSelectIconDlg:public QDialog, public Ui_SelectIconDlg{
Q_OBJECT
public:
CSelectIconDlg(Database* db,QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WFlags fl = 0);
CSelectIconDlg(Database* db,int,QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WFlags fl = 0);
bool CustomIconsModified;
public slots:
void OnAddIcon();
void OnPickIcon();
void OnCancel();
void OnDelete();
void OnSelectionChanged(QListWidgetItem*,QListWidgetItem*);
private:
Database* db;

@ -63,30 +63,36 @@
<string>Icon:</string>
</property>
</widget>
<widget class="QComboBox" name="ComboIconPicker" >
<widget class="QPushButton" name="ButtonCancel" >
<property name="geometry" >
<rect>
<x>70</x>
<y>40</y>
<width>50</width>
<height>21</height>
<x>227</x>
<y>77</y>
<width>70</width>
<height>24</height>
</rect>
</property>
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="shortcut" >
<string>Alt+C</string>
</property>
</widget>
<widget class="QPushButton" name="ButtonCancel" >
<widget class="QPushButton" name="ButtonOK" >
<property name="geometry" >
<rect>
<x>227</x>
<x>147</x>
<y>77</y>
<width>70</width>
<height>24</height>
</rect>
</property>
<property name="text" >
<string>&amp;Cancel</string>
<string>O&amp;K</string>
</property>
<property name="shortcut" >
<string>Alt+C</string>
<string>Alt+K</string>
</property>
</widget>
<widget class="Line" name="line1" >
@ -108,21 +114,15 @@
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QPushButton" name="ButtonOK" >
<widget class="QComboBox" name="ComboIconPicker" >
<property name="geometry" >
<rect>
<x>147</x>
<y>77</y>
<width>70</width>
<height>24</height>
<x>70</x>
<y>40</y>
<width>50</width>
<height>21</height>
</rect>
</property>
<property name="text" >
<string>O&amp;K</string>
</property>
<property name="shortcut" >
<string>Alt+K</string>
</property>
</widget>
<widget class="QPushButton" name="Button_Icon" >
<property name="geometry" >
@ -130,7 +130,7 @@
<x>123</x>
<y>39</y>
<width>21</width>
<height>24</height>
<height>23</height>
</rect>
</property>
<property name="text" >

@ -21,7 +21,7 @@
</sizepolicy>
</property>
<property name="windowTitle" >
<string>Dialog</string>
<string>Icon Selection</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
@ -90,7 +90,7 @@
<bool>true</bool>
</property>
<property name="resizeMode" >
<enum>QListView::Adjust</enum>
<enum>QListView::Fixed</enum>
</property>
<property name="gridSize" >
<size>