# Path: src/controllers/utils.py
# def registerContext(func):
#     @functools.wraps(func)
#     def wrapper(*args, **kwargs):
#         self = args[0]
#         if hasattr(self, '__contextName__'):
#             contexts.update({self.__contextName__: self})
#         func(*args, **kwargs)
# 
#     return wrapper


import os
import sys
import copy
import json
import requests
import urllib
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, QThreadPool, QRunnable
from PyQt5.QtGui import QImage
from log import logger
from .utils import registerContext
from dwidgets import dthread, CoverRunnable
from config.constants import ArtistCoverPath, AlbumCoverPath, SongCoverPath, OnlineSongCoverPath
from deepin_utils.file import get_parent_dir
                    f.write(r.content)
                self.worker.download360SongCoverSuccessed.emit(
                    self.artist, self.title, localUrl)
        except Exception, e:
            logger.error(e)


class CoverWorker(QObject):

    __contextName__ = "CoverWorker"

    downloadArtistCoverSuccessed = pyqtSignal('QString', 'QString')
    downloadAlbumCoverSuccessed = pyqtSignal('QString', 'QString', 'QString')
    download360SongCoverSuccessed = pyqtSignal('QString', 'QString', 'QString')

    updateArtistCover = pyqtSignal('QString', 'QString')
    updateAlbumCover = pyqtSignal('QString', 'QString', 'QString')
    updateOnlineSongCover = pyqtSignal('QString', 'QString', 'QString')

    defaultArtistCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
    defaultAlbumCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
    defaultSongCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
    defaultFolderCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'folder-music.svg')

    albumCoverThreadPool = QThreadPool()


# Path: src/controllers/utils.py
# def registerContext(func):
#     @functools.wraps(func)
#     def wrapper(*args, **kwargs):
#         self = args[0]
#         if hasattr(self, '__contextName__'):
#             contexts.update({self.__contextName__: self})
#         func(*args, **kwargs)
# 
#     return wrapper


# Path: src/controllers/coverworker.py
import os
import sys
import copy
import json
import requests
import urllib
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, QThreadPool, QRunnable
from PyQt5.QtGui import QImage
from log import logger
from .utils import registerContext
from dwidgets import dthread, CoverRunnable
from config.constants import ArtistCoverPath, AlbumCoverPath, SongCoverPath, OnlineSongCoverPath
from deepin_utils.file import get_parent_dir

                    f.write(r.content)
                self.worker.download360SongCoverSuccessed.emit(
                    self.artist, self.title, localUrl)
        except Exception, e:
            logger.error(e)


class CoverWorker(QObject):

    __contextName__ = "CoverWorker"

    downloadArtistCoverSuccessed = pyqtSignal('QString', 'QString')
    downloadAlbumCoverSuccessed = pyqtSignal('QString', 'QString', 'QString')
    download360SongCoverSuccessed = pyqtSignal('QString', 'QString', 'QString')

    updateArtistCover = pyqtSignal('QString', 'QString')
    updateAlbumCover = pyqtSignal('QString', 'QString', 'QString')
    updateOnlineSongCover = pyqtSignal('QString', 'QString', 'QString')

    defaultArtistCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
    defaultAlbumCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
    defaultSongCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
    defaultFolderCover = os.path.join(
        get_parent_dir(__file__, 2), 'skin', 'images', 'folder-music.svg')

    albumCoverThreadPool = QThreadPool()


    @registerContext