Renamed 'ugitlibs' to just plain 'ugit'
[ugit.git] / ugit / pushcontroller.py
blobb70b34f3b946b5aeea6b82709c79d980b6c771ac
1 import os
2 from PyQt4.QtGui import QDialog
4 import utils
5 import qtutils
6 from qobserver import QObserver
7 from views import PushGUI
9 def push_branches(model, parent):
10 model = model.clone()
11 view = PushGUI(parent)
12 controller = PushController(model,view)
13 view.show()
14 return view.exec_() == QDialog.Accepted
16 class PushController(QObserver):
17 def __init__(self, model, view):
18 QObserver.__init__(self,model,view)
20 self.add_observables(
21 'remote',
22 'remotes',
23 'local_branch',
24 'local_branches',
25 'remote_branch',
26 'remote_branches',
29 self.add_actions('remotes', self.display_remotes)
30 self.add_callbacks(
31 remotes = self.update_remotes,
32 local_branches = self.update_local_branches,
33 remote_branches = self.update_remote_branches,
34 push_button = self.push_to_remote_branch,
36 self.refresh_view()
38 def display_remotes(self, widget):
39 displayed = []
40 for remote in self.model.get_remotes():
41 url = self.model.remote_url(remote)
42 display = '%s\t(%s %s)' \
43 % (remote, unicode(self.tr('URL:')), url)
44 displayed.append(display)
45 qtutils.set_items(widget,displayed)
47 def push_to_remote_branch(self):
48 if not self.model.get_remote():
49 errmsg = self.tr('No repository selected.')
50 qtutils.show_output(errmsg)
51 return
53 if not self.model.get_remote_branch():
54 errmsg = self.tr('Please supply a branch name.')
55 qtutils.show_output(errmsg)
56 return
58 if not self.model.get_local_branch():
59 msg = self.tr('Pushing with an empty local branch '
60 + 'will remove the remote branch.\n'
61 + 'Continue?')
62 if not qtutils.question(self.view, self.tr('warning'), msg):
63 return
65 remote = self.model.get_remote()
66 local_branch = self.model.get_local_branch()
67 remote_branch = self.model.get_remote_branch()
68 ffwd = self.view.ffwd_only_checkbox.isChecked()
69 tags = self.view.tags_checkbox.isChecked()
71 status, output = self.model.push(remote,
72 local_branch, remote_branch,
73 ffwd=ffwd, tags=tags)
74 qtutils.show_output(output)
75 if not status:
76 self.view.accept()
78 def update_remotes(self,*rest):
79 widget = self.view.remotes
80 remotes = self.model.get_remotes()
81 selection = qtutils.get_selected_item(widget,remotes)
82 if not selection: return
83 self.model.set_remote(selection)
84 self.view.remote.selectAll()
86 def update_local_branches(self,*rest):
87 branches = self.model.get_local_branches()
88 widget = self.view.local_branches
89 selection = qtutils.get_selected_item(widget,branches)
90 if not selection: return
92 self.model.set_local_branch(selection)
93 self.model.set_remote_branch(selection)
95 self.view.local_branch.selectAll()
96 self.view.remote_branch.selectAll()
98 def update_remote_branches(self,*rest):
99 widget = self.view.remote_branches
100 branches = self.model.get_remote_branches()
101 selection = qtutils.get_selected_item(widget,branches)
102 if not selection: return
104 branch = utils.basename(selection)
105 if branch == 'HEAD': return
106 self.model.set_remote_branch(branch)
107 self.view.remote_branch.selectAll()