jump functions
authorMarcus Wikström <mece@ovi.com>
Tue, 9 Feb 2010 19:58:50 +0000 (21:58 +0200)
committerMarcus Wikström <mece@ovi.com>
Tue, 9 Feb 2010 19:58:50 +0000 (21:58 +0200)
debian/rules [changed mode: 0755->0644]
src/usr/lib/hildon-desktop/comicwidget.py

old mode 100755 (executable)
new mode 100644 (file)
index ed655b8..6e754d5 100644 (file)
@@ -205,6 +205,29 @@ class ComicDb():
                                print "comic db creation failed after copy"
 
 
                                print "comic db creation failed after copy"
 
 
+       def get_stored(self):
+               try:
+                       idf = open(self.dbfile + ".last", 'r')
+                       retval = idf.read()
+                       print "got stored index :" + str(retval)
+                       idf.close()
+                       return int(retval)
+               except:
+                       return 0
+
+       def store_last(self, sid = 0):
+               try:
+                       idf = open(self.dbfile + ".last", 'w')
+                       if sid > 0:
+                               idf.write(str(sid))
+                       else:
+                               idf.write(str(self.currentcomic))
+                       idf.close()
+                       return True
+               except:                 
+                       return False
+
+
        def get_comic(self):
                print str(self.currentcomic)
                if self.currentcomic < 0:
        def get_comic(self):
                print str(self.currentcomic)
                if self.currentcomic < 0:
@@ -279,6 +302,9 @@ class ComicDb():
                dbw = csv.writer(dbf)
                dbw.writerow(irow)
                dbf.close()
                dbw = csv.writer(dbf)
                dbw.writerow(irow)
                dbf.close()
+               stored = self.get_stored()
+               if stored > 0:
+                       self.store_last(stored + 1)
 
        def insert_row_first(self, irow):
                dbf = open(self.dbfile, 'w')
 
        def insert_row_first(self, irow):
                dbf = open(self.dbfile, 'w')
@@ -1117,8 +1143,16 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                                self.e_goweb.show_all()
 
                        elif func == 'switch':
                                self.e_goweb.show_all()
 
                        elif func == 'switch':
+                               # Check if store needed..
+                               if not self.db.currentcomic == 0 and not self.db.currentcomic == (len(self.db.db) - 1):
+                                       print "Storing location " + str(self.db.currentcomic)
+                                       if self.db.store_last():
+                                               print "stored successfully"
+                                       else:
+                                               print "store failed"
+                                
                                self.active_comics = self.get_active_comics()
                                self.active_comics = self.get_active_comics()
-                               print "closing log"
+                               # print "closing log"
                                #sys.stdout.close()
                                #sys.stdout = sys.__stdout__
                                #sys.stderr.close()
                                #sys.stdout.close()
                                #sys.stdout = sys.__stdout__
                                #sys.stderr.close()
@@ -1275,6 +1309,20 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
 
                #if not, write defaults
 
 
                #if not, write defaults
 
+       def goto_comic(self, index):
+               self.db.currentcomic = index
+               self.e_open.remove(self.comic_image)
+               self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
+               self.e_open.add(self.comic_image)
+               self.e_open.show_all()
+               self.e_goweb.remove(self.label)
+               titl = str(self.db.db[self.db.currentcomic]['title'])
+               if len(titl) > 22:
+                       titl = titl[:19] + "..."
+               self.label.set_markup(self.get_markup())
+               self.e_goweb.add(self.label)
+               self.e_goweb.show_all()
+       
 # ************************* OPTION DIALOGS ********************************
 
        def show_options(self, widget):
 # ************************* OPTION DIALOGS ********************************
 
        def show_options(self, widget):
@@ -1291,12 +1339,32 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                comics_button.set_alignment(0,0,0,0)
                comics_button.connect("clicked", self.show_comics)
 
                comics_button.set_alignment(0,0,0,0)
                comics_button.connect("clicked", self.show_comics)
 
+               navfirst_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+               navfirst_button.set_text("Go to earliest", "Jump to the earliest cached comic")
+               navfirst_button.set_alignment(0,0,0,0)
+               navfirst_button.connect("clicked", self.show_nav, "oldest")
+
+               navlast_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+               navlast_button.set_text("Go to latest", "Jump to the latest cached comic")
+               navlast_button.set_alignment(0,0,0,0)
+               navlast_button.connect("clicked", self.show_nav, "newest")
+
+               navstored_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+               navstored_button.set_text("Go to last visited", "Jump to where you were before you switched comics")
+               navstored_button.set_alignment(0,0,0,0)
+               navstored_button.connect("clicked", self.show_nav, "stored")
+
                # size_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
                # size_button.set_text("Change size", "Change the size of the widget")
                # size_button.set_alignment(0,0,0,0)
                # size_button.connect("clicked", self.show_size)
 
                # size_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
                # size_button.set_text("Change size", "Change the size of the widget")
                # size_button.set_alignment(0,0,0,0)
                # size_button.connect("clicked", self.show_size)
 
+
+
                print "adding buttons to dialog, starting with comics"
                print "adding buttons to dialog, starting with comics"
+               dialog.vbox.pack_start(navstored_button, True, True, 0)
+               dialog.vbox.pack_start(navfirst_button, True, True, 0)
+               dialog.vbox.pack_start(navlast_button, True, True, 0)
                dialog.vbox.pack_start(comics_button, True, True, 0)
                print "adding about button"
                dialog.vbox.pack_start(about_button, True, True, 0)
                dialog.vbox.pack_start(comics_button, True, True, 0)
                print "adding about button"
                dialog.vbox.pack_start(about_button, True, True, 0)
@@ -1306,6 +1374,14 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                dialog.run()
                dialog.destroy()
 
                dialog.run()
                dialog.destroy()
 
+       def show_nav(self, widget, goto):
+               if goto == "stored":
+                       print "look for stored file"
+                       self.goto_comic(self.db.get_stored())
+               elif goto == "newest":
+                       self.goto_comic(0)
+               elif goto == "oldest":
+                       self.goto_comic(len(self.db.db) - 1)
        def show_about(self, widget):
                print "in about dialog"
                dialog = gtk.AboutDialog()
        def show_about(self, widget):
                print "in about dialog"
                dialog = gtk.AboutDialog()