Changeset 51

Show
Ignore:
Timestamp:
02/25/06 22:57:18 (3 years ago)
Author:
nicfit
Message:

New playlist config, closes #26

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Makefile.in

    r28 r51  
    7878        -rm Makefile 
    7979        -rm ./src/*.glade.* ./src/*.gladep* 
     80        -rm ./svn-commit* 
    8081 
    8182maintainer-clean: dist-clean docs-clean 
  • trunk/src/audio_control.py

    r46 r51  
    5353        self._rewind_flag = False 
    5454        self._rewind_set = False 
    55         self._gap_delay = mesk.config.getint(mesk.AUDIO, 'gst_delay') 
     55        self._gap_delay = mesk.config.getint(mesk.CONFIG_AUDIO, 'gst_delay') 
    5656 
    5757        # Get widgets 
     
    289289            self._set_track_scale(0, upper = src.audio_info.time_secs) 
    290290 
    291         uri = src.uri 
    292         # Strip file:// since the file sink does not deal with it. 
    293         if uri.find("file://") == 0: 
    294             uri = uri[len("file://"):] 
     291        uri = mesk.utils.strip_file_uri(src.uri) 
    295292        self._src.set_property('location', uri) 
    296293 
     
    391388 
    392389    def _create_audio_sink(self): 
    393         config_sink = mesk.config.get(mesk.AUDIO, 'gst_sink') 
     390        config_sink = mesk.config.get(mesk.CONFIG_AUDIO, 'gst_sink') 
    394391        if config_sink == mesk.GST_OSS: 
    395392            audio_sink = gst.element_factory_make("osssink", "audio_sink") 
  • trunk/src/main_window.py

    r37 r51  
    2323from playlist_control import PlaylistControl 
    2424 
     25import config 
     26 
    2527import mesk 
    2628_ = mesk.common.i18n._ 
     
    4547        self.audio_control = AudioControl(self.xml) 
    4648 
     49        self._active_playlist = None 
    4750        # Load playlists 
    48         self._active_playlist = None 
    49         for pl_config in mesk.config.items(mesk.PLAYLISTS): 
    50             pl = mesk.playlist.load(pl_config[1]) 
    51             pl_ctrl = PlaylistControl(pl_config[0], pl, self.audio_control) 
     51        playlists = config.playlist_names() 
     52        for pl in playlists: 
     53            if not config.playlist_auto_open(pl): 
     54                continue 
     55 
     56            try: 
     57                pl_ctrl = PlaylistControl(pl, self.audio_control) 
     58            except Exception, ex: 
     59                msg = _("Error loading playlist '%s'") % (pl) 
     60                d = gtk.MessageDialog(None, gtk.DIALOG_MODAL, 
     61                                      type = gtk.MESSAGE_ERROR, 
     62                                      buttons = gtk.BUTTONS_OK, 
     63                                      message_format = msg) 
     64                d.format_secondary_text(str(ex)) 
     65                d.run() 
     66                d.destroy() 
     67                continue 
     68 
    5269            self.add_notebook_control(pl_ctrl) 
    53             # FIXME: Only one of the playlists may be the active playlist 
    5470            if not self._active_playlist: 
    5571                self._active_playlist = pl_ctrl 
    5672 
    57         self._active_playlist.set_active(True) 
    58         self.audio_control.set_playlist(self._active_playlist.get_playlist()) 
     73        if self._active_playlist: 
     74            self._active_playlist.set_active(True) 
     75            pl = self._active_playlist.get_playlist() 
     76            self.audio_control.set_playlist(pl) 
    5977 
    6078    def add_notebook_control(self, ctrl): 
     
    6583 
    6684    def show(self): 
    67         compact = mesk.config.getboolean(mesk.UI, 'compact_state') 
     85        compact = mesk.config.getboolean(mesk.CONFIG_UI, 'compact_state') 
    6886        self.xml.get_widget('compact_menuitem').set_active(compact) 
    6987 
     
    88106        (x, y) = self.window.get_position() 
    89107        if not self._is_compact: 
    90             mesk.config.set(mesk.UI, 'main_window_width', str(width)) 
    91             mesk.config.set(mesk.UI, 'main_window_height', str(height)) 
    92             mesk.config.set(mesk.UI, 'main_window_pos_x', str(x)) 
    93             mesk.config.set(mesk.UI, 'main_window_pos_y', str(y)) 
     108            mesk.config.set(mesk.CONFIG_UI, 'main_window_width', str(width)) 
     109            mesk.config.set(mesk.CONFIG_UI, 'main_window_height', str(height)) 
     110            mesk.config.set(mesk.CONFIG_UI, 'main_window_pos_x', str(x)) 
     111            mesk.config.set(mesk.CONFIG_UI, 'main_window_pos_y', str(y)) 
    94112        else: 
    95             mesk.config.set(mesk.UI, 'compact_main_window_pos_x', str(x)) 
    96             mesk.config.set(mesk.UI, 'compact_main_window_pos_y', str(y)) 
     113            mesk.config.set(mesk.CONFIG_UI, 'compact_main_window_pos_x', str(x)) 
     114            mesk.config.set(mesk.CONFIG_UI, 'compact_main_window_pos_y', str(y)) 
    97115 
    98116    def _restore_window_attrs(self): 
    99         width = mesk.config.getint(mesk.UI, 'main_window_width') 
    100         height = mesk.config.getint(mesk.UI, 'main_window_height') 
    101         x = mesk.config.getint(mesk.UI, 'main_window_pos_x') 
    102         y = mesk.config.getint(mesk.UI, 'main_window_pos_y') 
     117        width = mesk.config.getint(mesk.CONFIG_UI, 'main_window_width') 
     118        height = mesk.config.getint(mesk.CONFIG_UI, 'main_window_height') 
     119        x = mesk.config.getint(mesk.CONFIG_UI, 'main_window_pos_x') 
     120        y = mesk.config.getint(mesk.CONFIG_UI, 'main_window_pos_y') 
    103121 
    104122        self.window.resize(width, height) 
     
    107125    ### Window event callbacks ### 
    108126    def _on_window_delete(self, widget, event): 
    109         if mesk.config.getboolean(mesk.UI, 'window_hide_on_close'): 
     127        if mesk.config.getboolean(mesk.CONFIG_UI, 'window_hide_on_close'): 
    110128            self.window.hide() 
    111129            return True 
     
    137155 
    138156            # Restore compact window position 
    139             x = mesk.config.getint(mesk.UI, 'compact_main_window_pos_x') 
    140             y = mesk.config.getint(mesk.UI, 'compact_main_window_pos_y') 
     157            x = mesk.config.getint(mesk.CONFIG_UI, 'compact_main_window_pos_x') 
     158            y = mesk.config.getint(mesk.CONFIG_UI, 'compact_main_window_pos_y') 
    141159            self.window.move(x, y) 
    142160        else: 
     
    149167 
    150168        self._is_compact = state 
    151         mesk.config.set(mesk.UI, 'compact_state', str(state)) 
     169        mesk.config.set(mesk.CONFIG_UI, 'compact_state', str(state)) 
    152170 
    153171    def _on_open_menuitem_activate(self, widget): 
  • trunk/src/mesk/__init__.py

    r42 r51  
    3030MESK_DIR = os.path.expandvars('${HOME}/.%s' % APP_NAME.lower()) 
    3131PLAYLISTS_DIR = "%s/playlists" 
     32 
    3233GLADE_XML = 'mesk_gui.glade' 
    3334 
    3435# Sections 
    35 MAIN = 'mesk' 
    36 UI = 'ui' 
    37 AUDIO = 'audio' 
    38 PLAYLISTS = 'playlists
     36CONFIG_MAIN    = 'mesk' 
     37CONFIG_UI      = 'ui' 
     38CONFIG_AUDIO    = 'audio' 
     39CONFIG_PLAYLIST = 'playlist
    3940 
    4041# GST sinks 
     
    4344GST_ESD  = 'esd' 
    4445 
     46DEFAULT_PLAYLIST_NAME = 'mesk' 
     47DEFAULT_PLAYLIST_URI = 'file://%s/%s' % (PLAYLISTS_DIR, DEFAULT_PLAYLIST_NAME) 
     48 
    4549# Program options 
    4650# section: {opt_name: [type, default, enum_choices, help_string]} 
    4751options = { 
    48     MAIN: { 
     52    CONFIG_MAIN: { 
    4953    'version': [str, APP_VERSION, None, _('Application version')], 
     54    'playlists': [str, DEFAULT_PLAYLIST_NAME, None, 
     55                  _('A list of playlists (separated by \';\') that refer to ' 
     56                    'a playlist config section below')] 
    5057    }, 
    5158 
    52     UI: { 
     59    CONFIG_UI: { 
    5360    'compact_state': [bool, True, None, _('Start in compact view mode')], 
    5461    'window_hide_on_close': [bool, False, None, 
     
    6673    }, 
    6774 
    68     AUDIO: { 
     75    CONFIG_AUDIO: { 
    6976    'gst_sink': [str, GST_ALSA, None, 
    7077                 _("GStreamer output sink. May be '%s', '%s', '%s'") % \ 
     
    7481    }, 
    7582 
    76     PLAYLISTS: { 
    77     '%s' % APP_NAME: [str, '%s/%s.m3u' % (MESK_DIR, APP_NAME), None, 
    78                       _('Default playlist')] 
     83    CONFIG_PLAYLIST + '.' + DEFAULT_PLAYLIST_NAME: { 
     84    'uri': [str, DEFAULT_PLAYLIST_URI, None, _('Playlist (file) location')], 
     85    'auto-open': [bool, True, None, _('Open on startup')], 
     86    'current': [int, 0, None, _('Starting playlist index')], 
     87    'repeat': [bool, False, None, _('Is the playlist in repeat mode')], 
     88    'shuffle': [bool, False, None, _('Is the playlist in shuffle mode')], 
    7989    }, 
    8090} 
  • trunk/src/mesk/audio_source.py

    r28 r51  
    3333class FileAudioSource(AudioSource): 
    3434    def __init__(self, file_path): 
    35         # Hack for gstreamer, which does not like real uris for local files 
    36         if file_path.find('file://') == 0: 
    37             file_path = file_path.split('file://')[1] 
    3835        AudioSource.__init__(self, file_path) 
    3936 
  • trunk/src/mesk/common/config.py

    r31 r51  
    6161                else: 
    6262                    # FIXME: Migrage configs 
     63                    if not self.has_section(sect): 
     64                        self.add_section(sect) 
    6365                    self.set(sect, opt, val) 
    6466 
  • trunk/src/mesk/playlist.py

    r50 r51  
    2020import sys, os.path 
    2121import random 
     22 
    2223import audio_source 
     24import utils 
    2325 
    2426def load(pl_source): 
    2527    pl = Playlist() 
    2628    if os.path.splitext(pl_source)[1] == '.m3u': 
     29        pl_source = utils.strip_file_uri(pl_source) 
    2730        if not os.path.exists(pl_source): 
    2831            fp = file(pl_source, 'w') 
  • trunk/src/mesk/utils.py

    r50 r51  
    2020#  $Id$ 
    2121################################################################################ 
    22  
    23 import gtk, pango 
    2422 
    2523import common.i18n 
     
    6563    return tstr 
    6664 
    67 # This function was ripped from Gajim (http://www.gajim.org) 
    68 def get_default_font(): 
    69     '''Get the desktop setting for application font 
    70     first check for GNOME, then XFCE and last KDE 
    71     it returns None on failure or else a string 'Font Size' ''' 
    72          
    73     # Gnome/gconf 
    74     try: 
    75         import gconf 
    76         # in try because daemon may not be there 
    77         client = gconf.client_get_default() 
    78  
    79         return client.get_string('/desktop/gnome/interface/font_name') 
    80     except: 
    81         pass 
    82  
    83     # try to get xfce default font 
    84     # Xfce 4.2 adopts freedesktop.org's Base Directory Specification 
    85     # see http://www.xfce.org/~benny/xfce/file-locations.html 
    86     # and http://freedesktop.org/Standards/basedir-spec 
    87     xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '') 
    88     if xdg_config_home == '': 
    89         xdg_config_home = os.path.expanduser('~/.config') # default      
    90     xfce_config_file = os.path.join(xdg_config_home, 
    91                                     'xfce4/mcs_settings/gtk.xml') 
    92      
    93     # KDE 
    94     kde_config_file = os.path.expanduser('~/.kde/share/config/kdeglobals') 
    95      
    96     if os.path.exists(xfce_config_file): 
    97         try: 
    98             for line in file(xfce_config_file): 
    99                 if line.find('name="Gtk/FontName"') != -1: 
    100                     start = line.find('value="') + 7 
    101                     return line[start:line.find('"', start)] 
    102         except: 
    103             #we talk about file 
    104             print >> sys.stderr, \ 
    105                      _('Error: cannot open %s for reading') % xfce_config_file 
    106     elif os.path.exists(kde_config_file): 
    107         try: 
    108             for line in file(kde_config_file): 
    109                 if line.find('font=') == 0: # font=Verdana,9,other_numbers 
    110                     start = 5 # 5 is len('font=') 
    111                     line = line[start:] 
    112                     values = line.split(',') 
    113                     font_name = values[0] 
    114                     font_size = values[1] 
    115                     font_string = '%s %s' % (font_name, font_size) # Verdana 9 
    116                     return font_string 
    117         except: 
    118              #we talk about file 
    119              print >> sys.stderr, \ 
    120                       _('Error: cannot open %s for reading') % kde_config_file 
    121      
    122     return 'Sans 10' 
     65def strip_file_uri(uri): 
     66    file_path = uri 
     67    if uri.find('file://') == 0: 
     68        file_path = uri.split('file://')[1] 
     69    return file_path 
  • trunk/src/playlist_control.py

    r48 r51  
    2626_ = mesk.common.i18n._ 
    2727 
     28import gtk_utils, config 
     29 
    2830# Data model: 
    2931(COL_STATUS_IMG, 
     
    3436class PlaylistControl(gobject.GObject): 
    3537 
    36     def __init__(self, name, playlist, audio_control): 
     38    def __init__(self, name, audio_control): 
    3739        self.name = name 
     40 
    3841        self._is_active = False 
    3942        self._playlist = None 
     
    97100        self._pl_view.append_column(col) 
    98101 
     102        # Load playlist 
     103        self._pl_config = config.PlaylistConfig(self.name) 
     104        pl = mesk.playlist.load(self._pl_config.uri) 
     105        pl.set_shuffle(self._pl_config.shuffle) 
     106        pl.set_repeat(self._pl_config.repeat) 
     107        pl.set_curr_index(self._pl_config.current - 1) 
     108 
    99109        # Fill playlist model 
    100         self.set_playlist(playlist
     110        self.set_playlist(pl
    101111 
    102112        self._pl_view.set_model(self._pl_model) 
     
    129139 
    130140        shuffled = self._playlist.is_shuffled() 
     141        repeating = self._playlist.is_repeating() 
    131142        self.widget_xml.get_widget('shuffle_checkbutton').set_active(shuffled) 
     143        self.widget_xml.get_widget('repeat_checkbutton').set_active(repeating) 
    132144 
    133145        self._update_playlist_stats() 
     
    326338        self._txt_renderer = gtk.CellRendererText() 
    327339        # Make text font slightly smaller 
    328         font = mesk.utils.get_default_font() 
     340        font = gtk_utils.get_default_font() 
    329341        font_desc = pango.FontDescription(font) 
    330342        # 1024 pango units per device unit, subtract 2 points