From 019f801e5ae1c184cb45a9bcf5aff33eec812525 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 9 Mar 2010 23:28:45 +0100 Subject: [PATCH] Added wifi toggle --- README | 1 - hooks/wifi | 27 ++++++++++++++++ src/app_bluetooth.vala | 2 +- src/app_wifi.vala | 35 ++++++++++++++++++++ src/wifi.vala | 73 ++++++++++++++++++++++++++++++++++++++++++ src/zavai.vala | 2 ++ 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100755 hooks/wifi create mode 100644 src/app_wifi.vala create mode 100644 src/wifi.vala diff --git a/README b/README index 3639c33..85518e0 100644 --- a/README +++ b/README @@ -161,7 +161,6 @@ TODO list / wish list - turn on/off chip - start/stop wicd - start/stop wicd-client - - turn on/off bluetooth - alarm - play sound at alarm trigger - leave expired alarm on screen until acknowledged diff --git a/hooks/wifi b/hooks/wifi new file mode 100755 index 0000000..298a7b7 --- /dev/null +++ b/hooks/wifi @@ -0,0 +1,27 @@ +#!/bin/sh + +case "$1" in + # At the start of zavai + status) + if [ "`om wifi power`" = 1 ] + then + echo on + else + echo off + fi + ;; + # When starting wifi + start) + om wifi power 1 + ;; + # When stopping wifi + stop) + om wifi power 0 + ;; + *) + echo "Usage: $0 {start|stop|status}." >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/src/app_bluetooth.vala b/src/app_bluetooth.vala index acd3aa8..12a3b94 100644 --- a/src/app_bluetooth.vala +++ b/src/app_bluetooth.vala @@ -1,7 +1,7 @@ /* * app_bluetooth - zavai Bluetooth ui functions * - * Copyright (C) 2009 Enrico Zini + * Copyright (C) 2010 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/app_wifi.vala b/src/app_wifi.vala new file mode 100644 index 0000000..b694be5 --- /dev/null +++ b/src/app_wifi.vala @@ -0,0 +1,35 @@ +/* + * app_wifi - zavai Wifi ui functions + * + * Copyright (C) 2010 Enrico Zini + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +using GLib; + +namespace zavai { +namespace ui { +namespace wifi { + +public void init() +{ + // Menus + zavai.menu_misc.add_service_toggle(zavai.wifi.wifi, "Start Wifi", "Stop Wifi"); +} + +} +} +} diff --git a/src/wifi.vala b/src/wifi.vala new file mode 100644 index 0000000..f97242b --- /dev/null +++ b/src/wifi.vala @@ -0,0 +1,73 @@ +/* + * wifi - wifi resource for zavai + * + * Copyright (C) 2010 Enrico Zini + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +using GLib; + +namespace zavai { +namespace wifi { + +public class Wifi: zavai.Service +{ + public Wifi() + { + Object(name: "wifi"); + } + + /// Start wifi + public override void start() + { + if (started) return; + + try { + // Then run our own script + zavai.app.run_script(zavai.config.homedir + "/wifi start"); + } catch (Error e) { + zavai.log.error("Running " + zavai.config.homedir + "/wifi start: " + e.message); + return; + } + + zavai.log.info("wifi turned on"); + base.start(); + } + + // Release usage of wifi + public override void stop() + { + if (!started) return; + + try { + zavai.app.run_script(zavai.config.homedir + "/wifi stop"); + } catch (Error e) { + zavai.log.error("Running device stop wifi: " + e.message); + } + base.stop(); + } +} + +public Wifi wifi = null; + +public void init() +{ + wifi = new Wifi(); + +} + +} +} diff --git a/src/zavai.vala b/src/zavai.vala index c0f7240..3c3c55d 100644 --- a/src/zavai.vala +++ b/src/zavai.vala @@ -101,6 +101,7 @@ static int main (string[] args) { zavai.clock.init(); zavai.audio.init(); zavai.log.init(); + zavai.wifi.init(); zavai.bluetooth.init(); /* @@ -121,6 +122,7 @@ static int main (string[] args) { zavai.ui.wm.init(); zavai.ui.calendar.init(); zavai.ui.alarm.init(); + zavai.ui.wifi.init(); zavai.ui.bluetooth.init(); zavai.ui.debug.init(); -- 2.39.5