1
# Qt 4 based frontend to software-properties
3
# Copyright (c) 2007 Canonical Ltd.
5
# Author: Jonathan Riddell <jriddell@ubuntu.com>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22
from __future__ import absolute_import, print_function
24
from gettext import gettext as _
26
from PyQt5.QtCore import *
27
from PyQt5.QtGui import *
30
from aptsources.sourceslist import SourceEntry
31
from .I18nHelper import *
33
UIDIR = '/home/jr/src/software-properties/deneutral'
35
class DialogEdit(QDialog):
37
def __init__(self, parent, sourceslist, source_entry, datadir):
38
QDialog.__init__(self, parent)
39
self.sourceslist = sourceslist
40
self.source_entry = source_entry
41
uic.loadUi("%s/designer/dialog_edit.ui" % datadir, self)
43
self.combobox_type.addItem(_("Binary"))
44
self.combobox_type.addItem(_("Source code"))
45
if source_entry.type == "deb":
46
self.combobox_type.setCurrentIndex(0)
47
elif source_entry.type == "deb-src":
48
self.combobox_type.setCurrentIndex(1)
50
print("Error, unknown source type: '%s'" % source_entry.type)
53
self.entry_uri.setText(source_entry.uri)
54
self.entry_dist.setText(source_entry.dist)
57
for c in source_entry.comps:
59
comps = comps + " " + c
62
self.entry_comps.setText(comps)
64
self.entry_comment.setText(source_entry.comment)
66
translate_widget(self)
68
self.entry_uri.textChanged.connect(self.check_line)
69
self.entry_dist.textChanged.connect(self.check_line)
70
self.entry_comps.textChanged.connect(self.check_line)
71
self.entry_comment.textChanged.connect(self.check_line)
73
def check_line(self, text):
74
"""Check for a valid apt line and set the enabled value of the
75
button 'add' accordingly"""
76
line = self.get_line()
77
self.button_edit_ok = self.buttonBox.button(QDialogButtonBox.Ok)
79
self.button_edit_ok.setEnabled(False)
81
source_entry = SourceEntry(line)
82
if source_entry.invalid == True:
83
self.button_edit_ok.setEnabled(False)
85
self.button_edit_ok.setEnabled(True)
88
"""Collect all values from the entries and create an apt line"""
89
if self.source_entry.disabled == True:
94
if self.combobox_type.currentIndex() == 0:
97
line = line + "deb-src"
99
text = self.entry_uri.text()
100
if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1:
102
line = line + " " + text
104
text = self.entry_dist.text()
105
if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1:
107
line = line + " " + text
109
text = self.entry_comps.text()
110
if text.find("#") != -1:
113
line = line + " " + text
115
text = self.entry_comment.text()
117
line = line + " #" + text + "\n"
123
result = self.exec_()
124
if result == QDialog.Accepted:
125
line = self.get_line()
128
index = self.sourceslist.list.index(self.source_entry)
129
file = self.sourceslist.list[index].file
130
self.sourceslist.list[index] = SourceEntry(line,file)