make handling of plugin path and recent files more consistent
This commit is contained in:
@ -69,7 +69,7 @@
|
||||
static const QString blank(" ");
|
||||
static constexpr int BUFLEN = 256;
|
||||
|
||||
LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
LammpsGui::LammpsGui(QWidget *parent, const QString &filename) :
|
||||
QMainWindow(parent), ui(new Ui::LammpsGui), highlighter(nullptr), capturer(nullptr),
|
||||
status(nullptr), logwindow(nullptr), imagewindow(nullptr), chartwindow(nullptr),
|
||||
slideshow(nullptr), logupdater(nullptr), dirstatus(nullptr), progress(nullptr),
|
||||
@ -98,21 +98,21 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
|
||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||
plugin_path.clear();
|
||||
std::string deffile = settings.value("plugin_path", "liblammps.so").toString().toStdString();
|
||||
for (const char *libfile : {deffile.c_str(), "./liblammps.so", "liblammps.dylib",
|
||||
QString deffile = settings.value("plugin_path", "liblammps.so").toString();
|
||||
for (const char *libfile : {deffile.toStdString().c_str(), "./liblammps.so", "liblammps.dylib",
|
||||
"./liblammps.dylib", "liblammps.dll"}) {
|
||||
if (lammps.load_lib(libfile)) {
|
||||
auto canonical = QFileInfo(libfile).canonicalFilePath();
|
||||
plugin_path = canonical.toStdString();
|
||||
settings.setValue("plugin_path", canonical);
|
||||
plugin_path = QFileInfo(libfile).canonicalFilePath();
|
||||
settings.setValue("plugin_path", plugin_path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin_path.empty()) {
|
||||
if (plugin_path.isEmpty()) {
|
||||
// none of the plugin paths could load, remove key
|
||||
settings.remove("plugin_path");
|
||||
QMessageBox::critical(this, "Error", "Cannot open LAMMPS shared library file");
|
||||
QMessageBox::critical(this, "Error", "Cannot open LAMMPS shared library file.\n"
|
||||
"Use -p command line flag to specify a path to the library.");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
@ -281,7 +281,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
dirstatus->show();
|
||||
ui->statusbar->addWidget(progress);
|
||||
|
||||
if (filename) {
|
||||
if (filename.size() > 0) {
|
||||
open_file(filename);
|
||||
} else {
|
||||
setWindowTitle("LAMMPS-GUI - Editor - *unknown*");
|
||||
@ -505,6 +505,7 @@ void LammpsGui::start_exe()
|
||||
void LammpsGui::update_recents(const QString &filename)
|
||||
{
|
||||
QSettings settings;
|
||||
if (settings.contains("recent"))
|
||||
recent = settings.value("recent").value<QList<QString>>();
|
||||
|
||||
for (int i = 0; i < recent.size(); ++i) {
|
||||
@ -517,7 +518,8 @@ void LammpsGui::update_recents(const QString &filename)
|
||||
|
||||
if (!filename.isEmpty() && !recent.contains(filename)) recent.prepend(filename);
|
||||
if (recent.size() > 5) recent.removeLast();
|
||||
settings.setValue("recent", QVariant::fromValue(recent));
|
||||
if (recent.size() > 0) settings.setValue("recent", QVariant::fromValue(recent));
|
||||
else settings.remove("recent");
|
||||
|
||||
ui->action_1->setVisible(false);
|
||||
if ((recent.size() > 0) && !recent[0].isEmpty()) {
|
||||
@ -1438,9 +1440,9 @@ void LammpsGui::about()
|
||||
version += " using dark theme\n";
|
||||
if (lammps.has_plugin()) {
|
||||
version += "LAMMPS library loaded as plugin";
|
||||
if (!plugin_path.empty()) {
|
||||
if (!plugin_path.isEmpty()) {
|
||||
version += " from file ";
|
||||
version += plugin_path;
|
||||
version += plugin_path.toStdString();
|
||||
}
|
||||
} else {
|
||||
version += "LAMMPS library linked to executable";
|
||||
|
||||
@ -68,7 +68,7 @@ class LammpsGui : public QMainWindow {
|
||||
friend class Tutorial2Wizard;
|
||||
|
||||
public:
|
||||
LammpsGui(QWidget *parent = nullptr, const char *filename = nullptr);
|
||||
LammpsGui(QWidget *parent = nullptr, const QString &filename = QString());
|
||||
~LammpsGui() override;
|
||||
|
||||
protected:
|
||||
@ -172,7 +172,7 @@ private:
|
||||
LammpsWrapper lammps;
|
||||
LammpsRunner *runner;
|
||||
QString docver;
|
||||
std::string plugin_path;
|
||||
QString plugin_path;
|
||||
bool is_running;
|
||||
int run_counter;
|
||||
std::vector<char *> lammps_args;
|
||||
|
||||
@ -53,19 +53,22 @@ int main(int argc, char *argv[])
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("file", "The LAMMPS input file to open (optional).");
|
||||
parser.process(app); // this removes known arguments
|
||||
parser.process(app);
|
||||
|
||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||
if (parser.isSet(plugindir)) {
|
||||
QString pluginpath = parser.value(plugindir);
|
||||
QStringList pluginpath = parser.values(plugindir);
|
||||
if (pluginpath.length() > 0) {
|
||||
QSettings settings;
|
||||
settings.setValue("plugin_path", pluginpath);
|
||||
settings.setValue("plugin_path", QString(pluginpath.at(0)));
|
||||
settings.sync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *infile = nullptr;
|
||||
if (argc > 1) infile = argv[1];
|
||||
QString infile;
|
||||
QStringList args = parser.positionalArguments();
|
||||
if (args.size() > 0) infile = args[0];
|
||||
LammpsGui w(nullptr, infile);
|
||||
w.show();
|
||||
return app.exec();
|
||||
|
||||
Reference in New Issue
Block a user