Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactoring. #378

Merged
merged 6 commits into from May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/configdialog.cpp
Expand Up @@ -44,13 +44,13 @@ ConfigDialog::ConfigDialog(MainWindow *parent)
ui->checkBoxAutoPull->setChecked(QtPassSettings::isAutoPull());
ui->checkBoxAutoPush->setChecked(QtPassSettings::isAutoPush());
ui->checkBoxAlwaysOnTop->setChecked(QtPassSettings::isAlwaysOnTop());
ui->comboBoxClipboard->setCurrentIndex(QtPassSettings::getClipBoardTypeRaw());

setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile());
setPwgenPath(QtPassSettings::getPwgenExecutable());
setPasswordConfiguration(QtPassSettings::getPasswordConfiguration());

usePass(QtPassSettings::isUsePass());
useClipboard(QtPassSettings::getClipBoardType());
useSelection(QtPassSettings::isUseSelection());
useAutoclear(QtPassSettings::isUseAutoclear());
useAutoclearPanel(QtPassSettings::isUseAutoclearPanel());
Expand All @@ -59,6 +59,8 @@ ConfigDialog::ConfigDialog(MainWindow *parent)
usePwgen(QtPassSettings::isUsePwgen());
useTemplate(QtPassSettings::isUseTemplate());

on_comboBoxClipboard_activated(QtPassSettings::getClipBoardTypeRaw());

ui->profileTable->verticalHeader()->hide();
ui->profileTable->horizontalHeader()->setStretchLastSection(true);
ui->label->setText(ui->label->text() + VERSION);
Expand Down Expand Up @@ -277,14 +279,6 @@ void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
ui->labelPanelSeconds->setEnabled(state);
}

/**
* @brief ConfigDialog::useClipboard set the clipboard use from MainWindow.
*/
void ConfigDialog::useClipboard(Enums::clipBoardType useClipboard) {
ui->comboBoxClipboard->setCurrentIndex(static_cast<int>(useClipboard));
on_comboBoxClipboard_activated(static_cast<int>(useClipboard));
}

/**
* @brief ConfigDialog::useSelection set the clipboard type use from
* MainWindow.
Expand Down
1 change: 0 additions & 1 deletion src/configdialog.h
Expand Up @@ -27,7 +27,6 @@ class ConfigDialog : public QDialog {
explicit ConfigDialog(MainWindow *parent);
~ConfigDialog();

void useClipboard(Enums::clipBoardType);
void useSelection(bool useSelection);
void useAutoclear(bool useAutoclear);
void useAutoclearPanel(bool useAutoclearPanel);
Expand Down
22 changes: 7 additions & 15 deletions src/keygendialog.cpp
Expand Up @@ -26,16 +26,13 @@ KeygenDialog::~KeygenDialog() { delete ui; }
* @param arg1
*/
void KeygenDialog::on_passphrase1_textChanged(const QString &arg1) {
if (ui->passphrase1->text() == ui->passphrase2->text()) {
ui->buttonBox->setEnabled(true);
bool state = ui->passphrase1->text() == ui->passphrase2->text();
if (state) {
replace("Passphrase", arg1);
if (arg1 == "")
no_protection(true);
else
no_protection(false);
} else {
ui->buttonBox->setEnabled(false);
no_protection(arg1.isEmpty());
}

ui->buttonBox->setEnabled(state);
}

/**
Expand All @@ -52,13 +49,8 @@ void KeygenDialog::on_passphrase2_textChanged(const QString &arg1) {
* @param arg1
*/
void KeygenDialog::on_checkBox_stateChanged(int arg1) {
if (arg1) {
ui->plainTextEdit->setReadOnly(false);
ui->plainTextEdit->setEnabled(true);
} else {
ui->plainTextEdit->setReadOnly(true);
ui->plainTextEdit->setEnabled(false);
}
ui->plainTextEdit->setReadOnly(!arg1);
ui->plainTextEdit->setEnabled(arg1);
}

/**
Expand Down
140 changes: 110 additions & 30 deletions src/keygendialog.ui
Expand Up @@ -65,7 +65,13 @@
</property>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -78,57 +84,132 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="labelPassphrase">
<property name="text">
<string>Passphrase</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelEmail">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Email</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2" colspan="3">
<widget class="QLineEdit" name="passphrase2">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
<item row="0" column="1">
<widget class="QLineEdit" name="email">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="email"/>
</item>
<item row="0" column="3">
<item row="1" column="0">
<widget class="QLabel" name="labelName">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="name">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="2" colspan="3">
<item row="2" column="0">
<widget class="QLabel" name="labelPassphrase">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Passphrase</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="passphrase1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLineEdit" name="name"/>
<item row="3" column="1">
<widget class="QLineEdit" name="passphrase2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="labelPassphraseInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;There is no limit on the length of a passphrase, and it should be carefully chosen. From the perspective of security, the passphrase to unlock the private key is one of the weakest points in GnuPG (and other public-key encryption systems as well) since it is the only protection you have if another individual gets your private key. &lt;br/&gt;Ideally, the passphrase should not use words from a dictionary and should mix the case of alphabetic characters as well as use non-alphabetic characters.&lt;br/&gt;A good passphrase is crucial to the secure use of GnuPG.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="labelPassphraseInfo">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;There is no limit on the length of a passphrase, and it should be carefully chosen. From the perspective of security, the passphrase to unlock the private key is one of the weakest points in GnuPG (and other public-key encryption systems as well) since it is the only protection you have if another individual gets your private key. &lt;br/&gt;Ideally, the passphrase should not use words from a dictionary and should mix the case of alphabetic characters as well as use non-alphabetic characters.&lt;br/&gt;A good passphrase is crucial to the secure use of GnuPG.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -208,7 +289,6 @@ Expire-Date: 0
</widget>
<tabstops>
<tabstop>email</tabstop>
<tabstop>name</tabstop>
<tabstop>passphrase1</tabstop>
<tabstop>passphrase2</tabstop>
<tabstop>checkBox</tabstop>
Expand All @@ -223,8 +303,8 @@ Expire-Date: 0
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>254</x>
<y>473</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
Expand All @@ -239,8 +319,8 @@ Expire-Date: 0
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>322</x>
<y>473</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
Expand Down
35 changes: 14 additions & 21 deletions src/mainwindow.cpp
Expand Up @@ -10,7 +10,6 @@
#include <QMessageBox>
#include <QQueue>
#include <QShortcut>
#include <QSystemTrayIcon>
#include <QTextCodec>
#ifdef Q_OS_WIN
#define WIN32_LEAN_AND_MEAN /*_KILLING_MACHINE*/
Expand Down Expand Up @@ -51,6 +50,7 @@ MainWindow::MainWindow(QWidget *parent)
#endif
ui->setupUi(this);

// i think this should be moved out of MainWindow (in main.cpp as example)
if (!checkConfig()) {
// no working config so this should quit without config anything
QApplication::quit();
Expand Down Expand Up @@ -284,9 +284,9 @@ bool MainWindow::checkConfig() {
// since we are still in constructor, can't directly hide
QTimer::singleShot(10, this, SLOT(hide()));
}
} else if (!QtPassSettings::isUseTrayIcon() && tray != NULL) {
} /*else if (!QtPassSettings::isUseTrayIcon() && tray != NULL) {
destroyTrayIcon();
}
}*/

// dbg()<< version;

Expand Down Expand Up @@ -386,11 +386,10 @@ void MainWindow::config() {
if (QtPassSettings::isAlwaysOnTop()) {
Qt::WindowFlags flags = windowFlags();
this->setWindowFlags(flags | Qt::WindowStaysOnTopHint);
this->show();
} else {
this->setWindowFlags(Qt::Window);
this->show();
}
this->show();

updateProfileBox();
ui->treeView->setRootIndex(proxyModel.mapFromSource(
Expand All @@ -407,8 +406,9 @@ void MainWindow::config() {
updateGitButtonVisibility();
if (QtPassSettings::isUseTrayIcon() && tray == NULL)
initTrayIcon();
else if (!QtPassSettings::isUseTrayIcon() && tray != NULL)
else if (!QtPassSettings::isUseTrayIcon() && tray != NULL) {
destroyTrayIcon();
}
}
freshStart = false;
}
Expand Down Expand Up @@ -1088,28 +1088,21 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name) {
* it
*/
void MainWindow::initTrayIcon() {
if (tray != NULL) {
dbg() << "Creating tray icon again?";
return;
}
if (QSystemTrayIcon::isSystemTrayAvailable() == true) {
// Setup tray icon
this->tray = new TrayIcon(this);
if (tray == NULL)
dbg() << "Allocating tray icon failed.";
} else {
dbg() << "No tray icon for this OS possibly also not show options?";
this->tray = new TrayIcon(this);
// Setup tray icon

if (tray == NULL)
dbg() << "Allocating tray icon failed.";

if (!tray->getIsAllocated()) {
destroyTrayIcon();
}
}

/**
* @brief MainWindow::destroyTrayIcon remove that pesky tray icon
*/
void MainWindow::destroyTrayIcon() {
if (tray == NULL) {
dbg() << "Destroy non existing tray icon?";
return;
}
delete this->tray;
tray = NULL;
}
Expand Down