Skip to content

Commit

Permalink
Merge pull request #1 from WasabiFan/ev3dev-jessie
Browse files Browse the repository at this point in the history
Add IP address to status bar

Issue ev3dev/ev3dev#184
  • Loading branch information
dlech committed Oct 27, 2014
2 parents 7ee2b75 + 0dfc474 commit 4cdf6b5
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ set (BRICKMAN_COMMON_SOURCE_FILES
src/view/NetworkConnectionMenuItem.vala
src/view/NetworkConnectionsWindow.vala
src/view/NetworkPropertiesWindow.vala
src/view/NetworkStatusBarItem.vala
src/view/NetworkStatusWindow.vala
src/view/ShutdownDialog.vala
src/view/USBWindow.vala
Expand Down
19 changes: 18 additions & 1 deletion src/controller/NetworkController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace BrickManager {

NetworkStatusWindow status_window;
NetworkConnectionsWindow connections_window;
public NetworkStatusBarItem network_status_bar_item;
internal Binding status_bar_item_binding;
ConnManAgent agent;
Manager manager;
Technology? wifi_technology;
Expand All @@ -62,6 +64,8 @@ namespace BrickManager {
critical ("%s", err.message);
}
});

network_status_bar_item = new NetworkStatusBarItem();
}

async void init_async () throws IOError {
Expand Down Expand Up @@ -148,6 +152,10 @@ namespace BrickManager {
return true;
});
}
if(status_bar_item_binding != null)
status_bar_item_binding.unbind();
status_bar_item_binding = null;

changed.foreach ((service) => {
NetworkConnectionMenuItem menu_item;
if (service_map.has_key (service)) {
Expand All @@ -163,6 +171,15 @@ namespace BrickManager {
service_map[service] = menu_item;
}
connections_window.menu.add_menu_item (menu_item);

// Show the IP address of the primary service in the status bar
// The list is ordered, so the first one is the one we want
if(status_bar_item_binding == null) {
status_bar_item_binding = service.bind_property (
"ipv4", network_status_bar_item, "text",
BindingFlags.SYNC_CREATE, transform_service_ipv4_to_address_string);
}

});
}

Expand Down Expand Up @@ -473,4 +490,4 @@ namespace BrickManager {
return true;
}
}
}
}
1 change: 1 addition & 0 deletions src/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace BrickManager {
var home_window = new HomeWindow ();
var network_controller = new NetworkController ();
home_window.add_controller (network_controller);
ConsoleApp.screen.status_bar.add_left (network_controller.network_status_bar_item);
var usb_controller = new USBController ();
home_window.add_controller (usb_controller);
var battery_controller = new BatteryController ();
Expand Down
68 changes: 68 additions & 0 deletions src/view/NetworkStatusBarItem.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* brickman -- Brick Manager for LEGO Mindstorms EV3/ev3dev
*
* Copyright (C) 2014 WasabiFan <[email protected]>
*
* based on BatteryStatusBarItem.vala
* Copyright (C) 2014 David Lechner <[email protected]>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/

/*
* NetworkStatusBarItem.vala:
*
* Indicates network IP address in status bar
*/

using EV3devKit;
using GRX;

namespace BrickManager {
public class NetworkStatusBarItem : StatusBarItem {
const ushort TOP = 2;
static Font font;

static construct {
font = Font.load ("xm6x8");
}

string _text = "";
TextOption text_option;

public string text {
get { return _text; }
set {
_text = value;
redraw();
}
}

public NetworkStatusBarItem () {
text_option = new TextOption () {
font = NetworkStatusBarItem.font,
bg_color = Color.no_color
};
}

public override int draw (int x, StatusBar.Align align) {
var color = status_bar.screen.fg_color;
text_option.fg_color = color;
var main_width = text_option.vala_string_width(_text) + 2;

draw_vala_string (_text, x + 1, TOP, text_option);
return main_width;
}
}
}
5 changes: 4 additions & 1 deletion test/controller/FakeNetworkController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace BrickManager {
NetworkStatusWindow network_status_window;
public Window start_window { get { return network_status_window; } }
NetworkConnectionsWindow network_connections_window;
public NetworkStatusBarItem network_status_bar_item;
ConnManAgent agent;
Gtk.Dialog? agent_request_input_dialog;

Expand Down Expand Up @@ -94,6 +95,8 @@ namespace BrickManager {
connman_technology_liststore, toggle, path, ControlPanel.NetworkTechnologyColumn.CONNECTED));

/* NetworkConnectionsWindow */
network_status_bar_item = new NetworkStatusBarItem();
network_status_bar_item.text = "192.168.137.3";

network_connections_window = new NetworkConnectionsWindow ();
bind_property ("has-wifi", network_connections_window, "has-wifi", BindingFlags.SYNC_CREATE);
Expand Down Expand Up @@ -494,4 +497,4 @@ namespace BrickManager {
}
}
}
}
}
2 changes: 2 additions & 0 deletions test/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace BrickManager {
home_window.add_controller (control_panel.about_controller);
DesktopTestApp.screen.status_bar.add_right (
control_panel.battery_controller.battery_status_bar_item);
DesktopTestApp.screen.status_bar.add_left (
control_panel.network_controller.network_status_bar_item);
home_window.shutdown_dialog.power_off_button_pressed.connect (() =>
DesktopTestApp.quit ());
home_window.shutdown_dialog.reboot_button_pressed.connect (() => {
Expand Down

0 comments on commit 4cdf6b5

Please sign in to comment.