#! /usr/bin/env python
# Creative Commons has made the contents of this file
# available under a CC-GNU-LGPL license:
#
# http://creativecommons.org/licenses/LGPL/2.1/
#
# A copy of the full license can be found as part of this
# distribution in the file COPYING.
# 
# You may use the liblicense software in accordance with the
# terms of that license. You agree that you are solely 
# responsible for your use of the liblicense software and you
# represent and warrant to Creative Commons that your use
# of the liblicense software will comply with the CC-GNU-LGPL.
#
# Copyright 2007, Creative Commons, www.creativecommons.org.
# Copyright 2007, Scott Shawcroft.

import liblicense
from liblicense.gui_gtk import *
import gtk

icon_location = "/usr/share/liblicense/icons"
if icon_location[0]=="@":
    icon_location="."
    
class DefaultLicense (gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)
        self.set_title("Default Content License")
        self.connect("destroy",self.save)
        
        box = gtk.VBox()
        box.show()
        box.set_border_width(4)
        self.add(box)
        
        #title
        title_box = gtk.HBox()
        title_box.set_border_width(4)
        icon = gtk.Image()
        icon.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file_at_size(icon_location + "/scales.svg", 48, 48))
        icon.show()
        title_box.pack_start(icon,False,False,5)
        
        label = gtk.Label("Default Content License")
        label.show()
        title_box.pack_start(label,False)
        title_box.show()
        box.pack_start(title_box)
        
        #widget
        frame = gtk.Frame()
        frame.show()
        frame.set_border_width(4)
        
        self.default = liblicense.get_default()
        self.chooser = LicenseWidget(self.default)
        self.chooser.show()
        self.chooser.set_border_width(4)
        frame.add(self.chooser)
        box.pack_start(frame)
        
        #buttons
        bbox = gtk.HButtonBox()
        bbox.show()
        box.pack_start(bbox)
        bbox.set_layout(gtk.BUTTONBOX_END)
        
        app = gtk.Button(stock=gtk.STOCK_CLOSE)
        app.show()
        app.connect("clicked",self.save)
        bbox.pack_end(app,False,False)
    
    def destroy(self,widget):
        gtk.main_quit()
    
    def run(self):
        gtk.main()
    
    def save(self,widget):
        liblicense.set_default(self.chooser.get_license())
        self.destroy(widget)
        

if __name__=="__main__":
    window = DefaultLicense()
    window.show()
    window.run()
