1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2009 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 from gpodder
import util
28 from gpodder
.gtkui
.interface
.common
import BuilderWidget
31 class gPodderChannel(BuilderWidget
):
33 self
.gPodderChannel
.set_title( self
.channel
.title
)
34 self
.entryTitle
.set_text( self
.channel
.title
)
35 self
.labelURL
.set_text(self
.channel
.url
)
37 self
.LabelDownloadTo
.set_text( self
.channel
.save_dir
)
38 self
.LabelWebsite
.set_text( self
.channel
.link
)
40 self
.cbNoSync
.set_active( not self
.channel
.sync_to_devices
)
41 self
.musicPlaylist
.set_text(self
.channel
.device_playlist_name
)
42 if self
.channel
.username
:
43 self
.FeedUsername
.set_text( self
.channel
.username
)
44 if self
.channel
.password
:
45 self
.FeedPassword
.set_text( self
.channel
.password
)
47 self
.cover_downloader
.register('cover-available', self
.cover_download_finished
)
48 self
.cover_downloader
.request_cover(self
.channel
)
50 # Hide the website button if we don't have a valid URL
51 if not self
.channel
.link
:
52 self
.btn_website
.hide_all()
55 b
.set_text( self
.channel
.description
)
56 self
.channel_description
.set_buffer( b
)
58 #Add Drag and Drop Support
59 flags
= gtk
.DEST_DEFAULT_ALL
60 targets
= [ ('text/uri-list', 0, 2), ('text/plain', 0, 4) ]
61 actions
= gtk
.gdk
.ACTION_DEFAULT | gtk
.gdk
.ACTION_COPY
62 self
.vboxCoverEditor
.drag_dest_set( flags
, targets
, actions
)
63 self
.vboxCoverEditor
.connect( 'drag_data_received', self
.drag_data_received
)
65 def on_btn_website_clicked(self
, widget
):
66 util
.open_website(self
.channel
.link
)
68 def on_btnDownloadCover_clicked(self
, widget
):
69 dlg
= gtk
.FileChooserDialog(title
=_('Select new podcast cover artwork'), parent
=self
.gPodderChannel
, action
=gtk
.FILE_CHOOSER_ACTION_OPEN
)
70 dlg
.add_button(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_CANCEL
)
71 dlg
.add_button(gtk
.STOCK_OPEN
, gtk
.RESPONSE_OK
)
73 if dlg
.run() == gtk
.RESPONSE_OK
:
75 self
.cover_downloader
.replace_cover(self
.channel
, url
)
79 def on_btnClearCover_clicked(self
, widget
):
80 self
.cover_downloader
.replace_cover(self
.channel
)
82 def cover_download_finished(self
, channel_url
, pixbuf
):
83 if pixbuf
is not None:
84 self
.imgCover
.set_from_pixbuf(pixbuf
)
85 self
.gPodderChannel
.show()
87 def drag_data_received( self
, widget
, content
, x
, y
, sel
, ttype
, time
):
88 files
= sel
.data
.strip().split('\n')
90 self
.show_message( _('You can only drop a single image or URL here.'), _('Drag and drop'))
95 if file.startswith('file://') or file.startswith('http://'):
96 self
.cover_downloader
.replace_cover(self
.channel
, file)
99 self
.show_message( _('You can only drop local files and http:// URLs here.'), _('Drag and drop'))
101 def on_gPodderChannel_destroy(self
, widget
, *args
):
102 self
.cover_downloader
.unregister('cover-available', self
.cover_download_finished
)
104 def on_btnOK_clicked(self
, widget
, *args
):
105 self
.channel
.sync_to_devices
= not self
.cbNoSync
.get_active()
106 self
.channel
.device_playlist_name
= self
.musicPlaylist
.get_text()
107 self
.channel
.set_custom_title(self
.entryTitle
.get_text())
108 self
.channel
.username
= self
.FeedUsername
.get_text().strip()
109 self
.channel
.password
= self
.FeedPassword
.get_text()
112 self
.gPodderChannel
.destroy()
113 self
.callback_closed()