From c1572abedfb12ddb6c7e0c0b8534af6398009b95 Mon Sep 17 00:00:00 2001 From: dubslow Date: Wed, 15 Oct 2014 11:18:32 -0500 Subject: [PATCH] more details --- src/core.cpp | 29 ++++++++++++++--------------- src/core.h | 1 + src/widget/widget.cpp | 10 ++++++++++ src/widget/widget.h | 3 ++- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index 436c9d5c4..d44c1af72 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -115,11 +115,7 @@ Core::~Core() if (alInDev) alcCaptureCloseDevice(alInDev); - if (pwhash) - { - delete[] pwhash; - pwhash = nullptr; - } + clearPassword(); } Core* Core::getInstance() @@ -1124,7 +1120,9 @@ bool Core::loadConfiguration(QString path) while (error != 0) { error = tox_encrypted_load(tox, reinterpret_cast(data.data()), data.size(), pwhash, TOX_HASH_LENGTH); - // something something QInputDialog new password + emit blockingGetPassword(); + if (!pwhash) + // we need a way to start core without any profile } */ } } @@ -1155,22 +1153,18 @@ void Core::saveConfiguration() } QString profile = Settings::getInstance().getCurrentProfile(); - //qDebug() << "saveConf read profile: " << profile; + if (profile == "") { // no profile active; this should only happen on startup, if at all profile = sanitize(getUsername()); + if (profile == "") // happens on creation of a new Tox ID profile = getIDString(); - //qDebug() << "saveConf: read sanitized user as " << profile; + Settings::getInstance().setCurrentProfile(profile); } - QString path = dir + QDir::separator() + profile + TOX_EXT; - QFileInfo info(path); -// if (!info.exists()) // fall back to old school 'data' -// { //path = dir + QDir::separator() + CONFIG_FILE_NAME; -// qDebug() << "Core:" << path << " does not exist"; -// } + QString path = directory.filePath(profile + TOX_EXT); saveConfiguration(path); } @@ -1204,6 +1198,10 @@ void Core::saveConfiguration(const QString& path) if (Settings::getInstance().getEncryptTox()) { + if (!pwhash) + emit blockingGetPassword(); + //if (!pwhash) + // revert to unsaved...? or maybe we shouldn't even try to get a pw from here ^ int ret = tox_encrypted_save(tox, data, pwhash, TOX_HASH_LENGTH); if (ret == -1) { @@ -1229,8 +1227,9 @@ void Core::switchConfiguration(const QString& profile) } else qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile; - saveConfiguration(); + saveConfiguration(); + clearPassword(); toxTimer->stop(); if (tox) { diff --git a/src/core.h b/src/core.h index 7e8dc632e..071413f2f 100644 --- a/src/core.h +++ b/src/core.h @@ -115,6 +115,7 @@ signals: void connected(); void disconnected(); void blockingClearContacts(); + void blockingGetPassword(); void friendRequestReceived(const QString& userId, const QString& message); void friendMessageReceived(int friendId, const QString& message, bool isAction); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 18231d2ac..a1abb9719 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -147,6 +147,7 @@ Widget::Widget(QWidget *parent) connect(core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated); connect(core, &Core::avInvite, this, &Widget::playRingtone); connect(core, &Core::blockingClearContacts, this, &Widget::clearContactsList, Qt::BlockingQueuedConnection); + connect(core, &Core::blockingGetPassword, this, &Widget::getPassword, Qt::BlockingQueuedConnection); connect(core, SIGNAL(messageSentResult(int,QString,int)), this, SLOT(onMessageSendResult(int,QString,int))); connect(core, SIGNAL(groupSentResult(int,QString,int)), this, SLOT(onGroupSendResult(int,QString,int))); @@ -830,3 +831,12 @@ void Widget::onGroupSendResult(int groupId, const QString& message, int result) if (result == -1) g->chatForm->addSystemInfoMessage("Message failed to send", "red"); } + +void Widget::getPassword() +{ + //QString password = QInputDialog(); + //if (password.isEmpty()) + // core->clearPassword(); + //else + // core->setPassword(password); +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 572ba1922..db5fc282e 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -57,7 +57,6 @@ public: bool isFriendWidgetCurActiveWidget(Friend* f); bool getIsWindowMinimized(); static QList searchProfiles(); - void clearContactsList(); ~Widget(); virtual void closeEvent(QCloseEvent *event); @@ -109,6 +108,8 @@ private slots: void onGroupSendResult(int groupId, const QString& message, int result); void playRingtone(); void onIconClick(); + void clearContactsList(); + void getPassword(); private: void hideMainForms();