Time prefs: Use button label symbols & relayout
Add becomes +, Remove becomes −, the current button labels "Add" and "Remove" are used as tool tips. Relayout the controls so that they fit nicely with the buttons: The add button is placed left of the server text control showing that it adds new server names while the remove button is placed next to the list view showing that it removes server names from the list. The reset button is placed next to the "Synchronize" button at the bottom of the tab group and is renamed "Reset to default server list". This makes the window a bit taller.
This commit is contained in:
parent
deda8cad48
commit
1520fffa4f
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
* Copyright 2011-2014 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Hamish Morrison <hamish@lavabit.com>
|
* Axel Dörfler, axeld@pinc-software.de
|
||||||
* Axel Dörfler <axeld@pinc-software.de>
|
* Hamish Morrison, hamish@lavabit.com
|
||||||
|
* John Scipione, jscipione@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -18,13 +19,14 @@
|
|||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
#include <ControlLook.h>
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
|
#include <Invoker.h>
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
#include <Size.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
#include "ntp.h"
|
#include "ntp.h"
|
||||||
@ -35,6 +37,9 @@
|
|||||||
#define B_TRANSLATION_CONTEXT "Time"
|
#define B_TRANSLATION_CONTEXT "Time"
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - Settings
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
:
|
:
|
||||||
fMessage(kMsgNetworkTimeSettings)
|
fMessage(kMsgNetworkTimeSettings)
|
||||||
@ -265,6 +270,9 @@ Settings::_GetPath(BPath& path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - NetworkTimeView
|
||||||
|
|
||||||
|
|
||||||
NetworkTimeView::NetworkTimeView(const char* name)
|
NetworkTimeView::NetworkTimeView(const char* name)
|
||||||
:
|
:
|
||||||
BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING),
|
BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING),
|
||||||
@ -317,12 +325,11 @@ NetworkTimeView::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case kMsgServerEdited:
|
case kMsgServerEdited:
|
||||||
{
|
{
|
||||||
bool isValidServerName
|
bool isValid = _IsValidServerName(fServerTextControl->Text());
|
||||||
= _IsValidServerName(fServerTextControl->Text());
|
|
||||||
fServerTextControl->TextView()->SetFontAndColor(0,
|
fServerTextControl->TextView()->SetFontAndColor(0,
|
||||||
fServerTextControl->TextView()->TextLength(), NULL, 0,
|
fServerTextControl->TextView()->TextLength(), NULL, 0,
|
||||||
isValidServerName ? &fTextColor : &fInvalidColor);
|
isValid ? &fTextColor : &fInvalidColor);
|
||||||
fAddButton->SetEnabled(isValidServerName);
|
fAddButton->SetEnabled(isValid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,16 +466,19 @@ NetworkTimeView::_InitView()
|
|||||||
new BMessage(kMsgAddServer));
|
new BMessage(kMsgAddServer));
|
||||||
fServerTextControl->SetModificationMessage(new BMessage(kMsgServerEdited));
|
fServerTextControl->SetModificationMessage(new BMessage(kMsgServerEdited));
|
||||||
|
|
||||||
fAddButton = new BButton("add", B_TRANSLATE("Add"),
|
const float kButtonWidth = fServerTextControl->Frame().Height();
|
||||||
new BMessage(kMsgAddServer));
|
|
||||||
fRemoveButton = new BButton("remove", B_TRANSLATE("Remove"),
|
fAddButton = new BButton("add", "+", new BMessage(kMsgAddServer));
|
||||||
new BMessage(kMsgRemoveServer));
|
fAddButton->SetToolTip(B_TRANSLATE("Add"));
|
||||||
fResetButton = new BButton("reset", B_TRANSLATE("Reset"),
|
fAddButton->SetExplicitSize(BSize(kButtonWidth, kButtonWidth));
|
||||||
new BMessage(kMsgResetServerList));
|
|
||||||
|
fRemoveButton = new BButton("remove", "−", new BMessage(kMsgRemoveServer));
|
||||||
|
fRemoveButton->SetToolTip(B_TRANSLATE("Remove"));
|
||||||
|
fRemoveButton->SetExplicitSize(BSize(kButtonWidth, kButtonWidth));
|
||||||
|
|
||||||
fServerListView = new BListView("serverList");
|
fServerListView = new BListView("serverList");
|
||||||
fServerListView->SetSelectionMessage(new
|
fServerListView->SetExplicitMinSize(BSize(B_SIZE_UNSET, kButtonWidth * 4));
|
||||||
BMessage(kMsgSetDefaultServer));
|
fServerListView->SetSelectionMessage(new BMessage(kMsgSetDefaultServer));
|
||||||
BScrollView* scrollView = new BScrollView("serverScrollView",
|
BScrollView* scrollView = new BScrollView("serverScrollView",
|
||||||
fServerListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
|
fServerListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
|
||||||
_UpdateServerList();
|
_UpdateServerList();
|
||||||
@ -481,23 +491,26 @@ NetworkTimeView::_InitView()
|
|||||||
B_TRANSLATE("Synchronize at boot"),
|
B_TRANSLATE("Synchronize at boot"),
|
||||||
new BMessage(kMsgSynchronizeAtBoot));
|
new BMessage(kMsgSynchronizeAtBoot));
|
||||||
fSynchronizeAtBootCheckBox->SetValue(fSettings.GetSynchronizeAtBoot());
|
fSynchronizeAtBootCheckBox->SetValue(fSettings.GetSynchronizeAtBoot());
|
||||||
|
|
||||||
|
fResetButton = new BButton("reset",
|
||||||
|
B_TRANSLATE("Reset to default server list"),
|
||||||
|
new BMessage(kMsgResetServerList));
|
||||||
|
|
||||||
fSynchronizeButton = new BButton("update", B_TRANSLATE("Synchronize"),
|
fSynchronizeButton = new BButton("update", B_TRANSLATE("Synchronize"),
|
||||||
new BMessage(kMsgSynchronize));
|
new BMessage(kMsgSynchronize));
|
||||||
fSynchronizeButton->SetExplicitAlignment(
|
|
||||||
BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM));
|
|
||||||
|
|
||||||
const float kInset = be_control_look->DefaultItemSpacing();
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
BLayoutBuilder::Group<>(this)
|
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
|
||||||
.AddGroup(B_VERTICAL, 0)
|
|
||||||
.Add(fServerTextControl)
|
.Add(fServerTextControl)
|
||||||
.Add(scrollView)
|
|
||||||
.End()
|
|
||||||
.AddGroup(B_VERTICAL, kInset / 2)
|
|
||||||
.Add(fAddButton)
|
.Add(fAddButton)
|
||||||
.Add(fRemoveButton)
|
.End()
|
||||||
.Add(fResetButton)
|
.AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
|
||||||
.AddGlue()
|
.Add(scrollView)
|
||||||
|
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
|
||||||
|
.Add(fRemoveButton)
|
||||||
|
.AddGlue()
|
||||||
|
.End()
|
||||||
.End()
|
.End()
|
||||||
.End()
|
.End()
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
@ -505,9 +518,13 @@ NetworkTimeView::_InitView()
|
|||||||
.Add(fTryAllServersCheckBox)
|
.Add(fTryAllServersCheckBox)
|
||||||
.Add(fSynchronizeAtBootCheckBox)
|
.Add(fSynchronizeAtBootCheckBox)
|
||||||
.End()
|
.End()
|
||||||
|
.End()
|
||||||
|
.AddGroup(B_HORIZONTAL)
|
||||||
|
.AddGlue()
|
||||||
|
.Add(fResetButton)
|
||||||
.Add(fSynchronizeButton)
|
.Add(fSynchronizeButton)
|
||||||
.End()
|
.End()
|
||||||
.SetInsets(kInset, kInset, kInset, kInset);
|
.SetInsets(B_USE_DEFAULT_SPACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -556,35 +573,7 @@ NetworkTimeView::_IsValidServerName(const char* serverName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
// #pragma mark - update functions
|
||||||
update_time(const Settings& settings, const char** errorString,
|
|
||||||
int32* errorCode)
|
|
||||||
{
|
|
||||||
int32 defaultServer = settings.GetDefaultServer();
|
|
||||||
|
|
||||||
status_t status = B_ENTRY_NOT_FOUND;
|
|
||||||
const char* server = settings.GetServer(defaultServer);
|
|
||||||
|
|
||||||
if (server != NULL)
|
|
||||||
status = ntp_update_time(server, errorString, errorCode);
|
|
||||||
|
|
||||||
if (status != B_OK && settings.GetTryAllServers()) {
|
|
||||||
for (int32 index = 0; ; index++) {
|
|
||||||
if (index == defaultServer)
|
|
||||||
index++;
|
|
||||||
|
|
||||||
server = settings.GetServer(index);
|
|
||||||
if (server == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
status = ntp_update_time(server, errorString, errorCode);
|
|
||||||
if (status == B_OK)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
@ -622,3 +611,34 @@ update_time(const Settings& settings, BMessenger* messenger,
|
|||||||
|
|
||||||
return resume_thread(*thread);
|
return resume_thread(*thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
update_time(const Settings& settings, const char** errorString,
|
||||||
|
int32* errorCode)
|
||||||
|
{
|
||||||
|
int32 defaultServer = settings.GetDefaultServer();
|
||||||
|
|
||||||
|
status_t status = B_ENTRY_NOT_FOUND;
|
||||||
|
const char* server = settings.GetServer(defaultServer);
|
||||||
|
|
||||||
|
if (server != NULL)
|
||||||
|
status = ntp_update_time(server, errorString, errorCode);
|
||||||
|
|
||||||
|
if (status != B_OK && settings.GetTryAllServers()) {
|
||||||
|
for (int32 index = 0; ; index++) {
|
||||||
|
if (index == defaultServer)
|
||||||
|
index++;
|
||||||
|
|
||||||
|
server = settings.GetServer(index);
|
||||||
|
if (server == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
status = ntp_update_time(server, errorString, errorCode);
|
||||||
|
if (status == B_OK)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
* Copyright 2011-2014 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Hamish Morrison <hamish@lavabit.com>
|
* Axel Dörfler, axeld@pinc-software.de
|
||||||
* Axel Dörfler <axeld@pinc-software.de>
|
* Hamish Morrison, hamish@lavabit.com
|
||||||
|
* John Scipione, jscipione@gmail.com
|
||||||
*/
|
*/
|
||||||
#ifndef NETWORK_TIME_VIEW_H
|
#ifndef NETWORK_TIME_VIEW_H
|
||||||
#define NETWORK_TIME_VIEW_H
|
#define NETWORK_TIME_VIEW_H
|
||||||
@ -16,11 +17,10 @@
|
|||||||
class BButton;
|
class BButton;
|
||||||
class BCheckBox;
|
class BCheckBox;
|
||||||
class BListView;
|
class BListView;
|
||||||
class BTextControl;
|
|
||||||
class BMessage;
|
class BMessage;
|
||||||
class BMessenger;
|
class BMessenger;
|
||||||
class BPath;
|
class BPath;
|
||||||
class Settings;
|
class BTextControl;
|
||||||
|
|
||||||
|
|
||||||
static const uint32 kMsgNetworkTimeSettings = 'ntst';
|
static const uint32 kMsgNetworkTimeSettings = 'ntst';
|
||||||
@ -37,16 +37,6 @@ static const uint32 kMsgSynchronizationResult = 'syrs';
|
|||||||
static const uint32 kMsgNetworkTimeChange = 'ntch';
|
static const uint32 kMsgNetworkTimeChange = 'ntch';
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
update_time(const Settings& settings, BMessenger* messenger,
|
|
||||||
thread_id* thread);
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
update_time(const Settings& settings, const char** errorString,
|
|
||||||
int32* errorCode);
|
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
@ -115,4 +105,16 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
update_thread(void* params);
|
||||||
|
|
||||||
|
status_t
|
||||||
|
update_time(const Settings& settings, BMessenger* messenger,
|
||||||
|
thread_id* thread);
|
||||||
|
|
||||||
|
status_t
|
||||||
|
update_time(const Settings& settings, const char** errorString,
|
||||||
|
int32* errorCode);
|
||||||
|
|
||||||
|
|
||||||
#endif // NETWORK_TIME_VIEW_H
|
#endif // NETWORK_TIME_VIEW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user