From e482b42659967bf8298a8ffddd404ab627623b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 25 Nov 2003 10:20:59 +0000 Subject: [PATCH] Basic Sounds pref app. i forgot to include the Jamfile and the resource file. Sorry but the app has only the features from R5. Extra features may come later. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5479 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/sounds/Colors.h | 53 ----- src/prefs/sounds/HApp.cpp | 45 +++-- src/prefs/sounds/HApp.h | 15 ++ src/prefs/sounds/HEventItem.cpp | 95 +++++---- src/prefs/sounds/HEventItem.h | 27 ++- src/prefs/sounds/HEventList.cpp | 222 ++++++-------------- src/prefs/sounds/HEventList.h | 33 +-- src/prefs/sounds/HTypeList.h | 22 -- src/prefs/sounds/HWindow.cpp | 348 ++++++++++---------------------- src/prefs/sounds/HWindow.h | 17 +- src/prefs/sounds/Icon.rsrc | Bin 3182 -> 0 bytes src/prefs/sounds/Resource.rsrc | Bin 4212 -> 0 bytes src/prefs/sounds/main.cpp | 8 - 13 files changed, 323 insertions(+), 562 deletions(-) delete mode 100644 src/prefs/sounds/Colors.h delete mode 100644 src/prefs/sounds/HTypeList.h delete mode 100644 src/prefs/sounds/Icon.rsrc delete mode 100644 src/prefs/sounds/Resource.rsrc delete mode 100644 src/prefs/sounds/main.cpp diff --git a/src/prefs/sounds/Colors.h b/src/prefs/sounds/Colors.h deleted file mode 100644 index 42a582fa72..0000000000 --- a/src/prefs/sounds/Colors.h +++ /dev/null @@ -1,53 +0,0 @@ -//Useful until be gets around to making these sorts of things -//globals akin to be_plain_font, etc. - - -#ifndef _SGB_COLORS_H_ -#define _SGB_COLORS_H_ - - -//****************************************************************************************************** -//**** SYSTEM HEADER FILES -//****************************************************************************************************** -#include - - -//****************************************************************************************************** -//**** CONSTANT DEFINITIONS -//****************************************************************************************************** -//Be standard UI colors -const rgb_color BeBackgroundGrey = {216,216,216, 255}; -const rgb_color BeInactiveControlGrey = {240,240,240, 255}; -const rgb_color BeFocusBlue = {0, 0, 229, 255}; -const rgb_color BeHighlight = {255,255,255, 255}; -const rgb_color BeShadow = {152,152,152, 255}; -const rgb_color BeDarkShadow = {108,108,108, 255}; -const rgb_color BeLightShadow = {194,194,194, 255}; -const rgb_color BeButtonGrey = {232,232,232, 255}; -const rgb_color BeInactiveGrey = {127,127,127, 255}; -const rgb_color BeListSelectGrey = {178,178,178, 255}; -const rgb_color BeTitleBarYellow = {255,203,0, 255}; - -//Other colors -const rgb_color Black = {0, 0, 0, 255}; -const rgb_color White = {255,255,255, 255}; -const rgb_color Red = {255,0, 0, 255}; -const rgb_color Green = {0, 167,0, 255}; -const rgb_color LightGreen = {90, 240,90, 255}; -const rgb_color Blue = {49, 61, 225, 255}; -const rgb_color LightBlue = {64, 162,255, 255}; -const rgb_color Purple = {144,64, 221, 255}; -const rgb_color LightPurple = {166,74, 255, 255}; -const rgb_color Lavender = {193,122,255, 255}; -const rgb_color Yellow = {255,203,0, 255}; -const rgb_color Orange = {255,163,0, 255}; -const rgb_color Flesh = {255,231,186, 255}; -const rgb_color Tan = {208,182,121, 255}; -const rgb_color Brown = {154,110,45, 255}; -const rgb_color Grey = {200,200,200, 255}; -const rgb_color LightMetallicBlue = {143,166,240, 255}; -const rgb_color MedMetallicBlue = {75, 96, 154, 255}; -const rgb_color DarkMetallicBlue = {78, 89, 126, 255}; - - -#endif diff --git a/src/prefs/sounds/HApp.cpp b/src/prefs/sounds/HApp.cpp index 3c5e351f51..0c483fd902 100644 --- a/src/prefs/sounds/HApp.cpp +++ b/src/prefs/sounds/HApp.cpp @@ -1,7 +1,21 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HApp.cpp +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include #include "HApp.h" #include "HWindow.h" -#include "HAboutWindow.h" -#include "RectUtils.h" #define APP_SIG "application/x-vnd.openSounds" @@ -11,13 +25,9 @@ HApp::HApp() :BApplication(APP_SIG) { BRect rect; - RectUtils utils; - if(utils.LoadRectFromApp("window_rect",&rect) == false) - { - rect.Set(50,50,450,400); - } + rect.Set(200,150,500,450); - HWindow *win = new HWindow(rect,"OpenSounds"); + HWindow *win = new HWindow(rect,"Sounds"); win->Show(); } @@ -35,9 +45,18 @@ HApp::~HApp() void HApp::AboutRequested() { - (new HAboutWindow("openSounds", - __DATE__, -"Created by Atsushi Takamatsu @ Sapporo,Japan.\nOpenBeOS Development by Oliver Ruiz Dorantes @ Tarragona,Spain", -"http://anas.worldonline.es/urnenfel/beos/openbeos", -"E-Mail: urnenfelder@worldonline.es"))->Show(); + (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" + "OpenBeOS, 2003","OK"))->Go(); } + +int main() +{ + HApp app; + app.Run(); + return 0; +} + diff --git a/src/prefs/sounds/HApp.h b/src/prefs/sounds/HApp.h index e0e3215395..0b80edde25 100644 --- a/src/prefs/sounds/HApp.h +++ b/src/prefs/sounds/HApp.h @@ -1,3 +1,18 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HApp.h +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #ifndef __HAPP_H__ #define __HAPP_H__ diff --git a/src/prefs/sounds/HEventItem.cpp b/src/prefs/sounds/HEventItem.cpp index c94303192d..6361ad48e5 100644 --- a/src/prefs/sounds/HEventItem.cpp +++ b/src/prefs/sounds/HEventItem.cpp @@ -1,6 +1,19 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HEventItem.cpp +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #include "HEventItem.h" -#include "ResourceUtils.h" -#include #include #include #include @@ -11,16 +24,10 @@ /*********************************************************** * Constructor ***********************************************************/ -HEventItem::HEventItem(const char* name,const char* path) - :CLVEasyItem(0,false,false,20) - ,fName(name) +HEventItem::HEventItem(const char* name, const char* path) + : BListItem(), + fName(name) { - //BBitmap* bitmap = new BBitmap(BRect(0,0,15,15),B_COLOR_8_BIT); - BBitmap *bitmap = ResourceUtils().GetBitmapResource('BBMP',"Sound Bitmap"); - SetColumnContent(0,bitmap,false); - SetColumnContent(1,fName.String(),false,false); - SetColumnContent(2,"",false,false); - delete bitmap; SetPath(path); } @@ -38,45 +45,53 @@ void HEventItem::SetPath(const char* in_path) { fPath = in_path; - BPath path(in_path); - BPath parent; - BMediaFiles mfiles; - entry_ref ref; - - if(path.InitCheck() == B_OK) - { - SetColumnContent(2,path.Leaf(),false,false); - ::get_ref_for_path(path.Path(),&ref); - if(mfiles.SetRefFor(BMediaFiles::B_SOUNDS,Name(),ref) != B_OK) - (new BAlert("","Error","OK"))->Go(); - path.GetParent(&parent); - SetColumnContent(3,parent.Path(),false,false);// falta - }else{ - SetColumnContent(2,"",false,false); - //if(mfiles.RemoveRefFor(BMediaFiles::B_SOUNDS,Name(),ref) != B_OK) - // (new BAlert("","Entry not found","OK"))->Go(); - mfiles.RemoveItem(BMediaFiles::B_SOUNDS,Name()); - ::add_system_beep_event(Name()); - SetColumnContent(3,"",false,false);// falta - } } + /*********************************************************** * Remove ***********************************************************/ void -HEventItem::Remove() +HEventItem::Remove(const char *type) { - BMediaFiles mfiles; - - mfiles.RemoveItem(BMediaFiles::B_SOUNDS,Name()); + BMediaFiles().RemoveItem(type, Name()); } + /*********************************************************** - * + * DrawItem ***********************************************************/ -const char* -HEventItem::Path() const +void +HEventItem::DrawItem(BView *owner, BRect itemRect, bool complete) { - return fPath.String(); + rgb_color kBlack = { 0,0,0,0 }; + rgb_color kHighlight = { 206,207,206,0 }; + + if (IsSelected() || complete) { + rgb_color color; + if (IsSelected()) + color = kHighlight; + else + color = owner->ViewColor(); + + owner->SetHighColor(color); + owner->SetLowColor(color); + owner->FillRect(itemRect); + owner->SetHighColor(kBlack); + + } else { + owner->SetLowColor(owner->ViewColor()); + } + + BPoint point = itemRect.LeftTop() + BPoint(5, 10); + + owner->SetHighColor(kBlack); + owner->SetFont(be_plain_font); + owner->MovePenTo(point); + owner->DrawString(Name()); + + point += BPoint(100, 0); + BPath path(Path()); + owner->MovePenTo(point); + owner->DrawString(path.Leaf() ? path.Leaf() : ""); } diff --git a/src/prefs/sounds/HEventItem.h b/src/prefs/sounds/HEventItem.h index c64de1b1e7..4f6b03895c 100644 --- a/src/prefs/sounds/HEventItem.h +++ b/src/prefs/sounds/HEventItem.h @@ -1,20 +1,37 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HEventItem.h, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Author: Jérôme Duval +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #ifndef __HEVENTITEM_H__ #define __HEVENTITEM_H__ -#include "CLVEasyItem.h" +#include #include #include -class HEventItem :public CLVEasyItem { +class HEventItem : public BListItem { public: HEventItem(const char* event_name ,const char* path); virtual ~HEventItem(); + virtual void DrawItem(BView *owner, BRect itemRect, + bool drawEverything = false); - const char* Name()const {return fName.String();} - const char* Path()const; - void Remove(); + 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: diff --git a/src/prefs/sounds/HEventList.cpp b/src/prefs/sounds/HEventList.cpp index d7e142fdec..675aa39171 100644 --- a/src/prefs/sounds/HEventList.cpp +++ b/src/prefs/sounds/HEventList.cpp @@ -1,9 +1,23 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HEventList.cpp +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #include "HEventList.h" #include "HEventItem.h" #include "HWindow.h" -#include "IconMenuItem.h" - +#include #include #include #include @@ -19,26 +33,12 @@ /*********************************************************** * Constructor ***********************************************************/ -HEventList::HEventList(BRect rect - ,CLVContainerView** ContainerView - ,const char* name) - :ColumnListView(rect - ,ContainerView - ,name - ,B_FOLLOW_ALL - ,B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE - ,B_SINGLE_SELECTION_LIST - ,false - ,false - ,true) +HEventList::HEventList(BRect rect, const char* name) + : BListView(rect, name, B_SINGLE_SELECTION_LIST, + B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE), + fType(NULL) { - AddColumn(new CLVColumn(NULL,20,CLV_LOCK_AT_BEGINNING|CLV_NOT_MOVABLE| - CLV_NOT_RESIZABLE|CLV_PUSH_PASS|CLV_MERGE_WITH_RIGHT)); - AddColumn(new CLVColumn("Event",100,CLV_SORT_KEYABLE)); - AddColumn( new CLVColumn("Sound",130,CLV_SORT_KEYABLE)); - AddColumn( new CLVColumn("Path",200,CLV_SORT_KEYABLE)); - SetSortKey(1); - SetSortFunction(CLVEasyItem::CompareItems); + } /*********************************************************** @@ -46,6 +46,8 @@ HEventList::HEventList(BRect rect ***********************************************************/ HEventList::~HEventList() { + RemoveAll(); + delete fType; } /*********************************************************** @@ -57,14 +59,15 @@ HEventList::SetType(const char* type) RemoveAll(); BMediaFiles mfiles; mfiles.RewindRefs(type); + delete fType; + fType = strdup(type); BString name; entry_ref ref; - while(mfiles.GetNextRef(&name,&ref) == B_OK) - { - AddItem(new HEventItem(name.String(),BPath(&ref).Path())); + while(mfiles.GetNextRef(&name,&ref) == B_OK) { + BPath path(&ref); + AddItem(new HEventItem(name.String(), path.Path())); } - SortItems(); } /*********************************************************** @@ -73,32 +76,12 @@ HEventList::SetType(const char* type) void HEventList::RemoveAll() { - int32 count = CountItems(); - while(count> 0) - delete fPointerList.RemoveItem(--count); + BListItem *item; + while((item = RemoveItem((int32)0))!=NULL) + delete item; MakeEmpty(); } -/*********************************************************** - * Add event item - ***********************************************************/ -void -HEventList::AddEvent(HEventItem *item) -{ - fPointerList.AddItem(item); - AddItem(item); -} - -/*********************************************************** - * Remove event item - ***********************************************************/ -void -HEventList::RemoveEvent(HEventItem *item) -{ - item->Remove(); - fPointerList.RemoveItem(item); - RemoveItem(item); -} /*********************************************************** * Selection Changed @@ -106,12 +89,28 @@ HEventList::RemoveEvent(HEventItem *item) void HEventList::SelectionChanged() { + BListView::SelectionChanged(); + int32 sel = CurrentSelection(); if(sel >= 0) { HEventItem *item = cast_as(ItemAt(sel),HEventItem); if(!item) return; + + entry_ref ref; + BMediaFiles().GetRefFor(fType, item->Name(), &ref); + + BPath path(&ref); + if((path.InitCheck()==B_OK) || (ref.name == NULL) || (strcmp(ref.name, "")==0)) { + item->SetPath(path.Path()); + InvalidateItem(sel); + } else { + printf("name %s\n", ref.name); + BMediaFiles().RemoveRefFor(fType, item->Name(), ref); + (new BAlert("alert", "No such file or directory", "Ok"))->Go(); + return; + } BMessage msg(M_EVENT_CHANGED); msg.AddString("name",item->Name()); @@ -121,122 +120,23 @@ HEventList::SelectionChanged() } /*********************************************************** - * MouseDown + * SetPath ***********************************************************/ void -HEventList::MouseDown(BPoint pos) +HEventList::SetPath(const char* path) { - BPoint point = pos; - int32 buttons; - - Window()->CurrentMessage()->FindInt32("buttons", &buttons); - this->MakeFocus(true); - - // 右クリックのハンドリング - if(buttons == B_SECONDARY_MOUSE_BUTTON) - { - int32 sel = IndexOf(pos); - if(sel >= 0) - Select(sel); - else - DeselectAll(); - sel = CurrentSelection(); - bool enabled = (sel >= 0)?true:false; - - BPopUpMenu *theMenu = new BPopUpMenu("RIGHT_CLICK",false,false); - BFont font(be_plain_font); - font.SetSize(10); - theMenu->SetFont(&font); - /* HWindow *parent = cast_as(Window(),HWindow); - - BMenuField *menufield = cast_as(parent->FindView("filemenu"),BMenuField); - BMenu *old_menu = menufield->Menu(); - - int32 menus = old_menu->CountItems(); - - for(register int32 i = 0;i < menus-3;i++) - { - BMenuItem *old_item = old_menu->ItemAt(i); - if(!old_item) - continue; - BMessage *old_msg = old_item->Message(); - BMessage *msg = new BMessage(*old_msg ); - BMenuItem *new_item = new BMenuItem(old_item->Label(),msg); - new_item->SetEnabled(enabled); - theMenu->AddItem(new_item); - } - theMenu->AddSeparatorItem(); - theMenu->AddItem(new BMenuItem("",new BMessage(M_NONE_MESSAGE))); - theMenu->AddItem(new BMenuItem("Other…",new BMessage(M_OTHER_MESSAGE))); - theMenu->FindItem(M_NONE_MESSAGE)->SetEnabled(enabled); - theMenu->FindItem(M_OTHER_MESSAGE)->SetEnabled(enabled); - */ - BMenu *submenu = new BMenu("Open With…"); - submenu->SetFont(&font); - BMimeType mime("audio"); + int32 sel = CurrentSelection(); + if(sel >= 0) { + HEventItem *item = cast_as(ItemAt(sel),HEventItem); + if(!item) + return; - if(enabled) - { - HEventItem *item = cast_as(this->ItemAt(sel),HEventItem); - const char* path = item->Path(); - BFile file(path,B_READ_ONLY); - BNodeInfo ninfo(&file); - char type[B_MIME_TYPE_LENGTH+1]; - ninfo.GetType(type); - mime.SetTo(type); - } - BMessage message; - mime.GetSupportingApps(&message); - /* int32 sub; - int32 supers; - message.FindInt32("be:subs", &sub); - message.FindInt32("be:supers", &supers); - */ - for (int32 index =0; ; index++) - { - const char *signature; - int32 length; + entry_ref ref; + BEntry entry(path); + entry.GetRef(&ref); + BMediaFiles().SetRefFor(fType, item->Name(), ref); - if (message.FindData("applications", 'CSTR', index, (const void **)&signature, - &length) != B_OK) - break; - - entry_ref ref; - if(be_roster->FindApp(signature,&ref) != B_OK) - continue; - BMessage *msg = new BMessage(M_OPEN_WITH); - msg->AddRef("refs",&ref); - msg->AddString("sig",signature); - - BBitmap *icon = new BBitmap(BRect(0,0,15,15),B_COLOR_8_BIT); - BNodeInfo::GetTrackerIcon(&ref,icon,B_MINI_ICON); - - submenu->AddItem(new IconMenuItem(BPath(&ref).Leaf(),msg,0,0,icon)); - // push each of the supporting apps signature uniquely - //queryIterator->PushUniqueSignature(signature); - } - - theMenu->AddItem(submenu); - theMenu->AddSeparatorItem(); - theMenu->AddItem(new BMenuItem("Remove Event",new BMessage(M_REMOVE_EVENT))); - //theMenu->FindItem(M_OPEN_WITH)->SetEnabled(enabled); - theMenu->FindItem(M_REMOVE_EVENT)->SetEnabled(enabled); - submenu->SetEnabled(enabled); - BRect r; - ConvertToScreen(&pos); - r.top = pos.y - 5; - r.bottom = pos.y + 5; - r.left = pos.x - 5; - r.right = pos.x + 5; - - BMenuItem *theItem = theMenu->Go(pos, false,true,r); - if(theItem) - { - BMessage* aMessage = theItem->Message(); - if(aMessage) - this->Window()->PostMessage(aMessage); - } - delete theMenu; - }else - ColumnListView::MouseDown(point); + item->SetPath(path); + InvalidateItem(sel); + } } diff --git a/src/prefs/sounds/HEventList.h b/src/prefs/sounds/HEventList.h index 484f1e18b4..19463d835a 100644 --- a/src/prefs/sounds/HEventList.h +++ b/src/prefs/sounds/HEventList.h @@ -1,30 +1,39 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HEventList.h +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #ifndef __HEVENTLIST_H__ #define __HEVENTLIST_H__ -#include "ColumnListView.h" - -class HEventItem; +#include +#include "HEventItem.h" enum{ M_EVENT_CHANGED = 'SCAG' }; -class HEventList :public ColumnListView { +class HEventList : public BListView { public: HEventList(BRect rect - ,CLVContainerView** ContainerView - ,const char* name="EventList"); + , const char* name="EventList"); virtual ~HEventList(); void RemoveAll(); - void AddEvent(HEventItem *item); - void RemoveEvent(HEventItem *item); - void SetType(const char* type); + void SetPath(const char* path); protected: - virtual void MouseDown(BPoint point); virtual void SelectionChanged(); private: - BList fPointerList; - + char *fType; }; #endif diff --git a/src/prefs/sounds/HTypeList.h b/src/prefs/sounds/HTypeList.h deleted file mode 100644 index a086797cea..0000000000 --- a/src/prefs/sounds/HTypeList.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __HTYPELIST_H__ -#define __HTYPELIST_H__ - -#include - -enum{ - M_TYPE_CHANGED = 'TCHD' -}; - -class HTypeList :public BListView{ -public: - HTypeList(BRect rect,const char* name = "TypeList"); - virtual ~HTypeList(); -protected: - void AddType(const char* name); - void Init(); - void RemoveAll(); - virtual void SelectionChanged(); -private: - BList fPointerList; -}; -#endif \ No newline at end of file diff --git a/src/prefs/sounds/HWindow.cpp b/src/prefs/sounds/HWindow.cpp index abe286f157..90f0cb7795 100644 --- a/src/prefs/sounds/HWindow.cpp +++ b/src/prefs/sounds/HWindow.cpp @@ -1,11 +1,23 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HWindow.cpp +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #include "HWindow.h" #include "HEventList.h" #include "HEventItem.h" -#include "HTypeList.h" -#include "BetterScrollView.h" -#include "RectUtils.h" -#include "TextEntryAlert.h" - +#include +#include #include #include #include @@ -32,13 +44,17 @@ HWindow::HWindow(BRect rect ,const char* name) ,fFilePanel(NULL) ,fPlayer(NULL) { - InitMenu(); InitGUI(); float min_width,min_height,max_width,max_height; GetSizeLimits(&min_width,&max_width,&min_height,&max_height); - min_width = 320; - min_height = 150; + min_width = 300; + min_height = 200; SetSizeLimits(min_width,max_width,min_height,max_height); + + fFilePanel = new BFilePanel(); + fFilePanel->SetTarget(this); + + fEventList->Select(0); } /*********************************************************** @@ -57,64 +73,47 @@ void HWindow::InitGUI() { BRect rect = Bounds(); - rect.top = KeyMenuBar()->Bounds().Height()+1; - - /*fTypeList = new HTypeList(rect); - BScrollView *scrollView = new BScrollView("" - ,fTypeList - ,B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM + rect.bottom -= 106; + BView *view = new BView(rect,"",B_FOLLOW_ALL, B_WILL_DRAW|B_PULSE_NEEDED); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(view); + + BRect stringRect(16, 5, 60, 22); + BStringView *stringView = new BStringView(stringRect, "event", "Event"); + stringView->SetFont(be_bold_font); + view->AddChild(stringView); + + stringRect.OffsetBy(100, 0); + stringView = new BStringView(stringRect, "sound", "Sound"); + stringView->SetFont(be_bold_font); + view->AddChild(stringView); + + rect.left += 13; + rect.right -= B_V_SCROLL_BAR_WIDTH + 13; + rect.top += 28; + rect.bottom -= 7; + fEventList = new HEventList(rect); + fEventList->SetType(BMediaFiles::B_SOUNDS); + + BScrollView *scrollView = new BScrollView("" + ,fEventList + ,B_FOLLOW_ALL ,0 ,false ,true); - AddChild(scrollView); - */ - //rect.left = rect.right + B_V_SCROLL_BAR_WIDTH+3; - rect.right -= B_V_SCROLL_BAR_WIDTH; - rect.bottom = Bounds().bottom - B_H_SCROLL_BAR_HEIGHT - 80; - BetterScrollView *betterScrollView; - fEventList = new HEventList(rect,(CLVContainerView**)&betterScrollView); - fEventList->SetType(BMediaFiles::B_SOUNDS); - AddChild(betterScrollView); + view->AddChild(scrollView); - app_info info; - be_app->GetAppInfo(&info); - BEntry entry(&info.ref); - float width; - BFile appfile(&entry,B_WRITE_ONLY); - attr_info ainfo; - - if(appfile.GetAttrInfo("event_width",&ainfo) == B_OK) - { - appfile.ReadAttr("event_width",B_FLOAT_TYPE,0,&width,sizeof(float)); - CLVColumn *col = fEventList->ColumnAt(1); - if(col) - col->SetWidth(width); - } - - if(appfile.GetAttrInfo("sound_width",&ainfo) == B_OK) - { - appfile.ReadAttr("sound_width",B_FLOAT_TYPE,0,&width,sizeof(float)); - CLVColumn *col = fEventList->ColumnAt(2); - if(col) - col->SetWidth(width); - } - - rect.top = rect.bottom +1; - rect.bottom = Bounds().bottom; - rect.right = Bounds().right; - BView *view = new BView(rect,"",B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM,B_WILL_DRAW|B_PULSE_NEEDED); + rect = Bounds(); + rect.top = rect.bottom - 105; + view = new BView(rect,"",B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM,B_WILL_DRAW|B_PULSE_NEEDED); view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(view); - rect = view->Bounds(); - rect.top += 10; - rect.bottom -= 10; - rect.left += 10; - rect.right -= 10; + rect = view->Bounds().InsetBySelf(12, 12); BBox *box = new BBox(rect,"",B_FOLLOW_ALL); view->AddChild(box); rect = box->Bounds(); rect.top += 10; - rect.left += 10; + rect.left += 15; rect.right -= 10; rect.bottom = rect.top + 20; BMenu *menu = new BMenu("file"); @@ -129,68 +128,30 @@ HWindow::InitGUI() ,"Sound File:" ,menu ,B_FOLLOW_TOP|B_FOLLOW_LEFT); - menuField->SetDivider(menuField->StringWidth("Media Files:")+3); + menuField->SetDivider(menuField->StringWidth("Sound File:")+10); box->AddChild(menuField); - rect.OffsetBy(0,25); + rect.OffsetBy(-2,38); rect.left = rect.right - 80; BButton *button = new BButton(rect - ,"play" - ,"Play" - ,new BMessage(M_PLAY_MESSAGE) + ,"stop" + ,"Stop" + ,new BMessage(M_STOP_MESSAGE) ,B_FOLLOW_RIGHT|B_FOLLOW_TOP); box->AddChild(button); rect.OffsetBy(-90,0); button = new BButton(rect - ,"stop" - ,"Stop" - ,new BMessage(M_STOP_MESSAGE) + ,"play" + ,"Play" + ,new BMessage(M_PLAY_MESSAGE) ,B_FOLLOW_RIGHT|B_FOLLOW_TOP); box->AddChild(button); - - rect.OffsetBy(-110,0); - button = new BButton(rect - ,"setsystem" - ,"As System event" - ,NULL - ,B_FOLLOW_RIGHT|B_FOLLOW_TOP); - button->ResizeToPreferred(); - box->AddChild(button); // setup file menu SetupMenuField(); menu->FindItem("")->SetMarked(true); } -/*********************************************************** - * Initalize Menus - ***********************************************************/ -void -HWindow::InitMenu() -{ - BMenuBar *menuBar = new BMenuBar(Bounds(),"MENUBAR"); - BMenu *menu; - BMenuItem *item; - - menu = new BMenu("File"); - item = new BMenuItem("Add New Event…",new BMessage(M_ADD_EVENT),'A'); - item->SetTarget(this); - menu->AddItem(item); - - item = new BMenuItem("Remove Event",new BMessage(M_REMOVE_EVENT),'R'); - item->SetTarget(this); - menu->AddItem(item); - - menu->AddSeparatorItem(); - item = new BMenuItem("About openSounds…",new BMessage(B_ABOUT_REQUESTED),0,0); - item->SetTarget(be_app); - menu->AddItem(item); - menu->AddSeparatorItem(); - item = new BMenuItem("Quit",new BMessage(B_QUIT_REQUESTED),'Q',0); - menu->AddItem(item); - menuBar->AddItem(menu); - this->AddChild(menuBar); -} /*********************************************************** * MessageReceived @@ -198,64 +159,35 @@ HWindow::InitMenu() void HWindow::MessageReceived(BMessage *message) { - switch(message->what) - { - case M_OPEN_WITH: - { - entry_ref app_ref; - if(message->FindRef("refs",&app_ref) == B_OK) - { - BMessage msg(B_REFS_RECEIVED); - int32 sel = fEventList->CurrentSelection(); - if(sel < 0) - break; - HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); - const char* path = item->Path(); - entry_ref ref; - ::get_ref_for_path(path,&ref); - msg.AddRef("refs",&ref); - be_roster->Launch(&app_ref,&msg); - } - break; - } - case M_REMOVE_EVENT: - { - RemoveEvent(); - break; - } - case M_ADD_EVENT: - { - char new_Event[20]; - (new BAlert("Add an event","Note that to use this event, applications should call him by the function:\n status_t system_beep(const char *eventName);\n declared on be/support/Beep.h","OK",NULL,NULL, - B_WIDTH_AS_USUAL,B_WARNING_ALERT))->Go(); - if (((new TextEntryAlert("Add an event ...","Type name: ", "new event name", - "Create","Cancel",true,120,1,B_WIDTH_AS_USUAL,false, - NULL,B_FLOATING_WINDOW_LOOK) - )->Go(new_Event,20))==0){ - add_system_beep_event(new_Event); - - BMediaFiles mfiles; - mfiles.RewindRefs("Sound"); - entry_ref ref; - mfiles.GetRefFor("Sound",new_Event,&ref); - fEventList->AddEvent(new HEventItem(new_Event,BPath(&ref).Path())); - } - break; - } + switch(message->what) { case M_OTHER_MESSAGE: { - if(!fFilePanel) - fFilePanel = new BFilePanel(); - fFilePanel->SetTarget(this); + BMenuField *menufield = cast_as(FindView("filemenu"),BMenuField); + BMenu *menu = menufield->Menu(); + + int32 sel = fEventList->CurrentSelection(); + if(sel >= 0) { + HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); + BPath path(item->Path()); + if(path.InitCheck() != B_OK) { + BMenuItem *item = menu->FindItem(""); + if(item) + item->SetMarked(true); + } else{ + BMenuItem *item = menu->FindItem(path.Leaf()); + if(item) + item->SetMarked(true); + } + } fFilePanel->Show(); break; } + case B_SIMPLE_DATA: case B_REFS_RECEIVED: { entry_ref ref; int32 sel = fEventList->CurrentSelection(); - if(message->FindRef("refs",&ref) == B_OK && sel >= 0) - { + if(message->FindRef("refs",&ref) == B_OK && sel >= 0) { BMenuField *menufield = cast_as(FindView("filemenu"),BMenuField); BMenu *menu = menufield->Menu(); // check audio file @@ -266,8 +198,7 @@ HWindow::MessageReceived(BMessage *message) BMimeType mtype(type); BMimeType superType; mtype.GetSupertype(&superType); - if(strcmp(superType.Type(),"audio") != 0) - { + if(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(); @@ -277,14 +208,12 @@ HWindow::MessageReceived(BMessage *message) BMessage *msg = new BMessage(M_ITEM_MESSAGE); BPath path(&ref); msg->AddRef("refs",&ref); - if(!(menu->FindItem(path.Leaf()))) - menu->AddItem(new BMenuItem(path.Leaf(),msg),0); - // refresh item - HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); - item->SetPath(path.Path()); - fEventList->InvalidateItem(sel); - // check file menu BMenuItem *menuitem = menu->FindItem(path.Leaf()); + if(!menuitem) + menu->AddItem(menuitem = new BMenuItem(path.Leaf(),msg),0); + // refresh item + fEventList->SetPath(BPath(&ref).Path()); + // check file menu if(menuitem) menuitem->SetMarked(true); } @@ -296,21 +225,11 @@ HWindow::MessageReceived(BMessage *message) if(sel >= 0) { HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); - //system_beep(item->Name()); const char* path = item->Path(); if(path) { entry_ref ref; ::get_ref_for_path(path,&ref); - /*BSound *sound = new BSound(&ref); - if(sound->InitCheck() == B_OK) - { - fSoundPlayer.Start(); - fId = fSoundPlayer.StartPlaying(sound); - sound->ReleaseRef(); - }*/ - - //fSoundHandle = ::play_sound(&ref,false,false,true); delete fPlayer; fPlayer = new BFileGameSound(&ref,false); fPlayer->StartPlaying(); @@ -320,7 +239,6 @@ HWindow::MessageReceived(BMessage *message) } case M_STOP_MESSAGE: { - //::stop_sound(fSoundHandle); if(!fPlayer) break; if(fPlayer->IsPlaying()) @@ -337,15 +255,13 @@ HWindow::MessageReceived(BMessage *message) BMenuField *menufield = cast_as(FindView("filemenu"),BMenuField); BMenu *menu = menufield->Menu(); - if(message->FindString("path",&path) == B_OK) - { + if(message->FindString("path",&path) == B_OK) { BPath path(path); - if(path.InitCheck() != B_OK) - { + if(path.InitCheck() != B_OK) { BMenuItem *item = menu->FindItem(""); if(item) item->SetMarked(true); - }else{ + } else { BMenuItem *item = menu->FindItem(path.Leaf()); if(item) item->SetMarked(true); @@ -356,27 +272,14 @@ HWindow::MessageReceived(BMessage *message) case M_ITEM_MESSAGE: { entry_ref ref; - if(message->FindRef("refs",&ref) == B_OK) - { - int32 sel = fEventList->CurrentSelection(); - if(sel >= 0) - { - HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); - item->SetPath(BPath(&ref).Path()); - fEventList->InvalidateItem(sel); - } + if(message->FindRef("refs",&ref) == B_OK) { + fEventList->SetPath(BPath(&ref).Path()); } break; } case M_NONE_MESSAGE: { - int32 sel = fEventList->CurrentSelection(); - if(sel >= 0) - { - HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); - item->SetPath(NULL); - fEventList->InvalidateItem(sel); - } + fEventList->SetPath(NULL); break; } default: @@ -393,16 +296,15 @@ HWindow::SetupMenuField() BMenuField *menufield = cast_as(FindView("filemenu"),BMenuField); BMenu *menu = menufield->Menu(); int32 count = fEventList->CountItems(); - for(register int32 i = 0;i < count;i++) - { - HEventItem *item = cast_as(fEventList->ItemAt(i),HEventItem); + for(int32 i = 0; i < count; i++) { + HEventItem *item = cast_as(fEventList->ItemAt(i), HEventItem); if(!item) continue; BPath path(item->Path()); if(path.InitCheck() != B_OK) continue; - if( menu->FindItem(path.Leaf()) ) + if(menu->FindItem(path.Leaf())) continue; BMessage *msg = new BMessage(M_ITEM_MESSAGE); @@ -478,33 +380,6 @@ HWindow::SetupMenuField() } -/*********************************************************** - * Remove Event - ***********************************************************/ -void -HWindow::RemoveEvent() -{ - int32 sel = fEventList->CurrentSelection(); - if(sel < 0) - return; - // check system beep event - HEventItem *item = cast_as(fEventList->ItemAt(sel),HEventItem); - if(::strcmp(item->Name(),"Beep") == 0 - ||::strcmp(item->Name(),"Startup")==0 - ||::strcmp(item->Name(),"New E-mail") == 0) - { - beep(); - (new BAlert("","This is a system beep event.","OK"))->Go(); - return; - } - // - int32 index = (new BAlert("","Would you like to remove this event?","OK","Cancel"))->Go(); - if(index == 0) - { - if(item) - fEventList->RemoveEvent(item); - } -} /*********************************************************** * Pulse @@ -519,21 +394,19 @@ HWindow::Pulse() if(!menufield) return; - if(sel >=0) - { + if(sel >=0) { menufield->SetEnabled(true); button->SetEnabled(true); - }else{ + } else { menufield->SetEnabled(false); button->SetEnabled(false); } - if(fPlayer) - { + if(fPlayer) { if(fPlayer->IsPlaying()) stop->SetEnabled(true); else stop->SetEnabled(false); - }else + } else stop->SetEnabled(false); } @@ -555,24 +428,7 @@ HWindow::DispatchMessage(BMessage *message,BHandler *handler) bool HWindow::QuitRequested() { - RectUtils utils; - CLVColumn *col = fEventList->ColumnAt(1); - float width = col->Width(); - - app_info info; - be_app->GetAppInfo(&info); - BEntry entry(&info.ref); - - BFile appfile(&entry,B_WRITE_ONLY); - appfile.WriteAttr("event_width",B_FLOAT_TYPE,0,&width,sizeof(float)); - - col = fEventList->ColumnAt(2); - width = col->Width(); - appfile.WriteAttr("sound_width",B_FLOAT_TYPE,0,&width,sizeof(float)); - fEventList->RemoveAll(); - - utils.SaveRectToApp("window_rect",this->Frame()); be_app->PostMessage(B_QUIT_REQUESTED); return true; } diff --git a/src/prefs/sounds/HWindow.h b/src/prefs/sounds/HWindow.h index 2e60141c20..e4c603bf96 100644 --- a/src/prefs/sounds/HWindow.h +++ b/src/prefs/sounds/HWindow.h @@ -1,3 +1,18 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: HWindow.h +// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu +// Description: Sounds Preferences +// Created : November 24, 2003 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #ifndef __HWINDOW_H__ #define __HWINDOW_H__ @@ -30,10 +45,8 @@ protected: virtual void DispatchMessage(BMessage *message ,BHandler *handler); void InitGUI(); - void InitMenu(); void SetupMenuField(); void Pulse(); - void RemoveEvent(); private: //HTypeList* fTypeList; HEventList* fEventList; diff --git a/src/prefs/sounds/Icon.rsrc b/src/prefs/sounds/Icon.rsrc deleted file mode 100644 index e93496fd196ac2970479c8b322c372dad55ac528..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3182 zcmeHJy-or_5FR2ZMh!fIy_L0va`@AzT!6&#av&%P$c4jzo$p{wcmxV7pMr#jhp@no zH(2M}b#aaai6(S+$=uA&>^HOX?cPtZL`2!bX@b=$WRq|IxPT?ber}i?_nZ(mF2&cn z?BiXc1FnJmZ(Bq!NnKLk)>#(?;{1l|n1`5$_zc8nAU*@@KLdwO;XFaf7yF${>=etT zd^S~W`eB&n`i|4+w)}vtAeSlU&x+Yiuio)nHM2I{gPaatTo*2rTV6E`{Aw+|Pn6M~ zv{z}>oBmyhUjpOW_B!oe<*8c>PuRCtzR4Adzq2Xt*6;egZjYq!33bUK~$Kby_wcE8_` z^kA^S;Q3Xo-&v5$>?8DOG*XkvM9G{skHiywL~t_4a5&`TV>KR+^&H?KW)AA1E^49& zj3F440v6h?0~+J#8Zh_wKCpgpVfnE59}W%P^nrC6E>R2XmLls%@xY;%AH3_jAXam@ z*uUIY+%1>+A%1XD@kh&lJ;LngG zWRfIFNRlr}lB6R^5+-R$B%Rm$c|PB6J0@$t-BYi7-tXuA^?5$ewfn5kR!W7_T}zm{ z1QGsYNUS3EL#4^Fzrx6}TwuuhLdeG~>X2CSPgWx=)@9UW4KqE+m|U(@gAvsYQI3+w3DpY=*|QWV=QrnGK8Nx-l7uN+cFjRw#r=DLdg)F%`z)PjJGtD;7t5veXFGn8fdJ1J#%+G8gY;56q1>lJq=mN?9|v&N8K zodhver!{wlD5LA7`1)oYp_hw40{y!|MGjI?&dVLMblsF|MG?{UXAbI0o@l_Xcy<9D z)iRez$0>C4)b;Zem0_tiaZ-_7bV|u?Rh_~PE2_(*nQ>`-=iLcakxzwlL+IfC-%JWt>_uURMH zB%FfNa2C$NdAI-<;SyYiD{vLA!F9L^x8OG1fxB=I9>7C*1drhfJcVcQ9P;oIUcqa4 z18?CSyoZnQ2|mLYn1-+L4Zgz<_zAzD02ND>s)Q=2hGkF#wO~O#tbmoU3RXiStbrz2 z3+td6*24za2oZ=v3v7n1uno4u4%i8;unTs>9+1(S?o5s_%Uf$$b;Q$lYfr1)-!+)* zO!qq9kwT%jGno=Exz&zWYPMH*x1Ewa^49HmC6Yby!T!COxb5Y#Q%UV5FTS;=VtXbt uXeYZpmw`;CT@uNcr`~rNi1*paKvxOJP5yge`EH4x_HMsib9nkbcJ&+T3U?_0 diff --git a/src/prefs/sounds/main.cpp b/src/prefs/sounds/main.cpp deleted file mode 100644 index 78fd456155..0000000000 --- a/src/prefs/sounds/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "HApp.h" - -int main() -{ - HApp app; - app.Run(); - return 0; -}