Skip to content

Commit

Permalink
Implement review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
phoerious committed Oct 19, 2018
1 parent bea31f9 commit 0ca7fd3
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ QJsonObject BrowserAction::getErrorReply(const QString& action, const int errorC
QJsonObject BrowserAction::buildMessage(const QString& nonce) const
{
QJsonObject message;
message["version"] = KEEPASSX_VERSION;
message["version"] = KEEPASSXC_VERSION;
message["success"] = "true";
message["nonce"] = nonce;
return message;
Expand Down
5 changes: 3 additions & 2 deletions src/cli/Remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ int Remove::removeEntry(Database* database, const QString& databasePath, const Q
QTextStream out(Utils::STDOUT, QIODevice::WriteOnly);
QTextStream err(Utils::STDERR, QIODevice::WriteOnly);

Entry* entry = database->rootGroup()->findEntryByPath(entryPath);
QPointer<Entry> entry = database->rootGroup()->findEntryByPath(entryPath);
if (!entry) {
err << QObject::tr("Entry %1 not found.").arg(entryPath) << endl;
return EXIT_FAILURE;
}

QString entryTitle = entry->title();
bool recycled = true;
if (Tools::hasChild(database->metadata()->recycleBin(), entry) || !database->metadata()->recycleBinEnabled()) {
auto* recycleBin = database->metadata()->recycleBin();
if (!database->metadata()->recycleBinEnabled() || (recycleBin && recycleBin->findEntryByUuid(entry->uuid()))) {
delete entry;
recycled = false;
} else {
Expand Down
7 changes: 5 additions & 2 deletions src/cli/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void setStdinEcho(bool enable = true)
#endif
}

namespace Test
{
QStringList nextPasswords = {};

/**
Expand All @@ -85,6 +87,7 @@ void setNextPassword(const QString& password)
{
nextPasswords.append(password);
}
} // namespace Test

/**
* Read a user password from STDIN or return a password previously
Expand All @@ -97,8 +100,8 @@ QString getPassword()
QTextStream out(STDOUT, QIODevice::WriteOnly);

// return preset password if one is set
if (!nextPasswords.isEmpty()) {
auto password = nextPasswords.takeFirst();
if (!Test::nextPasswords.isEmpty()) {
auto password = Test::nextPasswords.takeFirst();
// simulate user entering newline
out << endl;
return password;
Expand Down
6 changes: 5 additions & 1 deletion src/cli/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ extern FILE* STDIN;

void setStdinEcho(bool enable);
QString getPassword();
void setNextPassword(const QString& password);
int clipText(const QString& text);

namespace Test
{
void setNextPassword(const QString& password);
}
};

#endif // KEEPASSXC_UTILS_H
4 changes: 2 additions & 2 deletions src/cli/keepassxc-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char** argv)
}

QCoreApplication app(argc, argv);
QCoreApplication::setApplicationVersion(KEEPASSX_VERSION);
QCoreApplication::setApplicationVersion(KEEPASSXC_VERSION);

#ifdef QT_NO_DEBUG
Bootstrap::bootstrapApplication();
Expand Down Expand Up @@ -72,7 +72,7 @@ int main(int argc, char** argv)
if (parser.positionalArguments().empty()) {
if (parser.isSet("version")) {
// Switch to parser.showVersion() when available (QT 5.4).
out << KEEPASSX_VERSION << endl;
out << KEEPASSXC_VERSION << endl;
return EXIT_SUCCESS;
}
parser.showHelp();
Expand Down
2 changes: 1 addition & 1 deletion src/config-keepassx.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef KEEPASSX_CONFIG_KEEPASSX_H
#define KEEPASSX_CONFIG_KEEPASSX_H

#define KEEPASSX_VERSION "@KEEPASSXC_VERSION@"
#define KEEPASSXC_VERSION "@KEEPASSXC_VERSION@"

#define KEEPASSX_SOURCE_DIR "@CMAKE_SOURCE_DIR@"
#define KEEPASSX_BINARY_DIR "@CMAKE_BINARY_DIR@"
Expand Down
15 changes: 0 additions & 15 deletions src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,6 @@ QString humanReadableFileSize(qint64 bytes, quint32 precision)
return QString("%1 %2").arg(QLocale().toString(size, 'f', precision), units.at(i));
}

bool hasChild(const QObject* parent, const QObject* child)
{
if (!parent || !child) {
return false;
}

const QObjectList children = parent->children();
for (QObject* c : children) {
if (child == c || hasChild(c, child)) {
return true;
}
}
return false;
}

bool readFromDevice(QIODevice* device, QByteArray& data, int size)
{
QByteArray buffer;
Expand Down
1 change: 0 additions & 1 deletion src/core/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class QIODevice;
namespace Tools
{
QString humanReadableFileSize(qint64 bytes, quint32 precision = 2);
bool hasChild(const QObject* parent, const QObject* child);
bool readFromDevice(QIODevice* device, QByteArray& data, int size = 16384);
bool readAllFromDevice(QIODevice* device, QByteArray& data);
QString imageReaderFilter();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AboutDialog::AboutDialog(QWidget* parent)
setWindowFlags(Qt::Sheet);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

m_ui->nameLabel->setText(m_ui->nameLabel->text().replace("${VERSION}", KEEPASSX_VERSION));
m_ui->nameLabel->setText(m_ui->nameLabel->text().replace("${VERSION}", KEEPASSXC_VERSION));
QFont nameLabelFont = m_ui->nameLabel->font();
nameLabelFont.setPointSize(nameLabelFont.pointSize() + 4);
m_ui->nameLabel->setFont(nameLabelFont);
Expand All @@ -52,7 +52,7 @@ AboutDialog::AboutDialog(QWidget* parent)
}

QString debugInfo = "KeePassXC - ";
debugInfo.append(tr("Version %1").arg(KEEPASSX_VERSION).append("\n"));
debugInfo.append(tr("Version %1").arg(KEEPASSXC_VERSION).append("\n"));
#ifndef KEEPASSXC_BUILD_TYPE_RELEASE
debugInfo.append(tr("Build Type: %1").arg(KEEPASSXC_BUILD_TYPE).append("\n"));
#endif
Expand Down
8 changes: 5 additions & 3 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ void DatabaseWidget::deleteEntries()
selectedEntries.append(m_entryView->entryFromIndex(index));
}

bool inRecycleBin = Tools::hasChild(m_db->metadata()->recycleBin(), selectedEntries.first());
auto* recycleBin = m_db->metadata()->recycleBin();
bool inRecycleBin = recycleBin && recycleBin->findEntryByUuid(selectedEntries.first()->uuid());
if (inRecycleBin || !m_db->metadata()->recycleBinEnabled()) {
QString prompt;
if (selected.size() == 1) {
Expand Down Expand Up @@ -688,9 +689,10 @@ void DatabaseWidget::deleteGroup()
return;
}

bool inRecycleBin = Tools::hasChild(m_db->metadata()->recycleBin(), currentGroup);
auto* recycleBin = m_db->metadata()->recycleBin();
bool inRecycleBin = recycleBin && recycleBin->findGroupByUuid(currentGroup->uuid());
bool isRecycleBin = (currentGroup == m_db->metadata()->recycleBin());
bool isRecycleBinSubgroup = Tools::hasChild(currentGroup, m_db->metadata()->recycleBin());
bool isRecycleBinSubgroup = currentGroup->findGroupByUuid(m_db->metadata()->recycleBin()->uuid());
if (inRecycleBin || isRecycleBin || isRecycleBinSubgroup || !m_db->metadata()->recycleBinEnabled()) {
QMessageBox::StandardButton result = MessageBox::question(
this,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/WelcomeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ WelcomeWidget::WelcomeWidget(QWidget* parent)
{
m_ui->setupUi(this);

m_ui->welcomeLabel->setText(tr("Welcome to KeePassXC %1").arg(KEEPASSX_VERSION));
m_ui->welcomeLabel->setText(tr("Welcome to KeePassXC %1").arg(KEEPASSXC_VERSION));
QFont welcomeLabelFont = m_ui->welcomeLabel->font();
welcomeLabelFont.setBold(true);
welcomeLabelFont.setPointSize(welcomeLabelFont.pointSize() + 4);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/group/GroupModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ bool GroupModel::dropMimeData(const QMimeData* data,
}

Group* dragGroup = db->resolveGroup(groupUuid);
if (!dragGroup || !Tools::hasChild(db, dragGroup) || dragGroup == db->rootGroup()) {
if (!dragGroup || !db->rootGroup()->findGroupByUuid(dragGroup->uuid()) || dragGroup == db->rootGroup()) {
return false;
}

if (dragGroup == parentGroup || Tools::hasChild(dragGroup, parentGroup)) {
if (dragGroup == parentGroup || dragGroup->findGroupByUuid(parentGroup->uuid())) {
return false;
}

Expand Down Expand Up @@ -278,7 +278,7 @@ bool GroupModel::dropMimeData(const QMimeData* data,
}

Entry* dragEntry = db->resolveEntry(entryUuid);
if (!dragEntry || !Tools::hasChild(db, dragEntry)) {
if (!dragEntry || !db->rootGroup()->findEntryByUuid(dragEntry->uuid())) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char** argv)
{
Application app(argc, argv);
Application::setApplicationName("keepassxc");
Application::setApplicationVersion(KEEPASSX_VERSION);
Application::setApplicationVersion(KEEPASSXC_VERSION);
// don't set organizationName as that changes the return value of
// QStandardPaths::writableLocation(QDesktopServices::DataLocation)
Bootstrap::bootstrapApplication();
Expand Down
Loading

0 comments on commit 0ca7fd3

Please sign in to comment.