~ubuntu-core-dev/software-properties/main

« back to all changes in this revision

Viewing changes to softwareproperties/qt/DialogEdit.py

  • Committer: Simon Quigley
  • Date: 2018-07-14 10:11:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1049.
  • Revision ID: tsimonq2@ubuntu.com-20180714101132-jpm43js9q13vplzm
Use sed to make everything say Qt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  Qt 4 based frontend to software-properties
 
2
#
 
3
#  Copyright (c) 2007 Canonical Ltd.
 
4
#
 
5
#  Author: Jonathan Riddell <jriddell@ubuntu.com>
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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
 
20
#  USA
 
21
 
 
22
from __future__ import absolute_import, print_function
 
23
 
 
24
from gettext import gettext as _
 
25
 
 
26
from PyQt5.QtCore import *
 
27
from PyQt5.QtGui import *
 
28
from PyQt5 import uic
 
29
 
 
30
from aptsources.sourceslist import SourceEntry
 
31
from .I18nHelper import *
 
32
 
 
33
UIDIR = '/home/jr/src/software-properties/deneutral'
 
34
 
 
35
class DialogEdit(QDialog):
 
36
 
 
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)
 
42
 
 
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)
 
49
    else:
 
50
      print("Error, unknown source type: '%s'" % source_entry.type)
 
51
 
 
52
    # uri
 
53
    self.entry_uri.setText(source_entry.uri)
 
54
    self.entry_dist.setText(source_entry.dist)
 
55
 
 
56
    comps = ""
 
57
    for c in source_entry.comps:
 
58
      if len(comps) > 0:
 
59
        comps = comps + " " + c
 
60
      else:
 
61
        comps = c
 
62
    self.entry_comps.setText(comps)
 
63
 
 
64
    self.entry_comment.setText(source_entry.comment)
 
65
 
 
66
    translate_widget(self)
 
67
 
 
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)
 
72
 
 
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)
 
78
    if line == False:
 
79
      self.button_edit_ok.setEnabled(False)
 
80
      return
 
81
    source_entry = SourceEntry(line)
 
82
    if source_entry.invalid == True:
 
83
      self.button_edit_ok.setEnabled(False)
 
84
    else:
 
85
      self.button_edit_ok.setEnabled(True)
 
86
 
 
87
  def get_line(self):
 
88
    """Collect all values from the entries and create an apt line"""
 
89
    if self.source_entry.disabled == True:
 
90
        line = "#"
 
91
    else:
 
92
        line = ""
 
93
 
 
94
    if self.combobox_type.currentIndex() == 0:
 
95
      line = line + "deb"
 
96
    else:
 
97
      line = line + "deb-src"
 
98
 
 
99
    text = self.entry_uri.text()
 
100
    if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1:
 
101
      return False
 
102
    line = line + " " + text
 
103
 
 
104
    text = self.entry_dist.text()
 
105
    if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1:
 
106
      return False
 
107
    line = line + " " + text
 
108
 
 
109
    text = self.entry_comps.text()
 
110
    if text.find("#") != -1:
 
111
      return False
 
112
    elif text != "":
 
113
      line = line + " " + text
 
114
 
 
115
    text = self.entry_comment.text()
 
116
    if text != "":
 
117
      line = line + " #" + text + "\n"
 
118
    else:
 
119
      line = line + "\n"
 
120
    return line
 
121
 
 
122
  def run(self):
 
123
      result = self.exec_()
 
124
      if result == QDialog.Accepted:
 
125
        line = self.get_line()
 
126
 
 
127
        # change repository
 
128
        index = self.sourceslist.list.index(self.source_entry)
 
129
        file = self.sourceslist.list[index].file
 
130
        self.sourceslist.list[index] = SourceEntry(line,file)
 
131
      return result