Ejemplo n.º 1
0
    def init_menu(self):
        menubar = self.menuBar()

        file_menu = menubar.addMenu("&File")

        setting_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_FileDialogListView), t("Settings"),
            self)
        setting_action.setShortcut("Ctrl+S")
        setting_action.triggered.connect(self.show_setting)

        exit_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_DialogCancelButton), t("Exit"), self)
        exit_action.setShortcut(QtGui.QKeySequence("Ctrl+Q"))
        exit_action.setStatusTip(t("Exit application"))
        exit_action.triggered.connect(self.close)

        file_menu.addAction(setting_action)
        file_menu.addSeparator()
        file_menu.addAction(exit_action)

        profile_menu = menubar.addMenu(t("Profiles"))
        new_profile_action = QtWidgets.QAction(t("New Profile"), self)
        new_profile_action.triggered.connect(self.new_profile)

        show_profile_action = QtWidgets.QAction(t("Current Profile Settings"),
                                                self)
        show_profile_action.triggered.connect(self.show_profile)

        delete_profile_action = QtWidgets.QAction(t("Delete Current Profile"),
                                                  self)
        delete_profile_action.triggered.connect(self.delete_profile)
        profile_menu.addAction(new_profile_action)
        profile_menu.addAction(show_profile_action)
        profile_menu.addAction(delete_profile_action)

        about_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_FileDialogInfoView), t("About"), self)
        about_action.triggered.connect(self.show_about)

        changes_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_FileDialogDetailedView),
            t("View Changes"), self)
        changes_action.triggered.connect(self.show_changes)

        log_dir_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_DialogOpenButton),
            t("Open Log Directory"), self)
        log_dir_action.triggered.connect(self.show_log_dir)

        log_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_FileDialogDetailedView),
            t("View GUI Debug Logs"), self)
        log_action.triggered.connect(self.show_logs)

        report_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_DialogHelpButton), t("Report Issue"),
            self)
        report_action.triggered.connect(self.open_issues)

        version_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_BrowserReload),
            t("Check for Newer Version of FastFlix"), self)
        version_action.triggered.connect(
            lambda: latest_fastflix(no_new_dialog=True))

        ffmpeg_update_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_ArrowDown),
            t("Download Newest FFmpeg"), self)
        ffmpeg_update_action.triggered.connect(self.download_ffmpeg)

        clean_logs_action = QtWidgets.QAction(
            self.si(QtWidgets.QStyle.SP_DialogResetButton),
            t("Clean Old Logs"), self)
        clean_logs_action.triggered.connect(self.clean_old_logs)

        help_menu = menubar.addMenu(t("Help"))
        help_menu.addAction(changes_action)
        help_menu.addAction(report_action)
        help_menu.addAction(log_dir_action)
        help_menu.addAction(log_action)
        help_menu.addAction(clean_logs_action)
        help_menu.addSeparator()
        help_menu.addAction(version_action)
        if reusables.win_based:
            help_menu.addAction(ffmpeg_update_action)
        help_menu.addSeparator()
        help_menu.addAction(about_action)
Ejemplo n.º 2
0
    def init_menu(self):
        menubar = self.menuBar()

        file_menu = menubar.addMenu("&File")

        setting_action = QtWidgets.QAction(
            self.style().standardIcon(QtWidgets.QStyle.SP_FileDialogListView),
            "&Settings", self)
        setting_action.setShortcut("Ctrl+S")
        setting_action.triggered.connect(self.show_setting)

        exit_action = QtWidgets.QAction(
            self.style().standardIcon(QtWidgets.QStyle.SP_DialogCancelButton),
            "&Exit", self)
        exit_action.setShortcut(QtGui.QKeySequence("Ctrl+Q"))
        exit_action.setStatusTip("Exit application")
        exit_action.triggered.connect(self.close)

        file_menu.addAction(setting_action)
        file_menu.addSeparator()
        file_menu.addAction(exit_action)

        about_action = QtWidgets.QAction(
            self.style().standardIcon(QtWidgets.QStyle.SP_FileDialogInfoView),
            "&About", self)
        about_action.triggered.connect(self.show_about)

        changes_action = QtWidgets.QAction(
            self.style().standardIcon(
                QtWidgets.QStyle.SP_FileDialogDetailedView), "View &Changes",
            self)
        changes_action.triggered.connect(self.show_changes)

        log_dir_action = QtWidgets.QAction(
            self.style().standardIcon(QtWidgets.QStyle.SP_DialogOpenButton),
            "Open Log Directory", self)
        log_dir_action.triggered.connect(self.show_log_dir)

        log_action = QtWidgets.QAction(
            self.style().standardIcon(
                QtWidgets.QStyle.SP_FileDialogDetailedView),
            "View GUI Debug &Logs", self)
        log_action.triggered.connect(self.show_logs)

        report_action = QtWidgets.QAction(
            self.style().standardIcon(QtWidgets.QStyle.SP_DialogHelpButton),
            "Report &Issue", self)
        report_action.triggered.connect(self.open_issues)

        version_action = QtWidgets.QAction(
            self.style().standardIcon(QtWidgets.QStyle.SP_BrowserReload),
            "Check for Newer Version of FastFlix", self)
        version_action.triggered.connect(
            lambda: latest_fastflix(no_new_dialog=True))

        help_menu = menubar.addMenu("&Help")
        help_menu.addAction(changes_action)
        help_menu.addAction(report_action)
        help_menu.addAction(log_dir_action)
        help_menu.addAction(log_action)
        help_menu.addSeparator()
        help_menu.addAction(version_action)
        help_menu.addSeparator()
        help_menu.addAction(about_action)
Ejemplo n.º 3
0
def required_info(logger, data_path, log_dir):
    if reusables.win_based:
        # This fixes the taskbar icon not always appearing
        try:
            import ctypes

            app_id = f"cdgriffith.fastflix.{__version__}".encode("utf-8")
            ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
                app_id)
        except Exception:
            logger.exception(
                "Could not set application ID for Windows, please raise issue in github with above error"
            )

    ffmpeg_folder = Path(user_data_dir("FFmpeg", appauthor=False,
                                       roaming=True))
    ffmpeg = shutil.which("ffmpeg")
    if ffmpeg:
        ffmpeg = Path(ffmpeg).resolve()
    ffprobe = shutil.which("ffprobe")
    if ffprobe:
        ffprobe = Path(ffprobe).resolve()

    if ffmpeg_folder.exists():
        for file in ffmpeg_folder.iterdir():
            if file.is_file() and file.name.lower() in ("ffmpeg",
                                                        "ffmpeg.exe"):
                ffmpeg = file
            if file.is_file() and file.name.lower() in ("ffprobe",
                                                        "ffprobe.exe"):
                ffprobe = file
        if (not ffmpeg or not ffprobe) and (ffmpeg_folder / "bin").exists():
            for file in (ffmpeg_folder / "bin").iterdir():
                if file.is_file() and file.name.lower() in ("ffmpeg",
                                                            "ffmpeg.exe"):
                    ffmpeg = file
                if file.is_file() and file.name.lower() in ("ffprobe",
                                                            "ffprobe.exe"):
                    ffprobe = file

    logger.addHandler(
        logging.FileHandler(log_dir / f"flix_gui_{file_date()}.log",
                            encoding="utf-8"))

    config_file = Path(data_path, "fastflix.json")
    logger.debug(f'Using config file "{config_file}"')
    if not config_file.exists():
        config = Box({
            "version": __version__,
            "work_dir": str(data_path),
            "disable_update_check": False
        })
        config.to_json(filename=config_file, indent=2)
    else:
        try:
            config = Box.from_json(filename=config_file)
        except JSONDecodeError as err:
            logger.exception(f'Error with config file: "{config_file}"')
            error_message(
                msg=f"Bad config file: {config_file}"
                "<br> If you are unsure what to do, just delete the file"
                f"<br><br>Error: {err}",
                traceback=True,
            )
            sys.exit(1)
        if "version" not in config or "work_dir" not in config:
            message(
                "Config file does not have all required fields, adding defaults"
            )
            config.version = __version__
            config.work_dir = str(data_path)
            config.disable_update_check = False
            config.to_json(filename=config_file, indent=2)
        if StrictVersion(config.version) < StrictVersion(__version__):
            message(
                f"<h2 style='text-align: center;'>Welcome to FastFlix {__version__}!</h2><br>"
                f"<p style='text-align: center; font-size: 15px;'>Please check out the changes made since your last "
                f"update ({config.version})<br>View the change log in the Help menu (Alt+H then C)<br></p>"
            )
            config.version = __version__
            config.to_json(filename=config_file, indent=2)
        if "ffmpeg" in config:
            ffmpeg = Path(config.ffmpeg)
        if "ffprobe" in config:
            ffprobe = Path(config.ffprobe)
    work_dir = Path(config.get("work_dir", data_path))
    if not work_dir.exists():
        try:
            work_dir.mkdir(parents=True, exist_ok=True)
        except OSError as err:
            logger.error(f"Cannot use specified working directory {work_dir}"
                         f" - Falling back to {data_path} due to error: {err}")
            work_dir = data_path
            work_dir.mkdir(parents=True, exist_ok=True)

    if not ffmpeg or not ffprobe:
        qm = QtWidgets.QMessageBox
        if reusables.win_based:
            ret = qm.question(
                None,
                "FFmpeg not found!",
                f"<h2>FFmpeg not found!</h2> <br> Automatically download FFmpeg?",
                qm.Yes | qm.No,
            )
            if ret == qm.Yes:
                try:
                    windows_download_ffmpeg(ffmpeg_folder)
                except Exception as err:
                    logger.exception("Could not download FFmpeg")
                    sys.exit(2)
                else:
                    ffmpeg = ffmpeg_folder / "bin" / "ffmpeg.exe"
                    ffprobe = ffmpeg_folder / "bin" / "ffprobe.exe"
            else:
                sys.exit(1)
        else:
            qm.question(
                None,
                "FFmpeg not found!",
                "<h2>FFmpeg not found!</h2> "
                "Please <a href='https://ffmpeg.org/download.html'>download a static FFmpeg</a> and add it to PATH",
                qm.Close,
            )
            sys.exit(1)
    else:
        logger.info(f"Using FFmpeg {ffmpeg}")
        logger.info(f"Using FFprobe {ffprobe}")

    try:
        flix = Flix(ffmpeg=ffmpeg, ffprobe=ffprobe)
    except FlixError:
        error_message("FFmpeg or FFmpeg could not be executed properly!<br>",
                      traceback=True)
        sys.exit(1)

    if not config.get("disable_update_check"):
        latest_fastflix()

    return flix, work_dir, config_file