Ticket #2412: time_pref_net.patch

File time_pref_net.patch, 81.5 KB (added by hamish, 13 years ago)

networktime integrated into time preflet, and time preflet converted to layout manager

  • src/preferences/time/NetworkTimeView.cpp

     
     1/*
     2 * Copyright 2011, Haiku, Inc. All Rights Reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Hamish Morrison <hamish@lavabit.com>
     7 *      Axel Dörfler <axeld@pinc-software.de>
     8 */
     9 
     10#include "NetworkTimeView.h"
     11
     12#include <Alert.h>
     13#include <Application.h>
     14#include <Button.h>
     15#include <CheckBox.h>
     16#include <File.h>
     17#include <FindDirectory.h>
     18#include <MenuField.h>
     19#include <MenuItem.h>
     20#include <Path.h>
     21#include <PopUpMenu.h>
     22#include <View.h>
     23
     24#include <stdio.h>
     25#include <string.h>
     26
     27#include "ntp.h"
     28
     29
     30class MessengerMonitor : public Monitor {
     31    public:
     32        MessengerMonitor(BLooper& looper)
     33            :
     34            fLooper(looper)
     35        {
     36        }
     37
     38        virtual void
     39        Done(status_t status)
     40        {
     41            BMessage message(kMsgStatusUpdate);
     42            message.AddInt32("status", status);
     43
     44            fLooper.PostMessage(&message);
     45            fLooper.PostMessage(kMsgStopSynchronization);
     46        }
     47
     48    private:
     49        virtual void
     50        update(float progress, const char *text, va_list args)
     51        {
     52            BMessage message(kMsgStatusUpdate);
     53            if (progress != -1.f)
     54                message.AddFloat("progress", progress);
     55
     56            if (text != NULL) {
     57                char buffer[2048];
     58                vsnprintf(buffer, sizeof(buffer), text, args);
     59                message.AddString("message", buffer);
     60            }
     61
     62            fLooper.PostMessage(&message);
     63        }
     64
     65        BLooper& fLooper;
     66};
     67
     68
     69class UpdateLooper : public BLooper {
     70    public:
     71        UpdateLooper(const BMessage &settings, Monitor *monitor);
     72
     73        void MessageReceived(BMessage *message);
     74
     75    private:
     76        const BMessage  &fSettings;
     77        Monitor         *fMonitor;
     78};
     79
     80
     81UpdateLooper::UpdateLooper(const BMessage &settings, Monitor *monitor)
     82    : BLooper("update looper"),
     83    fSettings(settings),
     84    fMonitor(monitor)
     85{
     86    PostMessage(kMsgSynchronize);
     87}
     88
     89
     90void
     91UpdateLooper::MessageReceived(BMessage *message)
     92{
     93    if (message->what != kMsgSynchronize)
     94        return;
     95
     96    update_time(fSettings, fMonitor);
     97}
     98
     99
     100status_t
     101adopt_int32(const BMessage &from, BMessage &to,
     102    const char *name, bool &updated)
     103{
     104    int32 value;
     105    if (from.FindInt32(name, &value) != B_OK)
     106        return B_ENTRY_NOT_FOUND;
     107
     108    int32 original;
     109    if (to.FindInt32(name, &original) == B_OK) {
     110        if (value == original)
     111            return B_OK;
     112
     113        updated = true;
     114        return to.ReplaceInt32(name, value);
     115    }
     116
     117    updated = true;
     118    return to.AddInt32(name, value);
     119}
     120
     121
     122status_t
     123adopt_bool(const BMessage &from, BMessage &to,
     124    const char *name, bool &updated)
     125{
     126    bool value;
     127    if (from.FindBool(name, &value) != B_OK)
     128        return B_ENTRY_NOT_FOUND;
     129
     130    bool original;
     131    if (to.FindBool(name, &original) == B_OK) {
     132        if (value == original)
     133            return B_OK;
     134
     135        updated = true;
     136        return to.ReplaceBool(name, value);
     137    }
     138
     139    updated = true;
     140    return to.AddBool(name, value);
     141}
     142
     143
     144status_t
     145adopt_rect(const BMessage &from, BMessage &to,
     146    const char *name, bool &updated)
     147{
     148    BRect rect;
     149    if (from.FindRect(name, &rect) != B_OK)
     150        return B_ENTRY_NOT_FOUND;
     151
     152    BRect original;
     153    if (to.FindRect(name, &original) == B_OK) {
     154        if (rect == original)
     155            return B_OK;
     156
     157        updated = true;
     158        return to.ReplaceRect(name, rect);
     159    }
     160
     161    updated = true;
     162    return to.AddRect(name, rect);
     163}
     164
     165
     166Settings::Settings()
     167    :
     168    fMessage(kMsgNetworkTimeSettings),
     169    fWasUpdated(false)
     170{
     171    ResetToDefaults();
     172    Load();
     173}
     174
     175
     176Settings::~Settings()
     177{
     178    if (fWasUpdated)
     179        Save();
     180}
     181
     182
     183void
     184Settings::CopyMessage(BMessage &message) const
     185{
     186    message = fMessage;
     187}
     188
     189
     190const BMessage &
     191Settings::Message() const
     192{
     193    return fMessage;
     194}
     195
     196
     197void
     198Settings::UpdateFrom(BMessage &message)
     199{
     200    if (message.HasBool("reset servers")) {
     201        fMessage.RemoveName("server");
     202        fWasUpdated = true;
     203    }
     204
     205    if (message.HasString("server")) {
     206        // remove old servers
     207        fMessage.RemoveName("server");
     208
     209        const char *server;
     210        int32 index = 0;
     211        while (message.FindString("server", index++, &server) == B_OK) {
     212            fMessage.AddString("server", server);
     213        }
     214
     215        fWasUpdated = true;
     216    }
     217
     218    adopt_int32(message, fMessage, "default server", fWasUpdated);
     219
     220    adopt_bool(message, fMessage, "synchronize at boot", fWasUpdated);
     221    adopt_bool(message, fMessage, "try all servers", fWasUpdated);
     222    adopt_bool(message, fMessage, "choose default server", fWasUpdated);
     223
     224    adopt_rect(message, fMessage, "edit servers frame", fWasUpdated);
     225}
     226
     227
     228void
     229Settings::ResetServersToDefaults()
     230{
     231    fMessage.RemoveName("server");
     232
     233    fMessage.AddString("server", "pool.ntp.org");
     234    fMessage.AddString("server", "de.pool.ntp.org");
     235    fMessage.AddString("server", "time.nist.gov");
     236
     237    if (fMessage.ReplaceInt32("default server", 0) != B_OK)
     238        fMessage.AddInt32("default server", 0);
     239}
     240
     241
     242void
     243Settings::ResetToDefaults()
     244{
     245    fMessage.MakeEmpty();
     246    ResetServersToDefaults();
     247
     248    fMessage.AddBool("synchronize at boot", true);
     249    fMessage.AddBool("try all servers", true);
     250
     251    fMessage.AddRect("status frame", BRect(0, 0, 300, 150));
     252    fMessage.AddRect("edit servers frame", BRect(0, 0, 250, 250));
     253}
     254
     255
     256status_t
     257Settings::Load()
     258{
     259    status_t status;
     260
     261    BPath path;
     262    if ((status = GetPath(path)) != B_OK)
     263        return status;
     264
     265    BFile file(path.Path(), B_READ_ONLY);
     266    if ((status = file.InitCheck()) != B_OK)
     267        return status;
     268
     269    BMessage load;
     270    if ((status = load.Unflatten(&file)) != B_OK)
     271        return status;
     272
     273    if (load.what != kMsgNetworkTimeSettings)
     274        return B_BAD_TYPE;
     275
     276    fMessage = load;
     277    return B_OK;
     278}
     279
     280
     281status_t
     282Settings::Save()
     283{
     284    status_t status;
     285
     286    BPath path;
     287    if ((status = GetPath(path)) != B_OK)
     288        return status;
     289
     290    BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
     291    if ((status = file.InitCheck()) != B_OK)
     292        return status;
     293
     294    file.SetSize(0);
     295
     296    return fMessage.Flatten(&file);
     297}
     298
     299
     300status_t
     301Settings::GetPath(BPath &path)
     302{
     303    status_t status;
     304    if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
     305        return status;
     306    path.Append("pinc.networktime settings");
     307    return B_OK;
     308}
     309
     310
     311NetworkTimeView::NetworkTimeView(const char* name)
     312    :
     313    BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING),
     314    fEditServerListWindow(NULL),
     315    fUpdateThread(-1),
     316    fStatusString(""),
     317    fSettings()
     318{
     319    fSettings.Load();
     320    _InitView();
     321}
     322
     323
     324void
     325NetworkTimeView::_InitView()
     326{
     327    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     328
     329    BPopUpMenu* menu = new BPopUpMenu("serverMenu");
     330    fServerListMenuField = new BMenuField("serverList", "Use server:", menu);
     331    _UpdateServerListMenu();
     332    fEditServerListButton = new BButton("editServerList", "Edit Server List",
     333        new BMessage(kMsgEditServerList));
     334   
     335    fTryAllServersCheckBox = new BCheckBox("tryAllServers", "Try all servers",
     336        new BMessage(kMsgTryAllServers));
     337    bool boolean;
     338    if (fSettings.Message().FindBool("try all servers", &boolean) == B_OK)
     339        fTryAllServersCheckBox->SetValue(boolean);
     340   
     341    fSynchronizeAtBootCheckBox = new BCheckBox("autoUpdate",
     342        "Synchronize at boot", new BMessage(kMsgSynchronizeAtBoot));
     343    if (fSettings.Message().FindBool("synchronize at boot", &boolean) == B_OK)
     344        fSynchronizeAtBootCheckBox->SetValue(boolean);
     345    fSynchronizeButton = new BButton("update", "Synchronize now",
     346        new BMessage(kMsgSynchronize));
     347   
     348    BLayoutBuilder::Group<>(this)
     349        .AddGroup(B_HORIZONTAL)
     350            .Add(fServerListMenuField)
     351            .Add(fEditServerListButton)
     352        .End()
     353        .Add(fTryAllServersCheckBox)
     354        .Add(fSynchronizeAtBootCheckBox)
     355        .AddGroup(B_HORIZONTAL)
     356            .AddGlue()
     357            .Add(fSynchronizeButton)
     358        .End()
     359        .SetInsets(5, 5, 5, 5);
     360}
     361
     362
     363void
     364NetworkTimeView::_UpdateServerListMenu()
     365{
     366    while (fServerListMenuField->Menu()->RemoveItem(0L) != NULL);
     367   
     368    const char* server;
     369    int32 index = 0;
     370    while (fSettings.Message().FindString("server", index++, &server)
     371        == B_OK)
     372        fServerListMenuField->Menu()->AddItem(
     373            new BMenuItem(server, new BMessage(kMsgDefaultServer)));
     374   
     375    int32 defaultServer;
     376    if (fSettings.Message().FindInt32("default server", &defaultServer)
     377        != B_OK)
     378        defaultServer = 0;
     379    fServerListMenuField->Menu()->ItemAt(defaultServer)->SetMarked(true);
     380}
     381
     382
     383void
     384NetworkTimeView::MessageReceived(BMessage* message)
     385{
     386    switch (message->what) {
     387        case kMsgTryAllServers:
     388        {
     389            BMessage update(kMsgUpdateSettings);
     390            update.AddBool("try all servers",
     391                fTryAllServersCheckBox->Value());
     392            Looper()->PostMessage(&update);
     393            break;
     394        }
     395       
     396        case kMsgSynchronizeAtBoot:
     397        {
     398            BMessage update(kMsgUpdateSettings);
     399            update.AddBool("synchronize at boot",
     400                fSynchronizeAtBootCheckBox->Value());
     401            Looper()->PostMessage(&update);
     402            break;
     403        }
     404       
     405        case kMsgSettingsUpdated:
     406        {
     407            if (message->HasString("server"))
     408                _UpdateServerListMenu();
     409            else {
     410                int32 defaultServer;
     411                if (fSettings.Message()
     412                    .FindInt32("default server", &defaultServer) != B_OK)
     413                    defaultServer = 0;
     414                fServerListMenuField->Menu()->ItemAt(defaultServer)
     415                    ->SetMarked(true);
     416            }
     417            bool boolean;
     418            if (message->FindBool("synchronize at boot", &boolean) == B_OK)
     419                fSynchronizeAtBootCheckBox->SetValue(boolean);
     420            if (message->FindBool("try all servers", &boolean) == B_OK)
     421                fTryAllServersCheckBox->SetValue(boolean);
     422            break;
     423        }
     424       
     425        case kMsgUpdateSettings:
     426        {
     427            fSettings.UpdateFrom(*message);
     428            message->what = kMsgSettingsUpdated;
     429            BWindow *window;
     430            int32 index = 0;
     431
     432            while ((window = be_app->WindowAt(index++)) != NULL)
     433                window->PostMessage(message);
     434            break;
     435        }
     436
     437        case kMsgResetServerList:
     438        {
     439            fSettings.ResetServersToDefaults();
     440
     441            BMessage updated = fSettings.Message();
     442            updated.what = kMsgSettingsUpdated;
     443
     444            BWindow *window;
     445            int32 index = 0;
     446            while ((window = be_app->WindowAt(index++)) != NULL)
     447                window->PostMessage(message);
     448           
     449            break;
     450        }
     451
     452        case kMsgEditServerList:
     453            if (fEditServerListWindow == NULL) {
     454                BRect rect(0, 0, 250, 250);
     455                fEditServerListWindow = new EditServerListWindow(rect,
     456                    fSettings.Message(), Looper());
     457            }
     458            fEditServerListWindow->Show();
     459            break;
     460           
     461        case kMsgEditServerListWindowClosed:
     462            fEditServerListWindow = NULL;
     463            break;
     464
     465        case kMsgDefaultServer:
     466        {
     467            int32 index;
     468            if (message->FindInt32("index", &index) != B_OK)
     469                break;
     470            BMessage update(kMsgUpdateSettings);
     471            update.AddInt32("default server", index);
     472            Looper()->PostMessage(&update);
     473            break;
     474        }
     475
     476        case kMsgStopSynchronization:
     477            if (fUpdateThread >= B_OK)
     478                kill_thread(fUpdateThread);
     479            fUpdateThread = -1;
     480
     481            fSynchronizeButton->SetLabel("Synchronize");
     482            fSynchronizeButton->Message()->what = kMsgSynchronize;
     483            break;
     484
     485        case kMsgSynchronize:
     486        {
     487            if (fUpdateThread >= B_OK)
     488                break;
     489
     490            MessengerMonitor* monitor = new MessengerMonitor(*Looper());
     491            update_time(fSettings.Message(), monitor, &fUpdateThread);
     492            fSynchronizeButton->SetLabel("Stop");
     493            fSynchronizeButton->Message()->what = kMsgStopSynchronization;
     494            break;
     495        }
     496       
     497        case kMsgStatusUpdate:
     498        {
     499            message->FindString("message", &fStatusString);
     500            status_t status;
     501            if (message->FindInt32("status", (int32 *)&status) == B_OK) {
     502                if (status != B_OK) {
     503                    (new BAlert("Time", "Error synchronizing!", "OK"))->Go();
     504                }
     505            }
     506            break;
     507        }
     508    }
     509}
     510
     511
     512status_t
     513update_time(const BMessage &settings, Monitor *monitor)
     514{
     515    int32 defaultServer;
     516    if (settings.FindInt32("default server", &defaultServer) != B_OK)
     517        defaultServer = 0;
     518
     519    status_t status = B_ENTRY_NOT_FOUND;
     520    const char *server;
     521    if (settings.FindString("server", defaultServer, &server) == B_OK)
     522        status = ntp_update_time(server, monitor);
     523
     524    // try other servers if we should
     525    if (status != B_OK && settings.FindBool("try all servers")) {
     526        for (int32 index = 0; ; index++) {
     527            if (index == defaultServer)
     528                index++;
     529            if (settings.FindString("server", index, &server) != B_OK)
     530                break;
     531
     532            status = ntp_update_time(server, monitor);
     533            if (status == B_OK) {
     534                if (be_app != NULL && settings.FindBool("choose default server")) {
     535                    BMessage update(kMsgUpdateSettings);
     536                    update.AddInt32("default server", index);
     537                    be_app->PostMessage(&update);
     538                }
     539                break;
     540            }
     541        }
     542    }
     543
     544    if (monitor != NULL)
     545        monitor->Done(status);
     546
     547    delete monitor;
     548    return status;
     549}
     550
     551
     552status_t
     553update_time(const BMessage &settings, Monitor *monitor, thread_id *_asyncThread)
     554{
     555    if (_asyncThread != NULL) {
     556        BLooper *looper = new UpdateLooper(settings, monitor);
     557        *_asyncThread = looper->Run();
     558        return B_OK;
     559    }
     560
     561    return update_time(settings, monitor);
     562}
  • src/preferences/time/EditServerListWindow.h

     
     1/*
     2 * Copyright 2004, pinc Software. All Rights Reserved.
     3 * Distributed under the terms of the MIT license.
     4 */
     5#ifndef EDIT_SERVER_LIST_WINDOW_H
     6#define EDIT_SERVER_LIST_WINDOW_H
     7
     8
     9#include <Window.h>
     10
     11class BTextView;
     12
     13
     14class EditServerListWindow : public BWindow {
     15    public:
     16        EditServerListWindow(BRect position, const BMessage &settings, BLooper* looper);
     17        virtual ~EditServerListWindow();
     18
     19        virtual bool QuitRequested();
     20        virtual void MessageReceived(BMessage *message);
     21
     22    private:
     23        void UpdateDefaultServerView(const BMessage &message);
     24        void UpdateServerView(const BMessage &message);
     25
     26        void UpdateServerList();
     27
     28        const BMessage  &fSettings;
     29        BTextView       *fServerView;
     30       
     31        BLooper         *fLooper;
     32};
     33
     34#endif  /* EDIT_SERVER_LIST_WINDOW_H */
  • src/preferences/time/TimeZoneListItem.cpp

     
    11/*
    2  * Copyright 2010, Haiku Inc. All rights reserved.
     2 * Copyright 2011, Haiku Inc. All rights reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    99 *      Oliver Tappe <zooey@hirschkaefer.de>
    1010*/
    1111
    12 
    1312#include "TimeZoneListItem.h"
    1413
    1514#include <new>
  • src/preferences/time/BaseView.cpp

     
    88 */
    99
    1010#include "BaseView.h"
    11 #include "TimeMessages.h"
    1211
    13 
    1412#include <DateTime.h>
    1513#include <OS.h>
    1614
     15#include "TimeMessages.h"
    1716
    18 TTimeBaseView::TTimeBaseView(BRect frame, const char* name)
    19     : BView(frame, name, B_FOLLOW_NONE, B_PULSE_NEEDED),
    20       fMessage(H_TIME_UPDATE)
     17
     18TTimeBaseView::TTimeBaseView(const char* name)
     19    :
     20    BGroupView(name, B_VERTICAL, 0),
     21    fMessage(H_TIME_UPDATE)
    2122{
     23    SetFlags(Flags() | B_PULSE_NEEDED);
    2224}
    2325
    2426
  • src/preferences/time/ZoneView.cpp

     
    88 *      Philippe Saint-Pierre <stpere@gmail.com>
    99 *      Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
    1010 *      Oliver Tappe <zooey@hirschkaefer.de>
     11 *      Hamish Morrison <hamish@lavabit.com>
    1112 */
    1213
    13 
    1414#include "ZoneView.h"
    1515
    1616#include <stdlib.h>
     
    7777
    7878
    7979
    80 TimeZoneView::TimeZoneView(BRect frame)
     80TimeZoneView::TimeZoneView(const char* name)
    8181    :
    82     BView(frame, "timeZoneView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP),
     82    BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING),
    8383    fToolTip(NULL),
    8484    fCurrentZoneItem(NULL),
    8585    fOldZoneItem(NULL),
     
    173173            break;
    174174
    175175        default:
    176             BView::MessageReceived(message);
     176            BGroupView::MessageReceived(message);
    177177            break;
    178178    }
    179179}
     
    233233void
    234234TimeZoneView::_InitView()
    235235{
    236     // left side
    237     BRect frameLeft(Bounds());
    238     frameLeft.right = frameLeft.Width() / 2.0;
    239     frameLeft.InsetBy(10.0f, 10.0f);
    240 
    241     // City Listing
    242     fZoneList = new BOutlineListView(frameLeft, "cityList",
    243         B_SINGLE_SELECTION_LIST);
     236    fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST);
    244237    fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED));
    245238    fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE));
    246 
    247239    _BuildZoneMenu();
    248 
    249240    BScrollView* scrollList = new BScrollView("scrollList", fZoneList,
    250         B_FOLLOW_ALL, 0, false, true);
    251     AddChild(scrollList);
     241        B_FRAME_EVENTS | B_WILL_DRAW, false, true);
    252242
    253     // right side
    254     BRect frameRight(Bounds());
    255     frameRight.left = frameRight.Width() / 2.0;
    256     frameRight.InsetBy(10.0f, 10.0f);
    257     frameRight.top = frameLeft.top;
     243    fCurrent = new TTZDisplay("currentTime", B_TRANSLATE("Current time:"));
     244    fPreview = new TTZDisplay("previewTime", B_TRANSLATE("Preview time:"));
    258245
    259     // Time Displays
    260     fCurrent = new TTZDisplay(frameRight, "currentTime",
    261         B_TRANSLATE("Current time:"));
    262     AddChild(fCurrent);
    263     fCurrent->ResizeToPreferred();
    264 
    265     frameRight.top = fCurrent->Frame().bottom + 10.0;
    266     fPreview = new TTZDisplay(frameRight, "previewTime",
    267         B_TRANSLATE("Preview time:"));
    268     AddChild(fPreview);
    269     fPreview->ResizeToPreferred();
    270 
    271     // set button
    272     fSetZone = new BButton(frameRight, "setTimeZone",
    273         B_TRANSLATE("Set time zone"),
     246    fSetZone = new BButton("setTimeZone", B_TRANSLATE("Set time zone"),
    274247        new BMessage(H_SET_TIME_ZONE));
    275     AddChild(fSetZone);
    276248    fSetZone->SetEnabled(false);
    277     fSetZone->ResizeToPreferred();
    278 
    279     fSetZone->MoveTo(frameRight.right - fSetZone->Bounds().Width(),
    280         scrollList->Frame().bottom - fSetZone->Bounds().Height());
     249   
     250    BLayoutBuilder::Group<>(this)
     251        .Add(scrollList)
     252        .AddGroup(B_VERTICAL, 5)
     253            .Add(fCurrent)
     254            .Add(fPreview)
     255            .AddGlue()
     256            .AddGroup(B_HORIZONTAL, 5)
     257                .AddGlue()
     258                .Add(fSetZone)
     259            .End()
     260        .End()
     261        .SetInsets(5, 5, 5, 5);
    281262}
    282263
    283264
  • src/preferences/time/DateTimeEdit.h

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      McCall <mccall@@digitalparadise.co.uk>
    77 *      Mike Berg <mike@berg-net.us>
    88 *      Julun <host.haiku@gmx.de>
    9  *
     9 *      Hamish Morrison <hamish@lavabit.com>
    1010 */
    1111#ifndef _DATE_TIME_EDIT_H
    1212#define _DATE_TIME_EDIT_H
     
    2121
    2222class TTimeEdit : public TSectionEdit {
    2323public:
    24                                 TTimeEdit(BRect frame, const char* name,
    25                                     uint32 sections);
     24                                TTimeEdit(const char* name, uint32 sections);
    2625    virtual                     ~TTimeEdit();
    2726
    2827    virtual void                KeyDown(const char* bytes, int32 numBytes);
    2928
    3029    virtual void                InitView();
    31     virtual void                DrawSection(uint32 index, bool isfocus);
    32     virtual void                DrawSeparator(uint32 index);
     30    virtual void                DrawSection(uint32 index, BRect bounds,
     31                                    bool isfocus);
     32    virtual void                DrawSeparator(uint32 index, BRect bounds);
    3333
    34     virtual void                SetSections(BRect area);
    3534    virtual void                SectionFocus(uint32 index);
    36     virtual float               SeparatorWidth() const;
     35    virtual float               MinSectionWidth();
     36    virtual float               SeparatorWidth();
    3737
     38    virtual float               PreferredHeight();
    3839    virtual void                DoUpPress();
    3940    virtual void                DoDownPress();
    4041
     
    6566
    6667class TDateEdit : public TSectionEdit {
    6768public:
    68                                 TDateEdit(BRect frame, const char* name,
    69                                     uint32 sections);
     69                                TDateEdit(const char* name, uint32 sections);
    7070    virtual                     ~TDateEdit();
    7171    virtual void                KeyDown(const char* bytes, int32 numBytes);
    7272
    7373    virtual void                InitView();
    74     virtual void                DrawSection(uint32 index, bool isfocus);
    75     virtual void                DrawSeparator(uint32 index);
     74    virtual void                DrawSection(uint32 index, BRect bounds,
     75                                    bool isfocus);
     76    virtual void                DrawSeparator(uint32 index, BRect bounds);
    7677
    77     virtual void                SetSections(BRect area);
    7878    virtual void                SectionFocus(uint32 index);
    79     virtual float               SeparatorWidth() const;
     79    virtual float               MinSectionWidth();
     80    virtual float               SeparatorWidth();
    8081
     82    virtual float               PreferredHeight();
    8183    virtual void                DoUpPress();
    8284    virtual void                DoDownPress();
    8385
    8486    virtual void                BuildDispatch(BMessage* message);
     87   
    8588
    8689            void                SetDate(int32 year, int32 month, int32 day);
    8790
     
    9093            void                _CheckRange();
    9194            bool                _IsValidDoubleDigit(int32 value);
    9295            int32               _SectionValue(int32 index) const;
    93 
    9496private:
    9597            BDate               fDate;
    9698            bigtime_t           fLastKeyDownTime;
  • src/preferences/time/SectionEdit.cpp

     
    11/*
    2  * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Mike Berg <mike@berg-net.us>
    77 *      Julun <host.haiku@gmx.de>
    8  *
     8 *      Hamish Morrison <hamish@lavabit.com>
    99 */
    1010
    1111#include "SectionEdit.h"
    1212
    1313#include <Bitmap.h>
    1414#include <ControlLook.h>
     15#include <LayoutUtils.h>
    1516#include <List.h>
    1617#include <Window.h>
    1718
    1819#include "TimeMessages.h"
    1920
    2021
    21 TSection::TSection(BRect frame)
    22     :
    23     fFrame(frame)
    24 {
    25 }
    26 
    27 
    28 BRect
    29 TSection::Bounds() const
    30 {
    31     BRect frame(fFrame);
    32     return frame.OffsetByCopy(B_ORIGIN);
    33 }
    34 
    35 
    36 void
    37 TSection::SetFrame(BRect frame)
    38 {
    39     fFrame = frame;
    40 }
    41 
    42 
    43 BRect
    44 TSection::Frame() const
    45 {
    46     return fFrame;
    47 }
    48 
    49 
    5022const uint32 kArrowAreaWidth = 16;
    5123
    5224
    53 TSectionEdit::TSectionEdit(BRect frame, const char* name, uint32 sections)
     25TSectionEdit::TSectionEdit(const char* name, uint32 sections)
    5426    :
    55     BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
    56     fSectionList(NULL),
     27    BControl(name, NULL, NULL, B_WILL_DRAW | B_NAVIGABLE),
    5728    fFocus(-1),
    5829    fSectionCount(sections),
    5930    fHoldValue(0)
    6031{
    61     InitView();
    6232}
    6333
    6434
    6535TSectionEdit::~TSectionEdit()
    6636{
    67     int32 count = fSectionList->CountItems();
    68     if (count > 0) {
    69         for (int32 index = 0; index < count; index++)
    70             delete (TSection*)fSectionList->ItemAt(index);
    71     }
    72     delete fSectionList;
    7337}
    7438
    7539
     
    8751    DrawBorder(updateRect);
    8852
    8953    for (uint32 idx = 0; idx < fSectionCount; idx++) {
    90         DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
    91         if (idx < fSectionCount -1)
    92             DrawSeparator(idx);
     54        DrawSection(idx, FrameForSection(idx),
     55            ((uint32)fFocus == idx) && IsFocus());
     56        if (idx < fSectionCount - 1)
     57            DrawSeparator(idx, FrameForSeparator(idx));
    9358    }
    9459}
    9560
     
    10368        DoUpPress();
    10469    else if (fDownRect.Contains(where))
    10570        DoDownPress();
    106     else if (fSectionList->CountItems()> 0) {
    107         TSection* section;
     71    else if (fSectionCount > 0) {
    10872        for (uint32 idx = 0; idx < fSectionCount; idx++) {
    109             section = (TSection*)fSectionList->ItemAt(idx);
    110             if (section->Frame().Contains(where)) {
     73            if (FrameForSection(idx).Contains(where)) {
    11174                SectionFocus(idx);
    11275                return;
    11376            }
     
    11679}
    11780
    11881
     82BSize
     83TSectionEdit::MaxSize()
     84{
     85    return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
     86        BSize(B_SIZE_UNLIMITED, PreferredHeight()));
     87}
     88
     89
     90BSize
     91TSectionEdit::MinSize()
     92{
     93    BSize minSize;
     94    minSize.height = PreferredHeight();
     95    minSize.width = (SeparatorWidth() + MinSectionWidth())
     96        * fSectionCount;
     97    return BLayoutUtils::ComposeSize(ExplicitMinSize(),
     98        minSize);
     99}
     100
     101
     102BSize
     103TSectionEdit::PreferredSize()
     104{
     105    return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
     106        MinSize());
     107}
     108
     109
     110BRect
     111TSectionEdit::FrameForSection(uint32 index)
     112{
     113    BRect area = SectionArea();
     114    float sepWidth = SeparatorWidth();
     115   
     116    float width = (area.Width() -
     117        sepWidth * (fSectionCount - 1))
     118        / fSectionCount;
     119    area.left += index * (width + sepWidth);
     120    area.right = area.left + width;
     121
     122    return area;
     123}
     124
     125
     126BRect
     127TSectionEdit::FrameForSeparator(uint32 index)
     128{
     129    BRect area = SectionArea();
     130    float sepWidth = SeparatorWidth();
     131
     132    float width = (area.Width() -
     133        sepWidth * (fSectionCount - 1))
     134        / fSectionCount;
     135    area.left += (index + 1) * width + index * sepWidth;
     136    area.right = area.left + sepWidth;
     137
     138    return area;
     139}
     140
     141
    119142void
    120143TSectionEdit::MakeFocus(bool focused)
    121144{
     
    141164        case B_LEFT_ARROW:
    142165            fFocus -= 1;
    143166            if (fFocus < 0)
    144                 fFocus = fSectionCount -1;
     167                fFocus = fSectionCount - 1;
    145168            SectionFocus(fFocus);
    146169            break;
    147170
     
    180203uint32
    181204TSectionEdit::CountSections() const
    182205{
    183     return fSectionList->CountItems();
     206    return fSectionCount;
    184207}
    185208
    186209
     
    191214}
    192215
    193216
    194 void
    195 TSectionEdit::InitView()
     217BRect
     218TSectionEdit::SectionArea() const
    196219{
    197     // setup sections
    198     fSectionList = new BList(fSectionCount);
    199     fSectionArea = Bounds().InsetByCopy(2, 2);
    200     fSectionArea.right -= kArrowAreaWidth;
     220    BRect sectionArea = Bounds().InsetByCopy(2, 2);
     221    sectionArea.right -= kArrowAreaWidth;
     222    return sectionArea;
    201223}
    202224
    203225
     
    222244    BPoint left(fUpRect.left + 3, fUpRect.bottom - 1);
    223245    BPoint right(left.x + 2 * (middle.x - left.x), fUpRect.bottom - 1);
    224246
    225     SetPenSize(2);
     247    SetPenSize(1);
     248    SetLowColor(ViewColor());
    226249
    227250    if (updateRect.Intersects(fUpRect)) {
    228251        FillRect(fUpRect, B_SOLID_LOW);
     
    244267
    245268    SetPenSize(1);
    246269}
    247 
    248 
    249 float
    250 TSectionEdit::SeparatorWidth() const
    251 {
    252     return 0.0f;
    253 }
    254 
  • src/preferences/time/AnalogClock.h

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Mike Berg <mike@berg-net.us>
    77 *      Julun <host.haiku@gmx.de>
     8 *      Hamish Morrison <hamish@lavabit.com>
    89 */
    910#ifndef _ANALOG_CLOCK_H
    1011#define _ANALOG_CLOCK_H
     
    1314#include <View.h>
    1415
    1516
    16 class BBitmap;
    17 class OffscreenClock;
    18 
    19 
    2017class TAnalogClock : public BView {
    2118public:
    22                                 TAnalogClock(BRect frame, const char* name,
    23                                     bool drawSecondHand = true, bool interactive = true);
    24     virtual                     ~TAnalogClock();
     19                            TAnalogClock(const char* name,
     20                                bool drawSecondHand = true,
     21                                bool interactive = true);
     22    virtual                 ~TAnalogClock();
    2523
    26     virtual void                AttachedToWindow();
    27     virtual void                Draw(BRect updateRect);
    28     virtual void                MessageReceived(BMessage* message);
    29     virtual void                MouseDown(BPoint point);
    30     virtual void                MouseUp(BPoint point);
    31     virtual void                MouseMoved(BPoint point, uint32 transit,
    32                                     const BMessage* message);
     24    virtual void            Draw(BRect updateRect);
     25    virtual void            MessageReceived(BMessage* message);
     26    virtual void            MouseDown(BPoint point);
     27    virtual void            MouseUp(BPoint point);
     28    virtual void            MouseMoved(BPoint point, uint32 transit,
     29                                const BMessage* message);
     30    virtual void            FrameResized(float, float);
     31   
     32    virtual BSize           MaxSize();
     33    virtual BSize           MinSize();
     34    virtual BSize           PreferredSize();
    3335
    34             void                SetTime(int32 hour, int32 minute, int32 second);
     36            void            SetTime(int32 hour, int32 minute, int32 second);
     37            bool            IsChangingTime();
     38            void            ChangeTimeFinished();
    3539
    36             bool                IsChangingTime()
    37                                     {   return fTimeChangeIsOngoing;    }
    38             void                ChangeTimeFinished();
     40            void            GetTime(int32* hour, int32* minute, int32* second);
     41            void            DrawClock();
     42
     43            bool            InHourHand(BPoint point);
     44            bool            InMinuteHand(BPoint point);
     45
     46            void            SetHourHand(BPoint point);
     47            void            SetMinuteHand(BPoint point);
     48
     49            void            SetHourDragging(bool dragging);
     50            void            SetMinuteDragging(bool dragging);
    3951private:
    40             void                _InitView(BRect frame);
    4152
    42             BBitmap*            fBitmap;
    43             OffscreenClock*     fClock;
     53            float           _GetPhi(BPoint point);
     54            bool            _InHand(BPoint point, int32 ticks, float radius);
     55            void            _DrawHands(float x, float y, float radius,
     56                                rgb_color hourHourColor,
     57                                rgb_color hourMinuteColor,
     58                                rgb_color secondsColor, rgb_color knobColor);
    4459
    45             bool                fDrawSecondHand;
    46             bool                fInteractive;
    47             bool                fDraggingHourHand;
    48             bool                fDraggingMinuteHand;
     60            int32           fHours;
     61            int32           fMinutes;
     62            int32           fSeconds;
     63            bool            fDirty;
     64           
     65            float           fCenterX;
     66            float           fCenterY;
     67            float           fRadius;
    4968
    50             bool                fTimeChangeIsOngoing;
     69            bool            fHourDragging;
     70            bool            fMinuteDragging;
     71            bool            fDrawSecondHand;
     72            bool            fInteractive;
     73
     74            bool            fTimeChangeIsOngoing;
     75           
    5176};
    5277
    5378
  • src/preferences/time/TimeWindow.cpp

     
    11/*
    2  * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Andrew McCall <mccall@@digitalparadise.co.uk>
    77 *      Julun <host.haiku@gmx.de>
    8  *
     8 *      Hamish Morrison <hamish@lavabit.com>
    99 */
    1010
    1111#include "TimeWindow.h"
    1212#include "BaseView.h"
    1313#include "DateTimeView.h"
     14#include "NetworkTimeView.h"
    1415#include "TimeMessages.h"
    1516#include "TimeSettings.h"
    1617#include "ZoneView.h"
    1718
    18 
    1919#include <Application.h>
    2020#include <Catalog.h>
     21#include <LayoutBuilder.h>
    2122#include <Message.h>
    2223#include <Screen.h>
    2324#include <TabView.h>
     
    2728#define B_TRANSLATE_CONTEXT "Time"
    2829
    2930TTimeWindow::TTimeWindow(BRect rect)
    30     : BWindow(rect, B_TRANSLATE("Time"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
     31    :
     32    BWindow(rect, B_TRANSLATE("Time"), B_TITLED_WINDOW,
     33        B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
    3134{
    3235    _InitWindow();
    3336    _AlignWindow();
     
    7679            SetRevertStatus();
    7780            break;
    7881
     82        case kMsgTryAllServers:
     83            fNetworkTimeView->MessageReceived(message);
     84            break;
     85
     86        case kMsgSynchronizeAtBoot:
     87            fNetworkTimeView->MessageReceived(message);
     88            break;
     89
     90        case kMsgEditServerList:
     91            fNetworkTimeView->MessageReceived(message);
     92            break;
     93           
     94        case kMsgEditServerListWindowClosed:
     95            fNetworkTimeView->MessageReceived(message);
     96            break;
     97           
     98        case kMsgResetServerList:
     99            fNetworkTimeView->MessageReceived(message);
     100            break;
     101           
     102        case kMsgUpdateSettings:
     103            fNetworkTimeView->MessageReceived(message);
     104            break;
     105           
     106        case kMsgSettingsUpdated:
     107            fNetworkTimeView->MessageReceived(message);
     108            break;
     109           
     110        case kMsgDefaultServer:
     111            fNetworkTimeView->MessageReceived(message);
     112            break;
     113       
     114        case kMsgSynchronize:
     115            fNetworkTimeView->MessageReceived(message);
     116            break;
     117           
     118        case kMsgStopSynchronization:
     119            fNetworkTimeView->MessageReceived(message);
     120            break;
     121           
     122        case kMsgStatusUpdate:
     123            fNetworkTimeView->MessageReceived(message);
     124            break;
     125
    79126        default:
    80127            BWindow::MessageReceived(message);
    81128            break;
     
    102149{
    103150    SetPulseRate(500000);
    104151
    105     fDateTimeView = new DateTimeView(Bounds());
     152    fDateTimeView = new DateTimeView(B_TRANSLATE("Date and time"));
     153    fTimeZoneView = new TimeZoneView(B_TRANSLATE("Time zone"));
     154    fNetworkTimeView = new NetworkTimeView(B_TRANSLATE("Network time"));
    106155
    107     BRect bounds = fDateTimeView->Bounds();
    108     fTimeZoneView = new TimeZoneView(bounds);
    109 
    110     fBaseView = new TTimeBaseView(bounds, "baseView");
    111     AddChild(fBaseView);
    112 
     156    fBaseView = new TTimeBaseView("baseView");
    113157    fBaseView->StartWatchingAll(fDateTimeView);
    114158    fBaseView->StartWatchingAll(fTimeZoneView);
    115159
    116     bounds.OffsetBy(10.0, 10.0);
    117     BTabView* tabView = new BTabView(bounds.InsetByCopy(-5.0, -5.0),
    118         "tabView" , B_WIDTH_AS_USUAL, B_FOLLOW_NONE);
    119 
    120     BTab* tab = new BTab();
    121     tabView->AddTab(fDateTimeView, tab);
    122     tab->SetLabel(B_TRANSLATE("Date & Time"));
    123 
    124     tab = new BTab();
    125     tabView->AddTab(fTimeZoneView, tab);
    126     tab->SetLabel(B_TRANSLATE("Time zone"));
    127 
     160    BTabView* tabView = new BTabView("tabView");
     161    tabView->AddTab(fDateTimeView);
     162    tabView->AddTab(fTimeZoneView);
     163    tabView->AddTab(fNetworkTimeView);
     164   
    128165    fBaseView->AddChild(tabView);
    129     tabView->ResizeBy(0.0, tabView->TabHeight());
    130166
    131     BRect rect = Bounds();
    132 
    133     rect.left = 10;
    134     rect.top = rect.bottom - 10;
    135 
    136     fRevertButton = new BButton(rect, "revert", "Revert",
    137         new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
    138 
    139     fRevertButton->ResizeToPreferred();
     167    fRevertButton = new BButton("revert", "Revert", new BMessage(kMsgRevert));
    140168    fRevertButton->SetEnabled(false);
    141     float buttonHeight = fRevertButton->Bounds().Height();
    142     fRevertButton->MoveBy(0, -buttonHeight);
    143     fBaseView->AddChild(fRevertButton);
    144169    fRevertButton->SetTarget(this);
    145 
    146     fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0,
    147         tabView->Bounds().Height() + buttonHeight + 30.0);
    148 
    149     ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height());
     170   
     171    BLayoutBuilder::Group<>(this, B_VERTICAL, 5)
     172        .Add(fBaseView)
     173        .AddGroup(B_HORIZONTAL, 5)
     174            .Add(fRevertButton)
     175            .AddGlue()
     176        .End()
     177        .SetInsets(5, 5, 5, 5);
    150178}
    151179
    152180
  • src/preferences/time/Jamfile

     
    1010    BaseView.cpp
    1111    Bitmaps.cpp
    1212    DateTimeEdit.cpp
     13    EditServerListWindow.cpp
    1314    SectionEdit.cpp
    1415    DateTimeView.cpp
     16    NetworkTimeView.cpp
     17    ntp.cpp
    1518    Time.cpp
    1619    TimeSettings.cpp
    1720    TimeWindow.cpp
     
    2831
    2932Preference Time
    3033    : $(sources)
    31     : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS)
     34    : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) $(HAIKU_NETWORK_LIBS)
    3235    : Time.rdef
    3336    ;
    3437
  • src/preferences/time/DateTimeView.cpp

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    77 *      Mike Berg <mike@berg-net.us>
    88 *      Julun <host.haiku@gmx.de>
    99 *      Philippe Saint-Pierre <stpere@gmail.com>
     10 *      Hamish Morrison <hamish@lavabit.com>
    1011 */
    1112
    1213#include "DateTimeView.h"
     
    1516#include "TimeMessages.h"
    1617#include "TimeWindow.h"
    1718
     19#include <Box.h>
    1820#include <CalendarView.h>
     21#include <Catalog.h>
    1922#include <CheckBox.h>
    2023#include <DateTime.h>
    2124#include <Entry.h>
     
    3235
    3336#include <syscalls.h>
    3437
     38#undef B_TRANSLATE_CONTEXT
     39#define B_TRANSLATE_CONTEXT "Time"
    3540
     41
    3642using BPrivate::BCalendarView;
    3743using BPrivate::BDateTime;
    3844using BPrivate::B_LOCAL_TIME;
    3945
    4046
    41 DateTimeView::DateTimeView(BRect frame)
    42     : BView(frame, "dateTimeView", B_FOLLOW_NONE, B_WILL_DRAW
    43         | B_NAVIGABLE_JUMP),
     47DateTimeView::DateTimeView(const char* name)
     48    :
     49    BGroupView(name, B_HORIZONTAL, 5),
    4450    fGmtTime(NULL),
    4551    fUseGmtTime(false),
    4652    fInitialized(false),
     
    204210void
    205211DateTimeView::_InitView()
    206212{
    207     font_height fontHeight;
    208     be_plain_font->GetHeight(&fontHeight);
    209     float textHeight = fontHeight.descent + fontHeight.ascent
    210         + fontHeight.leading + 6.0; // 6px border
    211 
    212     // left side
    213     BRect bounds = Bounds();
    214     bounds.InsetBy(10.0, 10.0);
    215     bounds.top += textHeight + 10.0;
    216 
    217     fCalendarView = new BCalendarView(bounds, "calendar");
     213    fCalendarView = new BCalendarView("calendar");
    218214    fCalendarView->SetWeekNumberHeaderVisible(false);
    219     fCalendarView->ResizeToPreferred();
    220215    fCalendarView->SetSelectionMessage(new BMessage(kDayChanged));
    221216    fCalendarView->SetInvocationMessage(new BMessage(kDayChanged));
    222217
    223     bounds.top -= textHeight + 10.0;
    224     bounds.bottom = bounds.top + textHeight;
    225     bounds.right = fCalendarView->Frame().right;
    226 
    227     fDateEdit = new TDateEdit(bounds, "dateEdit", 3);
    228     AddChild(fDateEdit);
    229     AddChild(fCalendarView);
    230 
    231     // right side, 2px extra for separator
    232     bounds.OffsetBy(bounds.Width() + 22.0, 0.0);
    233     fTimeEdit = new TTimeEdit(bounds, "timeEdit", 4);
    234     AddChild(fTimeEdit);
    235 
    236     bounds = fCalendarView->Frame();
    237     bounds.OffsetBy(bounds.Width() + 22.0, 0.0);
    238 
    239     fClock = new TAnalogClock(bounds, "analogClock");
    240     AddChild(fClock);
     218    fDateEdit = new TDateEdit("dateEdit", 3);
     219    fTimeEdit = new TTimeEdit("timeEdit", 4);
     220    fClock = new TAnalogClock("analogClock");
     221   
    241222    BTime time(BTime::CurrentTime(B_LOCAL_TIME));
    242223    fClock->SetTime(time.Hour(), time.Minute(), time.Second());
    243224
    244     // clock radio buttons
    245     bounds.top = fClock->Frame().bottom + 10.0;
    246     BStringView* text = new BStringView(bounds, "clockSetTo", "Clock set to:");
    247     AddChild(text);
    248     text->ResizeToPreferred();
     225    BStringView* text = new BStringView("clockSetTo",
     226        B_TRANSLATE("Clock set to:"));
     227    fLocalTime = new BRadioButton("localTime",
     228        B_TRANSLATE("Local time"), new BMessage(kRTCUpdate));
     229    fGmtTime = new BRadioButton("greenwichMeanTime",
     230        B_TRANSLATE("GMT"), new BMessage(kRTCUpdate));
    249231
    250     bounds.left += 10.0f;
    251     bounds.top = text->Frame().bottom;
    252     fLocalTime = new BRadioButton(bounds, "localTime", "Local time",
    253         new BMessage(kRTCUpdate));
    254     AddChild(fLocalTime);
    255     fLocalTime->ResizeToPreferred();
    256 
    257     bounds.left = fLocalTime->Frame().right + 10.0;
    258     fGmtTime = new BRadioButton(bounds, "greenwichMeanTime", "GMT",
    259         new BMessage(kRTCUpdate));
    260     AddChild(fGmtTime);
    261     fGmtTime->ResizeToPreferred();
    262 
    263232    if (fUseGmtTime)
    264233        fGmtTime->SetValue(B_CONTROL_ON);
    265234    else
    266235        fLocalTime->SetValue(B_CONTROL_ON);
    267 
    268236    fOldUseGmtTime = fUseGmtTime;
    269237
    270     ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0);
     238    BBox* divider = new BBox(BRect(0, 0, 1, 1),
     239        B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
     240        B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
     241    divider->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED));
     242
     243    BLayoutBuilder::Group<>(this)
     244        .AddGroup(B_VERTICAL, 5)
     245            .Add(fDateEdit)
     246            .Add(fCalendarView)
     247        .End()
     248        .Add(divider)
     249        .AddGroup(B_VERTICAL, 5)
     250            .Add(fTimeEdit)
     251            .Add(fClock)
     252            .Add(text)
     253            .AddGroup(B_HORIZONTAL, 5)
     254                .Add(fLocalTime)
     255                .Add(fGmtTime)
     256            .End()
     257        .End()
     258        .SetInsets(5, 5, 5, 5);
    271259}
    272260
    273261
  • src/preferences/time/TZDisplay.h

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Andrew McCall <mccall@@digitalparadise.co.uk>
    77 *      Mike Berg <mike@berg-net.us>
    88 *      Julun <host.haiku@gmx.de>
    9  *
     9 *      Hamish Morrison <hamish@lavabit.com>
    1010 */
    1111#ifndef _TZ_DISPLAY_H
    1212#define _TZ_DISPLAY_H
     
    1818
    1919class TTZDisplay : public BView {
    2020public:
    21                                 TTZDisplay(BRect frame, const char* name,
     21                                TTZDisplay(const char* name,
    2222                                    const char* label);
    2323    virtual                     ~TTZDisplay();
    2424
    2525    virtual void                AttachedToWindow();
    2626    virtual void                ResizeToPreferred();
    2727    virtual void                Draw(BRect updateRect);
     28   
     29    virtual BSize               MaxSize();
     30    virtual BSize               MinSize();
     31    virtual BSize               PreferredSize();
    2832
    2933            const char*         Label() const;
    3034            void                SetLabel(const char* label);
     
    3640            void                SetTime(const char* time);
    3741
    3842private:
     43            BSize               _CalcPrefSize();
     44
    3945            BString             fLabel;
    4046            BString             fText;
    4147            BString             fTime;
  • src/preferences/time/Time.cpp

     
    11/*
    2  * Copyright 2002-2007, Haiku. All rights reserved.
     2 * Copyright 2002-2011, Haiku. All rights reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Andrew McCall <mccall@digitalparadise.co.uk>
    77 *      Mike Berg <mike@berg-net.us>
    88 *      Julun <host.haiku@gmx.de>
     9 *      Hamish Morrison <hamish@lavabit.com>
    910 */
    1011
    1112#include "Time.h"
    12 #include "TimeWindow.h"
    1313
    14 
    1514#include <Alert.h>
    1615#include <Catalog.h>
    1716
    1817#include <unistd.h>
    1918
     19#include "NetworkTimeView.h"
     20#include "TimeWindow.h"
     21
    2022#undef B_TRANSLATE_CONTEXT
    2123#define B_TRANSLATE_CONTEXT "Time"
    2224
     
    2426
    2527
    2628TimeApplication::TimeApplication()
    27     : BApplication(kAppSignature),
    28       fWindow(NULL)
     29    :
     30    BApplication(kAppSignature),
     31    fWindow(NULL)
    2932{
    30     fWindow = new TTimeWindow(BRect(100, 100, 570, 327));
     33    fWindow = new TTimeWindow(BRect(100, 100, 530, 360));
    3134}
    3235
    3336
     
    4750TimeApplication::AboutRequested()
    4851{
    4952    BAlert* alert = new BAlert(B_TRANSLATE("about"),
    50         B_TRANSLATE("Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
    51                     "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."),
     53        B_TRANSLATE(
     54        "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
     55        "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."),
    5256        B_TRANSLATE("OK"));
    5357    alert->Go();
    5458}
     
    6064int
    6165main(int argc, char** argv)
    6266{
    63     TimeApplication app;
    64     setuid(0);
    65     app.Run();
     67    if (argc > 1) {
     68        if (!strcmp(argv[1], "--silent-update")) {
     69            Settings settings;
     70            bool boolean;
     71            if (settings.Message().FindBool("synchronize at boot", &boolean)
     72                == B_OK) {
     73                    if (!boolean) return 0;
     74                    update_time(settings.Message(), NULL);
     75            }
     76        }
     77    }
     78    else {
     79        TimeApplication app;
     80        setuid(0);
     81        app.Run();
     82    }
    6683
    6784    return 0;
    6885}
  • src/preferences/time/EditServerListWindow.cpp

     
     1/*
     2 * Copyright 2004, pinc Software. All Rights Reserved.
     3 * Distributed under the terms of the MIT license.
     4 */
     5
     6#include "EditServerListWindow.h"
     7#include "NetworkTimeView.h"
     8
     9#include <Application.h>
     10#include <TextView.h>
     11#include <ScrollView.h>
     12#include <Button.h>
     13#include <Screen.h>
     14
     15#include <string.h>
     16#include <stdlib.h>
     17
     18
     19static const char *kServerDelimiters = ", \n\t";
     20
     21
     22struct tokens {
     23    char *buffer;
     24    char *next;
     25    const char *delimiters;
     26};
     27
     28
     29static void
     30put_tokens(tokens &tokens)
     31{
     32    free(tokens.buffer);
     33    tokens.buffer = NULL;
     34}
     35
     36
     37static status_t
     38prepare_tokens(tokens &tokens, const char *text, const char *delimiters)
     39{
     40    tokens.buffer = strdup(text);
     41    if (tokens.buffer == NULL)
     42        return B_NO_MEMORY;
     43
     44    tokens.delimiters = delimiters;
     45    tokens.next = tokens.buffer;
     46    return B_OK;
     47}
     48
     49
     50static const char *
     51next_token(tokens &tokens)
     52{
     53    char *token = strtok(tokens.next, tokens.delimiters);
     54    if (tokens.next != NULL)
     55        tokens.next = NULL;
     56    if (token == NULL)
     57        put_tokens(tokens);
     58
     59    return token;
     60}
     61
     62
     63//  #pragma mark -
     64
     65
     66EditServerListWindow::EditServerListWindow(BRect position, const BMessage& settings, BLooper* looper)
     67    :
     68    BWindow(position, "Edit Server List", B_TITLED_WINDOW,
     69        B_ASYNCHRONOUS_CONTROLS),
     70    fSettings(settings),
     71    fLooper(looper)
     72{
     73    BRect rect = Bounds();
     74    BView *view = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
     75    view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     76    AddChild(view);
     77
     78    rect = view->Bounds().InsetByCopy(5, 5);
     79
     80    BButton *button = new BButton(rect, "defaults", "Reset To Defaults",
     81        new BMessage(kMsgResetServerList), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
     82    float width, height;
     83    button->GetPreferredSize(&width, &height);
     84    button->ResizeTo(rect.Width(), height);
     85    button->MoveBy(0, rect.Height() - height);
     86    button->SetTarget(be_app);
     87    view->AddChild(button);
     88
     89    rect.bottom -= 5 + height;
     90    rect.InsetBy(2, 2);
     91    rect.right -= B_V_SCROLL_BAR_WIDTH;
     92
     93    fServerView = new BTextView(rect, "list",
     94        rect.OffsetToCopy(B_ORIGIN).InsetByCopy(3, 3), B_FOLLOW_ALL);
     95    fServerView->SetStylable(true);
     96
     97    BScrollView *scrollView = new BScrollView("scroller", fServerView, B_FOLLOW_ALL, B_WILL_DRAW, false, true);
     98    view->AddChild(scrollView);
     99
     100    UpdateServerView(settings);
     101
     102    SetSizeLimits(200, 16384, 200, 16384);
     103
     104    if (Frame().LeftTop() == B_ORIGIN) {
     105        // center on screen
     106        BScreen screen;
     107        MoveTo((screen.Frame().Width() - Bounds().Width()) / 2,
     108            (screen.Frame().Height() - Bounds().Height()) / 2);
     109    }
     110}
     111
     112
     113EditServerListWindow::~EditServerListWindow()
     114{
     115}
     116
     117
     118void
     119EditServerListWindow::UpdateDefaultServerView(const BMessage &message)
     120{
     121    int32 defaultServer;
     122    if (message.FindInt32("default server", &defaultServer) != B_OK)
     123        return;
     124
     125    BFont font(be_plain_font);
     126    fServerView->SetFontAndColor(0, fServerView->TextLength(),
     127        &font, B_FONT_FAMILY_AND_STYLE);
     128
     129    struct tokens tokens;
     130    const char *server;
     131    if (fSettings.FindString("server", defaultServer, &server) == B_OK
     132        && prepare_tokens(tokens, fServerView->Text(), kServerDelimiters) == B_OK) {
     133        const char *token;
     134        while ((token = next_token(tokens)) != NULL) {
     135            if (strcasecmp(token, server))
     136                continue;
     137
     138            int32 start = int32(token - tokens.buffer);
     139
     140            BFont font;
     141            font.SetFace(B_BOLD_FACE);
     142            fServerView->SetFontAndColor(start, start + strlen(server),
     143                &font, B_FONT_FAMILY_AND_STYLE);
     144           
     145            break;
     146        }
     147        put_tokens(tokens);
     148    }
     149}
     150
     151
     152void
     153EditServerListWindow::UpdateServerView(const BMessage &message)
     154{
     155    if (message.HasString("server") || message.HasBool("reset servers"))
     156        fServerView->SetText("");
     157
     158    int32 defaultServer;
     159    if (message.FindInt32("default server", &defaultServer) != B_OK)
     160        defaultServer = 0;
     161
     162    const char *server;
     163    int32 index = 0;
     164    for (; message.FindString("server", index, &server) == B_OK; index++) {
     165        int32 start, end;
     166        fServerView->GetSelection(&start, &end);
     167
     168        fServerView->Insert(server);
     169        fServerView->Insert("\n");
     170    }
     171
     172    UpdateDefaultServerView(message);
     173}
     174
     175
     176void
     177EditServerListWindow::UpdateServerList()
     178{
     179    // get old default server
     180
     181    int32 defaultServer;
     182    if (fSettings.FindInt32("default server", &defaultServer) != B_OK)
     183        defaultServer = 0;
     184    const char *server;
     185    if (fSettings.FindString("server", defaultServer, &server) != B_OK)
     186        server = NULL;
     187
     188    // take over server list
     189
     190    struct tokens tokens;
     191    if (prepare_tokens(tokens, fServerView->Text(), kServerDelimiters) == B_OK) {
     192        BMessage servers(kMsgUpdateSettings);
     193
     194        int32 count = 0, newDefaultServer = -1;
     195
     196        const char *token;
     197        while ((token = next_token(tokens)) != NULL) {
     198            servers.AddString("server", token);
     199            if (!strcasecmp(token, server))
     200                newDefaultServer = count;
     201
     202            count++;
     203        }
     204
     205        if (count != 0) {
     206            if (newDefaultServer == -1)
     207                newDefaultServer = 0;
     208
     209            servers.AddInt32("default server", newDefaultServer);
     210            fLooper->PostMessage(&servers);
     211        } else
     212            fLooper->PostMessage(kMsgResetServerList);
     213    }
     214}
     215
     216
     217bool
     218EditServerListWindow::QuitRequested()
     219{
     220    fLooper->PostMessage(kMsgEditServerListWindowClosed);
     221
     222    BMessage update(kMsgUpdateSettings);
     223    update.AddRect("edit servers frame", Frame());
     224    fLooper->PostMessage(&update);
     225
     226    UpdateServerList();
     227    return true;
     228}
     229
     230
     231void
     232EditServerListWindow::MessageReceived(BMessage *message)
     233{
     234    switch (message->what) {
     235        case kMsgServersEdited:
     236            UpdateServerList();
     237            break;
     238
     239        case kMsgSettingsUpdated:
     240            if (message->HasString("server"))
     241                UpdateServerView(*message);
     242            else
     243                UpdateDefaultServerView(*message);
     244            break;
     245    }
     246}
     247
  • src/preferences/time/DateTimeEdit.cpp

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    88 *      Julun <host.haiku@gmx.de>
    99 *      Clemens <mail@Clemens-Zeidler.de>
    1010 *      Adrien Destugues <pulkomandy@pulkomandy.cx>
     11 *      Hamish Morrison <hamish@lavabit.com>
    1112 */
    1213
    13 
    1414#include "DateTimeEdit.h"
    1515
    1616#include <stdlib.h>
     
    2424using BPrivate::B_LOCAL_TIME;
    2525
    2626
    27 TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections)
     27TTimeEdit::TTimeEdit(const char* name, uint32 sections)
    2828    :
    29     TSectionEdit(frame, name, sections),
     29    TSectionEdit(name, sections),
    3030    fLastKeyDownTime(0),
    3131    fFields(NULL),
    3232    fFieldCount(0),
     
    5757    int32 section = FocusIndex();
    5858    if (section < 0 || section > 2)
    5959        return;
    60 
    6160    bigtime_t currentTime = system_time();
    6261    if (currentTime - fLastKeyDownTime < 1000000) {
    6362        int32 doubleDigit = number + fLastKeyDownInt * 10;
     
    8483{
    8584    // make sure we call the base class method, as it
    8685    // will create the arrow bitmaps and the section list
    87     TSectionEdit::InitView();
    88 
    8986    fTime = BDateTime::CurrentDateTime(B_LOCAL_TIME);
    9087    _UpdateFields();
    91 
    92     SetSections(fSectionArea);
    9388}
    9489
    9590
    9691void
    97 TTimeEdit::DrawSection(uint32 index, bool hasFocus)
     92TTimeEdit::DrawSection(uint32 index, BRect bounds, bool hasFocus)
    9893{
    99     TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));
    100     if (!section)
     94    if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount)
    10195        return;
    102 
    103     if (fFieldPositions == NULL || index * 2 + 1 > (uint32)fFieldPosCount)
    104         return;
    105 
    106     BRect bounds = section->Frame();
    107 
    10896    SetLowColor(ViewColor());
    10997    if (hasFocus)
    11098        SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
     
    113101    fText.CopyCharsInto(field, fFieldPositions[index * 2],
    114102        fFieldPositions[index * 2 + 1] - fFieldPositions[index * 2]);
    115103
    116     // calc and center text in section rect
    117     float width = be_plain_font->StringWidth(field);
    118 
    119     BPoint offset(-((bounds.Width()- width) / 2.0) - 1.0,
    120         bounds.Height() / 2.0 - 6.0);
    121 
     104    BPoint point(bounds.LeftBottom());
     105    point.y -= bounds.Height() / 2.0 - 6.0;
     106    point.x += (bounds.Width() - StringWidth(field)) / 2;
    122107    SetHighColor(0, 0, 0, 255);
    123108    FillRect(bounds, B_SOLID_LOW);
    124     DrawString(field, bounds.LeftBottom() - offset);
     109    DrawString(field, point);
    125110}
    126111
    127112
    128113void
    129 TTimeEdit::DrawSeparator(uint32 index)
     114TTimeEdit::DrawSeparator(uint32 index, BRect bounds)
    130115{
    131     TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));
    132     if (!section)
     116    if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount)
    133117        return;
    134118
    135     if (fFieldPositions == NULL || index * 2 + 2 > (uint32)fFieldPosCount)
    136         return;
    137 
    138119    BString field;
    139120    fText.CopyCharsInto(field, fFieldPositions[index * 2 + 1],
    140121        fFieldPositions[index * 2 + 2] - fFieldPositions[index * 2 + 1]);
    141122
    142     float sepWidth = SeparatorWidth();
    143     BRect bounds = section->Frame();
    144     float width = be_plain_font->StringWidth(field);
    145     BPoint offset(-((sepWidth - width) / 2.0) - 1.0,
    146         bounds.Height() / 2.0 - 6.0);
    147     DrawString(field, bounds.RightBottom() - offset);
     123    BPoint point(bounds.LeftBottom());
     124    point.y -= bounds.Height() / 2.0 - 6.0;
     125    point.x += (bounds.Width() - StringWidth(field)) / 2;
     126    SetHighColor(0, 0, 0, 255);
     127    DrawString(field, point);
    148128}
    149129
    150130
    151 void
    152 TTimeEdit::SetSections(BRect area)
     131float
     132TTimeEdit::SeparatorWidth()
    153133{
    154     // by default divide up the sections evenly
    155     BRect bounds(area);
    156 
    157     float sepWidth = SeparatorWidth();
    158 
    159     float sep_2 = ceil(sepWidth / fSectionCount + 1);
    160     float width = bounds.Width() / fSectionCount - sep_2;
    161     bounds.right = bounds.left + (width - sepWidth / fSectionCount);
    162 
    163     for (uint32 idx = 0; idx < fSectionCount; idx++) {
    164         fSectionList->AddItem(new TSection(bounds));
    165 
    166         bounds.left = bounds.right + sepWidth;
    167         if (idx == fSectionCount - 2)
    168             bounds.right = area.right - 1;
    169         else
    170             bounds.right = bounds.left + (width - sep_2);
    171     }
     134    return 10.0f;
    172135}
    173136
    174137
    175138float
    176 TTimeEdit::SeparatorWidth() const
     139TTimeEdit::MinSectionWidth()
    177140{
    178     return 10.0f;
     141    return be_plain_font->StringWidth("00");
    179142}
    180143
    181144
     
    236199
    237200    // send message to change time
    238201    DispatchMessage();
     202   
    239203}
    240204
    241205
     
    247211
    248212    message->AddBool("time", true);
    249213
    250     for (int32 index = 0; index < fSectionList->CountItems() - 1; ++index) {
     214    for (int32 index = 0; index < (int)fSectionCount; ++index) {
    251215        uint32 data = _SectionValue(index);
    252216
    253217        if (fFocus == index)
     
    277241TTimeEdit::_UpdateFields()
    278242{
    279243    time_t time = fTime.Time_t();
    280     BLocale::Default()->FormatTime(&fText, fFieldPositions, fFieldPosCount,
    281         time, B_MEDIUM_TIME_FORMAT);
     244   
     245    if (fFieldPositions != NULL) {
     246        free(fFieldPositions);
     247        fFieldPositions = NULL;
     248    }
     249    BLocale::Default()->FormatTime(&fText, fFieldPositions,
     250        fFieldPosCount, time, B_MEDIUM_TIME_FORMAT);
     251
     252    if (fFields != NULL) {
     253        free(fFields);
     254        fFields = NULL;
     255    }
    282256    BLocale::Default()->GetTimeFields(fFields, fFieldCount,
    283257        B_MEDIUM_TIME_FORMAT);
    284258}
     
    405379}
    406380
    407381
     382float
     383TTimeEdit::PreferredHeight()
     384{
     385    font_height fontHeight;
     386    GetFontHeight(&fontHeight);
     387    return ceilf((fontHeight.ascent + fontHeight.descent) * 1.4);
     388}
     389
     390
    408391//  #pragma mark -
    409392
    410393
    411 TDateEdit::TDateEdit(BRect frame, const char* name, uint32 sections)
     394TDateEdit::TDateEdit(const char* name, uint32 sections)
    412395    :
    413     TSectionEdit(frame, name, sections),
     396    TSectionEdit(name, sections),
    414397    fFields(NULL),
    415398    fFieldCount(0),
    416399    fFieldPositions(NULL),
     
    476459{
    477460    // make sure we call the base class method, as it
    478461    // will create the arrow bitmaps and the section list
    479     TSectionEdit::InitView();
    480 
    481462    fDate = BDate::CurrentDate(B_LOCAL_TIME);
    482463    _UpdateFields();
    483 
    484     SetSections(fSectionArea);
    485464}
    486465
    487466
    488467void
    489 TDateEdit::DrawSection(uint32 index, bool hasFocus)
     468TDateEdit::DrawSection(uint32 index, BRect bounds, bool hasFocus)
    490469{
    491     TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));
    492     if (!section)
     470    if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount)
    493471        return;
    494472
    495     if (fFieldPositions == NULL || index * 2 + 1 > (uint32)fFieldPosCount)
    496         return;
    497 
    498473    SetLowColor(ViewColor());
    499474    if (hasFocus)
    500475        SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
     
    503478    fText.CopyCharsInto(field, fFieldPositions[index * 2],
    504479        fFieldPositions[index * 2 + 1] - fFieldPositions[index * 2]);
    505480
    506     // calc and center text in section rect
    507     BRect bounds = section->Frame();
    508     float width = StringWidth(field);
    509     BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0,
    510         (bounds.Height() / 2.0 - 6.0));
    511 
     481    BPoint point(bounds.LeftBottom());
     482    point.y -= bounds.Height() / 2.0 - 6.0;
     483    point.x += (bounds.Width() - StringWidth(field)) / 2;
    512484    SetHighColor(0, 0, 0, 255);
    513485    FillRect(bounds, B_SOLID_LOW);
    514     DrawString(field, bounds.LeftBottom() - offset);
     486    DrawString(field, point);
    515487}
    516488
    517489
    518490void
    519 TDateEdit::DrawSeparator(uint32 index)
     491TDateEdit::DrawSeparator(uint32 index, BRect bounds)
    520492{
    521493    if (index >= 2)
    522494        return;
    523495
    524     TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));
    525     if (!section)
     496    if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount)
    526497        return;
    527498
    528     if (fFieldPositions == NULL || index * 2 + 2 > (uint32)fFieldPosCount)
    529         return;
    530 
    531499    BString field;
    532500    fText.CopyCharsInto(field, fFieldPositions[index * 2 + 1],
    533501        fFieldPositions[index * 2 + 2] - fFieldPositions[index * 2 + 1]);
    534502
    535     BRect bounds = section->Frame();
    536     float width = be_plain_font->StringWidth(field);
    537     float sepWidth = SeparatorWidth();
    538     BPoint offset(-((sepWidth - width) / 2.0) - 1.0,
    539         bounds.Height() / 2.0 - 6.0);
    540 
     503    BPoint point(bounds.LeftBottom());
     504    point.y -= bounds.Height() / 2.0 - 6.0;
     505    point.x += (bounds.Width() - StringWidth(field)) / 2;
    541506    SetHighColor(0, 0, 0, 255);
    542     DrawString(field, bounds.RightBottom() - offset);
     507    DrawString(field, point);
    543508}
    544509
    545510
    546511void
    547 TDateEdit::SetSections(BRect area)
     512TDateEdit::SectionFocus(uint32 index)
    548513{
    549     // TODO : we have to be more clever here, as the fields can move and have
    550     // different sizes depending on the locale
    551 
    552     // create sections
    553     for (uint32 idx = 0; idx < fSectionCount; idx++)
    554         fSectionList->AddItem(new TSection(area));
    555 
    556     BRect bounds(area);
    557     float sepWidth = SeparatorWidth();
    558 
    559     TSection* section = static_cast<TSection*>(fSectionList->ItemAt(0));
    560     float width = be_plain_font->StringWidth("0000") + 10;
    561     bounds.left = area.left;
    562     bounds.right = bounds.left + width;
    563     section->SetFrame(bounds);
    564 
    565     section = static_cast<TSection*>(fSectionList->ItemAt(1));
    566     width = be_plain_font->StringWidth("0000") + 10;
    567     bounds.left = bounds.right + sepWidth;
    568     bounds.right = bounds.left + width;
    569     section->SetFrame(bounds);
    570 
    571     section = static_cast<TSection*>(fSectionList->ItemAt(2));
    572     width = be_plain_font->StringWidth("0000") + 10;
    573     bounds.left = bounds.right + sepWidth;
    574     bounds.right = bounds.left + width;
    575     section->SetFrame(bounds);
     514    fLastKeyDownTime = 0;
     515    fFocus = index;
     516    fHoldValue = _SectionValue(index);
     517    Draw(Bounds());
    576518}
    577519
    578520
    579521float
    580 TDateEdit::SeparatorWidth() const
     522TDateEdit::MinSectionWidth()
    581523{
    582     return 10.0f;
     524    return be_plain_font->StringWidth("00");
    583525}
    584526
    585527
    586 void
    587 TDateEdit::SectionFocus(uint32 index)
     528float
     529TDateEdit::SeparatorWidth()
    588530{
    589     fLastKeyDownTime = 0;
    590     fFocus = index;
    591     fHoldValue = _SectionValue(index);
    592     Draw(Bounds());
     531    return 10.0f;
    593532}
    594533
    595534
     
    647586
    648587    message->AddBool("time", false);
    649588
    650     for (int32 index = 0; index < fSectionList->CountItems(); ++index) {
     589    for (int32 index = 0; index < (int)fSectionCount; ++index) {
    651590        uint32 data = _SectionValue(index);
    652591
    653592        if (fFocus == index)
     
    677616TDateEdit::_UpdateFields()
    678617{
    679618    time_t time = BDateTime(fDate, BTime()).Time_t();
     619   
     620    if (fFieldPositions != NULL) {
     621        free(fFieldPositions);
     622        fFieldPositions = NULL;
     623    }
    680624    BLocale::Default()->FormatDate(&fText, fFieldPositions, fFieldPosCount,
    681625        time, B_SHORT_DATE_FORMAT);
     626   
     627    if (fFields != NULL) {
     628        free(fFields);
     629        fFields = NULL;
     630    }   
    682631    BLocale::Default()->GetDateFields(fFields, fFieldCount,
    683632        B_SHORT_DATE_FORMAT);
    684633}
     
    797746
    798747    return value;
    799748}
     749
     750
     751float
     752TDateEdit::PreferredHeight()
     753{
     754    font_height fontHeight;
     755    GetFontHeight(&fontHeight);
     756    return ceilf((fontHeight.ascent + fontHeight.descent) * 1.4);
     757}
  • src/preferences/time/NetworkTimeView.h

     
     1/*
     2 * Copyright 2011, Haiku, Inc. All Rights Reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Hamish Morrison <hamish@lavabit.com>
     7 *      Axel Dörfler <axeld@pinc-software.de>
     8 */
     9#ifndef NETWORK_TIME_VIEW_H
     10#define NETWORK_TIME_VIEW_H
     11
     12#include <LayoutBuilder.h>
     13#include <Message.h>
     14#include <Path.h>
     15
     16#include "EditServerListWindow.h"
     17#include "TimeMessages.h"
     18
     19class BMenuField;
     20class BButton;
     21class BCheckBox;
     22class Monitor;
     23class Settings;
     24
     25
     26status_t
     27update_time(const BMessage &settings, Monitor *monitor,
     28    thread_id *_asyncThread);
     29status_t
     30update_time(const BMessage &settings, Monitor *monitor);
     31
     32
     33class Settings {
     34    public:
     35        Settings();
     36        ~Settings();
     37
     38        void CopyMessage(BMessage &message) const;
     39        const BMessage &Message() const;
     40        void UpdateFrom(BMessage &message);
     41
     42        void ResetServersToDefaults();
     43        void ResetToDefaults();
     44        status_t Load();
     45        status_t Save();
     46
     47    private:
     48        status_t GetPath(BPath &path);
     49
     50        BMessage    fMessage;
     51        bool        fWasUpdated;
     52};
     53
     54
     55class NetworkTimeView : public BGroupView {
     56    public:
     57        NetworkTimeView(const char* name);
     58       
     59        virtual void MessageReceived(BMessage* message);
     60    private:
     61        void _InitView();
     62        void _UpdateServerListMenu();
     63    private:
     64   
     65        BMenuField*     fServerListMenuField;
     66        BButton*        fEditServerListButton;
     67        BButton*        fSynchronizeButton;
     68        BCheckBox*      fTryAllServersCheckBox;
     69        BCheckBox*      fSynchronizeAtBootCheckBox;
     70
     71        BWindow*        fEditServerListWindow;
     72       
     73        thread_id       fUpdateThread;
     74        const char*     fStatusString;
     75        Settings        fSettings;
     76};
     77   
     78#endif
  • src/preferences/time/BaseView.h

     
    1010#define _BASE_VIEW_H
    1111
    1212
     13#include <LayoutBuilder.h>
    1314#include <Message.h>
    14 #include <View.h>
    1515
    1616
    17 class TTimeBaseView: public BView {
     17class TTimeBaseView: public BGroupView {
    1818public:
    19                                 TTimeBaseView(BRect frame, const char* name);
     19                                TTimeBaseView(const char* name);
    2020    virtual                     ~TTimeBaseView();
    2121
    2222    virtual void                Pulse();
  • src/preferences/time/ZoneView.h

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Mike Berg <mike@berg-net.us>
    77 *      Julun <host.haiku@gmx.de>
     8 *      Hamish Morrison <hamish@lavabit.com>
    89 */
    910#ifndef ZONE_VIEW_H
    1011#define ZONE_VIEW_H
    1112
    1213
     14#include <LayoutBuilder.h>
    1315#include <TimeZone.h>
    14 #include <View.h>
    1516
    1617
    1718class BButton;
     
    2425class TTZDisplay;
    2526
    2627
    27 class TimeZoneView : public BView {
     28class TimeZoneView : public BGroupView {
    2829public:
    29                                 TimeZoneView(BRect frame);
     30                                TimeZoneView(const char* name);
    3031    virtual                     ~TimeZoneView();
    3132
    3233    virtual void                AttachedToWindow();
  • src/preferences/time/AnalogClock.cpp

     
    11/*
    2  * Copyright 2004-2009, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    77 *      Julun <host.haiku@gmx.de>
    88 *      Stephan Aßmus <superstippi@gmx.de>
    99 *      Clemens <mail@Clemens-Zeidler.de>
     10 *      Hamish Morrison <hamish@lavabit.com>
    1011 */
    1112
    1213#include "AnalogClock.h"
     
    1415#include <math.h>
    1516#include <stdio.h>
    1617
    17 #include <Bitmap.h>
     18#include <LayoutUtils.h>
    1819#include <Message.h>
    1920#include <Window.h>
    2021
     
    2425#define DRAG_DELTA_PHI 0.2
    2526
    2627
    27 class OffscreenClock : public BView {
    28 public:
    29                             OffscreenClock(BRect frame, const char* name,
    30                                 bool drawSecondHand = true);
    31     virtual                 ~OffscreenClock();
    32 
    33             void            SetTime(int32 hour, int32 minute, int32 second);
    34             void            GetTime(int32* hour, int32* minute, int32* second);
    35             bool            IsDirty() const {   return fDirty;  }
    36             void            DrawClock();
    37 
    38             bool            InHourHand(BPoint point);
    39             bool            InMinuteHand(BPoint point);
    40 
    41             void            SetHourHand(BPoint point);
    42             void            SetMinuteHand(BPoint point);
    43 
    44             void            SetHourDragging(bool dragging);
    45             void            SetMinuteDragging(bool dragging);
    46 
    47 private:
    48             float           _GetPhi(BPoint point);
    49             bool            _InHand(BPoint point, int32 ticks, float radius);
    50             void            _DrawHands(float x, float y, float radius,
    51                                 rgb_color hourHourColor,
    52                                 rgb_color hourMinuteColor,
    53                                 rgb_color secondsColor, rgb_color knobColor);
    54 
    55             int32           fHours;
    56             int32           fMinutes;
    57             int32           fSeconds;
    58             bool            fDirty;
    59 
    60             float           fCenterX;
    61             float           fCenterY;
    62             float           fRadius;
    63 
    64             bool            fHourDragging;
    65             bool            fMinuteDragging;
    66            
    67             bool            fDrawSecondHand;
    68 };
    69 
    70 
    71 OffscreenClock::OffscreenClock(BRect frame, const char* name,
    72     bool drawSecondHand)
    73     :
    74     BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
    75     fHours(0),
    76     fMinutes(0),
    77     fSeconds(0),
    78     fDirty(true),
    79     fHourDragging(false),
    80     fMinuteDragging(false),
    81     fDrawSecondHand(drawSecondHand)
    82 {
    83     SetFlags(Flags() | B_SUBPIXEL_PRECISE);
    84 
    85     BRect bounds = Bounds();
    86     fCenterX = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5;
    87     fCenterY = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5;
    88         // + 0.5 is for the offset to pixel centers
    89         // (important when drawing with B_SUBPIXEL_PRECISE)
    90 
    91     fRadius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5;
    92     fRadius -= 3;
    93 }
    94 
    95 
    96 OffscreenClock::~OffscreenClock()
    97 {
    98 }
    99 
    100 
    10128void
    102 OffscreenClock::SetTime(int32 hour, int32 minute, int32 second)
     29TAnalogClock::GetTime(int32* hour, int32* minute, int32* second)
    10330{
    104     if (fHours == hour && fMinutes == minute && fSeconds == second)
    105         return;
    106 
    107     fHours = hour;
    108     fMinutes = minute;
    109     fSeconds = second;
    110 
    111     fDirty = true;
    112 }
    113 
    114 
    115 void
    116 OffscreenClock::GetTime(int32* hour, int32* minute, int32* second)
    117 {
    11831    *hour = fHours;
    11932    *minute = fMinutes;
    12033    *second = fSeconds;
     
    12235
    12336
    12437void
    125 OffscreenClock::DrawClock()
     38TAnalogClock::DrawClock()
    12639{
    12740    if (!LockLooper())
    12841        return;
     
    13245    rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
    13346    SetHighColor(background);
    13447    FillRect(bounds);
    135 
    136 
     48   
    13749    bounds.Set(fCenterX - fRadius, fCenterY - fRadius,
    13850        fCenterX + fRadius, fCenterY + fRadius);
    13951
     
    207119}
    208120
    209121
     122void
     123TAnalogClock::FrameResized(float, float)
     124{
     125    BRect bounds = Bounds();
     126
     127    // + 0.5 is for the offset to pixel centers
     128    // (important when drawing with B_SUBPIXEL_PRECISE)
     129    fCenterX = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5;
     130    fCenterY = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5;
     131    fRadius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5;
     132    fRadius -= 3;
     133}
     134
     135
     136BSize
     137TAnalogClock::MaxSize()
     138{
     139    return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
     140        BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
     141}
     142
     143
     144BSize
     145TAnalogClock::MinSize()
     146{
     147    return BSize(0, 0);
     148}
     149
     150
     151BSize
     152TAnalogClock::PreferredSize()
     153{
     154    return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
     155        BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
     156}
     157
     158
    210159bool
    211 OffscreenClock::InHourHand(BPoint point)
     160TAnalogClock::InHourHand(BPoint point)
    212161{
    213162    int32 ticks = fHours;
    214163    if (ticks > 12)
     
    222171
    223172
    224173bool
    225 OffscreenClock::InMinuteHand(BPoint point)
     174TAnalogClock::InMinuteHand(BPoint point)
    226175{
    227176    return _InHand(point, fMinutes, fRadius * 0.9);
    228177}
    229178
    230179
    231180void
    232 OffscreenClock::SetHourHand(BPoint point)
     181TAnalogClock::SetHourHand(BPoint point)
    233182{
    234183    point.x -= fCenterX;
    235184    point.y -= fCenterY;
     
    247196
    248197
    249198void
    250 OffscreenClock::SetMinuteHand(BPoint point)
     199TAnalogClock::SetMinuteHand(BPoint point)
    251200{
    252201    point.x -= fCenterX;
    253202    point.y -= fCenterY;
     
    260209}
    261210
    262211
    263 void
    264 OffscreenClock::SetHourDragging(bool dragging)
    265 {
    266     fHourDragging = dragging;
    267     fDirty = true;
    268 }
    269 
    270 
    271 void
    272 OffscreenClock::SetMinuteDragging(bool dragging)
    273 {
    274     fMinuteDragging = dragging;
    275     fDirty = true;
    276 }
    277 
    278 
    279212float
    280 OffscreenClock::_GetPhi(BPoint point)
     213TAnalogClock::_GetPhi(BPoint point)
    281214{
    282215    if (point.x == 0 && point.y < 0)
    283216        return 2 * M_PI;
     
    302235
    303236
    304237bool
    305 OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
     238TAnalogClock::_InHand(BPoint point, int32 ticks, float radius)
    306239{
    307240    point.x -= fCenterX;
    308241    point.y -= fCenterY;
     
    323256
    324257
    325258void
    326 OffscreenClock::_DrawHands(float x, float y, float radius,
    327     rgb_color hourColor,
    328     rgb_color minuteColor,
    329     rgb_color secondsColor,
    330     rgb_color knobColor)
     259TAnalogClock::_DrawHands(float x, float y, float radius,
     260    rgb_color hourColor, rgb_color minuteColor,
     261    rgb_color secondsColor, rgb_color knobColor)
    331262{
    332263    float offsetX;
    333264    float offsetY;
     
    366297//  #pragma mark -
    367298
    368299
    369 TAnalogClock::TAnalogClock(BRect frame, const char* name,
     300TAnalogClock::TAnalogClock(const char* name,
    370301    bool drawSecondHand, bool interactive)
    371302    :
    372     BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),
    373     fBitmap(NULL),
    374     fClock(NULL),
     303    BView(name, B_WILL_DRAW | B_DRAW_ON_CHILDREN | B_FRAME_EVENTS),
     304    fHours(0),
     305    fMinutes(0),
     306    fSeconds(0),
     307    fDirty(true),
     308    fHourDragging(false),
     309    fMinuteDragging(false),
    375310    fDrawSecondHand(drawSecondHand),
    376311    fInteractive(interactive),
    377     fDraggingHourHand(false),
    378     fDraggingMinuteHand(false),
    379312    fTimeChangeIsOngoing(false)
    380313{
    381     _InitView(frame);
     314    SetFlags(Flags() | B_SUBPIXEL_PRECISE);
    382315}
    383316
    384317
    385318TAnalogClock::~TAnalogClock()
    386319{
    387     delete fBitmap;
    388320}
    389321
    390322
    391323void
    392 TAnalogClock::_InitView(BRect rect)
    393 {
    394     fClock = new OffscreenClock(Bounds(), "offscreen", fDrawSecondHand);
    395     fBitmap = new BBitmap(Bounds(), B_RGB32, true);
    396     fBitmap->Lock();
    397     fBitmap->AddChild(fClock);
    398     fBitmap->Unlock();
    399 }
    400 
    401 
    402 void
    403 TAnalogClock::AttachedToWindow()
    404 {
    405     SetViewColor(B_TRANSPARENT_COLOR);
    406 }
    407 
    408 
    409 void
    410324TAnalogClock::MessageReceived(BMessage* message)
    411325{
    412326    int32 change;
     
    445359        return;
    446360    }
    447361   
    448     fDraggingMinuteHand = fClock->InMinuteHand(point);
    449     if (fDraggingMinuteHand) {
    450         fClock->SetMinuteDragging(true);
     362    if (InMinuteHand(point)) {
     363        fMinuteDragging = true;
     364        fDirty = true;
    451365        SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
    452366        Invalidate();
    453367        return;
    454368    }
    455     fDraggingHourHand = fClock->InHourHand(point);
    456     if (fDraggingHourHand) {
    457         fClock->SetHourDragging(true);
     369    if (InHourHand(point)) {
     370        fHourDragging = true;
     371        fDirty = true;
    458372        SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
    459373        Invalidate();
    460374        return;
     
    470384        return;
    471385    }
    472386   
    473     if (fDraggingHourHand || fDraggingMinuteHand) {
     387    if (fHourDragging || fMinuteDragging) {
    474388        int32 hour, minute, second;
    475         fClock->GetTime(&hour, &minute, &second);
     389        GetTime(&hour, &minute, &second);
    476390        BMessage message(H_USER_CHANGE);
    477391        message.AddBool("time", true);
    478392        message.AddInt32("hour", hour);
     
    480394        Window()->PostMessage(&message);
    481395        fTimeChangeIsOngoing = true;
    482396    }
    483     fDraggingHourHand = false;
    484     fDraggingMinuteHand = false;
    485     fClock->SetMinuteDragging(false);
    486     fClock->SetHourDragging(false);
     397    fHourDragging = false;
     398    fDirty = true;
     399    fMinuteDragging = false;
     400    fDirty = true;
    487401}
    488402
    489403
     
    495409        return;
    496410    }
    497411
    498     if (fDraggingMinuteHand)
    499         fClock->SetMinuteHand(point);
    500     if (fDraggingHourHand)
    501         fClock->SetHourHand(point);
     412    if (fMinuteDragging)
     413        SetMinuteHand(point);
     414    if (fHourDragging)
     415        SetHourHand(point);
    502416
    503417    Invalidate();
    504418}
     
    507421void
    508422TAnalogClock::Draw(BRect /*updateRect*/)
    509423{
    510     if (fBitmap) {
    511         if (fClock->IsDirty())
    512             fClock->DrawClock();
    513         DrawBitmap(fBitmap, BPoint(0, 0));
    514     }
     424    if (fDirty)
     425        DrawClock();
    515426}
    516427
    517428
     
    519430TAnalogClock::SetTime(int32 hour, int32 minute, int32 second)
    520431{
    521432    // don't set the time if the hands are in a drag action
    522     if (fDraggingHourHand || fDraggingMinuteHand || fTimeChangeIsOngoing)
     433    if (fHourDragging || fMinuteDragging || fTimeChangeIsOngoing)
    523434        return;
     435   
     436    if (fHours == hour && fMinutes == minute && fSeconds == second)
     437        return;
    524438
    525     if (fClock)
    526         fClock->SetTime(hour, minute, second);
     439    fHours = hour;
     440    fMinutes = minute;
     441    fSeconds = second;
    527442
     443    fDirty = true;
     444
    528445    BWindow* window = Window();
    529446    if (window && window->Lock()) {
    530447        Invalidate();
     
    533450}
    534451
    535452
     453bool
     454TAnalogClock::IsChangingTime()
     455{
     456    return fTimeChangeIsOngoing;
     457}
     458
     459
    536460void
    537461TAnalogClock::ChangeTimeFinished()
    538462{
  • src/preferences/time/SectionEdit.h

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Mike Berg <mike@berg-net.us>
    77 *      Julun <host.haiku@gmx.de>
    8  *
     8 *      Hamish Morrison <hamish@lavabit.com>
    99 */
    1010#ifndef _SECTION_EDIT_H
    1111#define _SECTION_EDIT_H
     
    1818class BList;
    1919
    2020
    21 class TSection {
    22 public:
    23                                 TSection(BRect frame);
    24 
    25             BRect               Bounds() const;
    26             void                SetFrame(BRect frame);
    27             BRect               Frame() const;
    28 
    29 private:
    30             BRect               fFrame;
    31 };
    32 
    33 
    3421class TSectionEdit: public BControl {
    3522public:
    36                                 TSectionEdit(BRect frame, const char* name,
     23                                TSectionEdit(const char* name,
    3724                                    uint32 sections);
    3825    virtual                     ~TSectionEdit();
    3926
     
    4330    virtual void                MakeFocus(bool focused = true);
    4431    virtual void                KeyDown(const char* bytes, int32 numBytes);
    4532
     33            BSize               MaxSize();
     34            BSize               MinSize();
     35            BSize               PreferredSize();
     36
    4637            uint32              CountSections() const;
    4738            int32               FocusIndex() const;
    4839            BRect               SectionArea() const;
    4940
    5041protected:
    51     virtual void                InitView();
    52 
    53     // hooks
    5442    virtual void                DrawBorder(const BRect& updateRect);
    55     virtual void                DrawSection(uint32 index, bool isFocus) {}
    56     virtual void                DrawSeparator(uint32 index) {}
     43    virtual void                DrawSection(uint32 index, BRect bounds,
     44                                    bool isFocus) {}
     45    virtual void                DrawSeparator(uint32 index, BRect bounds) {}
    5746
     47            BRect               FrameForSection(uint32 index);
     48            BRect               FrameForSeparator(uint32 index);
     49
    5850    virtual void                SectionFocus(uint32 index) {}
    5951    virtual void                SectionChange(uint32 index, uint32 value) {}
    6052    virtual void                SetSections(BRect area) {}
    61     virtual float               SeparatorWidth() const;
    62 
     53   
     54    virtual float               SeparatorWidth() = 0;
     55    virtual float               MinSectionWidth() = 0;
     56    virtual float               PreferredHeight() = 0;
     57   
    6358    virtual void                DoUpPress() {}
    6459    virtual void                DoDownPress() {}
    6560
    6661    virtual void                DispatchMessage();
    6762    virtual void                BuildDispatch(BMessage* message) = 0;
    6863
    69 protected:
    70             BList*              fSectionList;
    71 
     64protected:         
    7265            BRect               fUpRect;
    7366            BRect               fDownRect;
    74             BRect               fSectionArea;
    7567
    7668            int32               fFocus;
    7769            uint32              fSectionCount;
  • src/preferences/time/TZDisplay.cpp

     
    11/*
    2  * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Andrew McCall <mccall@@digitalparadise.co.uk>
    77 *      Mike Berg <mike@berg-net.us>
    88 *      Julun <host.haiku@gmx.de>
    9  *
     9 *      Hamish Morrison <hamish@lavabit.com>
    1010 */
    1111
     12#include "TZDisplay.h"
     13
    1214#include <stdio.h>
    1315
    14 #include "TZDisplay.h"
     16#include <LayoutUtils.h>
    1517
    1618
    1719namespace {
     
    2628}
    2729
    2830
    29 TTZDisplay::TTZDisplay(BRect frame, const char* name, const char* label)
    30     : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
     31TTZDisplay::TTZDisplay(const char* name, const char* label)
     32    : BView(name, B_WILL_DRAW),
    3133      fLabel(label),
    3234      fText(""),
    3335      fTime("")
     
    121123    Invalidate();
    122124}
    123125
     126
     127BSize
     128TTZDisplay::MaxSize()
     129{
     130    BSize size = _CalcPrefSize();
     131    size.width = B_SIZE_UNLIMITED;
     132   
     133    return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
     134        size);
     135}
     136
     137
     138BSize
     139TTZDisplay::MinSize()
     140{
     141    return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
     142        _CalcPrefSize());
     143}
     144
     145
     146BSize
     147TTZDisplay::PreferredSize()
     148{
     149    return MinSize();
     150}
     151
     152
     153BSize
     154TTZDisplay::_CalcPrefSize()
     155{
     156    font_height fontHeight;
     157    GetFontHeight(&fontHeight);
     158   
     159    BSize size;
     160    size.height = 2 * ceilf(fontHeight.ascent + fontHeight.descent);
     161    size.width =StringWidth(
     162        "                                                       ");
     163    return size;   
     164}
     165
  • src/preferences/time/TimeMessages.h

     
    4646// change time finished
    4747const uint32 kChangeTimeFinished = 'tcfi';
    4848
     49// network time messages
     50const uint32 kMsgNetworkTimeSettings = 'ntst';
     51const uint32 kMsgDefaultServer = 'dfsr';
     52const uint32 kMsgEditServerList = 'esrv';
     53const uint32 kMsgTryAllServers = 'tras';
     54const uint32 kMsgSynchronizeAtBoot = 'synb';
     55const uint32 kMsgSynchronize = 'sync';
     56const uint32 kMsgStopSynchronization = 'stps';
     57const uint32 kMsgStatusUpdate = 'stup';
    4958
     59// network time edit window messages
     60const uint32 kMsgUpdateSettings = 'upse';
     61const uint32 kMsgSettingsUpdated = 'seUp';
     62const uint32 kMsgServersEdited = 'sedt';
     63const uint32 kMsgResetServerList = 'rtsl';
     64const uint32 kMsgEditServerListWindowClosed = 'eswc';
     65
     66
    5067#endif  // _TIME_MESSAGES_H
    5168
  • src/preferences/time/TimeWindow.h

     
    55 * Authors:
    66 *      Andrew McCall <mccall@@digitalparadise.co.uk>
    77 *      Julun <host.haiku@gmx.de>
    8  *
    98 */
    109#ifndef _TIME_WINDOW_H
    1110#define _TIME_WINDOW_H
     
    1817class DateTimeView;
    1918class TTimeBaseView;
    2019class TimeZoneView;
     20class NetworkTimeView;
    2121
    2222
    2323class TTimeWindow : public BWindow {
     
    3939            TTimeBaseView*      fBaseView;
    4040            DateTimeView*       fDateTimeView;
    4141            TimeZoneView*       fTimeZoneView;
     42            NetworkTimeView*    fNetworkTimeView;
    4243            BButton*            fRevertButton;
    4344};
    4445
  • src/preferences/time/DateTimeView.h

     
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    77 *      Mike Berg <mike@berg-net.us>
    88 *      Julun <host.haiku@gmx.de>
    99 *      Philippe Saint-Pierre <stpere@gmail.com>
     10 *      Hamish Morrison <hamish@lavabit.com>
    1011 */
    1112#ifndef _DATE_TIME_VIEW_H
    1213#define _DATE_TIME_VIEW_H
    1314
    1415
    15 #include <View.h>
     16#include <LayoutBuilder.h>
    1617
    1718
    1819class TDateEdit;
     
    2728using BPrivate::BCalendarView;
    2829
    2930
    30 class DateTimeView : public BView {
     31class DateTimeView : public BGroupView {
    3132public:
    32                                 DateTimeView(BRect frame);
     33                                DateTimeView(const char* name);
    3334    virtual                     ~DateTimeView();
    3435
    3536    virtual void                AttachedToWindow();
  • src/kits/shared/CalendarView.cpp

     
    1111
    1212#include <stdlib.h>
    1313
     14#include <LayoutUtils.h>
    1415#include <Window.h>
    1516
    1617
     
    7273}
    7374
    7475
     76BCalendarView::BCalendarView(const char* name, uint32 flags)
     77    :
     78    BView(name, flags),
     79    BInvoker(),
     80    fSelectionMessage(NULL),
     81    fDay(0),
     82    fYear(0),
     83    fMonth(0),
     84    fFocusChanged(false),
     85    fSelectionChanged(false),
     86    fWeekStart(B_WEEK_START_SUNDAY),
     87    fDayNameHeaderVisible(true),
     88    fWeekNumberHeaderVisible(true)
     89{
     90    _InitObject();
     91}
     92
     93
    7594BCalendarView::~BCalendarView()
    7695{
    7796    SetSelectionMessage(NULL);
     
    559578}
    560579
    561580
     581BSize
     582BCalendarView::MaxSize()
     583{
     584    return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
     585        BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
     586}
     587
     588
     589BSize
     590BCalendarView::MinSize()
     591{
     592    float width, height;
     593    _GetPreferredSize(&width, &height);
     594    return BLayoutUtils::ComposeSize(ExplicitMinSize(),
     595        BSize(width, height));
     596}
     597
     598
     599BSize
     600BCalendarView::PreferredSize()
     601{
     602    return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
     603        MinSize());
     604}
     605
     606
    562607int32
    563608BCalendarView::Day() const
    564609{
  • headers/private/shared/CalendarView.h

     
    3636                                BCalendarView(BRect frame, const char *name, week_start start,
    3737                                    uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
    3838                                    uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
     39                               
     40                                BCalendarView(const char* name,
     41                                    uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
    3942
    4043        virtual                 ~BCalendarView();
    4144
     
    8891
    8992        virtual void            ResizeToPreferred();
    9093        virtual void            GetPreferredSize(float *width, float *height);
     94       
     95        virtual BSize           MaxSize();
     96        virtual BSize           MinSize();
     97        virtual BSize           PreferredSize();
    9198
    9299        int32                   Day() const;
    93100        int32                   Year() const;