Browse Source

Add button to delete password

pull/1793/head
tux3 10 years ago
parent
commit
0642c1b0d7
  1. 15
      src/profile.cpp
  2. 1
      src/profile.h
  3. 23
      src/widget/form/profileform.cpp
  4. 2
      src/widget/form/profileform.h
  5. 46
      src/widget/form/profileform.ui

15
src/profile.cpp

@ -4,6 +4,9 @@
#include "src/core/core.h" #include "src/core/core.h"
#include "src/historykeeper.h" #include "src/historykeeper.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
#include "src/widget/widget.h"
#include "src/widget/form/setpassworddialog.h"
#include "src/nexus.h"
#include <cassert> #include <cassert>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -323,3 +326,15 @@ void Profile::restartCore()
saveToxSave(); saveToxSave();
QMetaObject::invokeMethod(core, "reset"); QMetaObject::invokeMethod(core, "reset");
} }
void Profile::setPassword(QString newPassword)
{
QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile();
password = newPassword;
core->setPassword(password);
saveToxSave();
HistoryKeeper::getInstance()->importMessages(oldMessages);
Nexus::getDesktopGUI()->reloadHistory();
}

1
src/profile.h

@ -30,6 +30,7 @@ public:
bool isEncrypted(); ///< Returns true if we have a password set (doesn't check the actual file on disk) bool isEncrypted(); ///< Returns true if we have a password set (doesn't check the actual file on disk)
bool checkPassword(); ///< Checks whether the password is valid bool checkPassword(); ///< Checks whether the password is valid
QString getPassword(); QString getPassword();
void setPassword(QString newPassword); ///< Changes the encryption password and re-saves everything with it
QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted
void saveToxSave(); ///< Saves the profile's .tox save, encrypted if needed. Invalid on deleted profiles. void saveToxSave(); ///< Saves the profile's .tox save, encrypted if needed. Invalid on deleted profiles.

23
src/widget/form/profileform.cpp

@ -94,6 +94,8 @@ ProfileForm::ProfileForm(QWidget *parent) :
connect(bodyUI->exportButton, &QPushButton::clicked, this, &ProfileForm::onExportClicked); connect(bodyUI->exportButton, &QPushButton::clicked, this, &ProfileForm::onExportClicked);
connect(bodyUI->deleteButton, &QPushButton::clicked, this, &ProfileForm::onDeleteClicked); connect(bodyUI->deleteButton, &QPushButton::clicked, this, &ProfileForm::onDeleteClicked);
connect(bodyUI->logoutButton, &QPushButton::clicked, this, &ProfileForm::onLogoutClicked); connect(bodyUI->logoutButton, &QPushButton::clicked, this, &ProfileForm::onLogoutClicked);
connect(bodyUI->deletePassButton, &QPushButton::clicked, this, &ProfileForm::onDeletePassClicked);
connect(bodyUI->changePassButton, &QPushButton::clicked, this, &ProfileForm::onChangePassClicked);
connect(core, &Core::usernameSet, this, [=](const QString& val) { bodyUI->userName->setText(val); }); connect(core, &Core::usernameSet, this, [=](const QString& val) { bodyUI->userName->setText(val); });
connect(core, &Core::statusMessageSet, this, [=](const QString& val) { bodyUI->statusMessage->setText(val); }); connect(core, &Core::statusMessageSet, this, [=](const QString& val) { bodyUI->statusMessage->setText(val); });
@ -306,3 +308,24 @@ void ProfileForm::onSaveQrClicked()
GUI::showWarning(tr("Failed to copy file"), tr("The file you chose could not be written to.")); GUI::showWarning(tr("Failed to copy file"), tr("The file you chose could not be written to."));
} }
} }
void ProfileForm::onDeletePassClicked()
{
Profile* pro = Nexus::getProfile();
if (!pro->isEncrypted())
{
GUI::showInfo(tr("Nothing to remove"), tr("Your profile does not have a password!"));
return;
}
if (!GUI::askQuestion(tr("Really delete password?","deletion confirmation title"),
tr("Are you sure you want to delete your password?","deletion confirmation text")))
return;
Nexus::getProfile()->setPassword(QString());
}
void ProfileForm::onChangePassClicked()
{
}

2
src/widget/form/profileform.h

@ -69,6 +69,8 @@ private slots:
void onLogoutClicked(); void onLogoutClicked();
void onCopyQrClicked(); void onCopyQrClicked();
void onSaveQrClicked(); void onSaveQrClicked();
void onDeletePassClicked();
void onChangePassClicked();
private: private:
void refreshProfiles(); void refreshProfiles();

46
src/widget/form/profileform.ui

@ -37,7 +37,7 @@
<widget class="QWidget" name="scrollAreaWidgetContents"> <widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>-3</x> <x>-41</x>
<y>0</y> <y>0</y>
<width>630</width> <width>630</width>
<height>625</height> <height>625</height>
@ -234,6 +234,50 @@ Profile does not contain your history.</string>
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="deletePassButton">
<property name="text">
<string>Delete password</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changePassButton">
<property name="text">
<string>Change password</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

Loading…
Cancel
Save