Undo avatar choice if the whole preferences dialog is cancelled.

This commit is contained in:
Howard Stearns 2015-08-13 15:55:43 -07:00
parent 722c024f61
commit 63608d8012
2 changed files with 24 additions and 3 deletions

View file

@ -68,12 +68,24 @@ void PreferencesDialog::fullAvatarURLChanged(const QString& newValue, const QStr
} }
void PreferencesDialog::accept() { void PreferencesDialog::accept() {
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
_lastGoodAvatarURL = myAvatar->getFullAvatarURLFromPreferences();
_lastGoodAvatarName = myAvatar->getFullAvatarModelName();
savePreferences(); savePreferences();
close(); close();
delete _marketplaceWindow; delete _marketplaceWindow;
_marketplaceWindow = NULL; _marketplaceWindow = NULL;
} }
void PreferencesDialog::restoreLastGoodAvatar() {
fullAvatarURLChanged(_lastGoodAvatarURL.toString(), _lastGoodAvatarName);
}
void PreferencesDialog::reject() {
restoreLastGoodAvatar();
QDialog::reject();
}
void PreferencesDialog::openSnapshotLocationBrowser() { void PreferencesDialog::openSnapshotLocationBrowser() {
QString dir = QFileDialog::getExistingDirectory(this, tr("Snapshots Location"), QString dir = QFileDialog::getExistingDirectory(this, tr("Snapshots Location"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
@ -127,8 +139,9 @@ void PreferencesDialog::loadPreferences() {
ui.collisionSoundURLEdit->setText(myAvatar->getCollisionSoundURL()); ui.collisionSoundURLEdit->setText(myAvatar->getCollisionSoundURL());
fullAvatarURLChanged(myAvatar->getFullAvatarURLFromPreferences().toString(), _lastGoodAvatarURL = myAvatar->getFullAvatarURLFromPreferences();
myAvatar->getFullAvatarModelName()); _lastGoodAvatarName = myAvatar->getFullAvatarModelName();
fullAvatarURLChanged(_lastGoodAvatarURL.toString(), _lastGoodAvatarName);
ui.sendDataCheckBox->setChecked(!menuInstance->isOptionChecked(MenuOption::DisableActivityLogger)); ui.sendDataCheckBox->setChecked(!menuInstance->isOptionChecked(MenuOption::DisableActivityLogger));
@ -211,7 +224,11 @@ void PreferencesDialog::savePreferences() {
} }
myAvatar->setCollisionSoundURL(ui.collisionSoundURLEdit->text()); myAvatar->setCollisionSoundURL(ui.collisionSoundURLEdit->text());
// avatar model url is already persisted by fullAvatarURLChanged()
// MyAvatar persists its own data. If it doesn't agree with what the user has explicitly accepted, set it back to old values.
if (_lastGoodAvatarURL != myAvatar->getFullAvatarURLFromPreferences()) {
restoreLastGoodAvatar();
}
if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableActivityLogger) if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableActivityLogger)
!= ui.sendDataCheckBox->isChecked()) { != ui.sendDataCheckBox->isChecked()) {

View file

@ -33,6 +33,9 @@ protected:
private: private:
void loadPreferences(); void loadPreferences();
void savePreferences(); void savePreferences();
QUrl _lastGoodAvatarURL;
QString _lastGoodAvatarName;
void restoreLastGoodAvatar();
Ui_PreferencesDialog ui; Ui_PreferencesDialog ui;
@ -42,6 +45,7 @@ private:
private slots: private slots:
void accept(); void accept();
void reject();
void openFullAvatarModelBrowser(); void openFullAvatarModelBrowser();
void openSnapshotLocationBrowser(); void openSnapshotLocationBrowser();
void openScriptsLocationBrowser(); void openScriptsLocationBrowser();