diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 7c684a0c..e8a79230 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -2361,6 +2361,7 @@ void MainWindow::on_actionImport_Viatom_Data_triggered() void MainWindow::GenerateStatistics() { reset_reportModeUi() ; + if (!p_profile) return; Statistics stats; QString htmlStats = stats.GenerateHTML(); diff --git a/oscar/newprofile.cpp b/oscar/newprofile.cpp index c86a0ad3..dd031397 100644 --- a/oscar/newprofile.cpp +++ b/oscar/newprofile.cpp @@ -33,9 +33,11 @@ NewProfile::NewProfile(QWidget *parent, const QString *user) : ui(new Ui::NewProfile) { ui->setupUi(this); - if (user) + if (user) { + originalProfileName=*user; ui->userNameEdit->setText(*user); // ui->userNameEdit->setText(getUserName()); + } QLocale locale = QLocale::system(); QString shortformat = locale.dateFormat(QLocale::ShortFormat); @@ -206,14 +208,23 @@ void NewProfile::on_nextButton_clicked() ui->stackedWidget->setCurrentIndex(index); } else { // Finish button clicked. - QString username = ui->userNameEdit->text().trimmed(); + newProfileName = ui->userNameEdit->text().trimmed(); + QString profileName; + if (originalProfileName.isEmpty() ) { + profileName = newProfileName; + } else { + profileName = originalProfileName; + ui->userNameEdit->setText(originalProfileName); + //QString profileName = originalProfileName.isEmpty()? newProfileName : originalProfileName; + } + //QString profileName = originalProfileName.isEmpty()? newProfileName : originalProfileName; if (QMessageBox::question(this, tr("Profile Changes"), tr("Accept and save this information?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { - Profile *profile = Profiles::Get(username); + Profile *profile = Profiles::Get(profileName); if (!profile) { // No profile, create one. - profile = Profiles::Create(username); + profile = Profiles::Create(profileName); } Profile &prof = *profile; @@ -264,15 +275,31 @@ void NewProfile::on_nextButton_clicked() // also call unitsChanged if height also changed. Need for update BMI. if (mainwin && mainwin->getDaily()) { mainwin->getDaily()->UnitsChanged(); } } - - AppSetting->setProfileName(username); + AppSetting->setProfileName(profileName); profile->Save(); - - if (mainwin) - mainwin->GenerateStatistics(); - - this->accept(); + if ( !originalProfileName.isEmpty() && !newProfileName.isEmpty() && (originalProfileName != newProfileName)) { + QString originalProfileFullName = p_pref->Get("{home}/Profiles/") + originalProfileName; + QString newProfileFullName = p_pref->Get("{home}/Profiles/") + newProfileName; + QFile file(originalProfileFullName); + if (file.exists()) { + bool status = file.rename(newProfileFullName); + if (status) { // successful rename + QCoreApplication::processEvents(); + mainwin->RestartApplication(true,"-l"); + exit(0); + } else { + QMessageBox::question(this, tr("Invalid User Name"), tr("Please Update User without special characters"), QMessageBox::Ok); + ui->stackedWidget->setCurrentIndex(1); + ui->userNameEdit->setText(newProfileName); + } + } + } else { + if (mainwin) { + mainwin->GenerateStatistics(); + } + this->accept(); + } } } @@ -336,7 +363,7 @@ void NewProfile::edit(const QString name) } ui->userNameEdit->setText(name); - ui->userNameEdit->setReadOnly(true); + // ui->userNameEdit->setReadOnly(true); ui->firstNameEdit->setText(profile->user->firstName()); ui->lastNameEdit->setText(profile->user->lastName()); diff --git a/oscar/newprofile.h b/oscar/newprofile.h index 6235d56a..186e991f 100644 --- a/oscar/newprofile.h +++ b/oscar/newprofile.h @@ -65,6 +65,8 @@ class NewProfile : public QDialog double m_tmp_height_cm; int m_firstPage; bool m_passwordHashed; + QString originalProfileName; + QString newProfileName; }; #endif // NEWPROFILE_H diff --git a/oscar/profileselector.cpp b/oscar/profileselector.cpp index 90fba81e..f7e3ea42 100644 --- a/oscar/profileselector.cpp +++ b/oscar/profileselector.cpp @@ -7,6 +7,9 @@ * License. See the file COPYING in the main directory of the source code * for more details. */ +#define TEST_MACROS_ENABLEDoff +#include + #include #include "profileselector.h" @@ -60,7 +63,7 @@ ProfileSelector::ProfileSelector(QWidget *parent) : ui->diskSpaceInfo->setVisible(false); QItemSelectionModel * sm = ui->profileView->selectionModel(); - if (sm) + if (sm) connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_selectionChanged(QModelIndex,QModelIndex))); ui->buttonEditProfile->setEnabled(false); ui->buttonOpenProfile->setEnabled(false); @@ -302,7 +305,7 @@ void ProfileSelector::on_buttonEditProfile_clicked() Profile * prof = Profiles::profiles[name]; //SelectProfile(name); // may not be necessary... - NewProfile *newprof = new NewProfile(this); + NewProfile *newprof = new NewProfile(this,&name); newprof->edit(name); newprof->setWindowModality(Qt::ApplicationModal); newprof->setModal(true);