def on_action_add_activate(self, action): """Add a new group""" dialog = UIGroupDetail(self.ui.dialog_groups, self.model) if dialog.show(default_name='', title=_('Add new group'), treeiter=None) == Gtk.ResponseType.OK: os.mkdir(os.path.join(DIR_HOSTS, dialog.name)) self.model.add_data( GroupInfo(name=dialog.name, description=dialog.name)) debug.add_info(_('Added a new group "%s"') % dialog.name) dialog.destroy()
def on_action_add_activate(self, action): """Add a new group""" dialog = UIGroupDetail(self.ui.dialog_groups, self.model) if dialog.show(default_name='', title=_('Add new group'), treeiter=None) == Gtk.ResponseType.OK: os.mkdir(os.path.join(DIR_HOSTS, dialog.name)) self.model.add_data(GroupInfo(name=dialog.name, description=dialog.name)) debug.add_info(_('Added a new group "%s"') % dialog.name) dialog.destroy()
def reload_hosts(self): """Load hosts from the settings files""" self.model_hosts.clear() self.hosts.clear() hosts_path = self.get_current_group_path() # Fix bug where the groups model isn't yet emptied, resulting in # being still used after a clear, then an invalid path if not os.path.isdir(hosts_path): return for filename in os.listdir(hosts_path): # Skip folders, used for groups if os.path.isdir(os.path.join(hosts_path, filename)): continue debug.add_info('Loading host %s' % os.path.join(hosts_path, filename)) settings_host = settings.Settings(filename=os.path.join( hosts_path, filename), case_sensitive=True) name = settings_host.get(SECTION_HOST, OPTION_HOST_NAME) description = settings_host.get(SECTION_HOST, OPTION_HOST_DESCRIPTION) host = HostInfo(name=name, description=description) destinations = {} # Load host destinations if SECTION_DESTINATIONS in settings_host.get_sections(): for option in settings_host.get_options(SECTION_DESTINATIONS): value = settings_host.get(SECTION_DESTINATIONS, option) destinations[option] = DestinationInfo(name=option, value=value) # Load associations association_index = 1 associations_count = settings_host.get_int( section=SECTION_HOST, option=OPTION_HOST_ASSOCIATIONS) while association_index <= associations_count: section = '%s %d' % (SECTION_ASSOCIATION, association_index) host.add_association( description=settings_host.get( section=section, option=OPTION_ASSOCIATION_DESCRIPTION), destination_name=settings_host.get( section=section, option=OPTION_ASSOCIATION_DESTINATION), service_name=settings_host.get( section=section, option=OPTION_ASSOCIATION_SERVICE), arguments=json.loads( settings_host.get( section=section, option=OPTION_ASSOCIATION_ARGUMENTS))) association_index += 1 self.add_host(host, destinations, False)
def on_action_remove_activate(self, action): """Remove the selected group""" selected_row = get_treeview_selected_row(self.ui.tvw_groups) group_name = self.model.get_key(selected_row) if selected_row else '' if selected_row and group_name and show_message_dialog( class_=UIMessageDialogNoYes, parent=self.ui.dialog_groups, message_type=Gtk.MessageType.WARNING, title=None, msg1=_('Remove the group'), msg2=_('Remove the group «%s»?') % group_name, is_response_id=Gtk.ResponseType.YES): group_path = os.path.join(DIR_HOSTS, group_name) # Check for directory not empty if len(os.listdir(group_path)) and not show_message_dialog( class_=UIMessageDialogNoYes, parent=self.ui.dialog_groups, message_type=Gtk.MessageType.WARNING, title=None, msg1=_('The group is not empty'), msg2='%s\n%s\n\n%s' % ( text('If you delete an item, it will ' 'be permanently lost.'), _('All the hosts defined for the group will be lost.'), _('Are you sure you want to delete the ' 'group «%s»?') % group_name, ), is_response_id=Gtk.ResponseType.YES): # Exit immediately without deleting the group return # Delete all the contained files and the directory for the group for filename in os.listdir(group_path): os.remove(os.path.join(group_path, filename)) os.rmdir(group_path) debug.add_info(_('Removed the group "%s"') % group_name) self.model.remove(selected_row)
def on_action_process_activate(self, action): """Execute an action for the selected process""" selected_row = get_treeview_selected_row(self.ui.tvw_processes) if selected_row: iter_parent = self.model.model.iter_parent(selected_row) selected_path = self.model.model[selected_row].path # Get the path of the process if iter_parent is None: tree_path = self.model.model[selected_row].path else: tree_path = self.model.model[iter_parent].path # selected_key = self.model.get_key(tree_path) if selected_key in self.processes: selected_process = self.processes[selected_key] treeiter = self.model.get_iter(selected_key) if action is self.ui.action_kill: # Resume the process and terminate it selected_process.send_signal(subprocess.signal.SIGCONT) selected_process.terminate() debug.add_info( _('The process with the PID %d was terminated') % ( selected_process.pid)) self.model.add_detail(treeiter, _('Process terminated'), 'media-playback-stop') elif action is self.ui.action_pause: # Pause the process by sending the STOP signal selected_process.send_signal(subprocess.signal.SIGSTOP) debug.add_info( _('The process with the PID %d was paused') % ( selected_process.pid)) self.model.add_detail(treeiter, _('Process paused'), 'media-playback-pause') elif action is self.ui.action_resume: # Pause the process by sending the CONT signal selected_process.send_signal(subprocess.signal.SIGCONT) debug.add_info( _('The process with the PID %d was resumed') % ( selected_process.pid)) self.model.add_detail(treeiter, _('Process resumed'), 'media-playback-start')