--- a/immsview Tue Feb 03 13:50:03 2004 -0500
+++ b/immsview Tue Feb 03 15:55:27 2004 -0500
@@ -20,9 +20,13 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
-_immsview_version = "$Id: immsview 1693 2004-02-03 18:50:03Z fabien $"
+_immsview_version = "$Id: immsview 1694 2004-02-03 20:55:27Z fabien $"
# $Log$
+# Revision 1.13 2004/02/03 20:55:27 fabien
+# Play selected: check if the file exist, elsewhere try to
+# update it through the Db.
+#
# Revision 1.12 2004/02/03 18:50:03 fabien
# Add double click and remove sorting when refreshing data.
#
@@ -165,15 +169,21 @@
FROM Library
WHERE Library.path = '%s';''' % (path))
return cu.fetchone()
- def get_ratings_and_info(self):
+ def get_ratings_and_info(self, uids = None):
print time.ctime(time.time()) + ": querying"
cu = self.cx.cursor()
- cu.execute('''SELECT Rating.uid, Rating.rating,
+ qry = '''SELECT Rating.uid, Rating.rating,
Library.path, Last.last
FROM Rating, Library, Last
WHERE Rating.uid = Library.uid AND
- Library.sid = Last.sid
- ORDER BY Rating.rating DESC;''')
+ Library.sid = Last.sid '''
+ if uids:
+ qry += 'AND (Library.uid = %d' % (uids.pop())
+ for uid in uids:
+ qry += ' OR Library.uid = %d' % uid
+ qry += ') '
+ qry += 'ORDER BY Rating.rating DESC;'
+ cu.execute(qry)
# Better to fetch everything since locking can really mess
# things in imms plugin.
print time.ctime(time.time()) + ": mapping"
@@ -181,7 +191,8 @@
tune = cu.fetchone()
while tune:
try:
- tmp = {'rating' : int(tune[1]),
+ tmp = {'uid' : tune[0],
+ 'rating' : int(tune[1]),
'path' : tune[2].decode('utf-8', 'replace'),
'last' : int(tune[3])}
results.append(tmp)
@@ -196,17 +207,31 @@
COL_LAST_STR = 2
COL_LAST = 3
COL_SELECT = 4
+ COL_UID = 5
def __init__(self, db):
gtk.ListStore.__init__(self,
gobject.TYPE_INT,
gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_INT,
- gobject.TYPE_BOOLEAN)
+ gobject.TYPE_BOOLEAN,
+ gobject.TYPE_INT)
self.db = db
# self.set_default_sort_func(self.default_sort)
def default_sort(self, a, b, dummy):
return 0
+ def tune_to_giter(self, tune, giter = None, curtime = 0):
+ if not curtime:
+ curtime = time.time()
+ if not giter:
+ giter = self.append(None)
+ self.set(giter,
+ IMMSStore.COL_UID, tune['uid'],
+ IMMSStore.COL_RATING, tune['rating'],
+ IMMSStore.COL_PATH, tune['path'],
+ IMMSStore.COL_LAST_STR, strtime(curtime-tune['last']),
+ IMMSStore.COL_LAST, tune['last'],
+ IMMSStore.COL_SELECT, gtk.FALSE)
def refresh(self):
curtime = time.time()
col, order = self.get_sort_column_id()
@@ -219,13 +244,7 @@
self.clear()
print time.ctime(time.time()) + ": inserting"
for tune in tunes:
- iter = self.append(None)
- self.set(iter,
- IMMSStore.COL_RATING, tune['rating'],
- IMMSStore.COL_PATH, tune['path'],
- IMMSStore.COL_LAST_STR, strtime(curtime-tune['last']),
- IMMSStore.COL_LAST, tune['last'],
- IMMSStore.COL_SELECT, gtk.FALSE)
+ self.tune_to_giter(tune, curtime = curtime)
print time.ctime(time.time()) + ": end insert"
self.set_sort_column_id(col, order)
def find_selection(self):
@@ -242,6 +261,12 @@
return self.get_path(giter)
giter = self.iter_next(giter)
return None
+ def update_iter(self, giter):
+ uid = self.get_value(giter, IMMSStore.COL_UID)
+ tunes = self.db.get_ratings_and_info([uid,])
+ for tune in tunes:
+ self.tune_to_giter(tune, giter)
+ return giter
class IMMSView(gtk.TreeView):
def __init__(self, model, xmms):
@@ -281,16 +306,29 @@
giter = model.get_iter(gpath)
model.set_value(giter, IMMSStore.COL_SELECT, gtk.TRUE)
self.set_cursor(gpath)
+ def get_filename(self, giter):
+ update = 0
+ fn = model.get_value(giter, IMMSStore.COL_PATH)
+ try:
+ os.stat(fn)
+ except OSError:
+ update = 1
+ if update:
+ model.update_iter(giter)
+ fn = model.get_value(giter, IMMSStore.COL_PATH)
+ try:
+ os.stat(fn)
+ except OSError:
+ return None
def get_file_selected(self):
model, giter = self.get_selection().get_selected()
if giter:
- return model.get_value(giter, IMMSStore.COL_PATH)
+ return self.get_filename(giter)
return None
def on_row_activated(self, tview, path, col):
model = self.get_model()
giter = model.get_iter(path)
- fn = model.get_value(giter, IMMSStore.COL_PATH)
- self.xmms.play_file(fn)
+ self.set_current_song(fn)
class IMMSToolbar(gtk.Toolbar):