Skip to content

Conversation

@lucydodo
Copy link
Member

@lucydodo lucydodo commented Sep 4, 2020

This patch changes to support custom configuration file. This PR is related to issue #2317

Two options are added for the command line:

  • -c [config_file]
  • --config [config_file]

We can also use environment variables without using options on the command line.
export DB4S_CONFIG_FILE=[config_file]

If there is an environment variable and use the -c or --config option, the environment variable is ignored.

Usage

$ ./DB\ Browser\ for\ SQLite -c db4sconfig
$ ./DB\ Browser\ for\ SQLite --config db4sconfig
$ export DB4S_CONFIG_FILE=db4sconfig
$ ./DB\ Browser\ for\ SQLite

Possible problem

The database file may be overwritten if the user enters only the value of the database file to be open without specifying a configuration file parameter when using this option. -> $ ./DB\ Browser\ for\ SQLite --config veryImportantDB.db
Solved through this commit(60ddbdd).

Known Bugs

If you specify an environment variable on macOS and run it with the following command, the config file is not saved anywhere.
open ./DB\ Browser\ for\ SQLite.app/
However, if you specify as follows, it is saved normally.
./DB\ Browser\ for\ SQLite.app/Contents/MacOS/DB\ Browser\ for\ SQLite

Test Environment

  • macOS Catalina (10.15.6, 19G2021)

@lucydodo lucydodo added the enhancement Feature requests. label Sep 4, 2020
@lucydodo lucydodo requested a review from mgrojo September 4, 2020 16:47
@lucydodo lucydodo self-assigned this Sep 4, 2020
@lucydodo
Copy link
Member Author

lucydodo commented Sep 4, 2020

@mgrojo I have permission to merge, but I haven't finished studying and analyzing the project source tree yet.
May I ask for a review to you due to I am worried that it will cause unexpected problems to project via my code. 👀

Copy link
Member

@mgrojo mgrojo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good start! Thanks for letting me review it.

Implement setter(setUserConfigurationFile) to store user configuration file.
Move the code that print error when the argument for the option is not provided.
Print detailed information when the value of an environment variable is substituted.
Replaced with 'nullptr' instead of 'NULL' according to Modern C++ standard.
Add code to check if provided file is a normal configuration file.
Change the QSetting class object to be created only once(setSettingsObject).
Using the '->' operator.

Thank you so much for reviewing! @mgrojo
@lucydodo
Copy link
Member Author

lucydodo commented Sep 5, 2020

@mgrojo Thanks for the review! 😄 I modified the code according to your review.
In addition, the following modifications were made too:

  • Ignore the option if user does NOT have permission to the configuration file.
  • Fixed that the code for 'clearValue()' and 'restoreDefaults()' was not modified, so it did not work for user configuration file.

I added a comment, but it seems that the code is like 'spaghetti code'. I'll try think about neat code continue. 👀

Copy link
Member

@mgrojo mgrojo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a user point of view would be ready for merging, but I've made some comments regarding the code which you might want to consider.

SeongTae Jeong added 2 commits September 6, 2020 20:54
Make QSettings* object(settings) as a static member variable.
Compress error message when no arguments.
Change the behavior of the 'setSettingsObject()` method to be similar to the existing interface.
Simplify the normal file check code.
@lucydodo
Copy link
Member Author

lucydodo commented Sep 6, 2020

@mgrojo Thanks for the second review! 😄 I modified the code according to your review.
and thank you for always catching something I never thought of. thanks to that, I feel myself growing with our project. 😄

However, calling setSettingsObject() every time in method seems to slow down the program operation.

Change to abort 'setSettingsObject()' if QSettings object has already been created
@mgrojo mgrojo merged commit 0644bc0 into sqlitebrowser:master Sep 6, 2020
@mgrojo
Copy link
Member

mgrojo commented Sep 6, 2020

Thanks, @lucydodo. It's now merged!

After merging, I've seen something that I think could be improved. If the file doesn't exist, it should be allowed and passed to QSettings so an initial file can be populated. Another option could be having an Export Settings option from the GUI, but although we had that, I think it is better to allow to create a new file from the argument. Application will run with default values and the file will be initialized with whatever setting the user changes, and they will be able to reuse it in the future. What do you think?

@lucydodo
Copy link
Member Author

lucydodo commented Sep 6, 2020

@mgrojo Sorry I didn't understand what you say because my English is not very well.
You mean that the user give the uncreated file as an argument?

@mgrojo
Copy link
Member

mgrojo commented Sep 6, 2020

Sorry, I was executing another branch 😄 It works as expected, forget my comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants