1 # Copyright (c) 2010 Citrix Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from OVEStandard import *
16 from OVEConfig import *
17 from OVELogger import *
18 from Ui_ConfigWindow import *
20 from OVEHostWindow import *
22 class OVEConfigWindow(QtGui.QDialog):
23 def __init__(self, app):
24 QtGui.QDialog.__init__(self)
26 self.ui = Ui_ConfigWindow()
29 self.connect(self.ui.hostAddButton, QtCore.SIGNAL("clicked()"), self.xon_hostAddButton_clicked)
30 self.connect(self.ui.hostEditButton, QtCore.SIGNAL("clicked()"), self.xon_hostEditButton_clicked)
31 self.connect(self.ui.hostDeleteButton, QtCore.SIGNAL("clicked()"), self.xon_hostDeleteButton_clicked)
32 self.connect(self.ui.buttonBox, QtCore.SIGNAL("clicked(QAbstractButton *)"), self.xon_actionButton_Box_clicked)
33 self.connect(self.ui.hostList, QtCore.SIGNAL("currentItemChanged(QListWidgetItem *, QListWidgetItem *)"), self.xon_hostList_currentItemChanged)
34 self.connect(self.ui.logTrafficCheckBox, QtCore.SIGNAL("stateChanged(int)"), self.xon_logTrafficCheckBox_stateChanged)
35 self.connect(self.ui.truncateUuidsCheckBox, QtCore.SIGNAL("stateChanged(int)"), self.xon_truncateUuidsCheckBox_stateChanged)
39 def handleHostWindowRecord(self, record, isEdit):
40 if record['accepted'] and record['address'].strip() != '':
41 currentRow = self.ui.hostList.currentRow()
43 self.configHosts[currentRow] = record
45 self.configHosts.append(record)
49 def xon_hostAddButton_clicked(self):
50 hostWindow = OVEHostWindow(self)
52 self.handleHostWindowRecord(hostWindow.record(), False)
54 def xon_hostEditButton_clicked(self):
55 if self.ui.hostList.currentItem() is None:
56 pass # OVELog('No item to edit')
58 currentRow = self.ui.hostList.currentRow()
59 hostWindow = OVEHostWindow(self, self.configHosts[currentRow])
61 self.handleHostWindowRecord(hostWindow.record(), True)
63 def xon_hostDeleteButton_clicked(self):
64 if self.ui.hostList.currentItem() is not None:
65 currentRow = self.ui.hostList.currentRow()
66 del self.configHosts[currentRow]
69 def xon_actionButton_Box_clicked(self, button):
70 role = self.ui.buttonBox.buttonRole(button)
71 if role == QtGui.QDialogButtonBox.AcceptRole:
74 elif role == QtGui.QDialogButtonBox.ApplyRole:
76 elif role == QtGui.QDialogButtonBox.RejectRole:
77 if self.configChanged():
80 ret = QtGui.QMessageBox.warning(
81 self, "OVSDB Monitor",
82 "Changes not applied. Discard?",
83 QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Apply,
84 QtGui.QMessageBox.Discard)
86 if ret == QtGui.QMessageBox.Apply:
88 if ret != QtGui.QMessageBox.Cancel:
91 def xon_hostList_currentItemChanged(self, current, previous):
92 editable = (current is not None)
93 self.ui.hostEditButton.setEnabled(editable)
94 self.ui.hostDeleteButton.setEnabled(editable)
96 def xon_logTrafficCheckBox_stateChanged(self, value):
97 self.configLogTraffic = (value == Qt.Checked)
99 def xon_truncateUuidsCheckBox_stateChanged(self, value):
100 self.configTruncateUuids = (value == Qt.Checked)
102 def updateWidgets(self):
103 self.ui.hostList.clear()
104 for host in self.configHosts:
105 self.ui.hostList.addItem(host['address'])
106 self.ui.logTrafficCheckBox.setChecked(self.configLogTraffic)
107 self.ui.truncateUuidsCheckBox.setChecked(self.configTruncateUuids)
109 def configChanged(self):
111 (self.configHosts == OVEConfig.Inst().hosts) and
112 (self.configLogTraffic == (OVEConfig.Inst().logTraffic))and
113 (self.configTruncateUuids == (OVEConfig.Inst().truncateUuids))
116 def readConfig(self):
117 self.configHosts = deepcopy(OVEConfig.Inst().hosts)
118 self.configLogTraffic = OVEConfig.Inst().logTraffic
119 self.configTruncateUuids = OVEConfig.Inst().truncateUuids
121 def writeConfig(self):
122 OVEConfig.Inst().hosts = deepcopy(self.configHosts)
123 OVEConfig.Inst().logTraffic = self.configLogTraffic
124 OVEConfig.Inst().truncateUuids = self.configTruncateUuids
125 OVEConfig.Inst().saveConfig()