kovidgoyal/calibre — pull request #191 by cbhaley (2014-02-25 13:46:08+00:00)
Title: Infrastructure for allowing a device to "synchronize" data with calibres'...

... database. The exact meaning of "synchronize" is left to the device. This implementation adds almost zero overhead (nanoseconds per book) if the device driver does not do any synchronization.

During book matching in gui2.device, whenever a book on the device is matched to a book in the DB, the (new) device method synchronize_with_db is called. It can copy information from the device to calibre's db or vice versa. If it returns True then the book's metadata is updated from calibre's DB even if it otherwise would not be. This permits the synchronization process to request that data in calibre be unconditionally sent to the device.

Note that the synchronize_with_db method is called on the GUI thread. It is the device driver's responsibility to be threadsafe with respect to the device manager thread.

A lightly-tested implementation in the wireless driver is included to show how the new method might be used. It implements syncing a yes/no "is read" column and a "read date" column from the device to calibre.