diff --git a/src/preferences/sounds/HApp.cpp b/src/preferences/sounds/HApp.cpp index a68f629e06..3a5a0fdbd3 100644 --- a/src/preferences/sounds/HApp.cpp +++ b/src/preferences/sounds/HApp.cpp @@ -16,13 +16,14 @@ HApp::HApp() - : BApplication("application/x-vnd.Haiku-Sounds") + : + BApplication("application/x-vnd.Haiku-Sounds") { BRect rect; rect.Set(200, 150, 590, 570); - HWindow *win = new HWindow(rect, "Sounds"); - win->Show(); + HWindow* window = new HWindow(rect, "Sounds"); + window->Show(); } @@ -34,12 +35,14 @@ HApp::~HApp() void HApp::AboutRequested() { - (new BAlert("About Sounds", "Sounds\n" - " Brought to you by :\n" - " Oliver Ruiz Dorantes\n" - " Jérôme DUVAL.\n" - " Original work from Atsushi Takamatsu.\n" - "Copyright " B_UTF8_COPYRIGHT "2003-2006 Haiku", "OK"))->Go(); + BAlert* alert = new BAlert("About Sounds", + "Sounds\n" + " Brought to you by :\n" + " Oliver Ruiz Dorantes\n" + " Jérôme DUVAL.\n" + " Original work from Atsushi Takamatsu.\n" + "Copyright " B_UTF8_COPYRIGHT "2003-2006 Haiku", "OK"); + alert->Go(); } diff --git a/src/preferences/sounds/HApp.h b/src/preferences/sounds/HApp.h index 83ebc24e2d..aa5f406f9b 100644 --- a/src/preferences/sounds/HApp.h +++ b/src/preferences/sounds/HApp.h @@ -14,13 +14,12 @@ #include -class HApp :public BApplication { - public: - HApp(); - virtual ~HApp(); - - protected: - virtual void AboutRequested(); +class HApp : public BApplication { +public: + HApp(); + virtual ~HApp(); + virtual void AboutRequested(); }; + #endif // HAPP_H diff --git a/src/preferences/sounds/HEventList.cpp b/src/preferences/sounds/HEventList.cpp index 82c192e22d..32be272d81 100644 --- a/src/preferences/sounds/HEventList.cpp +++ b/src/preferences/sounds/HEventList.cpp @@ -18,7 +18,8 @@ HEventRow::HEventRow(const char* name, const char* path) - : BRow(), + : + BRow(), fName(name) { SetField(new BStringField(name), kEventColumn); @@ -41,18 +42,21 @@ HEventRow::SetPath(const char* _path) void -HEventRow::Remove(const char *type) +HEventRow::Remove(const char* type) { BMediaFiles().RemoveItem(type, Name()); } HEventList::HEventList(BRect rect, const char* name) - : BColumnListView(rect, name, B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true), - fType(NULL) + : + BColumnListView(rect, name, B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true), + fType(NULL) { - AddColumn(new BStringColumn("Event", 150, 50, 500, B_TRUNCATE_MIDDLE), kEventColumn); - AddColumn(new BStringColumn("Sound", 150, 50, 500, B_TRUNCATE_END), kSoundColumn); + AddColumn(new BStringColumn("Event", 150, 50, 500, B_TRUNCATE_MIDDLE), + kEventColumn); + AddColumn(new BStringColumn("Sound", 150, 50, 500, B_TRUNCATE_END), + kSoundColumn); } @@ -76,7 +80,8 @@ HEventList::SetType(const char* type) entry_ref ref; while (mfiles.GetNextRef(&name,&ref) == B_OK) { BPath path(&ref); - if ((path.InitCheck() != B_OK) || (ref.name == NULL) || (strcmp(ref.name, "") == 0)) + if (path.InitCheck() != B_OK || ref.name == NULL + || strcmp(ref.name, "") == 0) AddRow(new HEventRow(name.String(), NULL)); else AddRow(new HEventRow(name.String(), path.Path())); @@ -87,8 +92,8 @@ HEventList::SetType(const char* type) void HEventList::RemoveAll() { - BRow *row; - while ((row = RowAt((int32)0, NULL))!=NULL) { + BRow* row; + while ((row = RowAt((int32)0, NULL)) != NULL) { RemoveRow(row); delete row; } @@ -100,19 +105,22 @@ HEventList::SelectionChanged() { BColumnListView::SelectionChanged(); - HEventRow* row = (HEventRow *)CurrentSelection(); + HEventRow* row = (HEventRow*)CurrentSelection(); if (row != NULL) { entry_ref ref; BMediaFiles().GetRefFor(fType, row->Name(), &ref); BPath path(&ref); - if ((path.InitCheck()==B_OK) || (ref.name == NULL) || (strcmp(ref.name, "") == 0)) { + if (path.InitCheck() == B_OK || ref.name == NULL + || strcmp(ref.name, "") == 0) { row->SetPath(path.Path()); UpdateRow(row); } else { printf("name %s\n", ref.name); BMediaFiles().RemoveRefFor(fType, row->Name(), ref); - (new BAlert("alert", "No such file or directory", "OK"))->Go(); + BAlert* alert = new BAlert("alert", + "No such file or directory", "OK"); + alert->Go(); return; } BMessage msg(M_EVENT_CHANGED); @@ -126,7 +134,7 @@ HEventList::SelectionChanged() void HEventList::SetPath(const char* path) { - HEventRow* row = (HEventRow *)CurrentSelection(); + HEventRow* row = (HEventRow*)CurrentSelection(); if (row != NULL) { entry_ref ref; BEntry entry(path); diff --git a/src/preferences/sounds/HEventList.h b/src/preferences/sounds/HEventList.h index 9a447ec5a8..1590b0cde9 100644 --- a/src/preferences/sounds/HEventList.h +++ b/src/preferences/sounds/HEventList.h @@ -10,9 +10,11 @@ #ifndef __HEVENTLIST_H__ #define __HEVENTLIST_H__ + #include #include + enum { kEventColumn, kSoundColumn, @@ -21,19 +23,18 @@ enum { class HEventRow : public BRow { public: - HEventRow(const char* event_name, - const char* path); - virtual ~HEventRow(); + HEventRow(const char* event_name, + const char* path); + virtual ~HEventRow(); - const char* Name() const { return fName.String();} - const char* Path() const { return fPath.String();} - void Remove(const char *type); - void SetPath(const char* path); -protected: + const char* Name() const { return fName.String(); } + const char* Path() const { return fPath.String(); } + void Remove(const char* type); + void SetPath(const char* path); private: - BString fName; - BString fPath; + BString fName; + BString fPath; }; @@ -44,15 +45,19 @@ enum { class HEventList : public BColumnListView { public: - HEventList(BRect rect, - const char* name = "EventList"); - virtual ~HEventList(); - void RemoveAll(); - void SetType(const char* type); - void SetPath(const char* path); + HEventList(BRect rect, + const char* name = "EventList"); + virtual ~HEventList(); + void RemoveAll(); + void SetType(const char* type); + void SetPath(const char* path); + protected: - virtual void SelectionChanged(); + virtual void SelectionChanged(); + private: - char *fType; + char* fType; }; -#endif + + +#endif // __HEVENTLIST_H__ diff --git a/src/preferences/sounds/HWindow.cpp b/src/preferences/sounds/HWindow.cpp index c7172d3233..d6295517e2 100644 --- a/src/preferences/sounds/HWindow.cpp +++ b/src/preferences/sounds/HWindow.cpp @@ -38,8 +38,9 @@ static const char kSettingsFile[] = "Sounds_Settings"; -HWindow::HWindow(BRect rect, const char *name) - : _inherited(rect, name, B_TITLED_WINDOW, 0), +HWindow::HWindow(BRect rect, const char* name) + : + BWindow(rect, name, B_TITLED_WINDOW, 0), fFilePanel(NULL), fPlayer(NULL) { @@ -78,7 +79,7 @@ HWindow::~HWindow() BMessage msg; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(kSettingsFile); - BFile file(path.Path(), B_WRITE_ONLY|B_CREATE_FILE); + BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); if (file.InitCheck() == B_OK) { msg.AddRect("frame", fFrame); @@ -93,7 +94,8 @@ HWindow::InitGUI() { BRect rect = Bounds(); rect.bottom -= 106; - BView *listView = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED); + BView* listView = new BView(rect, "", B_FOLLOW_NONE, + B_WILL_DRAW | B_PULSE_NEEDED); listView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(listView); @@ -108,34 +110,37 @@ HWindow::InitGUI() rect = Bounds(); rect.top = rect.bottom - 105; - BView *view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED); + BView* view = new BView(rect, "", B_FOLLOW_NONE, + B_WILL_DRAW | B_PULSE_NEEDED); view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(view); rect = view->Bounds().InsetBySelf(12, 12); - BBox *box = new BBox(rect, "", B_FOLLOW_ALL); + BBox* box = new BBox(rect, "", B_FOLLOW_ALL); view->AddChild(box); rect = box->Bounds(); rect.top += 10; rect.left += 15; rect.right -= 10; rect.bottom = rect.top + 20; - BMenu *menu = new BMenu("file"); + BMenu* menu = new BMenu("file"); menu->SetRadioMode(true); menu->SetLabelFromMarked(true); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("", new BMessage(M_NONE_MESSAGE))); - menu->AddItem(new BMenuItem("Other" B_UTF8_ELLIPSIS, new BMessage(M_OTHER_MESSAGE))); - BMenuField *menuField = new BMenuField(rect, "filemenu", "Sound file:", menu, - B_FOLLOW_TOP | B_FOLLOW_LEFT); + menu->AddItem(new BMenuItem("Other" B_UTF8_ELLIPSIS, + new BMessage(M_OTHER_MESSAGE))); + BMenuField* menuField = new BMenuField(rect, "filemenu", "Sound file:", + menu, B_FOLLOW_TOP | B_FOLLOW_LEFT); menuField->SetDivider(menuField->StringWidth("Sound file:") + 10); box->AddChild(menuField); rect.OffsetBy(-2, menuField->Bounds().Height() + 15); - BButton *button = new BButton(rect, "stop", "Stop", new BMessage(M_STOP_MESSAGE), - B_FOLLOW_RIGHT | B_FOLLOW_TOP); + BButton* button = new BButton(rect, "stop", "Stop", + new BMessage(M_STOP_MESSAGE), B_FOLLOW_RIGHT | B_FOLLOW_TOP); button->ResizeToPreferred(); button->SetEnabled(false); - button->MoveTo(box->Bounds().right - button->Bounds().Width() - 15, rect.top); + button->MoveTo(box->Bounds().right - button->Bounds().Width() - 15, + rect.top); box->AddChild(button); rect = button->Frame(); @@ -151,7 +156,8 @@ HWindow::InitGUI() box->AddChild(button); view->MoveTo(0, listView->Frame().bottom); - ResizeTo(Bounds().Width(), listView->Frame().bottom + view->Bounds().Height()); + ResizeTo(Bounds().Width(), + listView->Frame().bottom + view->Bounds().Height()); listView->SetResizingMode(B_FOLLOW_ALL); view->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM); @@ -162,24 +168,24 @@ HWindow::InitGUI() void -HWindow::MessageReceived(BMessage *message) +HWindow::MessageReceived(BMessage* message) { switch (message->what) { case M_OTHER_MESSAGE: { - BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField); - BMenu *menu = menufield->Menu(); + BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField); + BMenu* menu = menufield->Menu(); - HEventRow* row = (HEventRow *)fEventList->CurrentSelection(); + HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (row != NULL) { BPath path(row->Path()); if (path.InitCheck() != B_OK) { - BMenuItem *item = menu->FindItem(""); - if (item) + BMenuItem* item = menu->FindItem(""); + if (item != NULL) item->SetMarked(true); } else { - BMenuItem *item = menu->FindItem(path.Leaf()); - if (item) + BMenuItem* item = menu->FindItem(path.Leaf()); + if (item != NULL) item->SetMarked(true); } } @@ -191,10 +197,11 @@ HWindow::MessageReceived(BMessage *message) case B_REFS_RECEIVED: { entry_ref ref; - HEventRow* row = (HEventRow *)fEventList->CurrentSelection(); + HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (message->FindRef("refs", &ref) == B_OK && row != NULL) { - BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField); - BMenu *menu = menufield->Menu(); + BMenuField* menufield = cast_as(FindView("filemenu"), + BMenuField); + BMenu* menu = menufield->Menu(); // check audio file BNode node(&ref); @@ -204,24 +211,26 @@ HWindow::MessageReceived(BMessage *message) BMimeType mtype(type); BMimeType superType; mtype.GetSupertype(&superType); - if (superType.Type() == NULL || strcmp(superType.Type(), "audio") != 0) { + if (superType.Type() == NULL + || strcmp(superType.Type(), "audio") != 0) { beep(); - (new BAlert("", "This is not a audio file.", "OK", NULL, NULL, - B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); + BAlert* alert = new BAlert("", "This is not a audio file.", + "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); + alert->Go(); break; } // add file item - BMessage *msg = new BMessage(M_ITEM_MESSAGE); + BMessage* msg = new BMessage(M_ITEM_MESSAGE); BPath path(&ref); msg->AddRef("refs", &ref); - BMenuItem *menuitem = menu->FindItem(path.Leaf()); - if (!menuitem) + BMenuItem* menuitem = menu->FindItem(path.Leaf()); + if (menuitem == NULL) menu->AddItem(menuitem = new BMenuItem(path.Leaf(), msg), 0); // refresh item fEventList->SetPath(BPath(&ref).Path()); // check file menu - if (menuitem) + if (menuitem != NULL) menuitem->SetMarked(true); } break; @@ -229,10 +238,10 @@ HWindow::MessageReceived(BMessage *message) case M_PLAY_MESSAGE: { - HEventRow* row = (HEventRow *)fEventList->CurrentSelection(); + HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (row != NULL) { - const char *path = row->Path(); - if (path) { + const char* path = row->Path(); + if (path != NULL) { entry_ref ref; ::get_ref_for_path(path, &ref); delete fPlayer; @@ -245,7 +254,7 @@ HWindow::MessageReceived(BMessage *message) case M_STOP_MESSAGE: { - if (!fPlayer) + if (fPlayer == NULL) break; if (fPlayer->IsPlaying()) { fPlayer->StopPlaying(); @@ -257,19 +266,19 @@ HWindow::MessageReceived(BMessage *message) case M_EVENT_CHANGED: { - const char *path; - BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField); - BMenu *menu = menufield->Menu(); + const char* path; + BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField); + BMenu* menu = menufield->Menu(); if (message->FindString("path", &path) == B_OK) { BPath path(path); if (path.InitCheck() != B_OK) { - BMenuItem *item = menu->FindItem(""); - if (item) + BMenuItem* item = menu->FindItem(""); + if (item != NULL) item->SetMarked(true); } else { - BMenuItem *item = menu->FindItem(path.Leaf()); - if (item) + BMenuItem* item = menu->FindItem(path.Leaf()); + if (item != NULL) item->SetMarked(true); } } @@ -291,7 +300,7 @@ HWindow::MessageReceived(BMessage *message) } default: - _inherited::MessageReceived(message); + BWindow::MessageReceived(message); } } @@ -299,12 +308,12 @@ HWindow::MessageReceived(BMessage *message) void HWindow::SetupMenuField() { - BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField); - BMenu *menu = menufield->Menu(); + BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField); + BMenu* menu = menufield->Menu(); int32 count = fEventList->CountRows(); for (int32 i = 0; i < count; i++) { - HEventRow *row = (HEventRow *)fEventList->RowAt(i); - if (!row) + HEventRow* row = (HEventRow*)fEventList->RowAt(i); + if (row == NULL) continue; BPath path(row->Path()); @@ -313,7 +322,7 @@ HWindow::SetupMenuField() if (menu->FindItem(path.Leaf())) continue; - BMessage *msg = new BMessage(M_ITEM_MESSAGE); + BMessage* msg = new BMessage(M_ITEM_MESSAGE); entry_ref ref; ::get_ref_for_path(path.Path(), &ref); msg->AddRef("refs", &ref); @@ -329,7 +338,7 @@ HWindow::SetupMenuField() if (err == B_OK) err = dir.SetTo(path.Path()); while (err == B_OK) { - err = dir.GetNextEntry((BEntry*)&entry, true); + err = dir.GetNextEntry(&entry, true); if (entry.InitCheck() != B_NO_ERROR) break; @@ -338,7 +347,7 @@ HWindow::SetupMenuField() if (menu->FindItem(item_path.Leaf())) continue; - BMessage *msg = new BMessage(M_ITEM_MESSAGE); + BMessage* msg = new BMessage(M_ITEM_MESSAGE); entry_ref ref; ::get_ref_for_path(item_path.Path(), &ref); msg->AddRef("refs", &ref); @@ -349,7 +358,7 @@ HWindow::SetupMenuField() if (err == B_OK) err = dir.SetTo(path.Path()); while (err == B_OK) { - err = dir.GetNextEntry((BEntry*)&entry, true); + err = dir.GetNextEntry(&entry, true); if (entry.InitCheck() != B_NO_ERROR) break; @@ -358,7 +367,7 @@ HWindow::SetupMenuField() if (menu->FindItem(item_path.Leaf())) continue; - BMessage *msg = new BMessage(M_ITEM_MESSAGE); + BMessage* msg = new BMessage(M_ITEM_MESSAGE); entry_ref ref; ::get_ref_for_path(item_path.Path(), &ref); @@ -370,7 +379,7 @@ HWindow::SetupMenuField() if (err == B_OK) err = dir.SetTo(path.Path()); while (err == B_OK) { - err = dir.GetNextEntry((BEntry*)&entry, true); + err = dir.GetNextEntry(&entry, true); if (entry.InitCheck() != B_NO_ERROR) break; @@ -379,7 +388,7 @@ HWindow::SetupMenuField() if (menu->FindItem(item_path.Leaf())) continue; - BMessage *msg = new BMessage(M_ITEM_MESSAGE); + BMessage* msg = new BMessage(M_ITEM_MESSAGE); entry_ref ref; ::get_ref_for_path(item_path.Path(), &ref); @@ -393,19 +402,19 @@ HWindow::SetupMenuField() void HWindow::Pulse() { - HEventRow* row = (HEventRow *)fEventList->CurrentSelection(); - BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField); - BButton *button = cast_as(FindView("play"), BButton); - BButton *stop = cast_as(FindView("stop"), BButton); + HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); + BMenuField* menufield = cast_as(FindView("filemenu"), BMenuField); + BButton* button = cast_as(FindView("play"), BButton); + BButton* stop = cast_as(FindView("stop"), BButton); - if (!menufield) + if (menufield == NULL) return; if (row != NULL) { menufield->SetEnabled(true); - const char *path = row->Path(); - if (path && strcmp(path, "")) + const char* path = row->Path(); + if (path != NULL && strcmp(path, "")) button->SetEnabled(true); else button->SetEnabled(false); @@ -414,7 +423,7 @@ HWindow::Pulse() button->SetEnabled(false); } - if (fPlayer) { + if (fPlayer != NULL) { if (fPlayer->IsPlaying()) stop->SetEnabled(true); else @@ -425,7 +434,7 @@ HWindow::Pulse() void -HWindow::DispatchMessage(BMessage *message, BHandler *handler) +HWindow::DispatchMessage(BMessage* message, BHandler* handler) { if (message->what == B_PULSE) Pulse(); diff --git a/src/preferences/sounds/HWindow.h b/src/preferences/sounds/HWindow.h index 706f43b344..da27a993ff 100644 --- a/src/preferences/sounds/HWindow.h +++ b/src/preferences/sounds/HWindow.h @@ -35,22 +35,23 @@ enum{ class HWindow : public BWindow { public: - HWindow(BRect rect, const char* name); -protected: - virtual ~HWindow(); - virtual void MessageReceived(BMessage *message); - virtual bool QuitRequested(); - virtual void DispatchMessage(BMessage *message, - BHandler *handler); - void InitGUI(); - void SetupMenuField(); - void Pulse(); + HWindow(BRect rect, const char* name); + virtual ~HWindow(); + + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); + virtual void DispatchMessage(BMessage* message, + BHandler* handler); + void InitGUI(); + void SetupMenuField(); + void Pulse(); + private: - typedef BWindow _inherited; - HEventList* fEventList; - BFilePanel* fFilePanel; - BFileGameSound* fPlayer; - BRect fFrame; + HEventList* fEventList; + BFilePanel* fFilePanel; + BFileGameSound* fPlayer; + BRect fFrame; }; + #endif // __HWINDOW_H__