add a logout option to the menu

This commit is contained in:
Stephen Birarda 2014-02-21 17:13:22 -08:00
parent 0686539734
commit 6165ca658a
4 changed files with 21 additions and 2 deletions

View file

@ -91,6 +91,8 @@ Menu::Menu() :
0,
this,
SLOT(loginForCurrentDomain())));
addActionToQMenuAndActionHash(fileMenu, MenuOption::Logout, 0, &AccountManager::getInstance(), SLOT(logout()));
addDisabledActionAndSeparator(fileMenu, "Scripts");
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));

View file

@ -245,6 +245,7 @@ namespace MenuOption {
const QString LodTools = "LOD Tools";
const QString Log = "Log";
const QString Login = "Login";
const QString Logout = "Logout";
const QString LookAtVectors = "Look-at Vectors";
const QString MetavoxelEditor = "Metavoxel Editor...";
const QString Metavoxels = "Metavoxels";

View file

@ -63,6 +63,21 @@ AccountManager::AccountManager() :
}
}
const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash";
void AccountManager::logout() {
// a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file
_accounts.remove(_rootURL);
QSettings settings;
settings.beginGroup(ACCOUNTS_GROUP);
QString keyURLString(_rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE));
settings.remove(keyURLString);
qDebug() << "Removed account info for" << _rootURL << "from in-memory accounts and .ini file";
}
void AccountManager::setRootURL(const QUrl& rootURL) {
if (_rootURL != rootURL) {
_rootURL = rootURL;
@ -255,7 +270,8 @@ void AccountManager::requestFinished() {
// store this access token into the local settings
QSettings localSettings;
localSettings.beginGroup(ACCOUNTS_GROUP);
localSettings.setValue(rootURL.toString().replace("//", "slashslash"), QVariant::fromValue(freshAccountInfo));
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
QVariant::fromValue(freshAccountInfo));
}
} else {
// TODO: error handling

View file

@ -34,7 +34,6 @@ public:
class AccountManager : public QObject {
Q_OBJECT
public:
static AccountManager& getInstance();
void authenticatedRequest(const QString& path,
@ -55,6 +54,7 @@ public:
public slots:
void requestFinished();
void requestError(QNetworkReply::NetworkError error);
void logout();
signals:
void authenticationRequired();
void receivedAccessToken(const QUrl& rootURL);