def load(self):        
     '''load songs and playlists from db file'''
     self.logdebug("Loading library...")
     
     # Load songs
     try:
         db_objs = utils.load_db(get_config_file("songs.db"))
     except:    
         self.logexception("Failed to load library")
         db_objs = []
         
     # Load playlists    
     try:    
         pls_objs = utils.load_db(get_config_file("playlists.db"))
     except:    
         self.logexception("Failed load playlists")
         pls_objs = []
         
         
     if db_objs:    
         for obj in db_objs:
             try:
                 song_type = obj["song_type"]
             except KeyError:    
                 self.logerror("Song with no type found, %s", obj.get("uri"))
                 
             if song_type not in self.__song_types:    
                 self.logwarn("Song type %s not exist, for registration", song_type)
                 self.register_type(song_type)
                 
             if self.__force_check:    
                 s = Song()
                 s.init_from_dict(obj)
                 s["uri"] = utils.realuri(s.get("uri"))
             else:    
                 s = Song(obj)
             s.set_type(song_type)    
             if not self.__force_check or not self.__songs.has_key(s.get("uri")):
                 self.add(s)
                 
     if pls_objs:            
         for pl_obj in pls_objs:            
             name, infos = pl_obj
             if self.__force_check:
                 infos = map(utils.realuri, infos)
             self.create_playlist("local", name, infos)    
     if self.__force_check:        
         self.save()
     self.__dirty = False    
     
     # fire signal
     self.__reset_queued_signal()
     gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save)
     gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal)
     
     self.logdebug("%s songs loaded in %s types", len(self.__songs), len(self.__song_types))
     self.logdebug("Finish loading library")
     gobject.idle_add(self.__delay_post_load)
 def save(self):                    
     if not self.collect_view.items:
         return
     items = []
     for item in self.collect_view.items:
         items.append(item.get_tags())
     utils.save_db(items, get_config_file("favorite_webcasts.db"))    
 def load(self):            
     ''' Load config items from the file. '''
     try:
         self._config.read(get_config_file(CONFIG_FILENAME))
         self._timeout_save()
     except:    
         pass
    def __init__(self, *args, **kwargs):
        TreeView.__init__(self, *args, **kwargs)
        targets = [
            ("text/deepin-radios", gtk.TARGET_SAME_APP, 1),
        ]
        self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
                           targets, gtk.gdk.ACTION_COPY)

        self.connect_after("drag-data-received", self.on_drag_data_received)
        self.connect("double-click-item", self.on_double_click_item)
        self.connect("button-press-event", self.on_button_press_event)
        self.connect("delete-select-items", self.try_emit_empty_signal)
        self.connect("right-press-items", self.on_right_press_items)

        Dispatcher.connect("play-radio", self.on_dispatcher_play_radio)
        Player.connect("play-end", self.on_play_end)

        self.lock = threading.Lock()

        self.current_index = 0
        self.playlist = []
        self.limit_number = 25
        self.preview_db_file = get_config_file("preview_radios.db")
        self.status_db_file = get_cache_file("musicfm/status.db")
        self.load_status()
 def save(self):    
     if not self.__dirty:
         return True
     
     # Quickly copy obj before pickle it
     self.__db_operation_lock.acquire()
     songs = self.__songs.values()
     playlists = self.__playlists["local"][:]
     self.__db_operation_lock.release()
     objs = [ song.get_dict() for song in songs if song.get_type() in self.__save_song_type ]
     
     # save
     utils.save_db(objs, get_config_file("songs.db"))
     utils.save_db([pl.get_pickle_obj() for pl in playlists ], get_config_file("playlists.db"))
     self.logdebug("%d songs saved and %d playlists saved", len(objs), len(playlists))
     self.__dirty = False
    def __init__(self, *args, **kwargs):
        TreeView.__init__(self, *args, **kwargs)
        targets = [
            ("text/deepin-radios", gtk.TARGET_SAME_APP, 1),
        ]
        self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
                           targets, gtk.gdk.ACTION_COPY)

        self.connect_after("drag-data-received", self.on_drag_data_received)
        self.connect("double-click-item", self.on_double_click_item)
        self.connect("button-press-event", self.on_button_press_event)
        self.connect("delete-select-items", self.try_emit_empty_signal)
        self.connect("right-press-items", self.on_right_press_items)

        Dispatcher.connect("play-radio", self.on_dispatcher_play_radio)
        Player.connect("play-end", self.on_play_end)

        self.lock = threading.Lock()

        self.current_index = 0
        self.playlist = []
        self.limit_number = 25
        self.preview_db_file = get_config_file("preview_radios.db")
        self.status_db_file = get_cache_file("musicfm/status.db")
        self.load_status()
Exemple #7
0
 def save(self):
     if not self.collect_view.items:
         return
     items = []
     for item in self.collect_view.items:
         items.append(item.get_tags())
     utils.save_db(items, get_config_file("favorite_webcasts.db"))
Exemple #8
0
    def __init__(self, session_bus, argv, dbus_name, dbus_path):
        dbus.service.Object.__init__(self, session_bus, dbus_path)

        (self.appid, self.game_name, self.width, self.height, self.swf_url,
         self.resizable) = argv
        self.game_name = urllib.unquote(self.game_name)
        self.width = int(self.width)
        self.height = int(self.height)
        self.plug_status = False
        self.conf_db = get_config_file("conf.db")
        self.p = None
        self.current_sink_index = None
        #self.sound_manager = SoundSetting(self.sound_sink_callback)
        self.loading = True
        self.hand_pause = False
        self.game_pause = False
        self.fullscreen_state = False
        self.guide_box_expand = True
        self.window_normal_info = {}
        self.maximize_state = False
        self.share_show = False

        self.call_flash_game(self.appid)
        self.init_ui()
        self.plug_id = None

        def unique(self):
            self.application.window.present()

        def message_receiver(self, *message):
            message_type, contents = message
            if message_type == 'send_plug_id':
                self.plug_id = int(str(contents[1]))
                self.content_page.add_plug_id(self.plug_id)
                self.plug_status = True
                self.start_loading()
            elif message_type == 'loading_uri_finish':
                fetch_service.add_missions([self.download_task])
            elif message_type == 'enter_bottom':
                if self.show_bottom:
                    self.paned_box.bottom_window.show()
            elif message_type == 'enter_top':
                if self.show_top:
                    self.paned_box.top_window.show()
            elif message_type == 'onload_loading':
                self.start_download_swf()
            elif message_type == 'game_action':
                if contents == 'pause':
                    self.command_pause_game()

        setattr(Player, 'unique', dbus.service.method(dbus_name)(unique))
        setattr(Player, 'message_receiver',
                dbus.service.method(dbus_name)(message_receiver))
        setattr(Player, 'update_signal',
                dbus.service.signal(dbus_name)(self.update_signal))

        self.send_message('get_plug_id', '')
Exemple #9
0
 def save(self):    
     if not self.__dirty:
         return True
     
     songs = []
     with self.keep_operation():
         songs = self.__songs.values()
         
     objs = [ song.get_dict() for song in songs if song not in self.__hiddens ]    
     utils.save_db(objs, get_config_file(self.__user_save_db))
     self.__dirty = False
 def save(self):    
     if not self.__dirty:
         return True
     
     songs = []
     with self.keep_operation():
         songs = self.__songs.values()
         
     objs = [ song.get_dict() for song in songs if song not in self.__hiddens ]    
     utils.save_db(objs, get_config_file(self.__user_save_db))
     self.__dirty = False
Exemple #11
0
    def save(self):
        if not self.__dirty:
            return True

        # Quickly copy obj before pickle it
        self.__db_operation_lock.acquire()
        songs = self.__songs.values()
        playlists = self.__playlists["local"][:]
        self.__db_operation_lock.release()
        objs = [
            song.get_dict() for song in songs
            if song.get_type() in self.__save_song_type
        ]

        # save
        utils.save_db(objs, get_config_file("songs.db"))
        utils.save_db([pl.get_pickle_obj() for pl in playlists],
                      get_config_file("playlists.db"))
        self.logdebug("%d songs saved and %d playlists saved", len(objs),
                      len(playlists))
        self.__dirty = False
 def __init__(self):
     TreeView.__init__(self, enable_drag_drop=False, enable_multiple_select=True)        
     
     self.connect("double-click-item", self.on_music_view_double_click)
     self.connect("press-return", self.on_music_view_press_return)
     
     event_manager.connect("add-songs", self.on_event_add_songs)
     event_manager.connect("play-songs", self.on_event_play_songs)
     
     self.db_file = get_config_file("baidumusic.db")
     self.load()
     
     self.request_thread_id = 0
    def __init__(self, *args, **kwargs):
        ListView.__init__(self, *args, **kwargs)
        targets = [("text/deepin-webcasts", gtk.TARGET_SAME_APP, 1),]
        self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP, targets, gtk.gdk.ACTION_COPY)

        self.connect_after("drag-data-received", self.on_drag_data_received)
        self.connect("single-click-item", self.__on_single_click_item)
        self.connect("double-click-item", self.on_double_click_item)
        self.connect("button-press-event", self.on_button_press_event)
        self.connect("delete-select-items", self.try_emit_empty_signal)
        self.connect("right-press-items", self.on_right_press_items)

        self.set_expand_column(1)
        Dispatcher.connect("play-webcast", self.on_dispatcher_play_webcast)
        Dispatcher.connect("add-webcasts", self.on_dispatcher_add_webcasts)
        self.limit_number = 25
        WebcastDB.connect("changed", self.on_db_update_songs)
        
        self.preview_db_file = get_config_file("preview_webcasts.db")
    def __init__(self):
        gtk.VBox.__init__(self)
        SignalContainer.__init__(self)

        # Init categorys.
        self.get_categorys()
        
        # load data.
        self.__load_webcast_query()
        
        # Init webcastbar.
        self.__init_webcastbar()
        
        # Init iconview.
        self.metro_view = self.get_icon_view()
        self.metro_view_sw = self.metro_view.get_scrolled_window()
        
        self.page_box = gtk.VBox()
        self.page_box.add(self.metro_view_sw)
        
        
        # webcasts view
        self.webcast_view = self.get_webcast_view()
        self.webcast_view_sw = self.webcast_view.get_scrolled_window()
        
        # collect view
        self.collected_db_file = get_config_file("favorite_webcasts.db")
        self.collected_view = self.get_webcast_view()
        self.collected_view_sw = self.collected_view.get_scrolled_window()
        
        # Init collect view.
        
        # init listview page.
        self.init_listview_page()
        Dispatcher.connect("change-webcast", self.on_dispatcher_change_webcast)
        WebcastDB.connect("changed", self.on_db_update_songs)
        
        body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True)
        body_paned.add1(self.webcastbar)
        body_paned.add2(self.page_box)
        self.add(body_paned)
    def __init__(self):
        gtk.VBox.__init__(self)
        SignalContainer.__init__(self)

        # Init categorys.
        self.get_categorys()

        # load data.
        self.__load_webcast_query()

        # Init webcastbar.
        self.__init_webcastbar()

        # Init iconview.
        self.metro_view = self.get_icon_view()
        self.metro_view_sw = self.metro_view.get_scrolled_window()

        self.page_box = gtk.VBox()
        self.page_box.add(self.metro_view_sw)

        # webcasts view
        self.webcast_view = self.get_webcast_view()
        self.webcast_view_sw = self.webcast_view.get_scrolled_window()

        # collect view
        self.collected_db_file = get_config_file("favorite_webcasts.db")
        self.collected_view = self.get_webcast_view()
        self.collected_view_sw = self.collected_view.get_scrolled_window()

        # Init collect view.

        # init listview page.
        self.init_listview_page()
        Dispatcher.connect("change-webcast", self.on_dispatcher_change_webcast)
        WebcastDB.connect("changed", self.on_db_update_songs)

        body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"),
                            enable_drag=True)
        body_paned.add1(self.webcastbar)
        body_paned.add2(self.page_box)
        self.add(body_paned)
 def __init__(self):
     gobject.GObject.__init__(self)
         
     # set condition lock.
     self.__condition = Condition()
     
     # set datebase operation lock.
     self.__db_operation_lock = Condition()
     
     # Manager webcasts.
     self.__hiddens = set()
     self.__songs = {}
     self.__type = "webcast"
     
     # init params.
     self.__is_loaded = False
     self.__dirty = False
     self.__reset_queued_signal()
     
     self.__user_save_db = get_config_file("all_webcasts.db")
     self.__default_db = DEFAULT_DB
Exemple #17
0
 def __init__(self):
     gobject.GObject.__init__(self)
         
     # set condition lock.
     self.__condition = Condition()
     
     # set datebase operation lock.
     self.__db_operation_lock = Condition()
     
     # Manager webcasts.
     self.__hiddens = set()
     self.__songs = {}
     self.__type = "webcast"
     
     # init params.
     self.__is_loaded = False
     self.__dirty = False
     self.__reset_queued_signal()
     
     self.__user_save_db = get_config_file("all_webcasts.db")
     self.__default_db = DEFAULT_DB
    def __init__(self, *args, **kwargs):
        ListView.__init__(self, *args, **kwargs)
        targets = [
            ("text/deepin-webcasts", gtk.TARGET_SAME_APP, 1),
        ]
        self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
                           targets, gtk.gdk.ACTION_COPY)

        self.connect_after("drag-data-received", self.on_drag_data_received)
        self.connect("single-click-item", self.__on_single_click_item)
        self.connect("double-click-item", self.on_double_click_item)
        self.connect("button-press-event", self.on_button_press_event)
        self.connect("delete-select-items", self.try_emit_empty_signal)
        self.connect("right-press-items", self.on_right_press_items)

        self.set_expand_column(1)
        Dispatcher.connect("play-webcast", self.on_dispatcher_play_webcast)
        Dispatcher.connect("add-webcasts", self.on_dispatcher_add_webcasts)
        self.limit_number = 25
        WebcastDB.connect("changed", self.on_db_update_songs)

        self.preview_db_file = get_config_file("preview_webcasts.db")
Exemple #19
0
 def load(self):
     ''' Load config items from the file. '''
     self._config.read(get_config_file(CONFIG_FILENAME))
Exemple #20
0
from deepin_utils.file import get_parent_dir
import gtk
import cPickle
import shutil
import fcntl
import threading as td
import urllib, urllib2
from constant import GAME_CENTER_SERVER_ADDRESS, PROGRAM_VERSION
from xdg_support import get_config_file
from nls import LANGUAGE

LOG_PATH = "/tmp/dgc-frontend.log"

dgc_root_dir = os.path.realpath(get_parent_dir(__file__, 2))

temp_db = get_config_file('temp.db')
def is_wizard_showed():
    if os.path.exists(temp_db):
        data = load_db(temp_db)
        if data.get('wizard'):
            return data['wizard'] == PROGRAM_VERSION
        else:
            return False

def set_wizard_showed():
    if os.path.exists(temp_db):
        data = load_db(temp_db)
        data['wizard'] = PROGRAM_VERSION
    else:
        data = dict(wizard=PROGRAM_VERSION)
 def write(self):    
     ''' write configure to file. '''
     filename = get_config_file(CONFIG_FILENAME)
     f = file(filename, "w")
     self._config.write(f)
     f.close()
Exemple #22
0
    def load(self):
        '''load songs and playlists from db file'''
        self.logdebug("Loading library...")

        # Load songs
        try:
            db_objs = utils.load_db(get_config_file("songs.db"))
        except:
            self.logexception("Failed to load library")
            db_objs = []

        # Load playlists
        try:
            pls_objs = utils.load_db(get_config_file("playlists.db"))
        except:
            self.logexception("Failed load playlists")
            pls_objs = []

        if db_objs:
            for obj in db_objs:
                try:
                    song_type = obj["song_type"]
                except KeyError:
                    self.logerror("Song with no type found, %s",
                                  obj.get("uri"))

                if song_type not in self.__song_types:
                    self.logwarn("Song type %s not exist, for registration",
                                 song_type)
                    self.register_type(song_type)

                if self.__force_check:
                    s = Song()
                    s.init_from_dict(obj)
                    s["uri"] = utils.realuri(s.get("uri"))
                else:
                    s = Song(obj)
                s.set_type(song_type)
                if not self.__force_check or not self.__songs.has_key(
                        s.get("uri")):
                    self.add(s)

        if pls_objs:
            for pl_obj in pls_objs:
                name, infos = pl_obj
                if self.__force_check:
                    infos = map(utils.realuri, infos)
                self.create_playlist("local", name, infos)
        if self.__force_check:
            self.save()
        self.__dirty = False

        # fire signal
        self.__reset_queued_signal()
        gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save)
        gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20,
                            self.__fire_queued_signal)

        self.logdebug("%s songs loaded in %s types", len(self.__songs),
                      len(self.__song_types))
        self.logdebug("Finish loading library")
        gobject.idle_add(self.__delay_post_load)
Exemple #23
0
    def __init__(self, session_bus, argv, dbus_name, dbus_path):
        dbus.service.Object.__init__(self, session_bus, dbus_path)

        (self.appid, self.game_name, self.width, self.height, self.swf_url, 
                self.resizable) = argv
        self.game_name = urllib.unquote(self.game_name)
        self.width = int(self.width)
        self.height = int(self.height)
        self.plug_status = False
        self.conf_db = get_config_file("conf.db")
        self.p = None
        self.current_sink_index = None
        #self.sound_manager = SoundSetting(self.sound_sink_callback)
        self.loading = True
        self.hand_pause = False
        self.game_pause = False
        self.fullscreen_state = False
        self.guide_box_expand = True
        self.window_normal_info = {}
        self.maximize_state = False
        self.share_show = False

        self.call_flash_game(self.appid)
        self.init_ui()
        self.plug_id = None

        def unique(self):
            self.application.window.present()

        def message_receiver(self, *message):
            message_type, contents = message
            if message_type == 'send_plug_id':
                self.plug_id = int(str(contents[1]))
                self.content_page.add_plug_id(self.plug_id)
                self.plug_status = True
                self.start_loading()
            elif message_type == 'loading_uri_finish':
                fetch_service.add_missions([self.download_task])
            elif message_type == 'enter_bottom':
                if self.show_bottom:
                    self.paned_box.bottom_window.show()
            elif message_type == 'enter_top':
                if self.show_top:
                    self.paned_box.top_window.show()
            elif message_type == 'onload_loading':
                self.start_download_swf()
            elif message_type == 'game_action':
                if contents == 'pause':
                    self.command_pause_game()

        setattr(Player, 
                'unique', 
                dbus.service.method(dbus_name)(unique))
        setattr(Player, 
                'message_receiver', 
                dbus.service.method(dbus_name)(message_receiver))
        setattr(Player,
                'update_signal',
                dbus.service.signal(dbus_name)(self.update_signal))

        self.send_message('get_plug_id', '')
 def load(self):            
     ''' Load config items from the file. '''
     self._config.read(get_config_file(CONFIG_FILENAME))
Exemple #25
0
 def write(self):
     ''' write configure to file. '''
     filename = get_config_file("config")
     f = file(filename, "w")
     self._config.write(f)
     f.close()
 def write(self):    
     ''' write configure to file. '''
     filename = get_config_file("config")
     f = file(filename, "w")
     self._config.write(f)
     f.close()
    def __init__(self, session_bus):
        dbus.service.Object.__init__(self, session_bus, GAME_CENTER_DBUS_PATH)
        self.conf_db = get_config_file("conf.db")
        self.in_wizard_showing = False

        self.init_ui()