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 19 years ago
parent baac763ff0
commit 2dddd37814
  1. 1
      src/Database.h
  2. 58
      src/PwManager.cpp
  3. 1
      src/PwManager.h
  4. 2
      src/dialogs/EditEntryDlg.cpp
  5. 2
      src/dialogs/EditGroupDlg.cpp
  6. 29
      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 QPixmap& icon(int index)=0;
virtual int numIcons()=0; virtual int numIcons()=0;
virtual void addIcon(const QPixmap& icon)=0; virtual void addIcon(const QPixmap& icon)=0;
virtual void removeIcon(int Id)=0;
Q_UINT32 CryptoAlgorithmus; Q_UINT32 CryptoAlgorithmus;
Q_UINT32 KeyEncRounds; Q_UINT32 KeyEncRounds;

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

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

@ -146,7 +146,7 @@ int i;
for(i=0;i!=db->numGroups();i++){ for(i=0;i!=db->numGroups();i++){
tmp=""; tmp="";
for(int j=0;j<db->group(i).Level;j++)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); tmp+db->group(i).Name,i);
} }
Combo_Group->setCurrentItem(db->getGroupIndex(entry->GroupID)); Combo_Group->setCurrentItem(db->getGroupIndex(entry->GroupID));

@ -66,7 +66,7 @@ done(0);
void CEditGroupDialog::OnIconDlg(){ void CEditGroupDialog::OnIconDlg(){
CSelectIconDlg dlg(db,this); CSelectIconDlg dlg(db,IconID,this);
int r=dlg.exec(); int r=dlg.exec();
if(r!=-1){ if(r!=-1){
ComboIconPicker->clear(); 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); setupUi(this);
db=database; 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); CtxMenu=new QMenu(this);
DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete")); DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete"));
CustomIconsModified=false; 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(); updateView();
List->setCurrentItem(List->item(CurrentID));
} }
void CSelectIconDlg::updateView(){ void CSelectIconDlg::updateView(){
@ -47,6 +50,7 @@ for(int i=0; i<db->numIcons(); i++){
if(i<BUILTIN_ICONS) if(i<BUILTIN_ICONS)
List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),QString::number(i))); List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),QString::number(i)));
else else
if(!db->icon(i).isNull())
List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),"["+QString::number(i)+"]")); List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),"["+QString::number(i)+"]"));
item->setData(32,i); item->setData(32,i);
} }
@ -54,7 +58,8 @@ for(int i=0; i<db->numIcons(); i++){
void CSelectIconDlg::OnAddIcon(){ 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; QStringList errors;
for(int i=0;i<filenames.size();i++){ for(int i=0;i<filenames.size();i++){
QPixmap icon; QPixmap icon;
@ -67,6 +72,7 @@ if(errors.size())
QMessageBox::warning(this,tr("Error"),tr("An error occured while loading the icon(s):\n")); QMessageBox::warning(this,tr("Error"),tr("An error occured while loading the icon(s):\n"));
CustomIconsModified=true; CustomIconsModified=true;
updateView(); updateView();
List->setCurrentItem(List->item(List->count()-1));
} }
void CSelectIconDlg::contextMenuEvent(QContextMenuEvent *event){ void CSelectIconDlg::contextMenuEvent(QContextMenuEvent *event){
@ -82,6 +88,11 @@ event->accept();
CtxMenu->popup(event->globalPos()); CtxMenu->popup(event->globalPos());
} }
void CSelectIconDlg::OnDelete(){
db->removeIcon(List->currentItem()->data(32).toInt());
updateView();
}
void CSelectIconDlg::OnPickIcon(){ void CSelectIconDlg::OnPickIcon(){
done(List->currentItem()->data(32).toInt()); done(List->currentItem()->data(32).toInt());
} }
@ -89,3 +100,11 @@ done(List->currentItem()->data(32).toInt());
void CSelectIconDlg::OnCancel(){ void CSelectIconDlg::OnCancel(){
done(-1); done(-1);
} }
void CSelectIconDlg::OnSelectionChanged(QListWidgetItem* cur,QListWidgetItem* prev){
Button_PickIcon->setEnabled(cur);
}

@ -31,14 +31,15 @@
class CSelectIconDlg:public QDialog, public Ui_SelectIconDlg{ class CSelectIconDlg:public QDialog, public Ui_SelectIconDlg{
Q_OBJECT Q_OBJECT
public: 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; bool CustomIconsModified;
public slots: public slots:
void OnAddIcon(); void OnAddIcon();
void OnPickIcon(); void OnPickIcon();
void OnCancel(); void OnCancel();
void OnDelete();
void OnSelectionChanged(QListWidgetItem*,QListWidgetItem*);
private: private:
Database* db; Database* db;

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

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