Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 06-01-2011, 12:26 AM   #1
rozen
Member
rozen began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Dec 2010
Location: CA
Device: nook
A Tiny Database Hack

Hi,

Since I often have several editions of the New York Times on my Nook where I can't readily tell the most recent one, I decided to try writing a simple plugin which would attach a date string to the title. I started with the Interface Demo Plugin and hacked away. I am running on Ubuntu 10.10.

Well I got my AddDate plugin to work but I had to make a hack to the database code. I feel that I should not have done that, so I am asking your guidance. Again, I think that I am missing something important.

The important code for my plug is the following:

def view(self):
rows = self.gui.library_view.selectionModel().selectedRow s()
previous = self.gui.library_view.currentIndex()

if not rows or len(rows) != 1:
d = error_dialog(self.gui, _('Cannot edit metadata'),
_('Please select exactly one row.'))
d.exec_()
return

row_list = [r.row() for r in rows]
current_row = 0

if len(row_list) == 1:
cr = row_list[0]
row_list = \
list(range(
self.gui.library_view.model().rowCount(QModelIndex ())))
current_row = row_list.index(cr)

r_db = self.gui.library_view.model().db
r_id = r_db.id(current_row)
r_metadata = r_db.get_metadata(current_row)
r_title = r_metadata.title
metadata_timestamp = r_metadata.timestamp
metadata_timestamp = metadata_timestamp.timetuple()

import time
date_addition = time.strftime("%a, %d %b %Y", metadata_timestamp)
if r_title.find(date_addition) > -1:
self.close()
return
new_title = r_title + ' [' + date_addition + ']'
r_metadata.title = new_title

r_db.set_metadata(r_id, r_metadata)

changed = set([r_id])
rows_to_refresh = set([r_id])

m = self.gui.library_view.model()

if rows_to_refresh:
m.refresh_rows(rows_to_refresh)

if changed:
m.refresh_ids(list(changed))
current = self.gui.library_view.currentIndex()
if self.gui.cover_flow:
self.gui.cover_flow.dataChanged()
m.current_changed(current, previous)
self.gui.tags_view.recount()

self.close()


When Executing the statement:

r_db.set_metadata(r_id, r_metadata)

I get an error from _set_title in database2.py. Specifically, the line

only_case_change = icu_lower(old_title) == icu_lower(title)

burps because old_title is None.

So I replaced that statement with:

only_case_change = 0
if old_title: # Added by Rozen.
only_case_change = icu_lower(old_title) == icu_lower(title)

For completeness I have attached my plugin.

Since I feel that I have done something evil in ignorance, I would appreciate any suggestion.

Thanks in Advance,
Don
Attached Files
File Type: zip add_date_plugin.zip (15.7 KB, 250 views)
rozen is offline   Reply With Quote
Old 06-01-2011, 01:14 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Just create a custom recipe based on the builtin one and set the timefmt field in the recipe.
kovidgoyal is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Paid Hack Request: Photo Slideshow Hack for Kindle 3 chmreader Kindle Developer's Corner 0 05-25-2011 01:24 PM
Calibre Database cp Kindle Database mitch13 Library Management 1 05-22-2011 07:33 PM
Is it a tiny little ebook? GraceKrispy Lounge 13 05-02-2010 02:43 AM
Book titles hack? Time delay hack? re838uk Sony Reader 0 10-08-2009 05:29 AM
Hack Attack! Esquire wants us to hack their e-paper cover TadW News 26 10-22-2008 03:51 AM


All times are GMT -4. The time now is 04:22 AM.


MobileRead.com is a privately owned, operated and funded community.