A few small bugfixes for the signoff feature.
[hgct.git] / settings.py
blob2048ba711dca9381b181f78fd6be4ccc976f2224
1 # Copyright (c) 2005 Fredrik Kuivinen <freku045@student.liu.se>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 from ctcore import *
17 import qt
18 qconnect = qt.QObject.connect
19 Qt = qt.Qt
21 class Settings(qt.QDialog):
22 def __init__(self):
23 qt.QDialog.__init__(self)
24 self.setModal(True)
25 self.setCaption('Preferences')
26 self.layout = qt.QVBox(self)
27 l = self.layout
28 l.setMargin(10)
29 l.setSpacing(10)
31 self.quitL = qt.QHBox(l)
32 self.quitBox = qt.QCheckBox(self.quitL)
33 self.quitLabel = qt.QLabel('Exit on no changed files', self.quitL)
34 self.quitLabel.setBuddy(self.quitBox)
36 # The following widget is there to get some additional space
37 # between the elements.
38 self.spaceW = qt.QWidget(l)
39 self.signoffLabel = qt.QLabel('Commit signoff:', l)
40 self.signoffBox = qt.QTextEdit(l)
41 self.signoffLabel.setBuddy(self.signoffBox)
43 self.buttonL = qt.QHBox(l)
44 self.ok = qt.QPushButton("&Ok", self.buttonL)
45 self.cancel = qt.QPushButton("&Cancel", self.buttonL)
46 qconnect(self.ok, qt.SIGNAL("clicked()"), self.accept)
47 qconnect(self.cancel, qt.SIGNAL("clicked()"), self.reject)
49 self.resize(l.sizeHint())
50 l.resize(l.sizeHint())
51 self.qset = qt.QSettings()
52 self.loadSettings()
54 def loadSettings(self):
55 self.qset.setPath(shortName, shortName)
56 self.qset.resetGroup()
57 self.qset.beginGroup(shortName)
59 self.splitter = eval(str(self.qset.readEntry('/geometry/splitter', '[400, 200]')[0]))
60 self.width = self.qset.readNumEntry('/geometry/width', 500)[0]
61 self.height = self.qset.readNumEntry('/geometry/height', 600)[0]
62 self.quitOnNoChanges = str(self.qset.readEntry('quitOnNoChanges', 'False')[0]) == 'True'
63 self.signoff = str(self.qset.readEntry('signoff', '')[0])
65 self.quitBox.setChecked(self.quitOnNoChanges)
66 self.signoffBox.setText(self.signoff)
68 def writeSettings(self):
69 self.qset.setPath(shortName, shortName)
70 self.qset.resetGroup()
71 self.qset.beginGroup(shortName)
73 self.qset.writeEntry('/geometry/splitter', repr(self.splitter))
74 self.qset.writeEntry('/geometry/width', self.width)
75 self.qset.writeEntry('/geometry/height', self.height)
76 self.qset.writeEntry('quitOnNoChanges', str(self.quitOnNoChanges))
77 self.qset.writeEntry('signoff', str(self.signoff))
79 # Flush the written entries to disk
80 del self.qset
81 self.qset = qt.QSettings()
83 def paintEvent(self, e):
84 qt.QDialog.paintEvent(self, e)
86 def showSettings(self):
87 if self.exec_loop() == qt.QDialog.Accepted:
88 self.quitOnNoChanges = self.quitBox.isChecked()
89 self.signoff = self.signoffBox.text()
91 self.quitBox.setChecked(self.quitOnNoChanges)
92 self.signoffBox.setText(self.signoff)