Source

rfremix firstboot module / rfremix.py

# -*- coding: utf-8 -*-
#
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2.  This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# Authors: Russian Fedora Team. http://russianfedora.ru
#
import gtk

from firstboot.config import *
from firstboot.constants import *
from firstboot.functions import *
from firstboot.module import *

import gettext
_ = lambda x: gettext.ldgettext("firstboot", x)
N_ = lambda x: x

class moduleClass(Module):
    def __init__(self):
        Module.__init__(self)
        self.priority = 0
        # self.priority = 99
        self.sidebarTitle = N_("RFRemix configure")
        self.title = N_("RFRemix configure")
        self.icon = "workstation.png"

    def apply(self, interface, testing=False):
        if self.ch1.get_property('sensitive') and self.ch1.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t bool /apps/nautilus/preferences/always_use_browser true')
        if self.ch2.get_property('sensitive') and self.ch2.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t bool /desktop/gnome/interface/menu_have_icons true')
        if self.ch3.get_property('sensitive') and self.ch3.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t bool /desktop/gnome/interface/buttons_have_icons true')
        if self.ch5.get_property('sensitive') and self.ch5.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t bool /apps/gnome-terminal/global/use_menu_accelerators false')
        if self.ch6.get_property('sensitive') and self.ch6.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t list --list-type=string /apps/gedit-2/preferences/encodings/auto_detected "[UTF-8,CURRENT,WINDOWS-1251,KOI8R,ISO-8859-5]"')
        if self.ch7.get_property('sensitive') and self.ch7.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t int /apps/eog/ui/image_collection_position 3')
        if self.ch8.get_property('sensitive') and self.ch8.state == 1:
            os.system('/usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t int /apps/panel/toplevels/top_panel/padding 0; /usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t int /apps/panel/toplevels/bottom_panel/padding 0; /usr/bin/gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t int /apps/panel/applets/systray/prefs/padding 0')
        if self.ch15.get_property('sensitive') and self.ch15.state == 1:
            os.system('sed -i "s!UseNetworkManager=true!UseNetworkManager=false!g" /etc/PackageKit/PackageKit.conf; sed -i "s!UseNetworkHeuristic=true!UseNetworkHeuristic=false!g" /etc/PackageKit/PackageKit.conf')
        if self.button.get_property('sensitive'):
            if self.button.state == 0: # 0 is for rf-fonts
                os.system('/usr/sbin/freetype-backend rfremix')
            else: # 1 or else is for original fonts
                os.system(' /usr/sbin/freetype-backend fedora')
        if self.wmanager_button.get_property('sensitive'):
            if self.wmanager_button.state == 0: # gdm
                print "yeeeeah! GDM!"
            else: # kdm
                print "woohooo!! KDM!!"
        return RESULT_SUCCESS

    def createScreen(self):
        self.vbox = gtk.VBox()

        label = gtk.Label(_("Now your can enable some parameters, which are disabled in original\n"
                            "Fedora, such as fonts style, icons, encoding autodetection and others.\n"
                            "These are global parameter, they will be enabled for all users."))
        label.set_line_wrap(True)
        label.set_alignment(0.0, 0.5)
        label.set_size_request(500, -1)

        self.vbox.pack_start(label, False, False, 10)
        
        notebook = gtk.Notebook()
        
        ## Here goes first tab of notebook
        first_tab_vbox = gtk.VBox()
        
        label = gtk.Label(_("<b>GNOME Preferences (if GConf installed)</b>"))
        label.set_use_markup(True)
        label.set_line_wrap(True)
        label.set_alignment(0.0, 0.5)
        label.set_size_request(500, -1)
        
        first_tab_vbox.pack_start(label, False, True, 10)

        self.ch1 = gtk.CheckButton(label=_('Use single window mode in Nautilus'))
        first_tab_vbox.pack_start(self.ch1, False, True, 1)
        self.ch2 = gtk.CheckButton(label=_('Turn on icons in menus'))
        first_tab_vbox.pack_start(self.ch2, False, True, 1)
        self.ch3 = gtk.CheckButton(label=_('Turn on icons on buttons'))
        first_tab_vbox.pack_start(self.ch3, False, True, 1)
        self.ch5 = gtk.CheckButton(label=_('Disable menu accelerators in GNOME Terminal'))
        first_tab_vbox.pack_start(self.ch5, False, True, 1)
        self.ch6 = gtk.CheckButton(label=_('Autodetec windows-1251 encoding in Gedit'))
        first_tab_vbox.pack_start(self.ch6, False, True, 1)
        self.ch7 = gtk.CheckButton(label=_('Place collection right in the Eye of GNOME'))
        first_tab_vbox.pack_start(self.ch7, False, True, 1)
        self.ch8 = gtk.CheckButton(label=_('No padding between icons and applets in panels'))
        first_tab_vbox.pack_start(self.ch8, False, True, 1)

        label = gtk.Label(_("<b>System Preferences</b>"))
        label.set_use_markup(True)
        label.set_line_wrap(True)
        label.set_alignment(0.0, 0.5)
        label.set_size_request(500, -1)
        
        first_tab_vbox.pack_start(label, False, True, 10)

        self.ch15 = gtk.CheckButton(label=_('Let PackageKit work without network'))
        first_tab_vbox.pack_start(self.ch15, False, True, 1)

        self.ch1.set_active(True)
        self.ch2.set_active(True)
        self.ch5.set_active(True)
        self.ch6.set_active(True)
        self.ch8.set_active(True)
        self.ch15.set_active(True)
        if not os.path.exists('/usr/bin/gconftool-2'):
            self.ch1.set_sensitive(False)
            self.ch2.set_sensitive(False)
            self.ch3.set_sensitive(False)
            self.ch5.set_sensitive(False)
            self.ch6.set_sensitive(False)
            self.ch7.set_sensitive(False)
            self.ch8.set_sensitive(False)
        if not os.path.exists('/etc/PackageKit/PackageKit.conf'):
            self.ch15.set_sensitive(False)

        box2 = gtk.VBox()
        self.button = gtk.RadioButton(None, (_("Use Freetype built with BCL and SPR")))
        self.button.set_active(True)
        if not os.path.exists('/usr/sbin/freetype-backend'):
            self.button.set_sensitive(False)
        box2.pack_start(self.button)
        self.button = gtk.RadioButton(self.button, (_("Use Freetype as in Fedora")))
        if not os.path.exists('/usr/sbin/freetype-backend'):
            self.button.set_sensitive(False)
        box2.pack_start(self.button)
        
        first_tab_vbox.pack_start(box2, False, True, 0)
        
        notebook.append_page(first_tab_vbox, gtk.Label(_("first tab")))
        
        ## Here goes second tab of notebook
        second_tab_vbox = gtk.VBox()
        notebook.append_page(second_tab_vbox, gtk.Label(_("second tab")))
        
        label = gtk.Label(_("Choose window manager"))
        label.set_alignment(0.0, 0.5)
        second_tab_vbox.pack_start(label, False, True, 0)
        
        __active_already_set = False # is gdm is not present and someone is (kdm) -- let's set that one. Else -- gdm is active anyway.
        box = gtk.VBox()
        self.wmanager_button = gtk.RadioButton(None, (_("GDM (default)")))
        self.wmanager_button.set_active(True)
        if not os.path.exists('/usr/bin/gdm'):
            self.wmanager_button.set_sensitive(False)
        else:
            __active_already_set = True
        box.pack_start(self.wmanager_button)
        self.wmanager_button = gtk.RadioButton(self.wmanager_button, (_("KDM")))
        self.wmanager_button.set_active(True)
        if not os.path.exists('/usr/bin/kdm'):
            self.wmanager_button.set_sensitive(False)
        else:
            if __active_already_set is False:
                self.wmanager_button.set_active(True)
        
        box.pack_start(self.wmanager_button)
        
        second_tab_vbox.pack_start(box, False, True, 0)
        
        self.vbox.pack_start(notebook)
    
    def initializeUI(self):
        pass