Apply clang-format

This commit is contained in:
Martchus 2017-05-01 03:26:04 +02:00
parent 1c033b4746
commit f5bdf4c438
26 changed files with 721 additions and 739 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ Makefile*
# documentation
/doc
# clang-format
/.clang-format

View File

@ -1,18 +1,18 @@
#include "./cli.h"
#include <passwordfile/io/passwordfile.h>
#include <passwordfile/io/cryptoexception.h>
#include <passwordfile/io/parsingexception.h>
#include <passwordfile/io/entry.h>
#include <passwordfile/io/field.h>
#include <passwordfile/io/parsingexception.h>
#include <passwordfile/io/passwordfile.h>
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/application/commandlineutils.h>
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/catchiofailure.h>
#if defined(PLATFORM_UNIX)
#include <unistd.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <unistd.h>
#endif
#include <algorithm>
@ -53,26 +53,26 @@ InputMuter::~InputMuter()
void clearConsole()
{
#if defined(PLATFORM_WINDOWS)
HANDLE hStdOut;
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = {0, 0};
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(hStdOut == INVALID_HANDLE_VALUE) {
if (hStdOut == INVALID_HANDLE_VALUE) {
return;
}
// get the number of cells in the current buffer
if(!GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
return;
}
cellCount = csbi.dwSize.X * csbi.dwSize.Y;
// fill the entire buffer with spaces
if(!FillConsoleOutputCharacter(hStdOut, (TCHAR) ' ', cellCount, homeCoords, &count)) {
if (!FillConsoleOutputCharacter(hStdOut, (TCHAR)' ', cellCount, homeCoords, &count)) {
return;
}
// fill the entire buffer with the current colors and attributes
if(!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count)) {
if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count)) {
return;
}
// move the cursor home
@ -83,25 +83,25 @@ void clearConsole()
#endif
}
InteractiveCli::InteractiveCli() :
m_o(cout),
m_i(cin),
m_currentEntry(nullptr),
m_modified(false),
m_quit(false)
InteractiveCli::InteractiveCli()
: m_o(cout)
, m_i(cin)
, m_currentEntry(nullptr)
, m_modified(false)
, m_quit(false)
{
CMD_UTILS_START_CONSOLE;
}
void InteractiveCli::run(const string &file)
{
if(!file.empty()) {
if (!file.empty()) {
openFile(file, false);
}
string input;
while(!m_quit) {
while (!m_quit) {
getline(m_i, input);
if(!input.empty()) {
if (!input.empty()) {
processCommand(input);
}
}
@ -116,60 +116,60 @@ void InteractiveCli::processCommand(const string &cmd)
string param;
bool paramMissing = false;
if(CMD2("quit", "q")) {
if (CMD2("quit", "q")) {
quit();
} else if(CMD("q!")) {
} else if (CMD("q!")) {
m_quit = true;
} else if(CMD("wq")) {
} else if (CMD("wq")) {
saveFile();
m_quit = true;
} else if(CMD2("clear", "c")) {
} else if (CMD2("clear", "c")) {
clearConsole();
} else if(CMD2_P("openreadonly", "or")) {
} else if (CMD2_P("openreadonly", "or")) {
openFile(param, true);
} else if(CMD2_P("open", "o")) {
} else if (CMD2_P("open", "o")) {
openFile(param, false);
} else if(CMD2("close", "c")) {
} else if (CMD2("close", "c")) {
closeFile();
} else if(CMD2("save", "w")) {
} else if (CMD2("save", "w")) {
saveFile();
} else if(CMD2_P("create", "cr")) {
} else if (CMD2_P("create", "cr")) {
createFile(param);
} else if(CMD("chpassphrase")) {
} else if (CMD("chpassphrase")) {
changePassphrase();
} else if(CMD("rmpassphrase")) {
} else if (CMD("rmpassphrase")) {
removePassphrase();
} else if(CMD("pwd")) {
} else if (CMD("pwd")) {
pwd();
} else if(CMD_P("cd")) {
} else if (CMD_P("cd")) {
cd(param);
} else if(CMD("ls")) {
} else if (CMD("ls")) {
ls();
} else if(CMD2("tree", "t")) {
} else if (CMD2("tree", "t")) {
tree();
} else if(CMD2_P("mknode", "mkn")) {
} else if (CMD2_P("mknode", "mkn")) {
makeEntry(EntryType::Node, param);
} else if(CMD2_P("mkaccount", "mka")) {
} else if (CMD2_P("mkaccount", "mka")) {
makeEntry(EntryType::Account, param);
} else if(CMD2("rmentry", "rme")) {
} else if (CMD2("rmentry", "rme")) {
removeEntry(".");
} else if(CMD2_P("rmentry", "rme")) {
} else if (CMD2_P("rmentry", "rme")) {
removeEntry(param);
} else if(CMD2_P("rnentry", "rne")) {
} else if (CMD2_P("rnentry", "rne")) {
renameEntry(param);
} else if(CMD2_P("mventry", "me")) {
} else if (CMD2_P("mventry", "me")) {
moveEntry(param);
} else if(CMD2_P("readfield", "rf")) {
} else if (CMD2_P("readfield", "rf")) {
readField(param);
} else if(CMD2_P("setfield", "sf")) {
} else if (CMD2_P("setfield", "sf")) {
setField(false, param);
} else if(CMD2_P("setfieldpw", "sp")) {
} else if (CMD2_P("setfieldpw", "sp")) {
setField(true, param);
} else if(CMD2_P("rmfield", "rf")) {
} else if (CMD2_P("rmfield", "rf")) {
removeField(param);
} else if(CMD2("help", "?")) {
} else if (CMD2("help", "?")) {
printHelp();
} else if(paramMissing) {
} else if (paramMissing) {
m_o << "parameter is missing" << endl;
} else {
m_o << "command is unknown" << endl;
@ -180,26 +180,26 @@ Entry *InteractiveCli::resolvePath(const string &path)
{
auto parts = splitString<vector<string> >(path, "/", EmptyPartsTreat::Merge);
bool fromRoot = path.at(0) == '/';
if(fromRoot && parts.empty()) {
if (fromRoot && parts.empty()) {
return m_file.rootEntry();
} else {
Entry *entry = fromRoot ? m_file.rootEntry() : m_currentEntry;
for(const string &part : parts) {
if(part == "..") {
if(entry->parent()) {
for (const string &part : parts) {
if (part == "..") {
if (entry->parent()) {
entry = entry->parent();
} else {
m_o << "can not resolve path; entry \"" << entry->label() << "\" is root" << endl;
return nullptr;
}
} else if(part != ".") {
switch(entry->type()) {
} else if (part != ".") {
switch (entry->type()) {
case EntryType::Account:
m_o << "can not resolve path; entry \"" << entry->label() << "\" is not a node entry" << endl;
return nullptr;
case EntryType::Node:
for(Entry *child : (static_cast<NodeEntry *>(entry)->children())) {
if(child->label() == part) {
for (Entry *child : (static_cast<NodeEntry *>(entry)->children())) {
if (child->label() == part) {
entry = child;
goto next;
}
@ -208,7 +208,7 @@ Entry *InteractiveCli::resolvePath(const string &path)
return nullptr;
}
}
next:;
next:;
}
return entry;
}
@ -216,10 +216,10 @@ Entry *InteractiveCli::resolvePath(const string &path)
bool InteractiveCli::checkCommand(const string &str, const char *phrase, std::string &param, bool &paramMissing)
{
for(auto i = str.cbegin(), end = str.cend(); i != end; ++i, ++phrase) {
if(*phrase == 0) {
if(*i == ' ') {
if(++i != end) {
for (auto i = str.cbegin(), end = str.cend(); i != end; ++i, ++phrase) {
if (*phrase == 0) {
if (*i == ' ') {
if (++i != end) {
param.assign(i, end);
return true;
} else {
@ -227,7 +227,7 @@ bool InteractiveCli::checkCommand(const string &str, const char *phrase, std::st
}
}
return false;
} else if(*i != *phrase) {
} else if (*i != *phrase) {
return false;
}
}
@ -237,14 +237,14 @@ bool InteractiveCli::checkCommand(const string &str, const char *phrase, std::st
void InteractiveCli::openFile(const string &file, bool readOnly)
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
m_o << "file \"" << m_file.path() << "\" currently open; close first" << endl;
} else {
m_file.setPath(file);
try {
try {
m_file.open(readOnly);
if(m_file.isEncryptionUsed()) {
if (m_file.isEncryptionUsed()) {
m_file.setPassword(askForPassphrase());
}
m_file.load();
@ -256,13 +256,13 @@ void InteractiveCli::openFile(const string &file, bool readOnly)
} catch (const CryptoException &) {
m_o << "error occured when decrypting file \"" << file << "\"" << endl;
throw;
} catch(...) {
} catch (...) {
const char *what = catchIoFailure();
m_o << "IO error occured when opening file \"" << file << "\"" << endl;
throw ios_base::failure(what);
}
} catch(const std::exception &e) {
if(*e.what() != 0) {
} catch (const std::exception &e) {
if (*e.what() != 0) {
m_o << e.what() << endl;
}
m_file.clear();
@ -274,7 +274,7 @@ void InteractiveCli::openFile(const string &file, bool readOnly)
void InteractiveCli::closeFile()
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
m_file.clear();
m_currentEntry = nullptr;
m_o << "file closed" << endl;
@ -285,7 +285,7 @@ void InteractiveCli::closeFile()
void InteractiveCli::saveFile()
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
try {
try {
m_file.save(*m_file.password());
@ -301,8 +301,8 @@ void InteractiveCli::saveFile()
m_o << "IO error occured when saving file \"" << m_file.path() << "\"" << endl;
throw ios_base::failure(what);
}
} catch(const exception &e) {
if(*e.what() != 0) {
} catch (const exception &e) {
if (*e.what() != 0) {
m_o << e.what() << endl;
}
m_o << "file has been closed; try reopening the file" << endl;
@ -316,7 +316,7 @@ void InteractiveCli::saveFile()
void InteractiveCli::createFile(const string &file)
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
m_o << "file \"" << m_file.path() << "\" currently open; close first" << endl;
} else {
m_file.setPath(file);
@ -331,8 +331,8 @@ void InteractiveCli::createFile(const string &file)
m_o << "IO error occured when creating file \"" << file << "\"" << endl;
throw ios_base::failure(what);
}
} catch(exception &e) {
if(*e.what() != 0) {
} catch (exception &e) {
if (*e.what() != 0) {
m_o << e.what() << endl;
}
m_file.clear();
@ -344,12 +344,12 @@ void InteractiveCli::createFile(const string &file)
void InteractiveCli::changePassphrase()
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
try {
m_file.setPassword(askForPassphrase(true));
m_modified = true;
m_o << "passphrase changed; use save to apply" << endl;
} catch(runtime_error &) {
} catch (runtime_error &) {
m_o << "passphrase has not changed" << endl;
}
} else {
@ -359,8 +359,8 @@ void InteractiveCli::changePassphrase()
void InteractiveCli::removePassphrase()
{
if(m_file.isOpen()) {
if(*m_file.password()) {
if (m_file.isOpen()) {
if (*m_file.password()) {
m_file.clearPassword();
m_o << "passphrase removed; use save to apply" << endl;
m_modified = true;
@ -374,7 +374,7 @@ void InteractiveCli::removePassphrase()
void InteractiveCli::pwd()
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
auto path = m_currentEntry->path();
m_o << path.front() << ": /";
path.pop_front();
@ -386,8 +386,8 @@ void InteractiveCli::pwd()
void InteractiveCli::cd(const string &path)
{
if(m_file.isOpen()) {
if(Entry *entry = resolvePath(path)) {
if (m_file.isOpen()) {
if (Entry *entry = resolvePath(path)) {
m_currentEntry = entry;
m_o << "changed to \"" << entry->label() << "\"" << endl;
}
@ -398,17 +398,18 @@ void InteractiveCli::cd(const string &path)
void InteractiveCli::ls()
{
if(m_file.isOpen()) {
switch(m_currentEntry->type()) {
if (m_file.isOpen()) {
switch (m_currentEntry->type()) {
case EntryType::Account: {
m_o << "fields:";
for(const Field &field : static_cast<AccountEntry *>(m_currentEntry)->fields()) {
for (const Field &field : static_cast<AccountEntry *>(m_currentEntry)->fields()) {
m_o << " " << field.name();
}
break;
} case EntryType::Node: {
}
case EntryType::Node: {
m_o << "entries:";
for(const Entry *entry : static_cast<NodeEntry *>(m_currentEntry)->children()) {
for (const Entry *entry : static_cast<NodeEntry *>(m_currentEntry)->children()) {
m_o << " " << entry->label();
}
break;
@ -422,15 +423,15 @@ void InteractiveCli::ls()
void InteractiveCli::tree()
{
if(m_file.isOpen()) {
if (m_file.isOpen()) {
function<void(const Entry *entry, unsigned char level)> printEntries;
printEntries = [&printEntries, this] (const Entry *entry, unsigned char level) {
for(unsigned char i = 0; i < level; ++i) {
printEntries = [&printEntries, this](const Entry *entry, unsigned char level) {
for (unsigned char i = 0; i < level; ++i) {
m_o << " ";
}
m_o << entry->label() << endl;
if(entry->type() == EntryType::Node) {
for(const Entry *child : (static_cast<const NodeEntry *>(entry)->children())) {
if (entry->type() == EntryType::Node) {
for (const Entry *child : (static_cast<const NodeEntry *>(entry)->children())) {
printEntries(child, level + 2);
}
}
@ -443,10 +444,10 @@ void InteractiveCli::tree()
void InteractiveCli::makeEntry(EntryType entryType, const string &label)
{
if(m_file.isOpen()) {
switch(m_currentEntry->type()) {
if (m_file.isOpen()) {
switch (m_currentEntry->type()) {
case EntryType::Node:
switch(entryType) {
switch (entryType) {
case EntryType::Node:
m_o << "node entry \"" << (new NodeEntry(label, static_cast<NodeEntry *>(m_currentEntry)))->label() << "\" created" << endl;
break;
@ -466,12 +467,12 @@ void InteractiveCli::makeEntry(EntryType entryType, const string &label)
void InteractiveCli::removeEntry(const string &path)
{
if(m_file.isOpen()) {
if(Entry *entry = resolvePath(path)) {
if(entry == m_file.rootEntry()) {
if (m_file.isOpen()) {
if (Entry *entry = resolvePath(path)) {
if (entry == m_file.rootEntry()) {
m_o << "can not remove root entry" << endl;
} else {
if(entry == m_currentEntry) {
if (entry == m_currentEntry) {
m_currentEntry = entry->parent();
}
m_o << "removed entry \"" << entry->label() << "\"" << endl;
@ -486,12 +487,12 @@ void InteractiveCli::removeEntry(const string &path)
void InteractiveCli::renameEntry(const string &path)
{
if(m_file.isOpen()) {
if(Entry *entry = resolvePath(path)) {
if (m_file.isOpen()) {
if (Entry *entry = resolvePath(path)) {
string label;
m_o << "enter new name: " << endl;
getline(m_i, label);
if(label.empty()) {
if (label.empty()) {
m_o << "can not rename; new name is empty" << endl;
} else {
entry->setLabel(label);
@ -506,23 +507,23 @@ void InteractiveCli::renameEntry(const string &path)
void InteractiveCli::moveEntry(const string &path)
{
if(m_file.isOpen()) {
if(Entry *entry = resolvePath(path)) {
if (m_file.isOpen()) {
if (Entry *entry = resolvePath(path)) {
string newParentPath;
m_o << "enter path of new parent: " << endl;
getline(m_i, newParentPath);
if(newParentPath.empty()) {
if (newParentPath.empty()) {
m_o << "can not move; path of new parent is empty" << endl;
} else {
if(Entry *newParent = resolvePath(newParentPath)) {
switch(newParent->type()) {
if (Entry *newParent = resolvePath(newParentPath)) {
switch (newParent->type()) {
case EntryType::Account:
m_o << "can not move; new parent must be a node entry" << endl;
break;
case EntryType::Node:
if(entry->parent() == entry) {
if (entry->parent() == entry) {
m_o << "element not moved; parent doesn't change" << endl;
} else if(entry->type() == EntryType::Node && newParent->isIndirectChildOf(static_cast<NodeEntry *>(entry))) {
} else if (entry->type() == EntryType::Node && newParent->isIndirectChildOf(static_cast<NodeEntry *>(entry))) {
m_o << "can not move; new parent mustn't be child of the entry to move" << endl;
} else {
entry->setParent(static_cast<NodeEntry *>(newParent));
@ -540,17 +541,17 @@ void InteractiveCli::moveEntry(const string &path)
void InteractiveCli::readField(const string &fieldName)
{
if(m_file.isOpen()) {
if(m_currentEntry->type() == EntryType::Account) {
if (m_file.isOpen()) {
if (m_currentEntry->type() == EntryType::Account) {
const vector<Field> &fields = static_cast<AccountEntry *>(m_currentEntry)->fields();
bool valuesFound = false;
for(const Field &field : fields) {
if(field.name() == fieldName) {
for (const Field &field : fields) {
if (field.name() == fieldName) {
m_o << field.value() << endl;
valuesFound = true;
}
}
if(!valuesFound) {
if (!valuesFound) {
m_o << "field \"" << fieldName << "\" does not exist" << endl;
}
} else {
@ -563,40 +564,40 @@ void InteractiveCli::readField(const string &fieldName)
void InteractiveCli::setField(bool useMuter, const string &fieldName)
{
if(m_file.isOpen()) {
if(m_currentEntry->type() == EntryType::Account) {
if (m_file.isOpen()) {
if (m_currentEntry->type() == EntryType::Account) {
vector<Field> &fields = static_cast<AccountEntry *>(m_currentEntry)->fields();
unsigned int valuesFound = 0;
string value;
m_o << "enter new value: ";
if(useMuter) {
if (useMuter) {
InputMuter m;
getline(m_i, value);
m_o << endl << "repeat: ";
string repeat;
getline(m_i, repeat);
if(value != repeat) {
if (value != repeat) {
m_o << "values do not match; field has not been altered" << endl;
return;
}
} else {
getline(m_i, value);
}
for(Field &field : fields) {
if(field.name() == fieldName) {
for (Field &field : fields) {
if (field.name() == fieldName) {
++valuesFound;
if(valuesFound == 1) {
if (valuesFound == 1) {
field.setValue(value);
} else {
m_o << "enter new value for " << valuesFound << ". field (with the specified field): ";
value.clear();
if(useMuter) {
if (useMuter) {
InputMuter m;
getline(m_i, value);
m_o << endl << "repeat: ";
string repeat;
getline(m_i, repeat);
if(value == repeat) {
if (value == repeat) {
field.setValue(value);
} else {
m_o << "values do not match; field has not been altered" << endl;
@ -609,10 +610,10 @@ void InteractiveCli::setField(bool useMuter, const string &fieldName)
field.setType(useMuter ? FieldType::Password : FieldType::Normal);
}
}
switch(valuesFound) {
switch (valuesFound) {
case 0:
fields.emplace_back(static_cast<AccountEntry *>(m_currentEntry), fieldName, value);
if(useMuter) {
if (useMuter) {
fields.back().setType(FieldType::Password);
}
m_o << "new field with value inserted" << endl;
@ -635,27 +636,25 @@ void InteractiveCli::setField(bool useMuter, const string &fieldName)
void InteractiveCli::removeField(const string &fieldName)
{
if(m_file.isOpen()) {
if(m_currentEntry->type() == EntryType::Account) {
if (m_file.isOpen()) {
if (m_currentEntry->type() == EntryType::Account) {
vector<Field> &fields = static_cast<AccountEntry *>(m_currentEntry)->fields();
unsigned int valuesFound = 0;
for(Field &field : fields) {
if(field.name() == fieldName) {
for (Field &field : fields) {
if (field.name() == fieldName) {
++valuesFound;
}
}
switch(valuesFound) {
valuesFound = 0;
switch (valuesFound) {
valuesFound = 0;
case 0:
break;
case 1:
fields.erase(remove_if(fields.begin(), fields.end(), [&fieldName] (Field &field) {
return field.name() == fieldName;
}));
fields.erase(remove_if(fields.begin(), fields.end(), [&fieldName](Field &field) { return field.name() == fieldName; }));
break;
default:
fields.erase(remove_if(fields.begin(), fields.end(), [this, &fieldName, &valuesFound] (Field &field) {
if(field.name() == fieldName) {
fields.erase(remove_if(fields.begin(), fields.end(), [this, &fieldName, &valuesFound](Field &field) {
if (field.name() == fieldName) {
m_o << "remove " << ++valuesFound << ". occurrence? [y]=yes, different key=no " << endl;
string res;
getline(m_i, res);
@ -665,7 +664,7 @@ void InteractiveCli::removeField(const string &fieldName)
}
}));
}
switch(valuesFound) {
switch (valuesFound) {
case 0:
m_o << "can not remove field; specified field \"" << fieldName << "\" not found" << endl;
break;
@ -714,12 +713,13 @@ void InteractiveCli::printHelp()
"readfield,rf reads the specified field of the current account\n"
"setfield,sf sets the specified field of the current account\n"
"setfieldpw,sp sets the specified password field of the current account\n"
"rmfield,rf removes the specified field of the current account\n" << endl;
"rmfield,rf removes the specified field of the current account\n"
<< endl;
}
void InteractiveCli::quit()
{
if(m_file.isOpen() && m_modified) {
if (m_file.isOpen() && m_modified) {
m_o << "file modified; use q! or wq" << endl;
} else {
m_quit = true;
@ -728,7 +728,7 @@ void InteractiveCli::quit()
string InteractiveCli::askForPassphrase(bool confirm)
{
if(confirm) {
if (confirm) {
m_o << "enter new passphrase: ";
} else {
m_o << "enter passphrase: ";
@ -740,10 +740,10 @@ string InteractiveCli::askForPassphrase(bool confirm)
getline(m_i, input1);
}
m_o << endl;
if(input1.empty()) {
if (input1.empty()) {
m_o << "you did not enter a passphrase" << endl;
} else {
if(confirm) {
if (confirm) {
m_o << "confirm new passphrase: ";
m_o.flush();
string input2;
@ -752,7 +752,7 @@ string InteractiveCli::askForPassphrase(bool confirm)
getline(m_i, input2);
}
m_o << endl;
if(input1 != input2) {
if (input1 != input2) {
m_o << "phrases do not match" << endl;
throw runtime_error("confirmation failed");
}
@ -760,6 +760,4 @@ string InteractiveCli::askForPassphrase(bool confirm)
}
return input1;
}
}

View File

@ -4,15 +4,15 @@
#include <passwordfile/io/passwordfile.h>
#if defined(PLATFORM_UNIX)
# include <termios.h>
#include <termios.h>
#elif defined(PLATFORM_WINDOWS)
# include <windows.h>
#include <windows.h>
#endif
#include <string>
#include <vector>
#include <istream>
#include <ostream>
#include <string>
#include <vector>
namespace ApplicationUtilities {
typedef std::vector<std::string> StringVector;
@ -25,8 +25,7 @@ enum class EntryType : int;
namespace Cli {
class InputMuter
{
class InputMuter {
public:
InputMuter();
~InputMuter();
@ -42,8 +41,7 @@ private:
void clearConsole();
class InteractiveCli
{
class InteractiveCli {
public:
InteractiveCli();
void run(const std::string &file = std::string());
@ -80,7 +78,6 @@ private:
bool m_modified;
bool m_quit;
};
}
#endif // CLI_CLI_H

View File

@ -11,18 +11,20 @@ using namespace Io;
namespace QtGui {
FieldDelegate::FieldDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{}
FieldDelegate::FieldDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
void FieldDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if(auto *lineEdit = qobject_cast<QLineEdit *>(editor)) {
if (auto *lineEdit = qobject_cast<QLineEdit *>(editor)) {
const auto *model = index.model();
lineEdit->setText(model->data(index, Qt::EditRole).toString());
if(const auto *fieldModel = qobject_cast<const FieldModel *>(model)) {
if(fieldModel->passwordVisibility() == PasswordVisibility::Never) {
lineEdit->setEchoMode(fieldModel->field(static_cast<size_t>(index.row()))->type() != FieldType::Password ? QLineEdit::Normal : QLineEdit::Password);
if (const auto *fieldModel = qobject_cast<const FieldModel *>(model)) {
if (fieldModel->passwordVisibility() == PasswordVisibility::Never) {
lineEdit->setEchoMode(
fieldModel->field(static_cast<size_t>(index.row()))->type() != FieldType::Password ? QLineEdit::Normal : QLineEdit::Password);
} else {
lineEdit->setEchoMode(QLineEdit::Normal);
}
@ -35,4 +37,3 @@ void FieldDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con
}
} // namespace QtGui

View File

@ -5,8 +5,7 @@
namespace QtGui {
class FieldDelegate : public QStyledItemDelegate
{
class FieldDelegate : public QStyledItemDelegate {
public:
FieldDelegate(QObject *parent = nullptr);

View File

@ -12,7 +12,6 @@ class QtConfigArguments;
namespace QtGui {
int runWidgetsGui(int argc, char *argv[], const ApplicationUtilities::QtConfigArguments &qtConfigArgs, const QString &file);
}
#endif // INITIATE_H

View File

@ -4,14 +4,14 @@
#include "resources/config.h"
#include <qtutilities/resources/importplugin.h>
#include <qtutilities/resources/qtconfigarguments.h>
#include <qtutilities/resources/resources.h>
#include <qtutilities/resources/importplugin.h>
#include <qtutilities/settingsdialog/qtsettings.h>
#include <QApplication>
#include <QSettings>
#include <QFile>
#include <QSettings>
using namespace ApplicationUtilities;
using namespace Dialogs;
@ -27,7 +27,8 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
QtSettings qtSettings;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
// move old config to new location
const QString oldConfig = QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()).fileName();
const QString oldConfig
= QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()).fileName();
QFile::rename(oldConfig, settings.fileName()) || QFile::remove(oldConfig);
settings.sync();
qtSettings.restore(settings);
@ -38,7 +39,7 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
// init widgets GUI
MainWindow w(settings, &qtSettings);
w.show();
if(!file.isEmpty()) {
if (!file.isEmpty()) {
w.openFile(file);
}
// start event loop
@ -47,5 +48,4 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
qtSettings.save(settings);
return res;
}
}

View File

@ -1,9 +1,9 @@
#include "./mainwindow.h"
#include "./fielddelegate.h"
#include "../model/fieldmodel.h"
#include "../model/entrymodel.h"
#include "../model/entryfiltermodel.h"
#include "../model/entrymodel.h"
#include "../model/fieldmodel.h"
#include "ui_mainwindow.h"
@ -12,34 +12,34 @@
#include <passwordfile/io/cryptoexception.h>
#include <passwordfile/io/entry.h>
#include <qtutilities/enterpassworddialog/enterpassworddialog.h>
#include <qtutilities/misc/dialogutils.h>
#include <qtutilities/misc/desktoputils.h>
#include <qtutilities/misc/recentmenumanager.h>
#include <qtutilities/aboutdialog/aboutdialog.h>
#include <qtutilities/settingsdialog/settingsdialog.h>
#include <qtutilities/enterpassworddialog/enterpassworddialog.h>
#include <qtutilities/misc/desktoputils.h>
#include <qtutilities/misc/dialogutils.h>
#include <qtutilities/misc/recentmenumanager.h>
#include <qtutilities/settingsdialog/optioncategorymodel.h>
#include <qtutilities/settingsdialog/qtsettings.h>
#include <qtutilities/settingsdialog/settingsdialog.h>
#include <c++utilities/io/path.h>
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/io/path.h>
#include <QFileDialog>
#include <QMessageBox>
#include <QInputDialog>
#include <QActionGroup>
#include <QClipboard>
#include <QSettings>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QMimeData>
#include <QSettings>
#include <QTimerEvent>
#include <QUndoStack>
#include <QUndoView>
#include <QMimeData>
#include <QDesktopServices>
#include <stdexcept>
#include <cassert>
#include <stdexcept>
using namespace std;
using namespace IoUtilities;
@ -101,7 +101,7 @@ void MainWindow::setSomethingChanged()
*/
void MainWindow::setSomethingChanged(bool somethingChanged)
{
if(m_somethingChanged != somethingChanged) {
if (m_somethingChanged != somethingChanged) {
m_somethingChanged = somethingChanged;
updateWindowTitle();
}
@ -110,19 +110,21 @@ void MainWindow::setSomethingChanged(bool somethingChanged)
/*!
* \brief Constructs a new main window.
*/
MainWindow::MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings, QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow),
m_clearClipboardTimer(0),
m_aboutDlg(nullptr),
m_settings(settings),
m_qtSettings(qtSettings),
m_settingsDlg(nullptr)
MainWindow::MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings, QWidget *parent)
: QMainWindow(parent)
, m_ui(new Ui::MainWindow)
, m_clearClipboardTimer(0)
, m_aboutDlg(nullptr)
, m_settings(settings)
, m_qtSettings(qtSettings)
, m_settingsDlg(nullptr)
{
// setup ui
m_ui->setupUi(this);
#ifdef Q_OS_WIN32
setStyleSheet(QStringLiteral("%1 #splitter QWidget { background-color: palette(base); color: palette(text); } #splitter QWidget *, #splitter QWidget * { background-color: none; } #leftWidget { border-right: 1px solid %2; }").arg(dialogStyle(), windowFrameColor().name()));
setStyleSheet(QStringLiteral("%1 #splitter QWidget { background-color: palette(base); color: palette(text); } #splitter QWidget *, #splitter "
"QWidget * { background-color: none; } #leftWidget { border-right: 1px solid %2; }")
.arg(dialogStyle(), windowFrameColor().name()));
#endif
// set default values
setSomethingChanged(false);
@ -165,9 +167,9 @@ MainWindow::MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings, QWi
passwordVisibilityGroup->addAction(m_ui->actionHideAlways);
QString pwVisibility(settings.value(QStringLiteral("pwvisibility")).toString());
QAction *pwVisibilityAction;
if(pwVisibility == QStringLiteral("always")) {
if (pwVisibility == QStringLiteral("always")) {
pwVisibilityAction = m_ui->actionShowAlways;
} else if(pwVisibility == QStringLiteral("hidden")) {
} else if (pwVisibility == QStringLiteral("hidden")) {
pwVisibilityAction = m_ui->actionHideAlways;
} else {
pwVisibilityAction = m_ui->actionShowOnlyWhenEditing;
@ -225,43 +227,42 @@ MainWindow::MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings, QWi
* \brief Destroys the main window.
*/
MainWindow::~MainWindow()
{}
{
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(obj == m_undoView) {
switch(event->type()) {
if (obj == m_undoView) {
switch (event->type()) {
case QEvent::Hide:
m_ui->actionShowUndoStack->setChecked(false);
break;
default:
;
default:;
}
} else if(obj == m_ui->centralWidget) {
switch(event->type()) {
} else if (obj == m_ui->centralWidget) {
switch (event->type()) {
case QEvent::DragEnter:
case QEvent::Drop:
if(QDropEvent *dropEvent = static_cast<QDropEvent *>(event)) {
if (QDropEvent *dropEvent = static_cast<QDropEvent *>(event)) {
QString data;
const QMimeData *mimeData = dropEvent->mimeData();
if(mimeData->hasUrls()) {
if (mimeData->hasUrls()) {
const QUrl url = mimeData->urls().front();
if(url.scheme() == QLatin1String("file")) {
if (url.scheme() == QLatin1String("file")) {
data = url.path();
}
} else if(mimeData->hasText()) {
} else if (mimeData->hasText()) {
data = mimeData->text();
}
if(!data.isEmpty()) {
if (!data.isEmpty()) {
event->accept();
if(event->type() == QEvent::Drop) {
if (event->type() == QEvent::Drop) {
openFile(data);
}
}
return true;
}
default:
;
default:;
}
}
return QMainWindow::eventFilter(obj, event);
@ -270,14 +271,14 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
void MainWindow::closeEvent(QCloseEvent *event)
{
// ask if file is opened
if(m_file.hasRootEntry()) {
if(!closeFile()) {
if (m_file.hasRootEntry()) {
if (!closeFile()) {
event->ignore();
return;
}
}
// close undow view
if(m_undoView) {
if (m_undoView) {
m_undoView->close();
}
// save settings
@ -288,9 +289,9 @@ void MainWindow::closeEvent(QCloseEvent *event)
m_settings.setValue(QStringLiteral("accountfilter"), m_ui->accountFilterLineEdit->text());
m_settings.setValue(QStringLiteral("alwayscreatebackup"), m_ui->actionAlwaysCreateBackup->isChecked());
QString pwVisibility;
if(m_ui->actionShowAlways->isChecked()) {
if (m_ui->actionShowAlways->isChecked()) {
pwVisibility = QStringLiteral("always");
} else if(m_ui->actionHideAlways->isChecked()) {
} else if (m_ui->actionHideAlways->isChecked()) {
pwVisibility = QStringLiteral("hidden");
} else {
pwVisibility = QStringLiteral("editing");
@ -301,7 +302,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::timerEvent(QTimerEvent *event)
{
if(event->timerId() == m_clearClipboardTimer) {
if (event->timerId() == m_clearClipboardTimer) {
clearClipboard();
m_clearClipboardTimer = 0;
}
@ -312,15 +313,15 @@ void MainWindow::timerEvent(QTimerEvent *event)
*/
void MainWindow::showSettingsDialog()
{
if(!m_settingsDlg) {
if (!m_settingsDlg) {
m_settingsDlg = new SettingsDialog(this);
if(m_qtSettings) {
if (m_qtSettings) {
m_settingsDlg->setWindowTitle(tr("Qt settings"));
m_settingsDlg->setSingleCategory(m_qtSettings->category());
}
//connect(m_settingsDlg, &SettingsDialog::applied, this, &MainWindow::settingsAccepted);
}
if(m_settingsDlg->isHidden()) {
if (m_settingsDlg->isHidden()) {
m_settingsDlg->showNormal();
} else {
m_settingsDlg->activateWindow();
@ -332,8 +333,9 @@ void MainWindow::showSettingsDialog()
*/
void MainWindow::showAboutDialog()
{
if(!m_aboutDlg) {
m_aboutDlg = new AboutDialog(this, tr("A simple password store using AES-256-CBC encryption via OpenSSL."), QImage(":/icons/hicolor/128x128/apps/passwordmanager.png"));
if (!m_aboutDlg) {
m_aboutDlg = new AboutDialog(this, tr("A simple password store using AES-256-CBC encryption via OpenSSL."),
QImage(":/icons/hicolor/128x128/apps/passwordmanager.png"));
}
m_aboutDlg->show();
}
@ -343,7 +345,7 @@ void MainWindow::showAboutDialog()
*/
void MainWindow::showPassowrdGeneratorDialog()
{
PasswordGeneratorDialog* pwgDialog = new PasswordGeneratorDialog(this);
PasswordGeneratorDialog *pwgDialog = new PasswordGeneratorDialog(this);
pwgDialog->show();
}
@ -352,11 +354,12 @@ void MainWindow::showPassowrdGeneratorDialog()
*/
void MainWindow::showOpenFileDialog()
{
if(m_file.hasRootEntry() && !closeFile()) {
if (m_file.hasRootEntry() && !closeFile()) {
return;
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Select a password list"), QString(), tr("Password Manager files (*.pwmgr);;All files (*)"));
if(!fileName.isEmpty()) {
QString fileName
= QFileDialog::getOpenFileName(this, tr("Select a password list"), QString(), tr("Password Manager files (*.pwmgr);;All files (*)"));
if (!fileName.isEmpty()) {
openFile(fileName);
}
}
@ -366,10 +369,10 @@ void MainWindow::showOpenFileDialog()
*/
void MainWindow::showSaveFileDialog()
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return;
}
if(askForCreatingFile()) {
if (askForCreatingFile()) {
saveFile();
}
}
@ -379,8 +382,8 @@ void MainWindow::showSaveFileDialog()
*/
void MainWindow::showUndoView()
{
if(m_ui->actionShowUndoStack->isChecked()) {
if(!m_undoView) {
if (m_ui->actionShowUndoStack->isChecked()) {
if (!m_undoView) {
m_undoView = new QUndoView(m_undoStack);
m_undoView->setWindowTitle(tr("Undo stack"));
m_undoView->setWindowFlags(Qt::Tool);
@ -389,7 +392,7 @@ void MainWindow::showUndoView()
m_undoView->installEventFilter(this);
}
m_undoView->show();
} else if(m_undoView) {
} else if (m_undoView) {
m_undoView->hide();
}
}
@ -402,7 +405,7 @@ bool MainWindow::openFile(const QString &path)
{
using namespace Dialogs;
// close previous file
if(m_file.hasRootEntry() && !closeFile()) {
if (m_file.hasRootEntry() && !closeFile()) {
return false;
}
// set path and open file
@ -410,27 +413,30 @@ bool MainWindow::openFile(const QString &path)
try {
m_file.open();
} catch (...) {
const QString errmsg = tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(catchIoFailure()));
const QString errmsg
= tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(catchIoFailure()));
m_ui->statusBar->showMessage(errmsg, 5000);
QMessageBox::critical(this, QApplication::applicationName(), errmsg);
return false;
}
// warn before loading a very big file
if(m_file.size() > 10485760) {
if(QMessageBox::warning(this, QApplication::applicationName(), tr("The file you want to load seems to be very big. Do you really want to open it?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
if (m_file.size() > 10485760) {
if (QMessageBox::warning(this, QApplication::applicationName(),
tr("The file you want to load seems to be very big. Do you really want to open it?"), QMessageBox::Yes, QMessageBox::No)
== QMessageBox::No) {
m_file.clear();
return false;
}
}
// ask for a password if required
if(m_file.isEncryptionUsed()) {
if (m_file.isEncryptionUsed()) {
EnterPasswordDialog pwDlg(this);
pwDlg.setWindowTitle(tr("Opening file") + QStringLiteral(" - " APP_NAME));
pwDlg.setInstruction(tr("Enter the password to open the file \"%1\"").arg(path));
pwDlg.setPasswordRequired(true);
switch(pwDlg.exec()) {
switch (pwDlg.exec()) {
case QDialog::Accepted:
if(pwDlg.password().isEmpty()) {
if (pwDlg.password().isEmpty()) {
m_ui->statusBar->showMessage(tr("A password is needed to open the file."), 5000);
QMessageBox::warning(this, QApplication::applicationName(), tr("A password is needed to open the file."));
m_file.clear();
@ -441,8 +447,7 @@ bool MainWindow::openFile(const QString &path)
case QDialog::Rejected:
m_file.clear();
return false;
default:
;
default:;
}
m_file.setPassword(pwDlg.password().toStdString());
}
@ -450,21 +455,20 @@ bool MainWindow::openFile(const QString &path)
QString msg;
try {
m_file.load();
} catch(const CryptoException &e) {
} catch (const CryptoException &e) {
msg = tr("The file couldn't be decrypted.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(e.what()));
} catch (...) {
try {
msg = QString::fromLocal8Bit(catchIoFailure());
} catch(const runtime_error &e) {
} catch (const runtime_error &e) {
msg = tr("Unable to parse the file. %1").arg(QString::fromLocal8Bit(e.what()));
}
}
// show a message in the error case
if(!msg.isEmpty()) {
if (!msg.isEmpty()) {
m_file.clear();
m_ui->statusBar->showMessage(msg, 5000);
if(QMessageBox::critical(this, QApplication::applicationName(), msg,
QMessageBox::Cancel, QMessageBox::Retry) == QMessageBox::Retry) {
if (QMessageBox::critical(this, QApplication::applicationName(), msg, QMessageBox::Cancel, QMessageBox::Retry) == QMessageBox::Retry) {
return openFile(path); // retry
} else {
return false;
@ -482,7 +486,7 @@ bool MainWindow::openFile(const QString &path)
bool MainWindow::createFile()
{
// close previous file
if(m_file.hasRootEntry() && !closeFile()) {
if (m_file.hasRootEntry() && !closeFile()) {
return false;
}
m_file.generateRootEntry();
@ -505,7 +509,7 @@ void MainWindow::createFile(const QString &path)
void MainWindow::createFile(const QString &path, const QString &password)
{
// close previous file
if(m_file.hasRootEntry() && !closeFile()) {
if (m_file.hasRootEntry() && !closeFile()) {
return;
}
// set path and password
@ -532,7 +536,7 @@ bool MainWindow::showFile()
m_fieldModel->reset();
m_entryModel->setRootEntry(m_file.rootEntry());
applyDefaultExpanding(QModelIndex());
if(m_file.path().empty()) {
if (m_file.path().empty()) {
m_ui->statusBar->showMessage(tr("A new password list has been created."), 5000);
} else {
m_recentMgr->addEntry(QString::fromStdString(m_file.path()));
@ -569,8 +573,8 @@ void MainWindow::updateUiStatus()
void MainWindow::updateWindowTitle()
{
Dialogs::DocumentStatus docStatus;
if(m_file.hasRootEntry()) {
if(m_somethingChanged) {
if (m_file.hasRootEntry()) {
if (m_somethingChanged) {
docStatus = Dialogs::DocumentStatus::Unsaved;
} else {
docStatus = Dialogs::DocumentStatus::Saved;
@ -583,9 +587,9 @@ void MainWindow::updateWindowTitle()
void MainWindow::applyDefaultExpanding(const QModelIndex &parent)
{
for(int row = 0, rows = m_entryFilterModel->rowCount(parent); row < rows; ++row) {
for (int row = 0, rows = m_entryFilterModel->rowCount(parent); row < rows; ++row) {
QModelIndex index = m_entryFilterModel->index(row, 0, parent);
if(!index.isValid()) {
if (!index.isValid()) {
return;
}
applyDefaultExpanding(index);
@ -601,30 +605,30 @@ QString MainWindow::selectedFieldsString() const
{
QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
QString text;
if(!selectedIndexes.isEmpty()) {
if(selectedIndexes.size() > 1) {
if (!selectedIndexes.isEmpty()) {
if (selectedIndexes.size() > 1) {
int maxRow = m_fieldModel->rowCount() - 1;
int firstRow = maxRow, lastRow = 0;
int maxCol = m_fieldModel->columnCount() - 1;
int firstCol = maxCol, lastCol = 0;
for(const QModelIndex &index : selectedIndexes) {
if(index.row() < firstRow) {
for (const QModelIndex &index : selectedIndexes) {
if (index.row() < firstRow) {
firstRow = index.row();
}
if(index.row() > lastRow) {
if (index.row() > lastRow) {
lastRow = index.row();
}
if(index.column() < firstCol) {
if (index.column() < firstCol) {
firstCol = index.column();
}
if(index.column() > lastCol) {
if (index.column() > lastCol) {
lastCol = index.column();
}
}
for(int row = firstRow; row <= lastRow; ++row) {
for(int col = firstCol; col <= lastCol; ++col) {
for (int row = firstRow; row <= lastRow; ++row) {
for (int col = firstCol; col <= lastCol; ++col) {
QModelIndex index = m_fieldModel->index(row, col);
if(selectedIndexes.contains(index)) {
if (selectedIndexes.contains(index)) {
text.append(index.data(Qt::EditRole).toString());
}
text.append('\t');
@ -644,20 +648,20 @@ QString MainWindow::selectedFieldsString() const
void MainWindow::insertFields(const QString &fieldsString)
{
QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
if(selectedIndexes.size() == 1) {
if (selectedIndexes.size() == 1) {
int rows = m_fieldModel->rowCount(), cols = m_fieldModel->columnCount();
int row = selectedIndexes.front().row();
int initCol = selectedIndexes.front().column();
assert(row < rows);
QStringList rowValues = fieldsString.split('\n');
if(rowValues.back().isEmpty()) {
if (rowValues.back().isEmpty()) {
rowValues.pop_back();
}
m_fieldModel->insertRows(row, rowValues.size(), QModelIndex());
for(const QString &rowValue : rowValues) {
for (const QString &rowValue : rowValues) {
int col = initCol;
for(const QString &cellValue : rowValue.split('\t')) {
if(col < cols) {
for (const QString &cellValue : rowValue.split('\t')) {
if (col < cols) {
m_fieldModel->setData(m_fieldModel->index(row, col), cellValue, Qt::EditRole);
++col;
} else {
@ -676,17 +680,13 @@ void MainWindow::insertFields(const QString &fieldsString)
*/
bool MainWindow::askForCreatingFile()
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return false;
}
QString fileName =
QFileDialog::getSaveFileName(
this,
tr("Select where you want to save the password list"),
QString(),
tr("Password Manager files (*.pwmgr);;All files (*)"));
if(fileName.isEmpty()) {
QString fileName = QFileDialog::getSaveFileName(
this, tr("Select where you want to save the password list"), QString(), tr("Password Manager files (*.pwmgr);;All files (*)"));
if (fileName.isEmpty()) {
m_ui->statusBar->showMessage(tr("The file was not be saved."), 7000);
return false;
} else {
@ -708,7 +708,7 @@ bool MainWindow::askForCreatingFile()
*/
bool MainWindow::showNoFileOpened()
{
if(!m_file.hasRootEntry()) {
if (!m_file.hasRootEntry()) {
QMessageBox::warning(this, QApplication::applicationName(), tr("There is no password list opened."));
return true;
}
@ -721,7 +721,7 @@ bool MainWindow::showNoFileOpened()
*/
bool MainWindow::showNoAccount()
{
if(!m_fieldModel->fields()) {
if (!m_fieldModel->fields()) {
QMessageBox::warning(this, QApplication::applicationName(), tr("There's no account selected."));
return true;
}
@ -734,10 +734,10 @@ bool MainWindow::showNoAccount()
*/
bool MainWindow::closeFile()
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return false;
}
if(m_somethingChanged) {
if (m_somethingChanged) {
QMessageBox msg(this);
msg.setText(tr("The password file has been modified."));
msg.setInformativeText(tr("Do you want to save the changes before closing?"));
@ -745,16 +745,15 @@ bool MainWindow::closeFile()
msg.setDefaultButton(QMessageBox::Save);
msg.setIcon(QMessageBox::Warning);
switch (msg.exec()) {
case QMessageBox::Save:
if(saveFile()) {
break;
} else {
return false;
}
case QMessageBox::Cancel:
return false;
default:
;
case QMessageBox::Save:
if (saveFile()) {
break;
} else {
return false;
}
case QMessageBox::Cancel:
return false;
default:;
}
}
m_fieldModel->reset();
@ -774,34 +773,35 @@ bool MainWindow::closeFile()
bool MainWindow::saveFile()
{
using namespace Dialogs;
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return false;
}
// create backup
if(!m_file.path().empty() && QFile::exists(QString::fromStdString(m_file.path()))) {
if(m_ui->actionAlwaysCreateBackup->isChecked()) {
if (!m_file.path().empty() && QFile::exists(QString::fromStdString(m_file.path()))) {
if (m_ui->actionAlwaysCreateBackup->isChecked()) {
try {
m_file.doBackup();
} catch(...) {
QString message(tr("The backup file couldn't be created because in IO error occured: %1").arg(QString::fromLocal8Bit(catchIoFailure())));
} catch (...) {
QString message(
tr("The backup file couldn't be created because in IO error occured: %1").arg(QString::fromLocal8Bit(catchIoFailure())));
QMessageBox::critical(this, QApplication::applicationName(), message);
m_ui->statusBar->showMessage(message, 7000);
return false;
}
}
} else {
if(!askForCreatingFile()) {
if (!askForCreatingFile()) {
return false;
}
}
// ask for a password if none is set
if(m_file.password()[0] == 0) {
if (m_file.password()[0] == 0) {
EnterPasswordDialog pwDlg(this);
pwDlg.setWindowTitle(tr("Saving file") + QStringLiteral(" - " APP_NAME));
pwDlg.setInstruction(tr("Enter a password to save the file"));
pwDlg.setVerificationRequired(true);
switch(pwDlg.exec()) {
switch (pwDlg.exec()) {
case QDialog::Accepted:
m_file.setPassword(pwDlg.password().toStdString());
break;
@ -816,14 +816,14 @@ bool MainWindow::saveFile()
m_file.save(m_file.password()[0] != 0);
} catch (const CryptoException &ex) {
msg = tr("The password list couldn't be saved due to encryption failure.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(ex.what()));
} catch(...) {
} catch (...) {
msg = QString::fromLocal8Bit(catchIoFailure());
}
// show status
if(!msg.isEmpty()) {
if (!msg.isEmpty()) {
m_ui->statusBar->showMessage(msg, 5000);
QMessageBox::critical(this, QApplication::applicationName(), msg);
return false;
QMessageBox::critical(this, QApplication::applicationName(), msg);
return false;
} else {
setSomethingChanged(false);
m_recentMgr->addEntry(QString::fromStdString(m_file.path()));
@ -837,22 +837,23 @@ bool MainWindow::saveFile()
*/
void MainWindow::exportFile()
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return;
}
QString targetPath = QFileDialog::getSaveFileName(this, QApplication::applicationName(), QString(), tr("Plain text document (*.txt);;All files (*.*)"));
if(!targetPath.isNull()) {
QString targetPath
= QFileDialog::getSaveFileName(this, QApplication::applicationName(), QString(), tr("Plain text document (*.txt);;All files (*.*)"));
if (!targetPath.isNull()) {
QString errmsg;
try {
m_file.exportToTextfile(targetPath.toStdString());
} catch (...) {
errmsg = tr("The password list couldn't be exported. %1").arg(QString::fromLocal8Bit(catchIoFailure()));
}
if(errmsg.isEmpty()) {
if (errmsg.isEmpty()) {
m_ui->statusBar->showMessage(tr("The password list has been exported."), 5000);
} else {
m_ui->statusBar->showMessage(errmsg, 5000);
QMessageBox::critical(this, QApplication::applicationName(), errmsg);
QMessageBox::critical(this, QApplication::applicationName(), errmsg);
}
}
}
@ -862,13 +863,13 @@ void MainWindow::exportFile()
*/
void MainWindow::showContainingDirectory()
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return;
} else if(m_file.path().empty()) {
} else if (m_file.path().empty()) {
QMessageBox::warning(this, QApplication::applicationName(), tr("The currently opened file hasn't been saved yet."));
} else {
QFileInfo file(QString::fromStdString(m_file.path()));
if(file.dir().exists()) {
if (file.dir().exists()) {
DesktopUtils::openLocalFileOrDir(file.dir().absolutePath());
}
}
@ -897,20 +898,21 @@ void MainWindow::addCategory()
*/
void MainWindow::addEntry(EntryType type)
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return;
}
QModelIndexList selectedIndexes = m_ui->treeView->selectionModel()->selectedRows(0);
if(selectedIndexes.size() == 1) {
if (selectedIndexes.size() == 1) {
QModelIndex selected = m_entryFilterModel->mapToSource(selectedIndexes.at(0));
if(m_entryModel->isNode(selected)) {
if (m_entryModel->isNode(selected)) {
bool result;
const QString text = QInputDialog::getText(this, type == EntryType::Account ? tr("Add account") : tr("Add category"), tr("Enter the entry name"), QLineEdit::Normal, tr("new entry"), &result);
const QString text = QInputDialog::getText(this, type == EntryType::Account ? tr("Add account") : tr("Add category"),
tr("Enter the entry name"), QLineEdit::Normal, tr("new entry"), &result);
if (result) {
if(!text.isEmpty()) {
if (!text.isEmpty()) {
int row = m_entryModel->rowCount(selected);
m_entryModel->setInsertType(type);
if(m_entryModel->insertRow(row, selected)) {
if (m_entryModel->insertRow(row, selected)) {
m_entryModel->setData(m_entryModel->index(row, 0, selected), text, Qt::DisplayRole);
setSomethingChanged(true);
} else {
@ -931,13 +933,13 @@ void MainWindow::addEntry(EntryType type)
*/
void MainWindow::removeEntry()
{
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return;
}
QModelIndexList selectedIndexes = m_ui->treeView->selectionModel()->selectedRows(0);
if(selectedIndexes.size() == 1) {
if (selectedIndexes.size() == 1) {
const QModelIndex selected = m_entryFilterModel->mapToSource(selectedIndexes.at(0));
if(!m_entryModel->removeRow(selected.row(), selected.parent())) {
if (!m_entryModel->removeRow(selected.row(), selected.parent())) {
QMessageBox::warning(this, QApplication::applicationName(), tr("Unable to remove the entry."));
}
} else {
@ -952,7 +954,7 @@ void MainWindow::removeEntry()
void MainWindow::applyFilter(const QString &filterText)
{
m_entryFilterModel->setFilterRegExp(filterText);
if(filterText.isEmpty()) {
if (filterText.isEmpty()) {
applyDefaultExpanding(QModelIndex());
} else {
m_ui->treeView->expandAll();
@ -964,8 +966,8 @@ void MainWindow::applyFilter(const QString &filterText)
*/
void MainWindow::accountSelected(const QModelIndex &selected, const QModelIndex &)
{
if(Entry *entry = m_entryModel->entry(m_entryFilterModel->mapToSource(selected))) {
if(entry->type() == EntryType::Account) {
if (Entry *entry = m_entryModel->entry(m_entryFilterModel->mapToSource(selected))) {
if (entry->type() == EntryType::Account) {
m_fieldModel->setAccountEntry(static_cast<AccountEntry *>(entry));
return;
}
@ -978,22 +980,23 @@ void MainWindow::accountSelected(const QModelIndex &selected, const QModelIndex
*/
void MainWindow::insertRow()
{
if(showNoFileOpened() || showNoAccount()) {
if (showNoFileOpened() || showNoAccount()) {
return;
}
QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
if(selectedIndexes.size()) {
if (selectedIndexes.size()) {
int row = m_fieldModel->rowCount();
for(const QModelIndex &index : selectedIndexes) {
if(index.row() < row) {
for (const QModelIndex &index : selectedIndexes) {
if (index.row() < row) {
row = index.row();
}
}
if(row < m_fieldModel->rowCount() - 1) {
if (row < m_fieldModel->rowCount() - 1) {
m_fieldModel->insertRow(row);
}
} else {
QMessageBox::warning(this, windowTitle(), tr("A field has to be selected since new fields are always inserted before the currently selected field."));
QMessageBox::warning(
this, windowTitle(), tr("A field has to be selected since new fields are always inserted before the currently selected field."));
}
}
@ -1002,17 +1005,17 @@ void MainWindow::insertRow()
*/
void MainWindow::removeRows()
{
if(showNoFileOpened() || showNoAccount()) {
if (showNoFileOpened() || showNoAccount()) {
return;
}
const QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
QList<int> rows;
for(const QModelIndex &index : selectedIndexes) {
for (const QModelIndex &index : selectedIndexes) {
rows << index.row();
}
if(rows.size()) {
for(int i = m_fieldModel->rowCount() - 1; i >= 0; --i) {
if(rows.contains(i)) {
if (rows.size()) {
for (int i = m_fieldModel->rowCount() - 1; i >= 0; --i) {
if (rows.contains(i)) {
m_fieldModel->removeRow(i);
}
}
@ -1042,13 +1045,13 @@ void MainWindow::markAsNormalField()
*/
void MainWindow::setFieldType(FieldType fieldType)
{
if(showNoFileOpened() || showNoAccount()) {
if (showNoFileOpened() || showNoAccount()) {
return;
}
QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
if(!selectedIndexes.isEmpty()) {
if (!selectedIndexes.isEmpty()) {
const QVariant typeVariant(static_cast<int>(fieldType));
for(const QModelIndex &index : selectedIndexes) {
for (const QModelIndex &index : selectedIndexes) {
m_fieldModel->setData(index, typeVariant, FieldTypeRole);
}
} else {
@ -1063,11 +1066,11 @@ void MainWindow::setFieldType(FieldType fieldType)
*/
void MainWindow::setPasswordVisibility(QAction *selectedAction)
{
if(selectedAction == m_ui->actionShowAlways) {
if (selectedAction == m_ui->actionShowAlways) {
m_fieldModel->setPasswordVisibility(PasswordVisibility::Always);
} else if(selectedAction == m_ui->actionShowOnlyWhenEditing) {
} else if (selectedAction == m_ui->actionShowOnlyWhenEditing) {
m_fieldModel->setPasswordVisibility(PasswordVisibility::OnlyWhenEditing);
} else if(selectedAction == m_ui->actionHideAlways) {
} else if (selectedAction == m_ui->actionHideAlways) {
m_fieldModel->setPasswordVisibility(PasswordVisibility::Never);
}
}
@ -1078,18 +1081,19 @@ void MainWindow::setPasswordVisibility(QAction *selectedAction)
void MainWindow::changePassword()
{
using namespace Dialogs;
if(showNoFileOpened()) {
if (showNoFileOpened()) {
return;
}
EnterPasswordDialog pwDlg(this);
pwDlg.setWindowTitle(tr("Changing password") + QStringLiteral(" - " APP_NAME));
pwDlg.setVerificationRequired(true);
switch(pwDlg.exec()) {
switch (pwDlg.exec()) {
case QDialog::Accepted:
if(pwDlg.password().isEmpty()) {
if (pwDlg.password().isEmpty()) {
m_file.clearPassword();
setSomethingChanged(true);
QMessageBox::warning(this, QApplication::applicationName(), tr("You didn't enter a password. <strong>No encryption</strong> will be used when saving the file next time."));
QMessageBox::warning(this, QApplication::applicationName(),
tr("You didn't enter a password. <strong>No encryption</strong> will be used when saving the file next time."));
} else {
m_file.setPassword(pwDlg.password().toStdString());
setSomethingChanged(true);
@ -1097,7 +1101,8 @@ void MainWindow::changePassword()
}
break;
default:
QMessageBox::warning(this, QApplication::applicationName(), tr("You aborted. The old password will still be used when saving the file next time."));
QMessageBox::warning(
this, QApplication::applicationName(), tr("You aborted. The old password will still be used when saving the file next time."));
}
}
@ -1106,27 +1111,28 @@ void MainWindow::changePassword()
*/
void MainWindow::showTreeViewContextMenu()
{
if(!m_file.hasRootEntry()) {
if (!m_file.hasRootEntry()) {
return;
}
QModelIndexList selectedIndexes = m_ui->treeView->selectionModel()->selectedRows(0);
if(selectedIndexes.size() == 1) {
if (selectedIndexes.size() == 1) {
QMenu contextMenu(this);
QModelIndex selected = m_entryFilterModel->mapToSource(selectedIndexes.at(0));
Entry *entry = m_entryModel->entry(selected);
if(entry->type() == EntryType::Node) {
if (entry->type() == EntryType::Node) {
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("list-add")), tr("Add account"), this, &MainWindow::addAccount);
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("list-add")), tr("Add category"), this, &MainWindow::addCategory);
}
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("list-remove")), tr("Remove entry"), this, &MainWindow::removeEntry);
if(entry->type() == EntryType::Node) {
if (entry->type() == EntryType::Node) {
auto *nodeEntry = static_cast<NodeEntry *>(entry);
contextMenu.addSeparator();
auto *action = new QAction(&contextMenu);
action->setCheckable(true);
action->setText(tr("Expanded by default"));
action->setChecked(nodeEntry->isExpandedByDefault());
connect(action, &QAction::triggered, std::bind(&EntryModel::setData, m_entryModel, std::cref(selected), QVariant(!nodeEntry->isExpandedByDefault()), DefaultExpandedRole));
connect(action, &QAction::triggered,
std::bind(&EntryModel::setData, m_entryModel, std::cref(selected), QVariant(!nodeEntry->isExpandedByDefault()), DefaultExpandedRole));
contextMenu.addAction(action);
}
contextMenu.exec(QCursor::pos());
@ -1140,7 +1146,7 @@ void MainWindow::showTableViewContextMenu()
{
// check whether there is a selection at all
QModelIndexList selectedIndexes = m_ui->tableView->selectionModel()->selectedIndexes();
if(!m_file.hasRootEntry() || !m_fieldModel->fields() || selectedIndexes.isEmpty()) {
if (!m_file.hasRootEntry() || !m_fieldModel->fields() || selectedIndexes.isEmpty()) {
return;
}
@ -1151,20 +1157,18 @@ void MainWindow::showTableViewContextMenu()
int row = selectedIndexes.front().row();
int multipleRows = 1;
QUrl url;
static const string protocols[] = {
"http:", "https:", "file:"
};
for(const QModelIndex &index : selectedIndexes) {
if(const Field *field = m_fieldModel->field(index.row())) {
if(url.isEmpty() && field->type() != FieldType::Password) {
for(const string &protocol : protocols) {
if(ConversionUtilities::startsWith(field->value(), protocol)) {
static const string protocols[] = { "http:", "https:", "file:" };
for (const QModelIndex &index : selectedIndexes) {
if (const Field *field = m_fieldModel->field(index.row())) {
if (url.isEmpty() && field->type() != FieldType::Password) {
for (const string &protocol : protocols) {
if (ConversionUtilities::startsWith(field->value(), protocol)) {
url = QString::fromUtf8(field->value().data());
}
}
}
if(hasFirstFieldType) {
if(firstType != field->type()) {
if (hasFirstFieldType) {
if (firstType != field->type()) {
allOfSameType = false;
break;
}
@ -1173,7 +1177,7 @@ void MainWindow::showTableViewContextMenu()
hasFirstFieldType = true;
}
}
if(multipleRows == 1 && index.row() != row) {
if (multipleRows == 1 && index.row() != row) {
++multipleRows;
}
}
@ -1184,10 +1188,11 @@ void MainWindow::showTableViewContextMenu()
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("list-add")), tr("Insert field"), this, &MainWindow::insertRow);
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("list-remove")), tr("Remove field(s)", 0, multipleRows), this, &MainWindow::removeRows);
// -> show the "Mark as ..." action only when all selected indexes are of the same type
if(hasFirstFieldType && allOfSameType) {
switch(firstType) {
if (hasFirstFieldType && allOfSameType) {
switch (firstType) {
case FieldType::Normal:
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("flag-black")), tr("Mark as password field"), this, &MainWindow::markAsPasswordField);
contextMenu.addAction(
QIcon::fromTheme(QStringLiteral("flag-black")), tr("Mark as password field"), this, &MainWindow::markAsPasswordField);
break;
case FieldType::Password:
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("flag-blue")), tr("Mark as normal field"), this, &MainWindow::markAsNormalField);
@ -1198,11 +1203,11 @@ void MainWindow::showTableViewContextMenu()
contextMenu.addSeparator();
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy"), this, &MainWindow::copyFields);
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy for 5 seconds"), this, &MainWindow::copyFieldsForXMilliSeconds);
if(QApplication::clipboard()->mimeData()->hasText()) {
if (QApplication::clipboard()->mimeData()->hasText()) {
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("edit-paste")), tr("Paste"), this, &MainWindow::insertFieldsFromClipboard);
}
// -> insert open URL
if(multipleRows == 1 && !url.isEmpty()) {
if (multipleRows == 1 && !url.isEmpty()) {
auto *openUrlAction = new QAction(QIcon::fromTheme(QStringLiteral("applications-internet")), tr("Open URL"), &contextMenu);
connect(openUrlAction, &QAction::triggered, bind(&QDesktopServices::openUrl, url));
contextMenu.addAction(openUrlAction);
@ -1217,17 +1222,16 @@ void MainWindow::showTableViewContextMenu()
void MainWindow::copyFieldsForXMilliSeconds(int x)
{
QString text = selectedFieldsString();
if(!text.isEmpty()) {
if(m_clearClipboardTimer) {
if (!text.isEmpty()) {
if (m_clearClipboardTimer) {
killTimer(m_clearClipboardTimer);
}
QApplication::clipboard()->setText(text);
if(x > 0) {
if (x > 0) {
m_clearClipboardTimer = startTimer(x, Qt::CoarseTimer);
}
} else {
QMessageBox::warning(this, QApplication::applicationName(), tr("The selection is empty."));
}
}
}

View File

@ -44,10 +44,9 @@ namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
~MainWindow();
@ -106,7 +105,7 @@ private slots:
void setSomethingChanged();
void setSomethingChanged(bool somethingChanged);
private:
private:
// showing conditional messages/prompts
bool askForCreatingFile();
bool showNoFileOpened();
@ -132,7 +131,6 @@ private:
Dialogs::QtSettings *m_qtSettings;
Dialogs::SettingsDialog *m_settingsDlg;
};
}
#endif // MAINWINDOW_H

View File

@ -10,13 +10,13 @@
#include <openssl/rand.h>
#include <QMessageBox>
#include <QClipboard>
#include <QMessageBox>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <sstream>
#include <string>
using namespace std;
using namespace Io;
@ -25,20 +25,13 @@ using namespace Dialogs;
namespace QtGui {
const char smallLetters[] = {'a','b','c','d','e','f',
'g','h','i','j','k',
'l','m','n','o','p',
'q','r','s','t','u',
'v','w','x','y','z'};
const char smallLetters[]
= { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
const char capitalLetters[] = {'A','B','C','D','E','F',
'G','H','I','J','K',
'L','M','N','O','P',
'Q','R','S','T','U',
'V','W','X','Y','Z'};
const char capitalLetters[]
= { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
const char digits[] = {'0','1','2','3','4',
'5','6','7','8','9'};
const char digits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
/*!
* \class PasswordGeneratorDialog
@ -48,13 +41,14 @@ const char digits[] = {'0','1','2','3','4',
/*!
* \brief Constructs a new password generator dialog.
*/
PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::PasswordGeneratorDialog)
PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::PasswordGeneratorDialog)
{
m_ui->setupUi(this);
#ifdef Q_OS_WIN32
setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }").arg(dialogStyle(), instructionTextColor().name()));
setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }")
.arg(dialogStyle(), instructionTextColor().name()));
#endif
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
@ -85,52 +79,51 @@ PasswordGeneratorDialog::~PasswordGeneratorDialog()
void PasswordGeneratorDialog::generateNewPassword()
{
int length = m_ui->LengthSpinBox->value();
if(length > 0) {
if(m_charset.empty()) {
if (length > 0) {
if (m_charset.empty()) {
bool useSmallLetters = m_ui->useSmallLettersCheckBox->isChecked();
bool useCapitalLetters = m_ui->useCapitalLettersCheckBox->isChecked();
bool useDigits = m_ui->useDigitsCheckBox->isChecked();
QString otherChars = m_ui->otherCharsLineEdit->text();
int charsetSize = otherChars.length();
if(useSmallLetters) {
if (useSmallLetters) {
charsetSize += sizeof(smallLetters);
}
if(useCapitalLetters) {
if (useCapitalLetters) {
charsetSize += sizeof(capitalLetters);
}
if(useDigits) {
if (useDigits) {
charsetSize += sizeof(digits);
}
m_charset.reserve(charsetSize);
if(useSmallLetters) {
if (useSmallLetters) {
m_charset.insert(m_charset.end(), std::begin(smallLetters), std::end(smallLetters));
}
if(useCapitalLetters) {
if (useCapitalLetters) {
m_charset.insert(m_charset.end(), std::begin(capitalLetters), std::end(capitalLetters));
}
if(useDigits) {
if (useDigits) {
m_charset.insert(m_charset.end(), std::begin(digits), std::end(digits));
}
char charval;
foreach(QChar qchar, otherChars) {
foreach (QChar qchar, otherChars) {
charval = qchar.toLatin1();
if(charval != '\x00' && charval != ' ' && std::find(m_charset.begin(), m_charset.end(), charval) == m_charset.end()) {
if (charval != '\x00' && charval != ' ' && std::find(m_charset.begin(), m_charset.end(), charval) == m_charset.end()) {
m_charset.push_back(charval);
}
}
}
if(!m_charset.empty()) {
if (!m_charset.empty()) {
try {
default_random_engine rng(m_random());
uniform_int_distribution<> dist(0, m_charset.size() - 1);
auto randchar = [this, &dist, &rng]() {
return m_charset[dist(rng)];
};
auto randchar = [this, &dist, &rng]() { return m_charset[dist(rng)]; };
string res(length, 0);
generate_n(res.begin(), length, randchar);
m_ui->passwordLineEdit->setText(QString::fromLatin1(res.c_str()));
} catch(const CryptoException &ex) {
QMessageBox::warning(this, QApplication::applicationName(), tr("Failed to generate password.\nOpenSSL error: %1").arg(QString::fromLocal8Bit(ex.what())));
} catch (const CryptoException &ex) {
QMessageBox::warning(this, QApplication::applicationName(),
tr("Failed to generate password.\nOpenSSL error: %1").arg(QString::fromLocal8Bit(ex.what())));
}
} else {
QMessageBox::warning(this, QApplication::applicationName(), tr("You have to select at least one checkbox."));
@ -145,10 +138,8 @@ void PasswordGeneratorDialog::generateNewPassword()
*/
void PasswordGeneratorDialog::handleCheckedCategoriesChanged()
{
m_ui->generatePassowordCommandLinkButton->setEnabled(m_ui->useCapitalLettersCheckBox->isChecked()
|| m_ui->useDigitsCheckBox->isChecked()
|| m_ui->useSmallLettersCheckBox->isChecked()
|| !m_ui->otherCharsLineEdit->text().isEmpty());
m_ui->generatePassowordCommandLinkButton->setEnabled(m_ui->useCapitalLettersCheckBox->isChecked() || m_ui->useDigitsCheckBox->isChecked()
|| m_ui->useSmallLettersCheckBox->isChecked() || !m_ui->otherCharsLineEdit->text().isEmpty());
m_charset.clear();
}
@ -168,5 +159,4 @@ void PasswordGeneratorDialog::copyPassword()
QClipboard *cb = QApplication::clipboard();
cb->setText(m_ui->passwordLineEdit->text());
}
}

View File

@ -13,14 +13,13 @@ namespace Ui {
class PasswordGeneratorDialog;
}
class PasswordGeneratorDialog : public QDialog
{
class PasswordGeneratorDialog : public QDialog {
Q_OBJECT
public:
explicit PasswordGeneratorDialog(QWidget *parent = 0);
~PasswordGeneratorDialog();
private Q_SLOTS:
void generateNewPassword();
void handleCheckedCategoriesChanged();
@ -32,7 +31,6 @@ private:
std::vector<char> m_charset;
Util::OpenSslRandomDevice m_random;
};
}
#endif // PASSWORDGENERATORDIALOG_H

View File

@ -10,8 +10,8 @@ namespace QtGui {
/*!
* \brief Constructs a new stack support with the specified \a undoStack.
*/
StackSupport::StackSupport(QUndoStack *undoStack) :
m_undoStack(undoStack)
{}
StackSupport::StackSupport(QUndoStack *undoStack)
: m_undoStack(undoStack)
{
}
}

View File

@ -9,9 +9,9 @@ namespace QtGui {
class StackAbsorper;
class StackSupport
{
class StackSupport {
friend class StackAbsorper;
public:
StackSupport(QUndoStack *undoStack = nullptr);
@ -37,8 +37,8 @@ inline QUndoStack *StackSupport::undoStack()
*/
inline bool StackSupport::push(CustomUndoCommand *command)
{
if(m_undoStack) {
if(command->isNoop()) {
if (m_undoStack) {
if (command->isNoop()) {
return true; // doing nothing can never fail
} else {
m_undoStack->push(command);
@ -53,7 +53,7 @@ inline bool StackSupport::push(CustomUndoCommand *command)
*/
inline void StackSupport::clearUndoStack()
{
if(m_undoStack) {
if (m_undoStack) {
m_undoStack->clear();
}
}
@ -62,12 +62,12 @@ inline void StackSupport::clearUndoStack()
* \brief The StackAbsorper class is used by the CustomUndoCommand class to prevent infinite recursion when pushing
* a new command to the stack.
*/
class StackAbsorper
{
class StackAbsorper {
public:
StackAbsorper(StackSupport *supported);
~StackAbsorper();
QUndoStack *stack();
private:
StackSupport *m_supported;
QUndoStack *m_stack;
@ -76,9 +76,9 @@ private:
/*!
* \brief Detaches the undo stack from the specified stack support temporary.
*/
inline StackAbsorper::StackAbsorper(StackSupport *supported) :
m_supported(supported),
m_stack(supported->m_undoStack)
inline StackAbsorper::StackAbsorper(StackSupport *supported)
: m_supported(supported)
, m_stack(supported->m_undoStack)
{
m_supported->m_undoStack = nullptr;
}
@ -98,7 +98,6 @@ inline QUndoStack *StackAbsorper::stack()
{
return m_stack;
}
}
#endif // QTGUI_STACKSUPPORT_H

View File

@ -1,8 +1,8 @@
#include "./undocommands.h"
#include "./stacksupport.h"
#include "../model/fieldmodel.h"
#include "../model/entrymodel.h"
#include "../model/fieldmodel.h"
#include <passwordfile/io/entry.h>
@ -23,16 +23,17 @@ namespace QtGui {
/*!
* \brief Constructs a new custom undo command with the specified \a stackSupport.
*/
CustomUndoCommand::CustomUndoCommand(StackSupport *stackSupport) :
m_stackSupport(stackSupport),
m_redoResult(false),
m_undoResult(true),
m_noop(false)
{}
CustomUndoCommand::CustomUndoCommand(StackSupport *stackSupport)
: m_stackSupport(stackSupport)
, m_redoResult(false)
, m_undoResult(true)
, m_noop(false)
{
}
void CustomUndoCommand::redo()
{
if(m_undoResult) {
if (m_undoResult) {
StackAbsorper stackAbsorper(m_stackSupport);
m_redoResult = internalRedo();
}
@ -40,7 +41,7 @@ void CustomUndoCommand::redo()
void CustomUndoCommand::undo()
{
if(m_redoResult) {
if (m_redoResult) {
StackAbsorper stackAbsorper(m_stackSupport);
m_undoResult = internalUndo();
}
@ -64,30 +65,30 @@ void CustomUndoCommand::undo()
/*!
* \brief Constructs a new command.
*/
FieldModelSetValueCommand::FieldModelSetValueCommand(FieldModel *model, const QModelIndex &index, const QVariant &value, int role) :
CustomUndoCommand(model),
m_account(model->accountEntry()),
m_model(model),
m_row(index.row()),
m_col(index.column()),
m_newValue(value),
m_oldValue(model->data(index, role)),
m_role(role)
FieldModelSetValueCommand::FieldModelSetValueCommand(FieldModel *model, const QModelIndex &index, const QVariant &value, int role)
: CustomUndoCommand(model)
, m_account(model->accountEntry())
, m_model(model)
, m_row(index.row())
, m_col(index.column())
, m_newValue(value)
, m_oldValue(model->data(index, role))
, m_role(role)
{
QString fieldName = model->index(m_row, 0, index.parent()).data().toString();
switch(role) {
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:
switch(m_col) {
switch (m_col) {
case 0:
if(m_oldValue.toString().isEmpty()) {
if (m_oldValue.toString().isEmpty()) {
setText(QApplication::translate("undocommands", "setting field name to »%1«").arg(m_newValue.toString()));
} else {
setText(QApplication::translate("undocommands", "setting field name »%1« to »%2«").arg(m_oldValue.toString(), m_newValue.toString()));
}
break;
case 1:
if(fieldName.isEmpty()) {
if (fieldName.isEmpty()) {
setText(QApplication::translate("undocommands", "setting value of empty field"));
} else {
setText(QApplication::translate("undocommands", "setting value of »%1« field").arg(fieldName));
@ -124,12 +125,12 @@ bool FieldModelSetValueCommand::internalUndo()
/*!
* \brief Constructs a new command.
*/
FieldModelInsertRowsCommand::FieldModelInsertRowsCommand(FieldModel *model, int row, int count) :
CustomUndoCommand(model),
m_account(model->accountEntry()),
m_model(model),
m_row(row),
m_count(count)
FieldModelInsertRowsCommand::FieldModelInsertRowsCommand(FieldModel *model, int row, int count)
: CustomUndoCommand(model)
, m_account(model->accountEntry())
, m_model(model)
, m_row(row)
, m_count(count)
{
setText(QApplication::translate("undocommands", "insertion of %1 row(s) before row %2", 0, count).arg(count).arg(row + 1));
}
@ -154,14 +155,14 @@ bool FieldModelInsertRowsCommand::internalUndo()
/*!
* \brief Constructs a new command.
*/
FieldModelRemoveRowsCommand::FieldModelRemoveRowsCommand(FieldModel *model, int row, int count) :
CustomUndoCommand(model),
m_account(model->accountEntry()),
m_model(model),
m_row(row),
m_count(count)
FieldModelRemoveRowsCommand::FieldModelRemoveRowsCommand(FieldModel *model, int row, int count)
: CustomUndoCommand(model)
, m_account(model->accountEntry())
, m_model(model)
, m_row(row)
, m_count(count)
{
if(count == 1) {
if (count == 1) {
setText(QApplication::translate("undocommands", "removal of row %1", 0, count).arg(row + 1));
} else {
setText(QApplication::translate("undocommands", "removal of the rows %1 to %2", 0, count).arg(row + 1).arg(row + count));
@ -171,9 +172,9 @@ FieldModelRemoveRowsCommand::FieldModelRemoveRowsCommand(FieldModel *model, int
bool FieldModelRemoveRowsCommand::internalRedo()
{
m_model->setAccountEntry(m_account);
if(m_values.isEmpty()) {
for(int row = m_row, end = m_row + m_count; row < end; ++row) {
if(const Field *field = m_model->field(row)) {
if (m_values.isEmpty()) {
for (int row = m_row, end = m_row + m_count; row < end; ++row) {
if (const Field *field = m_model->field(row)) {
m_values << Field(*field);
}
}
@ -185,7 +186,7 @@ bool FieldModelRemoveRowsCommand::internalUndo()
{
m_model->setAccountEntry(m_account);
bool res = m_model->insertRows(m_row, m_count, QModelIndex());
for(int row = m_row, end = m_row + m_count, value = 0, values = m_values.size(); row < end && value < values; ++row, ++value) {
for (int row = m_row, end = m_row + m_count, value = 0, values = m_values.size(); row < end && value < values; ++row, ++value) {
m_model->setData(m_model->index(row, 0), QString::fromStdString(m_values.at(value).name()), Qt::EditRole);
m_model->setData(m_model->index(row, 1), QString::fromStdString(m_values.at(value).value()), Qt::EditRole);
m_model->setData(m_model->index(row, 0), static_cast<int>(m_values.at(value).type()), FieldTypeRole);
@ -199,7 +200,7 @@ bool FieldModelRemoveRowsCommand::internalUndo()
void indexToPath(EntryModel *model, const QModelIndex &index, list<string> &res)
{
res.clear();
if(Entry *entry = model->entry(index)) {
if (Entry *entry = model->entry(index)) {
entry->path(res);
}
}
@ -210,7 +211,7 @@ void indexToPath(EntryModel *model, const QModelIndex &index, list<string> &res)
*/
Entry *entryFromPath(EntryModel *model, list<string> &path)
{
if(NodeEntry *rootEntry = model->rootEntry()) {
if (NodeEntry *rootEntry = model->rootEntry()) {
return rootEntry->entryByPath(path);
}
return nullptr;
@ -232,26 +233,27 @@ Entry *entryFromPathCpy(EntryModel *model, list<string> path)
/*!
* \brief Constructs a new command.
*/
EntryModelSetValueCommand::EntryModelSetValueCommand(EntryModel *model, const QModelIndex &index, const QVariant &value, int role) :
CustomUndoCommand(model),
m_model(model),
m_newValue(value),
m_oldValue(model->data(index, role)),
m_role(role)
EntryModelSetValueCommand::EntryModelSetValueCommand(EntryModel *model, const QModelIndex &index, const QVariant &value, int role)
: CustomUndoCommand(model)
, m_model(model)
, m_newValue(value)
, m_oldValue(model->data(index, role))
, m_role(role)
{
indexToPath(model, index, m_path);
switch(role) {
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:
if(m_oldValue.toString().isEmpty()) {
if (m_oldValue.toString().isEmpty()) {
setText(QApplication::translate("undocommands", "setting entry name to »%1«").arg(m_newValue.toString()));
} else {
setText(QApplication::translate("undocommands", "setting entry name from »%1« to »%2«").arg(m_oldValue.toString(), m_newValue.toString()));
setText(
QApplication::translate("undocommands", "setting entry name from »%1« to »%2«").arg(m_oldValue.toString(), m_newValue.toString()));
}
break;
default:
QString name = model->data(model->index(index.row(), 0, index.parent()), Qt::DisplayRole).toString();
if(name.isEmpty()) {
if (name.isEmpty()) {
setText(QApplication::translate("undocommands", "setting property of an entry"));
} else {
setText(QApplication::translate("undocommands", "setting property of entry »%1«").arg(name));
@ -262,7 +264,7 @@ EntryModelSetValueCommand::EntryModelSetValueCommand(EntryModel *model, const QM
bool EntryModelSetValueCommand::internalRedo()
{
if(Entry *entry = entryFromPath(m_model, m_path)) {
if (Entry *entry = entryFromPath(m_model, m_path)) {
bool res = m_model->setData(m_model->index(entry), m_newValue, m_role);
m_path.clear();
entry->path(m_path);
@ -273,7 +275,7 @@ bool EntryModelSetValueCommand::internalRedo()
bool EntryModelSetValueCommand::internalUndo()
{
if(Entry *entry = entryFromPath(m_model, m_path)) {
if (Entry *entry = entryFromPath(m_model, m_path)) {
bool res = m_model->setData(m_model->index(entry), m_oldValue, m_role);
m_path.clear();
entry->path(m_path);
@ -290,11 +292,11 @@ bool EntryModelSetValueCommand::internalUndo()
/*!
* \brief Constructs a new command.
*/
EntryModelModifyRowsCommand::EntryModelModifyRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent) :
CustomUndoCommand(model),
m_model(model),
m_row(row),
m_count(count)
EntryModelModifyRowsCommand::EntryModelModifyRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent)
: CustomUndoCommand(model)
, m_model(model)
, m_row(row)
, m_count(count)
{
indexToPath(model, parent, m_parentPath);
}
@ -314,8 +316,8 @@ EntryModelModifyRowsCommand::~EntryModelModifyRowsCommand()
*/
bool EntryModelModifyRowsCommand::insert()
{
if(Entry *parentEntry = entryFromPathCpy(m_model, m_parentPath)) {
if(m_model->insertEntries(m_row, m_model->index(parentEntry), m_values)) {
if (Entry *parentEntry = entryFromPathCpy(m_model, m_parentPath)) {
if (m_model->insertEntries(m_row, m_model->index(parentEntry), m_values)) {
m_values.clear();
return true;
}
@ -332,7 +334,7 @@ bool EntryModelModifyRowsCommand::insert()
*/
bool EntryModelModifyRowsCommand::remove()
{
if(Entry *parentEntry = entryFromPathCpy(m_model, m_parentPath)) {
if (Entry *parentEntry = entryFromPathCpy(m_model, m_parentPath)) {
m_values = m_model->takeEntries(m_row, m_count, m_model->index(parentEntry));
return !m_values.isEmpty();
}
@ -347,11 +349,11 @@ bool EntryModelModifyRowsCommand::remove()
/*!
* \brief Constructs a new command.
*/
EntryModelInsertRowsCommand::EntryModelInsertRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent) :
EntryModelModifyRowsCommand(model, row, count, parent)
EntryModelInsertRowsCommand::EntryModelInsertRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent)
: EntryModelModifyRowsCommand(model, row, count, parent)
{
setText(QApplication::translate("undocommands", "insertion of %1 entry/entries", 0, count).arg(count));
switch(m_model->insertType()) {
switch (m_model->insertType()) {
case EntryType::Account:
m_values << new AccountEntry;
break;
@ -379,8 +381,8 @@ bool EntryModelInsertRowsCommand::internalUndo()
/*!
* \brief Constructs a new command.
*/
EntryModelRemoveRowsCommand::EntryModelRemoveRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent) :
EntryModelModifyRowsCommand(model, row, count, parent)
EntryModelRemoveRowsCommand::EntryModelRemoveRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent)
: EntryModelModifyRowsCommand(model, row, count, parent)
{
setText(QApplication::translate("undocommands", "removal of %1 entry/entries", 0, count).arg(count));
}
@ -403,12 +405,13 @@ bool EntryModelRemoveRowsCommand::internalUndo()
/*!
* \brief Constructs a new command.
*/
EntryModelMoveRowsCommand::EntryModelMoveRowsCommand(EntryModel *model, const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) :
CustomUndoCommand(model),
m_model(model),
m_sourceRow(sourceRow),
m_count(count),
m_destChild(destinationChild)
EntryModelMoveRowsCommand::EntryModelMoveRowsCommand(
EntryModel *model, const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
: CustomUndoCommand(model)
, m_model(model)
, m_sourceRow(sourceRow)
, m_count(count)
, m_destChild(destinationChild)
{
indexToPath(model, sourceParent, m_sourceParentPath);
indexToPath(model, destinationParent, m_destParentPath);
@ -417,10 +420,10 @@ EntryModelMoveRowsCommand::EntryModelMoveRowsCommand(EntryModel *model, const QM
bool EntryModelMoveRowsCommand::internalRedo()
{
if(m_count) {
if (m_count) {
Entry *sourceParentEntry = entryFromPathCpy(m_model, m_sourceParentPath);
Entry *destParentEntry = entryFromPathCpy(m_model, m_destParentPath);
if(sourceParentEntry && destParentEntry) {
if (sourceParentEntry && destParentEntry) {
return m_model->moveRows(m_model->index(sourceParentEntry), m_sourceRow, m_count, m_model->index(destParentEntry), m_destChild);
}
return false;
@ -430,21 +433,21 @@ bool EntryModelMoveRowsCommand::internalRedo()
bool EntryModelMoveRowsCommand::internalUndo()
{
if(m_count) {
if (m_count) {
Entry *sourceParentEntry = entryFromPathCpy(m_model, m_sourceParentPath);
Entry *destParentEntry = entryFromPathCpy(m_model, m_destParentPath);
if(sourceParentEntry && destParentEntry) {
if (sourceParentEntry && destParentEntry) {
int sourceRow = m_destChild;
int destChild = m_sourceRow;
// moves whithin the same parent needs special consideration
if(sourceParentEntry == destParentEntry) {
if (sourceParentEntry == destParentEntry) {
// move entry down
if(m_sourceRow < m_destChild) {
if (m_sourceRow < m_destChild) {
sourceRow -= m_count;
// move entry up
} else if(m_sourceRow > m_destChild) {
// move entry up
} else if (m_sourceRow > m_destChild) {
destChild += m_count;
// keep entry were it is
// keep entry were it is
} else {
return true;
}
@ -455,5 +458,4 @@ bool EntryModelMoveRowsCommand::internalUndo()
}
return true;
}
}

View File

@ -3,9 +3,9 @@
#include <passwordfile/io/field.h>
#include <QList>
#include <QUndoCommand>
#include <QUndoStack>
#include <QList>
#include <QVariant>
QT_FORWARD_DECLARE_CLASS(QModelIndex)
@ -21,8 +21,7 @@ class FieldModel;
class EntryModel;
class StackSupport;
class CustomUndoCommand : public QUndoCommand
{
class CustomUndoCommand : public QUndoCommand {
public:
explicit CustomUndoCommand(StackSupport *stackSupport);
bool redoResult() const;
@ -30,10 +29,12 @@ public:
bool isNoop() const;
void redo();
void undo();
protected:
void setNoop(bool noop);
virtual bool internalRedo() = 0;
virtual bool internalUndo() = 0;
private:
StackSupport *m_stackSupport;
bool m_redoResult;
@ -75,13 +76,14 @@ inline void CustomUndoCommand::setNoop(bool noop)
m_noop = noop;
}
class FieldModelSetValueCommand : public CustomUndoCommand
{
class FieldModelSetValueCommand : public CustomUndoCommand {
public:
explicit FieldModelSetValueCommand(FieldModel *model, const QModelIndex &index, const QVariant &value, int role);
protected:
bool internalRedo();
bool internalUndo();
private:
Io::AccountEntry *m_account;
FieldModel *m_model;
@ -92,13 +94,14 @@ private:
int m_role;
};
class FieldModelInsertRowsCommand : public CustomUndoCommand
{
class FieldModelInsertRowsCommand : public CustomUndoCommand {
public:
explicit FieldModelInsertRowsCommand(FieldModel *model, int row, int count);
protected:
bool internalRedo();
bool internalUndo();
private:
Io::AccountEntry *m_account;
FieldModel *m_model;
@ -106,13 +109,14 @@ private:
int m_count;
};
class FieldModelRemoveRowsCommand : public CustomUndoCommand
{
class FieldModelRemoveRowsCommand : public CustomUndoCommand {
public:
explicit FieldModelRemoveRowsCommand(FieldModel *model, int row, int count);
protected:
bool internalRedo();
bool internalUndo();
private:
Io::AccountEntry *m_account;
FieldModel *m_model;
@ -121,13 +125,14 @@ private:
QList<Io::Field> m_values;
};
class EntryModelSetValueCommand : public CustomUndoCommand
{
class EntryModelSetValueCommand : public CustomUndoCommand {
public:
explicit EntryModelSetValueCommand(EntryModel *model, const QModelIndex &index, const QVariant &value, int role);
protected:
bool internalRedo();
bool internalUndo();
private:
EntryModel *m_model;
std::list<std::string> m_path;
@ -136,10 +141,10 @@ private:
int m_role;
};
class EntryModelModifyRowsCommand : public CustomUndoCommand
{
class EntryModelModifyRowsCommand : public CustomUndoCommand {
public:
~EntryModelModifyRowsCommand();
protected:
explicit EntryModelModifyRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent);
bool internalRedo() = 0;
@ -153,31 +158,33 @@ protected:
QList<Io::Entry *> m_values;
};
class EntryModelInsertRowsCommand : public EntryModelModifyRowsCommand
{
class EntryModelInsertRowsCommand : public EntryModelModifyRowsCommand {
public:
explicit EntryModelInsertRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent);
protected:
bool internalRedo();
bool internalUndo();
};
class EntryModelRemoveRowsCommand : public EntryModelModifyRowsCommand
{
class EntryModelRemoveRowsCommand : public EntryModelModifyRowsCommand {
public:
explicit EntryModelRemoveRowsCommand(EntryModel *model, int row, int count, const QModelIndex &parent);
protected:
bool internalRedo();
bool internalUndo();
};
class EntryModelMoveRowsCommand : public CustomUndoCommand
{
class EntryModelMoveRowsCommand : public CustomUndoCommand {
public:
explicit EntryModelMoveRowsCommand(EntryModel *model, const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild);
explicit EntryModelMoveRowsCommand(
EntryModel *model, const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild);
protected:
bool internalRedo();
bool internalUndo();
private:
EntryModel *m_model;
std::list<std::string> m_sourceParentPath;
@ -186,7 +193,6 @@ private:
std::list<std::string> m_destParentPath;
int m_destChild;
};
}
#endif // UNDOCOMMANDS_H

View File

@ -1,9 +1,9 @@
#include "./cli/cli.h"
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
# include "./gui/initiategui.h"
#include "./gui/initiategui.h"
#endif
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
# include "./quickgui/initiatequick.h"
#include "./quickgui/initiatequick.h"
#endif
#include "resources/config.h"
@ -11,15 +11,15 @@
#include <passwordfile/util/openssl.h>
#include <c++utilities/application/argumentparser.h>
#include <c++utilities/application/failure.h>
#include <c++utilities/application/commandlineutils.h>
#include <c++utilities/application/failure.h>
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
# include <qtutilities/resources/qtconfigarguments.h>
# include <QString>
#include <QString>
#include <qtutilities/resources/qtconfigarguments.h>
ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES
#else
# include <c++utilities/application/fakeqtconfigarguments.h>
#include <c++utilities/application/fakeqtconfigarguments.h>
#endif
#include <iostream>
@ -37,7 +37,7 @@ int main(int argc, char *argv[])
ArgumentParser parser;
// file argument
Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)");
fileArg.setValueNames({"path"});
fileArg.setValueNames({ "path" });
fileArg.setRequiredValueCount(1);
fileArg.setCombinable(true);
fileArg.setRequired(false);
@ -47,38 +47,38 @@ int main(int argc, char *argv[])
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
// cli argument
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
cliArg.setSubArguments({&fileArg});
cliArg.setSubArguments({ &fileArg });
// help argument
HelpArgument helpArg(parser);
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg});
parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg });
// holds the application's return code
int res = 0;
// parse the specified arguments
try {
parser.parseArgs(argc, argv);
if(cliArg.isPresent()) {
if (cliArg.isPresent()) {
Cli::InteractiveCli cli;
if(fileArg.isPresent()) {
if (fileArg.isPresent()) {
cli.run(fileArg.values().front());
} else {
cli.run();
}
} else if(qtConfigArgs.areQtGuiArgsPresent()) {
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
} else if (qtConfigArgs.areQtGuiArgsPresent()) {
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
QString file;
if(fileArg.isPresent()) {
if (fileArg.isPresent()) {
file = QString::fromLocal8Bit(fileArg.values().front());
}
#endif
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
if (qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
#else
CMD_UTILS_START_CONSOLE;
cout << "The application has not been built with Qt widgets support." << endl;
#endif
} else if(qtConfigArgs.qtQuickGuiArg().isPresent()) {
} else if (qtConfigArgs.qtQuickGuiArg().isPresent()) {
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
#else
@ -96,7 +96,7 @@ int main(int argc, char *argv[])
#endif
}
}
} catch(const Failure &ex) {
} catch (const Failure &ex) {
CMD_UTILS_START_CONSOLE;
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
}

View File

@ -5,8 +5,7 @@
namespace QtGui {
class EntryFilterModel : public QSortFilterProxyModel
{
class EntryFilterModel : public QSortFilterProxyModel {
Q_OBJECT
public:
explicit EntryFilterModel(QObject *parent = nullptr);
@ -16,9 +15,7 @@ protected:
private:
bool hasAcceptedChildren(const QModelIndex &index) const;
};
}
#endif // ENTRYFILTERMODEL_H

View File

@ -2,7 +2,7 @@
#define ENTRYMODEL_H
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
# include "gui/stacksupport.h"
#include "gui/stacksupport.h"
#endif
#include <c++utilities/application/global.h>
@ -20,15 +20,15 @@ namespace QtGui {
/*!
* \brief The EntryModelRoles enum defines custom roles for the EntryModel class.
*/
enum EntryModelRoles
{
enum EntryModelRoles {
SerializedRole = Qt::UserRole + 1, /**< the entry (including descendants) in serialized from (QByteArray) */
DefaultExpandedRole = Qt::UserRole + 2 /**< whether the entry should be expanded by default */
};
class EntryModel : public QAbstractItemModel
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
, public StackSupport
,
public StackSupport
#endif
{
Q_OBJECT
@ -89,7 +89,7 @@ inline Io::NodeEntry *EntryModel::rootEntry()
*/
inline void EntryModel::setRootEntry(Io::NodeEntry *entry)
{
if(m_rootEntry != entry) {
if (m_rootEntry != entry) {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
clearUndoStack();
#endif
@ -122,7 +122,6 @@ inline void EntryModel::setInsertType(Io::EntryType type)
{
m_insertType = type;
}
}
#endif // ENTRYMODEL_H

View File

@ -2,7 +2,7 @@
#define FIELDMODEL_H
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
# include "gui/stacksupport.h"
#include "gui/stacksupport.h"
#endif
#include <passwordfile/io/entry.h>
@ -20,16 +20,14 @@ namespace QtGui {
/*!
* \brief The FieldModelRoles enum defines custom roles for the FieldModel class.
*/
enum FieldModelRoles
{
enum FieldModelRoles {
FieldTypeRole = Qt::UserRole + 1 /**< the field type */
};
/*!
* \brief The PasswordVisibility enum defines when passwords will be visible.
*/
enum PasswordVisibility
{
enum PasswordVisibility {
Always, /**< passwords are always visible */
OnlyWhenEditing, /**< passwords are only visible when editing */
Never /**< passwords are never visible */
@ -37,11 +35,12 @@ enum PasswordVisibility
class FieldModel : public QAbstractTableModel
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
, public StackSupport
,
public StackSupport
#endif
{
Q_OBJECT
public:
public:
explicit FieldModel(QObject *parent = nullptr);
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
explicit FieldModel(QUndoStack *undoStack, QObject *parent = nullptr);
@ -128,11 +127,10 @@ inline PasswordVisibility FieldModel::passwordVisibility() const
inline void FieldModel::setPasswordVisibility(PasswordVisibility passwordVisibility)
{
m_passwordVisibility = passwordVisibility;
if(m_fields) {
if (m_fields) {
emit dataChanged(index(0, 1), index(m_fields->size() - 1, 1), QVector<int>() << Qt::DisplayRole << Qt::EditRole);
}
}
}
#endif // FIELDMODEL_H

View File

@ -2,13 +2,13 @@
#include <qmath.h>
#include <QDebug>
#include <QFile>
#include <QGuiApplication>
#include <QRegExp>
#include <QScreen>
#include <QUrl>
#include <QUrlQuery>
#include <QGuiApplication>
#include <QScreen>
#include <QDebug>
using namespace Io;
@ -40,14 +40,14 @@ ApplicationInfo::ApplicationInfo()
m_sliderHandleHeight = sizeWithRatio(87);
m_sliderGapWidth = sizeWithRatio(100);
m_isPortraitMode = isMobile() ? rect.height() > rect.width() : false;
m_hMargin = m_isPortraitMode ? 20 * ratio() : 50 * ratio();
m_hMargin = m_isPortraitMode ? 20 * ratio() : 50 * ratio();
m_applicationWidth = isMobile() ? rect.width() : 1120;
m_constants->insert(QLatin1String("rowDelegateHeight"), QVariant(sizeWithRatio(118)));
m_fieldModel = new FieldModel(this);
if(isMobile()) {
if (isMobile()) {
connect(QGuiApplication::primaryScreen(), &QScreen::orientationChanged, this, &ApplicationInfo::notifyPortraitMode);
}
}
@ -90,5 +90,4 @@ void ApplicationInfo::setIsPortraitMode(const bool newMode)
emit hMarginChanged();
}
}
}

View File

@ -8,8 +8,7 @@
namespace QtGui {
class ApplicationInfo : public QObject
{
class ApplicationInfo : public QObject {
Q_OBJECT
Q_PROPERTY(int applicationWidth READ applicationWidth WRITE setApplicationWidth NOTIFY applicationWidthChanged)
Q_PROPERTY(bool isMobile READ isMobile CONSTANT)
@ -114,7 +113,7 @@ inline const QString &ApplicationInfo::currentFile() const
inline void ApplicationInfo::setCurrentFile(const QString &currentFile)
{
if(m_currentFile != currentFile) {
if (m_currentFile != currentFile) {
m_currentFile = currentFile;
emit currentFileChanged();
}
@ -132,7 +131,7 @@ inline Io::AccountEntry *ApplicationInfo::currentAccountEntry()
inline QString ApplicationInfo::currentAccountName() const
{
if(m_fieldModel->accountEntry()) {
if (m_fieldModel->accountEntry()) {
return QString::fromStdString(m_fieldModel->accountEntry()->label());
}
return QString();
@ -172,7 +171,6 @@ inline qreal ApplicationInfo::sizeWithRatio(const qreal height)
{
return ratio() * height;
}
}
#endif // APPLICATIONINFO_H

View File

@ -7,11 +7,11 @@
namespace QtGui {
class ApplicationPaths
{
class ApplicationPaths {
public:
static QString settingsPath();
static QString dowloadedFilesPath();
protected:
static QString path(QStandardPaths::StandardLocation location);
};
@ -30,13 +30,12 @@ inline QString ApplicationPaths::path(QStandardPaths::StandardLocation location)
{
QString path = QStandardPaths::standardLocations(location).value(0);
QDir dir(path);
if(!dir.exists())
if (!dir.exists())
dir.mkpath(path);
if(!path.isEmpty() && !path.endsWith("/"))
if (!path.isEmpty() && !path.endsWith("/"))
path += "/";
return path;
}
}
#endif // APPLICATIONPATHS_H

View File

@ -11,15 +11,15 @@
#include <qtutilities/resources/resources.h>
#if defined(GUI_QTWIDGETS)
# include <QApplication>
#include <QApplication>
#else
# include <QGuiApplication>
#endif
#include <QGuiApplication>
#endif
#include <QDebug>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QTextCodec>
#include <QtQml>
#include <QQmlApplicationEngine>
#include <QDebug>
using namespace ApplicationUtilities;
@ -55,5 +55,4 @@ int runQuickGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs)
int res = a.exec();
return res;
}
}

View File

@ -12,7 +12,6 @@ class QtConfigArguments;
namespace QtGui {
int runQuickGui(int argc, char *argv[], const ApplicationUtilities::QtConfigArguments &qtConfigArgs);
}
#endif // QT_QUICK_GUI_INITIATE_H

View File

@ -265,92 +265,92 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="318"/>
<location filename="../gui/mainwindow.cpp" line="319"/>
<source>Qt settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="336"/>
<location filename="../gui/mainwindow.cpp" line="337"/>
<source>A simple password store using AES-256-CBC encryption via OpenSSL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="358"/>
<location filename="../gui/mainwindow.cpp" line="361"/>
<source>Select a password list</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="358"/>
<location filename="../gui/mainwindow.cpp" line="361"/>
<location filename="../gui/mainwindow.cpp" line="688"/>
<source>Password Manager files (*.pwmgr);;All files (*)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="385"/>
<location filename="../gui/mainwindow.cpp" line="388"/>
<source>Undo stack</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="413"/>
<location filename="../gui/mainwindow.cpp" line="417"/>
<source>An IO error occured when opening the specified file &quot;%1&quot;.
(%2)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="420"/>
<location filename="../gui/mainwindow.cpp" line="425"/>
<source>The file you want to load seems to be very big. Do you really want to open it?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="428"/>
<location filename="../gui/mainwindow.cpp" line="434"/>
<source>Opening file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="429"/>
<location filename="../gui/mainwindow.cpp" line="435"/>
<source>Enter the password to open the file &quot;%1&quot;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="434"/>
<location filename="../gui/mainwindow.cpp" line="435"/>
<location filename="../gui/mainwindow.cpp" line="440"/>
<location filename="../gui/mainwindow.cpp" line="441"/>
<source>A password is needed to open the file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="454"/>
<location filename="../gui/mainwindow.cpp" line="459"/>
<source>The file couldn&apos;t be decrypted.
OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="459"/>
<location filename="../gui/mainwindow.cpp" line="464"/>
<source>Unable to parse the file. %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="519"/>
<location filename="../gui/mainwindow.cpp" line="523"/>
<source>The file &lt;i&gt;%1&lt;/i&gt; couldn&apos;t be created.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="536"/>
<location filename="../gui/mainwindow.cpp" line="540"/>
<source>A new password list has been created.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="539"/>
<location filename="../gui/mainwindow.cpp" line="543"/>
<source>The password list has been load.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="670"/>
<location filename="../gui/mainwindow.cpp" line="674"/>
<source>Exactly one fields needs to be selected (top-left corner for insertion).</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="686"/>
<location filename="../gui/mainwindow.cpp" line="688"/>
<source>Select where you want to save the password list</source>
<translation type="unfinished"></translation>
</message>
@ -380,7 +380,7 @@ OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="763"/>
<location filename="../gui/mainwindow.cpp" line="762"/>
<source>The password list has been closed.</source>
<translation type="unfinished"></translation>
</message>
@ -416,124 +416,124 @@ OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="843"/>
<location filename="../gui/mainwindow.cpp" line="844"/>
<source>Plain text document (*.txt);;All files (*.*)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="849"/>
<location filename="../gui/mainwindow.cpp" line="850"/>
<source>The password list couldn&apos;t be exported. %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="852"/>
<location filename="../gui/mainwindow.cpp" line="853"/>
<source>The password list has been exported.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="868"/>
<location filename="../gui/mainwindow.cpp" line="869"/>
<source>The currently opened file hasn&apos;t been saved yet.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="1118"/>
<location filename="../gui/mainwindow.cpp" line="909"/>
<location filename="../gui/mainwindow.cpp" line="1123"/>
<source>Add account</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="1119"/>
<location filename="../gui/mainwindow.cpp" line="909"/>
<location filename="../gui/mainwindow.cpp" line="1124"/>
<source>Add category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="910"/>
<source>Enter the entry name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="910"/>
<source>new entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="917"/>
<location filename="../gui/mainwindow.cpp" line="919"/>
<source>Unable to create new entry.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="920"/>
<location filename="../gui/mainwindow.cpp" line="922"/>
<source>You didn&apos;t enter text.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="926"/>
<location filename="../gui/mainwindow.cpp" line="928"/>
<source>No node element selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="941"/>
<location filename="../gui/mainwindow.cpp" line="943"/>
<source>Unable to remove the entry.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="944"/>
<location filename="../gui/mainwindow.cpp" line="946"/>
<source>No entry selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="996"/>
<location filename="../gui/mainwindow.cpp" line="999"/>
<source>A field has to be selected since new fields are always inserted before the currently selected field.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1020"/>
<location filename="../gui/mainwindow.cpp" line="1023"/>
<source>No fields have been removed since there are currently no fields selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1055"/>
<location filename="../gui/mainwindow.cpp" line="1058"/>
<source>No fields have been changed since there are currently no fields selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1085"/>
<location filename="../gui/mainwindow.cpp" line="1088"/>
<source>Changing password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1092"/>
<location filename="../gui/mainwindow.cpp" line="1096"/>
<source>You didn&apos;t enter a password. &lt;strong&gt;No encryption&lt;/strong&gt; will be used when saving the file next time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1096"/>
<location filename="../gui/mainwindow.cpp" line="1100"/>
<source>The new password will be used next time you save the file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1100"/>
<location filename="../gui/mainwindow.cpp" line="1105"/>
<source>You aborted. The old password will still be used when saving the file next time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1121"/>
<location filename="../gui/mainwindow.cpp" line="1126"/>
<source>Remove entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1127"/>
<location filename="../gui/mainwindow.cpp" line="1132"/>
<source>Expanded by default</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1184"/>
<location filename="../gui/mainwindow.cpp" line="1188"/>
<source>Insert field</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="../gui/mainwindow.cpp" line="1185"/>
<location filename="../gui/mainwindow.cpp" line="1189"/>
<source>Remove field(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -541,37 +541,37 @@ OpenSSL error queue: %1</source>
</translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1190"/>
<location filename="../gui/mainwindow.cpp" line="1195"/>
<source>Mark as password field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1193"/>
<location filename="../gui/mainwindow.cpp" line="1198"/>
<source>Mark as normal field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1199"/>
<location filename="../gui/mainwindow.cpp" line="1204"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1200"/>
<location filename="../gui/mainwindow.cpp" line="1205"/>
<source>Copy for 5 seconds</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1202"/>
<location filename="../gui/mainwindow.cpp" line="1207"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1206"/>
<location filename="../gui/mainwindow.cpp" line="1211"/>
<source>Open URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1229"/>
<location filename="../gui/mainwindow.cpp" line="1234"/>
<source>The selection is empty.</source>
<translation type="unfinished"></translation>
</message>
@ -634,18 +634,18 @@ OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/passwordgeneratordialog.cpp" line="133"/>
<location filename="../gui/passwordgeneratordialog.cpp" line="126"/>
<source>Failed to generate password.
OpenSSL error: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/passwordgeneratordialog.cpp" line="136"/>
<location filename="../gui/passwordgeneratordialog.cpp" line="129"/>
<source>You have to select at least one checkbox.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/passwordgeneratordialog.cpp" line="139"/>
<location filename="../gui/passwordgeneratordialog.cpp" line="132"/>
<source>The length has to be at least one.</source>
<translation type="unfinished"></translation>
</message>
@ -714,37 +714,37 @@ OpenSSL error: %1</source>
<context>
<name>undocommands</name>
<message>
<location filename="../gui/undocommands.cpp" line="84"/>
<location filename="../gui/undocommands.cpp" line="85"/>
<source>setting field name to »%1«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="86"/>
<location filename="../gui/undocommands.cpp" line="87"/>
<source>setting field name »%1« to »%2«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="91"/>
<location filename="../gui/undocommands.cpp" line="92"/>
<source>setting value of empty field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="93"/>
<location filename="../gui/undocommands.cpp" line="94"/>
<source>setting value of »%1« field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="99"/>
<location filename="../gui/undocommands.cpp" line="100"/>
<source>setting type of »%1« field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="102"/>
<location filename="../gui/undocommands.cpp" line="103"/>
<source>setting field property in row »%1«</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="134"/>
<location filename="../gui/undocommands.cpp" line="135"/>
<source>insertion of %1 row(s) before row %2</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -752,7 +752,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="165"/>
<location filename="../gui/undocommands.cpp" line="166"/>
<source>removal of row %1</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -760,7 +760,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="167"/>
<location filename="../gui/undocommands.cpp" line="168"/>
<source>removal of the rows %1 to %2</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -768,27 +768,27 @@ OpenSSL error: %1</source>
</translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="247"/>
<location filename="../gui/undocommands.cpp" line="248"/>
<source>setting entry name to »%1«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="249"/>
<location filename="../gui/undocommands.cpp" line="251"/>
<source>setting entry name from »%1« to »%2«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="255"/>
<location filename="../gui/undocommands.cpp" line="257"/>
<source>setting property of an entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="257"/>
<location filename="../gui/undocommands.cpp" line="259"/>
<source>setting property of entry »%1«</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="353"/>
<location filename="../gui/undocommands.cpp" line="355"/>
<source>insertion of %1 entry/entries</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -796,7 +796,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="385"/>
<location filename="../gui/undocommands.cpp" line="387"/>
<source>removal of %1 entry/entries</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -804,7 +804,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="415"/>
<location filename="../gui/undocommands.cpp" line="418"/>
<source>move of %1 entry/entries</source>
<translation type="unfinished">
<numerusform></numerusform>

View File

@ -265,92 +265,92 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="318"/>
<location filename="../gui/mainwindow.cpp" line="319"/>
<source>Qt settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="336"/>
<location filename="../gui/mainwindow.cpp" line="337"/>
<source>A simple password store using AES-256-CBC encryption via OpenSSL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="358"/>
<location filename="../gui/mainwindow.cpp" line="361"/>
<source>Select a password list</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="358"/>
<location filename="../gui/mainwindow.cpp" line="361"/>
<location filename="../gui/mainwindow.cpp" line="688"/>
<source>Password Manager files (*.pwmgr);;All files (*)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="385"/>
<location filename="../gui/mainwindow.cpp" line="388"/>
<source>Undo stack</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="413"/>
<location filename="../gui/mainwindow.cpp" line="417"/>
<source>An IO error occured when opening the specified file &quot;%1&quot;.
(%2)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="420"/>
<location filename="../gui/mainwindow.cpp" line="425"/>
<source>The file you want to load seems to be very big. Do you really want to open it?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="428"/>
<location filename="../gui/mainwindow.cpp" line="434"/>
<source>Opening file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="429"/>
<location filename="../gui/mainwindow.cpp" line="435"/>
<source>Enter the password to open the file &quot;%1&quot;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="434"/>
<location filename="../gui/mainwindow.cpp" line="435"/>
<location filename="../gui/mainwindow.cpp" line="440"/>
<location filename="../gui/mainwindow.cpp" line="441"/>
<source>A password is needed to open the file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="454"/>
<location filename="../gui/mainwindow.cpp" line="459"/>
<source>The file couldn&apos;t be decrypted.
OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="459"/>
<location filename="../gui/mainwindow.cpp" line="464"/>
<source>Unable to parse the file. %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="519"/>
<location filename="../gui/mainwindow.cpp" line="523"/>
<source>The file &lt;i&gt;%1&lt;/i&gt; couldn&apos;t be created.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="536"/>
<location filename="../gui/mainwindow.cpp" line="540"/>
<source>A new password list has been created.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="539"/>
<location filename="../gui/mainwindow.cpp" line="543"/>
<source>The password list has been load.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="670"/>
<location filename="../gui/mainwindow.cpp" line="674"/>
<source>Exactly one fields needs to be selected (top-left corner for insertion).</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="686"/>
<location filename="../gui/mainwindow.cpp" line="688"/>
<source>Select where you want to save the password list</source>
<translation type="unfinished"></translation>
</message>
@ -380,7 +380,7 @@ OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="763"/>
<location filename="../gui/mainwindow.cpp" line="762"/>
<source>The password list has been closed.</source>
<translation type="unfinished"></translation>
</message>
@ -416,124 +416,124 @@ OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="843"/>
<location filename="../gui/mainwindow.cpp" line="844"/>
<source>Plain text document (*.txt);;All files (*.*)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="849"/>
<location filename="../gui/mainwindow.cpp" line="850"/>
<source>The password list couldn&apos;t be exported. %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="852"/>
<location filename="../gui/mainwindow.cpp" line="853"/>
<source>The password list has been exported.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="868"/>
<location filename="../gui/mainwindow.cpp" line="869"/>
<source>The currently opened file hasn&apos;t been saved yet.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="1118"/>
<location filename="../gui/mainwindow.cpp" line="909"/>
<location filename="../gui/mainwindow.cpp" line="1123"/>
<source>Add account</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="1119"/>
<location filename="../gui/mainwindow.cpp" line="909"/>
<location filename="../gui/mainwindow.cpp" line="1124"/>
<source>Add category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="910"/>
<source>Enter the entry name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="908"/>
<location filename="../gui/mainwindow.cpp" line="910"/>
<source>new entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="917"/>
<location filename="../gui/mainwindow.cpp" line="919"/>
<source>Unable to create new entry.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="920"/>
<location filename="../gui/mainwindow.cpp" line="922"/>
<source>You didn&apos;t enter text.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="926"/>
<location filename="../gui/mainwindow.cpp" line="928"/>
<source>No node element selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="941"/>
<location filename="../gui/mainwindow.cpp" line="943"/>
<source>Unable to remove the entry.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="944"/>
<location filename="../gui/mainwindow.cpp" line="946"/>
<source>No entry selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="996"/>
<location filename="../gui/mainwindow.cpp" line="999"/>
<source>A field has to be selected since new fields are always inserted before the currently selected field.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1020"/>
<location filename="../gui/mainwindow.cpp" line="1023"/>
<source>No fields have been removed since there are currently no fields selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1055"/>
<location filename="../gui/mainwindow.cpp" line="1058"/>
<source>No fields have been changed since there are currently no fields selected.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1085"/>
<location filename="../gui/mainwindow.cpp" line="1088"/>
<source>Changing password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1092"/>
<location filename="../gui/mainwindow.cpp" line="1096"/>
<source>You didn&apos;t enter a password. &lt;strong&gt;No encryption&lt;/strong&gt; will be used when saving the file next time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1096"/>
<location filename="../gui/mainwindow.cpp" line="1100"/>
<source>The new password will be used next time you save the file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1100"/>
<location filename="../gui/mainwindow.cpp" line="1105"/>
<source>You aborted. The old password will still be used when saving the file next time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1121"/>
<location filename="../gui/mainwindow.cpp" line="1126"/>
<source>Remove entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1127"/>
<location filename="../gui/mainwindow.cpp" line="1132"/>
<source>Expanded by default</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1184"/>
<location filename="../gui/mainwindow.cpp" line="1188"/>
<source>Insert field</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="../gui/mainwindow.cpp" line="1185"/>
<location filename="../gui/mainwindow.cpp" line="1189"/>
<source>Remove field(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -541,37 +541,37 @@ OpenSSL error queue: %1</source>
</translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1190"/>
<location filename="../gui/mainwindow.cpp" line="1195"/>
<source>Mark as password field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1193"/>
<location filename="../gui/mainwindow.cpp" line="1198"/>
<source>Mark as normal field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1199"/>
<location filename="../gui/mainwindow.cpp" line="1204"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1200"/>
<location filename="../gui/mainwindow.cpp" line="1205"/>
<source>Copy for 5 seconds</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1202"/>
<location filename="../gui/mainwindow.cpp" line="1207"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1206"/>
<location filename="../gui/mainwindow.cpp" line="1211"/>
<source>Open URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/mainwindow.cpp" line="1229"/>
<location filename="../gui/mainwindow.cpp" line="1234"/>
<source>The selection is empty.</source>
<translation type="unfinished"></translation>
</message>
@ -634,18 +634,18 @@ OpenSSL error queue: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/passwordgeneratordialog.cpp" line="133"/>
<location filename="../gui/passwordgeneratordialog.cpp" line="126"/>
<source>Failed to generate password.
OpenSSL error: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/passwordgeneratordialog.cpp" line="136"/>
<location filename="../gui/passwordgeneratordialog.cpp" line="129"/>
<source>You have to select at least one checkbox.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/passwordgeneratordialog.cpp" line="139"/>
<location filename="../gui/passwordgeneratordialog.cpp" line="132"/>
<source>The length has to be at least one.</source>
<translation type="unfinished"></translation>
</message>
@ -714,37 +714,37 @@ OpenSSL error: %1</source>
<context>
<name>undocommands</name>
<message>
<location filename="../gui/undocommands.cpp" line="84"/>
<location filename="../gui/undocommands.cpp" line="85"/>
<source>setting field name to »%1«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="86"/>
<location filename="../gui/undocommands.cpp" line="87"/>
<source>setting field name »%1« to »%2«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="91"/>
<location filename="../gui/undocommands.cpp" line="92"/>
<source>setting value of empty field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="93"/>
<location filename="../gui/undocommands.cpp" line="94"/>
<source>setting value of »%1« field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="99"/>
<location filename="../gui/undocommands.cpp" line="100"/>
<source>setting type of »%1« field</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="102"/>
<location filename="../gui/undocommands.cpp" line="103"/>
<source>setting field property in row »%1«</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="134"/>
<location filename="../gui/undocommands.cpp" line="135"/>
<source>insertion of %1 row(s) before row %2</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -752,7 +752,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="165"/>
<location filename="../gui/undocommands.cpp" line="166"/>
<source>removal of row %1</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -760,7 +760,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="167"/>
<location filename="../gui/undocommands.cpp" line="168"/>
<source>removal of the rows %1 to %2</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -768,27 +768,27 @@ OpenSSL error: %1</source>
</translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="247"/>
<location filename="../gui/undocommands.cpp" line="248"/>
<source>setting entry name to »%1«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="249"/>
<location filename="../gui/undocommands.cpp" line="251"/>
<source>setting entry name from »%1« to »%2«</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="255"/>
<location filename="../gui/undocommands.cpp" line="257"/>
<source>setting property of an entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/undocommands.cpp" line="257"/>
<location filename="../gui/undocommands.cpp" line="259"/>
<source>setting property of entry »%1«</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="353"/>
<location filename="../gui/undocommands.cpp" line="355"/>
<source>insertion of %1 entry/entries</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -796,7 +796,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="385"/>
<location filename="../gui/undocommands.cpp" line="387"/>
<source>removal of %1 entry/entries</source>
<translation type="unfinished">
<numerusform></numerusform>
@ -804,7 +804,7 @@ OpenSSL error: %1</source>
</translation>
</message>
<message numerus="yes">
<location filename="../gui/undocommands.cpp" line="415"/>
<location filename="../gui/undocommands.cpp" line="418"/>
<source>move of %1 entry/entries</source>
<translation type="unfinished">
<numerusform></numerusform>