Ticket #5111: Sounds.patch
File Sounds.patch, 17.7 KB (added by , 14 years ago) |
---|
-
HWindow.cpp
19 19 #include <Beep.h> 20 20 #include <Box.h> 21 21 #include <Button.h> 22 #include <Catalog.h> 22 23 #include <ClassInfo.h> 23 24 #include <FindDirectory.h> 24 25 #include <fs_attr.h> 26 #include <GroupLayoutBuilder.h> 27 #include <Locale.h> 25 28 #include <MediaFiles.h> 26 29 #include <MenuBar.h> 27 30 #include <MenuField.h> … … 35 38 #include <Sound.h> 36 39 37 40 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 44 HWindow::HWindow(BRect rect, const char* name) 45 : _inherited(rect, name, B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS), 40 46 fFilePanel(NULL), 41 47 fPlayer(NULL) 42 48 { 43 49 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);49 50 50 51 fFilePanel = new BFilePanel(); 51 52 fFilePanel->SetTarget(this); … … 62 63 void 63 64 HWindow::InitGUI() 64 65 { 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(); 77 67 fEventList->SetType(BMediaFiles::B_SOUNDS); 78 68 fEventList->SetSelectionMode(B_SINGLE_SELECTION_LIST); 79 69 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"); 94 75 menu->SetRadioMode(true); 95 76 menu->SetLabelFromMarked(true); 96 77 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); 111 83 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); 115 87 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); 123 91 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 ); 128 105 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 129 117 // setup file menu 130 118 SetupMenuField(); 131 menu->FindItem( "<none>")->SetMarked(true);119 menu->FindItem(TR("<none>"))->SetMarked(true); 132 120 } 133 121 134 122 135 123 void 136 HWindow::MessageReceived(BMessage *message)124 HWindow::MessageReceived(BMessage* message) 137 125 { 138 126 switch (message->what) { 139 127 case M_OTHER_MESSAGE: 140 128 { 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(); 143 131 144 HEventRow* row = (HEventRow *)fEventList->CurrentSelection();132 HEventRow* row = (HEventRow* )fEventList->CurrentSelection(); 145 133 if (row != NULL) { 146 134 BPath path(row->Path()); 147 135 if (path.InitCheck() != B_OK) { 148 BMenuItem *item = menu->FindItem("<none>");136 BMenuItem* item = menu->FindItem("<none>"); 149 137 if (item) 150 138 item->SetMarked(true); 151 139 } else { 152 BMenuItem *item = menu->FindItem(path.Leaf());140 BMenuItem* item = menu->FindItem(path.Leaf()); 153 141 if (item) 154 142 item->SetMarked(true); 155 143 } … … 162 150 case B_REFS_RECEIVED: 163 151 { 164 152 entry_ref ref; 165 HEventRow* row = (HEventRow *)fEventList->CurrentSelection();153 HEventRow* row = (HEventRow* )fEventList->CurrentSelection(); 166 154 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(); 169 157 170 158 // check audio file 171 159 BNode node(&ref); … … 177 165 mtype.GetSupertype(&superType); 178 166 if (superType.Type() == NULL || strcmp(superType.Type(), "audio") != 0) { 179 167 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, 181 169 B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); 182 170 break; 183 171 } 184 172 185 173 // add file item 186 BMessage *msg = new BMessage(M_ITEM_MESSAGE);174 BMessage* msg = new BMessage(M_ITEM_MESSAGE); 187 175 BPath path(&ref); 188 176 msg->AddRef("refs", &ref); 189 BMenuItem *menuitem = menu->FindItem(path.Leaf());177 BMenuItem* menuitem = menu->FindItem(path.Leaf()); 190 178 if (!menuitem) 191 179 menu->AddItem(menuitem = new BMenuItem(path.Leaf(), msg), 0); 192 180 // refresh item … … 200 188 201 189 case M_PLAY_MESSAGE: 202 190 { 203 HEventRow* row = (HEventRow *)fEventList->CurrentSelection();191 HEventRow* row = (HEventRow* )fEventList->CurrentSelection(); 204 192 if (row != NULL) { 205 const char *path = row->Path();193 const char* path = row->Path(); 206 194 if (path) { 207 195 entry_ref ref; 208 196 ::get_ref_for_path(path, &ref); … … 228 216 229 217 case M_EVENT_CHANGED: 230 218 { 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(); 234 222 235 223 if (message->FindString("path", &path) == B_OK) { 236 224 BPath path(path); 237 225 if (path.InitCheck() != B_OK) { 238 BMenuItem *item = menu->FindItem("<none>");226 BMenuItem* item = menu->FindItem(TR("<none>")); 239 227 if (item) 240 228 item->SetMarked(true); 241 229 } else { 242 BMenuItem *item = menu->FindItem(path.Leaf());230 BMenuItem* item = menu->FindItem(path.Leaf()); 243 231 if (item) 244 232 item->SetMarked(true); 245 233 } … … 270 258 void 271 259 HWindow::SetupMenuField() 272 260 { 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(); 275 263 int32 count = fEventList->CountRows(); 276 264 for (int32 i = 0; i < count; i++) { 277 HEventRow *row = (HEventRow *)fEventList->RowAt(i);265 HEventRow* row = (HEventRow* )fEventList->RowAt(i); 278 266 if (!row) 279 267 continue; 280 268 … … 284 272 if (menu->FindItem(path.Leaf())) 285 273 continue; 286 274 287 BMessage *msg = new BMessage(M_ITEM_MESSAGE);275 BMessage* msg = new BMessage(M_ITEM_MESSAGE); 288 276 entry_ref ref; 289 277 ::get_ref_for_path(path.Path(), &ref); 290 278 msg->AddRef("refs", &ref); … … 309 297 if (menu->FindItem(item_path.Leaf())) 310 298 continue; 311 299 312 BMessage *msg = new BMessage(M_ITEM_MESSAGE);300 BMessage* msg = new BMessage(M_ITEM_MESSAGE); 313 301 entry_ref ref; 314 302 ::get_ref_for_path(item_path.Path(), &ref); 315 303 msg->AddRef("refs", &ref); … … 329 317 if (menu->FindItem(item_path.Leaf())) 330 318 continue; 331 319 332 BMessage *msg = new BMessage(M_ITEM_MESSAGE);320 BMessage* msg = new BMessage(M_ITEM_MESSAGE); 333 321 entry_ref ref; 334 322 335 323 ::get_ref_for_path(item_path.Path(), &ref); … … 350 338 if (menu->FindItem(item_path.Leaf())) 351 339 continue; 352 340 353 BMessage *msg = new BMessage(M_ITEM_MESSAGE);341 BMessage* msg = new BMessage(M_ITEM_MESSAGE); 354 342 entry_ref ref; 355 343 356 344 ::get_ref_for_path(item_path.Path(), &ref); … … 364 352 void 365 353 HWindow::Pulse() 366 354 { 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); 371 359 372 360 if (!menufield) 373 361 return; … … 375 363 if (row != NULL) { 376 364 menufield->SetEnabled(true); 377 365 378 const char *path = row->Path();366 const char* path = row->Path(); 379 367 if (path && strcmp(path, "")) 380 368 button->SetEnabled(true); 381 369 else … … 396 384 397 385 398 386 void 399 HWindow::DispatchMessage(BMessage *message, BHandler *handler)387 HWindow::DispatchMessage(BMessage* message, BHandler* handler) 400 388 { 401 389 if (message->what == B_PULSE) 402 390 Pulse(); -
HWindow.h
6 6 // by the OpenBeOS license. 7 7 // 8 8 // 9 // File: 10 // Author: 11 // Description: 12 // Created : 9 // File: HWindow.h 10 // Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu 11 // Description: Sounds Preferences 12 // Created : November 24, 2003 13 13 // 14 14 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 15 15 … … 40 40 HWindow(BRect rect ,const char* name); 41 41 protected: 42 42 virtual ~HWindow(); 43 virtual void MessageReceived(BMessage *message);43 virtual void MessageReceived(BMessage* message); 44 44 virtual bool QuitRequested(); 45 virtual void DispatchMessage(BMessage *message46 ,BHandler *handler);45 virtual void DispatchMessage(BMessage* message 46 ,BHandler* handler); 47 47 void InitGUI(); 48 48 void SetupMenuField(); 49 49 void Pulse(); … … 52 52 HEventList* fEventList; 53 53 typedef BWindow _inherited; 54 54 BFilePanel* fFilePanel; 55 BFileGameSound *fPlayer;55 BFileGameSound* fPlayer; 56 56 }; 57 57 #endif -
HEventList.cpp
10 10 #include "HEventList.h" 11 11 12 12 #include <Alert.h> 13 #include <Catalog.h> 13 14 #include <ColumnTypes.h> 14 15 #include <Entry.h> 16 #include <Locale.h> 15 17 #include <MediaFiles.h> 16 18 #include <Path.h> 17 19 #include <stdio.h> 18 20 21 #undef TR_CONTEXT 22 #define TR_CONTEXT "HEventList" 19 23 20 24 HEventRow::HEventRow(const char* name, const char* path) 21 25 : BRow(), … … 36 40 { 37 41 fPath = _path; 38 42 BPath path(_path); 39 SetField(new BStringField(_path ? path.Leaf() : "<none>"), kSoundColumn);43 SetField(new BStringField(_path ? path.Leaf() : TR("<none>")), kSoundColumn); 40 44 } 41 45 42 46 43 47 void 44 HEventRow::Remove(const char *type)48 HEventRow::Remove(const char* type) 45 49 { 46 50 BMediaFiles().RemoveItem(type, Name()); 47 51 } 48 52 49 53 50 HEventList::HEventList( BRect rect,const char* name)51 : BColumnListView( rect, name, B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true),54 HEventList::HEventList(const char* name) 55 : BColumnListView(name, 0, B_PLAIN_BORDER, true), 52 56 fType(NULL) 53 57 { 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); 56 62 } 57 63 58 64 … … 76 82 entry_ref ref; 77 83 while (mfiles.GetNextRef(&name,&ref) == B_OK) { 78 84 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)) 80 87 AddRow(new HEventRow(name.String(), NULL)); 81 88 else 82 89 AddRow(new HEventRow(name.String(), path.Path())); … … 87 94 void 88 95 HEventList::RemoveAll() 89 96 { 90 BRow *row;97 BRow* row; 91 98 while ((row = RowAt((int32)0, NULL))!=NULL) { 92 99 RemoveRow(row); 93 100 delete row; … … 100 107 { 101 108 BColumnListView::SelectionChanged(); 102 109 103 HEventRow* row = (HEventRow *)CurrentSelection();110 HEventRow* row = (HEventRow* )CurrentSelection(); 104 111 if (row != NULL) { 105 112 entry_ref ref; 106 113 BMediaFiles().GetRefFor(fType, row->Name(), &ref); 107 114 108 115 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)) { 110 118 row->SetPath(path.Path()); 111 119 UpdateRow(row); 112 120 } else { 113 121 printf("name %s\n", ref.name); 114 122 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(); 116 125 return; 117 126 } 118 127 BMessage msg(M_EVENT_CHANGED); … … 126 135 void 127 136 HEventList::SetPath(const char* path) 128 137 { 129 HEventRow* row = (HEventRow *)CurrentSelection();138 HEventRow* row = (HEventRow* )CurrentSelection(); 130 139 if (row != NULL) { 131 140 entry_ref ref; 132 141 BEntry entry(path); -
Jamfile
1 1 SubDir HAIKU_TOP src preferences sounds ; 2 2 3 SetSubDirSupportedPlatformsBeOSCompatible ;4 5 3 UsePrivateHeaders interface ; 6 4 7 5 Preference Sounds : … … 9 7 # HEventItem.cpp 10 8 HWindow.cpp 11 9 HEventList.cpp 12 : be libcolumnlistview.a game tracker libmedia.so $(TARGET_LIBSUPC++) 10 : be libcolumnlistview.a game tracker libmedia.so $(TARGET_LIBSUPC++) liblocale.so 13 11 : Sounds.rdef 14 12 ; 13 14 DoCatalogs Sounds : 15 x-vnd.Haiku-Sounds 16 : 17 HApp.cpp 18 HWindow.cpp 19 HEventList.cpp 20 : en.catalog 21 ; -
HApp.cpp
13 13 #include "HWindow.h" 14 14 15 15 #include <Alert.h> 16 #include <Catalog.h> 17 #include <Locale.h> 16 18 19 #undef TR_CONTEXT 20 #define TR_CONTEXT "SoundsHApp" 17 21 18 22 HApp::HApp() 19 23 : BApplication("application/x-vnd.Haiku-Sounds") 20 24 { 25 be_locale->GetAppCatalog(&fCatalog); 26 21 27 BRect rect; 22 28 rect.Set(200, 150, 500, 450); 23 29 24 HWindow *win = new HWindow(rect, "Sounds");30 HWindow* win = new HWindow(rect, TR("Sounds")); 25 31 win->Show(); 26 32 } 27 33 … … 34 40 void 35 41 HApp::AboutRequested() 36 42 { 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(); 43 51 } 44 52 45 53 -
HEventList.h
27 27 28 28 const char* Name() const { return fName.String();} 29 29 const char* Path() const { return fPath.String();} 30 void Remove(const char *type);30 void Remove(const char* type); 31 31 void SetPath(const char* path); 32 32 protected: 33 33 … … 44 44 45 45 class HEventList : public BColumnListView { 46 46 public: 47 HEventList(BRect rect, 48 const char* name = "EventList"); 47 HEventList( const char* name = "EventList"); 49 48 virtual ~HEventList(); 50 49 void RemoveAll(); 51 50 void SetType(const char* type); -
HApp.h
12 12 13 13 14 14 #include <Application.h> 15 #include <Catalog.h> 15 16 16 17 17 18 class HApp :public BApplication { … … 21 22 22 23 protected: 23 24 virtual void AboutRequested(); 25 BCatalog fCatalog; 24 26 }; 25 27 26 28 #endif // HAPP_H