Diff exits with status code 2 if it is given binary files.
[hgct.git] / settings.py
blob29160700dd719d60b3c1b9fd0132c1f47e6a670f
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.QVBoxLayout(self)
27 self.layout.setMargin(10)
28 self.layout.setSpacing(10)
30 self.gridL = qt.QGridLayout(2, 3)
31 self.gridL.setColStretch(2, 1)
32 self.layout.addLayout(self.gridL)
34 self.quitBox = qt.QCheckBox(self)
35 self.quitLabel = qt.QLabel('Exit on no changed files', self)
36 self.quitLabel.setBuddy(self.quitBox)
37 self.gridL.addWidget(self.quitBox, 0, 0)
38 self.gridL.addWidget(self.quitLabel, 0, 1)
40 self.unknownBox = qt.QCheckBox(self)
41 self.unknownLabel = qt.QLabel('Show unknown files', self)
42 self.unknownLabel.setBuddy(self.unknownBox)
43 self.gridL.addWidget(self.unknownBox, 1, 0)
44 self.gridL.addWidget(self.unknownLabel, 1, 1)
47 self.exclBox = qt.QGroupBox(1, Qt.Horizontal, 'Ignore patterns (Git only)', self)
48 self.layout.addWidget(self.exclBox)
50 self.exclL = qt.QGrid(2, self.exclBox)
51 self.exclFLabel = qt.QLabel('Load and save patterns from/to ', self.exclL)
52 self.exclFE = qt.QLineEdit(self.exclL)
53 self.exclFLabel.setBuddy(self.exclFE)
55 self.exclDLabel = qt.QLabel('Load per directory patterns from ', self.exclL)
56 self.exclDE = qt.QLineEdit(self.exclL)
57 self.exclDLabel.setBuddy(self.exclDE)
59 self.layout.addSpacing(10)
61 self.signoffLabel = qt.QLabel('Commit signoff:', self)
62 self.signoffBox = qt.QTextEdit(self)
63 self.signoffLabel.setBuddy(self.signoffBox)
64 self.layout.addWidget(self.signoffLabel)
65 self.layout.addWidget(self.signoffBox)
67 self.buttonL = qt.QHBox(self)
68 self.layout.addWidget(self.buttonL)
69 self.ok = qt.QPushButton("&Ok", self.buttonL)
70 self.cancel = qt.QPushButton("&Cancel", self.buttonL)
71 qconnect(self.ok, qt.SIGNAL("clicked()"), self.accept)
72 qconnect(self.cancel, qt.SIGNAL("clicked()"), self.reject)
74 self.resize(self.size())
75 self.qset = qt.QSettings()
76 self.loadSettings()
78 def loadSettings(self):
79 self.qset.setPath(shortName, shortName)
80 self.qset.resetGroup()
81 self.qset.beginGroup(shortName)
83 self.splitter = eval(str(self.qset.readEntry('/geometry/splitter', '[400, 200]')[0]))
84 self.width = self.qset.readNumEntry('/geometry/width', 500)[0]
85 self.height = self.qset.readNumEntry('/geometry/height', 600)[0]
86 self.quitOnNoChanges = str(self.qset.readEntry('quitOnNoChanges', 'False')[0]) == 'True'
87 self.signoff = str(self.qset.readEntry('signoff', '')[0])
88 self.showUnknown = str(self.qset.readEntry('showUnknown', 'False')[0]) == 'True'
89 self._gitExcludeFile = str(self.qset.readEntry('gitExcludeFile', '${GIT_DIR}/info/exclude')[0])
90 self._gitExcludeDir = str(self.qset.readEntry('gitExcludeDir', '.gitignore')[0])
92 self.updateGui()
94 def updateGui(self):
95 self.quitBox.setChecked(self.quitOnNoChanges)
96 self.unknownBox.setChecked(self.showUnknown)
97 self.signoffBox.setText(self.signoff)
98 self.exclFE.setText(self._gitExcludeFile)
99 self.exclDE.setText(self._gitExcludeDir)
101 def writeSettings(self):
102 self.qset.setPath(shortName, shortName)
103 self.qset.resetGroup()
104 self.qset.beginGroup(shortName)
106 self.qset.writeEntry('/geometry/splitter', repr(self.splitter))
107 self.qset.writeEntry('/geometry/width', self.width)
108 self.qset.writeEntry('/geometry/height', self.height)
109 self.qset.writeEntry('quitOnNoChanges', str(self.quitOnNoChanges))
110 self.qset.writeEntry('signoff', self.signoff)
111 self.qset.writeEntry('showUnknown', str(self.showUnknown))
112 self.qset.writeEntry('gitExcludeFile', self._gitExcludeFile)
113 self.qset.writeEntry('gitExcludeDir', self._gitExcludeDir)
115 # Flush the written entries to disk
116 del self.qset
117 self.qset = qt.QSettings()
119 def paintEvent(self, e):
120 qt.QDialog.paintEvent(self, e)
122 def showSettings(self):
123 result = False
124 if self.exec_loop() == qt.QDialog.Accepted:
125 result = True
126 self.quitOnNoChanges = self.quitBox.isChecked()
127 self.signoff = str(self.signoffBox.text())
128 self.showUnknown = self.unknownBox.isChecked()
129 self._gitExcludeFile = str(self.exclFE.text())
130 self._gitExcludeDir = str(self.exclDE.text())
132 self.updateGui()
133 return result
135 def gitExcludeFile(self):
136 def replace(m):
137 if os.environ.has_key(m.group(1)):
138 return os.environ[m.group(1)]
139 else:
140 return ''
142 if self._gitExcludeFile == '':
143 return None
144 else:
145 return excludeFileRE.sub(replace, self._gitExcludeFile)
147 def gitExcludeDir(self):
148 if self._gitExcludeDir == '':
149 return None
150 else:
151 return self._gitExcludeDir
153 excludeFileRE = re.compile(r'\$\{([^}]*)\}')