Add ability to drag'n'drop fields (username, password, ...) to other applications
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@339 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
f1d9fcfd60
commit
73e8c49e3b
|
@ -242,7 +242,7 @@ void KeepassEntryView::OnDeleteEntry(){
|
|||
}
|
||||
|
||||
bool backup = false;
|
||||
IGroupHandle* bGroup;
|
||||
IGroupHandle* bGroup = NULL;
|
||||
if (config->backup() && ((EntryViewItem*)entries[0])->EntryHandle->group() != (bGroup=db->backupGroup()))
|
||||
backup = true;
|
||||
if (backup && !bGroup) {
|
||||
|
@ -266,40 +266,68 @@ void KeepassEntryView::OnDeleteEntry(){
|
|||
emit fileModified();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void KeepassEntryView::updateEntry(EntryViewItem* item){
|
||||
IEntryHandle* entry = item->EntryHandle;
|
||||
int j=0;
|
||||
item->setText(j++,entry->title());
|
||||
item->setIcon(0,db->icon(entry->image()));
|
||||
if(config->hideUsernames())
|
||||
item->setText(j++,"******");
|
||||
QString KeepassEntryView::columnString(IEntryHandle* entry, int col, bool forceClearText) {
|
||||
switch (col) {
|
||||
case 0:
|
||||
return entry->title();
|
||||
case 1:
|
||||
if (config->hideUsernames() && !forceClearText)
|
||||
return "******";
|
||||
else
|
||||
item->setText(j++,entry->username());
|
||||
item->setText(j++,entry->url());
|
||||
if(config->hidePasswords())
|
||||
item->setText(j++,"******");
|
||||
return entry->username();
|
||||
case 2:
|
||||
return entry->url();
|
||||
case 3:
|
||||
{
|
||||
if (config->hidePasswords() && !forceClearText) {
|
||||
return "******";
|
||||
}
|
||||
else {
|
||||
SecString password = entry->password();
|
||||
password.unlock();
|
||||
item->setText(j++,password.string());
|
||||
return password.string();
|
||||
}
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
QString comment = entry->comment();
|
||||
int toPos = comment.indexOf(QRegExp("[\\r\\n]"));
|
||||
if (toPos == -1)
|
||||
item->setText(j++,comment);
|
||||
return comment;
|
||||
else
|
||||
item->setText(j++,comment.left(toPos));
|
||||
item->setText(j++,entry->expire().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entry->creation().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entry->lastMod().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entry->lastAccess().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entry->binaryDesc());
|
||||
if (ViewMode == ShowSearchResults) {
|
||||
item->setText(j,entry->group()->title());
|
||||
item->setIcon(j++,db->icon(entry->group()->image()));
|
||||
return comment.left(toPos);
|
||||
}
|
||||
case 5:
|
||||
return entry->expire().dateToString(Qt::SystemLocaleDate);
|
||||
case 6:
|
||||
return entry->creation().dateToString(Qt::SystemLocaleDate);
|
||||
case 7:
|
||||
return entry->lastMod().dateToString(Qt::SystemLocaleDate);
|
||||
case 8:
|
||||
return entry->lastAccess().dateToString(Qt::SystemLocaleDate);
|
||||
case 9:
|
||||
return entry->binaryDesc();
|
||||
case 10:
|
||||
return entry->group()->title();
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
void KeepassEntryView::updateEntry(EntryViewItem* item){
|
||||
IEntryHandle* entry = item->EntryHandle;
|
||||
|
||||
int cols = NUM_COLUMNS - 1;
|
||||
if (ViewMode == ShowSearchResults) {
|
||||
item->setIcon(10, db->icon(entry->group()->image()));
|
||||
++cols;
|
||||
}
|
||||
|
||||
for (int i=0; i<cols; ++i) {
|
||||
item->setText(i, columnString(entry, i));
|
||||
}
|
||||
item->setIcon(0, db->icon(entry->image()));
|
||||
}
|
||||
|
||||
void KeepassEntryView::editEntry(EntryViewItem* item){
|
||||
|
@ -511,41 +539,15 @@ void KeepassEntryView::showGroup(IGroupHandle* group){
|
|||
}
|
||||
|
||||
void KeepassEntryView::createItems(QList<IEntryHandle*>& entries){
|
||||
for(int i=0;i<entries.size();i++){
|
||||
if(!entries[i]->isValid())continue;
|
||||
for (int i=0; i<entries.size(); ++i) {
|
||||
if (!entries[i]->isValid())
|
||||
continue;
|
||||
|
||||
EntryViewItem* item = new EntryViewItem(this);
|
||||
Items.push_back(item);
|
||||
Items.back()->EntryHandle = entries[i];
|
||||
int j=0;
|
||||
item->setText(j++,entries[i]->title());
|
||||
item->setIcon(0,db->icon(entries[i]->image()));
|
||||
if(config->hideUsernames())
|
||||
item->setText(j++,"******");
|
||||
else
|
||||
item->setText(j++,entries[i]->username());
|
||||
item->setText(j++,entries[i]->url());
|
||||
if(config->hidePasswords())
|
||||
item->setText(j++,"******");
|
||||
else{
|
||||
SecString password=entries[i]->password();
|
||||
password.unlock();
|
||||
item->setText(j++,password.string());
|
||||
}
|
||||
QString comment = entries[i]->comment();
|
||||
int toPos = comment.indexOf(QRegExp("[\\r\\n]"));
|
||||
if (toPos == -1)
|
||||
item->setText(j++,comment);
|
||||
else
|
||||
item->setText(j++,comment.left(toPos));
|
||||
item->setText(j++,entries[i]->expire().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entries[i]->creation().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entries[i]->lastMod().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entries[i]->lastAccess().dateToString(Qt::SystemLocaleDate));
|
||||
item->setText(j++,entries[i]->binaryDesc());
|
||||
if (ViewMode == ShowSearchResults) {
|
||||
item->setText(j,entries[i]->group()->title());
|
||||
item->setIcon(j++,db->icon(entries[i]->group()->image()));
|
||||
}
|
||||
|
||||
updateEntry(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -604,7 +606,9 @@ void KeepassEntryView::mouseMoveEvent(QMouseEvent *event){
|
|||
QDrag *drag = new QDrag(this);
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
void* pDragItems=&DragItems;
|
||||
mimeData->setData("text/plain;charset=UTF-8",DragItems.first()->text(0).toUtf8());
|
||||
if (header()->logicalIndexAt(event->pos()) != -1) {
|
||||
mimeData->setText(columnStringView(DragStartItem, header()->logicalIndexAt(event->pos()), true));
|
||||
}
|
||||
mimeData->setData("application/x-keepassx-entry",QByteArray((char*)&pDragItems,sizeof(void*)));
|
||||
drag->setMimeData(mimeData);
|
||||
EventOccurredBlock = true;
|
||||
|
|
|
@ -23,10 +23,21 @@
|
|||
|
||||
#include "Kdb3Database.h"
|
||||
|
||||
class EntryViewItem;
|
||||
class GroupViewItem;
|
||||
enum SelectionState{NONE,SINGLE,MULTIPLE,SEARCHGROUP};
|
||||
|
||||
class EntryViewItem:public QTreeWidgetItem{
|
||||
public:
|
||||
EntryViewItem(QTreeWidget *parent);
|
||||
EntryViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
|
||||
EntryViewItem(QTreeWidgetItem *parent);
|
||||
EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
|
||||
IEntryHandle* EntryHandle;
|
||||
bool operator<(const QTreeWidgetItem& other) const;
|
||||
private:
|
||||
int compare(const QTreeWidgetItem& other, int col, int index) const;
|
||||
};
|
||||
|
||||
class KeepassEntryView:public QTreeWidget{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -56,6 +67,10 @@ class KeepassEntryView:public QTreeWidget{
|
|||
bool AutoResizeColumns;
|
||||
QList<int> columnSizes;
|
||||
|
||||
QString columnString(IEntryHandle* entry, int col, bool forceClearText=false);
|
||||
inline QString columnStringView(EntryViewItem* item, int col, bool forceClearText=false) {
|
||||
return columnString(item->EntryHandle, col, forceClearText);
|
||||
};
|
||||
void updateEntry(EntryViewItem*);
|
||||
void editEntry(EntryViewItem*);
|
||||
void createItems(QList<IEntryHandle*>& entries);
|
||||
|
@ -98,18 +113,4 @@ class KeepassEntryView:public QTreeWidget{
|
|||
void viewModeChanged(bool searchResultMode);
|
||||
};
|
||||
|
||||
|
||||
class EntryViewItem:public QTreeWidgetItem{
|
||||
public:
|
||||
EntryViewItem(QTreeWidget *parent);
|
||||
EntryViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
|
||||
EntryViewItem(QTreeWidgetItem *parent);
|
||||
EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
|
||||
IEntryHandle* EntryHandle;
|
||||
bool operator<(const QTreeWidgetItem& other) const;
|
||||
private:
|
||||
int compare(const QTreeWidgetItem& other, int col, int index) const;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -497,7 +497,6 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){
|
|||
QDrag *drag = new QDrag(this);
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
|
||||
mimeData->setData("text/plain;charset=UTF-8",DragItem->text(0).toUtf8());
|
||||
mimeData->setData("application/x-keepassx-group",QByteArray());
|
||||
drag->setMimeData(mimeData);
|
||||
|
||||
|
|
Loading…
Reference in New Issue