Skip to content

Commit

Permalink
Network preferences: add a checkbox to control NetworkStatus
Browse files Browse the repository at this point in the history
Fixes #3314.
Based on Barrett initial patch, reworked for the current network
preferences implementation.
  • Loading branch information
pulkomandy committed Jan 7, 2015
1 parent beb9b34 commit d37cd1e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
56 changes: 50 additions & 6 deletions src/preferences/network/NetworkSetupWindow.cpp
@@ -1,9 +1,10 @@
/*
* Copyright 2004-2011 Haiku Inc. All rights reserved.
* Copyright 2004-2015 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexander von Gluck, <kallisti5@unixzen.com>
* Adrien Destugues, <pulkomandy@pulkomandy.tk>
*/


Expand All @@ -12,6 +13,7 @@
#include <Application.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <Deskbar.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <InterfaceKit.h>
Expand Down Expand Up @@ -61,6 +63,11 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
new BMessage(kMsgRevert));
// fRevertButton->SetEnabled(false);

BMessage* message = new BMessage(kMsgToggleReplicant);
BCheckBox* replicantStatus = new BCheckBox("replicantStatus",
B_TRANSLATE("Show interfaces status in Deskbar"), message);
replicantStatus->SetValue(_IsReplicantInstalled());

// Build the layout
SetLayout(new BGroupLayout(B_VERTICAL));

Expand All @@ -75,6 +82,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
.Add(fPanel)
.Add(new BGroupView("panel"))
.End()
.Add(replicantStatus)
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.Add(fRevertButton)
.AddGlue()
Expand Down Expand Up @@ -106,9 +114,9 @@ NetworkSetupWindow::QuitRequested()


void
NetworkSetupWindow::MessageReceived(BMessage* msg)
NetworkSetupWindow::MessageReceived(BMessage* message)
{
switch (msg->what) {
switch (message->what) {
case kMsgProfileNew:
break;

Expand All @@ -118,7 +126,7 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
bool is_default;
bool is_current;

if (msg->FindString("path", &path) != B_OK)
if (message->FindString("path", &path) != B_OK)
break;

name.SetTo(path);
Expand All @@ -139,7 +147,6 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
break;
}


case kMsgApply: {
for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) {
NetworkSetupAddOn* addon
Expand All @@ -149,8 +156,12 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
break;
}

case kMsgToggleReplicant: {
_ShowReplicant(message->FindInt32("be:value"));
}

default:
inherited::MessageReceived(msg);
inherited::MessageReceived(message);
}
}

Expand Down Expand Up @@ -298,3 +309,36 @@ NetworkSetupWindow::_BuildShowTabView()

free(search_paths);
}


void
NetworkSetupWindow::_ShowReplicant(bool show)
{
if (show) {
char* argv[] = {const_cast<char *>("--deskbar"), NULL};

status_t ret = be_roster->Launch(
"application/x-vnd.Haiku-NetworkStatus", 1, argv);

if (ret != B_OK) {
BString errorMessage;
errorMessage.SetToFormat(
B_TRANSLATE("Installing NetworkStatus in Deskbar failed: %s"),
strerror(ret));
BAlert* alert = new BAlert(B_TRANSLATE("launch error"),
errorMessage, B_TRANSLATE("Ok"));
alert->Go(NULL);
}
} else {
BDeskbar deskbar;
deskbar.RemoveItem("NetworkStatus");
}
}


bool
NetworkSetupWindow::_IsReplicantInstalled()
{
BDeskbar deskbar;
return deskbar.HasItem("NetworkStatus");
}
4 changes: 4 additions & 0 deletions src/preferences/network/NetworkSetupWindow.h
Expand Up @@ -38,6 +38,7 @@ class NetworkSetupWindow : public BWindow
static const uint32 kMsgProfileNew = 'newp';
static const uint32 kMsgApply = 'aply';
static const uint32 kMsgRevert = 'rvrt';
static const uint32 kMsgToggleReplicant = 'trep';

bool QuitRequested();
void MessageReceived(BMessage* msg);
Expand All @@ -46,6 +47,9 @@ class NetworkSetupWindow : public BWindow
void _BuildProfilesMenu(BMenu* menu, int32 msg);
void _BuildShowTabView();

bool _IsReplicantInstalled();
void _ShowReplicant(bool show);

BButton* fRevertButton;
BButton* fApplyButton;

Expand Down

0 comments on commit d37cd1e

Please sign in to comment.