update model when deleting all bookmarks
[panucci.git] / src / panucci / qtui / qtmain.py
blobd02278863c4059e1b5314e36742cbf5c1492561d
1 # -*- coding: utf-8 -*-
3 # This file is part of Panucci.
4 # Copyright (c) 2008-2011 The Panucci Project
6 # Panucci 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 # Panucci 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 Panucci. If not, see <http://www.gnu.org/licenses/>.
19 from __future__ import absolute_import
21 import logging
22 import os.path
23 import cgi
24 from PySide import QtCore
25 from PySide import QtGui
27 try:
28 import pynotify
29 pynotify.init('Panucci')
30 have_pynotify = True
31 except:
32 have_pynotify = False
34 import panucci
35 from panucci import util
36 from panucci import platform
37 from panucci import playlist
38 from panucci.dbusinterface import interface
39 from panucci.services import ObservableService
40 from panucci.qtui import qtutil
41 from panucci.qtui import qtplaylist
42 from panucci.qtui import qtwidgets
44 ##################################################
45 # PanucciGUI
46 ##################################################
47 class PanucciGUI(object):
48 """ The object that holds the entire panucci gui """
50 def __init__(self, settings, filename=None):
51 self.__log = logging.getLogger('panucci.panucci.PanucciGUI')
52 interface.register_gui(self)
53 self.config = settings.config
54 self.playlist = playlist.Playlist(self.config)
56 self.app = QtGui.QApplication(["Panucci"])
57 self.app.setWindowIcon(QtGui.QIcon(util.find_data_file('panucci.png')))
58 self.main_window = QtGui.QMainWindow(None)
59 if platform.FREMANTLE:
60 self.main_window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow)
61 self.main_window.closeEvent = self.close_main_window_callback
62 self.create_actions()
63 self.__player_tab = PlayerTab(self)
64 self.__playlist_tab = qtplaylist.PlaylistTab(self, self.playlist)
65 if platform.HANDSET:
66 self.create_handset_menus()
67 else:
68 self.create_menus()
69 widget = QtGui.QWidget()
70 widget.setLayout(self.__player_tab.mainbox)
71 self.main_window.setCentralWidget(widget)
72 self.main_window.show()
73 self.playlist.init(filepath=filename)
74 self.app.exec_()
76 def create_actions(self):
77 # File menu
78 self.action_add_file = QtGui.QAction(QtGui.QIcon(':/actions/add.png'), _("Add File").decode("utf-8"), self.main_window, shortcut="Ctrl+A",
79 statusTip="Add file to playlist", triggered=self.add_file_callback)
80 self.action_add_folder = QtGui.QAction(QtGui.QIcon(':/images/open.png'), _("Add Folder").decode("utf-8"), self.main_window, shortcut="Ctrl+D",
81 statusTip="Add folder to playlist", triggered=self.add_folder_callback)
82 self.action_save_playlist = QtGui.QAction(QtGui.QIcon(':/images/save.png'), _("Save Playlist").decode("utf-8"), self.main_window, shortcut="Ctrl+W",
83 statusTip="Save current playlist as m3u", triggered=self.save_playlist_callback)
84 self.action_clear_playlist = QtGui.QAction(QtGui.QIcon(':/images/trashcan.png'), _("Clear Playlist").decode("utf-8"), self.main_window, shortcut="Ctrl+H",
85 statusTip="Clear current playlist", triggered=self.clear_playlist_callback)
86 self.action_delete_bookmarks = QtGui.QAction(QtGui.QIcon(':/images/trashcan.png'), _("Delete All Bookmarks").decode("utf-8"), self.main_window, shortcut="Ctrl+K",
87 statusTip="Delete all bookmarks", triggered=self.delete_bookmarks_callback)
88 self.action_quit = QtGui.QAction(QtGui.QIcon('/usr/share/icons/gnome/16x16/actions/exit.png'), "Quit", self.main_window, shortcut="Ctrl+Q",
89 statusTip="Exit the application", triggered=self.quit_panucci)
90 # Tools menu
91 self.action_playlist = QtGui.QAction(_("Playlist"), self.main_window, shortcut="Ctrl+P",
92 statusTip=_("Open playlist"), triggered=self.playlist_callback)
93 self.action_settings = QtGui.QAction(_("Settings"), self.main_window, shortcut="Ctrl+C",
94 statusTip=_("Open settings dialog"), triggered=self.settings_callback)
95 self.action_timer = QtGui.QAction(_("Sleep Timer"), self.main_window, shortcut="Ctrl+T",
96 statusTip=_("Start a timed shutdown"), triggered=self.create_timer_dialog)
97 # Settings menu
98 self.action_lock_progress = QtGui.QAction(_("Lock Progress Bar").decode("utf-8"), self.main_window, shortcut="Ctrl+L",
99 statusTip="Lock progress bar", triggered=self.lock_progress_callback)
100 self.action_lock_progress.setCheckable(True)
101 self.action_lock_progress.setChecked(self.config.getboolean("options", "lock_progress"))
102 self.action_dual_action = QtGui.QAction(_("Dual Action Button").decode("utf-8"), self.main_window, shortcut="Ctrl+B",
103 statusTip="Set dual action button", triggered=self.dual_action_callback)
104 self.action_dual_action.setCheckable(True)
105 self.action_dual_action.setChecked(self.config.getboolean("options", "dual_action_button"))
106 self.action_stay_at_end = QtGui.QAction(_("Stay at End").decode("utf-8"), self.main_window, shortcut="Ctrl+E",
107 statusTip="Stay at file end", triggered=self.stay_at_end_callback)
108 self.action_stay_at_end.setCheckable(True)
109 self.action_stay_at_end.setChecked(self.config.getboolean("options", "stay_at_end"))
110 self.action_seek_back = QtGui.QAction(_("Seek Back").decode("utf-8"), self.main_window, shortcut="Ctrl+S",
111 statusTip="Seek back to previous file", triggered=self.seek_back_callback)
112 self.action_seek_back.setCheckable(True)
113 self.action_seek_back.setChecked(self.config.getboolean("options", "seek_back"))
114 self.action_scrolling_labels = QtGui.QAction(_("Scrolling Labels").decode("utf-8"), self.main_window, shortcut="Ctrl+V",
115 statusTip="Scroll title labels when too long", triggered=self.scrolling_labels_callback)
116 self.action_scrolling_labels.setCheckable(True)
117 self.action_scrolling_labels.setChecked(self.config.getboolean("options", "scrolling_labels"))
118 self.action_play_mode_all = QtGui.QAction(_("All").decode("utf-8"), self.main_window, statusTip="Set play mode",
119 triggered=self.play_mode_all_callback)
120 self.action_play_mode_all.setCheckable(True)
121 self.action_play_mode_single = QtGui.QAction(_("Single").decode("utf-8"), self.main_window, statusTip="Set play mode",
122 triggered=self.play_mode_single_callback)
123 self.action_play_mode_single.setCheckable(True)
124 self.action_play_mode_random = QtGui.QAction(_("Random").decode("utf-8"), self.main_window, statusTip="Set play mode",
125 triggered=self.play_mode_random_callback)
126 self.action_play_mode_random.setCheckable(True)
127 self.action_play_mode_repeat = QtGui.QAction(_("Repeat").decode("utf-8"), self.main_window, statusTip="Set play mode",
128 triggered=self.play_mode_repeat_callback)
129 self.action_play_mode_repeat.setCheckable(True)
130 actiongroup = QtGui.QActionGroup(self.main_window)
131 actiongroup.setExclusive(True)
132 self.action_play_mode_all.setActionGroup(actiongroup)
133 self.action_play_mode_single.setActionGroup(actiongroup)
134 self.action_play_mode_random.setActionGroup(actiongroup)
135 self.action_play_mode_repeat.setActionGroup(actiongroup)
136 if self.config.get("options", "play_mode") == "single":
137 self.action_play_mode_single.setChecked(True)
138 elif self.config.get("options", "play_mode") == "random":
139 self.action_play_mode_random.setChecked(True)
140 elif self.config.get("options", "play_mode") == "repeat":
141 self.action_play_mode_repeat.setChecked(True)
142 else:
143 self.action_play_mode_all.setChecked(True)
144 # help menu
145 self.action_about = QtGui.QAction(QtGui.QIcon('about.png'), _("About").decode("utf-8"), self.main_window,
146 statusTip="Show about dialog", triggered=self.about_callback)
148 def create_menus(self):
149 # File menu
150 self.menu_file = self.main_window.menuBar().addMenu(_("File").decode("utf-8"))
151 self.menu_file.addAction(self.action_add_file)
152 self.menu_file.addAction(self.action_add_folder)
153 self.menu_file.addAction(self.action_save_playlist)
154 self.menu_file.addAction(self.action_clear_playlist)
155 self.menu_file.addAction(self.action_delete_bookmarks)
156 self.menu_file.addSeparator()
157 self.menu_file.addAction(self.action_quit)
158 # Tools menu
159 self.menu_tools = self.main_window.menuBar().addMenu(_("Tools").decode("utf-8"))
160 self.menu_tools.addAction(self.action_playlist)
161 self.menu_tools.addAction(self.action_timer)
162 #self.menu_tools.addAction(self.action_settings)
163 # Settings menu
164 self.menu_settings = self.main_window.menuBar().addMenu(_("Settings").decode("utf-8"))
165 self.menu_settings.addAction(self.action_lock_progress)
166 self.menu_settings.addAction(self.action_dual_action)
167 self.menu_settings.addAction(self.action_stay_at_end)
168 self.menu_settings.addAction(self.action_seek_back)
169 self.menu_settings.addAction(self.action_scrolling_labels)
170 self.menu_play_mode = self.menu_settings.addMenu(_("Play Mode").decode("utf-8"))
171 self.menu_play_mode.addAction(self.action_play_mode_all)
172 self.menu_play_mode.addAction(self.action_play_mode_single)
173 self.menu_play_mode.addAction(self.action_play_mode_random)
174 self.menu_play_mode.addAction(self.action_play_mode_repeat)
175 # Help menu
176 self.menu_help = self.main_window.menuBar().addMenu(_("Help").decode("utf-8"))
177 self.menu_help.addAction(self.action_about)
179 def create_handset_menus(self):
180 # Player menu
181 self.menu_player = self.main_window.menuBar().addMenu("Player")
182 self.menu_player.addAction(self.action_settings)
183 self.menu_player.addAction(self.action_playlist)
184 self.menu_player.addAction(self.action_add_file)
185 self.menu_player.addAction(self.action_add_folder)
186 self.menu_player.addAction(self.action_clear_playlist)
187 self.menu_player.addAction(self.action_timer)
188 self.menu_player.addAction(self.action_about)
189 # Playlist menu
190 self.menu_playlist = self.__playlist_tab.main_window.menuBar().addMenu("Playlist")
191 self.menu_playlist.addAction(self.action_save_playlist)
192 self.menu_playlist.addAction(self.action_delete_bookmarks)
194 def create_timer_dialog(self):
195 response = QtGui.QInputDialog.getInteger(self.main_window, _("Sleep Timer"), _("Shutdown time in minutes"),
196 value=5, minValue=1)
197 if response[1]:
198 QtCore.QTimer.singleShot(60000*response[0], self.quit_panucci)
200 def quit_panucci(self):
201 self.main_window.hide()
202 self.playlist.quit()
203 util.write_config(self.config)
204 self.app.exit()
206 def close_main_window_callback(self, event):
207 self.quit_panucci()
209 def show_main_window(self):
210 self.main_window.activateWindow()
212 def add_file_callback(self):
213 filenames = qtutil.get_file_from_filechooser(self)
214 if filenames:
215 self._play_file(filenames[0].encode('utf-8'))
217 def add_folder_callback(self):
218 filenames = qtutil.get_file_from_filechooser(self, folder=True)
219 if filenames:
220 self._play_file(filenames[0].encode('utf-8'))
222 def save_playlist_callback(self):
223 filenames = qtutil.get_file_from_filechooser(self, save_file=True, save_to=True)
224 if not filenames:
225 return False
227 filename = filenames[0]
228 if os.path.isfile(filename):
229 response = qtutil.dialog(self.main_window, _('File already exists!'),
230 _('The file %s already exists. You can choose another name or '
231 'overwrite the existing file.') % os.path.basename(filename), False, True, True, True)
233 if response == QtGui.QMessageBox.Cancel:
234 return None
235 elif response == QtGui.QMessageBox.Discard:
236 return self.save_playlist_callback()
238 ext = util.detect_filetype(filename)
239 if not self.playlist.save_to_new_playlist(filename, ext):
240 self.notify(_('Error saving playlist...'))
241 return False
243 return True
245 def clear_playlist_callback(self):
246 self.playlist.reset_playlist()
247 self.__playlist_tab.clear_model()
249 def delete_bookmarks_callback(self):
250 response = qtutil.dialog(self.main_window, _('Delete all bookmarks?'),
251 _('By accepting all bookmarks in the database will be deleted.'), True, False, True, False)
252 if response == QtGui.QMessageBox.Ok:
253 self.playlist.delete_all_bookmarks()
254 self.__playlist_tab.update_model()
256 def playlist_callback(self):
257 self.__playlist_tab.main_window.show()
259 def settings_callback(self):
260 from panucci.qtui.qtsettingsdialog import SettingsDialog
261 SettingsDialog(self)
263 def lock_progress_callback(self):
264 self.set_config_option("lock_progress", str(self.action_lock_progress.isChecked()).lower())
266 def dual_action_callback(self):
267 self.set_config_option("dual_action_button", str(self.action_dual_action.isChecked()).lower())
269 def stay_at_end_callback(self):
270 self.set_config_option("stay_at_end", str(self.action_stay_at_end.isChecked()).lower())
272 def seek_back_callback(self):
273 self.set_config_option("seek_back", str(self.action_seek_back.isChecked()).lower())
275 def scrolling_labels_callback(self):
276 self.set_config_option("scrolling_labels", str(self.action_scrolling_labels.isChecked()).lower())
277 self.__player_tab.label_title.set_scrolling(self.config.getboolean("options", "scrolling_labels"))
279 def play_mode_all_callback(self):
280 self.set_config_option("play_mode", "all")
282 def play_mode_single_callback(self):
283 self.set_config_option("play_mode", "single")
285 def play_mode_random_callback(self):
286 self.set_config_option("play_mode", "random")
288 def play_mode_repeat_callback(self):
289 self.set_config_option("play_mode", "repeat")
291 def about_callback(self):
292 from panucci.qtui import qtaboutdialog
293 qtaboutdialog.AboutDialog(self.main_window, panucci.__version__)
295 def set_config_option(self, option, value):
296 self.config.set("options", option, value)
298 def _play_file(self, filename, pause_on_load=False):
299 self.playlist.load( os.path.abspath(filename) )
301 if self.playlist.is_empty:
302 return False
304 ##################################################
305 # PlayerTab
306 ##################################################
307 class PlayerTab(ObservableService):
308 """ The tab that holds the player elements """
310 signals = [ 'select-current-item-request', ]
312 def __init__(self, gui_root):
313 self.__log = logging.getLogger('panucci.panucci.PlayerTab')
314 self.__gui_root = gui_root
315 self.config = gui_root.config
316 self.playlist = gui_root.playlist
317 ObservableService.__init__(self, self.signals, self.__log)
319 self.playlist.player.register( 'stopped', self.on_player_stopped )
320 self.playlist.player.register( 'playing', self.on_player_playing )
321 self.playlist.player.register( 'paused', self.on_player_paused )
322 #self.playlist.player.register( 'eof', self.on_player_eof )
323 self.playlist.register( 'end-of-playlist', self.on_player_end_of_playlist )
324 self.playlist.register( 'new-track-loaded', self.on_player_new_track )
325 self.playlist.register( 'new-metadata-available', self.on_player_new_metadata )
326 self.playlist.register( 'reset-playlist', self.on_player_reset_playlist )
328 self.mainbox = QtGui.QVBoxLayout()
329 self.mainbox.setContentsMargins(0, 0, 0, 0)
330 self.mainbox.setSpacing(0)
332 layout = QtGui.QHBoxLayout()
333 layout.setContentsMargins(0, 0, 0, 0)
334 layout.setSpacing(0)
335 self.label_cover = QtGui.QLabel()
336 self.label_cover.setContentsMargins(0, 5, 2, 5)
337 layout.addWidget(self.label_cover)
338 vlayout = QtGui.QVBoxLayout()
339 vlayout.setContentsMargins(0, 0, 0, 0)
340 vlayout.setSpacing(0)
341 vlayout.addStretch(5)
342 self.label_artist = QtGui.QLabel()
343 self.label_album = QtGui.QLabel()
344 self.label_artist.setContentsMargins(3, 0, 5, 10)
345 self.label_album.setContentsMargins(3, 0, 5, 10)
346 self.label_title = qtwidgets.ScrollingLabel(self.config)
347 self.label_title.setContentsMargins(0, 0, 0, 0)
348 vlayout.addWidget(self.label_artist)
349 vlayout.addWidget(self.label_album)
350 vlayout.addWidget(self.label_title)
351 vlayout.addStretch(5)
352 layout.addLayout(vlayout, 2)
353 self.mainbox.addLayout(layout, 8)
355 self.progress = QtGui.QProgressBar()
356 self.progress.setContentsMargins(0, 0, 0, 0)
357 self.mainbox.addWidget(self.progress)
358 self.progress.setTextVisible(True)
359 self.progress.setFormat("00:00 / 00:00")
360 self.progress.setValue(0)
361 self.progress.mousePressEvent = self.on_progress_clicked
362 progress_height = self.config.getint("options", "progress_height")
363 if progress_height != -1:
364 self.progress.setFixedHeight(progress_height)
366 self.icon_play = QtGui.QIcon(util.find_data_file('media-playback-start.png'))
367 self.icon_pause = QtGui.QIcon(util.find_data_file('media-playback-pause.png'))
369 self.button_rrewind = qtwidgets.DualActionButton(self.config,
370 QtGui.QIcon(util.find_data_file('media-skip-backward.png')),
371 self.button_rrewind_callback,
372 QtGui.QIcon(util.find_data_file("gtk-goto-first-ltr.png")),
373 self.playlist.prev)
374 self.button_rewind = QtGui.QPushButton(QtGui.QIcon(util.find_data_file('media-seek-backward.png')), "")
375 self.button_rewind.clicked.connect(self.button_rewind_callback)
376 self.button_play = QtGui.QPushButton(self.icon_play, "")
377 self.button_play.clicked.connect(self.button_play_callback)
378 self.button_forward = QtGui.QPushButton(QtGui.QIcon(util.find_data_file('media-seek-forward.png')), "")
379 self.button_forward.clicked.connect(self.button_forward_callback)
380 self.button_fforward = qtwidgets.DualActionButton(self.config,
381 QtGui.QIcon(util.find_data_file('media-skip-forward.png')),
382 self.button_fforward_callback,
383 QtGui.QIcon(util.find_data_file("gtk-goto-last-ltr.png")),
384 self.playlist.next)
385 self.button_bookmark = QtGui.QPushButton(QtGui.QIcon(util.find_data_file('bookmark-new.png')), "")
386 self.button_bookmark.clicked.connect(self.button_bookmark_callback)
388 button_height = self.config.getint("options", "button_height")
389 if button_height != -1:
390 self.button_rrewind.setFixedHeight(button_height)
391 self.button_rewind.setFixedHeight(button_height)
392 self.button_play.setFixedHeight(button_height)
393 self.button_forward.setFixedHeight(button_height)
394 self.button_fforward.setFixedHeight(button_height)
395 self.button_bookmark.setFixedHeight(button_height)
397 layout = QtGui.QHBoxLayout()
398 layout.setContentsMargins(0, 4, 0, 0)
399 layout.setSpacing(0)
400 layout.addWidget(self.button_rrewind)
401 layout.addWidget(self.button_rewind)
402 layout.addWidget(self.button_play)
403 layout.addWidget(self.button_forward)
404 layout.addWidget(self.button_fforward)
405 layout.addWidget(self.button_bookmark)
406 self.mainbox.addLayout(layout)
408 self.timer = QtCore.QTimer()
409 self.timer.setInterval(1000);
410 self.timer.timeout.connect(self.timer_callback)
412 def on_player_stopped(self):
413 self.stop_progress_timer()
414 #self.set_controls_sensitivity(False)
415 self.button_play.setIcon(self.icon_play)
417 def on_player_playing(self):
418 self.start_progress_timer()
419 self.button_play.setIcon(self.icon_pause)
420 #self.set_controls_sensitivity(True)
422 def on_player_paused( self, position, duration ):
423 self.stop_progress_timer()
424 #self.set_progress_callback( position, duration )
425 self.button_play.setIcon(self.icon_play)
427 def on_player_new_track(self):
428 for widget in [self.label_title, self.label_artist, self.label_album, self.label_cover]:
429 widget.setText('')
430 self.label_cover.hide()
431 self.has_coverart = False
433 def on_player_new_metadata(self):
434 self.metadata = self.playlist.get_file_metadata()
435 self.set_metadata(self.metadata)
437 if not self.playlist.player.playing:
438 position = self.playlist.get_current_position()
439 estimated_length = self.metadata.get('length', 0)
440 self.set_progress_callback( position, estimated_length )
441 self.playlist.player.set_position_duration(position, 0)
443 def on_player_end_of_playlist(self, loop):
444 if not loop:
445 self.playlist.player.stop_end_of_playlist()
446 estimated_length = self.metadata.get('length', 0)
447 self.set_progress_callback( 0, estimated_length )
448 self.playlist.player.set_position_duration(0, 0)
450 def on_player_reset_playlist(self):
451 self.on_player_stopped()
452 self.on_player_new_track()
453 self.reset_progress()
454 self.__gui_root.main_window.setWindowTitle("Panucci")
456 def reset_progress(self):
457 self.set_progress_callback(0,0)
459 def button_rrewind_callback(self):
460 self.do_seek(-1*self.config.getint("options", "seek_long"))
462 def button_rewind_callback(self):
463 self.do_seek(-1*self.config.getint("options", "seek_short"))
465 def button_play_callback(self):
466 self.playlist.player.play_pause_toggle()
468 def button_forward_callback(self):
469 self.do_seek(self.config.getint("options", "seek_short"))
471 def button_fforward_callback(self):
472 self.do_seek(self.config.getint("options", "seek_long"))
474 def button_bookmark_callback(self):
475 self.playlist.player.add_bookmark_at_current_position()
477 def set_progress_callback(self, time_elapsed, total_time):
478 """ times must be in nanoseconds """
479 time_string = "%s / %s" % ( util.convert_ns(time_elapsed),
480 util.convert_ns(total_time) )
481 self.progress.setFormat( time_string )
482 fraction = float(time_elapsed) / float(total_time) if total_time else 0
483 self.progress.setValue( int(fraction*100) )
485 def on_progress_clicked(self, event):
486 if ( not self.config.getboolean("options", "lock_progress") and
487 event.button() == QtCore.Qt.MouseButton.LeftButton ):
488 new_fraction = float(event.x())/float(self.progress.width())
489 resp = self.playlist.player.do_seek(percent=new_fraction)
490 if resp:
491 # Preemptively update the progressbar to make seeking smoother
492 self.set_progress_callback( *resp )
494 def timer_callback( self ):
495 if self.playlist.player.playing and not self.playlist.player.seeking:
496 pos_int, dur_int = self.playlist.player.get_position_duration()
497 # This prevents bogus values from being set while seeking
498 if ( pos_int > 10**9 ) and ( dur_int > 10**9 ):
499 self.set_progress_callback( pos_int, dur_int )
500 return True
502 def start_progress_timer( self ):
503 self.timer.start()
505 def stop_progress_timer( self ):
506 self.timer.stop()
508 def get_cover_size(self):
509 if self.__gui_root.main_window.isFullScreen():
510 size = self.config.getint("options", "cover_full_height")
511 else:
512 size = self.config.getint("options", "cover_height")
513 return size
515 def set_cover_size(self):
516 if self.has_coverart:
517 size = self.get_cover_size()
518 pixmap = self.label_cover.pixmap().scaled(size, size, mode=QtCore.Qt.SmoothTransformation)
519 self.label_cover.setPixmap(pixmap)
521 def set_metadata( self, tag_message ):
522 tags = { 'title': self.label_title, 'artist': self.label_artist,
523 'album': self.label_album }
525 # set the coverart
526 if tag_message.has_key('image') and tag_message['image'] is not None:
527 value = tag_message['image']
529 try:
530 pixmap = QtGui.QPixmap()
531 pixmap.loadFromData(value)
532 size = self.get_cover_size()
533 pixmap = pixmap.scaled(size, size, mode=QtCore.Qt.SmoothTransformation)
534 self.label_cover.setPixmap(pixmap)
535 self.label_cover.show()
536 self.has_coverart = True
537 except Exception, e:
538 self.__log.exception('Error setting coverart...')
540 # set the text metadata
541 for tag,value in tag_message.iteritems():
542 if tags.has_key(tag) and value is not None and value.strip():
543 value = value.decode('utf-8')
544 if tag == "artist":
545 _str = '<big>' + cgi.escape(value) + '</big>'
546 elif tag == "album":
547 _str = cgi.escape(value)
548 elif tag == "title":
549 _str = '<b><big>' + cgi.escape(value) + '</big></b>'
550 if not platform.MAEMO:
551 value += ' - Panucci'
552 if platform.FREMANTLE and len(value) > 25:
553 value = value[:24] + '...'
554 self.__gui_root.main_window.setWindowTitle(value)
556 if not self.has_coverart:
557 tags[tag].setAlignment(QtCore.Qt.AlignHCenter)
558 else:
559 tags[tag].setAlignment(QtCore.Qt.AlignLeft)
560 try:
561 tags[tag].setText(_str)
562 except TypeError, e:
563 self.__log.exception(str(e))
565 tags[tag].show()
567 def do_seek(self, seek_amount):
568 resp = self.playlist.do_seek(seek_amount*10**9)
569 if resp:
570 # Preemptively update the progressbar to make seeking smoother
571 self.set_progress_callback( *resp )