OSDN Git Service

add webkit_newui config option
[keitairc/keitairc.git] / lib / Keitairc / Config.pm
1 # -*- mode: perl; coding: utf-8 -*-
2 # Keitairc::Config
3 # $Id: Config.pm,v 1.36 2009-10-16 11:19:07 ishikawa Exp $
4 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/Keitairc/Config.pm,v $
5 #
6 # Copyright (c) 2008 Jun Morimoto <morimoto@mrmt.net>
7 # This program is covered by the GNU General Public License 2
8
9 package Keitairc::Config;
10 use AppConfig qw(:argcount);
11 use Cwd;
12 use Encode::MIME::Name;
13 use strict;
14 use warnings;
15 our @ISA = qw(AppConfig);
16
17 ################################################################
18 sub new{
19         my $class = shift;
20         my $arg = shift;
21         my @argv = @{$arg->{argv}};
22         my $me = $class->SUPER::new(
23                 {
24                         CASE => 1,
25                         GLOBAL => {
26                                 ARGCOUNT => ARGCOUNT_ONE,
27                         }
28                 },
29                 qw(irc_nick irc_username irc_desc
30                    irc_server irc_port irc_password
31                    irc_keyword irc_charset
32                    au_subscriber_id au_pcsv
33                    docomo_foma_icc docomo_imodeid
34                    softbank_serial_key emobile_userid
35                    use_cookie cookie_ttl session_ttl
36                    web_listen_port
37                    web_port web_title web_lines web_root web_schema
38                    web_username web_password web_host web_charset
39                    common_header extra_header
40                    fontsize mobile_fontsize silent_config
41                    show_newmsgonly show_joinleave show_console
42                    ping_delay reconnect_delay follow_nick
43                    smtp_server smtp_from smtp_to debug
44                    version daemonize pid_dir pid_file
45                    template_dir plugin_dir public_dir
46                    url_target url_redirect
47                    rgeocode_server
48                    reverse_message reverse_recent reverse_unread
49                    webkit_newui)
50                 );
51
52         # set default values
53         $me->version($arg->{version});
54         $me->silent_config($arg->{silent});
55         $me->irc_desc('keitairc');
56         $me->irc_port(6667);
57         $me->irc_charset('iso-2022-jp-1');
58         $me->web_port(8080);
59         $me->web_title('keitairc');
60         $me->web_lines(100);
61         $me->web_root('/');
62         $me->web_charset('shiftjis');
63         $me->web_schema('http');
64         $me->ping_delay(30);
65         $me->reconnect_delay(10);
66         $me->cookie_ttl(86400 * 3);  # 3 days
67         $me->session_ttl(60 * 30);  # 30 min
68         $me->au_subscriber_id('');
69         $me->docomo_foma_icc('');
70         $me->docomo_imodeid('');
71         $me->softbank_serial_key('');
72         $me->emobile_userid('');
73         $me->pid_dir('/var/run');
74         $me->pid_file('keitairc.pid');
75         $me->plugin_dir(getcwd() . '/lib/plugins:__KEITAIRC_DATA_DIR__/plugins');
76         $me->template_dir(getcwd() . '/lib/templates:__KEITAIRC_DATA_DIR__/templates');
77         $me->public_dir(getcwd() . '/lib/public:__KEITAIRC_DATA_DIR__/public');
78         $me->reverse_message(1);
79         $me->reverse_recent(1);
80         $me->reverse_unread(1);
81         $me->show_joinleave(1);
82         $me->show_console(0);
83         $me->fontsize('+0');
84         $me->mobile_fontsize(-1);
85         $me->url_target('_self');
86         $me->follow_nick(1);
87         $me->rgeocode_server('finds');
88         $me->common_header('
89 <meta name="Robots" content="noindex,nofollow" />
90 <meta name="Keywords" content="norobot" />
91 <meta http-equiv="pragma" content="no-cache" />
92 <meta http-equiv="cache-control" content="no-cache" />
93 <meta http-equiv="expires" content="-1" />');
94         $me->debug(0);
95         $me->daemonize(0);
96         $me->webkit_newui(1);
97
98         if(-r '/etc/keitairc'){
99                 $me->file('/etc/keitairc');
100         }
101         if(-r $ENV{HOME} . '/.keitairc'){
102                 $me->file($ENV{HOME} . '/.keitairc');
103         }
104
105         if(defined $argv[0]){
106                 if(-r $argv[0]){
107                         $me->file($argv[0]);
108                         shift(@argv);
109                 }
110         }
111
112         $me->args(\@argv);
113
114         if(defined $me->show_newmsgonly()){
115                 Keitairc::Log::log('show_newmsgonly has obsoleted from keitairc 2.0');
116         }
117
118         if(defined $me->web_username()){
119                 Keitairc::Log::log('web_username has obsoleted from keitairc 2.0');
120         }
121
122         if(defined $me->use_cookie()){
123                 Keitairc::Log::log('use_cookie has obsoleted from keitairc 2.0');
124         }
125
126         if(defined $me->au_pcsv()){
127                 Keitairc::Log::log('au_pcsv has obsoleted from keitairc 2.0');
128         }
129
130         if(!defined($me->irc_nick()) || !length($me->irc_nick())){
131                 Keitairc::Log::log_die('irc_nick does not specified');
132         }
133
134         if(!defined($me->irc_username()) || !length($me->irc_username())){
135                 Keitairc::Log::log_die('irc_username does not specified');
136         }
137
138         if(!defined($me->irc_server()) || !length($me->irc_server())){
139                 Keitairc::Log::log_die('irc_server does not specified');
140         }
141
142         if(!defined($me->web_listen_port()) || !length($me->web_listen_port())){
143                 $me->web_listen_port($me->web_port());
144         }
145
146         if(!defined($me->web_host()) || !length($me->web_host())){
147                 Keitairc::Log::log_die('web_host does not specified');
148         }
149
150         if(!defined($me->web_password()) || !length($me->web_password())){
151                 Keitairc::Log::log_die('web_password does not specified');
152         }
153
154         $me;
155 }
156
157 ################################################################
158 sub file{
159         my $me = shift;
160         my $file = shift;
161         if(-r $file){
162                 $me->SUPER::file($file);
163                 Keitairc::Log::log("Loaded configuration file: $file")
164                         unless $me->silent_config();
165                 return;
166         }
167         Keitairc::Log::log("$file does not exist");
168 }
169
170 ################################################################
171 sub content_charset{
172         my $me = shift;
173         Encode::MIME::Name::get_mime_name(Encode::resolve_alias($me->web_charset()));
174 }
175
176 1;