2 from PyQt4
.QtGui
import QDialog
5 from ugit
import qtutils
6 from ugit
.views
import RemoteView
7 from ugit
.qobserver
import QObserver
9 def remote_action(model
, parent
, action
):
14 ffwd_only_checkbox
=True,
16 if action
== "Fetch" or action
== "Pull":
17 model
.set_tags_checkbox(True)
18 view
= RemoteView(parent
, action
)
19 controller
= RemoteController(model
, view
, action
)
21 return view
.exec_() == QDialog
.Accepted
23 class RemoteController(QObserver
):
24 def init(self
, model
, view
, action
):
36 self
.action_method
= {
37 "Fetch": self
.fetch_action
,
38 "Push": self
.push_action
,
39 "Pull": self
.pull_action
,
42 self
.add_actions( remotes
= self
.display_remotes
)
44 action_button
= self
.action_method
,
45 remotes
= self
.update_remotes
,
46 local_branches
= self
.update_local_branches
,
47 remote_branches
= self
.update_remote_branches
,
50 if self
.view
.select_first_remote():
51 self
.model
.set_remotename(self
.model
.get_remotes()[0])
53 def display_remotes(self
, widget
):
55 for remotename
in self
.model
.get_remotes():
56 url
= self
.model
.remote_url(remotename
)
57 display
= '%s\t(%s %s)' \
58 % (remotename
, unicode(self
.tr('URL:')), url
)
59 displayed
.append(display
)
60 qtutils
.set_items(widget
,displayed
)
62 def update_remotes(self
,*rest
):
63 widget
= self
.view
.remotes
64 remotes
= self
.model
.get_remotes()
65 selection
= qtutils
.get_selected_item(widget
,remotes
)
66 if not selection
: return
67 self
.model
.set_remotename(selection
)
68 self
.view
.remotename
.selectAll()
70 def update_local_branches(self
,*rest
):
71 branches
= self
.model
.get_local_branches()
72 widget
= self
.view
.local_branches
73 selection
= qtutils
.get_selected_item(widget
,branches
)
74 if not selection
: return
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
)
86 if not selection
: return
88 branch
= utils
.basename(selection
)
89 if branch
== 'HEAD': return
90 self
.model
.set_remote_branch(branch
)
91 self
.view
.remote_branch
.selectAll()
93 def check_remote(self
):
94 if not self
.model
.get_remotename():
95 errmsg
= self
.tr('No repository selected.')
96 qtutils
.show_output(errmsg
)
101 def get_common_args(self
):
103 (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(),
112 def show_results(self
, status
, output
):
117 qtutils
.raise_logger()
119 #+-------------------------------------------------------------
121 def fetch_action(self
):
122 if not self
.check_remote():
124 args
, kwargs
= self
.get_common_args()
125 self
.show_results(*self
.model
.fetch_helper(*args
, **kwargs
))
128 def pull_action(self
):
129 if not self
.check_remote():
131 args
, kwargs
= self
.get_common_args()
132 self
.show_results(*self
.model
.pull_helper(*args
, **kwargs
))
134 def push_action(self
):
135 if not self
.check_remote():
137 args
, kwargs
= self
.get_common_args()
138 self
.show_results(*self
.model
.push_helper(*args
, **kwargs
))