nomsg
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@8 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
125
src/lib/EntryView.cpp
Normal file
125
src/lib/EntryView.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QDragLeaveEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QHeaderView>
|
||||
#include "main.h"
|
||||
#include "EntryView.h"
|
||||
|
||||
KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){
|
||||
CurrentGroup=0;
|
||||
updateColumns();
|
||||
header()->setResizeMode(QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
void KeepassEntryView::updateItems(){
|
||||
clear();
|
||||
if(!db)return;
|
||||
EntryViewItem *tmp=NULL;
|
||||
for(int i=0;i<db->Entries.size();i++){
|
||||
CEntry* entry=&db->Entries[i];
|
||||
Items.push_back(tmp=new EntryViewItem(this));
|
||||
Items.back()->pEntry=entry;
|
||||
int j=0;
|
||||
if(config.Columns[0]){
|
||||
tmp->setText(j++,entry->Title);}
|
||||
if(config.Columns[1]){
|
||||
if(config.ListView_HideUsernames)
|
||||
tmp->setText(j++,"******");
|
||||
else
|
||||
tmp->setText(j++,entry->UserName);}
|
||||
if(config.Columns[2]){
|
||||
tmp->setText(j++,entry->URL);}
|
||||
if(config.Columns[3]){
|
||||
if(config.ListView_HidePasswords)
|
||||
tmp->setText(j++,"******");
|
||||
else{
|
||||
tmp->setText(j++,entry->Password.getString());
|
||||
entry->Password.delRef();}}
|
||||
if(config.Columns[4]){
|
||||
tmp->setText(j++,entry->Additional.section('\n',0,0));}
|
||||
if(config.Columns[5]){
|
||||
tmp->setText(j++,entry->Expire.toString(DateTimeFormat));}
|
||||
if(config.Columns[6]){
|
||||
tmp->setText(j++,entry->Creation.toString(DateTimeFormat));}
|
||||
if(config.Columns[7]){
|
||||
tmp->setText(j++,entry->LastMod.toString(DateTimeFormat));}
|
||||
if(config.Columns[8]){
|
||||
tmp->setText(j++,entry->LastAccess.toString(DateTimeFormat));}
|
||||
if(config.Columns[9]){
|
||||
tmp->setText(j++,entry->BinaryDesc);}
|
||||
Items.back()->setIcon(0,EntryIcons[entry->ImageID]);
|
||||
}
|
||||
}
|
||||
|
||||
void KeepassEntryView::setCurrentGroup(uint id){
|
||||
for(int i=0; i<Items.size();i++){
|
||||
setItemHidden(Items[i],(Items[i]->pEntry->GroupID != id));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void KeepassEntryView::updateColumns(){
|
||||
QStringList cols;
|
||||
if(config.Columns[0]){
|
||||
cols << trUtf8("Titel");}
|
||||
if(config.Columns[1]){
|
||||
cols << trUtf8("Benutzername");}
|
||||
if(config.Columns[2]){
|
||||
cols << trUtf8("URL");}
|
||||
if(config.Columns[3]){
|
||||
cols << trUtf8("Passwort");}
|
||||
if(config.Columns[4]){
|
||||
cols << trUtf8("Kommentare");}
|
||||
if(config.Columns[5]){
|
||||
cols << trUtf8("Gültig bis");}
|
||||
if(config.Columns[6]){
|
||||
cols << trUtf8("Erstellung");}
|
||||
if(config.Columns[7]){
|
||||
cols << trUtf8("letzte Änderung");}
|
||||
if(config.Columns[8]){
|
||||
cols << trUtf8("letzter Zugriff");}
|
||||
if(config.Columns[9]){
|
||||
cols << trUtf8("Anhang");}
|
||||
setHeaderLabels(cols);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EntryViewItem::EntryViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
|
||||
|
||||
}
|
||||
|
||||
EntryViewItem::EntryViewItem(QTreeWidget *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){
|
||||
|
||||
}
|
||||
|
||||
EntryViewItem::EntryViewItem(QTreeWidgetItem *parent):QTreeWidgetItem(parent){
|
||||
|
||||
}
|
||||
|
||||
EntryViewItem::EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){
|
||||
|
||||
}
|
||||
51
src/lib/EntryView.h
Normal file
51
src/lib/EntryView.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef _ENTRY_VIEW_H_
|
||||
#define _ENTRY_VIEW_H_
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include "../PwManager.h"
|
||||
|
||||
class EntryViewItem;
|
||||
|
||||
class KeepassEntryView:public QTreeWidget{
|
||||
public:
|
||||
KeepassEntryView(QWidget* parent=0);
|
||||
void updateItems();
|
||||
void setCurrentGroup(uint GroupID);
|
||||
void updateColumns();
|
||||
PwDatabase* db;
|
||||
vector<EntryViewItem*>Items;
|
||||
private:
|
||||
int CurrentGroup;
|
||||
};
|
||||
|
||||
|
||||
class EntryViewItem:public QTreeWidgetItem{
|
||||
public:
|
||||
EntryViewItem(QTreeWidget *parent);
|
||||
EntryViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
|
||||
EntryViewItem(QTreeWidgetItem *parent);
|
||||
EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
|
||||
CEntry* pEntry;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
157
src/lib/GroupView.cpp
Normal file
157
src/lib/GroupView.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QDragLeaveEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <QFont>
|
||||
#include "main.h"
|
||||
#include "GroupView.h"
|
||||
|
||||
KeepassGroupView::KeepassGroupView(QWidget* parent):QTreeWidget(parent){
|
||||
LastHoverItem=NULL;
|
||||
setHeaderLabels(QStringList()<<tr("Gruppen"));
|
||||
}
|
||||
|
||||
void KeepassGroupView:: dragEnterEvent ( QDragEnterEvent * event ){
|
||||
if(event->mimeData()->hasFormat("keepass/group") ||
|
||||
event->mimeData()->hasFormat("keepass/entry")){
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void KeepassGroupView:: dragMoveEvent ( QDragMoveEvent * event ){
|
||||
GroupViewItem* item=(GroupViewItem*)itemAt(event->pos());
|
||||
if(LastHoverItem){
|
||||
QFont f=LastHoverItem->font(0);
|
||||
f.setBold(false);
|
||||
LastHoverItem->setFont(0,f);
|
||||
}
|
||||
if(item){
|
||||
QFont f=item->font(0);
|
||||
f.setBold(true);
|
||||
item->setFont(0,f);
|
||||
LastHoverItem=item;}
|
||||
else{
|
||||
LastHoverItem=NULL;}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void KeepassGroupView:: dragLeaveEvent ( QDragLeaveEvent * event ){
|
||||
if(LastHoverItem){
|
||||
QFont f=LastHoverItem->font(0);
|
||||
f.setBold(false);
|
||||
LastHoverItem->setFont(0,f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KeepassGroupView::dropEvent( QDropEvent * event ){
|
||||
if(LastHoverItem){
|
||||
QFont f=LastHoverItem->font(0);
|
||||
f.setBold(false);
|
||||
LastHoverItem->setFont(0,f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void KeepassGroupView::mousePressEvent(QMouseEvent *event){
|
||||
//save event position - maybe this is the start of a drag
|
||||
if (event->button() == Qt::LeftButton)
|
||||
DragStartPos = event->pos();
|
||||
//call base function
|
||||
QTreeWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
|
||||
if (!(event->buttons() & Qt::LeftButton))
|
||||
return;
|
||||
if ((event->pos() - DragStartPos).manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
GroupViewItem* item=(GroupViewItem*)itemAt(DragStartPos);
|
||||
if(!item)return;
|
||||
QDrag *drag = new QDrag(this);
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData("keepass/group",QByteArray((char*)&(item->pGroup),sizeof(void*)));
|
||||
drag->setMimeData(mimeData);
|
||||
drag->setPixmap(item->icon(0).pixmap());
|
||||
drag->start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void KeepassGroupView::updateItems(){
|
||||
for(GroupItr i=db->Groups.begin();i!=db->Groups.end();i++){
|
||||
if((*i).Level==0){
|
||||
if(Items.size()) Items.push_back(new GroupViewItem(this,getLastSameLevelItem(0)));
|
||||
else Items.push_back(new GroupViewItem(this));
|
||||
Items.back()->setText(0,(*i).Name);
|
||||
Items.back()->pGroup=&(*i);
|
||||
}
|
||||
else{
|
||||
if((*i).Level>(*(i-1)).Level){
|
||||
Items.push_back(new GroupViewItem(Items.back(),getLastSameLevelItem((*i).Level)));
|
||||
Items.back()->setText(0,(*i).Name);
|
||||
Items.back()->pGroup=&(*i);
|
||||
}
|
||||
if((*i).Level<=(*(i-1)).Level){
|
||||
GroupItemItr j;
|
||||
for(j=Items.end()-1;j!=Items.begin();j--){
|
||||
if((*j)->pGroup->Level<(*i).Level)break;}
|
||||
Items.push_back(new GroupViewItem((*j),getLastSameLevelItem((*i).Level)));
|
||||
Items.back()->setText(0,(*i).Name);
|
||||
Items.back()->pGroup=&(*i);
|
||||
}
|
||||
}
|
||||
Items.back()->setIcon(0,EntryIcons[(*i).ImageID]);
|
||||
}
|
||||
|
||||
for(int i=0;i<Items.size();i++){
|
||||
setItemExpanded(Items[i],Items[i]->pGroup->UI_ItemIsExpanded);
|
||||
}}
|
||||
|
||||
GroupViewItem* KeepassGroupView::getLastSameLevelItem(int level){
|
||||
for(int i=Items.size()-1;i>=0;i--){
|
||||
if(Items[i]->pGroup->Level==level){
|
||||
return Items[i];}
|
||||
}
|
||||
return Items.back();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
GroupViewItem::GroupViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){
|
||||
}
|
||||
|
||||
GroupViewItem::GroupViewItem(QTreeWidget *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){
|
||||
}
|
||||
|
||||
GroupViewItem::GroupViewItem(QTreeWidgetItem *parent):QTreeWidgetItem(parent){
|
||||
}
|
||||
|
||||
GroupViewItem::GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding):QTreeWidgetItem(parent,preceding){
|
||||
}
|
||||
60
src/lib/GroupView.h
Normal file
60
src/lib/GroupView.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 by Tarek Saidi *
|
||||
* tarek.saidi@arcor.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef _GROUP_VIEW_H_
|
||||
#define _GROUP_VIEW_H_
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include "../PwManager.h"
|
||||
|
||||
class GroupViewItem;
|
||||
typedef vector<GroupViewItem*>::iterator GroupItemItr;
|
||||
|
||||
class KeepassGroupView:public QTreeWidget{
|
||||
public:
|
||||
KeepassGroupView(QWidget* parent=0);
|
||||
void updateItems();
|
||||
PwDatabase *db;
|
||||
vector<GroupViewItem*>Items;
|
||||
protected:
|
||||
virtual void dragEnterEvent ( QDragEnterEvent * event );
|
||||
virtual void dragMoveEvent ( QDragMoveEvent * event );
|
||||
virtual void dragLeaveEvent ( QDragLeaveEvent * event );
|
||||
virtual void dropEvent ( QDropEvent * event );
|
||||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
QPoint DragStartPos;
|
||||
GroupViewItem* LastHoverItem;
|
||||
GroupViewItem* getLastSameLevelItem(int level);
|
||||
};
|
||||
|
||||
|
||||
class GroupViewItem:public QTreeWidgetItem{
|
||||
public:
|
||||
GroupViewItem(QTreeWidget *parent);
|
||||
GroupViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
|
||||
GroupViewItem(QTreeWidgetItem *parent);
|
||||
GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
|
||||
CGroup* pGroup;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user