diff options
author | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-11-23 23:48:56 +0100 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-11-23 23:48:56 +0100 |
commit | 02f3485d9a94bee60ae62a3e3216bf91ff442227 (patch) | |
tree | e6b8f538cefbbb02b83a692282c32f60927a857a | |
parent | 00e24b8f68c8467ada37ec5291592dc2a9b75303 (diff) |
uncrustify
-rw-r--r-- | configdialog.cpp | 216 | ||||
-rw-r--r-- | configdialog.h | 7 | ||||
-rw-r--r-- | keygendialog.cpp | 50 | ||||
-rw-r--r-- | keygendialog.h | 1 | ||||
-rw-r--r-- | main.cpp | 8 | ||||
-rw-r--r-- | mainwindow.cpp | 699 | ||||
-rw-r--r-- | mainwindow.h | 22 | ||||
-rw-r--r-- | passworddialog.cpp | 42 | ||||
-rw-r--r-- | progressindicator.cpp | 36 | ||||
-rw-r--r-- | progressindicator.h | 92 | ||||
-rw-r--r-- | singleapplication.cpp | 87 | ||||
-rw-r--r-- | singleapplication.h | 22 | ||||
-rw-r--r-- | storemodel.cpp | 27 | ||||
-rw-r--r-- | trayicon.cpp | 70 | ||||
-rw-r--r-- | trayicon.h | 4 | ||||
-rw-r--r-- | usersdialog.cpp | 32 | ||||
-rw-r--r-- | usersdialog.h | 7 | ||||
-rw-r--r-- | util.cpp | 39 |
18 files changed, 728 insertions, 733 deletions
diff --git a/configdialog.cpp b/configdialog.cpp index 69044908..6d61db86 100644 --- a/configdialog.cpp +++ b/configdialog.cpp @@ -44,7 +44,8 @@ ConfigDialog::~ConfigDialog() * @brief ConfigDialog::setPassPath * @param path */ -void ConfigDialog::setPassPath(QString path) { +void ConfigDialog::setPassPath(QString path) +{ ui->passPath->setText(path); } @@ -52,7 +53,8 @@ void ConfigDialog::setPassPath(QString path) { * @brief ConfigDialog::setGitPath * @param path */ -void ConfigDialog::setGitPath(QString path) { +void ConfigDialog::setGitPath(QString path) +{ ui->gitPath->setText(path); if (path.isEmpty()) { useGit(false); @@ -66,7 +68,8 @@ void ConfigDialog::setGitPath(QString path) { * @brief ConfigDialog::setGpgPath * @param path */ -void ConfigDialog::setGpgPath(QString path) { +void ConfigDialog::setGpgPath(QString path) +{ ui->gpgPath->setText(path); } @@ -74,7 +77,8 @@ void ConfigDialog::setGpgPath(QString path) { * @brief ConfigDialog::setStorePath * @param path */ -void ConfigDialog::setStorePath(QString path) { +void ConfigDialog::setStorePath(QString path) +{ ui->storePath->setText(path); } @@ -82,7 +86,8 @@ void ConfigDialog::setStorePath(QString path) { * @brief ConfigDialog::getPassPath * @return */ -QString ConfigDialog::getPassPath() { +QString ConfigDialog::getPassPath() +{ return ui->passPath->text(); } @@ -90,7 +95,8 @@ QString ConfigDialog::getPassPath() { * @brief ConfigDialog::getGitPath * @return */ -QString ConfigDialog::getGitPath() { +QString ConfigDialog::getGitPath() +{ return ui->gitPath->text(); } @@ -98,7 +104,8 @@ QString ConfigDialog::getGitPath() { * @brief ConfigDialog::getGpgPath * @return */ -QString ConfigDialog::getGpgPath() { +QString ConfigDialog::getGpgPath() +{ return ui->gpgPath->text(); } @@ -106,7 +113,8 @@ QString ConfigDialog::getGpgPath() { * @brief ConfigDialog::getStorePath * @return */ -QString ConfigDialog::getStorePath() { +QString ConfigDialog::getStorePath() +{ return ui->storePath->text(); } @@ -114,7 +122,8 @@ QString ConfigDialog::getStorePath() { * @brief ConfigDialog::usePass * @return */ -bool ConfigDialog::usePass() { +bool ConfigDialog::usePass() +{ return ui->radioButtonPass->isChecked(); } @@ -122,7 +131,8 @@ bool ConfigDialog::usePass() { * @brief ConfigDialog::usePass * @param pass */ -void ConfigDialog::usePass(bool usePass) { +void ConfigDialog::usePass(bool usePass) +{ if (usePass) { ui->radioButtonNative->setChecked(false); ui->radioButtonPass->setChecked(true); @@ -152,7 +162,8 @@ void ConfigDialog::on_radioButtonPass_clicked() /** * @brief ConfigDialog::setGroupBoxState */ -void ConfigDialog::setGroupBoxState() { +void ConfigDialog::setGroupBoxState() +{ if (ui->radioButtonPass->isChecked()) { ui->groupBoxNative->setEnabled(false); ui->groupBoxPass->setEnabled(true); @@ -166,13 +177,13 @@ void ConfigDialog::setGroupBoxState() { * @brief ConfigDialog::selectExecutable * @return */ -QString ConfigDialog::selectExecutable() { +QString ConfigDialog::selectExecutable() +{ QFileDialog dialog(this); dialog.setFileMode(QFileDialog::ExistingFile); dialog.setOption(QFileDialog::ReadOnly); - if (dialog.exec()) { + if (dialog.exec()) return dialog.selectedFiles().first(); - } else return ""; } @@ -180,14 +191,14 @@ QString ConfigDialog::selectExecutable() { * @brief ConfigDialog::selectFolder * @return */ -QString ConfigDialog::selectFolder() { +QString ConfigDialog::selectFolder() +{ QFileDialog dialog(this); dialog.setFileMode(QFileDialog::Directory); dialog.setFilter(QDir::NoFilter); dialog.setOption(QFileDialog::ShowDirsOnly); - if (dialog.exec()) { + if (dialog.exec()) return dialog.selectedFiles().first(); - } else return ""; } @@ -212,9 +223,8 @@ void ConfigDialog::on_toolButtonGit_clicked() void ConfigDialog::on_toolButtonGpg_clicked() { QString gpg = selectExecutable(); - if (!gpg.isEmpty()) { + if (!gpg.isEmpty()) ui->gpgPath->setText(gpg); - } } /** @@ -223,9 +233,8 @@ void ConfigDialog::on_toolButtonGpg_clicked() void ConfigDialog::on_toolButtonPass_clicked() { QString pass = selectExecutable(); - if (!pass.isEmpty()) { + if (!pass.isEmpty()) ui->passPath->setText(pass); - } } /** @@ -234,9 +243,8 @@ void ConfigDialog::on_toolButtonPass_clicked() void ConfigDialog::on_toolButtonStore_clicked() { QString store = selectFolder(); - if (!store.isEmpty()) { // TODO call check + if (!store.isEmpty()) // TODO call check ui->storePath->setText(store); - } } /** @@ -448,7 +456,7 @@ void ConfigDialog::genKey(QString batch, QDialog *dialog) */ void ConfigDialog::setProfiles(QHash<QString, QString> profiles, QString profile) { - //qDebug() << profiles; + // qDebug() << profiles; if (profiles.contains("")) { profiles.remove(""); // remove weird "" key value pairs @@ -462,10 +470,9 @@ void ConfigDialog::setProfiles(QHash<QString, QString> profiles, QString profile if (!i.value().isEmpty() && !i.key().isEmpty()) { ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key())); ui->profileTable->setItem(n, 1, new QTableWidgetItem(i.value())); - //qDebug() << "naam:" + i.key(); - if (i.key() == profile) { + // qDebug() << "naam:" + i.key(); + if (i.key() == profile) ui->profileTable->selectRow(n); - } } n++; } @@ -480,9 +487,9 @@ QHash<QString, QString> ConfigDialog::getProfiles() QHash<QString, QString> profiles; // Check? for (int i = 0; i < ui->profileTable->rowCount(); i++) { - QTableWidgetItem* pathItem = ui->profileTable->item(i, 1); + QTableWidgetItem *pathItem = ui->profileTable->item(i, 1); if (0 != pathItem) { - QTableWidgetItem* item = ui->profileTable->item(i, 0); + QTableWidgetItem *item = ui->profileTable->item(i, 0); if (item == 0) { qDebug() << "empty name, shoud fix in frontend"; continue; @@ -511,26 +518,24 @@ void ConfigDialog::on_addButton_clicked() */ void ConfigDialog::on_deleteButton_clicked() { - QSet<int> selectedRows; //we use a set to prevent doubles - QList<QTableWidgetItem*> itemList = ui->profileTable->selectedItems(); + QSet<int> selectedRows; // we use a set to prevent doubles + QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems(); if (itemList.count() == 0) { QMessageBox::warning(this, tr("No profile selected"), - tr("No profile selected to delete")); + tr("No profile selected to delete")); return; } - QTableWidgetItem * item; - foreach(item, itemList) - selectedRows.insert(item->row()); - //get a list, and sort it big to small + QTableWidgetItem *item; + foreach (item, itemList) + selectedRows.insert(item->row()); + // get a list, and sort it big to small QList<int> rows = selectedRows.toList(); qSort(rows.begin(), rows.end()); - //now actually do the removing: - foreach(int row, rows) { - ui->profileTable->removeRow(row); - } - if (ui->profileTable->rowCount() < 1) { + // now actually do the removing: + foreach (int row, rows) + ui->profileTable->removeRow(row); + if (ui->profileTable->rowCount() < 1) ui->deleteButton->setEnabled(false); - } } void ConfigDialog::criticalMessage(const QString &title, const QString &text) @@ -543,14 +548,15 @@ void ConfigDialog::criticalMessage(const QString &title, const QString &text) */ void ConfigDialog::wizard() { - //mainWindow->checkConfig(); + // mainWindow->checkConfig(); bool clean = false; QString gpg = ui->gpgPath->text(); - //QString gpg = mainWindow->getGpgExecutable(); - if(!QFile(gpg).exists()){ + // QString gpg = mainWindow->getGpgExecutable(); + if (!QFile(gpg).exists()) { criticalMessage(tr("GnuPG not found"), - tr("Please install GnuPG on your system.<br>Install <strong>gpg</strong> using your favorite package manager<br>or <a href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it from GnuPG.org")); + tr( + "Please install GnuPG on your system.<br>Install <strong>gpg</strong> using your favorite package manager<br>or <a href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it from GnuPG.org")); clean = true; } @@ -558,9 +564,8 @@ void ConfigDialog::wizard() qDebug() << names; if (QFile(gpg).exists() && names.empty()) { KeygenDialog d(this); - if (!d.exec()) { + if (!d.exec()) return; - } } QString passStore = ui->storePath->text(); @@ -568,27 +573,29 @@ void ConfigDialog::wizard() if (!QFile(passStore).exists()) { // TODO pass version? if (QMessageBox::question(this, tr("Create password-store?"), - tr("Would you like to create a password-store at %1?").arg(passStore), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - QDir().mkdir(passStore); + tr("Would you like to create a password-store at %1?").arg( + passStore), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + QDir().mkdir(passStore); #ifdef Q_OS_WIN - SetFileAttributes(passStore.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN); + SetFileAttributes(passStore.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN); #endif - if(useGit()) { - mainWindow->executePassGitInit(); - } - mainWindow->userDialog(passStore); + if (useGit()) + mainWindow->executePassGitInit(); + mainWindow->userDialog(passStore); } } - if(!QFile(passStore + ".gpg-id").exists()){ + if (!QFile(passStore + ".gpg-id").exists()) { qDebug() << ".gpg-id file does not exist"; if (!clean) { criticalMessage(tr("Password store not initialised"), - tr("The folder %1 doesn't seem to be a password store or is not yet initialised.").arg(passStore)); + tr( + "The folder %1 doesn't seem to be a password store or is not yet initialised.").arg( + passStore)); } - while(!QFile(passStore).exists()) { + while (!QFile(passStore).exists()) { on_toolButtonStore_clicked(); // allow user to cancel if (passStore == ui->storePath->text()) @@ -608,7 +615,8 @@ void ConfigDialog::wizard() * @brief ConfigDialog::useTrayIcon * @return */ -bool ConfigDialog::useTrayIcon() { +bool ConfigDialog::useTrayIcon() +{ return ui->checkBoxUseTrayIcon->isChecked(); } @@ -616,7 +624,8 @@ bool ConfigDialog::useTrayIcon() { * @brief ConfigDialog::hideOnClose * @return */ -bool ConfigDialog::hideOnClose() { +bool ConfigDialog::hideOnClose() +{ return ui->checkBoxHideOnClose->isEnabled() && ui->checkBoxHideOnClose->isChecked(); } @@ -624,7 +633,8 @@ bool ConfigDialog::hideOnClose() { * @brief ConfigDialog::useTrayIcon * @param useSystray */ -void ConfigDialog::useTrayIcon(bool useSystray) { +void ConfigDialog::useTrayIcon(bool useSystray) +{ ui->checkBoxUseTrayIcon->setChecked(useSystray); ui->checkBoxHideOnClose->setEnabled(useSystray); ui->checkBoxStartMinimized->setEnabled(useSystray); @@ -638,14 +648,16 @@ void ConfigDialog::useTrayIcon(bool useSystray) { * @brief ConfigDialog::hideOnClose * @param hideOnClose */ -void ConfigDialog::hideOnClose(bool hideOnClose) { +void ConfigDialog::hideOnClose(bool hideOnClose) +{ ui->checkBoxHideOnClose->setChecked(hideOnClose); } /** * @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked */ -void ConfigDialog::on_checkBoxUseTrayIcon_clicked() { +void ConfigDialog::on_checkBoxUseTrayIcon_clicked() +{ if (ui->checkBoxUseTrayIcon->isChecked()) { ui->checkBoxHideOnClose->setEnabled(true); ui->checkBoxStartMinimized->setEnabled(true); @@ -659,7 +671,8 @@ void ConfigDialog::on_checkBoxUseTrayIcon_clicked() { * @brief ConfigDialog::closeEvent * @param event */ -void ConfigDialog::closeEvent(QCloseEvent *event) { +void ConfigDialog::closeEvent(QCloseEvent *event) +{ // TODO save window size or something? event->accept(); } @@ -712,7 +725,8 @@ void ConfigDialog::on_toolButtonPwgen_clicked() * @brief ConfigDialog::getPwgenPath * @return */ -QString ConfigDialog::getPwgenPath() { +QString ConfigDialog::getPwgenPath() +{ return ui->pwgenPath->text(); } @@ -744,10 +758,10 @@ void ConfigDialog::on_checkBoxUsePwgen_clicked() * @brief ConfigDialog::usePwgen * @param usePwgen */ -void ConfigDialog::usePwgen(bool usePwgen) { - if (ui->pwgenPath->text().isEmpty()) { +void ConfigDialog::usePwgen(bool usePwgen) +{ + if (ui->pwgenPath->text().isEmpty()) usePwgen = false; - } ui->checkBoxUsePwgen->setChecked(usePwgen); on_checkBoxUsePwgen_clicked(); } @@ -756,7 +770,8 @@ void ConfigDialog::usePwgen(bool usePwgen) { * @brief ConfigDialog::useSymbols * @param useSymbols */ -void ConfigDialog::useSymbols(bool useSymbols) { +void ConfigDialog::useSymbols(bool useSymbols) +{ ui->checkBoxUseSymbols->setChecked(useSymbols); } @@ -764,11 +779,13 @@ void ConfigDialog::useSymbols(bool useSymbols) { * @brief ConfigDialog::setPasswordLength * @param pwLen */ -void ConfigDialog::setPasswordLength(int pwLen) { +void ConfigDialog::setPasswordLength(int pwLen) +{ ui->spinBoxPasswordLength->setValue(pwLen); } -void ConfigDialog::setPasswordChars(QString pwChars) { +void ConfigDialog::setPasswordChars(QString pwChars) +{ ui->lineEditPasswordChars->setText(pwChars); } @@ -776,7 +793,8 @@ void ConfigDialog::setPasswordChars(QString pwChars) { * @brief ConfigDialog::usePwgen * @return */ -bool ConfigDialog::usePwgen() { +bool ConfigDialog::usePwgen() +{ return ui->checkBoxUsePwgen->isChecked(); } @@ -784,7 +802,8 @@ bool ConfigDialog::usePwgen() { * @brief ConfigDialog::useSymbols * @return */ -bool ConfigDialog::useSymbols() { +bool ConfigDialog::useSymbols() +{ return ui->checkBoxUseSymbols->isChecked(); } @@ -792,7 +811,8 @@ bool ConfigDialog::useSymbols() { * @brief ConfigDialog::getPasswordLength * @return */ -int ConfigDialog::getPasswordLength() { +int ConfigDialog::getPasswordLength() +{ return ui->spinBoxPasswordLength->value(); } @@ -800,7 +820,8 @@ int ConfigDialog::getPasswordLength() { * @brief ConfigDialog::getPasswordChars * @return */ -QString ConfigDialog::getPasswordChars() { +QString ConfigDialog::getPasswordChars() +{ return ui->lineEditPasswordChars->text(); } @@ -808,7 +829,8 @@ QString ConfigDialog::getPasswordChars() { * @brief ConfigDialog::startMinimized * @return */ -bool ConfigDialog::startMinimized() { +bool ConfigDialog::startMinimized() +{ return ui->checkBoxStartMinimized->isChecked(); } @@ -816,14 +838,16 @@ bool ConfigDialog::startMinimized() { * @brief ConfigDialog::startMinimized * @param startMinimized */ -void ConfigDialog::startMinimized(bool startMinimized) { +void ConfigDialog::startMinimized(bool startMinimized) +{ ui->checkBoxStartMinimized->setChecked(startMinimized); } /** * @brief ConfigDialog::on_checkBoxUseTemplate_clicked */ -void ConfigDialog::on_checkBoxUseTemplate_clicked() { +void ConfigDialog::on_checkBoxUseTemplate_clicked() +{ ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked()); ui->checkBoxTemplateAllFields->setEnabled(ui->checkBoxUseTemplate->isChecked()); } @@ -832,16 +856,18 @@ void ConfigDialog::on_checkBoxUseTemplate_clicked() { * @brief ConfigDialog::useTemplate * @param useTemplate */ -void ConfigDialog::useTemplate(bool useTemplate) { - ui->checkBoxUseTemplate->setChecked(useTemplate); - on_checkBoxUseTemplate_clicked(); +void ConfigDialog::useTemplate(bool useTemplate) +{ + ui->checkBoxUseTemplate->setChecked(useTemplate); + on_checkBoxUseTemplate_clicked(); } /** * @brief ConfigDialog::useTemplate * @return */ -bool ConfigDialog::useTemplate() { +bool ConfigDialog::useTemplate() +{ return ui->checkBoxUseTemplate->isChecked(); } @@ -849,7 +875,8 @@ bool ConfigDialog::useTemplate() { * @brief ConfigDialog::setTemplate * @param passTemplate */ -void ConfigDialog::setTemplate(QString passTemplate) { +void ConfigDialog::setTemplate(QString passTemplate) +{ ui->plainTextEditTemplate->setPlainText(passTemplate); } @@ -857,7 +884,8 @@ void ConfigDialog::setTemplate(QString passTemplate) { * @brief ConfigDialog::getTemplate * @return */ -QString ConfigDialog::getTemplate() { +QString ConfigDialog::getTemplate() +{ return ui->plainTextEditTemplate->toPlainText(); } @@ -865,7 +893,8 @@ QString ConfigDialog::getTemplate() { * @brief ConfigDialog::autoPull * @param autoPull */ -void ConfigDialog::autoPull(bool autoPull) { +void ConfigDialog::autoPull(bool autoPull) +{ ui->checkBoxAutoPull->setChecked(autoPull); } @@ -873,7 +902,8 @@ void ConfigDialog::autoPull(bool autoPull) { * @brief ConfigDialog::autoPush * @param autoPush */ -void ConfigDialog::autoPush(bool autoPush) { +void ConfigDialog::autoPush(bool autoPush) +{ ui->checkBoxAutoPush->setChecked(autoPush); } @@ -881,7 +911,8 @@ void ConfigDialog::autoPush(bool autoPush) { * @brief ConfigDialog::autoPull * @return */ -bool ConfigDialog::autoPull() { +bool ConfigDialog::autoPull() +{ return ui->checkBoxAutoPull->isChecked(); } @@ -889,7 +920,8 @@ bool ConfigDialog::autoPull() { * @brief ConfigDialog::autoPush * @return */ -bool ConfigDialog::autoPush() { +bool ConfigDialog::autoPush() +{ return ui->checkBoxAutoPush->isChecked(); } @@ -897,7 +929,8 @@ bool ConfigDialog::autoPush() { * @brief ConfigDialog::templateAllFields * @return */ -bool ConfigDialog::templateAllFields() { +bool ConfigDialog::templateAllFields() +{ return ui->checkBoxTemplateAllFields->isChecked(); } @@ -905,6 +938,7 @@ bool ConfigDialog::templateAllFields() { * @brief ConfigDialog::templateAllFields * @param templateAll */ -void ConfigDialog::templateAllFields(bool templateAll) { +void ConfigDialog::templateAllFields(bool templateAll) +{ ui->checkBoxTemplateAllFields->setChecked(templateAll); } diff --git a/configdialog.h b/configdialog.h index d18cd0ab..7cc2fa12 100644 --- a/configdialog.h +++ b/configdialog.h @@ -8,7 +8,6 @@ #include <QCloseEvent> namespace Ui { - struct UserInfo; class ConfigDialog; @@ -39,7 +38,7 @@ public: QString getGitPath(); QString getGpgPath(); QString getStorePath(); - QHash<QString,QString> getProfiles(); + QHash<QString, QString> getProfiles(); bool usePass(); MainWindow::clipBoardType useClipboard(); bool useAutoclear(); @@ -106,8 +105,8 @@ private: void setGroupBoxState(); QString selectExecutable(); QString selectFolder(); - // QMessageBox::critical with hack to avoid crashes with - // Qt 5.4.1 when QApplication::exec was not yet called +// QMessageBox::critical with hack to avoid crashes with +// Qt 5.4.1 when QApplication::exec was not yet called void criticalMessage(const QString &title, const QString &text); MainWindow *mainWindow; }; diff --git a/keygendialog.cpp b/keygendialog.cpp index 64d31a61..64ae1ca8 100644 --- a/keygendialog.cpp +++ b/keygendialog.cpp @@ -22,11 +22,10 @@ void KeygenDialog::on_passphrase1_textChanged(const QString &arg1) if (ui->passphrase1->text() == ui->passphrase2->text()) { ui->buttonBox->setEnabled(true); replace("Passphrase", arg1); - if (arg1 == "") { + if (arg1 == "") no_protection(true); - } else { + else no_protection(false); - } } else { ui->buttonBox->setEnabled(false); } @@ -66,13 +65,12 @@ void KeygenDialog::on_name_textChanged(const QString &arg1) void KeygenDialog::replace(QString key, QString value) { QStringList clear; - QString expert = ui->plainTextEdit->toPlainText(); - QStringList lines = expert.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); + QString expert = ui->plainTextEdit->toPlainText(); + QStringList lines = expert.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); foreach (QString line, lines) { line.replace(QRegExp(key+":.*"), key + ": " + value); - if (key == "Passphrase") { + if (key == "Passphrase") line.replace("%no-protection", "Passphrase: " + value); - } clear.append(line); } ui->plainTextEdit->setPlainText(clear.join("\n")); @@ -82,25 +80,22 @@ void KeygenDialog::replace(QString key, QString value) * @brief KeygenDialog::no_protection * @param enable */\ -void KeygenDialog::no_protection(bool enable) + void KeygenDialog::no_protection(bool enable) { QStringList clear; - QString expert = ui->plainTextEdit->toPlainText(); - QStringList lines = expert.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); + QString expert = ui->plainTextEdit->toPlainText(); + QStringList lines = expert.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); foreach (QString line, lines) { bool remove = false; if (!enable) { - if (line.indexOf("%no-protection") == 0) { + if (line.indexOf("%no-protection") == 0) remove = true; - } } else { - if (line.indexOf("Passphrase") == 0) { + if (line.indexOf("Passphrase") == 0) line = "%no-protection"; - } } - if (!remove) { + if (!remove) clear.append(line); - } } ui->plainTextEdit->setPlainText(clear.join("\n")); } @@ -111,37 +106,36 @@ void KeygenDialog::no_protection(bool enable) */ void KeygenDialog::done(int r) { - if(QDialog::Accepted == r) // ok was pressed - { + if (QDialog::Accepted == r) { // ok was pressed ui->widget->setEnabled(false); ui->buttonBox->setEnabled(false); ui->checkBox->setEnabled(false); ui->plainTextEdit->setEnabled(false); - QProgressIndicator* pi = new QProgressIndicator(); + QProgressIndicator *pi = new QProgressIndicator(); pi->startAnimation(); pi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); ui->frame->hide(); - ui->label->setText(QString("This operation can take some minutes.<br />") + - "We need to generate a lot of random bytes. It is a good idea to perform " - "some other action (type on the keyboard, move the mouse, utilize the " - "disks) during the prime generation; this gives the random number " - "generator a better chance to gain enough entropy."); + ui->label->setText(QString( + "This operation can take some minutes.<br />") + +"We need to generate a lot of random bytes. It is a good idea to perform " + "some other action (type on the keyboard, move the mouse, utilize the " + "disks) during the prime generation; this gives the random number " + "generator a better chance to gain enough entropy."); this->layout()->addWidget(pi); this->show(); dialog->genKey(ui->plainTextEdit->toPlainText(), this); - } - else // cancel, close or exc was pressed - { + } else { // cancel, close or exc was pressed QDialog::done(r); return; } } -void KeygenDialog::closeEvent(QCloseEvent *event) { +void KeygenDialog::closeEvent(QCloseEvent *event) +{ // TODO save window size or somethign event->accept(); } diff --git a/keygendialog.h b/keygendialog.h index 01f4a39a..4058108e 100644 --- a/keygendialog.h +++ b/keygendialog.h @@ -33,7 +33,6 @@ private: void done(int r); void no_protection(bool enable); ConfigDialog *dialog; - }; #endif // KEYGENDIALOG_H @@ -7,9 +7,8 @@ int main(int argc, char *argv[]) // check for stupid apple psid or whatever flag QString text = ""; for (int i = 1; i < argc; ++i) { - if (i > 1) { + if (i > 1) text += " "; - } text += argv[i]; } #if SINGLE_APP @@ -18,9 +17,8 @@ int main(int argc, char *argv[]) name = qgetenv("USERNAME"); SingleApplication app(argc, argv, name + "QtPass"); if (app.isRunning()) { - if (text.length() > 0) { + if (text.length() > 0) app.sendMessage(text); - } return 0; } #else @@ -40,7 +38,7 @@ int main(int argc, char *argv[]) // locale = "ar_MA"; translator.load(QString(":localization/localization_") + locale + QString(".qm")); app.installTranslator(&translator); - app.setLayoutDirection(QObject::tr("LTR")=="RTL" ? Qt::RightToLeft : Qt::LeftToRight); + app.setLayoutDirection(QObject::tr("LTR") == "RTL" ? Qt::RightToLeft : Qt::LeftToRight); MainWindow w; diff --git a/mainwindow.cpp b/mainwindow.cpp index d2774431..7d816c34 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -34,9 +34,11 @@ MainWindow::MainWindow(QWidget *parent) : keygen(NULL), tray(NULL) { -// connect(process.data(), SIGNAL(readyReadStandardOutput()), this, SLOT(readyRead())); - connect(process.data(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); - connect(process.data(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus))); +// connect(process.data(), SIGNAL(readyReadStandardOutput()), this, SLOT(readyRead())); + connect(process.data(), SIGNAL(error(QProcess::ProcessError)), this, + SLOT(processError(QProcess::ProcessError))); + connect(process.data(), SIGNAL(finished(int, QProcess::ExitStatus)), this, + SLOT(processFinished(int, QProcess::ExitStatus))); ui->setupUi(this); enableUiElements(true); wrapperRunning = false; @@ -55,7 +57,8 @@ MainWindow::MainWindow(QWidget *parent) : QTimer::singleShot(10, this, SLOT(focusInput())); } -void MainWindow::focusInput() { +void MainWindow::focusInput() +{ ui->lineEdit->selectAll(); ui->lineEdit->setFocus(); } @@ -75,22 +78,25 @@ MainWindow::~MainWindow() #endif } -QSettings &MainWindow::getSettings() { +QSettings &MainWindow::getSettings() +{ if (!settings) { - QString portable_ini = QCoreApplication::applicationDirPath() + QDir::separator() + "qtpass.ini"; - //qDebug() << "Settings file: " + portable_ini; + QString portable_ini = QCoreApplication::applicationDirPath() + QDir::separator() + + "qtpass.ini"; + // qDebug() << "Settings file: " + portable_ini; if (QFile(portable_ini).exists()) { - // qDebug() << "Settings file exists, loading it in"; + // qDebug() << "Settings file exists, loading it in"; settings.reset(new QSettings(portable_ini, QSettings::IniFormat)); } else { - //qDebug() << "Settings file does not exist, use defaults"; + // qDebug() << "Settings file does not exist, use defaults"; settings.reset(new QSettings("IJHack", "QtPass")); } } return *settings; } -void MainWindow::mountWebDav() { +void MainWindow::mountWebDav() +{ #ifdef Q_OS_WIN char dst[20] = {0}; NETRESOURCEA netres; @@ -99,26 +105,32 @@ void MainWindow::mountWebDav() { netres.lpLocalName = 0; netres.lpRemoteName = webDavUrl.toUtf8().data(); DWORD size = sizeof(dst); - DWORD r = WNetUseConnectionA(reinterpret_cast<HWND>(effectiveWinId()), &netres, webDavPassword.toUtf8().constData(), - webDavUser.toUtf8().constData(), CONNECT_TEMPORARY | CONNECT_INTERACTIVE | CONNECT_REDIRECT, - dst, &size, 0); + DWORD r = WNetUseConnectionA( + reinterpret_cast<HWND>(effectiveWinId()), &netres, webDavPassword.toUtf8().constData(), + webDavUser.toUtf8().constData(), CONNECT_TEMPORARY | CONNECT_INTERACTIVE | CONNECT_REDIRECT, + dst, &size, 0); if (r == NO_ERROR) { passStore = dst; } else { char message[256] = {0}; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, r, 0, message, sizeof(message), 0); ui->textBrowser->setTextColor(Qt::red); - ui->textBrowser->setText(tr("Failed to connect WebDAV:\n") + message + " (0x" + QString::number(r, 16) + ")"); + ui->textBrowser->setText(tr( + "Failed to connect WebDAV:\n") + message + " (0x" + + QString::number(r, 16) + ")"); } #else - fusedav.start("fusedav -o nonempty -u \"" + webDavUser + "\" " + webDavUrl + " \"" + passStore + '"'); + fusedav.start( + "fusedav -o nonempty -u \"" + webDavUser + "\" " + webDavUrl + " \"" + passStore + '"'); fusedav.waitForStarted(); if (fusedav.state() == QProcess::Running) { QString pwd = webDavPassword; bool ok = true; if (pwd.isEmpty()) { pwd = QInputDialog::getText(this, tr("QtPass WebDAV password"), - tr("Enter password to connect to WebDAV:"), QLineEdit::Password, "", &ok); + tr( + "Enter password to connect to WebDAV:"), QLineEdit::Password, "", + &ok); } if (ok && !pwd.isEmpty()) { fusedav.write(pwd.toUtf8() + '\n'); @@ -130,12 +142,10 @@ void MainWindow::mountWebDav() { } QString error = fusedav.readAllStandardError(); int prompt = error.indexOf("Password:"); - if (prompt >= 0) { + if (prompt >= 0) |