Ticket #5111: Sounds.patch

File Sounds.patch, 17.7 KB (added by mt, 14 years ago)

patch file

  • HWindow.cpp

     
    1919#include <Beep.h>
    2020#include <Box.h>
    2121#include <Button.h>
     22#include <Catalog.h>
    2223#include <ClassInfo.h>
    2324#include <FindDirectory.h>
    2425#include <fs_attr.h>
     26#include <GroupLayoutBuilder.h>
     27#include <Locale.h>
    2528#include <MediaFiles.h>
    2629#include <MenuBar.h>
    2730#include <MenuField.h>
     
    3538#include <Sound.h>
    3639
    3740
    38 HWindow::HWindow(BRect rect, const char *name)
    39     : _inherited(rect, name, B_TITLED_WINDOW, 0),
     41#undef TR_CONTEXT
     42#define TR_CONTEXT "HWindow"
     43
     44HWindow::HWindow(BRect rect, const char* name)
     45    : _inherited(rect, name, B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS),
    4046    fFilePanel(NULL),
    4147    fPlayer(NULL)
    4248{
    4349    InitGUI();
    44     float min_width, min_height, max_width, max_height;
    45     GetSizeLimits(&min_width, &max_width, &min_height, &max_height);
    46     min_width = 300;
    47     min_height = 200;
    48     SetSizeLimits(min_width, max_width, min_height, max_height);
    4950
    5051    fFilePanel = new BFilePanel();
    5152    fFilePanel->SetTarget(this);
     
    6263void
    6364HWindow::InitGUI()
    6465{
    65     BRect rect = Bounds();
    66     rect.bottom -= 106;
    67     BView *listView = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED);
    68     listView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    69     AddChild(listView);
    70 
    71     rect.left += 13;
    72     rect.right -= 13;
    73     rect.top += 28;
    74     rect.bottom -= 7;
    75     fEventList = new HEventList(rect);
    76     listView->AddChild(fEventList);
     66    fEventList = new HEventList();
    7767    fEventList->SetType(BMediaFiles::B_SOUNDS);
    7868    fEventList->SetSelectionMode(B_SINGLE_SELECTION_LIST);
    7969
    80     rect = Bounds();
    81     rect.top = rect.bottom - 105;
    82     BView *view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED);
    83     view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    84     AddChild(view);
    85     rect = view->Bounds().InsetBySelf(12, 12);
    86     BBox *box = new BBox(rect, "", B_FOLLOW_ALL);
    87     view->AddChild(box);
    88     rect = box->Bounds();
    89     rect.top += 10;
    90     rect.left += 15;
    91     rect.right -= 10;
    92     rect.bottom = rect.top + 20;
    93     BMenu *menu = new BMenu("file");
     70    BGroupView* view = new BGroupView();
     71    BBox* box = new BBox("", B_WILL_DRAW | B_FRAME_EVENTS
     72        | B_NAVIGABLE_JUMP | B_PULSE_NEEDED);
     73
     74    BMenu* menu = new BMenu("file");
    9475    menu->SetRadioMode(true);
    9576    menu->SetLabelFromMarked(true);
    9677    menu->AddSeparatorItem();
    97    
    98     menu->AddItem(new BMenuItem("<none>", new BMessage(M_NONE_MESSAGE)));
    99     menu->AddItem(new BMenuItem("Other" B_UTF8_ELLIPSIS, new BMessage(M_OTHER_MESSAGE)));
    100     BMenuField *menuField = new BMenuField(rect, "filemenu", "Sound File:", menu,
    101         B_FOLLOW_TOP | B_FOLLOW_LEFT);
    102     menuField->SetDivider(menuField->StringWidth("Sound File:") + 10);
    103     box->AddChild(menuField);
    104     rect.OffsetBy(-2, menuField->Bounds().Height() + 15);
    105     BButton *button = new BButton(rect, "stop", "Stop", new BMessage(M_STOP_MESSAGE),
    106         B_FOLLOW_RIGHT | B_FOLLOW_TOP);
    107     button->ResizeToPreferred();
    108     button->SetEnabled(false);
    109     button->MoveTo(box->Bounds().right - button->Bounds().Width() - 15, rect.top);
    110     box->AddChild(button);
     78    menu->AddItem(new BMenuItem(TR("<none>"), new BMessage(M_NONE_MESSAGE)));
     79    menu->AddItem(new BMenuItem(TR("Other…") /*B_UTF8_ELLIPSIS*/,
     80        new BMessage(M_OTHER_MESSAGE)));
     81    BMenuField* menuField = new BMenuField("filemenu", TR("Sound File:"), menu);
     82    menuField->SetDivider(menuField->StringWidth(TR("Sound File:")) + 10);
    11183
    112     rect = button->Frame();
    113     view->ResizeTo(view->Bounds().Width(), 24 + rect.bottom + 12);
    114     box->ResizeTo(box->Bounds().Width(), rect.bottom + 12);
     84    BButton* stopbutton = new BButton("stop", TR("Stop"),
     85        new BMessage(M_STOP_MESSAGE));
     86    stopbutton->SetEnabled(false);
    11587
    116     button->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP);
    117     button = new BButton(rect, "play", "Play", new BMessage(M_PLAY_MESSAGE),
    118         B_FOLLOW_RIGHT | B_FOLLOW_TOP);
    119     button->ResizeToPreferred();
    120     button->SetEnabled(false);
    121     button->MoveTo(rect.left - button->Bounds().Width() - 15, rect.top);
    122     box->AddChild(button);
     88    BButton* playbutton = new BButton("play", TR("Play"),
     89        new BMessage(M_PLAY_MESSAGE));
     90    playbutton->SetEnabled(false);
    12391   
    124     view->MoveTo(0, listView->Frame().bottom);
    125     ResizeTo(Bounds().Width(), listView->Frame().bottom + view->Bounds().Height());
    126     listView->SetResizingMode(B_FOLLOW_ALL);
    127     view->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
     92    view->SetLayout(new BGroupLayout(B_HORIZONTAL));
     93    view->AddChild(BGroupLayoutBuilder(B_VERTICAL, 15)
     94        .AddGroup(B_HORIZONTAL)
     95            .Add(menuField)
     96            .AddGlue()
     97        .End()
     98        .AddGroup(B_HORIZONTAL, 15)
     99            .AddGlue()
     100            .Add(playbutton)
     101            .Add(stopbutton)
     102        .End()
     103        .SetInsets(15, 15, 15, 15)
     104    );
    128105
     106    box->AddChild(view);
     107
     108    SetLayout(new BGroupLayout(B_HORIZONTAL));
     109    AddChild(BGroupLayoutBuilder(B_VERTICAL)
     110        .AddGroup(B_VERTICAL, 20)
     111            .Add(fEventList)
     112            .Add(box)
     113        .End()
     114        .SetInsets(12, 28, 12, 12)
     115    );
     116
    129117    // setup file menu
    130118    SetupMenuField();
    131     menu->FindItem("<none>")->SetMarked(true);
     119    menu->FindItem(TR("<none>"))->SetMarked(true);
    132120}
    133121
    134122
    135123void
    136 HWindow::MessageReceived(BMessage *message)
     124HWindow::MessageReceived(BMessage* message)
    137125{
    138126    switch (message->what) {
    139127        case M_OTHER_MESSAGE:
    140128        {
    141             BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
    142             BMenu *menu = menufield->Menu();
     129            BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField);
     130            BMenu* menu = menufield->Menu();
    143131
    144             HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
     132            HEventRow* row = (HEventRow* )fEventList->CurrentSelection();
    145133            if (row != NULL) {
    146134                BPath path(row->Path());
    147135                if (path.InitCheck() != B_OK) {
    148                     BMenuItem *item = menu->FindItem("<none>");
     136                    BMenuItem* item = menu->FindItem("<none>");
    149137                    if (item)
    150138                        item->SetMarked(true);
    151139                } else {
    152                     BMenuItem *item = menu->FindItem(path.Leaf());
     140                    BMenuItem* item = menu->FindItem(path.Leaf());
    153141                    if (item)
    154142                        item->SetMarked(true);
    155143                }
     
    162150        case B_REFS_RECEIVED:
    163151        {
    164152            entry_ref ref;
    165             HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
     153            HEventRow* row = (HEventRow* )fEventList->CurrentSelection();
    166154            if (message->FindRef("refs", &ref) == B_OK && row != NULL) {
    167                 BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
    168                 BMenu *menu = menufield->Menu();
     155                BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField);
     156                BMenu* menu = menufield->Menu();
    169157
    170158                // check audio file
    171159                BNode node(&ref);
     
    177165                mtype.GetSupertype(&superType);
    178166                if (superType.Type() == NULL || strcmp(superType.Type(), "audio") != 0) {
    179167                    beep();
    180                     (new BAlert("", "This is not a audio file.", "OK", NULL, NULL,
     168                    (new BAlert("", TR("This is not a audio file."), TR("OK"), NULL, NULL,
    181169                        B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
    182170                    break;
    183171                }
    184172
    185173                // add file item
    186                 BMessage *msg = new BMessage(M_ITEM_MESSAGE);
     174                BMessage* msg = new BMessage(M_ITEM_MESSAGE);
    187175                BPath path(&ref);
    188176                msg->AddRef("refs", &ref);
    189                 BMenuItem *menuitem = menu->FindItem(path.Leaf());
     177                BMenuItem* menuitem = menu->FindItem(path.Leaf());
    190178                if (!menuitem)
    191179                    menu->AddItem(menuitem = new BMenuItem(path.Leaf(), msg), 0);
    192180                // refresh item
     
    200188
    201189        case M_PLAY_MESSAGE:
    202190        {
    203             HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
     191            HEventRow* row = (HEventRow* )fEventList->CurrentSelection();
    204192            if (row != NULL) {
    205                 const char *path = row->Path();
     193                const char* path = row->Path();
    206194                if (path) {
    207195                    entry_ref ref;
    208196                    ::get_ref_for_path(path, &ref);
     
    228216
    229217        case M_EVENT_CHANGED:
    230218        {
    231             const char *path;
    232             BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
    233             BMenu *menu = menufield->Menu();
     219            const char* path;
     220            BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField);
     221            BMenu* menu = menufield->Menu();
    234222
    235223            if (message->FindString("path", &path) == B_OK) {
    236224                BPath path(path);
    237225                if (path.InitCheck() != B_OK) {
    238                     BMenuItem *item = menu->FindItem("<none>");
     226                    BMenuItem* item = menu->FindItem(TR("<none>"));
    239227                    if (item)
    240228                        item->SetMarked(true);
    241229                } else {
    242                     BMenuItem *item = menu->FindItem(path.Leaf());
     230                    BMenuItem* item = menu->FindItem(path.Leaf());
    243231                    if (item)
    244232                        item->SetMarked(true);
    245233                }
     
    270258void
    271259HWindow::SetupMenuField()
    272260{
    273     BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
    274     BMenu *menu = menufield->Menu();
     261    BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField);
     262    BMenu* menu = menufield->Menu();
    275263    int32 count = fEventList->CountRows();
    276264    for (int32 i = 0; i < count; i++) {
    277         HEventRow *row = (HEventRow *)fEventList->RowAt(i);
     265        HEventRow* row = (HEventRow* )fEventList->RowAt(i);
    278266        if (!row)
    279267            continue;
    280268
     
    284272        if (menu->FindItem(path.Leaf()))
    285273            continue;
    286274
    287         BMessage *msg = new BMessage(M_ITEM_MESSAGE);
     275        BMessage* msg = new BMessage(M_ITEM_MESSAGE);
    288276        entry_ref ref;
    289277        ::get_ref_for_path(path.Path(), &ref);
    290278        msg->AddRef("refs", &ref);
     
    309297        if (menu->FindItem(item_path.Leaf()))
    310298            continue;
    311299
    312         BMessage *msg = new BMessage(M_ITEM_MESSAGE);
     300        BMessage* msg = new BMessage(M_ITEM_MESSAGE);
    313301        entry_ref ref;
    314302        ::get_ref_for_path(item_path.Path(), &ref);
    315303        msg->AddRef("refs", &ref);
     
    329317        if (menu->FindItem(item_path.Leaf()))
    330318            continue;
    331319
    332         BMessage *msg = new BMessage(M_ITEM_MESSAGE);
     320        BMessage* msg = new BMessage(M_ITEM_MESSAGE);
    333321        entry_ref ref;
    334322
    335323        ::get_ref_for_path(item_path.Path(), &ref);
     
    350338        if (menu->FindItem(item_path.Leaf()))
    351339            continue;
    352340
    353         BMessage *msg = new BMessage(M_ITEM_MESSAGE);
     341        BMessage* msg = new BMessage(M_ITEM_MESSAGE);
    354342        entry_ref ref;
    355343
    356344        ::get_ref_for_path(item_path.Path(), &ref);
     
    364352void
    365353HWindow::Pulse()
    366354{
    367     HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
    368     BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
    369     BButton *button = cast_as(FindView("play"), BButton);
    370     BButton *stop = cast_as(FindView("stop"), BButton);
     355    HEventRow* row = (HEventRow* )fEventList->CurrentSelection();
     356    BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField);
     357    BButton* button = cast_as(FindView("play"), BButton);
     358    BButton* stop = cast_as(FindView("stop"), BButton);
    371359
    372360    if (!menufield)
    373361        return;
     
    375363    if (row != NULL) {
    376364        menufield->SetEnabled(true);
    377365
    378         const char *path = row->Path();
     366        const char* path = row->Path();
    379367        if (path && strcmp(path, ""))
    380368            button->SetEnabled(true);
    381369        else
     
    396384
    397385
    398386void
    399 HWindow::DispatchMessage(BMessage *message, BHandler *handler)
     387HWindow::DispatchMessage(BMessage* message, BHandler* handler)
    400388{
    401389    if (message->what == B_PULSE)
    402390        Pulse();
  • HWindow.h

     
    66//  by the OpenBeOS license.
    77//
    88//
    9 //  File:        HWindow.h
    10 //  Author:      Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu
    11 //  Description: Sounds Preferences
    12 //  Created :    November 24, 2003
     9//  File:           HWindow.h
     10//  Author:         Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu
     11//  Description:    Sounds Preferences
     12//  Created :       November 24, 2003
    1313//
    1414// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    1515
     
    4040                        HWindow(BRect rect ,const char* name);
    4141protected:
    4242        virtual         ~HWindow();
    43         virtual void    MessageReceived(BMessage *message);
     43        virtual void    MessageReceived(BMessage* message);
    4444        virtual bool    QuitRequested();
    45         virtual void    DispatchMessage(BMessage *message
    46                                         ,BHandler *handler);
     45        virtual void    DispatchMessage(BMessage* message
     46                                        ,BHandler* handler);
    4747                void    InitGUI();
    4848                void    SetupMenuField();
    4949                void    Pulse();
     
    5252            HEventList* fEventList;
    5353        typedef BWindow _inherited;
    5454            BFilePanel* fFilePanel;
    55             BFileGameSound *fPlayer;
     55            BFileGameSound* fPlayer;
    5656};
    5757#endif
  • HEventList.cpp

     
    1010#include "HEventList.h"
    1111
    1212#include <Alert.h>
     13#include <Catalog.h>
    1314#include <ColumnTypes.h>
    1415#include <Entry.h>
     16#include <Locale.h>
    1517#include <MediaFiles.h>
    1618#include <Path.h>
    1719#include <stdio.h>
    1820
     21#undef TR_CONTEXT
     22#define TR_CONTEXT "HEventList"
    1923
    2024HEventRow::HEventRow(const char* name, const char* path)
    2125    : BRow(),
     
    3640{
    3741    fPath = _path;
    3842    BPath path(_path);
    39     SetField(new BStringField(_path ? path.Leaf() : "<none>"), kSoundColumn);
     43    SetField(new BStringField(_path ? path.Leaf() : TR("<none>")), kSoundColumn);
    4044}
    4145
    4246
    4347void
    44 HEventRow::Remove(const char *type)
     48HEventRow::Remove(const char* type)
    4549{
    4650    BMediaFiles().RemoveItem(type, Name());
    4751}
    4852
    4953
    50 HEventList::HEventList(BRect rect, const char* name)
    51     : BColumnListView(rect, name, B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true),
     54HEventList::HEventList(const char* name)
     55    : BColumnListView(name, 0, B_PLAIN_BORDER, true),
    5256        fType(NULL)
    5357{
    54     AddColumn(new BStringColumn("Event", 150, 50, 500, B_TRUNCATE_MIDDLE), kEventColumn);
    55     AddColumn(new BStringColumn("Sound", 150, 50, 500, B_TRUNCATE_END), kSoundColumn);
     58    AddColumn(new BStringColumn(TR("Event"), 150, 50, 500, B_TRUNCATE_MIDDLE),
     59        kEventColumn);
     60    AddColumn(new BStringColumn(TR("Sound"), 150, 50, 500, B_TRUNCATE_END),
     61        kSoundColumn);
    5662}
    5763
    5864
     
    7682    entry_ref ref;
    7783    while (mfiles.GetNextRef(&name,&ref) == B_OK) {
    7884        BPath path(&ref);
    79         if ((path.InitCheck() != B_OK) || (ref.name == NULL) || (strcmp(ref.name, "") == 0))
     85        if ((path.InitCheck() != B_OK) || (ref.name == NULL)
     86            || (strcmp(ref.name, "") == 0))
    8087            AddRow(new HEventRow(name.String(), NULL));
    8188        else
    8289            AddRow(new HEventRow(name.String(), path.Path()));
     
    8794void
    8895HEventList::RemoveAll()
    8996{
    90     BRow *row;
     97    BRow* row;
    9198    while ((row = RowAt((int32)0, NULL))!=NULL) {
    9299        RemoveRow(row);
    93100        delete row;
     
    100107{
    101108    BColumnListView::SelectionChanged();
    102109   
    103     HEventRow* row = (HEventRow *)CurrentSelection();
     110    HEventRow* row = (HEventRow* )CurrentSelection();
    104111    if (row != NULL) {
    105112        entry_ref ref;
    106113        BMediaFiles().GetRefFor(fType, row->Name(), &ref);
    107114       
    108115        BPath path(&ref);
    109         if ((path.InitCheck()==B_OK) || (ref.name == NULL) || (strcmp(ref.name, "") == 0)) {
     116        if ((path.InitCheck()==B_OK) || (ref.name == NULL)
     117            || (strcmp(ref.name, "") == 0)) {
    110118            row->SetPath(path.Path());
    111119            UpdateRow(row);
    112120        } else {
    113121            printf("name %s\n", ref.name);
    114122            BMediaFiles().RemoveRefFor(fType, row->Name(), ref);
    115             (new BAlert("alert", "No such file or directory", "Ok"))->Go();
     123            (new BAlert("alert", TR("No such file or directory"),
     124                TR("Ok")))->Go();
    116125            return;
    117126        }
    118127        BMessage msg(M_EVENT_CHANGED);
     
    126135void
    127136HEventList::SetPath(const char* path)
    128137{
    129     HEventRow* row = (HEventRow *)CurrentSelection();
     138    HEventRow* row = (HEventRow* )CurrentSelection();
    130139    if (row != NULL) {
    131140        entry_ref ref;
    132141        BEntry entry(path);
  • Jamfile

     
    11SubDir HAIKU_TOP src preferences sounds ;
    22
    3 SetSubDirSupportedPlatformsBeOSCompatible ;
    4 
    53UsePrivateHeaders interface ;
    64
    75Preference Sounds :
     
    97#   HEventItem.cpp
    108    HWindow.cpp
    119    HEventList.cpp
    12     : be libcolumnlistview.a game tracker libmedia.so $(TARGET_LIBSUPC++)
     10    : be libcolumnlistview.a game tracker libmedia.so $(TARGET_LIBSUPC++) liblocale.so
    1311    : Sounds.rdef
    1412    ;
     13
     14DoCatalogs Sounds :
     15    x-vnd.Haiku-Sounds
     16    :
     17    HApp.cpp
     18    HWindow.cpp
     19    HEventList.cpp
     20    : en.catalog
     21    ;
  • HApp.cpp

     
    1313#include "HWindow.h"
    1414
    1515#include <Alert.h>
     16#include <Catalog.h>
     17#include <Locale.h>
    1618
     19#undef TR_CONTEXT
     20#define TR_CONTEXT "SoundsHApp"
    1721
    1822HApp::HApp()
    1923    : BApplication("application/x-vnd.Haiku-Sounds")
    2024{
     25    be_locale->GetAppCatalog(&fCatalog);
     26
    2127    BRect rect;
    2228    rect.Set(200, 150, 500, 450);
    2329
    24     HWindow *win = new HWindow(rect, "Sounds");
     30    HWindow* win = new HWindow(rect, TR("Sounds"));
    2531    win->Show();
    2632}
    2733
     
    3440void
    3541HApp::AboutRequested()
    3642{
    37     (new BAlert("About Sounds", "Sounds\n"
    38                 "  Brought to you by :\n"
    39                 "   Oliver Ruiz Dorantes\n"
    40                 "   Jérôme DUVAL.\n"
    41                 "  Original work from Atsushi Takamatsu.\n"
    42                 "Copyright " B_UTF8_COPYRIGHT "2003-2006 Haiku", "OK"))->Go();
     43    (new BAlert(TR("About Sounds"),
     44                TR("Sounds\n"
     45                "  Brought to you by :\n"
     46                "\tOliver Ruiz Dorantes\n"
     47                "\tJérôme DUVAL.\n"
     48                "  Original work from Atsushi Takamatsu.\n"
     49                "Copyright ©2003-2006 Haiku"),
     50                TR("OK")))->Go();
    4351}
    4452
    4553
  • HEventList.h

     
    2727       
    2828        const char*     Name() const { return fName.String();}
    2929        const char*     Path() const { return fPath.String();}
    30             void        Remove(const char *type);
     30            void        Remove(const char* type);
    3131            void        SetPath(const char* path);
    3232protected:
    3333
     
    4444
    4545class HEventList : public BColumnListView {
    4646public:
    47                     HEventList(BRect rect,
    48                         const char* name = "EventList");
     47                    HEventList( const char* name = "EventList");
    4948        virtual         ~HEventList();
    5049                void    RemoveAll();
    5150                void    SetType(const char* type);
  • HApp.h

     
    1212
    1313
    1414#include <Application.h>
     15#include <Catalog.h>
    1516
    1617
    1718class HApp :public BApplication {
     
    2122
    2223    protected:
    2324        virtual void AboutRequested();
     25        BCatalog fCatalog;
    2426};
    2527
    2628#endif  // HAPP_H