Skip to content

Commit

Permalink
Update to allow custom base dir
Browse files Browse the repository at this point in the history
  • Loading branch information
miyamot0 committed Oct 2, 2020
1 parent 789d5d8 commit a9b4593
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 57 deletions.
4 changes: 2 additions & 2 deletions DataTracker.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
TEST_FEATURES = 1

VERSION_MAJOR = 0
VERSION_MINOR = 7
VERSION_BUILD = 3
VERSION_MINOR = 8
VERSION_BUILD = 0

DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR"\
"VERSION_MINOR=$$VERSION_MINOR"\
Expand Down
1 change: 0 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ int main(int argc, char *argv[])
qRegisterMetaType<ParseTypes::ParseAction>("ParseTypes::ParseAction");

QSettings settings;

settings.beginGroup(QLatin1String("DTProgramSettings"));
bool displayDark = settings.value(QLatin1String("displayDark"), false).toBool();
settings.endGroup();
Expand Down
2 changes: 1 addition & 1 deletion recordingwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RecordingWindow::RecordingWindow(QWidget *parent) : QDialog(parent), ui(new Ui::
installEventFilter(this);
setWindowTitle(tr("Session Recording Window"));

Qt::WindowFlags windowFlags = 0;
Qt::WindowFlags windowFlags = nullptr;
windowFlags |= Qt::WindowMaximizeButtonHint;
windowFlags |= Qt::WindowMinimizeButtonHint;
windowFlags |= Qt::WindowCloseButtonHint;
Expand Down
2 changes: 1 addition & 1 deletion sessionwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SessionWindow : public QDialog
Q_OBJECT

public:
explicit SessionWindow(QString mCurrentWorkingDirectory, QWidget *parent = 0);
explicit SessionWindow(QString mCurrentWorkingDirectory, QWidget *parent = nullptr);
~SessionWindow();

private slots:
Expand Down
8 changes: 7 additions & 1 deletion sessionwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonSync">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -1409,8 +1412,11 @@
</item>
<item>
<widget class="QLabel" name="labelStatus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
<string>Sync functionality disabled.</string>
</property>
</widget>
</item>
Expand Down
73 changes: 72 additions & 1 deletion settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
WindowTools::SetDialogFixedDisplay(this);
}

/**
* @brief SettingsDialog::SetPrimarySaveLocation
* @param location
*/
void SettingsDialog::SetPrimarySaveLocation(QString location)
{
primarySaveLocation = location;
ui->editPrimarySaveLocation->setText(location);
}

/**
* @brief SettingsDialog::SetSaveLocation
* @param location
Expand Down Expand Up @@ -120,6 +130,15 @@ void SettingsDialog::SetAutoUpdateCheck(bool value)
ui->checkBoxAutoUpdate->setChecked(value);
}

/**
* @brief SettingsDialog::GetPrimarySaveLocation
* @return
*/
QString SettingsDialog::GetPrimarySaveLocation()
{
return ui->editPrimarySaveLocation->text();
}

/**
* @brief SettingsDialog::GetSaveLocation
* @return
Expand Down Expand Up @@ -193,6 +212,7 @@ SettingsDialog::~SettingsDialog()
*/
void SettingsDialog::on_pushButton_clicked()
{
primarySaveLocation = GetPrimarySaveLocation();
alternateSaveLocation = GetSaveLocation();
spreadsheetOutput = GetSpreadsheetOption();
displayPlots = GetDisplayOption();
Expand All @@ -201,8 +221,13 @@ void SettingsDialog::on_pushButton_clicked()
autoMigrate = GetAutoMigrate();
autoUpdate = GetAutoUpdate();

QDir mDir(alternateSaveLocation);
QDir mDir(primarySaveLocation);
if (mDir.exists())
{
FileTools::CheckAndPrepDirectory("DataTracker3", mDir.absolutePath());
}

mDir = QDir(alternateSaveLocation);
if (mDir.exists())
{
FileTools::CheckAndPrepDirectory("DataTracker3", mDir.absolutePath());
Expand Down Expand Up @@ -256,3 +281,49 @@ void SettingsDialog::on_setSaveLocation_clicked()
ui->editSaveLocation->setText(mLocation);
}
}

void SettingsDialog::on_setPrimarySaveLocation_clicked()
{
QString mLocation;

if (ui->editPrimarySaveLocation->text().length() == 0)
{
#ifdef _WIN32
mLocation = QFileDialog::getExistingDirectory (this,
tr("Pick Primary Save Location"),
QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0],
QFileDialog::ShowDirsOnly);
#elif TARGET_OS_MAC
mLocation = QFileDialog::getExistingDirectory (this,
tr("Pick Primary Save Location"),
QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0],
QFileDialog::ShowDirsOnly | QFileDialog::DontUseNativeDialog);
#endif
}
else
{
#ifdef _WIN32
mLocation = QFileDialog::getExistingDirectory (this,
tr("Pick Primary Save Location"),
ui->editPrimarySaveLocation->text(),
QFileDialog::ShowDirsOnly);
#elif TARGET_OS_MAC
mLocation = QFileDialog::getExistingDirectory (this,
tr("Pick Primary Save Location"),
ui->editPrimarySaveLocation->text(),
QFileDialog::ShowDirsOnly | QFileDialog::DontUseNativeDialog);
#endif
}

// Remove the trailing location, if added
if (mLocation.contains("DataTracker3", Qt::CaseInsensitive))
{
mLocation = mLocation.replace("DataTracker3", "");
}

QDir mPotentialDir(mLocation);
if (mLocation.length() !=0 && mPotentialDir.exists())
{
ui->editPrimarySaveLocation->setText(mLocation);
}
}
6 changes: 5 additions & 1 deletion settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class SettingsDialog : public QDialog
Q_OBJECT

public:
explicit SettingsDialog(QWidget *parent = 0);
explicit SettingsDialog(QWidget *parent = nullptr);

QString primarySaveLocation;
QString alternateSaveLocation;
bool spreadsheetOutput = true;
bool displayPlots = false;
Expand All @@ -45,6 +46,7 @@ class SettingsDialog : public QDialog
bool autoMigrate = false;
bool autoUpdate = true;

void SetPrimarySaveLocation(QString location);
void SetSaveLocation(QString location);
void SetSpreadsheetOption(bool value);
void SetDisplayOption(bool value);
Expand All @@ -53,6 +55,7 @@ class SettingsDialog : public QDialog
void SetAutoMigrate(bool value);
void SetAutoUpdateCheck(bool value);

QString GetPrimarySaveLocation();
QString GetSaveLocation();
bool GetSpreadsheetOption();
bool GetDisplayOption();
Expand All @@ -66,6 +69,7 @@ class SettingsDialog : public QDialog
private slots:
void on_pushButton_clicked();
void on_setSaveLocation_clicked();
void on_setPrimarySaveLocation_clicked();

private:
Ui::SettingsDialog *ui;
Expand Down
Loading

0 comments on commit a9b4593

Please sign in to comment.