netflow: Correctly track flow creation time.
[cascardo/ovs.git] / ovsdb / ovsdbmonitor / OVELogWindow.py
1 # Copyright (c) 2010 Citrix Systems, Inc.
2 #
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:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 from OVEStandard import *
16 from OVELogger import *
17 from Ui_LogWindow import *
18
19 class OVELogWindow(QtGui.QDialog):
20     LOAD_KEY = 'LogWindow/window'
21     def __init__(self, app):
22         QtGui.QDialog.__init__(self)
23         self.app = app
24         self.ui = Ui_LogWindow()
25         self.ui.setupUi(self)
26         if self.isLoadable():
27             self.loadSettings()
28         self.connect(OVELogger.Inst(), QtCore.SIGNAL("logUpdated()"), self.logUpdated)
29         self.connect(self.ui.buttonBox, QtCore.SIGNAL("clicked(QAbstractButton *)"), self.xon_actionButton_Box_clicked)
30         
31     def xon_actionButton_Box_clicked(self, button):
32         role = self.ui.buttonBox.buttonRole(button)
33         if role == QtGui.QDialogButtonBox.ResetRole:
34             OVELogger.Inst().reset()
35             OVELog("Log reset")
36         
37     def logUpdated(self):
38         self.ui.textBrowser.setText("\n".join(OVELogger.Inst().contents))
39         self.ui.textBrowser.moveCursor(QtGui.QTextCursor.End)
40         self.ui.textBrowser.ensureCursorVisible()
41
42     def saveSettings(self):
43         key = self.LOAD_KEY
44         settings = QtCore.QSettings()
45         settings.setValue(key+"/loadable", QVariant(True))
46         settings.setValue(key+"/pos", QVariant(self.pos()))
47         settings.setValue(key+"/size", QVariant(self.size()))
48         settings.setValue(key+"/visible", QVariant(self.isVisible()))
49     
50     def loadSettings(self):
51         key = self.LOAD_KEY
52         settings = QtCore.QSettings()
53         pos = settings.value(key+"/pos", QVariant(QtCore.QPoint(200, 200))).toPoint()
54         size = settings.value(key+"/size", QVariant(QtCore.QSize(400, 400))).toSize()
55         visible = settings.value(key+"/visible", QVariant(True)).toBool()
56         self.resize(size)
57         self.move(pos)
58         self.setVisible(visible)
59
60     @classmethod
61     def isLoadable(cls):
62         key = cls.LOAD_KEY
63         settings = QtCore.QSettings()
64         return settings.value(key+"/loadable", QVariant(False)).toBool()