[haiku-commits] haiku: hrev47108 - src/preferences/time

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 10 Apr 2014 23:36:25 +0200 (CEST)

hrev47108 adds 3 changesets to branch 'master'
old head: f3259869930a99842b8932e1965fc5f32e891368
new head: 1520fffa4fd13aee78688ae7ea106eb99bad4773
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=1520fff+%5Ef325986

----------------------------------------------------------------------------

15cc2a1: Time prefs: Set pointer NULL, delete in destructor
  
  ... avoiding potential memory leak.

deda8ca: Time prefs: Set text colors in constructor

1520fff: 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.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 122 insertions(+), 75 deletions(-)
src/preferences/time/NetworkTimeView.cpp | 161 +++++++++++++++++----------
src/preferences/time/NetworkTimeView.h   |  36 +++---

############################################################################

Commit:      15cc2a1fad4c67ece238f5f20c9bae4607cf7c05
URL:         http://cgit.haiku-os.org/haiku/commit/?id=15cc2a1
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Apr  1 00:08:44 2014 UTC

Time prefs: Set pointer NULL, delete in destructor

... avoiding potential memory leak.

----------------------------------------------------------------------------

diff --git a/src/preferences/time/NetworkTimeView.cpp 
b/src/preferences/time/NetworkTimeView.cpp
index 4c4c5ad..82ce720 100644
--- a/src/preferences/time/NetworkTimeView.cpp
+++ b/src/preferences/time/NetworkTimeView.cpp
@@ -269,6 +269,14 @@ NetworkTimeView::NetworkTimeView(const char* name)
        :
        BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING),
        fSettings(),
+       fServerTextControl(NULL),
+       fAddButton(NULL),
+       fRemoveButton(NULL),
+       fResetButton(NULL),
+       fServerListView(NULL),
+       fTryAllServersCheckBox(NULL),
+       fSynchronizeAtBootCheckBox(NULL),
+       fSynchronizeButton(NULL),
        fUpdateThread(-1)
 {
        fSettings.Load();
@@ -276,6 +284,19 @@ NetworkTimeView::NetworkTimeView(const char* name)
 }
 
 
+NetworkTimeView::~NetworkTimeView()
+{
+       delete fServerTextControl;
+       delete fAddButton;
+       delete fRemoveButton;
+       delete fResetButton;
+       delete fServerListView;
+       delete fTryAllServersCheckBox;
+       delete fSynchronizeAtBootCheckBox;
+       delete fSynchronizeButton;
+}
+
+
 void
 NetworkTimeView::MessageReceived(BMessage* message)
 {
diff --git a/src/preferences/time/NetworkTimeView.h 
b/src/preferences/time/NetworkTimeView.h
index 3a56826..3a49455 100644
--- a/src/preferences/time/NetworkTimeView.h
+++ b/src/preferences/time/NetworkTimeView.h
@@ -84,6 +84,7 @@ private:
 class NetworkTimeView : public BGroupView {
 public:
                                                        NetworkTimeView(const 
char* name);
+       virtual                                 ~NetworkTimeView();
 
        virtual void                    MessageReceived(BMessage* message);
        virtual void                    AttachedToWindow();

############################################################################

Commit:      deda8cad48ba3b49cc3f9cc3f0a1c4309ebe2a88
URL:         http://cgit.haiku-os.org/haiku/commit/?id=deda8ca
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Apr  1 00:09:19 2014 UTC

Time prefs: Set text colors in constructor

----------------------------------------------------------------------------

diff --git a/src/preferences/time/NetworkTimeView.cpp 
b/src/preferences/time/NetworkTimeView.cpp
index 82ce720..336a60b 100644
--- a/src/preferences/time/NetworkTimeView.cpp
+++ b/src/preferences/time/NetworkTimeView.cpp
@@ -277,6 +277,8 @@ NetworkTimeView::NetworkTimeView(const char* name)
        fTryAllServersCheckBox(NULL),
        fSynchronizeAtBootCheckBox(NULL),
        fSynchronizeButton(NULL),
+       fTextColor(ui_color(B_CONTROL_TEXT_COLOR)),
+       fInvalidColor(ui_color(B_FAILURE_COLOR)),
        fUpdateThread(-1)
 {
        fSettings.Load();
@@ -315,13 +317,11 @@ NetworkTimeView::MessageReceived(BMessage* message)
 
                case kMsgServerEdited:
                {
-                       rgb_color defaultColor = ui_color(B_CONTROL_TEXT_COLOR);
-                       rgb_color invalid = ui_color(B_FAILURE_COLOR);
                        bool isValidServerName
                                = 
_IsValidServerName(fServerTextControl->Text());
                        fServerTextControl->TextView()->SetFontAndColor(0,
                                fServerTextControl->TextView()->TextLength(), 
NULL, 0,
-                               isValidServerName ? &defaultColor : &invalid);
+                               isValidServerName ? &fTextColor : 
&fInvalidColor);
                        fAddButton->SetEnabled(isValidServerName);
                        break;
                }
diff --git a/src/preferences/time/NetworkTimeView.h 
b/src/preferences/time/NetworkTimeView.h
index 3a49455..842c570 100644
--- a/src/preferences/time/NetworkTimeView.h
+++ b/src/preferences/time/NetworkTimeView.h
@@ -108,6 +108,9 @@ private:
                        BCheckBox*              fSynchronizeAtBootCheckBox;
                        BButton*                fSynchronizeButton;
 
+                       rgb_color               fTextColor;
+                       rgb_color               fInvalidColor;
+
                        thread_id               fUpdateThread;
 };
 

############################################################################

Revision:    hrev47108
Commit:      1520fffa4fd13aee78688ae7ea106eb99bad4773
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1520fff
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Apr  1 00:18:11 2014 UTC

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.

----------------------------------------------------------------------------

diff --git a/src/preferences/time/NetworkTimeView.cpp 
b/src/preferences/time/NetworkTimeView.cpp
index 336a60b..4d44b30 100644
--- a/src/preferences/time/NetworkTimeView.cpp
+++ b/src/preferences/time/NetworkTimeView.cpp
@@ -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.
  *
  * Authors:
- *             Hamish Morrison <hamish@xxxxxxxxxxx>
- *             Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ *             Hamish Morrison, hamish@xxxxxxxxxxx
+ *             John Scipione, jscipione@xxxxxxxxx
  */
 
 
@@ -18,13 +19,14 @@
 #include <Button.h>
 #include <Catalog.h>
 #include <CheckBox.h>
-#include <ControlLook.h>
 #include <File.h>
 #include <FindDirectory.h>
+#include <Invoker.h>
 #include <ListItem.h>
 #include <ListView.h>
 #include <Path.h>
 #include <ScrollView.h>
+#include <Size.h>
 #include <TextControl.h>
 
 #include "ntp.h"
@@ -35,6 +37,9 @@
 #define B_TRANSLATION_CONTEXT "Time"
 
 
+//     #pragma mark - Settings
+
+
 Settings::Settings()
        :
        fMessage(kMsgNetworkTimeSettings)
@@ -265,6 +270,9 @@ Settings::_GetPath(BPath& path)
 }
 
 
+//     #pragma mark - NetworkTimeView
+
+
 NetworkTimeView::NetworkTimeView(const char* name)
        :
        BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING),
@@ -317,12 +325,11 @@ NetworkTimeView::MessageReceived(BMessage* message)
 
                case kMsgServerEdited:
                {
-                       bool isValidServerName
-                               = 
_IsValidServerName(fServerTextControl->Text());
+                       bool isValid = 
_IsValidServerName(fServerTextControl->Text());
                        fServerTextControl->TextView()->SetFontAndColor(0,
                                fServerTextControl->TextView()->TextLength(), 
NULL, 0,
-                               isValidServerName ? &fTextColor : 
&fInvalidColor);
-                       fAddButton->SetEnabled(isValidServerName);
+                               isValid ? &fTextColor : &fInvalidColor);
+                       fAddButton->SetEnabled(isValid);
                        break;
                }
 
@@ -459,16 +466,19 @@ NetworkTimeView::_InitView()
                new BMessage(kMsgAddServer));
        fServerTextControl->SetModificationMessage(new 
BMessage(kMsgServerEdited));
 
-       fAddButton = new BButton("add", B_TRANSLATE("Add"),
-               new BMessage(kMsgAddServer));
-       fRemoveButton = new BButton("remove", B_TRANSLATE("Remove"),
-               new BMessage(kMsgRemoveServer));
-       fResetButton = new BButton("reset", B_TRANSLATE("Reset"),
-               new BMessage(kMsgResetServerList));
+       const float kButtonWidth = fServerTextControl->Frame().Height();
+
+       fAddButton = new BButton("add", "+", new BMessage(kMsgAddServer));
+       fAddButton->SetToolTip(B_TRANSLATE("Add"));
+       fAddButton->SetExplicitSize(BSize(kButtonWidth, kButtonWidth));
+
+       fRemoveButton = new BButton("remove", "−", new 
BMessage(kMsgRemoveServer));
+       fRemoveButton->SetToolTip(B_TRANSLATE("Remove"));
+       fRemoveButton->SetExplicitSize(BSize(kButtonWidth, kButtonWidth));
 
        fServerListView = new BListView("serverList");
-       fServerListView->SetSelectionMessage(new
-               BMessage(kMsgSetDefaultServer));
+       fServerListView->SetExplicitMinSize(BSize(B_SIZE_UNSET, kButtonWidth * 
4));
+       fServerListView->SetSelectionMessage(new 
BMessage(kMsgSetDefaultServer));
        BScrollView* scrollView = new BScrollView("serverScrollView",
                fServerListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
        _UpdateServerList();
@@ -481,23 +491,26 @@ NetworkTimeView::_InitView()
                B_TRANSLATE("Synchronize at boot"),
                new BMessage(kMsgSynchronizeAtBoot));
        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"),
                new BMessage(kMsgSynchronize));
-       fSynchronizeButton->SetExplicitAlignment(
-               BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM));
 
-       const float kInset = be_control_look->DefaultItemSpacing();
-       BLayoutBuilder::Group<>(this)
-               .AddGroup(B_HORIZONTAL)
-                       .AddGroup(B_VERTICAL, 0)
+       BLayoutBuilder::Group<>(this, B_VERTICAL)
+               .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
+                       .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
                                .Add(fServerTextControl)
-                               .Add(scrollView)
-                       .End()
-                       .AddGroup(B_VERTICAL, kInset / 2)
                                .Add(fAddButton)
-                               .Add(fRemoveButton)
-                               .Add(fResetButton)
-                               .AddGlue()
+                       .End()
+                       .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
+                               .Add(scrollView)
+                               .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
+                                       .Add(fRemoveButton)
+                                       .AddGlue()
+                               .End()
                        .End()
                .End()
                .AddGroup(B_HORIZONTAL)
@@ -505,9 +518,13 @@ NetworkTimeView::_InitView()
                                .Add(fTryAllServersCheckBox)
                                .Add(fSynchronizeAtBootCheckBox)
                        .End()
+               .End()
+               .AddGroup(B_HORIZONTAL)
+                       .AddGlue()
+                       .Add(fResetButton)
                        .Add(fSynchronizeButton)
                .End()
-               .SetInsets(kInset, kInset, kInset, kInset);
+               .SetInsets(B_USE_DEFAULT_SPACING);
 }
 
 
@@ -556,35 +573,7 @@ NetworkTimeView::_IsValidServerName(const char* serverName)
 }
 
 
-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;
-}
+//     #pragma mark - update functions
 
 
 int32
@@ -622,3 +611,34 @@ update_time(const Settings& settings, BMessenger* 
messenger,
 
        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;
+}
diff --git a/src/preferences/time/NetworkTimeView.h 
b/src/preferences/time/NetworkTimeView.h
index 842c570..6ab1ce8 100644
--- a/src/preferences/time/NetworkTimeView.h
+++ b/src/preferences/time/NetworkTimeView.h
@@ -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.
  *
  * Authors:
- *             Hamish Morrison <hamish@xxxxxxxxxxx>
- *             Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ *             Hamish Morrison, hamish@xxxxxxxxxxx
+ *             John Scipione, jscipione@xxxxxxxxx
  */
 #ifndef NETWORK_TIME_VIEW_H
 #define NETWORK_TIME_VIEW_H
@@ -16,11 +17,10 @@
 class BButton;
 class BCheckBox;
 class BListView;
-class BTextControl;
 class BMessage;
 class BMessenger;
 class BPath;
-class Settings;
+class BTextControl;
 
 
 static const uint32 kMsgNetworkTimeSettings = 'ntst';
@@ -37,16 +37,6 @@ static const uint32 kMsgSynchronizationResult = 'syrs';
 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 {
 public:
                                                        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


Other related posts:

  • » [haiku-commits] haiku: hrev47108 - src/preferences/time - jscipione