Skip to content

Commit

Permalink
Use QSettings to set the working and home directory
Browse files Browse the repository at this point in the history
Qucs Transcalc was using a fixed path (~/.qucs) to store and
retrieve the GUI input values, ignoring the QucsHomeDir that
could have been defined by the main GUI
  • Loading branch information
in3otd committed Apr 7, 2016
1 parent 861edd5 commit 32c691a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
14 changes: 11 additions & 3 deletions qucs/qucs-transcalc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ bool loadSettings()
settings.endGroup();
if(settings.contains("font"))QucsSettings.font.fromString(settings.value("font").toString());
if(settings.contains("Language"))QucsSettings.Language=settings.value("Language").toString();
if(settings.contains("QucsHomeDir"))
if(settings.value("QucsHomeDir").toString() != "")
QucsSettings.QucsHomeDir.setPath(settings.value("QucsHomeDir").toString());

QucsSettings.QucsWorkDir = QucsSettings.QucsHomeDir;

return true;
}
Expand All @@ -79,8 +84,8 @@ bool saveApplSettings(QucsTranscalc *qucs)
settings.setValue("ResUnit", TransUnits[2].units[QucsSettings.res_unit]);
settings.setValue("AngUnit", TransUnits[3].units[QucsSettings.ang_unit]);
settings.endGroup();
return true;

return true;
}


Expand All @@ -102,6 +107,7 @@ int main(int argc, char *argv[])
QucsSettings.res_unit = 0;
QucsSettings.ang_unit = 0;
QucsSettings.freq_unit = 0;
QucsSettings.QucsHomeDir.setPath(QDir::homePath() + "/.qucs");

// is application relocated?
char * var = getenv ("QUCSDIR");
Expand All @@ -113,7 +119,6 @@ int main(int argc, char *argv[])
} else {
QucsSettings.LangDir = LANGUAGEDIR;
}
QucsSettings.QucsWorkDir.setPath (QDir::homePath()+QDir::convertSeparators ("/.qucs"));
loadSettings();

QApplication a(argc, argv);
Expand All @@ -132,7 +137,8 @@ int main(int argc, char *argv[])
qucs->move(QucsSettings.x, QucsSettings.y); // ... before "show" !!!
qucs->show();

qucs->loadFile(QDir::homePath()+"/.qucs/transrc");
// load file with all the GUI input values from the Qucs Home
qucs->loadFile(QucsSettings.QucsHomeDir.filePath("transrc"));
qucs->setMode(QucsSettings.Mode);

// optional file argument
Expand All @@ -144,6 +150,8 @@ int main(int argc, char *argv[])

int result = a.exec();
saveApplSettings(qucs);
// save file with all the GUI input values in the Qucs Home
qucs->saveModes(QucsSettings.QucsHomeDir.filePath("transrc"));
delete qucs;
return result;
}
18 changes: 16 additions & 2 deletions qucs/qucs-transcalc/qucstrans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,28 @@ void QucsTranscalc::saveMode(QTextStream& stream) {
stream << "</" << t->description << ">\n";
}

// Writes the transmission line values for all modes into the given stream.
void QucsTranscalc::saveModes(QTextStream& stream) {
// Writes the transmission line values for all modes into the given file.
bool QucsTranscalc::saveModes(QString fname) {
int oldmode = mode;

QFile file(fname);
if(!file.open(QIODevice::WriteOnly)) {
QMessageBox::warning(this, QObject::tr("Warning"),
QObject::tr("Cannot save GUI settings in\n") + fname);
return false;
}

QTextStream stream(&file);
stream << "QucsTranscalc " PACKAGE_VERSION " GUI Settings File\n";
for (int i = 0; i < MAX_TRANS_TYPES; i++) {
mode = TransLineTypes[i].type;
saveMode (stream);
}
file.close();

mode = oldmode;

return true;
}

// Saves the GUI values into internal data structures.
Expand Down
2 changes: 1 addition & 1 deletion qucs/qucs-transcalc/qucstrans.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class QucsTranscalc : public QMainWindow {
bool isSelected (QString);

void saveMode (QTextStream&);
void saveModes (QTextStream&);
bool saveModes (QString);
bool loadFile (QString, int * _mode = 0);
QString getMode (void);
void setMode (QString);
Expand Down

0 comments on commit 32c691a

Please sign in to comment.