~bzr/ubuntu/lucid/qbzr/bzr-ppa

« back to all changes in this revision

Viewing changes to lib/config.py

  • Committer: Max Bowsher
  • Date: 2011-02-09 04:34:06 UTC
  • mfrom: (0.250.10 lucid)
  • Revision ID: maxb@f2s.com-20110209043406-12tctou1pcpylqhu
Merge beta-ppa into ppa upon release of 0.20.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import os.path
22
22
from PyQt4 import QtCore, QtGui
23
23
from bzrlib.config import (
24
 
    GlobalConfig,
25
24
    ensure_config_dir_exists,
26
25
    extract_email_address,
27
26
    )
34
33
    BTN_CANCEL,
35
34
    QBzrDialog,
36
35
    extract_name,
37
 
    QBzrGlobalConfig,
 
36
    get_qbzr_config,
 
37
    get_global_config,
38
38
    )
39
39
 
40
40
 
256
256
 
257
257
    def load(self):
258
258
        """Load the configuration."""
259
 
        config = GlobalConfig()
 
259
        config = get_global_config()
260
260
        parser = config._get_parser()
261
261
        
262
 
        qconfig = QBzrGlobalConfig()
263
 
        qparser = qconfig._get_parser()
 
262
        qconfig = get_qbzr_config()
264
263
 
265
264
        # Name & e-mail
266
265
        try:
326
325
            item.setText(1, value)
327
326
        
328
327
        # Diff
329
 
        self.diffShowIntergroupColors.setChecked(qconfig.get_user_option("diff_show_intergroup_colors") in ("True", "1"))
330
 
        defaultDiff = qconfig.get_user_option("default_diff")
 
328
        self.diffShowIntergroupColors.setChecked(qconfig.get_option("diff_show_intergroup_colors") in ("True", "1"))
 
329
        defaultDiff = qconfig.get_option("default_diff")
331
330
        if defaultDiff is None:
332
331
            defaultDiff = ""
333
332
 
352
351
                      QtCore.Qt.ItemIsEnabled |
353
352
                      QtCore.Qt.ItemIsUserCheckable)        
354
353
        
355
 
        extDiffs = qparser.get('EXTDIFF', {})
 
354
        extDiffs = qconfig.get_section('EXTDIFF')
356
355
        for name, command in extDiffs.items():
357
356
            create_ext_diff_item(name, command)
358
357
        self.extDiffListIgnore = False
359
358
 
360
359
        # Merge
361
 
        bzr_config = GlobalConfig()
 
360
        bzr_config = get_global_config()
362
361
        defaultMerge = bzr_config.get_user_option("external_merge")
363
362
        if defaultMerge is None:
364
363
            defaultMerge = ""
385
384
 
386
385
    def save(self):
387
386
        """Save the configuration."""
388
 
        config = GlobalConfig()
 
387
        config = get_global_config()
389
388
        parser = config._get_parser()
390
389
 
391
 
        qconfig = QBzrGlobalConfig()
392
 
        qparser = qconfig._get_parser()
 
390
        qconfig = get_qbzr_config()
393
391
 
394
392
        def set_or_delete_option(parser, name, value):
395
393
            if value:
450
448
                parser['DEFAULT']['bugtracker_%s_url' % abbrev] = url
451
449
 
452
450
        # Diff
453
 
        set_or_delete_option(qparser, 'diff_show_intergroup_colors',
454
 
                             self.diffShowIntergroupColors.isChecked())
 
451
        qconfig.set_option('diff_show_intergroup_colors',
 
452
                           self.diffShowIntergroupColors.isChecked())
 
453
        
455
454
        defaultDiff = None
456
 
        
457
 
        qparser['EXTDIFF'] = {}
 
455
        ext_diffs = {}
458
456
        for index in range(1, self.extDiffList.topLevelItemCount()):
459
457
            item = self.extDiffList.topLevelItem(index)
460
458
            name = unicode(item.text(0))
462
460
            if item.checkState(0) == QtCore.Qt.Checked:
463
461
                defaultDiff = command
464
462
            if name and command:
465
 
                qparser['EXTDIFF'][name] = command
466
 
        set_or_delete_option(qparser, 'default_diff',
467
 
                             defaultDiff)
 
463
                ext_diffs[name] = command
 
464
        qconfig.set_section('EXTDIFF', ext_diffs)
 
465
        qconfig.set_option('default_diff',
 
466
                           defaultDiff)
 
467
        
468
468
        # Merge        
469
469
        defaultMerge = None
470
470
        for index in range(self.extMergeList.topLevelItemCount()):
471
471
            item = self.extMergeList.topLevelItem(index)
472
472
            definition = unicode(item.text(0))
473
473
            if item.checkState(0) == QtCore.Qt.Checked:
474
 
                defaultMerge = definition            
 
474
                defaultMerge = definition
475
475
            
476
476
        set_or_delete_option(parser, 'external_merge',
477
477
                             defaultMerge)
478
478
        
479
 
        def save_config(config, parser):
480
 
            ensure_config_dir_exists(os.path.dirname(config._get_filename()))
481
 
            f = open(config._get_filename(), 'wb')
482
 
            parser.write(f)
483
 
            f.close()
 
479
        if hasattr(config, 'file_name'):
 
480
            file_name = config.file_name
 
481
        else:
 
482
            file_name = config._get_filename()
 
483
        ensure_config_dir_exists(os.path.dirname(file_name))
 
484
        f = open(file_name, 'wb')
 
485
        parser.write(f)
 
486
        f.close()
484
487
        
485
 
        save_config(config, parser)
486
 
        save_config(qconfig, qparser)
 
488
        qconfig.save()
487
489
 
488
490
    def do_accept(self):
489
491
        """Save changes and close the window."""