~hassan+af-2162-3524/openobject-client/login_profiles

« back to all changes in this revision

Viewing changes to bin/modules/gui/main.py

  • Committer: Scott Hassan
  • Date: 2012-02-03 06:04:37 UTC
  • Revision ID: hassan@iblue.dotfunk.com-20120203060437-25tb9y3mxhrly2bi
added the ability to have login profiles.  This are saved in the .openerprc file under urls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import os
24
24
import gettext
25
25
import urlparse
 
26
import string
26
27
 
27
28
import gobject
28
29
import gtk
399
400
        lang_widget.set_active(active_idx)
400
401
    return lang_list
401
402
 
402
 
def _server_ask(server_widget, parent=None):
 
403
def _server_ask(combo_server, server_liststore, parent=None):
403
404
    result = False
404
405
    ui = openerp_gtk_builder('openerp.ui', ['win_server', 'liststore5'])
405
406
    win = ui.get_object('win_server')
424
425
    listprotocol = gtk.ListStore(str)
425
426
    protocol_widget.set_model(listprotocol)
426
427
 
427
 
    m = re.match('^(http[s]?://|socket://)([\w.-]+):(\d{1,5})$', server_widget.get_text())
 
428
    m = re.match('^(http[s]?://|socket://)([\w.-]+):(\d{1,5})$', combo_server.get_active_text())
428
429
    if m:
429
430
        host_widget.set_text(m.group(2))
430
431
        port_widget.set_text(m.group(3))
442
443
    if res == gtk.RESPONSE_OK:
443
444
        protocol = protocol[protocol_widget.get_active_text()]
444
445
        url = '%s%s:%s' % ((protocol).strip(), (host_widget.get_text()).strip(), (port_widget.get_text()).strip())
445
 
        server_widget.set_text(url)
 
446
        iter = server_liststore.get_iter_root()
 
447
        while iter:
 
448
            if server_liststore.get_value(iter, 0)==url:
 
449
                combo_server.set_active_iter(iter)
 
450
                break
 
451
            iter = server_liststore.iter_next(iter)
 
452
        if not iter:
 
453
            iter = server_liststore.append([url])
 
454
            combo_server.set_active_iter(iter)
446
455
        result = url
447
456
    parent.present()
448
457
    win.destroy()
457
466
    def refreshlist(self, widget, db_widget, entry_db, label, url, butconnect=False):
458
467
        return _refresh_dblist(db_widget, entry_db, label, butconnect, url)
459
468
 
460
 
    def refreshlist_ask(self,widget, server_widget, db_widget, entry_db, label, butconnect = False, url=False, parent=None):
461
 
        url = _server_ask(server_widget, parent) or url
 
469
    def refreshlist_ask(self,widget, combo_server, server_liststore, db_widget, entry_db, label, butconnect = False, url=False, parent=None):
 
470
        url = _server_ask(combo_server, server_liststore, parent) or url
 
471
        return self.refreshlist(widget, db_widget, entry_db, label, url, butconnect)
 
472
    def refreshserver(self,widget, combo_server, server_liststore, db_widget, entry_db, 
 
473
                      label, butconnect = False, url=False, parent=None):
 
474
        url = combo_server.get_active_text()
462
475
        return self.refreshlist(widget, db_widget, entry_db, label, url, butconnect)
463
476
 
464
477
    def run(self, dbname=None, parent=None):
472
485
        win.show_all()
473
486
        img = self.ui.get_object('image_tinyerp')
474
487
        img.set_from_file(common.terp_path_pixmaps('openerp.png'))
475
 
        login = self.ui.get_object('ent_login')
 
488
        ent_login = self.ui.get_object('ent_login')
476
489
        passwd = self.ui.get_object('ent_passwd')
477
 
        server_widget = self.ui.get_object('ent_server')
 
490
        ent_server = self.ui.get_object('ent_server')
478
491
        but_connect = self.ui.get_object('button_connect')
479
492
        combo_db = self.ui.get_object('combo_db')
 
493
        combo_server = self.ui.get_object('combo_server')
480
494
        entry_db = self.ui.get_object('ent_db_login')
481
495
        change_button = self.ui.get_object('but_server')
482
496
        label = self.ui.get_object('combo_label')
 
497
        combo_label_server = self.ui.get_object('combo_label_server')
483
498
#        db_entry = self.ui.get_object('ent_db_login')
484
499
        label.hide()
485
500
        entry_db.hide()
486
 
 
487
 
        host = options.options['login.server']
488
 
        port = options.options['login.port']
489
 
        protocol = options.options['login.protocol']
 
501
        ent_server.hide()
 
502
        combo_label_server.hide()
 
503
 
 
504
        server_liststore = gtk.ListStore(str)
 
505
        server_liststore.clear()
 
506
 
 
507
        try:
 
508
            url_str = options.options['login.urls']
 
509
        except KeyError:
 
510
            _protocol = options.options.get('login.protocol', 'socket://')
 
511
            _port = options.options.get('login.port', '8070')
 
512
            _server = options.options.get('login.server', 'localhost')
 
513
            url_str = "%s%s:%s" % (_protocol, _server, _port)
 
514
 
 
515
        urls = []
 
516
        urlparts = url_str.split(",")
 
517
        for url in urlparts:
 
518
            server_liststore.append([url])
 
519
 
 
520
            (protocol, rest) = url.split("://", 1)
 
521
            protocol = protocol + "://"
 
522
            host, port = rest.split(":", 1)
 
523
 
 
524
            urls.append((protocol, host, port))
 
525
            urls.append(url)
 
526
 
 
527
        protocol, host, port= urls[0]
490
528
 
491
529
        url = '%s%s:%s' % (protocol, host, port)
492
 
        server_widget.set_text(url)
493
 
        login.set_text(options.options['login.login'])
 
530
        ent_server.set_text(url)
 
531
        
 
532
        combo_server.set_model(server_liststore)
 
533
        username = options.options['login.login']
 
534
        ent_login.set_text(username)
 
535
 
 
536
        cell = gtk.CellRendererText()
 
537
        combo_server.pack_start(cell, True)
 
538
        combo_server.add_attribute(cell, 'text', 0)
 
539
 
 
540
        lasturl = options.options.get('login.url', '')
 
541
        
 
542
        if lasturl:
 
543
            iter = server_liststore.get_iter_root()
 
544
            while iter:
 
545
                if server_liststore.get_value(iter, 0)==lasturl:
 
546
                    combo_server.set_active_iter(iter)
 
547
                    break
 
548
                iter = server_liststore.iter_next(iter)
494
549
 
495
550
        # construct the list of available db and select the last one used
496
551
        liststore = gtk.ListStore(str)
500
555
        combo_db.add_attribute(cell, 'text', 0)
501
556
 
502
557
        res = self.refreshlist(None, combo_db, entry_db, label, url, but_connect)
503
 
        change_button.connect_after('clicked', self.refreshlist_ask, server_widget, combo_db, entry_db, label, but_connect, url, win)
 
558
        change_button.connect_after('clicked', self.refreshlist_ask, combo_server, server_liststore, combo_db, entry_db, label, but_connect, url, win)
 
559
        combo_server.connect_after('changed', self.refreshserver, combo_server, server_liststore, combo_db, entry_db, label, but_connect, url, win)
504
560
 
505
561
        if dbname:
506
562
            iter = liststore.get_iter_root()
511
567
                iter = liststore.iter_next(iter)
512
568
 
513
569
        res = win.run()
514
 
        m = re.match('^(http[s]?://|socket://)([\w.\-]+):(\d{1,5})$', server_widget.get_text() or '')
 
570
 
 
571
        if combo_server.flags() & gtk.VISIBLE:
 
572
            server_url = combo_server.get_active_text()
 
573
        else:
 
574
            server_url = ent_server.get_text()
 
575
 
 
576
        m = re.match('^(http[s]?://|socket://)([\w.\-]+):(\d{1,5})$', server_url or '')
 
577
 
515
578
        if m:
516
579
            if combo_db.flags() & gtk.VISIBLE:
517
580
                dbname = combo_db.get_active_text()
518
581
            else:
519
582
                dbname = entry_db.get_text()
520
583
 
 
584
            urls = []
 
585
            iter = server_liststore.get_iter_root()
 
586
            while iter:
 
587
                urls.append(server_liststore.get_value(iter, 0))
 
588
                iter = server_liststore.iter_next(iter)
 
589
 
 
590
            options.options['login.urls'] = string.join(urls, ',')
 
591
            options.options['login.url'] = server_url
521
592
            options.options['login.server'] = m.group(2)
522
 
            options.options['login.login'] = login.get_text()
 
593
            options.options['login.login'] = ent_login.get_text()
523
594
            options.options['login.port'] = m.group(3)
524
595
            options.options['login.protocol'] = m.group(1)
525
596
            options.options['login.db'] = dbname
526
 
            result = (login.get_text(), passwd.get_text(), m.group(2), m.group(3), m.group(1), dbname)
 
597
            result = (ent_login.get_text(), passwd.get_text(), m.group(2), m.group(3), m.group(1), dbname)
527
598
        else:
528
599
            parent.present()
529
600
            win.destroy()