1 # Copyright (c) 2005 Fredrik Kuivinen <frekui@gmail.com>
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.
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
18 qconnect
= qt
.QObject
.connect
21 class Settings(qt
.QDialog
):
23 qt
.QDialog
.__init
__(self
)
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
.exclBox
= qt
.QGroupBox(1, Qt
.Horizontal
, 'Ignore patterns (Git only)', self
)
41 self
.layout
.addWidget(self
.exclBox
)
43 self
.exclL
= qt
.QGrid(2, self
.exclBox
)
44 self
.exclFLabel
= qt
.QLabel('Load and save patterns from/to ', self
.exclL
)
45 self
.exclFE
= qt
.QLineEdit(self
.exclL
)
46 self
.exclFLabel
.setBuddy(self
.exclFE
)
48 self
.exclDLabel
= qt
.QLabel('Load per directory patterns from ', self
.exclL
)
49 self
.exclDE
= qt
.QLineEdit(self
.exclL
)
50 self
.exclDLabel
.setBuddy(self
.exclDE
)
52 self
.layout
.addSpacing(10)
54 self
.signoffLabel
= qt
.QLabel('Commit signoff:', self
)
55 self
.signoffBox
= qt
.QTextEdit(self
)
56 self
.signoffLabel
.setBuddy(self
.signoffBox
)
57 self
.layout
.addWidget(self
.signoffLabel
)
58 self
.layout
.addWidget(self
.signoffBox
)
60 self
.buttonL
= qt
.QHBox(self
)
61 self
.layout
.addWidget(self
.buttonL
)
62 self
.ok
= qt
.QPushButton("&Ok", self
.buttonL
)
63 self
.cancel
= qt
.QPushButton("&Cancel", self
.buttonL
)
64 qconnect(self
.ok
, qt
.SIGNAL("clicked()"), self
.accept
)
65 qconnect(self
.cancel
, qt
.SIGNAL("clicked()"), self
.reject
)
67 self
.resize(self
.size())
68 self
.qset
= qt
.QSettings()
71 def loadSettings(self
):
72 self
.qset
.setPath(shortName
, shortName
)
73 self
.qset
.resetGroup()
74 self
.qset
.beginGroup(shortName
)
76 self
.splitter
= eval(str(self
.qset
.readEntry('/geometry/splitter', '[400, 200]')[0]))
77 self
.width
= self
.qset
.readNumEntry('/geometry/width', 500)[0]
78 self
.height
= self
.qset
.readNumEntry('/geometry/height', 600)[0]
79 self
.quitOnNoChanges
= str(self
.qset
.readEntry('quitOnNoChanges', 'False')[0]) == 'True'
80 self
.signoff
= unicode(self
.qset
.readEntry('signoff', '')[0])
81 self
.showUnknown
= str(self
.qset
.readEntry('showUnknown', 'False')[0]) == 'True'
82 self
._gitExcludeFile
= unicode(self
.qset
.readEntry('gitExcludeFile', '${GIT_DIR}/info/exclude')[0])
83 self
._gitExcludeDir
= unicode(self
.qset
.readEntry('gitExcludeDir', '.gitignore')[0])
88 self
.quitBox
.setChecked(self
.quitOnNoChanges
)
89 self
.signoffBox
.setText(self
.signoff
)
90 self
.exclFE
.setText(self
._gitExcludeFile
)
91 self
.exclDE
.setText(self
._gitExcludeDir
)
93 def writeSettings(self
):
94 self
.qset
.setPath(shortName
, shortName
)
95 self
.qset
.resetGroup()
96 self
.qset
.beginGroup(shortName
)
98 self
.qset
.writeEntry('/geometry/splitter', repr(self
.splitter
))
99 self
.qset
.writeEntry('/geometry/width', self
.width
)
100 self
.qset
.writeEntry('/geometry/height', self
.height
)
101 self
.qset
.writeEntry('quitOnNoChanges', str(self
.quitOnNoChanges
))
102 self
.qset
.writeEntry('signoff', self
.signoff
)
103 self
.qset
.writeEntry('showUnknown', str(self
.showUnknown
))
104 self
.qset
.writeEntry('gitExcludeFile', self
._gitExcludeFile
)
105 self
.qset
.writeEntry('gitExcludeDir', self
._gitExcludeDir
)
107 # Flush the written entries to disk
109 self
.qset
= qt
.QSettings()
111 def paintEvent(self
, e
):
112 qt
.QDialog
.paintEvent(self
, e
)
114 def showSettings(self
):
116 if self
.exec_loop() == qt
.QDialog
.Accepted
:
118 self
.quitOnNoChanges
= self
.quitBox
.isChecked()
119 self
.signoff
= unicode(self
.signoffBox
.text())
120 self
._gitExcludeFile
= unicode(self
.exclFE
.text())
121 self
._gitExcludeDir
= unicode(self
.exclDE
.text())
126 def gitExcludeFile(self
):
128 if os
.environ
.has_key(m
.group(1)):
129 return os
.environ
[m
.group(1)]
133 if self
._gitExcludeFile
== '':
136 return excludeFileRE
.sub(replace
, self
._gitExcludeFile
)
138 def gitExcludeDir(self
):
139 if self
._gitExcludeDir
== '':
142 return self
._gitExcludeDir
144 excludeFileRE
= re
.compile(r
'\$\{([^}]*)\}')