1 """This controller handles the remote dialog."""
5 from PyQt4
.QtGui
import QDialog
8 from cola
import qtutils
9 from cola
.views
import RemoteView
10 from cola
.qobserver
import QObserver
12 def remote_action(model
, parent
, action
):
14 model
.create(remotename
='',
16 ffwd_only_checkbox
=True)
17 view
= RemoteView(parent
, action
)
18 if action
== 'Fetch' or action
== 'Pull':
19 model
.set_tags_checkbox(False)
21 view
.tags_checkbox
.hide()
22 controller
= RemoteController(model
, view
, action
)
24 return view
.exec_() == QDialog
.Accepted
26 class RemoteController(QObserver
):
27 def init(self
, model
, view
, action
):
28 self
.add_observables('remotename',
36 self
.action_method
= {
37 'Fetch': self
.gen_remote_callback(self
.model
.fetch_helper
),
38 'Push': self
.gen_remote_callback(self
.model
.push_helper
),
39 'Pull': self
.gen_remote_callback(self
.model
.pull_helper
),
42 self
.add_actions(remotes
= self
.display_remotes
)
43 self
.add_callbacks(action_button
= self
.action_method
,
44 remotes
= self
.update_remotes
,
45 local_branches
= self
.update_local_branches
,
46 remote_branches
= self
.update_remote_branches
)
48 if self
.view
.select_first_remote():
49 self
.model
.set_remotename(self
.model
.get_remotes()[0])
51 def display_remotes(self
, widget
):
53 for remotename
in self
.model
.get_remotes():
54 url
= self
.model
.remote_url(remotename
)
55 display
= ('%s\t(%s %s)'
56 % (remotename
, unicode(self
.tr('URL:')), url
))
57 displayed
.append(display
)
58 qtutils
.set_items(widget
,displayed
)
60 def update_remotes(self
,*rest
):
61 widget
= self
.view
.remotes
62 remotes
= self
.model
.get_remotes()
63 selection
= qtutils
.get_selected_item(widget
, remotes
)
66 self
.model
.set_remotename(selection
)
67 self
.view
.remotename
.selectAll()
69 def update_local_branches(self
,*rest
):
70 branches
= self
.model
.get_local_branches()
71 widget
= self
.view
.local_branches
72 selection
= qtutils
.get_selected_item(widget
, branches
)
76 self
.model
.set_local_branch(selection
)
77 self
.model
.set_remote_branch(selection
)
79 self
.view
.local_branch
.selectAll()
80 self
.view
.remote_branch
.selectAll()
82 def update_remote_branches(self
,*rest
):
83 widget
= self
.view
.remote_branches
84 branches
= self
.model
.get_remote_branches()
85 selection
= qtutils
.get_selected_item(widget
,branches
)
88 branch
= utils
.basename(selection
)
91 self
.model
.set_remote_branch(branch
)
92 self
.view
.remote_branch
.selectAll()
94 def check_remote(self
):
95 if not self
.model
.get_remotename():
96 errmsg
= self
.tr('No repository selected.')
97 qtutils
.show_output(errmsg
)
102 def get_common_args(self
):
103 return (self
.model
.get_remotename(),
105 'local_branch': self
.model
.get_local_branch(),
106 'remote_branch': self
.model
.get_remote_branch(),
107 'ffwd': self
.model
.get_ffwd_only_checkbox(),
108 'tags': self
.model
.get_tags_checkbox(),
111 def show_results(self
, output
):
112 qtutils
.show_output(output
)
114 qtutils
.raise_logger()
116 #+-------------------------------------------------------------
118 def gen_remote_callback(self
, modelaction
):
119 """Generates a Qt callback for fetch/push/pull.
121 def remote_callback():
122 if not self
.check_remote():
124 remote
, kwargs
= self
.get_common_args()
125 output
= modelaction(remote
, **kwargs
)
126 if not output
: # git fetch --tags --verbose doesn't print anything...
127 output
= self
.tr('Already up-to-date.')
128 self
.show_results(output
)
129 return remote_callback