def okPushButtonPressed(self, button): self.persepolis_setting.beginGroup('settings') self.persepolis_setting.setValue('max-tries', self.tries_spinBox.value()) self.persepolis_setting.setValue('retry-wait', self.wait_spinBox.value()) self.persepolis_setting.setValue('timeout', self.time_out_spinBox.value()) self.persepolis_setting.setValue('connections', self.connections_spinBox.value()) self.persepolis_setting.setValue('rpc-port', self.rpc_port_spinbox.value()) self.persepolis_setting.setValue('download_path', self.download_folder_lineEdit.text()) self.persepolis_setting.setValue('download_path_temp', self.temp_download_lineEdit.text()) self.persepolis_setting.setValue('sound-volume', self.volume_dial.value()) self.persepolis_setting.setValue( 'notification', self.notification_comboBox.currentText()) self.persepolis_setting.setValue( 'wait-queue', self.wait_queue_time.text().split(':')) # change aria2_path if self.aria2_path_checkBox.isChecked(): self.persepolis_setting.setValue( 'settings/aria2_path', str(self.aria2_path_lineEdit.text())) # changing icons icons = self.icon_comboBox.currentText() self.persepolis_setting.setValue('icons', icons) if icons != self.current_icon: # it means icons changed for windows_list in [ self.parent.logwindow_list, self.parent.about_window_list, self.parent.addlinkwindows_list, self.parent.propertieswindows_list, self.parent.afterdownload_list, self.parent.text_queue_window_list, self.parent.progress_window_list, self.parent.plugin_queue_window_list ]: for window in windows_list: window.changeIcon(icons) self.parent.changeIcon(icons) # icons size icons_size = self.icons_size_comboBox.currentText() self.persepolis_setting.setValue('toolbar_icon_size', icons_size) icons_size = int(icons_size) self.parent.toolBar.setIconSize(QSize(icons_size, icons_size)) self.parent.toolBar2.setIconSize(QSize(icons_size, icons_size)) # style style = str(self.style_comboBox.currentText()) self.persepolis_setting.setValue('style', style) # language locale = str( self.lang_comboBox.itemData(self.lang_comboBox.currentIndex())) self.persepolis_setting.setValue('locale', locale) # color_scheme color_scheme = self.color_comboBox.currentText() self.persepolis_setting.setValue('color-scheme', color_scheme) # font and font size current_font = self.fontComboBox.currentFont() current_font = current_font.key() current_font = current_font.split(',') font = str(current_font[0]) self.persepolis_setting.setValue('font', font) font_size = self.font_size_spinBox.value() self.persepolis_setting.setValue('font-size', font_size) if self.font_checkBox.isChecked(): custom_font = 'yes' else: custom_font = 'no' self.persepolis_setting.setValue('custom-font', custom_font) # if user select qt notification >> enable_system_tray icon if self.persepolis_setting.value('notification') == 'QT notification': self.enable_system_tray_checkBox.setChecked(True) # start_persepolis_if_browser_executed_checkBox if self.start_persepolis_if_browser_executed_checkBox.isChecked(): self.persepolis_setting.setValue('browser-persepolis', 'yes') else: self.persepolis_setting.setValue('browser-persepolis', 'no') # hide_window_checkBox if self.hide_window_checkBox.isChecked(): self.persepolis_setting.setValue('hide-window', 'yes') else: self.persepolis_setting.setValue('hide-window', 'no') # enable_system_tray_checkBox if self.enable_system_tray_checkBox.isChecked(): self.persepolis_setting.setValue('tray-icon', 'yes') self.parent.system_tray_icon.show() self.parent.minimizeAction.setEnabled(True) self.parent.trayAction.setChecked(True) else: self.persepolis_setting.setValue('tray-icon', 'no') self.parent.system_tray_icon.hide() self.parent.minimizeAction.setEnabled(False) self.parent.trayAction.setChecked(False) # after_download_checkBox if self.after_download_checkBox.isChecked(): self.persepolis_setting.setValue('after-dialog', 'yes') else: self.persepolis_setting.setValue('after-dialog', 'no') # show_menubar_checkbox if self.show_menubar_checkbox.isChecked(): self.persepolis_setting.setValue('show-menubar', 'yes') self.parent.menubar.show() self.parent.toolBar2.hide() self.parent.showMenuBarAction.setChecked(True) else: self.persepolis_setting.setValue('show-menubar', 'no') self.parent.menubar.hide() self.parent.toolBar2.show() self.parent.showMenuBarAction.setChecked(False) # show_sidepanel_checkbox if self.show_sidepanel_checkbox.isChecked(): self.persepolis_setting.setValue('show-sidepanel', 'yes') self.parent.category_tree_qwidget.show() else: self.persepolis_setting.setValue('show-sidepanel', 'no') self.parent.category_tree_qwidget.hide() # show_progress_window_checkbox if self.show_progress_window_checkbox.isChecked(): self.persepolis_setting.setValue('show-progress', 'yes') else: self.persepolis_setting.setValue('show-progress', 'no') if self.startup_checkbox.isChecked(): self.persepolis_setting.setValue('startup', 'yes') if not (startup.checkstartup() ): # checking existence of Persepolis in system's startup startup.addstartup() # adding Persepolis to system's startup else: self.persepolis_setting.setValue('startup', 'no') if startup.checkstartup( ): # checking existence of Persepolis in system's startup startup.removestartup( ) # removing Persepolis from system's startup # keep_awake_checkBox if self.keep_awake_checkBox.isChecked(): self.persepolis_setting.setValue('awake', 'yes') self.parent.keep_awake_checkBox.setChecked(True) else: self.persepolis_setting.setValue('awake', 'no') self.parent.keep_awake_checkBox.setChecked(False) # this section creates temporary download folder and download folder and # download sub folders if they did not existed. download_path_temp = self.persepolis_setting.value( 'download_path_temp') download_path = self.persepolis_setting.value('download_path') folder_list = [download_path_temp, download_path] if self.subfolder_checkBox.isChecked(): self.persepolis_setting.setValue('subfolder', 'yes') for folder in [ 'Audios', 'Videos', 'Others', 'Documents', 'Compressed' ]: folder_list.append(os.path.join(download_path, folder)) else: self.persepolis_setting.setValue('subfolder', 'no') for folder in folder_list: osCommands.makeDirs(folder) if self.enable_notifications_checkBox.isChecked(): self.persepolis_setting.setValue('sound', 'yes') else: self.persepolis_setting.setValue('sound', 'no') # columns_tab if self.column0_checkBox.isChecked(): self.persepolis_setting.setValue('column0', 'yes') self.parent.download_table.setColumnHidden(0, False) if self.parent.download_table.isColumnHidden(0): self.parent.download_table.setColumnWidth(0, 100) else: self.persepolis_setting.setValue('column0', 'no') self.parent.download_table.setColumnHidden(0, True) if self.column1_checkBox.isChecked(): self.persepolis_setting.setValue('column1', 'yes') self.parent.download_table.setColumnHidden(1, False) if self.parent.download_table.isColumnHidden(1): self.parent.download_table.setColumnWidth(1, 100) else: self.persepolis_setting.setValue('column1', 'no') self.parent.download_table.setColumnHidden(1, True) if self.column2_checkBox.isChecked(): self.persepolis_setting.setValue('column2', 'yes') self.parent.download_table.setColumnHidden(2, False) if self.parent.download_table.isColumnHidden(2): self.parent.download_table.setColumnWidth(2, 100) else: self.persepolis_setting.setValue('column2', 'no') self.parent.download_table.setColumnHidden(2, True) if self.column3_checkBox.isChecked(): self.persepolis_setting.setValue('column3', 'yes') self.parent.download_table.setColumnHidden(3, False) if self.parent.download_table.isColumnHidden(3): self.parent.download_table.setColumnWidth(3, 100) else: self.persepolis_setting.setValue('column3', 'no') self.parent.download_table.setColumnHidden(3, True) if self.column4_checkBox.isChecked(): self.persepolis_setting.setValue('column4', 'yes') self.parent.download_table.setColumnHidden(4, False) if self.parent.download_table.isColumnHidden(4): self.parent.download_table.setColumnWidth(4, 100) else: self.persepolis_setting.setValue('column4', 'no') self.parent.download_table.setColumnHidden(4, True) if self.column5_checkBox.isChecked(): self.persepolis_setting.setValue('column5', 'yes') self.parent.download_table.setColumnHidden(5, False) if self.parent.download_table.isColumnHidden(5): self.parent.download_table.setColumnWidth(5, 100) else: self.persepolis_setting.setValue('column5', 'no') self.parent.download_table.setColumnHidden(5, True) if self.column6_checkBox.isChecked(): self.persepolis_setting.setValue('column6', 'yes') self.parent.download_table.setColumnHidden(6, False) if self.parent.download_table.isColumnHidden(6): self.parent.download_table.setColumnWidth(6, 100) else: self.persepolis_setting.setValue('column6', 'no') self.parent.download_table.setColumnHidden(6, True) if self.column7_checkBox.isChecked(): self.persepolis_setting.setValue('column7', 'yes') self.parent.download_table.setColumnHidden(7, False) if self.parent.download_table.isColumnHidden(7): self.parent.download_table.setColumnWidth(7, 100) else: self.persepolis_setting.setValue('column7', 'no') self.parent.download_table.setColumnHidden(7, True) if self.column10_checkBox.isChecked(): self.persepolis_setting.setValue('column10', 'yes') self.parent.download_table.setColumnHidden(10, False) if self.parent.download_table.isColumnHidden(10): self.parent.download_table.setColumnWidth(10, 100) else: self.persepolis_setting.setValue('column10', 'no') self.parent.download_table.setColumnHidden(10, True) if self.column11_checkBox.isChecked(): self.persepolis_setting.setValue('column11', 'yes') self.parent.download_table.setColumnHidden(11, False) if self.parent.download_table.isColumnHidden(11): self.parent.download_table.setColumnWidth(11, 100) else: self.persepolis_setting.setValue('column11', 'no') self.parent.download_table.setColumnHidden(11, True) if self.column12_checkBox.isChecked(): self.persepolis_setting.setValue('column12', 'yes') self.parent.download_table.setColumnHidden(12, False) if self.parent.download_table.isColumnHidden(12): self.parent.download_table.setColumnWidth(12, 100) else: self.persepolis_setting.setValue('column12', 'no') self.parent.download_table.setColumnHidden(12, True) # shortcuts # set new shortcuts i = 0 for qshortcut in self.qshortcuts_list: # set keys for QShortcut qshortcut.setKey(self.shortcuts_list[i]) i = i + 1 # video_finder self.persepolis_setting.setValue('video_finder/max_links', self.max_links_spinBox.value()) # saving value of persepolis_setting in second_key_value_dict. self.second_key_value_dict = {} for member in self.persepolis_setting.allKeys(): self.second_key_value_dict[member] = str( self.persepolis_setting.value(member)) # comparing first_key_value_dict with second_key_value_dict show_message_box = False for key in self.first_key_value_dict.keys(): if self.first_key_value_dict[key] != self.second_key_value_dict[ key]: if key in [ 'locale', 'aria2_path', 'download_path_temp', 'download_path', 'custom-font', 'rpc-port', 'max-tries', 'retry-wait', 'timeout', 'connections', 'style', 'font', 'font-size', 'color-scheme' ]: show_message_box = True # if any thing changed that needs restarting, then notify user about "Some changes take effect after restarting persepolis" if show_message_box: restart_messageBox = QMessageBox() restart_messageBox.setText( QCoreApplication.translate( "setting_src_ui_tr", '<b><center>Restart Persepolis Please!</center></b><br><center>Some changes take effect after restarting Persepolis</center>' )) restart_messageBox.setWindowTitle( QCoreApplication.translate("setting_src_ui_tr", 'Restart Persepolis!')) restart_messageBox.exec_() # applying changes self.persepolis_setting.endGroup() self.persepolis_setting.sync() self.close()
from persepolis.constants import BROWSER from persepolis.scripts import osCommands from persepolis.scripts.browser_integration import browserIntegration from persepolis.scripts.useful_tools import determineConfigFolder, returnDefaultSettings # initialization # download manager config folder . config_folder = determineConfigFolder() # persepolis tmp folder path persepolis_tmp = os.path.join(config_folder, 'persepolis_tmp') # create folders for folder in [config_folder, persepolis_tmp]: osCommands.makeDirs(folder) # persepolisdm.log file contains persepolis log. from persepolis.scripts import logger # refresh logs! log_file = os.path.join(str(config_folder), 'persepolisdm.log') # get current time current_time = time.strftime('%Y/%m/%d %H:%M:%S') # find number of lines in log_file. with open(log_file) as f: lines = sum(1 for _ in f) # if number of lines in log_file is more than 300, then keep last 200 lines in log_file.
def browserIntegration(browser): # for GNU/Linux if os_type == OS.LINUX: # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == BROWSER.CHROMIUM: native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == BROWSER.CHROME: native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == BROWSER.FIREFOX: native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == BROWSER.VIVALDI: native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == BROWSER.OPERA: native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' elif browser == BROWSER.BRAVE: native_message_folder = home_address + \ '/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts' # for FreeBSD and OpenBSD elif os_type in OS.BSD_FAMILY: # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == BROWSER.CHROMIUM: native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == BROWSER.CHROME: native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == BROWSER.FIREFOX: native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == BROWSER.VIVALDI: native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == BROWSER.OPERA: native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' elif browser == BROWSER.BRAVE: native_message_folder = home_address + \ '/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts' # for Mac OSX elif os_type == OS.OSX: # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == BROWSER.CHROMIUM: native_message_folder = home_address + \ '/Library/Application Support/Chromium/NativeMessagingHosts' elif browser == BROWSER.CHROME: native_message_folder = home_address + \ '/Library/Application Support/Google/Chrome/NativeMessagingHosts' elif browser == BROWSER.FIREFOX: native_message_folder = home_address + \ '/Library/Application Support/Mozilla/NativeMessagingHosts' elif browser == BROWSER.VIVALDI: native_message_folder = home_address + \ '/Library/Application Support/Vivaldi/NativeMessagingHosts' elif browser == BROWSER.OPERA: native_message_folder = home_address + \ '/Library/Application Support/Opera/NativeMessagingHosts/' elif browser == BROWSER.BRAVE: native_message_folder = home_address + \ '/Library/Application Support/BraveSoftware/Brave-Browser/NativeMessagingHosts/' # for MicroSoft Windows os (windows 7 , ...) elif os_type == OS.WINDOWS: # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) exec_path = os.path.join(current_directory, 'Persepolis Download Manager.exe') # the execution path in json file for Windows must in form of # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2 # "\" in address exec_path = exec_path.replace('\\', r'\\') if browser in BROWSER.CHROME_FAMILY: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'chrome') else: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'firefox') # WebExtension native hosts file prototype webextension_json_connector = { "name": "com.persepolis.pdmchromewrapper", "type": "stdio", "path": str(exec_path), "description": "Integrate Persepolis with %s using WebExtensions" % (browser) } # Add chrom* keys if browser in BROWSER.CHROME_FAMILY: webextension_json_connector["allowed_origins"] = [ "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/" ] # Add firefox keys elif browser == BROWSER.FIREFOX: webextension_json_connector["allowed_extensions"] = [ "*****@*****.**", "*****@*****.**" ] # Build final path native_message_file = os.path.join(native_message_folder, 'com.persepolis.pdmchromewrapper.json') osCommands.makeDirs(native_message_folder) # Write NMH file f = open(native_message_file, 'w') f.write(str(webextension_json_connector).replace("'", "\"")) f.close() if os_type != OS.WINDOWS: pipe_json = subprocess.Popen( ['chmod', '+x', str(native_message_file)], stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False) if pipe_json.wait() == 0: json_done = True else: json_done = False else: native_done = None import winreg # add the key to the windows registry if browser in BROWSER.CHROME_FAMILY: try: # create pdmchromewrapper key under NativeMessagingHosts winreg.CreateKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper" ) # open a connection to pdmchromewrapper key gintKey = winreg.OpenKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(gintKey, '', 0, winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(gintKey) json_done = True except WindowsError: json_done = False elif browser == BROWSER.FIREFOX: try: # create pdmchromewrapper key under NativeMessagingHosts for firefox winreg.CreateKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper" ) # open a connection to pdmchromewrapper key for firefox fintKey = winreg.OpenKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(fintKey, '', 0, winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(fintKey) json_done = True except WindowsError: json_done = False # create persepolis_run_shell file for gnu/linux and BSD and Mac # firefox and chromium and ... call persepolis with Native Messaging system. # json file calls persepolis_run_shell file. if os_type in (OS.UNIX_LIKE + [OS.OSX]): # find available shell shell_list = [ '/bin/bash', '/usr/local/bin/bash', '/bin/sh', '/usr/local/bin/sh', '/bin/ksh', '/bin/tcsh' ] for shell in shell_list: if os.path.isfile(shell): # define shebang shebang = '#!' + shell break if os_type == OS.OSX: # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) persepolis_path = os.path.join(current_directory, 'Persepolis Download Manager') else: persepolis_path = 'persepolis' persepolis_run_shell_contents = shebang + '\n' + '"' + persepolis_path + '" "$@"' f = open(exec_path, 'w') f.writelines(persepolis_run_shell_contents) f.close() # make persepolis_run_shell executable pipe_native = subprocess.Popen(['chmod', '+x', exec_path], stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False) if pipe_native.wait() == 0: native_done = True else: native_done = False return json_done, native_done
def browserIntegration(browser): # for GNU/Linux if os_type == 'Linux': # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' # for FreeBSD and OpenBSD elif os_type == 'FreeBSD' or os_type == 'OpenBSD': # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' # for Mac OSX elif os_type == 'Darwin': # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + \ '/Library/Application Support/Chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/Library/Application Support/Google/Chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/Library/Application Support/Mozilla/NativeMessagingHosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/Library/Application Support/Vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/Library/Application Support/Opera/NativeMessagingHosts/' # for MicroSoft Windows os (windows 7 , ...) elif os_type == 'Windows': # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) exec_path = os.path.join( current_directory, 'Persepolis Download Manager.exe') # the execution path in jason file for Windows must in form of # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2 # "\" in address exec_path = exec_path.replace('\\', r'\\') if browser in ['chrome','chromium','opera','vivaldi']: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'chrome') else: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'firefox') # WebExtension native hosts file prototype webextension_json_connector = { "name": "com.persepolis.pdmchromewrapper", "type": "stdio", "path": str(exec_path), "description": "Integrate Persepolis with %s using WebExtensions" % (browser) } # Add chrom* keys if browser in ['chrome','chromium','opera','vivaldi']: webextension_json_connector["allowed_origins"] = [ "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/" ] # Add firefox keys elif browser == 'firefox': webextension_json_connector["allowed_extensions"] = [ "*****@*****.**", "*****@*****.**" ] # Build final path native_message_file = os.path.join( native_message_folder, 'com.persepolis.pdmchromewrapper.json') osCommands.makeDirs(native_message_folder) # Write NMH file f = open(native_message_file, 'w') f.write(str(webextension_json_connector).replace("'", "\"")) f.close() if os_type != 'Windows': os.system('chmod +x \"' + str(native_message_file) + '\"') else: import winreg # add the key to the windows registry if browser in ['chrome','chromium','opera','vivaldi']: try: # create pdmchromewrapper key under NativeMessagingHosts winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper") # open a connection to pdmchromewrapper key gintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(gintKey, '', 0,winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(gintKey) return True except WindowsError: return False elif browser == 'firefox': try: # create pdmchromewrapper key under NativeMessagingHosts for firefox winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper") # open a connection to pdmchromewrapper key for firefox fintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(fintKey, '', 0,winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(fintKey) return True except WindowsError: return False # create persepolis_run_shell file for gnu/linux and BSD and Mac # firefox and chromium and ... call persepolis with Native Messaging system. # json file calls persepolis_run_shell file. if os_type == 'Linux' or os_type == 'OpenBSD' or os_type == 'FreeBSD' or os_type == 'Darwin': # find available shell shell_list = ['/bin/bash', '/usr/local/bin/bash', '/bin/sh', '/usr/local/bin/sh', '/bin/ksh', '/bin/tcsh'] for shell in shell_list: if os.path.isfile(shell): # define shebang shebang = '#!' + shell break if os_type == 'Darwin': # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) persepolis_path = os.path.join( current_directory, 'Persepolis Download Manager') else: persepolis_path = 'persepolis' persepolis_run_shell_contents = shebang + '\n' + '"' + persepolis_path + '" "$@"' f = open(exec_path, 'w') f.writelines(persepolis_run_shell_contents) f.close() # make persepolis_run_shell executable os.system('chmod +x \"' + exec_path + '\"')
import subprocess import shutil import time import os # initialization # download manager config folder . config_folder = determineConfigFolder() # persepolis tmp folder path persepolis_tmp = os.path.join(config_folder, 'persepolis_tmp') # create folders for folder in [config_folder, persepolis_tmp]: osCommands.makeDirs(folder) # persepolisdm.log file contains persepolis log. from persepolis.scripts import logger # refresh logs! log_file = os.path.join(str(config_folder), 'persepolisdm.log') # get current time current_time = time.strftime('%Y/%m/%d %H:%M:%S') # find number of lines in log_file. with open(log_file) as f: lines = sum(1 for _ in f) # if number of lines in log_file is more than 300, then keep last 200 lines in log_file.
def okPushButtonPressed(self, button): self.persepolis_setting.beginGroup('settings') self.persepolis_setting.setValue('max-tries', self.tries_spinBox.value()) self.persepolis_setting.setValue('retry-wait', self.wait_spinBox.value()) self.persepolis_setting.setValue('timeout', self.time_out_spinBox.value()) self.persepolis_setting.setValue('connections', self.connections_spinBox.value()) self.persepolis_setting.setValue('rpc-port', self.rpc_port_spinbox.value()) self.persepolis_setting.setValue('download_path', self.download_folder_lineEdit.text()) self.persepolis_setting.setValue('download_path_temp', self.temp_download_lineEdit.text()) self.persepolis_setting.setValue('sound-volume', self.volume_dial.value()) self.persepolis_setting.setValue( 'notification', self.notification_comboBox.currentText()) # changing icons icons = self.icon_comboBox.currentText() self.persepolis_setting.setValue('icons', icons) if icons != self.current_icon: # it means icons changed for list in [ self.parent.browser_integration_window_list, self.parent.about_window_list, self.parent.addlinkwindows_list, self.parent.propertieswindows_list, self.parent.afterdownload_list, self.parent.text_queue_window_list, self.parent.progress_window_list ]: for window in list: window.changeIcon(icons) self.parent.changeIcon(icons) # style style = str(self.style_comboBox.currentText()) self.persepolis_setting.setValue('style', style) if style != self.grandparent.persepolis_style: # if style changed,then set new style self.grandparent.setPersepolisStyle(style) # color_scheme color_scheme = self.color_comboBox.currentText() self.persepolis_setting.setValue('color-scheme', color_scheme) # if color_scheme changed , then set new color_scheme if color_scheme != self.grandparent.persepolis_color_scheme: self.grandparent.setPersepolisColorScheme(color_scheme) # font and font size current_font = self.fontComboBox.currentFont() current_font = current_font.key() current_font = current_font.split(',') font = str(current_font[0]) self.persepolis_setting.setValue('font', font) font_size = self.font_size_spinBox.value() self.persepolis_setting.setValue('font-size', font_size) if self.font_checkBox.isChecked(): custom_font = 'yes' # if font or font_size changed,set new font , font_size if self.grandparent.persepolis_font != font or int( self.grandparent.persepolis_font_size) != int(font_size): self.grandparent.setPersepolisFont(font, int(font_size), custom_font) self.grandparent.setPersepolisStyle(style) self.grandparent.setPersepolisColorScheme(color_scheme) else: custom_font = 'no' self.persepolis_setting.setValue('custom-font', custom_font) # if user select qt notification >> enable_system_tray icon if self.persepolis_setting.value('notification') == 'QT notification': self.enable_system_tray_checkBox.setChecked(True) # enable_system_tray_checkBox if self.enable_system_tray_checkBox.isChecked() == True: self.persepolis_setting.setValue('tray-icon', 'yes') self.parent.system_tray_icon.show() self.parent.minimizeAction.setEnabled(True) self.parent.trayAction.setChecked(True) else: self.persepolis_setting.setValue('tray-icon', 'no') self.parent.system_tray_icon.hide() self.parent.minimizeAction.setEnabled(False) self.parent.trayAction.setChecked(False) # after_download_checkBox if self.after_download_checkBox.isChecked() == True: self.persepolis_setting.setValue('after-dialog', 'yes') else: self.persepolis_setting.setValue('after-dialog', 'no') # show_menubar_checkbox if self.show_menubar_checkbox.isChecked() == True: self.persepolis_setting.setValue('show-menubar', 'yes') self.parent.menubar.show() self.parent.toolBar2.hide() self.parent.showMenuBarAction.setChecked(True) else: self.persepolis_setting.setValue('show-menubar', 'no') self.parent.menubar.hide() self.parent.toolBar2.show() self.parent.showMenuBarAction.setChecked(False) # show_sidepanel_checkbox if self.show_sidepanel_checkbox.isChecked() == True: self.persepolis_setting.setValue('show_sidepanel', 'yes') self.parent.category_tree_qwidget.show() else: self.persepolis_setting.setValue('show_sidepanel', 'no') self.parent.category_tree_qwidget.hide() # show_progress_window_checkbox if self.show_progress_window_checkbox.isChecked() == True: self.persepolis_setting.setValue('show-progress', 'yes') else: self.persepolis_setting.setValue('show-progress', 'no') if self.startup_checkbox.isChecked() == True: self.persepolis_setting.setValue('startup', 'yes') if not (startup.checkstartup() ): # checking existance of Persepolis in system's startup startup.addstartup() # adding Persepolis to system's startup else: self.persepolis_setting.setValue('startup', 'no') if startup.checkstartup( ): # checking existance of Persepolis in system's startup startup.removestartup( ) # removing Persepolis from system's startup # keep_awake_checkBox if self.keep_awake_checkBox.isChecked(): self.persepolis_setting.setValue('awake', 'yes') self.parent.keep_awake_checkBox.setChecked(True) else: self.persepolis_setting.setValue('awake', 'no') self.parent.keep_awake_checkBox.setChecked(False) # this section creates temporary download folder and download folder and # download sub folders if they did not existed. download_path_temp = self.persepolis_setting.value( 'download_path_temp') download_path = self.persepolis_setting.value('download_path') folder_list = [download_path_temp, download_path] if self.subfolder_checkBox.isChecked(): self.persepolis_setting.setValue('subfolder', 'yes') for folder in [ 'Audios', 'Videos', 'Others', 'Documents', 'Compressed' ]: folder_list.append(os.path.join(download_path, folder)) else: self.persepolis_setting.setValue('subfolder', 'no') for folder in folder_list: osCommands.makeDirs(folder) if self.enable_notifications_checkBox.isChecked() == True: self.persepolis_setting.setValue('sound', 'yes') else: self.persepolis_setting.setValue('sound', 'no') # columns_tab if self.column0_checkBox.isChecked(): self.persepolis_setting.setValue('column0', 'yes') self.parent.download_table.setColumnHidden(0, False) if self.parent.download_table.isColumnHidden(0): self.parent.download_table.setColumnWidth(0, 100) else: self.persepolis_setting.setValue('column0', 'no') self.parent.download_table.setColumnHidden(0, True) if self.column1_checkBox.isChecked(): self.persepolis_setting.setValue('column1', 'yes') self.parent.download_table.setColumnHidden(1, False) if self.parent.download_table.isColumnHidden(1): self.parent.download_table.setColumnWidth(1, 100) else: self.persepolis_setting.setValue('column1', 'no') self.parent.download_table.setColumnHidden(1, True) if self.column2_checkBox.isChecked(): self.persepolis_setting.setValue('column2', 'yes') self.parent.download_table.setColumnHidden(2, False) if self.parent.download_table.isColumnHidden(2): self.parent.download_table.setColumnWidth(2, 100) else: self.persepolis_setting.setValue('column2', 'no') self.parent.download_table.setColumnHidden(2, True) if self.column3_checkBox.isChecked(): self.persepolis_setting.setValue('column3', 'yes') self.parent.download_table.setColumnHidden(3, False) if self.parent.download_table.isColumnHidden(3): self.parent.download_table.setColumnWidth(3, 100) else: self.persepolis_setting.setValue('column3', 'no') self.parent.download_table.setColumnHidden(3, True) if self.column4_checkBox.isChecked(): self.persepolis_setting.setValue('column4', 'yes') self.parent.download_table.setColumnHidden(4, False) if self.parent.download_table.isColumnHidden(4): self.parent.download_table.setColumnWidth(4, 100) else: self.persepolis_setting.setValue('column4', 'no') self.parent.download_table.setColumnHidden(4, True) if self.column5_checkBox.isChecked(): self.persepolis_setting.setValue('column5', 'yes') self.parent.download_table.setColumnHidden(5, False) if self.parent.download_table.isColumnHidden(5): self.parent.download_table.setColumnWidth(5, 100) else: self.persepolis_setting.setValue('column5', 'no') self.parent.download_table.setColumnHidden(5, True) if self.column6_checkBox.isChecked(): self.persepolis_setting.setValue('column6', 'yes') self.parent.download_table.setColumnHidden(6, False) if self.parent.download_table.isColumnHidden(6): self.parent.download_table.setColumnWidth(6, 100) else: self.persepolis_setting.setValue('column6', 'no') self.parent.download_table.setColumnHidden(6, True) if self.column7_checkBox.isChecked(): self.persepolis_setting.setValue('column7', 'yes') self.parent.download_table.setColumnHidden(7, False) if self.parent.download_table.isColumnHidden(7): self.parent.download_table.setColumnWidth(7, 100) else: self.persepolis_setting.setValue('column7', 'no') self.parent.download_table.setColumnHidden(7, True) if self.column10_checkBox.isChecked(): self.persepolis_setting.setValue('column10', 'yes') self.parent.download_table.setColumnHidden(10, False) if self.parent.download_table.isColumnHidden(10): self.parent.download_table.setColumnWidth(10, 100) else: self.persepolis_setting.setValue('column10', 'no') self.parent.download_table.setColumnHidden(10, True) if self.column11_checkBox.isChecked(): self.persepolis_setting.setValue('column11', 'yes') self.parent.download_table.setColumnHidden(11, False) if self.parent.download_table.isColumnHidden(11): self.parent.download_table.setColumnWidth(11, 100) else: self.persepolis_setting.setValue('column11', 'no') self.parent.download_table.setColumnHidden(11, True) if self.column12_checkBox.isChecked(): self.persepolis_setting.setValue('column12', 'yes') self.parent.download_table.setColumnHidden(12, False) if self.parent.download_table.isColumnHidden(12): self.parent.download_table.setColumnWidth(12, 100) else: self.persepolis_setting.setValue('column12', 'no') self.parent.download_table.setColumnHidden(12, True) # saving value of persepolis_setting in second_key_value_dict. self.second_key_value_dict = {} for member in self.persepolis_setting.allKeys(): self.second_key_value_dict[member] = str( self.persepolis_setting.value(member)) # comparing first_key_value_dict with second_key_value_dict # if any thing changed, then notify user about "Some changes take effect after restarting persepolis" if self.first_key_value_dict != self.second_key_value_dict: restart_messageBox = QMessageBox() restart_messageBox.setText( '<b>Some changes take effect after restarting persepolis</b>') restart_messageBox.setWindowTitle('Restart Persepolis!') restart_messageBox.exec_() # applying changes self.persepolis_setting.endGroup() self.persepolis_setting.sync() self.close()
def browserIntegration(browser): # for GNU/Linux if os_type == 'Linux': # persepolis execution path config_folder = os.path.join( str(home_address), ".config/persepolis_download_manager") exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' # for FreeBSD and OpenBSD elif os_type == 'FreeBSD' or os_type == 'OpenBSD': # persepolis execution path config_folder = os.path.join( str(home_address), ".config/persepolis_download_manager") exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' # for Mac OSX elif os_type == 'Darwin': # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) exec_path = os.path.join( current_directory, 'Persepolis Download Manager') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + \ '/Library/Application Support/Chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/Library/Application Support/Google/Chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/Library/Application Support/Mozilla/NativeMessagingHosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/Library/Application Support/Vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/Library/Application Support/Opera/NativeMessagingHosts/' # for MicroSoft Windows os (windows 7 , ...) elif os_type == 'Windows': # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) exec_path = os.path.join( current_directory, 'Persepolis Download Manager.exe') # the execution path in jason file for Windows must in form of # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2 # "\" in address exec_path = exec_path.replace('\\', r'\\') if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi': native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'chrome') else: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'firefox') # WebExtension native hosts file prototype webextension_json_connector = { "name": "com.persepolis.pdmchromewrapper", "type": "stdio", "path": str(exec_path), "description": "Integrate Persepolis with %s using WebExtensions" % (browser) } # Add chrom* keys if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi': webextension_json_connector["allowed_origins"] = [ "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/" ] # Add firefox keys elif browser == 'firefox': webextension_json_connector["allowed_extensions"] = [ "*****@*****.**", "*****@*****.**" ] # Build final path native_message_file = os.path.join( native_message_folder, 'com.persepolis.pdmchromewrapper.json') osCommands.makeDirs(native_message_folder) # Write NMH file f = open(native_message_file, 'w') f.write(str(webextension_json_connector).replace("'", "\"")) f.close() if os_type != 'Windows': os.system('chmod +x "' + str(native_message_file) + '"') else: import winreg # add the key to the windows registry if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi': try: # create pdmchromewrapper key under NativeMessagingHosts winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper") # open a connection to pdmchromewrapper key gintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(gintKey, '', 0,winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(gintKey) return True except WindowsError: return False elif browser == 'firefox': try: # create pdmchromewrapper key under NativeMessagingHosts for firefox winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper") # open a connection to pdmchromewrapper key for firefox fintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(fintKey, '', 0,winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(fintKey) return True except WindowsError: return False # browsers will call persepolis with persepolis_run_shell file in gnu/linux and bsd # creating persepolis_run_shell file for gnu/linux and bsd if os_type == 'Linux' or os_type == 'OpenBSD' or os_type == 'FreeBSD': # finding shell shell_list = ['/bin/bash', '/usr/local/bin/bash', '/bin/sh', '/usr/local/bin/sh', '/bin/ksh', '/bin/tcsh'] for shell in shell_list: if os.path.isfile(shell): # defining shebang shebang = '#!' + shell break persepolis_run_shell_contents = shebang + '\n' + 'persepolis "$@"' f = Open(exec_path, 'w') f.writelines(persepolis_run_shell_contents) f.close() # making persepolis_run_shell executable os.system('chmod +x ' + exec_path)
def okPushButtonPressed(self, button): self.persepolis_setting.beginGroup('settings') self.persepolis_setting.setValue( 'max-tries', self.tries_spinBox.value()) self.persepolis_setting.setValue( 'retry-wait', self.wait_spinBox.value()) self.persepolis_setting.setValue( 'timeout', self.time_out_spinBox.value()) self.persepolis_setting.setValue( 'connections', self.connections_spinBox.value()) self.persepolis_setting.setValue( 'rpc-port', self.rpc_port_spinbox.value()) self.persepolis_setting.setValue( 'download_path', self.download_folder_lineEdit.text()) self.persepolis_setting.setValue( 'download_path_temp', self.temp_download_lineEdit.text()) self.persepolis_setting.setValue( 'sound-volume', self.volume_dial.value()) self.persepolis_setting.setValue( 'notification', self.notification_comboBox.currentText()) self.persepolis_setting.setValue( 'wait-queue', self.wait_queue_time.text().split(':')) # change aria2_path if self.aria2_path_checkBox.isChecked(): self.persepolis_setting.setValue('settings/aria2_path', str(self.aria2_path_lineEdit.text())) # changing icons icons = self.icon_comboBox.currentText() self.persepolis_setting.setValue('icons', icons) if icons != self.current_icon: # it means icons changed for list in [self.parent.logwindow_list, self.parent.about_window_list, self.parent.addlinkwindows_list, self.parent.propertieswindows_list, self.parent.afterdownload_list, self.parent.text_queue_window_list, self.parent.progress_window_list]: for window in list: window.changeIcon(icons) self.parent.changeIcon(icons) # icons size icons_size = self.icons_size_comboBox.currentText() self.persepolis_setting.setValue('toolbar_icon_size', icons_size) icons_size = int(icons_size) self.parent.toolBar.setIconSize(QSize(icons_size, icons_size)) self.parent.toolBar2.setIconSize(QSize(icons_size, icons_size)) # style style = str(self.style_comboBox.currentText()) self.persepolis_setting.setValue('style', style) # language locale = str(self.lang_comboBox.itemData(self.lang_comboBox.currentIndex())) self.persepolis_setting.setValue('locale', locale) # color_scheme color_scheme = self.color_comboBox.currentText() self.persepolis_setting.setValue('color-scheme', color_scheme) # font and font size current_font = self.fontComboBox.currentFont() current_font = current_font.key() current_font = current_font.split(',') font = str(current_font[0]) self.persepolis_setting.setValue('font', font) font_size = self.font_size_spinBox.value() self.persepolis_setting.setValue('font-size', font_size) if self.font_checkBox.isChecked(): custom_font = 'yes' else: custom_font = 'no' self.persepolis_setting.setValue('custom-font', custom_font) # if user select qt notification >> enable_system_tray icon if self.persepolis_setting.value('notification') == 'QT notification': self.enable_system_tray_checkBox.setChecked(True) # enable_system_tray_checkBox if self.enable_system_tray_checkBox.isChecked(): self.persepolis_setting.setValue('tray-icon', 'yes') self.parent.system_tray_icon.show() self.parent.minimizeAction.setEnabled(True) self.parent.trayAction.setChecked(True) else: self.persepolis_setting.setValue('tray-icon', 'no') self.parent.system_tray_icon.hide() self.parent.minimizeAction.setEnabled(False) self.parent.trayAction.setChecked(False) # after_download_checkBox if self.after_download_checkBox.isChecked(): self.persepolis_setting.setValue('after-dialog', 'yes') else: self.persepolis_setting.setValue('after-dialog', 'no') # show_menubar_checkbox if self.show_menubar_checkbox.isChecked(): self.persepolis_setting.setValue('show-menubar', 'yes') self.parent.menubar.show() self.parent.toolBar2.hide() self.parent.showMenuBarAction.setChecked(True) else: self.persepolis_setting.setValue('show-menubar', 'no') self.parent.menubar.hide() self.parent.toolBar2.show() self.parent.showMenuBarAction.setChecked(False) # show_sidepanel_checkbox if self.show_sidepanel_checkbox.isChecked(): self.persepolis_setting.setValue('show-sidepanel', 'yes') self.parent.category_tree_qwidget.show() else: self.persepolis_setting.setValue('show-sidepanel', 'no') self.parent.category_tree_qwidget.hide() # show_progress_window_checkbox if self.show_progress_window_checkbox.isChecked(): self.persepolis_setting.setValue('show-progress', 'yes') else: self.persepolis_setting.setValue('show-progress', 'no') if self.startup_checkbox.isChecked(): self.persepolis_setting.setValue('startup', 'yes') if not(startup.checkstartup()): # checking existance of Persepolis in system's startup startup.addstartup() # adding Persepolis to system's startup else: self.persepolis_setting.setValue('startup', 'no') if startup.checkstartup(): # checking existance of Persepolis in system's startup startup.removestartup() # removing Persepolis from system's startup # keep_awake_checkBox if self.keep_awake_checkBox.isChecked(): self.persepolis_setting.setValue('awake', 'yes') self.parent.keep_awake_checkBox.setChecked(True) else: self.persepolis_setting.setValue('awake', 'no') self.parent.keep_awake_checkBox.setChecked(False) # this section creates temporary download folder and download folder and # download sub folders if they did not existed. download_path_temp = self.persepolis_setting.value( 'download_path_temp') download_path = self.persepolis_setting.value('download_path') folder_list = [download_path_temp, download_path] if self.subfolder_checkBox.isChecked(): self.persepolis_setting.setValue('subfolder', 'yes') for folder in ['Audios', 'Videos', 'Others', 'Documents', 'Compressed']: folder_list.append(os.path.join(download_path, folder)) else: self.persepolis_setting.setValue('subfolder', 'no') for folder in folder_list: osCommands.makeDirs(folder) if self.enable_notifications_checkBox.isChecked(): self.persepolis_setting.setValue('sound', 'yes') else: self.persepolis_setting.setValue('sound', 'no') # columns_tab if self.column0_checkBox.isChecked(): self.persepolis_setting.setValue('column0', 'yes') self.parent.download_table.setColumnHidden(0, False) if self.parent.download_table.isColumnHidden(0): self.parent.download_table.setColumnWidth(0, 100) else: self.persepolis_setting.setValue('column0', 'no') self.parent.download_table.setColumnHidden(0, True) if self.column1_checkBox.isChecked(): self.persepolis_setting.setValue('column1', 'yes') self.parent.download_table.setColumnHidden(1, False) if self.parent.download_table.isColumnHidden(1): self.parent.download_table.setColumnWidth(1, 100) else: self.persepolis_setting.setValue('column1', 'no') self.parent.download_table.setColumnHidden(1, True) if self.column2_checkBox.isChecked(): self.persepolis_setting.setValue('column2', 'yes') self.parent.download_table.setColumnHidden(2, False) if self.parent.download_table.isColumnHidden(2): self.parent.download_table.setColumnWidth(2, 100) else: self.persepolis_setting.setValue('column2', 'no') self.parent.download_table.setColumnHidden(2, True) if self.column3_checkBox.isChecked(): self.persepolis_setting.setValue('column3', 'yes') self.parent.download_table.setColumnHidden(3, False) if self.parent.download_table.isColumnHidden(3): self.parent.download_table.setColumnWidth(3, 100) else: self.persepolis_setting.setValue('column3', 'no') self.parent.download_table.setColumnHidden(3, True) if self.column4_checkBox.isChecked(): self.persepolis_setting.setValue('column4', 'yes') self.parent.download_table.setColumnHidden(4, False) if self.parent.download_table.isColumnHidden(4): self.parent.download_table.setColumnWidth(4, 100) else: self.persepolis_setting.setValue('column4', 'no') self.parent.download_table.setColumnHidden(4, True) if self.column5_checkBox.isChecked(): self.persepolis_setting.setValue('column5', 'yes') self.parent.download_table.setColumnHidden(5, False) if self.parent.download_table.isColumnHidden(5): self.parent.download_table.setColumnWidth(5, 100) else: self.persepolis_setting.setValue('column5', 'no') self.parent.download_table.setColumnHidden(5, True) if self.column6_checkBox.isChecked(): self.persepolis_setting.setValue('column6', 'yes') self.parent.download_table.setColumnHidden(6, False) if self.parent.download_table.isColumnHidden(6): self.parent.download_table.setColumnWidth(6, 100) else: self.persepolis_setting.setValue('column6', 'no') self.parent.download_table.setColumnHidden(6, True) if self.column7_checkBox.isChecked(): self.persepolis_setting.setValue('column7', 'yes') self.parent.download_table.setColumnHidden(7, False) if self.parent.download_table.isColumnHidden(7): self.parent.download_table.setColumnWidth(7, 100) else: self.persepolis_setting.setValue('column7', 'no') self.parent.download_table.setColumnHidden(7, True) if self.column10_checkBox.isChecked(): self.persepolis_setting.setValue('column10', 'yes') self.parent.download_table.setColumnHidden(10, False) if self.parent.download_table.isColumnHidden(10): self.parent.download_table.setColumnWidth(10, 100) else: self.persepolis_setting.setValue('column10', 'no') self.parent.download_table.setColumnHidden(10, True) if self.column11_checkBox.isChecked(): self.persepolis_setting.setValue('column11', 'yes') self.parent.download_table.setColumnHidden(11, False) if self.parent.download_table.isColumnHidden(11): self.parent.download_table.setColumnWidth(11, 100) else: self.persepolis_setting.setValue('column11', 'no') self.parent.download_table.setColumnHidden(11, True) if self.column12_checkBox.isChecked(): self.persepolis_setting.setValue('column12', 'yes') self.parent.download_table.setColumnHidden(12, False) if self.parent.download_table.isColumnHidden(12): self.parent.download_table.setColumnWidth(12, 100) else: self.persepolis_setting.setValue('column12', 'no') self.parent.download_table.setColumnHidden(12, True) # video_finder if self.enable_video_finder_checkbox.isChecked(): enable = 'yes' else: enable = 'no' if self.hide_no_audio_checkbox.isChecked(): hide_no_audio = 'yes' else: hide_no_audio = 'no' if self.hide_no_video_checkbox.isChecked(): hide_no_video = 'yes' else: hide_no_video = 'no' self.persepolis_setting.setValue('video_finder/enable', enable) self.persepolis_setting.setValue('video_finder/hide_no_audio', hide_no_audio) self.persepolis_setting.setValue('video_finder/hide_no_video', hide_no_video) self.persepolis_setting.setValue('video_finder/max_links', self.max_links_spinBox.value()) # saving value of persepolis_setting in second_key_value_dict. self.second_key_value_dict = {} for member in self.persepolis_setting.allKeys(): self.second_key_value_dict[member] = str(self.persepolis_setting.value(member)) # comparing first_key_value_dict with second_key_value_dict show_message_box = False for key in self.first_key_value_dict.keys(): if self.first_key_value_dict[key] != self.second_key_value_dict[key]: if key in ['locale', 'aria2_path', 'download_path_temp', 'download_path', 'custom-font', 'rpc-port', 'max-tries', 'retry-wait', 'timeout', 'connections', 'style', 'font', 'font-size', 'color-scheme']: show_message_box = True # if any thing changed that needs restarting, then notify user about "Some changes take effect after restarting persepolis" if show_message_box: restart_messageBox = QMessageBox() restart_messageBox.setText(QCoreApplication.translate("setting_src_ui_tr", '<b><center>Restart Persepolis Please!</center></b><br><center>Some changes take effect after restarting Persepolis</center>')) restart_messageBox.setWindowTitle(QCoreApplication.translate("setting_src_ui_tr", 'Restart Persepolis!')) restart_messageBox.exec_() # applying changes self.persepolis_setting.endGroup() self.persepolis_setting.sync() self.close()