# -*- coding: utf-8 -*-

# Copyright (c) 2006 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the VCS configuration page.
"""

from ConfigurationPageBase import ConfigurationPageBase
from Ui_VcsPage import Ui_VcsPage

import Preferences

class VcsPage(ConfigurationPageBase, Ui_VcsPage):
    """
    Class implementing the VCS configuration page.
    """
    def __init__(self):
        """
        Constructor
        """
        ConfigurationPageBase.__init__(self)
        self.setupUi(self)
        self.setObjectName("VcsPage")
        
        # set initial values
        self.vcsAutoCloseCheckBox.setChecked(Preferences.getVCS("AutoClose"))
        self.vcsAutoSaveCheckBox.setChecked(Preferences.getVCS("AutoSaveFiles"))
        self.vcsAutoSaveProjectCheckBox.setChecked(\
            Preferences.getVCS("AutoSaveProject"))
        self.vcsStatusMonitorIntervalSpinBox.setValue(\
            Preferences.getVCS("StatusMonitorInterval"))
        svnOverride = Preferences.getVCS("SvnInterfaceGlobalOverride")
        try:
            import pysvn
        except ImportError:
            self.svnClientCombo.removeItem(2) # delete the pysvn entry
            if svnOverride == 2:
                svnOverride = 1
        self.svnClientCombo.setCurrentIndex(svnOverride)
        
    def save(self):
        """
        Public slot to save the VCS configuration.
        """
        Preferences.setVCS("AutoClose",
            int(self.vcsAutoCloseCheckBox.isChecked()))
        Preferences.setVCS("AutoSaveFiles",
            int(self.vcsAutoSaveCheckBox.isChecked()))
        Preferences.setVCS("AutoSaveProject",
            int(self.vcsAutoSaveProjectCheckBox.isChecked()))
        Preferences.setVCS("StatusMonitorInterval",
            self.vcsStatusMonitorIntervalSpinBox.value())
        Preferences.setVCS("SvnInterfaceGlobalOverride",
            self.svnClientCombo.currentIndex())
    
def create(dlg):
    """
    Module function to create the configuration page.
    
    @param dlg reference to the configuration dialog
    """
    page = VcsPage()
    return page
