File systray.patch of Package mikutube

--- ./MikuTube.py.org	2012-03-05 21:23:32.000000000 +0900
+++ ./MikuTube.py	2012-05-02 22:27:14.269350597 +0900
@@ -775,6 +775,24 @@
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkCheckButton" id="CB_TRAYICON">
+                        <property name="label" translatable="yes">トレイアイコンを有効にする</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="has_tooltip">True</property>
+                        <property name="tooltip_text" translatable="yes">※次回起動時から有効</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkCheckButton" id="CB_HD">
                         <property name="label" translatable="yes">HD画質を使用する(あれば)</property>
                         <property name="use_action_appearance">False</property>
@@ -1068,8 +1086,8 @@
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="has_tooltip">True</property>
-                            <property name="tooltip_markup" translatable="yes">youtube-dlの追加オプションを指定します。</property>
-                            <property name="tooltip_text" translatable="yes">youtube-dlの追加オプションを指定します。</property>
+                            <property name="tooltip_markup" translatable="yes">gksudo youtube-dl -U</property>
+                            <property name="tooltip_text" translatable="yes">youtube-dl -Uを実行する</property>
                             <property name="xalign">0</property>
                             <property name="label" translatable="yes">youtube-dlの最新版取得</property>
                           </object>
@@ -1084,7 +1102,7 @@
                             <property name="label" translatable="yes">更新</property>
                             <property name="use_action_appearance">False</property>
                             <property name="height_request">16</property>
-                            <property name="visible">True</property>
+                            <property name="visible">False</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
                             <property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
@@ -1172,6 +1190,7 @@
                             "keyword":"初音ミク PV",
                             "volume":"100",
                             "ontop":"False",
+                            "trayicon":"False",
                             "sortOrder":"2",
                             "listMaxCount":"0",
                             "useHD":"False",
@@ -1183,6 +1202,7 @@
                             "youtube-dl":"-n",
                             "youtube-dl-option":"",
                             "youtube-dl-timeout":"30",
+                            "readsize":"1",
                             "mplayer":""}
     AppName = "MikuTube"
     ConfigPath = "/.config/MikuTube.xml"
@@ -1638,7 +1658,7 @@
 
     gladefile = "Options.glade"
 
-    def __init__(self, engine,shuffle,ontop,useHD,playNotifyError,mplayer_opt,youtube_dl_timeout,playNotify,errorSkip):
+    def __init__(self, engine,shuffle,ontop,trayicon,useHD,playNotifyError,mplayer_opt,youtube_dl_timeout,playNotify,errorSkip):
         #Set the Glade file
         #load the dialog from the glade file
         #self.wTree = gtk.glade.XML(self.gladefile)
@@ -1660,6 +1680,7 @@
 
         self.shuffle = self.wTree.get_object ("CB_SHUFFLE")
         self.ontop = self.wTree.get_object ("CB_ONTOP")
+        self.trayicon = self.wTree.get_object ("CB_TRAYICON")
         self.useHD = self.wTree.get_object ("CB_HD")
         self.playNotifyError = self.wTree.get_object ("CB_USE_OSDERR")
         self.playNotify = self.wTree.get_object ("CB_USE_OSD")
@@ -1676,6 +1697,7 @@
             self.selectEngine.set_active(0)
         self.shuffle.set_active(shuffle)
         self.ontop.set_active(ontop)
+        self.trayicon.set_active(trayicon)
         self.useHD.set_active(useHD)
         self.errorSkip.set_active(errorSkip)
         self.playNotifyError.set_active(playNotifyError)
@@ -1693,6 +1715,7 @@
         #we are done with the dialog, destroy it
         shuffle = self.shuffle.get_active()
         ontop = self.ontop.get_active()
+        trayicon = self.trayicon.get_active()
         useHD = self.useHD.get_active()
         errorSkip = self.errorSkip.get_active()
         playNotifyError = self.playNotifyError.get_active()
@@ -1708,6 +1731,7 @@
         return   self.result,engine,\
                     shuffle,\
                     ontop,\
+                    trayicon,\
                     useHD,\
                     playNotifyError,\
                     mplayerOpt,\
@@ -2674,6 +2698,7 @@
             errorSkip = False
 
         self.mute = False
+        self.readsize = long(conf.GetOption("readsize"))
         # Create Player
         #self.createGST()
         self.PlayStart()
@@ -2682,6 +2707,18 @@
         self.currentWorker = 0
         self.overMaxBG = False
 
+        self.trayicon = eval(conf.GetOption("trayicon"))
+        if self.trayicon == True:
+            if os.path.exists("/usr/share/mikutube/MikuTube.png") == True:
+                iconPath = "/usr/share/mikutube/MikuTube.png"
+            elif os.path.exists(os.path.dirname(os.path.abspath(__file__)) + "/MikuTube.png") == True:
+                iconPath = os.path.dirname(os.path.abspath(__file__)) + "/MikuTube.png"
+            self.tray = gtk.StatusIcon()
+            self.tray.set_from_file(iconPath) 
+            self.tray.connect('popup-menu', self.on_right_click)
+            self.tray.connect('activate', self.on_left_click)
+            self.tray.set_tooltip(('MikuTube'))
+
     def __getitem__(self, key):
         """
 
@@ -2812,6 +2849,7 @@
             conf.SetOption("keyword",self.keyword)
             conf.SetOption("volume",self.volume)
             conf.SetOption("ontop",self.ontop)
+            conf.SetOption("trayicon",self.trayicon)
             conf.SetOption("sortOrder",self.order)
             conf.SetOption("listMaxCount",self.listMaxCount)
             conf.SetOption("useHD",self.useHD)
@@ -3038,10 +3076,10 @@
     def on_PM_OPTIONS_DLG_activate(self,widget):
         debuglog("OPTION DIALOG")
         global ENGINE,playNotifyError,MPLAYER_OPT,playNotify,errorSkip
-        dlg = OptionsWnd(ENGINE,self.playList.shuffle,self.ontop,self.useHD,playNotifyError,MPLAYER_OPT,self.youtube_dl_timeout,playNotify,errorSkip)
-        (ret, eng, shuffle, ontop, useHD, notifyError,mp_opt,youtube_dl_timeout,playNotify,errorSkip) = dlg.run()
+        dlg = OptionsWnd(ENGINE,self.playList.shuffle,self.ontop,self.trayicon,self.useHD,playNotifyError,MPLAYER_OPT,self.youtube_dl_timeout,playNotify,errorSkip)
+        (ret, eng, shuffle, ontop, trayicon, useHD, notifyError,mp_opt,youtube_dl_timeout,playNotify,errorSkip) = dlg.run()
         if ret == gtk.RESPONSE_OK :
-            (ENGINE, self.playList.shuffle, self.ontop, self.useHD, playNotifyError,MPLAYER_OPT,self.youtube_dl_timeout,playNotify,errorSkip) = (eng, shuffle, ontop, useHD, notifyError,mp_opt,youtube_dl_timeout,playNotify,errorSkip)
+            (ENGINE, self.playList.shuffle, self.ontop, self.trayicon, self.useHD, playNotifyError,MPLAYER_OPT,self.youtube_dl_timeout,playNotify,errorSkip) = (eng, shuffle, ontop, trayicon, useHD, notifyError,mp_opt,youtube_dl_timeout,playNotify,errorSkip)
             self.mainWindow.set_keep_above(self.ontop)
             self.savePlayInfo()
 
@@ -3095,7 +3133,7 @@
                             debuglog("Check Count2:" + str(m))
                             state = os.stat(self.__curWorker().flvfile)
                             debuglog("file size:"+str(state.st_size))
-                            readsize = 1024L*512L
+                            readsize = 1024L*512L*self.readsize
                             if state.st_size > readsize:
                                 break
                             wait(1)
@@ -3262,6 +3300,86 @@
         if self.drawMessage != None:
             self.drawMessage()
 
+    def on_Volume_Up_activate(self,widget):
+        if self.volume < 100 :
+            self.volume += 10
+        if self.mute == False:
+            self.player.Volume(float(self.volume))
+
+    def on_Volume_Down_activate(self,widget):
+        if self.volume > 0 :
+            self.volume -= 10
+        if self.mute == False:
+            self.player.Volume(float(self.volume))
+
+    def show_about_dialog(self, widget):
+        about_dialog = gtk.AboutDialog()
+        about_dialog.set_destroy_with_parent(True)
+        about_dialog.set_icon_name("SystrayIcon")
+        about_dialog.set_name('みくつべ♪')
+        about_dialog.set_version('1.8.0.2')
+        about_dialog.set_copyright("(C) かおりん")
+        about_dialog.set_comments(("みくつべ♪はYouTubeをキーワードで検索し、連続再生を行います。"))
+        about_dialog.set_authors(['http://code.google.com/p/mikutube/'])
+        about_dialog.run()
+        about_dialog.destroy()
+
+    def on_right_click(self, icon, event_button, event_time):
+        self.make_menu(event_button, event_time)
+
+    def on_left_click(self, widget):
+        self.mainWindow.present()
+
+    def make_menu(self, event_button, event_time):
+        menu = gtk.Menu()
+
+        play = gtk.MenuItem("再生")
+        play.show()
+        menu.append(play)
+        play.connect('activate', self.on_PM_PLAY_activate)
+
+        pause = gtk.MenuItem("一時停止")
+        pause.show()
+        menu.append(pause)
+        pause.connect('activate', self.on_PM_PAUSE_activate)
+
+        stop = gtk.MenuItem("停止")
+        stop.show()
+        menu.append(stop)
+        stop.connect('activate', self.on_PM_STOP_activate)
+
+        prev = gtk.MenuItem("前の動画")
+        prev.show()
+        menu.append(prev)
+        prev.connect('activate', self.on_PM_PREV_activate)
+
+        next = gtk.MenuItem("次の動画")
+        next.show()
+        menu.append(next)
+        next.connect('activate', self.on_PM_NEXT_activate)
+
+        volup = gtk.MenuItem("音量を上げる")
+        volup.show()
+        menu.append(volup)
+        volup.connect('activate', self.on_Volume_Up_activate)
+
+        voldown = gtk.MenuItem("音量を下げる")
+        voldown.show()
+        menu.append(voldown)
+        voldown.connect('activate', self.on_Volume_Down_activate)
+
+        about = gtk.MenuItem("みくつべ")
+        about.show()
+        menu.append(about)
+        about.connect('activate', self.show_about_dialog)
+
+        quit = gtk.MenuItem("終了")
+        quit.show()
+        menu.append(quit)
+        quit.connect('activate', self.on_quit)
+
+        menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, self.tray)
+
 #共通汎用関数(ダイアログ・メッセージボックス等)
 def notifyOSD(msg):
     if playNotify == True: