Network preferences: add a checkbox to control NetworkStatus
Fixes #3314. Based on Barrett initial patch, reworked for the current network preferences implementation.
This commit is contained in:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Alexander von Gluck, <[email protected]>
|
* Alexander von Gluck, <[email protected]>
|
||||||
|
* Adrien Destugues, <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
|
#include <Deskbar.h>
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
@@ -61,6 +63,11 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
|||||||
new BMessage(kMsgRevert));
|
new BMessage(kMsgRevert));
|
||||||
// fRevertButton->SetEnabled(false);
|
// 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
|
// Build the layout
|
||||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||||
|
|
||||||
@@ -75,6 +82,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
|||||||
.Add(fPanel)
|
.Add(fPanel)
|
||||||
.Add(new BGroupView("panel"))
|
.Add(new BGroupView("panel"))
|
||||||
.End()
|
.End()
|
||||||
|
.Add(replicantStatus)
|
||||||
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
||||||
.Add(fRevertButton)
|
.Add(fRevertButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
@@ -106,9 +114,9 @@ NetworkSetupWindow::QuitRequested()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkSetupWindow::MessageReceived(BMessage* msg)
|
NetworkSetupWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (message->what) {
|
||||||
case kMsgProfileNew:
|
case kMsgProfileNew:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -118,7 +126,7 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
|
|||||||
bool is_default;
|
bool is_default;
|
||||||
bool is_current;
|
bool is_current;
|
||||||
|
|
||||||
if (msg->FindString("path", &path) != B_OK)
|
if (message->FindString("path", &path) != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
name.SetTo(path);
|
name.SetTo(path);
|
||||||
@@ -139,7 +147,6 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case kMsgApply: {
|
case kMsgApply: {
|
||||||
for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) {
|
for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) {
|
||||||
NetworkSetupAddOn* addon
|
NetworkSetupAddOn* addon
|
||||||
@@ -149,8 +156,12 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case kMsgToggleReplicant: {
|
||||||
|
_ShowReplicant(message->FindInt32("be:value"));
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
inherited::MessageReceived(msg);
|
inherited::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,3 +309,36 @@ NetworkSetupWindow::_BuildShowTabView()
|
|||||||
|
|
||||||
free(search_paths);
|
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");
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class NetworkSetupWindow : public BWindow
|
|||||||
static const uint32 kMsgProfileNew = 'newp';
|
static const uint32 kMsgProfileNew = 'newp';
|
||||||
static const uint32 kMsgApply = 'aply';
|
static const uint32 kMsgApply = 'aply';
|
||||||
static const uint32 kMsgRevert = 'rvrt';
|
static const uint32 kMsgRevert = 'rvrt';
|
||||||
|
static const uint32 kMsgToggleReplicant = 'trep';
|
||||||
|
|
||||||
bool QuitRequested();
|
bool QuitRequested();
|
||||||
void MessageReceived(BMessage* msg);
|
void MessageReceived(BMessage* msg);
|
||||||
@@ -46,6 +47,9 @@ class NetworkSetupWindow : public BWindow
|
|||||||
void _BuildProfilesMenu(BMenu* menu, int32 msg);
|
void _BuildProfilesMenu(BMenu* menu, int32 msg);
|
||||||
void _BuildShowTabView();
|
void _BuildShowTabView();
|
||||||
|
|
||||||
|
bool _IsReplicantInstalled();
|
||||||
|
void _ShowReplicant(bool show);
|
||||||
|
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
BButton* fApplyButton;
|
BButton* fApplyButton;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user