Skip to content

Commit

Permalink
adding parameter port, close #116
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Jan 4, 2018
1 parent 12cee5f commit c2326bc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 29 deletions.
65 changes: 43 additions & 22 deletions bauble/connmgr.glade
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
Expand All @@ -59,7 +58,6 @@
<property name="has_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
Expand Down Expand Up @@ -132,7 +130,6 @@
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="border_width">3</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_add_button_clicked" swapped="no"/>
</object>
Expand All @@ -149,7 +146,6 @@
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="border_width">3</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_remove_button_clicked" swapped="no"/>
</object>
Expand Down Expand Up @@ -244,7 +240,6 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_usedefaults_chkbx_toggled" swapped="no"/>
</object>
Expand Down Expand Up @@ -306,7 +301,6 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="activate" handler="on_file_btnbrowse_clicked" swapped="no"/>
<signal name="clicked" handler="on_file_btnbrowse_clicked" swapped="no"/>
</object>
Expand Down Expand Up @@ -352,7 +346,6 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="activate" handler="on_pictureroot_btnbrowse_clicked" swapped="no"/>
<signal name="clicked" handler="on_pictureroot_btnbrowse_clicked" swapped="no"/>
</object>
Expand Down Expand Up @@ -380,7 +373,7 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<child>
<object class="GtkTable" id="dbms_parambox">
<property name="can_focus">False</property>
<property name="n_rows">5</property>
<property name="n_rows">6</property>
<property name="n_columns">2</property>
<child>
<object class="GtkLabel" id="label6">
Expand Down Expand Up @@ -410,8 +403,8 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="label" translatable="yes">User:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
Expand All @@ -422,8 +415,8 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="label" translatable="yes">Password:</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
Expand All @@ -434,8 +427,8 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="label" translatable="yes">Pictures root:</property>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -489,24 +482,23 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="passwd_chkbx">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_check_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -537,7 +529,6 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="activate" handler="on_pictureroot2_btnbrowse_clicked" swapped="no"/>
<signal name="clicked" handler="on_pictureroot2_btnbrowse_clicked" swapped="no"/>
</object>
Expand All @@ -551,8 +542,38 @@ Click on &lt;b&gt;Add&lt;/b&gt; to create a new connection.</property>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Port:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="port_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<property name="invisible_char_set">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
</object>
Expand Down
17 changes: 10 additions & 7 deletions bauble/connmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class ConnMgrPresenter(GenericEditorPresenter):
'file_entry': 'filename',
'database_entry': 'database',
'host_entry': 'host',
'port_entry': 'port',
'user_entry': 'user',
'passwd_chkbx': 'passwd',
'pictureroot2_entry': 'pictureroot',
Expand All @@ -225,7 +226,7 @@ class ConnMgrPresenter(GenericEditorPresenter):
view_accept_buttons = ['cancel_button', 'connect_button']

def __init__(self, view=None):
self.filename = self.database = self.host = self.user = \
self.filename = self.database = self.host = self.port = self.user = \
self.pictureroot = self.connection_name = \
self.prev_connection_name = None
self.use_defaults = True
Expand Down Expand Up @@ -510,7 +511,7 @@ def parameters_to_uri(self, params):
uri = "sqlite:///" + filename
return uri
subs['type'] = params['type'].lower()
if 'port' in params:
if params.get('port') is not None:
template = "%(type)s://%(user)s@%(host)s:%(port)s/%(db)s"
else:
template = "%(type)s://%(user)s@%(host)s/%(db)s"
Expand Down Expand Up @@ -564,20 +565,20 @@ def check_parameters_valid(self, params):
msg = _("Ghini does not have permission to "
"write to the database file:\n\n%s") % filename
else:
fields = []
missing_fields = []
if params["user"] == "":
valid = False
fields.append(_("user name"))
missing_fields.append(_("user name"))
if params["db"] == "":
valid = False
fields.append(_("database name"))
missing_fields.append(_("database name"))
if params["host"] == "":
valid = False
fields.append(_("DBMS host name"))
missing_fields.append(_("DBMS host name"))
if not valid:
msg = _("Current connection does not specify the fields:\n"
"%s\n"
"Please specify and try again.") % "\n".join(fields)
"Please specify and try again.") % "\n".join(missing_fields)
if not valid:
return valid, msg
## now check the params['pictures']
Expand Down Expand Up @@ -617,6 +618,7 @@ def get_params(self, new=None):
else:
result = {'db': self.database,
'host': self.host,
'port': self.port,
'user': self.user,
'pictures': self.pictureroot,
'passwd': self.passwd,
Expand All @@ -635,6 +637,7 @@ def set_params(self, params=None):
else:
self.database = params['db']
self.host = params['host']
self.port = params.get('port')
self.user = params['user']
self.pictureroot = params.get('pictures', '')
self.passwd = params['passwd']
Expand Down

0 comments on commit c2326bc

Please sign in to comment.