From 1c1de1a5cdb7ff94bdccb2686f406f5e8b7d9d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 10 Sep 2010 11:15:28 +0000 Subject: [PATCH] The Media:Rating attribute can now be controlled via the new Attributes menu. Added a TODO for how this should eventually work. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38598 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 77 ++++++++++++++++++++++++++++++-- src/apps/mediaplayer/MainWin.h | 9 +++- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index fdc6646f21..0ec60fbf6a 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include "AudioProducer.h" @@ -97,6 +98,8 @@ enum { M_SELECT_VIDEO_TRACK = 0x00010000, M_SELECT_VIDEO_TRACK_END = 0x000fffff, + M_SET_RATING, + M_SET_PLAYLIST_POSITION, M_FILE_DELETE, @@ -142,6 +145,9 @@ static property_info sPropertyInfo[] = { }; +static const char* kRatingAttrName = "Media:Rating"; + + //#define printf(a...) @@ -926,6 +932,14 @@ MainWin::MessageReceived(BMessage* msg) } break; + case M_SET_RATING: + { + int32 rating; + if (msg->FindInt32("rating", &rating) == B_OK) + _SetRating(rating); + break; + } + default: if (msg->what >= M_SELECT_AUDIO_TRACK && msg->what <= M_SELECT_AUDIO_TRACK_END) { @@ -1448,9 +1462,15 @@ MainWin::_CreateMenu() _SetupVideoAspectItems(fVideoAspectMenu); fVideoMenu->AddItem(fVideoAspectMenu); - item = new BMenuItem("<- This space for rent ->", NULL); - item->SetEnabled(false); - fAttributesMenu->AddItem(item); + fRatingMenu = new BMenu("Rating"); + fAttributesMenu->AddItem(fRatingMenu); + for (int32 i = 1; i <= 10; i++) { + char label[16]; + snprintf(label, sizeof(label), "%ld", i); + BMessage* setRatingMsg = new BMessage(M_SET_RATING); + setRatingMsg->AddInt32("rating", i); + fRatingMenu->AddItem(new BMenuItem(label, setRatingMsg)); + } } @@ -2255,6 +2275,56 @@ MainWin::_UpdatePlaylistItemFile() } } } + + _UpdateAttributesMenu(node); +} + + +void +MainWin::_UpdateAttributesMenu(const BNode& node) +{ + int32 rating = -1; + + attr_info info; + status_t status = node.GetAttrInfo(kRatingAttrName, &info); + if (status == B_OK && info.type == B_INT32_TYPE) { + // Node has the Rating attribute. + node.ReadAttr(kRatingAttrName, B_INT32_TYPE, 0, &rating, + sizeof(rating)); + } + + for (int32 i = 0; BMenuItem* item = fRatingMenu->ItemAt(i); i++) + item->SetMarked(i + 1 == rating); +} + + +void +MainWin::_SetRating(int32 rating) +{ + BAutolock locker(fPlaylist); + const FilePlaylistItem* item + = dynamic_cast(fController->Item()); + if (item == NULL) + return; + + BNode node(&item->Ref()); + if (node.InitCheck()) + return; + + locker.Unlock(); + + node.WriteAttr(kRatingAttrName, B_INT32_TYPE, 0, &rating, sizeof(rating)); + + // TODO: The whole mechnism should work like this: + // * There is already an attribute API for PlaylistItem, flesh it out! + // * FilePlaylistItem node-monitors it's file somehow. + // * FilePlaylistItem keeps attributes in sync and sends notications. + // * MainWin updates the menu according to FilePlaylistItem notifications. + // * PlaylistWin shows columns with attribute and other info. + // * PlaylistWin updates also upon FilePlaylistItem notifications. + // * This keeps attributes in sync when another app changes them. + + _UpdateAttributesMenu(node); } @@ -2280,6 +2350,7 @@ MainWin::_UpdateControlsEnabledStatus() fControls->SetEnabled(enabledButtons); fNoInterfaceMenuItem->SetEnabled(fHasVideo); + fAttributesMenu->SetEnabled(fHasAudio || fHasVideo); } diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 107096c16b..12f9557ba3 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -120,6 +120,9 @@ private: bool animate = true); void _UpdatePlaylistItemFile(); + void _UpdateAttributesMenu(const BNode& node); + void _SetRating(int32 rating); + void _UpdateControlsEnabledStatus(); void _UpdatePlaylistMenu(); void _AddPlaylistItem(PlaylistItem* item, @@ -131,6 +134,7 @@ private: void _AdoptGlobalSettings(); +private: bigtime_t fCreationTime; BMenuBar* fMenuBar; @@ -141,14 +145,15 @@ private: PlaylistWindow* fPlaylistWindow; BMenu* fFileMenu; + BMenu* fPlaylistMenu; BMenu* fAudioMenu; BMenu* fVideoMenu; BMenu* fVideoAspectMenu; BMenu* fAudioTrackMenu; BMenu* fVideoTrackMenu; - BMenu* fAttributesMenu; BMenuItem* fNoInterfaceMenuItem; - BMenu* fPlaylistMenu; + BMenu* fAttributesMenu; + BMenu* fRatingMenu; bool fHasFile; bool fHasVideo;