# Path: subdownloader/client/gui/models/imdbSearchModel.py
# class ImdbSearchModel(QAbstractTableModel):
#     NB_COLS = 2
#     COL_IMDB_ID = 0
#     COL_NAME = 1
# 
#     def __init__(self, parent: QObject=None):
#         QAbstractTableModel.__init__(self, parent)
#         self._imdb_data = []
#         self._headers = None
# 
#     def set_imdb_data(self, imdb_data: Sequence[ImdbMovieMatch]) -> None:
#         self.beginResetModel()
#         self._imdb_data = list(imdb_data)
#         self.endResetModel()
# 
#     def rowCount(self, parent: QModelIndex=None) -> int:
#         return len(self._imdb_data)
# 
#     def columnCount(self, parent: QModelIndex=None) -> int:
#         return self.NB_COLS
# 
#     def data(self, index: QModelIndex, role=None) -> Optional[str]:
#         row, col = index.row(), index.column()
#         if role == Qt.DisplayRole:
#             imdb = self._imdb_data[row]
#             if col == self.COL_IMDB_ID:
#                 return imdb.imdb_id
#             else:  # if col == self.COL_NAME:
#                 return imdb.title_year
# 
#         return None
# 
#     def get_imdb_at_row(self, row: int) -> ImdbMovieMatch:
#         return self._imdb_data[row]
# 
#     def sort(self, column: int, order=Qt.AscendingOrder) -> None:
#         reverse = order is Qt.DescendingOrder
#         self.beginResetModel()
#         if column == self.COL_IMDB_ID:
#             def key(identity):
#                 return identity.get_imdb_identity().get_imdb_id()
#         else:
#             def key(identity):
#                 return identity.video_identity.get_name().lower()
#         self._imdb_data = sorted(self._imdb_data, key=key,
#                                  reverse=reverse)
#         self.endResetModel()
# 
#     def headerData(self, section: int, orientation: int, role=None) -> Optional[str]:
#         if role == Qt.DisplayRole:
#             if orientation == Qt.Horizontal:
#                 if section == self.COL_IMDB_ID:
#                     return _('Id')
#                 else:
#                     return _('Name')
#             else:
#                 return None
# 
# Path: subdownloader/provider/imdb.py
# class ImdbMovieMatch:
#     def __init__(self, imdb_id: str, title: str, year: Optional[int]):
#         self.imdb_id = imdb_id
#         self.title = title
#         self.year = year
# 
#     @property
#     def url(self) -> str:
#         return 'https://www.imdb.com/title/{}'.format(self.imdb_id)
# 
#     @property
#     def title_year(self) -> str:
#         return '{}{}'.format(self.title, ' ({})'.format(self.year) if self.year is not None else '')
# 
#     def serialize(self) -> str:
#         year_str = '' if self.year is None else str(self.year)
#         return '{},{},{}'.format(self.imdb_id, year_str, self.title)
# 
#     @classmethod
#     def deserialize(cls, data: str) -> Optional['ImdbMovieMatch']:
#         try:
#             [imdb_id, year_str, title] = data.split(',', 2)
#             year = int(year_str.strip()) if year_str else None
#             return cls(imdb_id.strip(), title.strip(), year)
#         except ValueError:
#             return None


from typing import Optional, Sequence
from subdownloader.client.gui.models.imdbSearchModel import ImdbSearchModel
from subdownloader.provider.imdb import ImdbMovieMatch
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt
from PyQt5.QtWidgets import QHeaderView, QTableView
# -*- coding: utf-8 -*-
# Copyright (c) 2019 SubDownloader Developers - See COPYING - GPLv3





class ImdbListView(QTableView):
    def __init__(self, parent=None):
        QTableView.__init__(self, parent)

# Path: subdownloader/client/gui/models/imdbSearchModel.py
# class ImdbSearchModel(QAbstractTableModel):
#     NB_COLS = 2
#     COL_IMDB_ID = 0
#     COL_NAME = 1
# 
#     def __init__(self, parent: QObject=None):
#         QAbstractTableModel.__init__(self, parent)
#         self._imdb_data = []
#         self._headers = None
# 
#     def set_imdb_data(self, imdb_data: Sequence[ImdbMovieMatch]) -> None:
#         self.beginResetModel()
#         self._imdb_data = list(imdb_data)
#         self.endResetModel()
# 
#     def rowCount(self, parent: QModelIndex=None) -> int:
#         return len(self._imdb_data)
# 
#     def columnCount(self, parent: QModelIndex=None) -> int:
#         return self.NB_COLS
# 
#     def data(self, index: QModelIndex, role=None) -> Optional[str]:
#         row, col = index.row(), index.column()
#         if role == Qt.DisplayRole:
#             imdb = self._imdb_data[row]
#             if col == self.COL_IMDB_ID:
#                 return imdb.imdb_id
#             else:  # if col == self.COL_NAME:
#                 return imdb.title_year
# 
#         return None
# 
#     def get_imdb_at_row(self, row: int) -> ImdbMovieMatch:
#         return self._imdb_data[row]
# 
#     def sort(self, column: int, order=Qt.AscendingOrder) -> None:
#         reverse = order is Qt.DescendingOrder
#         self.beginResetModel()
#         if column == self.COL_IMDB_ID:
#             def key(identity):
#                 return identity.get_imdb_identity().get_imdb_id()
#         else:
#             def key(identity):
#                 return identity.video_identity.get_name().lower()
#         self._imdb_data = sorted(self._imdb_data, key=key,
#                                  reverse=reverse)
#         self.endResetModel()
# 
#     def headerData(self, section: int, orientation: int, role=None) -> Optional[str]:
#         if role == Qt.DisplayRole:
#             if orientation == Qt.Horizontal:
#                 if section == self.COL_IMDB_ID:
#                     return _('Id')
#                 else:
#                     return _('Name')
#             else:
#                 return None
# 
# Path: subdownloader/provider/imdb.py
# class ImdbMovieMatch:
#     def __init__(self, imdb_id: str, title: str, year: Optional[int]):
#         self.imdb_id = imdb_id
#         self.title = title
#         self.year = year
# 
#     @property
#     def url(self) -> str:
#         return 'https://www.imdb.com/title/{}'.format(self.imdb_id)
# 
#     @property
#     def title_year(self) -> str:
#         return '{}{}'.format(self.title, ' ({})'.format(self.year) if self.year is not None else '')
# 
#     def serialize(self) -> str:
#         year_str = '' if self.year is None else str(self.year)
#         return '{},{},{}'.format(self.imdb_id, year_str, self.title)
# 
#     @classmethod
#     def deserialize(cls, data: str) -> Optional['ImdbMovieMatch']:
#         try:
#             [imdb_id, year_str, title] = data.split(',', 2)
#             year = int(year_str.strip()) if year_str else None
#             return cls(imdb_id.strip(), title.strip(), year)
#         except ValueError:
#             return None


# Path: subdownloader/client/gui/views/imdb.py
from typing import Optional, Sequence
from subdownloader.client.gui.models.imdbSearchModel import ImdbSearchModel
from subdownloader.provider.imdb import ImdbMovieMatch
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt
from PyQt5.QtWidgets import QHeaderView, QTableView

# -*- coding: utf-8 -*-
# Copyright (c) 2019 SubDownloader Developers - See COPYING - GPLv3





class ImdbListView(QTableView):
    def __init__(self, parent=None):
        QTableView.__init__(self, parent)

        self._imdb_model = ImdbSearchModel()