""" Contains the main kbtv application """ ## MODULE IMPORTS AND SEARCH PATH ######################################## import sys, os, time KBTV_MAINPATH = os.path.dirname(os.path.abspath(sys.argv[0])) if not KBTV_MAINPATH in sys.path: sys.path.append(KBTV_MAINPATH) import btcopyright, bthardware, btdriver, bt848, buildprefs if buildprefs.WITH_SAA: import saa if buildprefs.WITH_PWC: import pwc from qt import QObject, SIGNAL, SLOT, Qt, QSplashScreen, QPixmap from kdecore import KUniqueApplication, KCmdLineArgs, KAboutData, KGlobal, i18n from kdeui import KMessageBox from kbtv_dcop import KbtvDCOPExObj from kbtv_part import KbtvPart from kbtv_version import KBTV_VERSION, KBTV_VERSION_NUM, KBTV_UNIQUENAME, \ KBTV_DESCRIPTION, KBTV_FANCYNAME ## KBTV COPYRIGHT ######################################################## KBTV_AUTHOR = btcopyright.MY_NAME KBTV_AUTHOR_EMAIL = btcopyright.MY_EMAIL KBTV_COPYRIGHT = btcopyright.MY_COPYRIGHT KBTV_LICENSE = btcopyright.BSD_LICENSE KBTV_LICENSE_TEXT = btcopyright.BSD_LICENSE_TEXT ## CONSTANTS ############################################################# from kbtv_version import KBTV_VERSION, KBTV_VERSION_NUM, KBTV_UNIQUENAME, \ KBTV_DESCRIPTION, KBTV_FANCYNAME KBTV_SCREENSIZE_SMALL = (200, 150) KBTV_SCREENSIZE_MEDIUM = (400, 300) KBTV_SPLASHIMG = "kbtv_splash.png" ## BEGIN ################################################################# # About aboutdata = KAboutData(KBTV_UNIQUENAME, KBTV_FANCYNAME, KBTV_VERSION, KBTV_DESCRIPTION, KAboutData.License_BSD, KBTV_COPYRIGHT) aboutdata.addAuthor(KBTV_AUTHOR, "Author and maintainer", KBTV_AUTHOR_EMAIL) aboutdata.setBugAddress(KBTV_AUTHOR_EMAIL) KCmdLineArgs.init(sys.argv, aboutdata) # App app = KUniqueApplication(True, True, False) QObject.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) if not app.start(): print i18n("Kbtv is already running.") sys.exit() # Splash splash = QSplashScreen(QPixmap(KBTV_SPLASHIMG), Qt.WStyle_StaysOnTop) splash.show() # Permissions, group check splash.message(i18n("Check setup..."), Qt.AlignBottom, Qt.white) # Saa. If WITH_SAA check if module is loaded (required), then check access if buildprefs.WITH_SAA: btdriver.use_driver = "saa" if not bthardware.saa_module_loaded(): msg = i18n("To use saa, the kernel module must be loaded. ") msg += i18n("You can use the btsetup utility for this. ") msg += i18n("If you continue, bktr is used instead. ") ret = KMessageBox.warningContinueCancel(splash, msg, i18n("Warning")) if ret == KMessageBox.Cancel: sys.exit() else: btdriver.use_driver = "bt848" else: if not (bthardware.saa_access()[0] and bthardware.saa_access()[1] and bthardware.saa_access()[2]): msg = i18n("Wrong permissions and/or group membership. ") msg += i18n("You need to be a member of the operator group, ") msg += i18n("and the saa, sau and iic devices must be owned ") msg += i18n("by root:operator and have permissions 660. ") msg += i18n("You can use the btsetup utility for this. ") ret = KMessageBox.warningContinueCancel(splash, msg, i18n("Warning")) if ret == KMessageBox.Cancel: sys.exit() # Pwc (saa goes first, we start up with bt848 for technical reasons) elif buildprefs.WITH_PWC: if not bthardware.pwc_module_loaded(): msg = i18n("To use pwc, the kernel module must be loaded. ") msg += i18n("You can use the btsetup utility for this. ") ret = KMessageBox.warningContinueCancel(splash, msg, i18n("Warning")) if ret == KMessageBox.Cancel: sys.exit() else: if not bthardware.pwc_access(): msg = i18n("Wrong permissions and/or group membership. ") msg += i18n("You need to be a member of the operator group, ") msg += i18n("and the video device must be owned by") msg += i18n("root:operator and have permissions 660. ") msg += i18n("You can use the btsetup utility for this. ") ret = KMessageBox.warningContinueCancel(splash, msg, i18n("Warning")) if ret == KMessageBox.Cancel: sys.exit() btdriver.use_driver = "pwc" btdriver.pwc_fd = open(pwc.PWCDEV, "rw") # Bktr else: if not (bthardware.bktr_access()[0] and bthardware.bktr_access()[1]): msg = i18n("Wrong permissions and/or group membership. ") msg += i18n("You need to be a member of the operator group, ") msg += i18n("and the bktr and tuner devices must be owned ") msg += i18n("by root:operator and have permissions 660. ") msg += i18n("You can use the btsetup utility for this. ") ret = KMessageBox.warningContinueCancel(splash, msg, i18n("Warning")) if ret == KMessageBox.Cancel: sys.exit() # GUI (takes longest) splash.message(i18n("Init GUI..."), Qt.AlignBottom, Qt.white) mainwindow = KbtvPart() app.setMainWidget(mainwindow) # Minimum size (for backscaling) mainwindow.setFixedSize(KBTV_SCREENSIZE_SMALL[0], KBTV_SCREENSIZE_SMALL[1]) # DCOP exports dcopif = KbtvDCOPExObj(mainwindow, KBTV_FANCYNAME) # Set window ID in environment (for SDL embedding) os.environ["SDL_WINDOWID"] = str(mainwindow.centralWidget().winId()) # Main window/part splash.message(i18n("Init Viewer..."), Qt.AlignBottom, Qt.white) if mainwindow.initViewer(): mainwindow.startViewer() if btdriver.use_driver in ("saa", "bt848"): mainwindow.tuneTo(mainwindow.current) mainwindow.show() splash.finish(mainwindow) # Event loop app.exec_loop() # Mute, stop displaying if btdriver.use_driver == "bt848": bt848.tuner_audiosource_set(0x80) bt848.tuner_quit() bt848.viewer_quit() if btdriver.use_driver == "saa": try: saa.tuner_audiosource_set(0x80) saa.tuner_quit() saa.viewer_quit() except NameError: pass if btdriver.use_driver == "pwc": try: pwc.viewer_quit() if btdriver.pwc_fd: btdriver.pwc_fd.close() except NameError: pass ## END ###################################################################