-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Create new KeepassHTTP KeyAcceptDialog #850
Closed
duk3luk3
wants to merge
8
commits into
keepassxreboot:develop
from
duk3luk3:feature/838-keepasshttp-keys
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0eb07ad
Create new KeepassHTTP KeyAcceptDialog
duk3luk3 62dc9d8
Insert KeepassHTTP Auth Key into multiple DBs
duk3luk3 840c04e
Handle empty key name edit
duk3luk3 8562fb1
Clean up
duk3luk3 e124348
Move open db check from server to keyaccept dialog
duk3luk3 b860e4c
Make strings translateable
duk3luk3 e97dacb
Formatting
duk3luk3 64689ae
Remove obsolete TODO comments
duk3luk3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (C) 2013 Francois Ferrand | ||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> | ||
* | ||
* 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 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "KeyAcceptDialog.h" | ||
#include "core/Entry.h" | ||
#include "ui_KeyAcceptDialog.h" | ||
#include <QDialogButtonBox> | ||
#include <QPushButton> | ||
#include <QStandardItem> | ||
#include <QStandardItemModel> | ||
#include <Qt> | ||
|
||
KeyAcceptDialog::KeyAcceptDialog(QWidget* parent) | ||
: QDialog(parent) | ||
, ui(new Ui::KeyAcceptDialog()) | ||
{ | ||
this->setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); | ||
|
||
ui->setupUi(this); | ||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); | ||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | ||
|
||
connect(ui->keyNameLineEdit, SIGNAL(textChanged(const QString)), this, SLOT(keyEditChanged(const QString))); | ||
|
||
QStandardItemModel* listViewModel = new QStandardItemModel(ui->databasesListView); | ||
ui->databasesListView->setModel(listViewModel); | ||
connect(listViewModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(modelItemChanged(QStandardItem*))); | ||
} | ||
|
||
KeyAcceptDialog::~KeyAcceptDialog() | ||
{ | ||
} | ||
|
||
void KeyAcceptDialog::setItems(const QList<QString>& items) | ||
{ | ||
QStandardItemModel* listViewModel = qobject_cast<QStandardItemModel*>(ui->databasesListView->model()); | ||
|
||
listViewModel->clear(); | ||
|
||
for (QString item : items) { | ||
QStandardItem* listItem = new QStandardItem(item); | ||
listItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); | ||
listItem->setData(Qt::Unchecked, Qt::CheckStateRole); | ||
|
||
listViewModel->appendRow(listItem); | ||
} | ||
} | ||
|
||
void KeyAcceptDialog::setItemEnabled(int itemIndex, bool enabled) | ||
{ | ||
QStandardItemModel* listViewModel = qobject_cast<QStandardItemModel*>(ui->databasesListView->model()); | ||
|
||
QStandardItem* item = listViewModel->item(itemIndex); | ||
|
||
if (item) { | ||
item->setEnabled(enabled); | ||
} | ||
} | ||
|
||
void KeyAcceptDialog::setItemChecked(int itemIndex, bool checked) | ||
{ | ||
QStandardItemModel* listViewModel = qobject_cast<QStandardItemModel*>(ui->databasesListView->model()); | ||
|
||
QStandardItem* item = listViewModel->item(itemIndex); | ||
|
||
if (item) { | ||
if (checked) { | ||
item->setCheckState(Qt::Checked); | ||
} else { | ||
item->setCheckState(Qt::Unchecked); | ||
} | ||
} | ||
} | ||
|
||
QList<int> KeyAcceptDialog::getCheckedItems() | ||
{ | ||
QStandardItemModel* listViewModel = qobject_cast<QStandardItemModel*>(ui->databasesListView->model()); | ||
|
||
int numRows = listViewModel->rowCount(); | ||
|
||
QList<int> resultList; | ||
|
||
for (int row = 0; row < numRows; row++) { | ||
QStandardItem* item = listViewModel->item(row); | ||
if (item->checkState() == Qt::Checked) { | ||
resultList << row; | ||
} | ||
} | ||
|
||
return resultList; | ||
} | ||
|
||
QString KeyAcceptDialog::getKeyName() | ||
{ | ||
return ui->keyNameLineEdit->text(); | ||
} | ||
|
||
void KeyAcceptDialog::checkAcceptable() | ||
{ | ||
QStandardItemModel* listViewModel = qobject_cast<QStandardItemModel*>(ui->databasesListView->model()); | ||
int numRows = listViewModel->rowCount(); | ||
bool hasChecked = false; | ||
for (int row = 0; row < numRows; row++) { | ||
QStandardItem* item = listViewModel->item(row); | ||
if (item->checkState() == Qt::Checked) { | ||
hasChecked = true; | ||
break; | ||
} | ||
} | ||
|
||
if (getKeyName().isEmpty()) { | ||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||
ui->buttonBox->button(QDialogButtonBox::Ok)->setToolTip(tr("Make sure the key name is not empty!")); | ||
} else if (!hasChecked) { | ||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||
ui->buttonBox->button(QDialogButtonBox::Ok)->setToolTip(tr("Check at least one database")); | ||
} else { | ||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | ||
ui->buttonBox->button(QDialogButtonBox::Ok)->setToolTip(""); | ||
} | ||
} | ||
|
||
void KeyAcceptDialog::keyEditChanged(const QString& text) | ||
{ | ||
(void)text; | ||
|
||
checkAcceptable(); | ||
} | ||
|
||
void KeyAcceptDialog::modelItemChanged(QStandardItem* item) | ||
{ | ||
(void)item; | ||
|
||
checkAcceptable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2013 Francois Ferrand | ||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> | ||
* | ||
* 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 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef KEYACCEPTDIALOG_H | ||
#define KEYACCEPTDIALOG_H | ||
|
||
#include <QDialog> | ||
#include <QScopedPointer> | ||
#include <QStandardItem> | ||
|
||
namespace Ui | ||
{ | ||
class KeyAcceptDialog; | ||
} | ||
|
||
class KeyAcceptDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit KeyAcceptDialog(QWidget* parent = nullptr); | ||
~KeyAcceptDialog(); | ||
|
||
void setItems(const QList<QString>& items); | ||
void setItemChecked(int itemIndex, bool checked); | ||
void setItemEnabled(int itemIndex, bool enabled); | ||
QList<int> getCheckedItems(); | ||
|
||
QString getKeyName(); | ||
|
||
void checkAcceptable(); | ||
|
||
private slots: | ||
void keyEditChanged(const QString& text); | ||
void modelItemChanged(QStandardItem* item); | ||
|
||
private: | ||
QScopedPointer<Ui::KeyAcceptDialog> ui; | ||
}; | ||
|
||
#endif // KEYACCEPTDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>KeyAcceptDialog</class> | ||
<widget class="QDialog" name="KeyAcceptDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>469</width> | ||
<height>292</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>KeePassXC: New key association request</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string><html><head/><body><p>You have received an association request for the above key.<br>If you would like to allow it access to your KeePassXC database,<br>give it a unique name to identify and accept it.</p></body></html></string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QLineEdit" name="keyNameLineEdit"/> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string><html><head/><body><p>Which databases should this key be valid for?<br>(The currently selected database is pre-selected; grayed-out databases are not opened - open them to enable accepting key!)</p></body></html></string> | ||
</property> | ||
<property name="wordWrap"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QListView" name="databasesListView"/> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>KeyAcceptDialog</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>KeyAcceptDialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay to stack-allocate (? - I am not sure if that is what happens, and whether Qt transforms that into something else)
resultList
here and then return it to the caller, where the caller will simply let it go out of scope?I.e. will the object be destroyed once it runs out of scope in the caller, and is this the proper way to do it or should this be done differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered on second question