diff --git a/weboob/applications/qcineoob/main_window.py b/weboob/applications/qcineoob/main_window.py
index 8a49e2e5..0be5c98e 100644
--- a/weboob/applications/qcineoob/main_window.py
+++ b/weboob/applications/qcineoob/main_window.py
@@ -23,18 +23,21 @@ from PyQt4.QtGui import QApplication
from weboob.capabilities.cinema import ICapCinema
from weboob.capabilities.torrent import ICapTorrent
+from weboob.capabilities.subtitle import ICapSubtitle
from weboob.tools.application.qt import QtMainWindow, QtDo
from weboob.tools.application.qt.backendcfg import BackendCfg
-
+from weboob.applications.suboob.suboob import LANGUAGE_CONV
from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow
from .minimovie import MiniMovie
from .miniperson import MiniPerson
from .minitorrent import MiniTorrent
+from .minisubtitle import MiniSubtitle
from .movie import Movie
from .person import Person
from .torrent import Torrent
+from .subtitle import Subtitle
class MainWindow(QtMainWindow):
def __init__(self, config, weboob, parent=None):
@@ -53,6 +56,7 @@ class MainWindow(QtMainWindow):
self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.search)
self.connect(self.ui.typeCombo, SIGNAL("returnPressed()"), self.search)
+ self.connect(self.ui.typeCombo, SIGNAL("currentIndexChanged(QString)"), self.typeComboChanged)
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
@@ -61,8 +65,14 @@ class MainWindow(QtMainWindow):
if self.ui.backendEdit.count() == 0:
self.backendsConfig()
+ langs = LANGUAGE_CONV.keys()
+ langs.sort()
+ for lang in langs:
+ self.ui.langCombo.addItem(lang)
+ self.ui.langCombo.hide()
+
def backendsConfig(self):
- bckndcfg = BackendCfg(self.weboob, (ICapCinema,ICapTorrent,), self)
+ bckndcfg = BackendCfg(self.weboob, (ICapCinema,ICapTorrent,ICapSubtitle,), self)
if bckndcfg.run():
self.loadBackendsList()
@@ -80,6 +90,12 @@ class MainWindow(QtMainWindow):
else:
self.ui.searchEdit.setEnabled(True)
+ def typeComboChanged(self,value):
+ if unicode(value) == 'subtitle':
+ self.ui.langCombo.show()
+ else:
+ self.ui.langCombo.hide()
+
def doAction(self, description, fun, args):
self.ui.currentActionLabel.setText(description)
if self.history['last_action'] != None:
@@ -140,6 +156,8 @@ class MainWindow(QtMainWindow):
self.searchMovie()
elif tosearch == 'torrent':
self.searchTorrent()
+ elif tosearch == 'subtitle':
+ self.searchSubtitle()
def searchMovie(self):
pattern = unicode(self.ui.searchEdit.text())
@@ -225,6 +243,7 @@ class MainWindow(QtMainWindow):
wperson = Person(person,self)
self.ui.info_content.layout().addWidget(wperson)
self.current_info_widget = wperson
+ QApplication.restoreOverrideCursor()
def searchTorrent(self):
pattern = unicode(self.ui.searchEdit.text())
@@ -268,6 +287,49 @@ class MainWindow(QtMainWindow):
self.ui.info_content.layout().addWidget(wtorrent)
self.current_info_widget = wtorrent
+ def searchSubtitle(self):
+ pattern = unicode(self.ui.searchEdit.text())
+ lang = unicode(self.ui.langCombo.currentText())
+ if not pattern:
+ return
+ self.doAction(u'Search subtitle "%s"'%pattern,self.searchSubtitleAction,[lang,pattern])
+
+ def searchSubtitleAction(self, lang, pattern):
+ self.ui.stackedWidget.setCurrentWidget(self.ui.list_page)
+ for mini in self.minis:
+ self.ui.list_content.layout().removeWidget(mini)
+ mini.hide()
+ mini.deleteLater()
+
+ self.minis = []
+ self.ui.searchEdit.setEnabled(False)
+ QApplication.setOverrideCursor( Qt.WaitCursor )
+
+ backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString())
+
+ self.process = QtDo(self.weboob, self.addSubtitle)
+ self.process.do('iter_subtitles', lang, pattern, backends=backend_name, caps=ICapSubtitle)
+
+ def addSubtitle(self, backend, subtitle):
+ if not backend:
+ self.ui.searchEdit.setEnabled(True)
+ QApplication.restoreOverrideCursor()
+ self.process = None
+ return
+ minisubtitle = MiniSubtitle(self.weboob, backend, subtitle, self)
+ self.ui.list_content.layout().addWidget(minisubtitle)
+ self.minis.append(minisubtitle)
+
+ def displaySubtitle(self, subtitle, backend):
+ self.ui.stackedWidget.setCurrentWidget(self.ui.info_page)
+ if self.current_info_widget != None:
+ self.ui.info_content.layout().removeWidget(self.current_info_widget)
+ self.current_info_widget.hide()
+ self.current_info_widget.deleteLater()
+ wsubtitle = Subtitle(subtitle, backend, self)
+ self.ui.info_content.layout().addWidget(wsubtitle)
+ self.current_info_widget = wsubtitle
+
def closeEvent(self, ev):
self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()))
self.config.save()
diff --git a/weboob/applications/qcineoob/miniperson.py b/weboob/applications/qcineoob/miniperson.py
index a59dcd1b..9937d25c 100644
--- a/weboob/applications/qcineoob/miniperson.py
+++ b/weboob/applications/qcineoob/miniperson.py
@@ -19,7 +19,8 @@
import urllib
-from PyQt4.QtGui import QFrame, QImage, QPixmap
+from PyQt4.QtGui import QFrame, QImage, QPixmap, QApplication
+from PyQt4.QtCore import Qt
from weboob.applications.qcineoob.ui.miniperson_ui import Ui_MiniPerson
from weboob.capabilities.base import NotAvailable
@@ -61,6 +62,7 @@ class MiniPerson(QFrame):
def mousePressEvent(self, event):
QFrame.mousePressEvent(self, event)
+ QApplication.setOverrideCursor( Qt.WaitCursor )
person = self.backend.get_person(self.person.id)
if person:
self.parent.doAction(u'Details of person "%s"'%person.name,self.parent.displayPerson,[person])
diff --git a/weboob/applications/qcineoob/minisubtitle.py b/weboob/applications/qcineoob/minisubtitle.py
new file mode 100644
index 00000000..33cf4054
--- /dev/null
+++ b/weboob/applications/qcineoob/minisubtitle.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010-2011 Romain Bignon
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+from PyQt4.QtGui import QFrame
+
+from weboob.applications.qcineoob.ui.minisubtitle_ui import Ui_MiniSubtitle
+from weboob.capabilities.base import NotAvailable
+
+class MiniSubtitle(QFrame):
+ def __init__(self, weboob, backend, subtitle, parent=None):
+ QFrame.__init__(self, parent)
+ self.parent = parent
+ self.ui = Ui_MiniSubtitle()
+ self.ui.setupUi(self)
+
+ self.weboob = weboob
+ self.backend = backend
+ self.subtitle = subtitle
+ self.ui.nameLabel.setText(subtitle.name)
+ if subtitle.nb_cd != NotAvailable:
+ self.ui.nbcdLabel.setText(u'%s'%subtitle.nb_cd)
+ self.ui.backendLabel.setText(backend.name)
+
+ def enterEvent(self, event):
+ self.setFrameShadow(self.Sunken)
+ QFrame.enterEvent(self, event)
+
+ def leaveEvent(self, event):
+ self.setFrameShadow(self.Raised)
+ QFrame.leaveEvent(self, event)
+
+ def mousePressEvent(self, event):
+ QFrame.mousePressEvent(self, event)
+
+ subtitle = self.backend.get_subtitle(self.subtitle.id)
+ if subtitle:
+ self.parent.doAction('Details of subtitle "%s"'%subtitle.name,self.parent.displaySubtitle,[subtitle,self.backend])
diff --git a/weboob/applications/qcineoob/qcineoob.py b/weboob/applications/qcineoob/qcineoob.py
index a1659c2b..8543d3c8 100644
--- a/weboob/applications/qcineoob/qcineoob.py
+++ b/weboob/applications/qcineoob/qcineoob.py
@@ -20,6 +20,7 @@
from weboob.capabilities.cinema import ICapCinema
from weboob.capabilities.torrent import ICapTorrent
+from weboob.capabilities.subtitle import ICapSubtitle
from weboob.tools.application.qt import QtApplication
from .main_window import MainWindow
@@ -31,7 +32,7 @@ class QCineoob(QtApplication):
COPYRIGHT = 'Copyright(C) 2010-2011 Romain Bignon'
DESCRIPTION = "Qt application allowing to search movies etc..."
SHORT_DESCRIPTION = "search movies"
- CAPS = ICapCinema,ICapTorrent
+ CAPS = ICapCinema,ICapTorrent,ICapSubtitle
CONFIG = {'settings': {'nsfw': 1,
'sfw': 1,
'sortby': 0,
@@ -39,7 +40,7 @@ class QCineoob(QtApplication):
}
}
def main(self, argv):
- self.load_backends([ICapCinema,ICapTorrent])
+ self.load_backends([ICapCinema,ICapTorrent,ICapSubtitle])
self.load_config()
self.main_window = MainWindow(self.config, self.weboob)
diff --git a/weboob/applications/qcineoob/subtitle.py b/weboob/applications/qcineoob/subtitle.py
new file mode 100644
index 00000000..5d46cf83
--- /dev/null
+++ b/weboob/applications/qcineoob/subtitle.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010-2011 Romain Bignon
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+import sys
+
+from PyQt4.QtCore import Qt,SIGNAL
+from PyQt4.QtGui import QFrame, QFileDialog
+
+from weboob.applications.qcineoob.ui.subtitle_ui import Ui_Subtitle
+from weboob.capabilities.base import NotAvailable, NotLoaded
+
+class Subtitle(QFrame):
+ def __init__(self, subtitle, backend, parent=None):
+ QFrame.__init__(self, parent)
+ self.parent = parent
+ self.backend = backend
+ self.ui = Ui_Subtitle()
+ self.ui.setupUi(self)
+
+ self.connect(self.ui.downloadButton, SIGNAL("clicked()"), self.download)
+
+ self.subtitle = subtitle
+ self.ui.nameLabel.setText(u'%s'%subtitle.name)
+ if subtitle.url != NotAvailable:
+ self.ui.urlEdit.setText(u'%s'%subtitle.url)
+
+ self.ui.verticalLayout.setAlignment(Qt.AlignTop)
+
+ def download(self):
+ fileDial = QFileDialog(self,'Save "%s" subtitle file'%self.subtitle.name,'%s'%self.subtitle.name,'all files (*)')
+ fileDial.setAcceptMode(QFileDialog.AcceptSave)
+ fileDial.setLabelText(QFileDialog.Accept,'Save subtitle file')
+ fileDial.setLabelText(QFileDialog.FileName,'Subtitle file name')
+ ok = (fileDial.exec_() == 1)
+ if not ok:
+ return
+ result = fileDial.selectedFiles()
+ if len(result) > 0:
+ dest = result[0]
+ data = self.backend.get_subtitle_file(self.subtitle.id)
+ try:
+ with open(dest, 'w') as f:
+ f.write(data)
+ except IOError, e:
+ print >>sys.stderr, 'Unable to write subtitle file in "%s": %s' % (dest, e)
+ return 1
+ return
+
diff --git a/weboob/applications/qcineoob/ui/main_window.ui b/weboob/applications/qcineoob/ui/main_window.ui
index 2b132e18..109ef933 100644
--- a/weboob/applications/qcineoob/ui/main_window.ui
+++ b/weboob/applications/qcineoob/ui/main_window.ui
@@ -57,8 +57,16 @@
torrent
+ -
+
+ subtitle
+
+
+ -
+
+
-
diff --git a/weboob/applications/qcineoob/ui/minisubtitle.ui b/weboob/applications/qcineoob/ui/minisubtitle.ui
new file mode 100644
index 00000000..0628218f
--- /dev/null
+++ b/weboob/applications/qcineoob/ui/minisubtitle.ui
@@ -0,0 +1,129 @@
+
+
+ MiniSubtitle
+
+
+
+ 0
+ 0
+ 464
+ 136
+
+
+
+ Form
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+ 9
+
+
+ 5
+
+
+ 5
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+ QFormLayout::ExpandingFieldsGrow
+
+
-
+
+
+
+ 75
+ true
+
+
+
+ Name
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 50
+ true
+ false
+
+
+
+ TextLabel
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Nb CD
+
+
+
+ -
+
+
+ TextLabel
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Where
+
+
+
+ -
+
+
+ TextLabel
+
+
+
+
+
+
+
+
+
+
diff --git a/weboob/applications/qcineoob/ui/subtitle.ui b/weboob/applications/qcineoob/ui/subtitle.ui
new file mode 100644
index 00000000..4e01bf60
--- /dev/null
+++ b/weboob/applications/qcineoob/ui/subtitle.ui
@@ -0,0 +1,218 @@
+
+
+ Subtitle
+
+
+
+ 0
+ 0
+ 629
+ 552
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 2000
+ 600
+
+
+
+ Frame
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+ -
+
+
+
+ 16777215
+ 600
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Download
+
+
+
+ -
+
+
+
+ 16777215
+ 35
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Name:
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 16777215
+ 35
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Size:
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 16777215
+ 200
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Description:
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+ 16777215
+ 200
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Files:
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+ 16777215
+ 40
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+ 3
+
+
+ 3
+
+
-
+
+
+ Url:
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+