#!/usr/bin/python2
# This file is part of SSHconf.
#
#    SSHconf is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    SSHconf is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with SSHconf.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Frank "ancho" Becker 
#
# Copyright 2010 Frank Becker <ancho@gmx.net>
'''
Created on 24.02.2010

@author: frank
'''

import ConfigParser
import os

class Settings():
    '''        
    This Class reads the Program Settings of sshconf
    '''
    
    def __init__(self):
        
        self.configfile = os.path.expanduser('~/.sshconf/sshconf.cfg')
        self.config = ConfigParser.ConfigParser()
        
        if( os.path.exists( os.path.expanduser('~/.sshconf') ) ):
            if( os.path.exists( self.configfile )):
                self.config.read( [self.configfile] )
            else:
                self.create_default_config()
        else:
            os.mkdir( os.path.expanduser('~/.sshconf') )
            self.create_default_config()
            
    
    def create_default_config(self):
        
        self.config.add_section('Main')
        self.config.set('Main', 'path', '~/.sshconf')
        self.config.set('Main', 'logfile', '%(path)s/sshconf.log')
        self.config.add_section('Terminal')
        self.config.set('Terminal', 'prog', '/usr/bin/x-terminal-emulator')
        self.config.set('Terminal', 'title_flag', '-T')
        
        self.save_config()
            
    def get_path(self):
        return self.config.get('Main', 'path')

    def set_path(self, path):
        self.config.set('Main', 'path', path)
    
    def get_logfile(self):
        return self.config.get('Main', 'logfile')

    def set_logfile(self, logfile):
        self.config.set('Main', 'logfile', logfile)

    def get_prog(self):
        return self.config.get('Terminal', 'prog')
        
    def set_prog(self, prog):
        self.config.set('Terminal', 'prog', prog)
    
    def get_titleflag(self):
        return self.config.get('Terminal', 'title_flag')
    
    def set_title_flag(self, title_flag):
        self.config.set('Terminal', 'title_flag', title_flag)
    
    def save_config(self):
        with open(self.configfile, 'wb') as configfile:
            self.config.write(configfile)
        