def init(self): mountpoint = self.core_config.mountpoint_base_dir settings.set_value("global/mountpoint", str(mountpoint)) self.line_edit_mountpoint.setText(str(mountpoint)) mountpoint_enabled = settings.get_value("global/mountpoint_enabled", None) if os.name == "nt": settings.set_value("global/mountpoint_enabled", False) mountpoint_enabled = False self.checkbox_enable_mountpoint.setDisabled(True) elif mountpoint_enabled is None: settings.set_value("global/mountpoint_enabled", True) mountpoint_enabled = True self.button_choose_mountpoint.setDisabled(not mountpoint_enabled) self.checkbox_enable_mountpoint.setChecked( Qt.Checked if mountpoint_enabled else Qt.Unchecked) tray_enabled = settings.get_value("global/tray_enabled", None) if tray_enabled is None: settings.set_value("global/tray_enabled", True) tray_enabled = True self.checkbox_tray.setChecked( Qt.Checked if tray_enabled else Qt.Unchecked) current = None for lg, key in lang.LANGUAGES.items(): self.combo_languages.addItem(lg, key) if key == settings.get_value("global/language"): current = lg if current: self.combo_languages.setCurrentText(current)
def init(self): proxy_type = settings.get_value("network/proxy_type", None) if proxy_type is None: self.combo_proxy_type.setCurrentIndex(0) else: self.combo_proxy_type.setCurrentText(proxy_type) self.line_edit_proxy_host.setText( settings.get_value("network/proxy_host", "")) self.line_edit_proxy_port.setText( str(settings.get_value("network/proxy_port", 8080))) self.line_edit_proxy_username.setText( settings.get_value("network/proxy_username", "")) if self.combo_proxy_type.currentIndex() == 0: self.widget_proxy_info.setDisabled(True) if settings.get_value("network/upload_limit", -1) != -1: self.radio_upload_limit.setChecked(True) self.line_edit_upload_limit.setText( str(settings.get_value("network/upload_limit", 10))) if settings.get_value("network/download_limit", -1) != -1: self.radio_download_limit.setChecked(True) self.line_edit_download_limit.setText( str(settings.get_value("network/download_limit", 10))) if settings.get_value("network/simultaneous_connections", None): self.spin_sim_connections.setValue( settings.get_value("network/simultaneous_connections", 1))
def reset(self): self.line_edit_password.setText("") self.check_box_use_pkcs11.setCheckState(Qt.Unchecked) self.line_edit_password.setDisabled(False) self.line_edit_pkcs11_pin.setText("") self.combo_pkcs11_key.clear() self.combo_pkcs11_key.addItem("0") self.combo_pkcs11_token.clear() self.combo_pkcs11_token.addItem("0") self.widget_pkcs11.hide() devices = devices_manager.list_available_devices( self.core_config.config_dir) # Display devices in `<organization>:<device_id>` format self.devices = {f"{o}:{d}": (o, d, t) for o, d, t in devices} if len(self.devices) == 1: self.line_edit_device.setText(next(iter(self.devices))) self.line_edit_password.setFocus() elif len(self.devices) > 1: last_device = settings.get_value("last_device") if last_device and last_device in self.devices: self.line_edit_device.setText(last_device) self.line_edit_password.setFocus() else: self.line_edit_device.setFocus() else: self.line_edit_device.setText("") self.line_edit_device.setFocus() completer = QCompleter(self.devices.keys()) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setFilterMode(Qt.MatchContains) completer.popup().setStyleSheet( "border: 2px solid rgb(46, 145, 208); border-top: 0;") self.line_edit_device.setCompleter(completer)
def switch_language(lang_key=None): global _current_translator if not lang_key: lang_key = settings.get_value("global/language") if not lang_key: lang_key = get_locale_language() logger.info( "No language in settings, trying local language '{}'".format( lang_key)) if lang_key not in LANGUAGES.values(): lang_key = "en" logger.warning( "Language '{}' unavailable, defaulting to English".format( lang_key)) translator = QTranslator() path = ":/translations/translations/parsec_{}.qm".format(lang_key) if not translator.load(path): logger.warning( "Unable to load the translations for language '{}'".format( lang_key)) return False if not QCoreApplication.installTranslator(translator): logger.warning( "Failed to install the translator for language '{}'".format( lang_key)) return False QCoreApplication.removeTranslator(_current_translator) settings.set_value("global/language", lang_key) _current_translator = translator QCoreApplication.processEvents() return True
def closeEvent(self, event): if ( not settings.get_value("global/tray_enabled") or not QSystemTrayIcon.isSystemTrayAvailable() or self.close_requested or self.core_config.debug or self.force_close ): if not self.force_close: result = ask_question( self, QCoreApplication.translate(self.__class__.__name__, "Confirmation"), QCoreApplication.translate("MainWindow", "Are you sure you want to quit ?"), ) if not result: event.ignore() self.close_requested = False return event.accept() else: event.accept() if self.tray: self.tray.hide() self.stop_core() else: if self.tray and not self.tray_message_shown: self.tray.showMessage( "Parsec", QCoreApplication.translate("MainWindow", "Parsec is still running.") ) self.tray_message_shown = True event.ignore() self.hide()
def add_tray_icon(self): if not QSystemTrayIcon.isSystemTrayAvailable() or not settings.get_value( "global/tray_enabled", "true" ): return self.tray = QSystemTrayIcon(self) menu = QMenu() action = menu.addAction(QCoreApplication.translate(self.__class__.__name__, "Show window")) action.triggered.connect(self.show_top) action = menu.addAction(QCoreApplication.translate(self.__class__.__name__, "Exit")) action.triggered.connect(self.close_app) self.tray.setContextMenu(menu) self.tray.setIcon(QIcon(":/icons/images/icons/parsec.png")) self.tray.activated.connect(self.tray_activated) self.tray.show()