shermp / NickelDBus

Monitor and control kobo Nickel via dbus
MIT License
27 stars 2 forks source link

Add ndbCurrentView method & ndbViewChanged signal #6

Closed shermp closed 4 years ago

shermp commented 4 years ago

This PR adds a method to find out what the currently shown view is (eg: HomePageView, ReadingView). It also adds a signal that is emitted every time the current view changes.

I search the result of QApplication::allWidgets() for a QStackedWidget which contains the HomePageView widget. I only search once, then cache the QStackedWidget pointer for subsequent calls. This method works as far back as firmware version 4.6.x.

According to @pgaskin this QStackedWidget is managed by the MainWindowController singleton. I can't figure out a way of getting it from the MWC, especially on older firmware versions. Unless anyone has any further ideas, I'll stick with the QApplication method.

shermp commented 4 years ago

Works well, but it would be useful to see if the N3Dialogs can be named more specifically.

That would be nice. I'll see if Kobo have set windowTitle.

EDIT: Nope, at least not in 4.6. It has been set for the home page, and "My Books", but not for the dialogs 😞

shermp commented 4 years ago

I finally figured out how to get the title of an N3Settings dialog. Tried N3Settings::getTitle() and N3Settings::getTitleLarge(), but couldn't figure out the proper return type. Tried char*, QString, QString*, QByteArray. Nothing seemed to work.

Digged further into the code, and found they returned a SmallLabel* and HeaderMediumLabel* respectively, both of which seem to be derived from QLabel.

And sure enough, calling QLabel::text() for the N3Settings::getTitleLarge() return value gives a useful title 😁

@pgaskin I've tested on FW 4.6, could you try a newer version please?

shermp commented 4 years ago

Found a much better way of getting the current dialog name, that isn't tied to the current language. Turns out N3Dialog is more of a generic wrapper than anything else. It contains a widget that has the dialog contents.

This widget can be obtained by calling N3Dialog::content(), and one can get the the object name from the returned QWidget pointer.

[root@(none) ~]# qndb -m ndbCurrentView
N3SettingsView
[root@(none) ~]# qndb -m ndbCurrentView
N3SettingsDeviceInformationView
shermp commented 4 years ago

Well, the NH failsafe just saved me from having to factory reset... Hooray for the failsafe 😀

For those wondering, apparently QTimer really prefers to be heap allocated.

shermp commented 4 years ago

Could you have one last quick look please @pgaskin when/if you get a moment?

I've now added a crude debounce style filter to prevent duplicate signals being sent, like what was happening before in FW 4.6

Otherwise I think I'm done, barring any issues.

shermp commented 4 years ago

Looks good. Tested on FW 15548.

Thank you very much.

I know you're currently pretty busy, so thanks for taking the time to look at this. It's most appreciated.