3 from qobserver
import QObserver
7 class PushController(QObserver
):
8 def __init__(self
, model
, view
):
9 QObserver
.__init
__(self
,model
,view
)
11 self
.model_to_view('remote', 'remoteText')
12 self
.model_to_view('remotes', 'remoteList')
13 self
.model_to_view('local_branch', 'localBranchText')
14 self
.model_to_view('remote_branch', 'remoteBranchText')
15 self
.model_to_view('local_branches', 'localBranchList')
16 self
.model_to_view('remote_branches', 'remoteBranchList')
18 self
.add_signals('textChanged(const QString&)',
21 view
.remoteBranchText
)
23 self
.add_signals('itemSelectionChanged()',
26 view
.remoteBranchList
)
28 self
.add_signals('released()',
32 self
.add_actions('remotes', self
.remotes
)
35 'remoteList': self
.remote_list
,
36 'localBranchList': self
.local_branch_list
,
37 'remoteBranchList': self
.remote_branch_list
,
38 'pushButton': self
.push
,
41 self
.connect(view
.cancelButton
, 'released()', view
.reject
)
42 model
.notify_observers('remotes','local_branches','remote_branches')
45 if not self
.model
.get_remote():
46 errmsg
= self
.tr('No repository selected.')
47 qtutils
.show_output(self
.view
, errmsg
)
50 if not self
.model
.get_remote_branch():
51 errmsg
= self
.tr('Please supply a branch name.')
52 qtutils
.show_output(self
.view
, errmsg
)
55 if not self
.model
.get_local_branch():
56 msg
= self
.tr('Pushing with an empty local branch '
57 + 'will remove the remote branch.\n'
59 if not qtutils
.question(self
.view
, self
.tr('warning'), msg
):
62 remote
= self
.model
.get_remote()
63 local_branch
= self
.model
.get_local_branch()
64 remote_branch
= self
.model
.get_remote_branch()
65 ffwd
= self
.view
.allowFFOnlyCheckBox
.isChecked()
66 tags
= self
.view
.tagsCheckBox
.isChecked()
68 status
, output
= self
.model
.push(remote
,
69 local_branch
, remote_branch
,
72 qtutils
.show_output(self
.view
, output
)
76 def remotes(self
, widget
):
78 for remote
in self
.model
.get_remotes():
79 url
= self
.model
.remote_url(remote
)
80 display
= '%s\t(%s %s)' \
81 % (remote
, unicode(self
.tr('URL:')), url
)
82 displayed
.append(display
)
83 qtutils
.set_items(widget
,displayed
)
85 def remote_list(self
):
86 widget
= self
.view
.remoteList
87 remotes
= self
.model
.get_remotes()
88 selection
= qtutils
.get_selected_item(widget
,remotes
)
89 if not selection
: return
90 self
.model
.set_remote(selection
)
91 self
.view
.remoteText
.selectAll()
93 def local_branch_list(self
):
94 branches
= self
.model
.get_local_branches()
95 widget
= self
.view
.localBranchList
96 selection
= qtutils
.get_selected_item(widget
,branches
)
97 if not selection
: return
99 self
.model
.set_local_branch(selection
)
100 self
.model
.set_remote_branch(selection
)
102 self
.view
.localBranchText
.selectAll()
103 self
.view
.remoteBranchText
.selectAll()
105 def remote_branch_list(self
):
106 widget
= self
.view
.remoteBranchList
107 branches
= self
.model
.get_remote_branches()
108 selection
= qtutils
.get_selected_item(widget
,branches
)
109 if not selection
: return
111 branch
= utils
.basename(selection
)
112 self
.model
.set_remote_branch(branch
)
113 self
.view
.remoteBranchText
.selectAll()