~ubuntu-branches/debian/sid/qbzr/sid

« back to all changes in this revision

Viewing changes to lib/bind.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-12-05 01:20:38 UTC
  • Revision ID: james.westby@ubuntu.com-20091205012038-41f57s3ecv2r34lz
Tags: upstream-0.16
ImportĀ upstreamĀ versionĀ 0.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# QBzr - Qt frontend to Bazaar commands
 
4
#
 
5
# Contributors:
 
6
#  Javier Der Derian <javierder@gmail.com>
 
7
#
 
8
# This program is free software; you can redistribute it and/or
 
9
# modify it under the terms of the GNU General Public License
 
10
# as published by the Free Software Foundation; either version 2
 
11
# of the License, or (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
21
 
 
22
 
 
23
from PyQt4 import QtCore, QtGui
 
24
 
 
25
from bzrlib import errors, osutils
 
26
 
 
27
from bzrlib.plugins.qbzr.lib.i18n import gettext
 
28
from bzrlib.plugins.qbzr.lib.subprocess import SubProcessDialog
 
29
from bzrlib.plugins.qbzr.lib.util import (
 
30
    url_for_display,
 
31
    StandardButton,
 
32
    BTN_CANCEL,
 
33
    )
 
34
from bzrlib.plugins.qbzr.lib.uifactory import ui_current_widget
 
35
from bzrlib.plugins.qbzr.lib.trace import (
 
36
   reports_exception,
 
37
   SUB_LOAD_METHOD,
 
38
   )
 
39
 
 
40
 
 
41
class QBzrBindDialog(SubProcessDialog):
 
42
 
 
43
    def __init__(self, branch, location=None, ui_mode = None):
 
44
        self.branch = branch
 
45
        super(QBzrBindDialog, self).__init__(
 
46
                                  gettext("Bind branch"),
 
47
                                  name = "bind",
 
48
                                  default_size = (400, 400),
 
49
                                  ui_mode = ui_mode,
 
50
                                  dialog = True,
 
51
                                  parent = None,
 
52
                                  hide_progress=False,
 
53
                                  )
 
54
 
 
55
        # Display information fields
 
56
        gbBind = QtGui.QGroupBox(gettext("Bind"), self)
 
57
        bind_box = QtGui.QFormLayout(gbBind)
 
58
        bind_box.addRow(gettext("Branch location:"),
 
59
            QtGui.QLabel(url_for_display(branch.base)))
 
60
        self.currbound = branch.get_bound_location()
 
61
        if self.currbound != None:
 
62
            bind_box.addRow(gettext("Currently bound to:"),
 
63
                QtGui.QLabel(url_for_display(self.currbound)))
 
64
 
 
65
        # Build the "Bind to" widgets
 
66
        branch_label = QtGui.QLabel(gettext("Bind to:"))
 
67
        branch_combo = QtGui.QComboBox()   
 
68
        branch_combo.setEditable(True)
 
69
        self.branch_combo = branch_combo
 
70
        browse_button = QtGui.QPushButton(gettext("Browse"))
 
71
        QtCore.QObject.connect(browse_button, QtCore.SIGNAL("clicked(bool)"),
 
72
            self.browse_clicked)
 
73
 
 
74
        # Add some useful values into the combo box. If a location was given,
 
75
        # default to it. If an old bound location exists, suggest it.
 
76
        # Otherwise suggest the parent branch, if any.
 
77
        suggestions = []
 
78
        if location:
 
79
            suggestions.append(osutils.abspath(location))
 
80
        old_location = branch.get_old_bound_location()
 
81
        if old_location:
 
82
            url = url_for_display(old_location)
 
83
            if url not in suggestions:
 
84
                suggestions.append(url)
 
85
        parent_location = branch.get_parent()
 
86
        if parent_location:
 
87
            url = url_for_display(parent_location)
 
88
            if url not in suggestions:
 
89
                suggestions.append(url)
 
90
        if suggestions:
 
91
            branch_combo.addItems(suggestions)
 
92
 
 
93
        # Build the "Bind to" row/panel
 
94
        bind_hbox = QtGui.QHBoxLayout()
 
95
        bind_hbox.addWidget(branch_label)
 
96
        bind_hbox.addWidget(branch_combo)
 
97
        bind_hbox.addWidget(browse_button)
 
98
        bind_hbox.setStretchFactor(branch_label,0)
 
99
        bind_hbox.setStretchFactor(branch_combo,1)
 
100
        bind_hbox.setStretchFactor(browse_button,0)
 
101
        bind_box.addRow(bind_hbox)
 
102
 
 
103
        # Put the form together
 
104
        layout = QtGui.QVBoxLayout(self)
 
105
        layout.addWidget(gbBind)
 
106
        layout.addWidget(self.make_default_status_box())
 
107
        layout.addWidget(self.buttonbox)
 
108
        
 
109
    def browse_clicked(self):
 
110
        fileName = QtGui.QFileDialog.getExistingDirectory(self,
 
111
            gettext("Select branch location"));
 
112
        if fileName != '':
 
113
            self.branch_combo.insertItem(0,fileName)
 
114
            self.branch_combo.setCurrentIndex(0)
 
115
        
 
116
    @reports_exception(type=SUB_LOAD_METHOD)
 
117
    @ui_current_widget   
 
118
    def validate(self):
 
119
        location = unicode(self.branch_combo.currentText())
 
120
        if not location:
 
121
            raise errors.BzrCommandError(
 
122
                gettext("Master branch location not specified."))
 
123
        return True
 
124
    
 
125
    def do_start(self):        
 
126
        location = unicode(self.branch_combo.currentText())
 
127
        self.process_widget.do_start(None, 'bind', location)