mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-25 04:26:28 +00:00
ApolMainWindow: handle closing the policy
* Close all tabs when closing the policy * Close the policy if using the "open policy" action and policy load succeeds. * Warn the user the above actions will close analysis tabs (if any tabs are open) * Set analysis widgets to delete on close since widgets are not deleted by QTabWidget.clear() or .removeTab()
This commit is contained in:
parent
95ecdf492a
commit
807efb1e10
15
data/apol.ui
15
data/apol.ui
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<class>ApolMainWindow_ui</class>
|
||||
<widget class="QMainWindow" name="ApolMainWindow_ui">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -68,6 +68,7 @@
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="open_policy"/>
|
||||
<addaction name="close_policy_action"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="exit_apol"/>
|
||||
</widget>
|
||||
@ -204,13 +205,21 @@
|
||||
<string>Ctrl+W</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="close_policy_action">
|
||||
<property name="text">
|
||||
<string>Close Policy</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Close the current policy. Closes all analyses too.</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>exit_apol</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<receiver>ApolMainWindow_ui</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -85,6 +85,7 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
||||
|
||||
# connect signals
|
||||
self.open_policy.triggered.connect(self.select_policy)
|
||||
self.close_policy_action.triggered.connect(self.close_policy)
|
||||
self.open_permmap.triggered.connect(self.select_permmap)
|
||||
self.new_analysis.triggered.connect(self.choose_analysis)
|
||||
self.AnalysisTabs.tabCloseRequested.connect(self.close_tab)
|
||||
@ -105,10 +106,26 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
||||
self.setWindowTitle("apol")
|
||||
|
||||
def select_policy(self):
|
||||
old_policy = self._policy
|
||||
|
||||
if old_policy and self.AnalysisTabs.count() > 0:
|
||||
reply = QMessageBox.question(
|
||||
self, "Continue?",
|
||||
"Loading a policy will close all existing analyses. Continue?",
|
||||
QMessageBox.Yes | QMessageBox.No)
|
||||
|
||||
if reply == QMessageBox.No:
|
||||
return
|
||||
|
||||
filename = QFileDialog.getOpenFileName(self, "Open policy file", ".")[0]
|
||||
if filename:
|
||||
self.load_policy(filename)
|
||||
|
||||
if self._policy != old_policy:
|
||||
# policy loading succeeded, clear any
|
||||
# existing tabs
|
||||
self.AnalysisTabs.clear()
|
||||
|
||||
def load_policy(self, filename):
|
||||
try:
|
||||
self._policy = SELinuxPolicy(filename)
|
||||
@ -121,6 +138,20 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
||||
if self._permmap:
|
||||
self._permmap.map_policy(self._policy)
|
||||
|
||||
def close_policy(self):
|
||||
if self.AnalysisTabs.count() > 0:
|
||||
reply = QMessageBox.question(
|
||||
self, "Continue?",
|
||||
"Loading a policy will close all existing analyses. Continue?",
|
||||
QMessageBox.Yes | QMessageBox.No)
|
||||
|
||||
if reply == QMessageBox.No:
|
||||
return
|
||||
|
||||
self.AnalysisTabs.clear()
|
||||
self._policy = None
|
||||
self.update_window_title()
|
||||
|
||||
def select_permmap(self):
|
||||
filename = QFileDialog.getOpenFileName(self, "Open permission map file", ".")[0]
|
||||
if filename:
|
||||
@ -159,6 +190,7 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
||||
newtab.setObjectName(counted_name)
|
||||
|
||||
newanalysis = tabclass(newtab, self._policy, self._permmap)
|
||||
newanalysis.setAttribute(Qt.WA_DeleteOnClose)
|
||||
|
||||
# create a vertical layout in the tab, place the analysis ui inside.
|
||||
tabLayout = QVBoxLayout()
|
||||
@ -180,19 +212,21 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
||||
self.tab_editor.setFocus()
|
||||
|
||||
def close_active_tab(self):
|
||||
"""Close the active tab. This is called from the context menu."""
|
||||
index = self.AnalysisTabs.currentIndex()
|
||||
if index >= 0:
|
||||
self.close_tab(index)
|
||||
|
||||
def rename_active_tab(self):
|
||||
"""Rename the active tab."""
|
||||
index = self.AnalysisTabs.currentIndex()
|
||||
if index >= 0:
|
||||
self.tab_name_editor(index)
|
||||
|
||||
def close_tab(self, index):
|
||||
"""Close a tab specified by index."""
|
||||
widget = self.AnalysisTabs.widget(index)
|
||||
widget.close()
|
||||
widget.deleteLater()
|
||||
self.AnalysisTabs.removeTab(index)
|
||||
|
||||
def rename_tab(self):
|
||||
|
@ -377,7 +377,9 @@ class TERuleQueryTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
# if query is broad, show warning.
|
||||
if not any((self.query.source, self.query.target, self.query.tclass, self.query.perms,
|
||||
self.query.xperms, self.query.default, self.query.boolean)):
|
||||
self.query.xperms, self.query.default, self.query.boolean)) \
|
||||
and max_results > 1000:
|
||||
|
||||
reply = QMessageBox.question(
|
||||
self, "Continue?",
|
||||
"This is a broad query, estimated to return {0} results. Continue?".
|
||||
|
Loading…
Reference in New Issue
Block a user