Reply To: Jivelite reboot und shutdows

Max2Play Home Forums Max2Play as Squeezebox (Player / Server) Jivelite reboot und shutdows Reply To: Jivelite reboot und shutdows

23. Januar 2016 at 13:33 #18101

Hi,

very nice idea 🙂
And it’s simple – I’ve just copied the KodiControl folder to to PowerControl (in /opt/jivelite/jivelite/share/jive/applets/)

And then modified the files:
PowerControlApplet.lua (renamed KodiControlApplet.lua)

 --[[
 =head1 NAME
 
 applets.PowerControl.PowerControlApplet - PowerControl Applet
 
 =head1 DESCRIPTION
 
 Reboot and Shutdown from Jivelite
 Author: Stefan Rick | Max2Play 2015 | modified by me
  
 =head1 FUNCTIONS
 
 Applet related methods are described in L<jive.Applet>. 
 
 =cut
 --]]
 
 
 -- stuff we use
 local tostring = tostring
 local os		      = require("os")
 local oo                     = require("loop.simple")
 local string                 = require("string")
 
 local Applet                 = require("jive.Applet")
 local RadioButton            = require("jive.ui.RadioButton")
 local RadioGroup             = require("jive.ui.RadioGroup")
 local Window                 = require("jive.ui.Window")
 local Popup                  = require("jive.ui.Popup")
 local Textarea               = require('jive.ui.Textarea')
 local SimpleMenu             = require("jive.ui.SimpleMenu")

 module(...)
 oo.class(_M, Applet)
 
 function menu(self, menuItem)
 
       log:info("menu")
       local group = RadioGroup()
       local currentSetting = self:getSettings().currentSetting
 
       -- create a SimpleMenu object with selections to be created
       local menu = SimpleMenu("menu", {
               -- first menu item
               {

                       -- text for the menu item
                       text = self:string("POWER RESTART"),
                       -- add a radiobutton with a callback function to be used when selected
                       icon = RadioButton(
                               -- skin style of radio button (defined in DefaultSkin)
                               "radio",
                               -- group to attach button
                               group,
                               -- callback function
                               function()
                                       log:info("Reboot")
   				       os.execute("sudo reboot")
			       end
                       ),
               },
               {
                       text = self:string("POWER SHUTDOWN"),
                       icon = RadioButton(
                               "radio",
                               group,
                               function()
					os.execute("sudo shutdown now")
                               end
                       ),
               }
       })
 
       -- create a window object
       local window = Window("window", self:string("POWER CONTROL")) 
 
       -- add the SimpleMenu to the window
       window:addWidget(menu)
 
       -- show the window
       window:show()
 end
 
 function warnMasses(self, warning)
       log:info(self:string(warning))
 
       -- create a Popup object, using already established 'toast_popup_text' skin style
       local powercontrol = Popup('toast_popup_text')
 
       -- add message to popup
       local powercontrolMessage = Group("group", {
                       text = Textarea('toast_popup_textarea',self:string(warning)),
             })
       powercontrol:addWidget(powercontrolMessage)
 
       -- display the message for 3 seconds
       powercontrol:showBriefly(3000, nil, Window.transitionPushPopupUp, Window.transitionPushPopupDown)
 end

PowerControlMeta.lua (renamed KodiControlMeta.lua)

 local oo            = require("loop.simple")
 local AppletMeta    = require("jive.AppletMeta")
 local appletManager = appletManager
 local jiveMain      = jiveMain
 
 module(...)
 oo.class(_M, AppletMeta)
  
 function jiveVersion(meta)
       return 1, 1
 end
 
 function defaultSettings(meta)
       return {
               currentSetting = 0,
       }
 end
 
 function registerApplet(meta)
       jiveMain:addItem(meta:menuItem('powercontrolapplet', 'home', "POWERCONTROL", function(applet, ...) applet:menu(...) end, 1000))
 end

and the strings.txt

#
# The two letter codes are defined by ISO 639-1
# http://en.wikipedia.org/wiki/List_of_ISO_639_codes

POWER RESTART
	EN	Reboot
	DE	Neustart
POWER SHUTDOWN
	EN	Shutdown
	DE	Herunterfahren
POWERCONTROL
	EN	Reboot and Shutdown
	DE	Neustart und Herunterfahren
POWER CONTROL
	EN	Reboot and Shutdown
	DE	Neustart und Herunterfahren

Works like a charm 🙂

PS: OK, wäre auch in deutsch gegangen – sollte hoffentlich aber auch so verständlich sein 😉