#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 
# Graphical tool to change timezone settings.
# 
# Author: JM. Philippe <jean-michel.philippe@doudoulinux.org>
#################################
# This file is part of DoudouLinux.
#
# DoudouLinux 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.
#
# DoudouLinux 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 DoudouLinux.  If not, see <http://www.gnu.org/licenses/>.

############################
import sys, os, gtk, gettext

############################
# register the lib directory
if os.path.isfile("/usr/lib/system-tools/timezone_widget.py"):
    # use the system directory
    sys.path.append("/usr/lib/system-tools")
else:
    # use the source code directory
    ScriptDir = os.path.dirname(__file__)
    sys.path.append( os.path.join(ScriptDir, "lib") )

from timezone_widget import TzWidget
from common import DataDir

############################
# create a window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_size_request(600, 380)
window.set_title( _("Timezone settings") )
window.set_icon_from_file(  os.path.join(DataDir, "icons", "timezone.png") )

############################
# create containers
container = gtk.VBox()
buttons = gtk.HBox()

############################
# create the ok button
ok = gtk.Button(stock="gtk-apply")
ok.set_use_stock(True)
buttons.pack_end(ok, False, False, 4)

############################
# create the cancel button
cancel = gtk.Button(stock="gtk-cancel")
cancel.set_use_stock(True)
buttons.pack_end(cancel, False, False, 4)

############################
# add the timezone widget
tzw = TzWidget(window)      #, debug=True)
#window.add( tzw.root() )
container.pack_start(tzw.root(), True, True, 4)
container.pack_start(buttons, False, False, 4)
window.add(container)

############################
# set bindings
def quit(*args):
    tzw.set_timezone()
    tzw.exit()
    gtk.main_quit()
def cancelquit(*args):
    tzw.exit()
    gtk.main_quit()
window.connect("delete-event", cancelquit)
window.connect("destroy", cancelquit)
ok.connect("clicked", quit)
cancel.connect("clicked", cancelquit)

############################
# show window
window.show_all()
window.present()

gtk.main()
