Skip to content

Commit

Permalink
[MetaSearch] allow for overwriting OWS connections, or assiging to se…
Browse files Browse the repository at this point in the history
…rialized string
  • Loading branch information
tomkralidis committed Mar 16, 2015
1 parent 8561b45 commit ff52a05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions python/plugins/MetaSearch/dialogs/maindialog.py
Expand Up @@ -52,7 +52,8 @@
from MetaSearch.dialogs.xmldialog import XMLDialog
from MetaSearch.util import (get_connections_from_file, get_ui_class,
get_help_url, highlight_xml, normalize_text,
open_url, render_template, StaticContext)
open_url, render_template, serialize_string,
StaticContext)

BASE_CLASS = get_ui_class('maindialog.ui')

Expand Down Expand Up @@ -648,6 +649,8 @@ def navigate(self):
def add_to_ows(self):
"""add to OWS provider connection list"""

conn_name_matches = []

item = self.treeRecords.currentItem()

if not item:
Expand Down Expand Up @@ -678,13 +681,19 @@ def add_to_ows(self):
keys = self.settings.childGroups()
self.settings.endGroup()

for key in keys:
if key.startswith(sname):
conn_name_matches.append(key)
if conn_name_matches:
sname = matches[-1]

# check for duplicates
if sname in keys:
msg = self.tr('Connection %s exists. Overwrite?') % sname
res = QMessageBox.warning(self, self.tr('Saving server'), msg,
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
return
if res != QMessageBox.Yes: # assign new name with serial
sname = serialize_string(sname)

# no dups detected or overwrite is allowed
self.settings.beginGroup('/Qgis/connections-%s' % stype[1])
Expand Down
16 changes: 16 additions & 0 deletions python/plugins/MetaSearch/util.py
Expand Up @@ -146,3 +146,19 @@ def normalize_text(text):
"""tidy up string"""

return text.replace('\n', '')


def serialize_string(input_string):
"""apply a serial counter to a string"""

s = input_string.strip().split()

last_token = s[-1]
all_other_tokens_as_string = input_string.replace(last_token, '')

if last_token.isdigit():
value = '%s%s' % (all_other_tokens_as_string, int(last_token) + 1)
else:
value = '%s 1' % input_string

return value

0 comments on commit ff52a05

Please sign in to comment.