########################################################################
#
#  Copyright (C) 2009, CZ.NIC, z.s.p.o.
# 
#  This file is part of dnstester.
#
#  dnstester 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.
#
#  dnstester 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
########################################################################

import pygtk
pygtk.require("2.0")
import gtk, gobject

import lang
from page import Page
import images, labeltext

class PageSelectNetwork(Page):

    title = 'netsel_title'
    number = 3
    focus_label = None
    
    CONFIG_SIMPLE = 1
    CONFIG_COMPLEX = 2

    def __init__(self, parent):
        Page.__init__(self, parent)
        self.widget = self.create_vbox()

    def create_vbox(self):
        alignment = gtk.Alignment()
        alignment.set_padding(20, 20, 20, 0)
        vbox = gtk.VBox()
        vbox.set_spacing(10)

        label = labeltext.LabelText('netsel_intro', padding = 0)
        vbox.pack_start(label, False, False)
        
        radio1 = gtk.RadioButton(group=None)
        lang.bind(radio1, 'simple_network_config')
        vbox.pack_start(radio1, False, False)

        image1 = gtk.Image()
        image1.set_from_file(images.fullname('onebox.png'))
        image1.set_alignment(0.1, 0)

        eventbox1 = gtk.EventBox()
        eventbox1.add(image1)
        eventbox1.connect("button_press_event", self.on_img1_click)
        vbox.pack_start(eventbox1, False, False)

        radio2 = gtk.RadioButton(group=radio1)
        lang.bind(radio2, 'complex_network_config')
        vbox.pack_start(radio2, False, False)

        image2 = gtk.Image()
        image2.set_from_file(images.fullname('twoboxes.png'))
        image2.set_alignment(0.1, 0)

        eventbox2 = gtk.EventBox()
        eventbox2.add(image2)
        eventbox2.connect("button_press_event", self.on_img2_click)
        vbox.pack_start(eventbox2, False, False)

        radio1.set_active(True)
        self.radio1 = radio1
        self.radio2 = radio2

        alignment.add(vbox)
        alignment.show_all()
        return alignment

    def on_img1_click(self, caller, event):
        self.radio1.set_active(True)

    def on_img2_click(self, caller, event):
        self.radio2.set_active(True)

    def get_config(self):

        if self.radio2.get_active():
            return self.CONFIG_COMPLEX
        else:
            return self.CONFIG_SIMPLE

    def on_before_show(self):
        self.parent.prevent_last_button()
        Page.on_before_show(self)

        if self.radio1.get_active():
            self.radio1.grab_focus()
        else:
            self.radio2.grab_focus()

