name = "Name"
desc = "Set System's Hostname"

from gtk import *
from GTK import *

from utils import *
         
class applet(Applet):
    def __init__(self):
        import string

        Applet.__init__(self)
        self.box = GtkVBox()
        self.add(self.box)
        self.box.show()

        lbl = GtkLabel('System Name')
        self.box.pack_start(lbl,expand=FALSE)
        lbl.show()

        try:
            f = open('/etc/hostname','r')
            hostname = string.strip(f.read())
            f.close()
        except:
            hostname = ''
            
        self.name = GtkEntry()
        self.name.set_text(hostname)
        self.box.pack_start(self.name,expand=FALSE)
        self.name.show()


    def save(self,msgbox=FALSE):
        import os
        ret = os.system('/bin/hostname %s' % self.name.get_text())
        if ret == 0:
            msg = 'System Name Set!'
        else:
            msg = 'System Name Not Set! Error!'
        try:
            f = open('/etc/hostname','w')
            f.write('%s\n' % self.name.get_text())
            f.close()
        except:
            pass
        
        ret = Applet.save(self,msgbox)
        
applet_instance = applet()
