Remove old comment. Saving the window position is just a bad idea.
[hgct.git] / settings.py
blobab84e421e1eb2e1a5fa88bb254c4138baadc85c9
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, re, os
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 self.exclBox = qt.QGroupBox(1, Qt.Horizontal, 'Show unknown files (Git only)', l)
37 self.exclBox.setCheckable(True)
38 self.exclFL = qt.QHBox(self.exclBox)
39 self.exclFLabel = qt.QLabel('Load and save ignore patterns from (Git only): ', self.exclFL)
40 self.exclFE = qt.QLineEdit(self.exclFL)
41 self.exclFLabel.setBuddy(self.exclFE)
43 self.exclDL = qt.QHBox(self.exclBox)
44 self.exclDLabel = qt.QLabel('Load per directory ignore patterns from (Git only): ', self.exclDL)
45 self.exclDE = qt.QLineEdit(self.exclDL)
46 self.exclDLabel.setBuddy(self.exclDE)
48 # The following widget is there to get some additional space
49 # between the elements.
50 self.spaceW = qt.QWidget(l)
51 self.signoffLabel = qt.QLabel('Commit signoff:', l)
52 self.signoffBox = qt.QTextEdit(l)
53 self.signoffLabel.setBuddy(self.signoffBox)
55 self.buttonL = qt.QHBox(l)
56 self.ok = qt.QPushButton("&Ok", self.buttonL)
57 self.cancel = qt.QPushButton("&Cancel", self.buttonL)
58 qconnect(self.ok, qt.SIGNAL("clicked()"), self.accept)
59 qconnect(self.cancel, qt.SIGNAL("clicked()"), self.reject)
61 self.resize(l.sizeHint())
62 l.resize(l.sizeHint())
63 self.qset = qt.QSettings()
64 self.loadSettings()
66 def loadSettings(self):
67 self.qset.setPath(shortName, shortName)
68 self.qset.resetGroup()
69 self.qset.beginGroup(shortName)
71 self.splitter = eval(str(self.qset.readEntry('/geometry/splitter', '[400, 200]')[0]))
72 self.width = self.qset.readNumEntry('/geometry/width', 500)[0]
73 self.height = self.qset.readNumEntry('/geometry/height', 600)[0]
74 self.quitOnNoChanges = str(self.qset.readEntry('quitOnNoChanges', 'False')[0]) == 'True'
75 self.signoff = str(self.qset.readEntry('signoff', '')[0])
76 self.gitShowUnknown = str(self.qset.readEntry('gitShowUnknown', 'False')[0]) == 'True'
77 self._gitExcludeFile = str(self.qset.readEntry('gitExcludeFile', '${GIT_DIR}/info/exclude')[0])
78 self._gitExcludeDir = str(self.qset.readEntry('gitExcludeDir', '.gitignore')[0])
80 self.updateGui()
82 def updateGui(self):
83 self.quitBox.setChecked(self.quitOnNoChanges)
84 self.signoffBox.setText(self.signoff)
85 self.exclBox.setChecked(self.gitShowUnknown)
86 self.exclFE.setText(self._gitExcludeFile)
87 self.exclDE.setText(self._gitExcludeDir)
89 def writeSettings(self):
90 self.qset.setPath(shortName, shortName)
91 self.qset.resetGroup()
92 self.qset.beginGroup(shortName)
94 self.qset.writeEntry('/geometry/splitter', repr(self.splitter))
95 self.qset.writeEntry('/geometry/width', self.width)
96 self.qset.writeEntry('/geometry/height', self.height)
97 self.qset.writeEntry('quitOnNoChanges', str(self.quitOnNoChanges))
98 self.qset.writeEntry('signoff', self.signoff)
99 self.qset.writeEntry('gitShowUnknown', str(self.gitShowUnknown))
100 self.qset.writeEntry('gitExcludeFile', self._gitExcludeFile)
101 self.qset.writeEntry('gitExcludeDir', self._gitExcludeDir)
103 # Flush the written entries to disk
104 del self.qset
105 self.qset = qt.QSettings()
107 def paintEvent(self, e):
108 qt.QDialog.paintEvent(self, e)
110 def showSettings(self):
111 result = False
112 if self.exec_loop() == qt.QDialog.Accepted:
113 result = True
114 self.quitOnNoChanges = self.quitBox.isChecked()
115 self.signoff = str(self.signoffBox.text())
116 self.gitShowUnknown = self.exclBox.isChecked()
117 self._gitExcludeFile = str(self.exclFE.text())
118 self._gitExcludeDir = str(self.exclDE.text())
120 self.updateGui()
121 return result
123 def gitExcludeFile(self):
124 def replace(m):
125 if os.environ.has_key(m.group(1)):
126 return os.environ[m.group(1)]
127 else:
128 return ''
130 if self._gitExcludeFile == '':
131 return None
132 else:
133 return excludeFileRE.sub(replace, self._gitExcludeFile)
135 def gitExcludeDir(self):
136 if self._gitExcludeDir == '':
137 return None
138 else:
139 return self._gitExcludeDir
141 excludeFileRE = re.compile(r'\$\{([^}]*)\}')