|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 |
|
7 """ |
|
8 Module implementing the Git configuration page. |
|
9 """ |
|
10 |
|
11 from __future__ import unicode_literals |
|
12 |
|
13 import os |
|
14 |
|
15 from PyQt5.QtCore import pyqtSlot |
|
16 from PyQt5.QtWidgets import QDialog |
|
17 |
|
18 from Preferences.ConfigurationPages.ConfigurationPageBase import \ |
|
19 ConfigurationPageBase |
|
20 from .Ui_GitPage import Ui_GitPage |
|
21 |
|
22 |
|
23 class GitPage(ConfigurationPageBase, Ui_GitPage): |
|
24 """ |
|
25 Class implementing the Git configuration page. |
|
26 """ |
|
27 def __init__(self, plugin): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param plugin reference to the plugin object |
|
32 """ |
|
33 super(GitPage, self).__init__() |
|
34 self.setupUi(self) |
|
35 self.setObjectName("GitPage") |
|
36 |
|
37 self.__plugin = plugin |
|
38 |
|
39 # set initial values |
|
40 # log |
|
41 self.logSpinBox.setValue( |
|
42 self.__plugin.getPreferences("LogLimit")) |
|
43 self.logWidthSpinBox.setValue( |
|
44 self.__plugin.getPreferences("LogSubjectColumnWidth")) |
|
45 self.findHarderCheckBox.setChecked( |
|
46 self.__plugin.getPreferences("FindCopiesHarder")) |
|
47 # commit |
|
48 self.commitSpinBox.setValue( |
|
49 self.__plugin.getPreferences("CommitMessages")) |
|
50 self.commitIdSpinBox.setValue( |
|
51 self.__plugin.getPreferences("CommitIdLength")) |
|
52 # cleanup |
|
53 self.cleanupPatternEdit.setText( |
|
54 self.__plugin.getPreferences("CleanupPatterns")) |
|
55 # repository optimization |
|
56 self.aggressiveCheckBox.setChecked( |
|
57 self.__plugin.getPreferences("AggressiveGC")) |
|
58 |
|
59 def save(self): |
|
60 """ |
|
61 Public slot to save the Git configuration. |
|
62 """ |
|
63 # log |
|
64 self.__plugin.setPreferences( |
|
65 "LogLimit", self.logSpinBox.value()) |
|
66 self.__plugin.setPreferences( |
|
67 "LogSubjectColumnWidth", self.logWidthSpinBox.value()) |
|
68 self.__plugin.setPreferences( |
|
69 "FindCopiesHarder", self.findHarderCheckBox.isChecked()) |
|
70 # commit |
|
71 self.__plugin.setPreferences( |
|
72 "CommitMessages", self.commitSpinBox.value()) |
|
73 self.__plugin.setPreferences( |
|
74 "CommitMessages", self.commitIdSpinBox.value()) |
|
75 # cleanup |
|
76 self.__plugin.setPreferences( |
|
77 "CleanupPatterns", self.cleanupPatternEdit.text()) |
|
78 # repository optimization |
|
79 self.__plugin.setPreferences( |
|
80 "AggressiveGC", self.aggressiveCheckBox.isChecked()) |
|
81 |
|
82 @pyqtSlot() |
|
83 def on_configButton_clicked(self): |
|
84 """ |
|
85 Private slot to edit the (per user) Git configuration file. |
|
86 """ |
|
87 from QScintilla.MiniEditor import MiniEditor |
|
88 cfgFile = self.__plugin.getConfigPath() |
|
89 if not os.path.exists(cfgFile): |
|
90 from ..GitUserConfigDataDialog import GitUserConfigDataDialog |
|
91 dlg = GitUserConfigDataDialog() |
|
92 if dlg.exec_() == QDialog.Accepted: |
|
93 firstName, lastName, email = dlg.getData() |
|
94 else: |
|
95 firstName, lastName, email = ( |
|
96 "Firstname", "Lastname", "email_address") |
|
97 try: |
|
98 f = open(cfgFile, "w") |
|
99 f.write("[user]\n") |
|
100 f.write(" name = {0} {1}\n".format(firstName, lastName)) |
|
101 f.write(" email = {0}\n".format(email)) |
|
102 f.close() |
|
103 except (IOError, OSError): |
|
104 # ignore these |
|
105 pass |
|
106 editor = MiniEditor(cfgFile, "Properties", self) |
|
107 editor.show() |