# $Id: config.rb,v 1.42 2004/04/28 13:17:58 eto Exp $
# Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL2.

require 'qwik/qp'
require 'getopts'
require 'pathname'

module Qwik
  class Config
    def initialize(debug=false, test=false)
      @debug = debug
      @test  = test
      File.umask(0)

      @version = "0.2.2"
      @release_date = "20040501"

      @base_dir = File.expand_path(File.dirname(__FILE__)+"/../../")
      @bin_dir  = @base_dir+"/bin"
      @lib_dir  = @base_dir+"/lib"
      @log_dir  = @base_dir+"/log"
      @etc_dir  = @base_dir+"/etc"
      @data_dir = @base_dir+"/data"
      @plugin_glob = @lib_dir+"/qwik/ext_*.rb"

      @cache_dir = @base_dir+"/cache"
      @super_dir = @lib_dir+"/super"
      @theme_dir = @lib_dir+"/theme"
#      @theme_dir = @base_dir+"/theme"
      @template_dir = @lib_dir+"/template"
      @grave_dir = @base_dir+"/grave"

      @pass_file = @etc_dir+'/password.txt'
      @pid_file = @log_dir+"/qwikweb.pid"
      @log_file = @log_dir+"/qwikweb.log"
      @accesslog_file = @log_dir+"/access.log"

      @default_hostname = "qwik.jp"
      @smtp_host = '127.0.0.1' # normal mail
      @smtp_port = '25'
      @qml_host = '127.0.0.1' # mail for QuickML
      @qml_port = '10025'

      @bind_address = "0.0.0.0"
      @port = 9190
      @ssl = false

      @default_theme = "qwikgreen"

      init_pagenames

      instance_variables.each {|name|
	self.class.class_eval { attr_reader name.delete('@') }
      }

      if @debug # for test
	instance_variables.each {|name|
	  self.class.class_eval { attr_writer name.delete('@') }
	}
      end
    end

    def parse_argv(argv)
      getopts("ds", 'p:', 'h:', 'm:', 't:')
      @debug = true if $OPT_d
      @port = $OPT_p.to_i if $OPT_p
      @default_hostname = $OPT_h.to_s if $OPT_h
      @ssl = true if $OPT_s
    end

    def init_pagenames
      @frontpage = "FrontPage"
      @siteconfig = "SiteConfig"
      @sitemember = "SiteMember"
      @sidemenu = "SideMenu"
      @topmenu = "TopMenu"
      @textformat = "TextFormat"
#      @interwiki = "InterWikiName"
      @getpass = "GetPass"
      @logoutpage = "LogoutPage"
      @editorfooter = "EditorFooter"
      @pagefooter = "PageFooter"
    end
  end
end
