Reviewers: ,


Please review this at http://codereview.tryton.org/16001/

Affected files:
  M tryton/config.py
  M tryton/gui/main.py
  M tryton/gui/window/dbcreate.py
  M tryton/gui/window/dblogin.py


Index: tryton/config.py
===================================================================
--- a/tryton/config.py
+++ b/tryton/config.py
@@ -47,11 +47,15 @@
     "Config manager"

     def __init__(self):
+        short_version = '.'.join(VERSION.split('.', 2)[:2])
+        demo_server = 'demo%s.tryton.org' % short_version
+        demo_database = 'demo%s' % short_version
         self.defaults = {
-            'login.login': 'admin',
-            'login.server': 'localhost',
+            'login.profile': demo_server,
+            'login.login': 'demo',
+            'login.server': demo_server,
             'login.port': '8070',
-            'login.db': False,
+            'login.db': demo_database,
             'login.expanded': False,
             'tip.autostart': False,
             'tip.position': 0,
Index: tryton/gui/main.py
===================================================================
--- a/tryton/gui/main.py
+++ b/tryton/gui/main.py
@@ -1174,13 +1174,13 @@
                 raise
             return ([], [])

-    def sig_login(self, widget=None, profile_name=False, res=None):
+    def sig_login(self, widget=None, res=None):
         if not self.sig_logout(widget, disconnect=False):
             return
         if not res:
             try:
                 dblogin = DBLogin(self.window)
-                res = dblogin.run(profile_name, self.window)
+                res = dblogin.run(self.window)
             except Exception, exception:
                 if exception.args == ('QueryCanceled',):
                     return False
Index: tryton/gui/window/dbcreate.py
===================================================================
--- a/tryton/gui/window/dbcreate.py
+++ b/tryton/gui/window/dbcreate.py
@@ -1,14 +1,12 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
 from __future__ import with_statement
-import ConfigParser
-import os
 import gtk
 import gobject
 import gettext
 import re
 import tryton.common as common
-from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR, get_config_dir
+from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR
 import tryton.rpc as rpc

 _ = gettext.gettext
@@ -401,23 +399,11 @@
                         parent.present()
                         self.dialog.destroy()
                         if self.sig_login:
-                            profile_cfg = os.path.join(get_config_dir(),
-                                'profiles.cfg')
-                            profiles = ConfigParser.SafeConfigParser()
-                            if os.path.exists(profile_cfg):
-                                profiles.read(profile_cfg)
-                            i, profile_name = 0, dbname
-                            while profile_name in profiles.sections():
-                                i += 1
-                                profile_name = '%s_%s' % (dbname, i)
-                            profiles.add_section(profile_name)
-                            profiles.set(profile_name, 'host', host)
-                            profiles.set(profile_name, 'port', port)
-                            profiles.set(profile_name, 'database', dbname)
-                            profiles.set(profile_name, 'username', '')
-                            with open(profile_cfg, 'wb') as configfile:
-                                profiles.write(configfile)
-                            self.sig_login(profile_name=profile_name)
+                            CONFIG['login.server'] = host
+                            CONFIG['login.port'] = port
+                            CONFIG['login.db'] = dbname
+                            CONFIG['login.login'] = 'admin'
+                            self.sig_login()
                         break

             break
Index: tryton/gui/window/dblogin.py
===================================================================
--- a/tryton/gui/window/dblogin.py
+++ b/tryton/gui/window/dblogin.py
@@ -141,16 +141,22 @@
         self.dialog.set_default_size(640, 350)
         self.dialog.set_default_response(gtk.RESPONSE_ACCEPT)

-    def run(self):
+    def run(self, profile_name):
         self.dialog.show_all()
         self.clear_entries()
         model = self.profile_tree.get_model()
         if model:
-            self.profile_tree.get_selection().select_path((0,))
+            for i, row in enumerate(model):
+                if row[0] == profile_name:
+                    break
+            else:
+                i = 0
+            self.profile_tree.get_selection().select_path((i,))
             self.profile_selected(self.profile_tree)
         self.dialog.run()
         self.parent.present()
         self.dialog.destroy()
+        return self.current_profile['name']

     def _current_profile(self):
         model, selection = self.profile_tree.get_selection().get_selected()
@@ -463,10 +469,19 @@

     def profile_manage(self, widget):
         dia = DBListEditor(self.dialog, self.profile_store, self.profiles)
-        dia.run()
+        active_profile = self.combo_profile.get_active()
+        profile_name = None
+        if active_profile != -1:
+            profile_name = self.profile_store[active_profile][0]
+        profile_name = dia.run(profile_name)
         with open(self.profile_cfg, 'wb') as configfile:
             self.profiles.write(configfile)

+        for idx, row in enumerate(self.profile_store):
+            if row[0] == profile_name:
+                self.combo_profile.set_active(idx)
+                break
+
     def profile_changed(self, combobox):
         position = combobox.get_active()
         if position == -1:
@@ -514,26 +529,20 @@
         self.entry_database.props.visible = visibility
         self.label_database.props.visible = visibility

-    def run(self, profile_name, parent):
-        if not profile_name:
-            selected_profile = CONFIG['login.profile']
-            if not selected_profile:
-                short_version = '.'.join(VERSION.split('.', 2)[:2])
-                selected_profile = 'demo%s.tryton.org' % short_version
-        else:
-            selected_profile = profile_name
-        can_use_profile = self.profiles.has_section(selected_profile)
+    def run(self, parent):
+        profile_name = CONFIG['login.profile']
+        can_use_profile = self.profiles.has_section(profile_name)
         if can_use_profile:
             for (configname, sectionname) in (('login.server', 'host'),
                     ('login.port', 'port'), ('login.db', 'database')):
-                if (self.profiles.get(selected_profile, sectionname) != \
+                if (self.profiles.get(profile_name, sectionname) != \
                         CONFIG[configname]):
                     can_use_profile = False
                     break

         if can_use_profile:
             for idx, row in enumerate(self.profile_store):
-                if row[0] == selected_profile:
+                if row[0] == profile_name:
                     self.combo_profile.set_active(idx)
                     break
         else:


--
[email protected] mailing list

Reply via email to