diff --git a/src/ConfigDialog.cpp b/src/ConfigDialog.cpp index bdacfe658..f6c825a9b 100644 --- a/src/ConfigDialog.cpp +++ b/src/ConfigDialog.cpp @@ -28,7 +28,7 @@ #include "Zones.h" #include "AddDeviceWizard.h" - +#include "MainWindow.h" ConfigDialog::ConfigDialog(QDir _home, Zones *_zones, Context *context) : home(_home), zones(_zones), context(context) @@ -147,7 +147,7 @@ ConfigDialog::ConfigDialog(QDir _home, Zones *_zones, Context *context) : setWindowTitle(tr("Options")); #endif - connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); + connect(closeButton, SIGNAL(clicked()), this, SLOT(closeClicked())); connect(saveButton, SIGNAL(clicked()), this, SLOT(saveClicked())); } @@ -156,6 +156,11 @@ void ConfigDialog::changePage(int index) pagesWidget->setCurrentIndex(index); } +void ConfigDialog::closeClicked() +{ + // don't save! + close(); +} // if save is clicked, we want to: // new mode: create a new zone starting at the selected date (which may be null, implying BEGIN // ! new mode: change the CP associated with the present mode @@ -171,6 +176,37 @@ void ConfigDialog::saveClicked() hide(); + // did the home directory change? + QString shome = appsettings->value(this, GC_HOMEDIR).toString(); + if (shome != "0" && shome != "" && QFileInfo(shome).absoluteFilePath() != QFileInfo(home.absolutePath()).absolutePath()) { + + // are you sure you want to change the location of the athlete library? + // if so we will restart, if not I'll revert to current directory + QMessageBox msgBox; + msgBox.setText("You changed the location of the athlete library"); + msgBox.setInformativeText("You have moved the location of the athlete library " + "This is where ALL new athletes and their activity files " + "will now be stored.\n\nCurrent athlete data will no longer be " + "available and you will need to relaunch GoldenCheetah.\n\nDo you want to apply and close GoldenCheetah?"); + + // we want our own buttons... + msgBox.addButton(tr("No, Keep current"), QMessageBox::RejectRole); + msgBox.addButton(tr("Yes, Apply and Close"), QMessageBox::AcceptRole); + msgBox.setDefaultButton(QMessageBox::Abort); + + if (msgBox.exec() == 1) { // accept! + + // close all the mainwindows + foreach(MainWindow *m, mainwindows) m->byebye(); + + } else { + + // revert to current home + appsettings->setValue(GC_HOMEDIR, QFileInfo(home.absolutePath()).absolutePath()); + + } + } + // do the zones first.. context->notifyConfigChanged(); close(); diff --git a/src/ConfigDialog.h b/src/ConfigDialog.h index 5bc3dfb17..2d8eddfcf 100644 --- a/src/ConfigDialog.h +++ b/src/ConfigDialog.h @@ -179,6 +179,7 @@ class ConfigDialog : public QMainWindow public slots: void changePage(int); void saveClicked(); + void closeClicked(); private: QSettings *settings; diff --git a/src/MainWindow.h b/src/MainWindow.h index b7b87c303..6361dc3e9 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -60,6 +60,7 @@ class MainWindow : public QMainWindow // temporary access to the context Context *contextmain() { return context; } // by ChooseCyclistDialog + void byebye() { close(); } // go bye bye for a restart protected: diff --git a/src/Pages.cpp b/src/Pages.cpp index eb2ce5fcb..395708cf4 100644 --- a/src/Pages.cpp +++ b/src/Pages.cpp @@ -198,6 +198,22 @@ GeneralPage::GeneralPage(Context *context) : context(context) configLayout->addWidget(perfManLTSavg, 10,1, Qt::AlignLeft); configLayout->addWidget(showSBToday, 11,1, Qt::AlignLeft); + // + // Athlete directory (home of athletes) + // + QVariant athleteDir = appsettings->value(this, GC_HOMEDIR); + athleteLabel = new QLabel(tr("Athlete Library:")); + athleteDirectory = new QLineEdit; + athleteDirectory->setText(athleteDir.toString() == "0" ? "" : athleteDir.toString()); + athleteBrowseButton = new QPushButton(tr("Browse")); + athleteBrowseButton->setFixedWidth(70); + + configLayout->addWidget(athleteLabel, 12,0, Qt::AlignRight); + configLayout->addWidget(athleteDirectory, 12,1); + configLayout->addWidget(athleteBrowseButton, 12,2); + + connect(athleteBrowseButton, SIGNAL(clicked()), this, SLOT(browseAthleteDir())); + // // Workout directory (train view) // @@ -208,9 +224,9 @@ GeneralPage::GeneralPage(Context *context) : context(context) workoutBrowseButton = new QPushButton(tr("Browse")); workoutBrowseButton->setFixedWidth(70); - configLayout->addWidget(workoutLabel, 12,0, Qt::AlignRight); - configLayout->addWidget(workoutDirectory, 12,1); - configLayout->addWidget(workoutBrowseButton, 13,1); + configLayout->addWidget(workoutLabel, 14,0, Qt::AlignRight); + configLayout->addWidget(workoutDirectory, 14,1); + configLayout->addWidget(workoutBrowseButton, 14,2); connect(workoutBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkoutDir())); @@ -239,6 +255,7 @@ GeneralPage::saveClicked() // Bike score estimation appsettings->setValue(GC_WORKOUTDIR, workoutDirectory->text()); + appsettings->setValue(GC_HOMEDIR, athleteDirectory->text()); appsettings->setValue(GC_ELEVATION_HYSTERESIS, hystedit->text()); // Performance Manager @@ -263,6 +280,14 @@ GeneralPage::browseWorkoutDir() workoutDirectory->setText(dir); } +void +GeneralPage::browseAthleteDir() +{ + QString dir = QFileDialog::getExistingDirectory(this, tr("Select Athlete Library"), + "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + athleteDirectory->setText(dir); +} + // // Passwords page // diff --git a/src/Pages.h b/src/Pages.h index bad756590..383865d23 100644 --- a/src/Pages.h +++ b/src/Pages.h @@ -61,6 +61,7 @@ class GeneralPage : public QWidget public slots: void browseWorkoutDir(); + void browseAthleteDir(); private: Context *context; @@ -72,13 +73,16 @@ class GeneralPage : public QWidget QCheckBox *garminSmartRecord; QLineEdit *garminHWMarkedit; QLineEdit *hystedit; + QLineEdit *athleteDirectory; QLineEdit *workoutDirectory; QPushButton *workoutBrowseButton; + QPushButton *athleteBrowseButton; QLabel *langLabel; QLabel *unitLabel; QLabel *warningLabel; QLabel *workoutLabel; + QLabel *athleteLabel; QLabel *perfManSTSLabel; QLabel *perfManLTSLabel; diff --git a/src/Settings.h b/src/Settings.h index 7d8feb979..5eb3048e1 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -21,6 +21,7 @@ #include "GoldenCheetah.h" #include +#define GC_HOMEDIR "homedirectory" #define GC_VERSION_USED "versionused" #define GC_SAFEEXIT "safeexit" #define GC_SETTINGS_CO "goldencheetah.org" diff --git a/src/main.cpp b/src/main.cpp index 1bf13d606..7ff0ce528 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,6 +77,9 @@ main(int argc, char *argv[]) QString libraryPath=".goldencheetah"; #endif + QString sh; + if ((sh=appsettings->value(NULL, GC_HOMEDIR).toString()) != "") localLibraryPath = sh; + //First check to see if the Library folder exists where the executable is (for USB sticks) QDir home = QDir(); //if it does, create an ini file for settings and cd into the library