Added action "Copy URL to Clipboard" (closes #1944021)

Fixed: Unnamed Database saved as ".kdb" (closes #2109972, #2118340)
Fixed: Date of Modification isn't updated (closes #2108658, #2121768)
Fixed and improved the initialization of the fallback random number source (closes #2091784)
Don't clear clipboard if "Clear clipboard after" is set to 0
Try to clear Klipper history when clearing clipboard

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@220 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent 07fb82c88b
commit 70bf7f5b5d
  1. 9
      src/Kdb3Database.cpp
  2. 4
      src/dialogs/AboutDlg.cpp
  3. 3
      src/forms/EditEntryDlg.ui
  4. 16
      src/forms/MainWindow.ui
  5. 59
      src/lib/EntryView.cpp
  6. 3
      src/lib/EntryView.h
  7. 13
      src/lib/random.cpp
  8. 2
      src/main_unix.cpp
  9. 12
      src/mainwindow.cpp
  10. 2
      src/res/default-detailview.html

@ -860,15 +860,18 @@ bool Kdb3Database::setFileKey(const QString& filename){
if(FileSize == 32){ if(FileSize == 32){
if(file.read((char*)RawMasterKey,32) != 32){ if(file.read((char*)RawMasterKey,32) != 32){
error=decodeFileError(file.error()); error=decodeFileError(file.error());
return false;} return false;
}
return true; return true;
} }
if(FileSize == 64){ if(FileSize == 64){
char hex[64]; char hex[64];
if(file.read(hex,64) != 64){ if(file.read(hex,64) != 64){
error=decodeFileError(file.error()); error=decodeFileError(file.error());
return false;} return false;
if(convHexToBinaryKey(hex,(char*)RawMasterKey))return true; }
if (convHexToBinaryKey(hex,(char*)RawMasterKey))
return true;
} }
SHA256 sha; SHA256 sha;
unsigned char* buffer = new unsigned char[2048]; unsigned char* buffer = new unsigned char[2048];

@ -45,11 +45,11 @@ AboutDialog::AboutDialog(QWidget* parent):QDialog(parent)
str+="<div style='margin-left:10px;'>"; str+="<div style='margin-left:10px;'>";
str+="<u>Tarek Saidi</u><br>"+tr("Developer, Project Admin")+"<br>tarek_saidi@users.sf.net<br>"; str+="<u>Tarek Saidi</u><br>"+tr("Developer, Project Admin")+"<br>tarek_saidi@users.sf.net<br>";
str+="<br>"; str+="<br>";
str+="<u>Felix Geyer</u><br>"+tr("Developer, Project Admin")+"<br>sniperbeamer@users.sf.net<br>";
str+="<br>";
str+="<u>Eugen Gorschenin</u><br>"+tr("Web Designer")+"<br>geugen@users.sf.de<br>"; str+="<u>Eugen Gorschenin</u><br>"+tr("Web Designer")+"<br>geugen@users.sf.de<br>";
str+="<br>"; str+="<br>";
str+="<u>Juan J Gonz&aacute;lez C&aacute;rdenas [Jota Jota]</u><br>"+tr("Developer")+"<br>myxelf@users.sf.net<br>"; str+="<u>Juan J Gonz&aacute;lez C&aacute;rdenas [Jota Jota]</u><br>"+tr("Developer")+"<br>myxelf@users.sf.net<br>";
str+="<br>";
str+="<u>Felix Geyer</u><br>"+tr("Developer")+"<br>sniperbeamer@users.sf.net<br>";
str+="</div><br><div style='margin-left:0px;'>"; str+="</div><br><div style='margin-left:0px;'>";
str+="<b>"+tr("Thanks To")+"</b><br>"; str+="<b>"+tr("Thanks To")+"</b><br>";
str+="</div><div style='margin-left:10px;'>"; str+="</div><div style='margin-left:10px;'>";

@ -243,6 +243,9 @@
<property name="tabChangesFocus" > <property name="tabChangesFocus" >
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item row="12" column="0" colspan="2" > <item row="12" column="0" colspan="2" >

@ -17,6 +17,14 @@
<string>KeePassX</string> <string>KeePassX</string>
</property> </property>
<widget class="QWidget" name="centralWidget" > <widget class="QWidget" name="centralWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>29</y>
<width>724</width>
<height>439</height>
</rect>
</property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
<widget class="QSplitter" name="VSplitter" > <widget class="QSplitter" name="VSplitter" >
@ -112,7 +120,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>724</width> <width>724</width>
<height>30</height> <height>29</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuHilfe" > <widget class="QMenu" name="menuHilfe" >
@ -170,6 +178,7 @@
<addaction name="EditUsernameToClipboardAction" /> <addaction name="EditUsernameToClipboardAction" />
<addaction name="EditPasswordToClipboardAction" /> <addaction name="EditPasswordToClipboardAction" />
<addaction name="EditOpenUrlAction" /> <addaction name="EditOpenUrlAction" />
<addaction name="EditCopyUrlAction" />
<addaction name="EditSaveAttachmentAction" /> <addaction name="EditSaveAttachmentAction" />
<addaction name="separator" /> <addaction name="separator" />
<addaction name="EditNewEntryAction" /> <addaction name="EditNewEntryAction" />
@ -564,6 +573,11 @@
<string>Bookmark &amp;this Database...</string> <string>Bookmark &amp;this Database...</string>
</property> </property>
</action> </action>
<action name="EditCopyUrlAction" >
<property name="text" >
<string>Copy URL to Clipboard</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

@ -21,6 +21,7 @@
#include <QHeaderView> #include <QHeaderView>
#include <QClipboard> #include <QClipboard>
#include <QFileDialog> #include <QFileDialog>
#include <QProcess>
#include "lib/AutoType.h" #include "lib/AutoType.h"
#include "lib/EntryView.h" #include "lib/EntryView.h"
#include "dialogs/EditEntryDlg.h" #include "dialogs/EditEntryDlg.h"
@ -243,14 +244,18 @@ void KeepassEntryView::OnNewEntry(){
} }
void KeepassEntryView::OnEntryActivated(QTreeWidgetItem* item,int Column){ void KeepassEntryView::OnEntryActivated(QTreeWidgetItem* item,int Column){
switch(columnListIndex(Column)){ switch (columnListIndex(Column)){
case 0: editEntry((EntryViewItem*)item); case 0:
editEntry((EntryViewItem*)item);
break; break;
case 1: OnUsernameToClipboard(); case 1:
OnUsernameToClipboard();
break; break;
case 2: OnEditOpenUrl(); case 2:
OnEditOpenUrl();
break; break;
case 3: OnPasswordToClipboard(); case 3:
OnPasswordToClipboard();
break; break;
} }
@ -266,14 +271,31 @@ void KeepassEntryView::OnEditOpenUrl(){
openBrowser( ((EntryViewItem*)selectedItems().first())->EntryHandle ); openBrowser( ((EntryViewItem*)selectedItems().first())->EntryHandle );
} }
void KeepassEntryView::OnEditCopyUrl(){
if (selectedItems().size() == 0) return;
QString url = ((EntryViewItem*)selectedItems().first())->EntryHandle->url();
if (url.startsWith("cmd://") && url.length()>6)
url = url.right(url.length()-6);
Clipboard->setText(url, QClipboard::Clipboard);
if(Clipboard->supportsSelection()){
Clipboard->setText(url, QClipboard::Selection);
}
}
void KeepassEntryView::OnUsernameToClipboard(){ void KeepassEntryView::OnUsernameToClipboard(){
if (selectedItems().size() == 0) return; if (selectedItems().size() == 0) return;
Clipboard->setText(((EntryViewItem*)selectedItems().first())->EntryHandle->username(), QClipboard::Clipboard); QString username = ((EntryViewItem*)selectedItems().first())->EntryHandle->username();
if (username.trimmed().isEmpty()) return;
Clipboard->setText(username, QClipboard::Clipboard);
if(Clipboard->supportsSelection()){ if(Clipboard->supportsSelection()){
Clipboard->setText(((EntryViewItem*)selectedItems().first())->EntryHandle->username(),QClipboard::Selection); Clipboard->setText(username, QClipboard::Selection);
} }
if (config->clipboardTimeOut()!=0) {
ClipboardTimer.setSingleShot(true); ClipboardTimer.setSingleShot(true);
ClipboardTimer.start(config->clipboardTimeOut()*1000); ClipboardTimer.start(config->clipboardTimeOut()*1000);
}
} }
void KeepassEntryView::OnPasswordToClipboard(){ void KeepassEntryView::OnPasswordToClipboard(){
@ -281,12 +303,16 @@ void KeepassEntryView::OnPasswordToClipboard(){
SecString password; SecString password;
password=((EntryViewItem*)selectedItems().first())->EntryHandle->password(); password=((EntryViewItem*)selectedItems().first())->EntryHandle->password();
password.unlock(); password.unlock();
Clipboard->setText(password.string(),QClipboard::Clipboard); if (password.string().isEmpty()) return;
Clipboard->setText(password.string(), QClipboard::Clipboard);
if(Clipboard->supportsSelection()){ if(Clipboard->supportsSelection()){
Clipboard->setText(password.string(),QClipboard::Selection); Clipboard->setText(password.string(), QClipboard::Selection);
} }
if (config->clipboardTimeOut()!=0) {
ClipboardTimer.setSingleShot(true); ClipboardTimer.setSingleShot(true);
ClipboardTimer.start(config->clipboardTimeOut()*1000); ClipboardTimer.start(config->clipboardTimeOut()*1000);
}
} }
void KeepassEntryView::OnClipboardTimeOut(){ void KeepassEntryView::OnClipboardTimeOut(){
@ -294,6 +320,13 @@ void KeepassEntryView::OnClipboardTimeOut(){
if(Clipboard->supportsSelection()){ if(Clipboard->supportsSelection()){
Clipboard->clear(QClipboard::Selection); Clipboard->clear(QClipboard::Selection);
} }
#ifdef Q_WS_X11
static bool clearKlipper = true;
if (clearKlipper){
if (QProcess::execute("dcop klipper klipper clearClipboardHistory")!=0)
clearKlipper = false;
}
#endif
} }
@ -312,9 +345,9 @@ void KeepassEntryView::contextMenuEvent(QContextMenuEvent* e){
} }
} }
} }
else else{
{while(selectedItems().size()){ while (selectedItems().size())
setItemSelected(selectedItems().first(),false);} setItemSelected(selectedItems().first(),false);
} }
e->accept(); e->accept();
ContextMenu->popup(e->globalPos()); ContextMenu->popup(e->globalPos());
@ -621,7 +654,7 @@ bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{
KpxDateTime DateThis; KpxDateTime DateThis;
KpxDateTime DateOther; KpxDateTime DateOther;
switch(ListIndex){ switch (ListIndex){
case 5: DateThis=EntryHandle->expire(); case 5: DateThis=EntryHandle->expire();
DateOther=((EntryViewItem&)other).EntryHandle->expire(); DateOther=((EntryViewItem&)other).EntryHandle->expire();
break; break;

@ -69,6 +69,7 @@ class KeepassEntryView:public QTreeWidget{
virtual void resizeEvent(QResizeEvent* event); virtual void resizeEvent(QResizeEvent* event);
virtual void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
private slots: private slots:
void OnColumnResized(int index,int OldSize, int NewSize); void OnColumnResized(int index,int OldSize, int NewSize);
void OnHeaderSectionClicked(int index); void OnHeaderSectionClicked(int index);
@ -91,6 +92,8 @@ class KeepassEntryView:public QTreeWidget{
void removeDragItems(); void removeDragItems();
void OnColumnMoved(int LogIndex,int OldVisIndex,int NewVisIndex); void OnColumnMoved(int LogIndex,int OldVisIndex,int NewVisIndex);
void OnEditOpenUrl(); void OnEditOpenUrl();
void OnEditCopyUrl();
signals: signals:
void fileModified(); void fileModified();
void selectionChanged(SelectionState); void selectionChanged(SelectionState);

@ -88,9 +88,18 @@ extern void initStdRand(){
stream << QCursor::pos(); stream << QCursor::pos();
stream << QDateTime::currentDateTime().toTime_t(); stream << QDateTime::currentDateTime().toTime_t();
stream << QTime::currentTime().msec(); stream << QTime::currentTime().msec();
#ifdef Q_WS_WIN
stream << GetCurrentProcessId();
#else
stream << getpid();
#endif
/* On a modern OS code, stack and heap base are randomized */
quint64 code_value = (quint64)initStdRand;
stream << code_value;
stream << (quint64)&code_value;
QByteArray hash = QCryptographicHash::hash(buffer, QCryptographicHash::Md4); QByteArray hash = QCryptographicHash::hash(buffer, QCryptographicHash::Sha1);
qsrand( (uint) hash.constData() ); qsrand( *((uint*) hash.data()) );
initalized = true; initalized = true;
} }

@ -70,5 +70,7 @@ void initAppPaths(int argc,char** argv) {
} }
AppDir.truncate(AppDir.lastIndexOf("/")); AppDir.truncate(AppDir.lastIndexOf("/"));
DataDir=AppDir+"/../share/keepassx"; DataDir=AppDir+"/../share/keepassx";
if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
DataDir=AppDir+"/share";
HomeDir = QDir::homePath()+"/.keepassx"; HomeDir = QDir::homePath()+"/.keepassx";
} }

@ -157,6 +157,7 @@ void KeepassMainWindow::setupConnections(){
connect(EditUsernameToClipboardAction, SIGNAL(triggered()), EntryView, SLOT(OnUsernameToClipboard())); connect(EditUsernameToClipboardAction, SIGNAL(triggered()), EntryView, SLOT(OnUsernameToClipboard()));
connect(EditPasswordToClipboardAction, SIGNAL(triggered()), EntryView, SLOT(OnPasswordToClipboard())); connect(EditPasswordToClipboardAction, SIGNAL(triggered()), EntryView, SLOT(OnPasswordToClipboard()));
connect(EditOpenUrlAction, SIGNAL(triggered()), EntryView, SLOT(OnEditOpenUrl())); connect(EditOpenUrlAction, SIGNAL(triggered()), EntryView, SLOT(OnEditOpenUrl()));
connect(EditCopyUrlAction, SIGNAL(triggered()), EntryView, SLOT(OnEditCopyUrl()));
connect(EditSaveAttachmentAction, SIGNAL(triggered()),EntryView, SLOT(OnSaveAttachment())); connect(EditSaveAttachmentAction, SIGNAL(triggered()),EntryView, SLOT(OnSaveAttachment()));
connect(EditSearchAction, SIGNAL(triggered()), this, SLOT(OnSearch())); connect(EditSearchAction, SIGNAL(triggered()), this, SLOT(OnSearch()));
connect(EditGroupSearchAction, SIGNAL(triggered()), this, SLOT(OnGroupSearch())); connect(EditGroupSearchAction, SIGNAL(triggered()), this, SLOT(OnGroupSearch()));
@ -282,6 +283,7 @@ void KeepassMainWindow::setupMenus(){
EntryView->ContextMenu->addAction(EditUsernameToClipboardAction); EntryView->ContextMenu->addAction(EditUsernameToClipboardAction);
EntryView->ContextMenu->addAction(EditPasswordToClipboardAction); EntryView->ContextMenu->addAction(EditPasswordToClipboardAction);
EntryView->ContextMenu->addAction(EditOpenUrlAction); EntryView->ContextMenu->addAction(EditOpenUrlAction);
EntryView->ContextMenu->addAction(EditCopyUrlAction);
EntryView->ContextMenu->addAction(EditSaveAttachmentAction); EntryView->ContextMenu->addAction(EditSaveAttachmentAction);
#ifdef AUTOTYPE #ifdef AUTOTYPE
EntryView->ContextMenu->addAction(EditAutoTypeAction); EntryView->ContextMenu->addAction(EditAutoTypeAction);
@ -578,6 +580,7 @@ void KeepassMainWindow::setStateFileOpen(bool IsOpen){
EditPasswordToClipboardAction->setEnabled(false); EditPasswordToClipboardAction->setEnabled(false);
EditUsernameToClipboardAction->setEnabled(false); EditUsernameToClipboardAction->setEnabled(false);
EditOpenUrlAction->setEnabled(false); EditOpenUrlAction->setEnabled(false);
EditCopyUrlAction->setEnabled(false);
EditSaveAttachmentAction->setEnabled(false); EditSaveAttachmentAction->setEnabled(false);
EditNewEntryAction->setEnabled(false); EditNewEntryAction->setEnabled(false);
EditEditEntryAction->setEnabled(false); EditEditEntryAction->setEnabled(false);
@ -722,6 +725,7 @@ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EditPasswordToClipboardAction->setEnabled(false); EditPasswordToClipboardAction->setEnabled(false);
EditUsernameToClipboardAction->setEnabled(false); EditUsernameToClipboardAction->setEnabled(false);
EditOpenUrlAction->setEnabled(false); EditOpenUrlAction->setEnabled(false);
EditCopyUrlAction->setEnabled(false);
EditSaveAttachmentAction->setEnabled(false); EditSaveAttachmentAction->setEnabled(false);
EditEditEntryAction->setEnabled(false); EditEditEntryAction->setEnabled(false);
EditCloneEntryAction->setEnabled(false); EditCloneEntryAction->setEnabled(false);
@ -736,6 +740,7 @@ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EditPasswordToClipboardAction->setEnabled(true); EditPasswordToClipboardAction->setEnabled(true);
EditUsernameToClipboardAction->setEnabled(true); EditUsernameToClipboardAction->setEnabled(true);
EditOpenUrlAction->setEnabled(true); EditOpenUrlAction->setEnabled(true);
EditCopyUrlAction->setEnabled(true);
EditSaveAttachmentAction->setEnabled(((EntryViewItem*)(EntryView->selectedItems()[0]))->EntryHandle->binarySize() > 0); EditSaveAttachmentAction->setEnabled(((EntryViewItem*)(EntryView->selectedItems()[0]))->EntryHandle->binarySize() > 0);
EditEditEntryAction->setEnabled(true); EditEditEntryAction->setEnabled(true);
EditCloneEntryAction->setEnabled(true); EditCloneEntryAction->setEnabled(true);
@ -750,6 +755,7 @@ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EditPasswordToClipboardAction->setEnabled(false); EditPasswordToClipboardAction->setEnabled(false);
EditUsernameToClipboardAction->setEnabled(false); EditUsernameToClipboardAction->setEnabled(false);
EditOpenUrlAction->setEnabled(false); EditOpenUrlAction->setEnabled(false);
EditCopyUrlAction->setEnabled(false);
EditSaveAttachmentAction->setEnabled(false); EditSaveAttachmentAction->setEnabled(false);
EditEditEntryAction->setEnabled(false); EditEditEntryAction->setEnabled(false);
EditCloneEntryAction->setEnabled(true); EditCloneEntryAction->setEnabled(true);
@ -770,6 +776,7 @@ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EditUsernameToClipboardAction->setEnabled(false); EditUsernameToClipboardAction->setEnabled(false);
EditPasswordToClipboardAction->setEnabled(false); EditPasswordToClipboardAction->setEnabled(false);
EditOpenUrlAction->setEnabled(false); EditOpenUrlAction->setEnabled(false);
EditCopyUrlAction->setEnabled(false);
EditSaveAttachmentAction->setEnabled(false); EditSaveAttachmentAction->setEnabled(false);
EditEditEntryAction->setEnabled(false); EditEditEntryAction->setEnabled(false);
EditCloneEntryAction->setEnabled(false); EditCloneEntryAction->setEnabled(false);
@ -784,6 +791,7 @@ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EditUsernameToClipboardAction->setEnabled(true); EditUsernameToClipboardAction->setEnabled(true);
EditPasswordToClipboardAction->setEnabled(true); EditPasswordToClipboardAction->setEnabled(true);
EditOpenUrlAction->setEnabled(true); EditOpenUrlAction->setEnabled(true);
EditCopyUrlAction->setEnabled(true);
EditSaveAttachmentAction->setEnabled(((EntryViewItem*)(EntryView->selectedItems()[0]))->EntryHandle->binarySize() > 0); EditSaveAttachmentAction->setEnabled(((EntryViewItem*)(EntryView->selectedItems()[0]))->EntryHandle->binarySize() > 0);
EditEditEntryAction->setEnabled(true); EditEditEntryAction->setEnabled(true);
EditCloneEntryAction->setEnabled(false); EditCloneEntryAction->setEnabled(false);
@ -798,6 +806,7 @@ void KeepassMainWindow::setStateEntrySelected(SelectionState s){
EditUsernameToClipboardAction->setEnabled(false); EditUsernameToClipboardAction->setEnabled(false);
EditPasswordToClipboardAction->setEnabled(false); EditPasswordToClipboardAction->setEnabled(false);
EditOpenUrlAction->setEnabled(false); EditOpenUrlAction->setEnabled(false);
EditCopyUrlAction->setEnabled(false);
EditSaveAttachmentAction->setEnabled(false); EditSaveAttachmentAction->setEnabled(false);
EditEditEntryAction->setEnabled(false); EditEditEntryAction->setEnabled(false);
EditCloneEntryAction->setEnabled(false); EditCloneEntryAction->setEnabled(false);
@ -833,7 +842,8 @@ bool KeepassMainWindow::OnFileSave(){
bool KeepassMainWindow::OnFileSaveAs(){ bool KeepassMainWindow::OnFileSaveAs(){
QString filename=KpxFileDialogs::saveFile(this,"MainWindow_FileSave", QString filename=KpxFileDialogs::saveFile(this,"MainWindow_FileSave",
tr("Save Database..."),QStringList()<<tr("KeePass Databases (*.kdb)")<< tr("All Files (*)")); tr("Save Database..."),QStringList()<<tr("KeePass Databases (*.kdb)")<< tr("All Files (*)"));
if(filename.isEmpty())return false; if (filename.isEmpty() || filename.compare(".kdb", Qt::CaseInsensitive)==0)
return false;
if(!db->changeFile(filename)){ if(!db->changeFile(filename)){
showErrMsg(QString("%1\n%2").arg(tr("File could not be saved.")).arg(db->getError())); showErrMsg(QString("%1\n%2").arg(tr("File could not be saved.")).arg(db->getError()));
db->changeFile(QString()); db->changeFile(QString());

@ -41,7 +41,7 @@
<td width="10%" class="fieldname">Password:</td> <td width="10%" class="fieldname">Password:</td>
<td width="40%" class="fieldvalue">%password%</td> <td width="40%" class="fieldvalue">%password%</td>
<td width="10%" class="fieldname">Modification:</td> <td width="10%" class="fieldname">Modification:</td>
<td width="40%" class="fieldvalue">%creation%</td> <td width="40%" class="fieldvalue">%lastmod%</td>
</tr> </tr>
<tr> <tr>
<td width="10%" class="fieldname">Attachment:</td> <td width="10%" class="fieldname">Attachment:</td>