From b2c80aad9e056a520feb5ab767d172857a9effa9 Mon Sep 17 00:00:00 2001 From: Billy Charlton Date: Sun, 18 May 2008 11:24:58 -0700 Subject: [PATCH] Implement "Manual" option Added dialog for entering manual tivo IP address; save manual entry as first entry in the list and in gconf; make it the default. --- tivo4tiny | 100 +++++++++++++++---- tivo4tiny.glade | 291 +++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 287 insertions(+), 104 deletions(-) diff --git a/tivo4tiny b/tivo4tiny index e55db21..4edc29f 100755 --- a/tivo4tiny +++ b/tivo4tiny @@ -1,5 +1,6 @@ #!/usr/bin/python +# --------------------- # Tivo 4 Tiny # (c) 2008 Billy Charlton, San Francisco CA, USA # Licensed under the GNU GPL Version 3.0 http://www.gnu.org @@ -39,9 +40,9 @@ import tempfile # BB Curve screen is portrait, so scale 240:-10. Others are landscape, so scale -10:240. # BB Curve can only handle 15fps well. Others can attempt 30fps, so just use native fps. CONVERSIONS = [ - ["iPod/iPhone/BB Curve" , ".avi", "-vf pp=md,scale=-10:240 -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:vbitrate=230:acodec=mp3:abitrate=128"], - ["BlackBerry Pearl" , ".avi", "-vf pp=md,scale=240:-10 -ofps 15 -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:vbitrate=230:acodec=mp3:abitrate=128"], - ["Full-size MPEG-4" , ".avi", "-vf scale=0:0 -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:acodec=mp3:abitrate=192"], + ["iPod/iPhone/BB Curve" , ".avi", "-vf pp=md,scale=-10:240 -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:vbitrate=230:acodec=libmp3lame:abitrate=128"], + ["BlackBerry Pearl" , ".avi", "-vf pp=md,scale=240:-10 -ofps 15 -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:vbitrate=230:acodec=libmp3lame:abitrate=128"], + ["Full-size MPEG-4" , ".avi", "-vf scale=0:0 -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:acodec=libmp3lame:abitrate=192"], ["Raw Copy (MPEG-2)" , ".mpg", "xxx"] ] @@ -364,12 +365,12 @@ class TivoSucker: # Use Avahi to populate list of Tivos on the network. - # May someday want to store the list from last time? def findTivos(self): # Clear list of Tivos self.ComboWhichTivo.set_model(None) self.ComboWhichTivo.clear() liststore = gtk.ListStore(str,str) + cell = gtk.CellRendererText() self.ComboWhichTivo.pack_start(cell, True) self.ComboWhichTivo.add_attribute(cell,'text',0) @@ -383,6 +384,9 @@ class TivoSucker: foundativo = "" ipaddr="" + # If there's already a Tivo selected in gconf, use that one. + lastTivo = self.gconfclient.get_string ("/apps/tivo4tiny/which_tivo") + while (k != ""): k = cmdout.readline() # First check for '=' which means a new Tivo @@ -392,16 +396,24 @@ class TivoSucker: # Then check for 'address' line which has the IP address if (k.find("address")>-1): ipaddr = k[1+k.find('['):k.find(']')] -# print "Found: ", foundativo, ipaddr - - # Add a new Tivo to combobox - liststore.append([foundativo,ipaddr]) + # Add this Tivo to combobox. + # If this is the one from the last time we ran, be sure it's the first choice + if (foundativo == lastTivo): + liststore.prepend([foundativo,ipaddr]) + lastTivo = None + else: + liststore.append([foundativo,ipaddr]) + + # Finally, add the last tivo if it hasn't been found already + if (lastTivo != None): + liststore.prepend([lastTivo,lastTivo]) + + liststore.append(["Manual...","0.0.0.0"]) self.ComboWhichTivo.set_model(liststore) - # Might want to save this later - if (len(liststore)>0): -# print "Got one!" + # if there are any Tivos found, set first item to active selection, + if (len(liststore) >1): # >1 because "Manual..." entry is always there self.ComboWhichTivo.set_active(0) # close the window and quit @@ -413,6 +425,9 @@ class TivoSucker: def prefs_delete_event(self, widget, event, data=None): return True + def showAddWindow(self): + self.addWindow.show_all() + def showPrefsWindow(self, widget): self.PrefsWindow.show_all() @@ -434,6 +449,11 @@ class TivoSucker: self.progressBarAll.set_sensitive(False) #Get the main windows, and connect the "destroy" events + self.addWindow = self.wTree.get_widget("dialogAddTivo") + self.addEntry = self.wTree.get_widget("entryAddTivo") + self.addWindow.connect("delete_event", self.prefs_delete_event) + self.addWindow.set_deletable(False) + self.PrefsWindow = self.wTree.get_widget("PrefsDialog") self.PrefsWindow.connect("delete_event", self.prefs_delete_event) self.PrefsWindow.set_deletable(False) @@ -529,14 +549,18 @@ class TivoSucker: dic = { "on_ListView_row_activated" : self.addTransfer, "on_MainWindow_destroy" : gtk.main_quit, "on_PrefsDialog_destroy" : self.closePrefsWindow, + "on_dialogAddTivo_destroy" : self.closeAddWindow, + "on_dialogAddTivo_close" : self.closeAddWindow, "on_ButtonShowPrefs_clicked" : self.showPrefsWindow, "on_EntryMak_changed" : self.entryMakChanged, "on_ComboFormat_changed" : self.comboFormatChanged, - "on_ComboWhichTivo_changed" : self.buttonUpdateListClicked, + "on_ComboWhichTivo_changed" : self.buttonWhichTivoClicked, "on_EntryFolder_changed" : self.entryFolderChanged, "on_ButtonPrefsOK_clicked" : self.prefsOKClicked, + "on_btnAddTivoOK_clicked" : self.addManualTivo, + "on_btnAddTivoCancel_clicked" : self.closeAddWindow, "on_ButtonChooseFolder_clicked" : self.chooseFolderClicked, - "on_ButtonUpdateList_clicked" : self.buttonUpdateListClicked + "on_ButtonUpdateList_clicked" : self.buttonWhichTivoClicked } self.wTree.signal_autoconnect(dic) @@ -550,7 +574,6 @@ class TivoSucker: self.gconfclient.set_string ("/apps/tivo4tiny/media_access_key",self.mak) def comboFormatChanged(self, widget): -# print "Format changed!" item = self.ComboFormat.get_active() if (item < 0): # what to do if no format suggested? @@ -563,21 +586,60 @@ class TivoSucker: def entryFolderChanged(self, widget): self.destdir = self.EntryFolder.get_text() -# print "Folder text changed! ", self.destdir self.gconfclient.set_string ("/apps/tivo4tiny/dest_dir",self.destdir) def closePrefsWindow(self, widget): -# print "hiding?" self.PrefsWindow.hide_all() - def buttonUpdateListClicked(self, widget): - self.populateShows() + def closeAddWindow(self, widget): + self.addWindow.hide_all() + + # User typed in a manual IP address and clicked "OK" + def addManualTivo(self,widget): + entry = self.addEntry.get_text() + print "add",entry + + if (len(entry)>0): + tivo = entry + ipaddr = entry + + # then create an entry for that item + self.ComboWhichTivo.get_model().prepend([tivo,ipaddr]) + self.ComboWhichTivo.set_active(0) + # Save the choice + self.gconfclient.set_string ("/apps/tivo4tiny/which_tivo", tivo) + # And, now that it's all done, let's repopulate the show list. + self.populateShows() + + self.addWindow.hide_all() + + + def buttonWhichTivoClicked(self, widget): + # Which Tivo is selected? + item = self.ComboWhichTivo.get_active() + if (item < 0): return + + tivo = self.ComboWhichTivo.get_model()[item][0] + ipaddr = self.ComboWhichTivo.get_model()[item][1] + + if (tivo == "Manual..."): + # Ask what IP address to connect to + self.showAddWindow() + + else: + # Save the choice + self.gconfclient.set_string ("/apps/tivo4tiny/which_tivo", tivo) + # And, now that it's all done, let's repopulate the show list. + self.populateShows() def prefsOKClicked(self, widget): -# print "OK!" self.PrefsWindow.hide_all() self.buttonUpdate.set_sensitive(True) + def addOKClicked(self, widget): + self.addWindow.hide_all() + print "now what?" + def chooseFolderClicked(self, widget): print "Not yet implemented" diff --git a/tivo4tiny.glade b/tivo4tiny.glade index 429e2d7..8991771 100644 --- a/tivo4tiny.glade +++ b/tivo4tiny.glade @@ -1,13 +1,13 @@ - + 650 450 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK Tivo 4 Tiny - /usr/share/tivo4tiny/tivo4tiny.png + tivo4tiny.png True @@ -114,47 +114,62 @@ 2 4 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - + - 3 - 4 + 2 + 3 + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + 1 + + PANGO_ELLIPSIZE_END + + + 2 + 3 1 2 - + GTK_FILL + 5 - + True + False True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Prefs... + Cancel All Transfers + 0 0 - - 3 - 4 - 5 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - + 0 + - 1 - 2 - + 1 + 2 @@ -172,62 +187,47 @@ - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - + - 1 - 2 + 1 + 2 + - + True - False True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Cancel All Transfers - 0 + Prefs... 0 + + 3 + 4 + 5 - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - 1 - - PANGO_ELLIPSIZE_END + - 2 - 3 + 3 + 4 1 2 - GTK_FILL - 5 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - - 2 - 3 - @@ -263,45 +263,34 @@ 5 10 - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - + 20 + 1 2 - 1 - 2 - - 5 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Format for: - - - 1 - 2 - GTK_FILL 5 - + True + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Media Access Key: + Download Folder + 0 + + 2 + 3 - 5 + @@ -320,33 +309,44 @@ - + True - True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Download Folder - 0 - + Media Access Key: - 2 - 3 - + 5 - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 20 - + 0 + Format for: + + + 1 + 2 + GTK_FILL + 5 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + 1 2 + 1 + 2 + 5 @@ -382,4 +382,125 @@ + + 5 + Add Tivo Manually + True + GTK_WIN_POS_CENTER_ON_PARENT + True + tivo4tiny.png + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + + + True + 2 + + + True + + + True + 0 + gtk-dialog-question + 6 + + + False + + + + + True + + + True + 0 + 0 + 5 + <b>Enter the IP address or network name of your Tivo.</b> + True + + + False + + + + + True + 0 + 0 + 5 + You can find the IP address of your Tivo at Tivo Central > Settings > Phone & Network. + True + + + False + 1 + + + + + True + True + True + 0.0.0.0 + + + False + 5 + 2 + + + + + 1 + + + + + False + 1 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + 0 + + + + + + True + True + True + gtk-ok + True + 0 + + + + 1 + + + + + False + GTK_PACK_END + + + + + -- 2.11.4.GIT