Pass command line filenames to already running instance#1258
Conversation
27daf8f to
4f97872
Compare
|
@TheZ3ro maybe you have time to check this PR? |
|
@frostasm yes of course :) |
4f97872 to
7506df3
Compare
|
@TheZ3ro @droidmonkey please check my changes :) |
7506df3 to
8b5a810
Compare
|
I did not found how to use QTest to test drag&drop. I will be grateful for the advice. |
src/gui/Application.cpp
Outdated
| if (config()->get("SingleInstance").toBool()) { | ||
| // Attempt to connect to the existing instance | ||
| QLocalSocket client; | ||
| for (int i = 0; i < 3; i++) { |
src/gui/MainWindow.cpp
Outdated
| if (!kdbxFiles.isEmpty()) { | ||
| event->acceptProposedAction(); | ||
| } | ||
| for(const QString &kdbxFile: kdbxFiles) { |
There was a problem hiding this comment.
kdbxFiles inside kdbxFilesFromUrls() has gone out of scope here, so reference count should be 1 again, but use asConst() around kdbxFiles nevertheless. Also add a space after for and move the & sign to the type name.
There was a problem hiding this comment.
@phoerious It would be nice if someone of the core developers have added information about how to use range-based for loop with Qt containers to the CONTRIBUTING.md
Good article about Qt containers and C++11 range-based loops
Also add a space after for and move the & sign to the type name.
done
There was a problem hiding this comment.
Perhaps we should do that. You need to some understanding of how reference counters and detaching work in Qt. It's not KeePassXC stuff though. It's general Qt knowledge.
There was a problem hiding this comment.
Of course these knowledge relates to Qt. But I'm sure that not everyone who sends patches understands how Qt lists and range-based for loops works :(
There was a problem hiding this comment.
That's what code reviews are for. :-)
src/main.cpp
Outdated
| for (int ii = filenames.size()-1; ii >= 0; ii--) { | ||
| QString filename = filenames.at(ii); | ||
| const QStringList fileNames = config()->get("LastOpenedDatabases").toStringList(); | ||
| for (const QString &filename: fileNames) { |
There was a problem hiding this comment.
Use asConst() and move & to the type name.
There was a problem hiding this comment.
asConst() function not needed with constant containers.
Qt A Porting Guide to C++11 Ranged For-Loops - Avoiding Detaching
There was a problem hiding this comment.
Ummm... I was pretty sure it was non-const when I wrote that comment, but I must have overlooked it.
src/main.cpp
Outdated
| for (int ii=0; ii < args.length(); ii++) { | ||
| QString filename = args[ii]; | ||
| const bool pwstdin = parser.isSet(pwstdinOption); | ||
| for (const QString &filename: fileNames) { |
src/gui/Application.cpp
Outdated
| client->waitForBytesWritten(WaitTimeoutMSec); | ||
| client->disconnectFromServer(); | ||
| } else { | ||
| client->deleteLater(); |
There was a problem hiding this comment.
You should move this to the top and add a return false after this statement.
There was a problem hiding this comment.
I did not understand what I should do :(
There was a problem hiding this comment.
Just move deleteLater() to the top, so you return early. Having a larger if block and then a simple else condition at the end of the function is quite error-prone and I consider it bad style. Better do whatever is in the else block right away and return and then you do what used to be in the if block.
There was a problem hiding this comment.
I rewrote function
450e61c to
411769c
Compare
|
I am also thinking about adding a unit test to pass file names between running instances. But I don't know how to check the correctness, because the current implementation is based on QApplication class (which is a singleton). Perhaps it makes sense to move the implementation of the checking "SingleInstance" and communication between processes in a separate class? |
411769c to
b3f03ed
Compare
|
It's hard to do, also because it's quite platform-dependent and raises the question if a whole application can still be seen as a unit. Usually, you want your unit tests to be fine-granular and atomic. If you come up with some good ideas, feel free to implement them. If not, I think this is good enough to be merged. |
|
@frostasm can you please rebase this? Thanks |
|
of course :) |
b3f03ed to
3720c5e
Compare
|
@TheZ3ro done |
|
Thanks! |
|
Unfortunately this reverted my change from #774 and causes recently opened databases to reopen in reversed order on next program startup. Is that necessary to achieve the purpose of this PR or an was it an oversight? |
|
@michaellass I was wondering why that was a problem again! Definitely an oversight. |
Description
Motivation and context
To simplify the opening of files when one copy of the program is running (if was enabled the option "Start only a single instance of KeePassXC")
How has this been tested?
Manually on Linux OS
Screenshots (if appropriate):
Types of changes
Checklist:
-DWITH_ASAN=ON. [REQUIRED]