Add generic preferences for every systems

Julien LepillerFri Aug 23 17:17:23+0200 2019

c018351

Add generic preferences for every systems

offlate/manager.py

9696
        self.writeProjects()
9797
9898
    def loadProject(self, name, lang, system, data):
99+
        if not "Generic" in self.settings.conf:
100+
            self.settings.conf["Generic"] = {}
99101
        if system == TRANSLATION_PROJECT:
100102
            if not "TP" in self.settings.conf:
101103
                self.settings.conf["TP"] = {}
102-
            proj = TPProject(self.settings.conf["TP"], name, lang, data)
104+
            settings = self.settings.conf["TP"]
105+
            for s in self.settings.conf["Generic"].keys():
106+
                settings[s] = self.settings.conf["Generic"][s]
107+
            proj = TPProject(settings, name, lang, data)
103108
        if system == TRANSIFEX:
104109
            if not 'Transifex' in self.settings.conf:
105110
                self.settings.conf['Transifex'] = {}
106-
            proj = TransifexProject(self.settings.conf['Transifex'], name, lang, data)
111+
            settings = self.settings.conf["Transifex"]
112+
            for s in self.settings.conf["Generic"].keys():
113+
                settings[s] = self.settings.conf["Generic"][s]
114+
            proj = TransifexProject(settings, name, lang, data)
107115
        if system == GITLAB:
108116
            if not 'Gitlab' in self.settings.conf:
109117
                self.settings.conf['Gitlab'] = {}
110-
            proj = GitlabProject(self.settings.conf['Gitlab'], name, lang, data)
118+
            settings = self.settings.conf["Gitlab"]
119+
            for s in self.settings.conf["Generic"].keys():
120+
                settings[s] = self.settings.conf["Generic"][s]
121+
            proj = GitlabProject(settings, name, lang, data)
111122
        self.project_list[name] = proj
112123
        return proj
113124

offlate/ui/settings.py

3131
        vbox = QVBoxLayout()
3232
3333
        tab = QTabWidget()
34+
        self.addGenericTab(tab)
3435
        self.addTPTab(tab)
3536
        self.addTransifexTab(tab)
3637
        self.addGitlabTab(tab)

7778
        self.data["Transifex"] = {}
7879
        self.data["Transifex"]["token"] = self.TransifexToken.text()
7980
81+
    def addGenericTab(self, tab):
82+
        formBox = QGroupBox(self.tr("Generic Settings"))
83+
        formLayout = QFormLayout()
84+
        self.genericFullname = QLineEdit()
85+
        self.genericFullname.setPlaceholderText(self.tr("John Doe <john@doe.me>"))
86+
87+
        if not "Generic" in self.data:
88+
            self.data["Generic"] = {}
89+
        if 'fullname' in self.data['Generic']:
90+
            self.genericFullname.setText(self.data["Generic"]["fullname"])
91+
92+
        formLayout.addRow(QLabel(self.tr("Full Name:")), self.genericFullname)
93+
94+
        self.genericFullname.textChanged.connect(self.updateGeneric)
95+
96+
        formBox.setLayout(formLayout)
97+
        tab.addTab(formBox, self.tr("Generic"))
98+
99+
    def updateGeneric(self):
100+
        self.data["Generic"] = {}
101+
        self.data["Generic"]["fullname"] = self.genericFullname.text()
102+
80103
    def addTPTab(self, tab):
81104
        formBox = QGroupBox(self.tr("Translation Project"))
82105
        formLayout = QFormLayout()

84107
        self.TPemail = QLineEdit()
85108
        self.TPuser = QLineEdit()
86109
        self.TPserver = QLineEdit()
87-
        self.TPfullname = QLineEdit()
88110
89111
        if not "TP" in self.data:
90112
            self.data["TP"] = {}

95117
            self.TPuser.setText(self.data["TP"]["user"])
96118
        if 'server' in self.data['TP']:
97119
            self.TPserver.setText(self.data["TP"]["server"])
98-
        if 'fullname' in self.data['TP']:
99-
            self.TPfullname.setText(self.data["TP"]["fullname"])
100120
101121
        self.TPemail.textChanged.connect(self.updateTP)
102122
        self.TPuser.textChanged.connect(self.updateTP)
103123
        self.TPserver.textChanged.connect(self.updateTP)
104-
        self.TPfullname.textChanged.connect(self.updateTP)
105124
106125
        formLayout.addRow(QLabel(self.tr("Email:")), self.TPemail)
107126
        formLayout.addRow(QLabel(self.tr("Server:")), self.TPserver)
108127
        formLayout.addRow(QLabel(self.tr("User Name:")), self.TPuser)
109-
        formLayout.addRow(QLabel(self.tr("Full Name (John Doe <john@doe.me>):")), self.TPfullname)
110128
111129
        formBox.setLayout(formLayout)
112130
        tab.addTab(formBox, "TP")

116134
        self.data["TP"]["email"] = self.TPemail.text()
117135
        self.data["TP"]["user"] = self.TPuser.text()
118136
        self.data["TP"]["server"] = self.TPserver.text()
119-
        self.data["TP"]["fullname"] = self.TPfullname.text()
120137
121138
    def ok(self):
122139
        self.done = True