04-18-2011, 01:08 PM | #1 |
Sigil developer
Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Detecting complete sync of books from device
Is there a way to tell when a device is fully connected - in the sense that calibre knows the ids of the books on the device.
I occasionally get a condition where someone (ok, me mainly ) runs the plugin before all the books that are on the device are identified. This means when my plugin asks calibre for the data, it gets back 0 books on the device, until you run it a second time after the job is done. |
04-18-2011, 02:03 PM | #2 |
Grand Sorcerer
Posts: 11,932
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
No, there isn't. What would you do if you had something like this? Refuse to run?
We could add a signal that is fired when the ondevice calculations are done. I see two issues. 1) It would be best not to interact with the user in that signal handler, because the GUI would blocked at what appears to be a random time. 2) it would be signaled when books are added or deleted. Kovid, I am thinking of emitting the signal after we call self.library_view.model().refresh_ondevice() at line 803 of device.py. Do you see any problem with this? |
Advert | |
|
04-18-2011, 02:08 PM | #3 |
creator of calibre
Posts: 44,321
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Why not do it at the end of metadata_downloaded? IIRC, that means the device is "fully connected"
|
04-18-2011, 02:13 PM | #4 | |
Grand Sorcerer
Posts: 11,932
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
My thought was that if we are adding this signal, something that connects to the signal might want to know if the booklists have changed. There are other methods that change the booklist, for example books_uploaded and books_deleted, and both of these call refresh_ondevice at the right time. |
|
04-18-2011, 02:16 PM | #5 |
creator of calibre
Posts: 44,321
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Best to have two signals in that case, it's not like they are a scarce resource metadata_downloaded and book list changed are very different things.
|
Advert | |
|
04-18-2011, 02:19 PM | #6 |
Grand Sorcerer
Posts: 11,932
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Both of them result in the same thing -- telling the signal recipient that the ondevice information has (potentially) changed. But I don't care enough to argue. I will add the signal to the end of metadata_downloaded.
|
04-18-2011, 02:29 PM | #7 |
Grand Sorcerer
Posts: 11,932
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Code pushed.
The signal is device_metadata_available, and is raised after all the connection processing is complete. It should be visible to a plugin as gui.device_metadata_available. The sequence: gui.device_manager.is_device_connected will become True, then sometime later gui.device_metadata_available will be signaled. This does not mean that there are no more jobs running. Automatic metadata management might have kicked off a sync_booklists to write new metadata onto the device, and that job might still be running when the signal is emitted. |
04-18-2011, 02:35 PM | #8 |
creator of calibre
Posts: 44,321
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
merged .
|
04-18-2011, 02:56 PM | #9 |
Sigil developer
Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Step away for a minute and look what happens
Just to be clear - my plugin does not have to be running and looking for a signal? It just has to test if gui.device_metadata_available is True before continuing - otherwise I will issue an error dialog to tell the user to wait and try again. (Actually I currently test if gui.device_manager.is_device_connected is True, and then I test if gui.device_manager.connected_device._main_prefix has a value because I think I used to test for just main_prefix but found that wasn't reset between connections so I test both - and now I'll add a 3rd test). I understand it won't be perfect as there could be books to send to/sync with the device - but it will prevent the majority of issues that might happen. Many thanks. |
04-18-2011, 04:18 PM | #10 | |
Grand Sorcerer
Posts: 11,932
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Thinking about it, I understand one of the difficulties you are facing. You don't track connections and disconnections, so this one signal isn't sufficient. You need to know when the device connects and disconnects so you can know what this signal means. Assuming Kovid accepts the change, I have added a second signal, gui.device_connected_changed.emit(connected). This signal is emitted whenever a device is connected or disconnected. The argument to the signal, connected, is True if a device has been connected, False otherwise. In your init method, connect to these two signals. If you get device_connected_changed(False), mark the fact that there is no device and clear the device valid indication. If you get device_connected_changed(True), mark that fact, and prepare to receive the device_metadata_available signal. When you receive the device_metadata_available, note that fact, which the rest of your plugin will use to determine whether the info is available or not. The initial condition is that there is no device. |
|
04-18-2011, 04:42 PM | #11 |
creator of calibre
Posts: 44,321
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Merged.
|
04-18-2011, 05:21 PM | #12 |
Sigil developer
Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Got it. Of course the plugin is already live once calibre starts. Thanks.
|
04-19-2011, 12:36 PM | #13 |
Sigil developer
Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Ok, don't got it.
I'm running from the source with the signals, but I'm obviously missing something in the syntax/use as I'm getting an error. I've put in my genesis routine in ui.py (testconnect1 just prints hello): self.gui.device_metadata_available.connect(self.te stconnect1) but I get this when I start calibre: File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 253, in initialize self.initialize_db() File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 234, in initialize_db self.initialize_db_stage2(db, None) File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 203, in initialize_db_stage2 self.start_gui(db) File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 159, in start_gui main.initialize(self.library_path, db, self.listener, self.actions) File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/ui.py", line 195, in initialize ac.do_genesis() File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/actions/__init__.py", line 97, in do_genesis self.genesis() File "calibre_plugins.kindle_collections.ui", line 55, in genesis TypeError: connect() failed between [] and unislot() |
04-19-2011, 12:53 PM | #14 |
Calibre Plugins Developer
Posts: 4,673
Karma: 2162246
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@meme - try hooking in initialization_complete rather than genesis?
|
04-19-2011, 01:00 PM | #15 |
creator of calibre
Posts: 44,321
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There was a bug with the way signals were implemented. Charles committed a fix a little while ago.
Use self.gui.device_signals.signal_name.connect(... |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre not detecting device | Bureaucromancer | Kobo Reader | 3 | 09-19-2010 12:16 AM |
Re-detecting a device such as iPad | gandor62 | Calibre | 1 | 06-18-2010 08:21 PM |
Calibre not detecting device prs500 | Miri | Calibre | 10 | 06-13-2010 01:46 PM |
Detecting device | mpetry | Calibre | 3 | 04-16-2010 09:05 PM |
Multi-Device Sync? | Sonist | Calibre | 6 | 02-03-2010 03:49 PM |