showing 'group' column only when search results are shown,

added KWalletImport.

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@128 b624d157-de02-0410-bad0-e51aec6abb33
master
tarek_saidi 18 years ago
parent 6cae658d24
commit 2b54ded391
  1. 77
      src/import/Import_KWalletXml.cpp
  2. 14
      src/import/Import_KWalletXml.h
  3. 32
      src/lib/EntryView.cpp
  4. 3
      src/lib/EntryView.h
  5. 1
      src/main.cpp
  6. 2
      src/mainwindow.cpp

@ -21,59 +21,50 @@
#include "Import_KWalletXml.h" #include "Import_KWalletXml.h"
#include <QFile> #include <QFile>
#include <QtXml> #include <QtXml>
#include <QMessageBox>
/*
bool Import_KWalletXml::importFile(QString FileName,StandardDatabase* pwm,QString& err){ bool Import_KWalletXml::importDatabase(QWidget* GuiParent, IDatabase* db){
QFile file(FileName); QFile* file=openFile(GuiParent,identifier(),QStringList()<<tr("XML Files (*.xml)")<<tr("All Files (*)"));
if(!file.exists()){ if(!file)return false;
err+=QObject::tr("File not found."); int len=file->size();
return false;} quint8* buffer=new quint8[len];
if(!file.open(QIODevice::ReadOnly)){ file->read((char*)buffer,len);
err+=QObject::tr("Could not open file."); file->close();
return false;} delete file;
int len=file.size(); QDomDocument doc;
if(len==0){ QString xmlerr;
err+=QObject::tr("File is empty."); int col,line;
return false;} if(!doc.setContent(QString::fromUtf8((char*)buffer,len),false,&xmlerr,&line,&col)){
quint8* buffer=new quint8[len];
file.read((char*)buffer,len);
file.close();
QDomDocument doc;
QString xmlerr;
int col,line;
if(!doc.setContent(QString::fromUtf8((char*)buffer,len),false,&xmlerr,&line,&col)){
qWarning("Import_PwManager::parseXmlContent():\n"); qWarning("Import_PwManager::parseXmlContent():\n");
qWarning(((xmlerr+" (Line:%1 Column:%2)").arg(line).arg(col)+QString('\n')).toAscii()); qWarning(((xmlerr+" (Line:%1 Column:%2)").arg(line).arg(col)+QString('\n')).toAscii());
err+=QObject::tr("Invalid XML file (see stdout for details)."); QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML data (see stdout for details)."));
delete [] buffer; delete [] buffer;
return false;} return false;}
delete [] buffer; delete [] buffer;
QDomElement root=doc.documentElement(); QDomElement root=doc.documentElement();
if(root.tagName()!="wallet"){err+=QObject::tr("Invalid XML file."); return false;} if(root.tagName()!="wallet"){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
QDomNodeList groups=root.elementsByTagName("folder"); QDomNodeList groups=root.elementsByTagName("folder");
if(!groups.length()){err+=QObject::tr("Document does not contain data."); return false;} if(!groups.length()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Document does not contain data.")); return false;}
for(int i=0;i<groups.length();i++){ for(int i=0;i<groups.length();i++){
if(!groups.item(i).isElement()){err+=QObject::tr("Invalid XML file."); return false;} if(!groups.item(i).isElement()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
QDomElement CurrGroup=groups.item(i).toElement(); QDomElement CurrGroup=groups.item(i).toElement();
if(!CurrGroup.hasAttribute("name")){err+=QObject::tr("Invalid XML file."); return false;} if(!CurrGroup.hasAttribute("name")){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
IGroupHandle* NewGroup=pwm->addGroup(NULL); CGroup NewGroup;
NewGroup->Name=CurrGroup.attribute("name"); NewGroup.Title=CurrGroup.attribute("name");
IGroupHandle* NewGroupHandle=db->addGroup(&NewGroup,NULL);
QDomNodeList entries=CurrGroup.elementsByTagName("password"); QDomNodeList entries=CurrGroup.elementsByTagName("password");
for(int j=0;j<entries.length();j++){ for(int j=0;j<entries.length();j++){
if(!entries.item(j).isElement()){err+=QObject::tr("Invalid XML file."); return false;} if(!entries.item(j).isElement()){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
QDomElement CurrEntry=entries.item(j).toElement(); QDomElement CurrEntry=entries.item(j).toElement();
if(!CurrEntry.hasAttribute("name")){err+=QObject::tr("Invalid XML file."); return false;} if(!CurrEntry.hasAttribute("name")){QMessageBox::critical(GuiParent,tr("Import Failed"),tr("Invalid XML file.")); return false;}
IEntryHandle* NewEntry=pwm->addEntry(); IEntryHandle* NewEntry=db->newEntry(NewGroupHandle);
NewEntry->Title=CurrEntry.attribute("name"); NewEntry->setTitle(CurrEntry.attribute("name"));
NewEntry->GroupID=NewGroup->ID;
QString pw=CurrEntry.text(); QString pw=CurrEntry.text();
NewEntry->Password.setString(pw,true); SecString pws;
pws.setString(pw,true);
NewEntry->setPassword(pws);
}
} }
return true;
} }
pwm->file=NULL;
pwm->SearchGroupID=-1;
pwm->CryptoAlgorithmus=ALGO_AES;
pwm->KeyEncRounds=6000;
return true;
}*/

@ -20,14 +20,14 @@
#ifndef _IMPORT_KWALLET_H_ #ifndef _IMPORT_KWALLET_H_
#define _IMPORT_KWALLET_H_ #define _IMPORT_KWALLET_H_
#include <qstring.h> #include "Database.h"
#include "StandardDatabase.h" #include "Import.h"
class Import_KWalletXml{
public:
bool importFile(QString FileName,StandardDatabase* db,QString& err);
private:
class Import_KWalletXml:public IImport, public ImporterBase{
public:
virtual bool importDatabase(QWidget* GuiParent, IDatabase* Database);
virtual QString identifier(){return "KWalletXml";}
virtual QString title(){return "KWallet XML File (*.xml)";}
}; };
#endif #endif

@ -224,7 +224,7 @@ void KeepassEntryView::updateEntry(EntryViewItem* item){
item->setText(j++,entry->lastAccess().dateToString(Qt::LocalDate));} item->setText(j++,entry->lastAccess().dateToString(Qt::LocalDate));}
if(Columns[9]){ if(Columns[9]){
item->setText(j++,entry->binaryDesc());} item->setText(j++,entry->binaryDesc());}
if(Columns[10]){ if(Columns[10] && ViewMode==ShowSearchResults){
item->setText(j,entry->group()->title()); item->setText(j,entry->group()->title());
item->setIcon(j++,db->icon(entry->group()->image()));} item->setIcon(j++,db->icon(entry->group()->image()));}
} }
@ -339,7 +339,11 @@ void KeepassEntryView::resizeEvent(QResizeEvent* e){
void KeepassEntryView::showSearchResults(){ void KeepassEntryView::showSearchResults(){
if(ViewMode==Normal){
ViewMode=ShowSearchResults; ViewMode=ShowSearchResults;
if(Columns[10])ColumnOrder[10]--;
updateColumns();
}
clear(); clear();
Items.clear(); Items.clear();
createItems(SearchResults); createItems(SearchResults);
@ -347,7 +351,10 @@ void KeepassEntryView::showSearchResults(){
void KeepassEntryView::showGroup(IGroupHandle* group){ void KeepassEntryView::showGroup(IGroupHandle* group){
if(ViewMode==ShowSearchResults){
ViewMode=Normal; ViewMode=Normal;
updateColumns();
}
clear(); clear();
Items.clear(); Items.clear();
if(group==NULL)return; if(group==NULL)return;
@ -393,7 +400,7 @@ void KeepassEntryView::createItems(QList<IEntryHandle*>& entries){
item->setText(j++,entries[i]->lastAccess().dateToString(Qt::LocalDate));} item->setText(j++,entries[i]->lastAccess().dateToString(Qt::LocalDate));}
if(Columns[9]){ if(Columns[9]){
item->setText(j++,entries[i]->binaryDesc());} item->setText(j++,entries[i]->binaryDesc());}
if(Columns[10]){ if(Columns[10] && ViewMode==ShowSearchResults){
item->setText(j,entries[i]->group()->title()); item->setText(j,entries[i]->group()->title());
item->setIcon(j++,db->icon(entries[i]->group()->image()));} item->setIcon(j++,db->icon(entries[i]->group()->image()));}
} }
@ -433,10 +440,14 @@ void KeepassEntryView::updateColumns(){
cols << tr("Last Access");} cols << tr("Last Access");}
if(Columns[9]){ if(Columns[9]){
cols << tr("Attachment");} cols << tr("Attachment");}
if(Columns[10]){ if(Columns[10] && ViewMode==ShowSearchResults){
cols << tr("Group");} cols << tr("Group");}
setHeaderLabels(cols); setHeaderLabels(cols);
for(int i=0;i<NUM_COLUMNS;i++){
if(!Columns[i])ColumnOrder[i]=100;
}
QMap<int,int> Order; QMap<int,int> Order;
for(int i=NUM_COLUMNS-1;i>=0;i--) for(int i=NUM_COLUMNS-1;i>=0;i--)
Order.insertMulti(ColumnOrder[i],i); Order.insertMulti(ColumnOrder[i],i);
@ -463,6 +474,7 @@ int KeepassEntryView::logicalColIndex(int LstIndex){
int c=-1; int c=-1;
for(int i=0;i<NUM_COLUMNS;i++){ for(int i=0;i<NUM_COLUMNS;i++){
if(Columns[i])c++; if(Columns[i])c++;
if(i==10 && Columns[10] && ViewMode!=ShowSearchResults)c--;
if(i==LstIndex)return c; if(i==LstIndex)return c;
} }
Q_ASSERT(false); Q_ASSERT(false);
@ -472,6 +484,13 @@ void KeepassEntryView::resizeColumns(){
AutoResizeColumns=false; AutoResizeColumns=false;
int w=viewport()->width(); int w=viewport()->width();
int sum=0; int sum=0;
for(int i=0;i<NUM_COLUMNS;i++){
// if(i==10) continue; //skip "Group" column
if(!Columns[i])ColumnSizes[i]=0;
if(Columns[i] && ColumnSizes[i]==0)ColumnSizes[i]=0.1f*(float)w;
}
for(int i=0;i<header()->count();i++){ for(int i=0;i<header()->count();i++){
sum+=ColumnSizes[columnListIndex(i)]; sum+=ColumnSizes[columnListIndex(i)];
} }
@ -484,7 +503,6 @@ void KeepassEntryView::resizeColumns(){
if(i==header()->count()-1){ if(i==header()->count()-1){
NewSize+=(w-sum); // add rounding difference to the last column NewSize+=(w-sum); // add rounding difference to the last column
} }
//qDebug("i=%i lstIndex=%i NewSize=%f",i,lstIndex,NewSize);
header()->resizeSection(header()->logicalIndex(i),NewSize); header()->resizeSection(header()->logicalIndex(i),NewSize);
ColumnSizes[lstIndex]=NewSize; ColumnSizes[lstIndex]=NewSize;
} }
@ -495,6 +513,7 @@ int KeepassEntryView::columnListIndex(int LogicalIndex){
int c=-1; int i=0; int c=-1; int i=0;
for(i;i<NUM_COLUMNS;i++){ for(i;i<NUM_COLUMNS;i++){
if(Columns[i])c++; if(Columns[i])c++;
if(i==10 && Columns[10] && ViewMode!=ShowSearchResults)c--;
if(c==LogicalIndex)break; if(c==LogicalIndex)break;
} }
return i; return i;
@ -597,8 +616,9 @@ EntryViewItem::EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding
bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{ bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{
int SortCol=treeWidget()->sortColumn(); int SortCol=treeWidget()->header()->sortIndicatorSection();
if(SortCol < 5 || SortCol==9 || SortCol==10){ //columns with string values (Title, Username, Password, URL, Comment, Group) int ListIndex=((KeepassEntryView*)treeWidget())->columnListIndex(SortCol);
if(ListIndex < 5 || ListIndex==9 || ListIndex==10){ //columns with string values (Title, Username, Password, URL, Comment, Group)
if(QString::localeAwareCompare(text(SortCol),other.text(SortCol)) < 0) if(QString::localeAwareCompare(text(SortCol),other.text(SortCol)) < 0)
return true; return true;
else else

@ -43,6 +43,7 @@ class KeepassEntryView:public QTreeWidget{
void showSearchResults(); void showSearchResults();
void showGroup(IGroupHandle* group); void showGroup(IGroupHandle* group);
void updateColumns(); void updateColumns();
int columnListIndex(int LogicalIndex);
IDatabase* db; IDatabase* db;
QList<EntryViewItem*>Items; QList<EntryViewItem*>Items;
QList<IEntryHandle*> SearchResults; QList<IEntryHandle*> SearchResults;
@ -53,7 +54,6 @@ class KeepassEntryView:public QTreeWidget{
void updateEntry(EntryViewItem*); void updateEntry(EntryViewItem*);
void editEntry(EntryViewItem*); void editEntry(EntryViewItem*);
void createItems(QList<IEntryHandle*>& entries); void createItems(QList<IEntryHandle*>& entries);
int columnListIndex(int LogicalIndex);
int logicalColIndex(int ListIndex); int logicalColIndex(int ListIndex);
QClipboard* Clipboard; QClipboard* Clipboard;
@ -68,6 +68,7 @@ class KeepassEntryView:public QTreeWidget{
EntryViewMode ViewMode; EntryViewMode ViewMode;
QVarLengthArray<float>ColumnSizes; QVarLengthArray<float>ColumnSizes;
QVarLengthArray<int>ColumnOrder; QVarLengthArray<int>ColumnOrder;
float GroupColumnSize;
virtual void contextMenuEvent(QContextMenuEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event);
virtual void paintEvent(QPaintEvent* event); virtual void paintEvent(QPaintEvent* event);

@ -307,7 +307,6 @@ void loadImages(){
bool small=true; bool small=true;
QString ThemeDir=AppDir+"/../share/keepass/icons/nuvola/32x32"; QString ThemeDir=AppDir+"/../share/keepass/icons/nuvola/32x32";
QPixmap tmpImg; QPixmap tmpImg;
//----------------------- //-----------------------

@ -66,6 +66,7 @@ QDBusConnection* dbusCon;
Import_KeePassX_Xml import_KeePassX_Xml; Import_KeePassX_Xml import_KeePassX_Xml;
Import_PwManager import_PwManager; Import_PwManager import_PwManager;
Import_KWalletXml import_KWalletXml;
Export_Txt export_Txt; Export_Txt export_Txt;
Export_KeePassX_Xml export_KeePassX_Xml; Export_KeePassX_Xml export_KeePassX_Xml;
@ -288,6 +289,7 @@ void KeepassMainWindow::setupMenus(){
_add_import(import_KeePassX_Xml) _add_import(import_KeePassX_Xml)
_add_import(import_PwManager) _add_import(import_PwManager)
_add_import(import_KWalletXml)
_add_export(export_Txt); _add_export(export_Txt);
_add_export(export_KeePassX_Xml); _add_export(export_KeePassX_Xml);