33 #include "nsComponentManagerUtils.h"
34 #include "nsServiceManagerUtils.h"
35 #include <nsICategoryManager.h>
37 #include "nsEnumeratorUtils.h"
38 #include "nsArrayEnumerator.h"
40 #include <nsStringGlue.h>
46 #define SB_MENU_HOST "menu"
47 #define SB_TOOLBAR_HOST "toolbar"
59 nsString mVisibleHost;
69 (
const char* aVisibleHost)
71 mVisibleHost = NS_ConvertASCIItoUTF16(aVisibleHost);
79 sbPlaylistCommandsVisibility::HandleCallback
81 const nsAString &
aHost,
82 const nsAString &
aData,
85 NS_ENSURE_ARG_POINTER(aContext);
86 NS_ENSURE_ARG_POINTER(_retval);
88 *_retval = (host.Equals(mVisibleHost));
102 sbPlaylistCommandsHelper::~sbPlaylistCommandsHelper()
109 sbPlaylistCommandsHelper::CreateCommandObjectForAction
110 (
const nsAString &aCommandId,
111 const nsAString &aLabel,
112 const nsAString &aTooltipText,
116 NS_ENSURE_ARG_POINTER(aCallback);
117 NS_ENSURE_ARG_POINTER(_retval);
118 NS_ENSURE_TRUE(!aCommandId.IsEmpty(), NS_ERROR_INVALID_ARG);
119 NS_ENSURE_TRUE(!aLabel.IsEmpty(), NS_ERROR_INVALID_ARG);
122 NS_ConvertUTF16toUTF8(aCommandId).
get(),
123 NS_ConvertUTF16toUTF8(aLabel).
get());
126 nsCOMPtr<sbIPlaylistCommandsBuilder> newCommand =
127 do_CreateInstance(
"@songbirdnest.com/Songbird/PlaylistCommandsBuilder;1",
129 NS_ENSURE_SUCCESS(rv, rv);
132 rv = newCommand->Init(aCommandId);
133 NS_ENSURE_SUCCESS(rv, rv);
141 NS_ENSURE_SUCCESS(rv, rv);
143 NS_ADDREF(*_retval = newCommand);
154 sbPlaylistCommandsHelper::AddToServicePane(
const nsAString &aMediaListGUID,
155 const nsAString &aMediaListType,
171 nsCOMPtr<sbIPlaylistCommandsManager> cmdsMgr =
173 NS_ENSURE_SUCCESS(rv, rv);
175 nsCOMPtr<sbIPlaylistCommands> dupCommand;
176 rv = aCommandObject->Duplicate(getter_AddRefs(dupCommand));
177 NS_ENSURE_SUCCESS(rv, rv);
179 rv = dupCommand->SetTargetFlags
181 NS_ENSURE_SUCCESS(rv, rv);
184 rv = cmdsMgr->RegisterPlaylistCommandsMediaList(aMediaListGUID,
187 NS_ENSURE_SUCCESS(rv, rv);
198 sbPlaylistCommandsHelper::AddToMediaItemContextMenu
199 (
const nsAString &aMediaListGUID,
200 const nsAString &aMediaListType,
204 nsCOMPtr<sbIPlaylistCommandsManager> cmdsMgr =
206 NS_ENSURE_SUCCESS(rv, rv);
208 nsCOMPtr<sbIPlaylistCommandsBuilder> commandBuilder =
209 do_QueryInterface(aCommandObject, &rv);
210 NS_ENSURE_SUCCESS(rv, rv);
213 rv = commandBuilder->SetTargetFlags
215 NS_ENSURE_SUCCESS(rv, rv);
218 rv = commandBuilder->SetVisibleCallback
220 NS_ENSURE_SUCCESS(rv, rv);
222 rv = cmdsMgr->RegisterPlaylistCommandsMediaItem(aMediaListGUID,
225 NS_ENSURE_SUCCESS(rv, rv);
236 sbPlaylistCommandsHelper::AddToToolbar(
const nsAString &aMediaListGUID,
237 const nsAString &aMediaListType,
241 nsCOMPtr<sbIPlaylistCommandsManager> cmdsMgr =
243 NS_ENSURE_SUCCESS(rv, rv);
245 nsCOMPtr<sbIPlaylistCommandsBuilder> commandBuilder =
246 do_QueryInterface(aCommandObject, &rv);
247 NS_ENSURE_SUCCESS(rv, rv);
250 rv = commandBuilder->SetTargetFlags
252 NS_ENSURE_SUCCESS(rv, rv);
255 rv = commandBuilder->
257 NS_ENSURE_SUCCESS(rv, rv);
259 rv = cmdsMgr->RegisterPlaylistCommandsMediaItem(aMediaListGUID,
262 NS_ENSURE_SUCCESS(rv, rv);
279 sbPlaylistCommandsHelper::AddCommandObject
280 (PRUint16 aTargetFlags,
281 const nsAString &aMediaListGUID,
282 const nsAString &aMediaListType,
285 NS_ENSURE_ARG_POINTER(aCommandObject);
288 nsCOMPtr<sbIPlaylistCommandsManager> cmdsMgr =
290 NS_ENSURE_SUCCESS(rv, rv);
296 rv = AddToServicePane(aMediaListGUID, aMediaListType, aCommandObject);
297 NS_ENSURE_SUCCESS(rv, rv);
310 unsigned short mediaItemMenuAndToolbar =
311 sbIPlaylistCommandsHelper::TARGET_MEDIAITEM_CONTEXT_MENU |
314 rv = aCommandObject->SetTargetFlags(mediaItemMenuAndToolbar);
315 NS_ENSURE_SUCCESS(rv, rv);
317 rv = cmdsMgr->RegisterPlaylistCommandsMediaItem(aMediaListGUID,
320 NS_ENSURE_SUCCESS(rv, rv);
322 else if (aTargetFlags &
323 sbIPlaylistCommandsHelper::TARGET_MEDIAITEM_CONTEXT_MENU)
326 rv = AddToMediaItemContextMenu(aMediaListGUID, aMediaListType, aCommandObject);
327 NS_ENSURE_SUCCESS(rv, rv);
329 else if (aTargetFlags &
330 sbIPlaylistCommandsHelper::TARGET_TOOLBAR)
333 rv = AddToToolbar(aMediaListGUID, aMediaListType, aCommandObject);
334 NS_ENSURE_SUCCESS(rv, rv);
342 sbPlaylistCommandsHelper::AddCommandObjectForType
343 (PRUint16 aTargetFlags,
344 const nsAString &aMediaListType,
347 NS_ENSURE_ARG_POINTER(aCommandObject);
353 rv = aCommandObject->GetId(
id);
354 NS_ENSURE_SUCCESS(rv, rv);
356 TRACE_FUNCTION(
"adding command with id \'%s\' to medialist type \'%s\'",
357 NS_ConvertUTF16toUTF8(
id).
get(),
358 NS_ConvertUTF16toUTF8(aMediaListType).
get());
362 rv = AddCommandObject(aTargetFlags,
366 NS_ENSURE_SUCCESS(rv, rv);
373 sbPlaylistCommandsHelper::AddCommandObjectForGUID
374 (PRUint16 aTargetFlags,
375 const nsAString &aMediaListGUID,
378 NS_ENSURE_ARG_POINTER(aCommandObject);
384 rv = aCommandObject->GetId(
id);
385 NS_ENSURE_SUCCESS(rv, rv);
387 TRACE_FUNCTION(
"adding command with id \'%s\' to medialist guid \'%s\'",
388 NS_ConvertUTF16toUTF8(
id).
get(),
389 NS_ConvertUTF16toUTF8(aMediaListGUID).
get());
393 rv = AddCommandObject(aTargetFlags,
397 NS_ENSURE_SUCCESS(rv, rv);
416 nsString mHiddenHost;
417 nsCOMPtr<sbIPlaylistCommandsBuilderPCCallback> mOriginalCallback;
421 (
const char* aHiddenHost,
424 mHiddenHost = NS_ConvertASCIItoUTF16(aHiddenHost);
425 mOriginalCallback = aCallback;
433 sbPlaylistCommandsHidden::HandleCallback
435 const nsAString &aHost,
436 const nsAString &aData,
439 NS_ENSURE_ARG_POINTER(aContext);
440 NS_ENSURE_ARG_POINTER(_retval);
441 nsString host(aHost);
444 if (host.Equals(mHiddenHost))
452 nsresult rv = mOriginalCallback->HandleCallback(aContext,
456 NS_ENSURE_SUCCESS(rv, rv);
475 sbPlaylistCommandsHelper::SetRemainingFlags
476 (PRUint16 aTargetFlags,
479 PRUint16 commandsLocation;
480 nsresult rv = aCommandObject->GetTargetFlags(&commandsLocation);
481 NS_ENSURE_SUCCESS(rv, rv);
483 if (!commandsLocation || commandsLocation == 0)
496 commandsLocation = commandsLocation & (~aTargetFlags);
498 rv = aCommandObject->SetTargetFlags(commandsLocation);
499 NS_ENSURE_SUCCESS(rv, rv);
514 sbPlaylistCommandsHelper::RemoveCommandObject
515 (PRUint16 aTargetFlags,
516 const nsAString &aMediaListGUID,
517 const nsAString &aMediaListType,
520 NS_ENSURE_ARG_POINTER(aCommandObject);
522 nsCOMPtr<sbIPlaylistCommandsManager> cmdsMgr =
524 NS_ENSURE_SUCCESS(rv, rv);
526 PRBool removeFromServicePane =
530 PRBool removeFromContextMenu =
534 PRBool removeFromToolbar =
539 if (removeFromServicePane)
547 rv = cmdsMgr->UnregisterPlaylistCommandsMediaList(aMediaListGUID,
550 NS_ENSURE_SUCCESS(rv, rv);
555 if (removeFromContextMenu && removeFromToolbar)
563 rv = cmdsMgr->UnregisterPlaylistCommandsMediaItem(aMediaListGUID,
566 NS_ENSURE_SUCCESS(rv, rv);
569 rv = SetRemainingFlags(aTargetFlags, aCommandObject);
570 NS_ENSURE_SUCCESS(rv, rv);
576 if (!removeFromContextMenu && !removeFromToolbar) {
577 rv = SetRemainingFlags(aTargetFlags, aCommandObject);
578 NS_ENSURE_SUCCESS(rv, rv);
583 PRUint16 commandsLocation;
584 rv = aCommandObject->GetTargetFlags(&commandsLocation);
585 NS_ENSURE_SUCCESS(rv, rv);
587 if (!commandsLocation || commandsLocation == 0)
602 nsCOMPtr<sbIPlaylistCommandsBuilderPCCallback> oldCallback;
603 rv = aCommandObject->GetVisibleCallback(getter_AddRefs(oldCallback));
604 NS_ENSURE_SUCCESS(rv, rv);
606 nsCOMPtr<sbIPlaylistCommandsBuilder> commandBuilder =
607 do_QueryInterface(aCommandObject,
609 NS_ENSURE_SUCCESS(rv, rv);
614 nsCOMPtr<sbPlaylistCommandsHidden> visCallback =
619 rv = commandBuilder->SetVisibleCallback(visCallback);
620 NS_ENSURE_SUCCESS(rv, rv);
621 rv = commandBuilder->NotifyListeners
622 (NS_LITERAL_STRING(
"onCommandChanged"),
628 PRBool isInContextMenu =
636 if (isInContextMenu && isInToolbar)
640 nsCOMPtr<sbIPlaylistCommandsBuilder> commandBuilder =
641 do_QueryInterface(aCommandObject,
643 NS_ENSURE_SUCCESS(rv, rv);
648 nsCOMPtr<sbPlaylistCommandsVisibility> visCallback =
652 rv = commandBuilder->SetVisibleCallback(visCallback);
653 NS_ENSURE_SUCCESS(rv, rv);
655 rv = commandBuilder->NotifyListeners
656 (NS_LITERAL_STRING(
"onCommandChanged"),
658 NS_ENSURE_SUCCESS(rv, rv);
661 else if ((isInContextMenu && removeFromContextMenu) ||
662 (isInToolbar && removeFromToolbar)) {
665 rv = cmdsMgr->UnregisterPlaylistCommandsMediaItem(aMediaListGUID,
668 NS_ENSURE_SUCCESS(rv, rv);
672 rv = SetRemainingFlags(aTargetFlags, aCommandObject);
673 NS_ENSURE_SUCCESS(rv, rv);
681 sbPlaylistCommandsHelper::RemoveCommandObjectForType
682 (PRUint16 aTargetFlags,
683 const nsAString &aMediaListType,
686 NS_ENSURE_ARG_POINTER(aCommandObject);
692 rv = aCommandObject->GetId(
id);
693 NS_ENSURE_SUCCESS(rv, rv);
695 TRACE_FUNCTION(
"removing object with id \'%s\' from medialist type \'%s\'",
696 NS_ConvertUTF16toUTF8(
id).
get(),
697 NS_ConvertUTF16toUTF8(aMediaListType).
get());
701 rv = RemoveCommandObject(aTargetFlags,
705 NS_ENSURE_SUCCESS(rv, rv);
713 sbPlaylistCommandsHelper::RemoveCommandObjectForGUID
714 (PRUint16 aTargetFlags,
715 const nsAString &aMediaListGUID,
718 NS_ENSURE_ARG_POINTER(aCommandObject);
724 rv = aCommandObject->GetId(
id);
725 NS_ENSURE_SUCCESS(rv, rv);
727 TRACE_FUNCTION(
"removing object with id \'%s\' from medialist guid \'%s\'",
728 NS_ConvertUTF16toUTF8(
id).
get(),
729 NS_ConvertUTF16toUTF8(aMediaListGUID).
get());
734 rv = RemoveCommandObject(aTargetFlags,
738 NS_ENSURE_SUCCESS(rv, rv);
747 sbPlaylistCommandsHelper::GetChildCommandWithId
749 const nsAString &aCommandId,
752 NS_ENSURE_ARG_POINTER(aParentCommand);
753 NS_ENSURE_ARG_POINTER(_retval);
755 nsString commandId(aCommandId);
756 nsCOMPtr<nsISimpleEnumerator> cmdEnum;
760 nsresult rv = aParentCommand->GetChildrenCommandObjects
761 (getter_AddRefs(cmdEnum));
762 NS_ENSURE_SUCCESS(rv, rv);
765 while (NS_SUCCEEDED(cmdEnum->HasMoreElements(&hasMore)) && hasMore) {
766 nsCOMPtr<sbIPlaylistCommands>
next;
767 if (NS_SUCCEEDED(cmdEnum->GetNext(getter_AddRefs(next))) && next) {
769 rv = next->GetId(aId);
770 NS_ENSURE_SUCCESS(rv, rv);
773 if (aId == commandId) {
774 NS_ADDREF(*_retval = next);
796 sbPlaylistCommandsHelper::GetCommandObject(PRUint16 aTargetFlag,
797 const nsAString &aMediaListGUID,
798 const nsAString &aMediaListType,
799 const nsAString &aCommandId,
802 NS_ENSURE_ARG_POINTER(_retval);
805 nsCOMPtr<sbIPlaylistCommandsManager> cmdsMgr =
807 NS_ENSURE_SUCCESS(rv, rv);
809 nsCOMPtr<sbIPlaylistCommands> foundCommand = nsnull;
810 nsCOMPtr<sbIPlaylistCommands> rootCommand;
813 sbIPlaylistCommandsHelper::TARGET_SERVICEPANE_MENU)
816 rv = cmdsMgr->GetPlaylistCommandsMediaList(aMediaListGUID,
818 getter_AddRefs(rootCommand));
819 NS_ENSURE_SUCCESS(rv, rv);
821 else if (aTargetFlag &
822 (sbIPlaylistCommandsHelper::TARGET_MEDIAITEM_CONTEXT_MENU |
823 sbIPlaylistCommandsHelper::TARGET_TOOLBAR)) {
825 rv = cmdsMgr->GetPlaylistCommandsMediaItem(aMediaListGUID,
827 getter_AddRefs(rootCommand));
828 NS_ENSURE_SUCCESS(rv, rv);
833 rv = GetChildCommandWithId(rootCommand,
835 getter_AddRefs(foundCommand));
836 NS_ENSURE_SUCCESS(rv, rv);
849 rv = foundCommand->GetTargetFlags(&foundFlags);
850 NS_ENSURE_SUCCESS(rv, rv);
852 if (foundFlags > 0 && (foundFlags & aTargetFlag) == 0)
854 foundCommand = nsnull;
857 NS_IF_ADDREF(*_retval = foundCommand);
864 sbPlaylistCommandsHelper::GetCommandObjectForType
865 (PRUint16 aTargetFlag,
866 const nsAString &aMediaListType,
867 const nsAString &aCommandId,
870 NS_ENSURE_ARG_POINTER(_retval);
873 TRACE_FUNCTION(
"getting object with id \'%s\' from medialist type \'%s\'",
874 NS_ConvertUTF16toUTF8(aCommandId).
get(),
875 NS_ConvertUTF16toUTF8(aMediaListType).
get());
877 nsCOMPtr<sbIPlaylistCommands> foundCommand;
878 rv = GetCommandObject(aTargetFlag,
882 getter_AddRefs(foundCommand));
883 NS_ENSURE_SUCCESS(rv, rv);
885 NS_IF_ADDREF(*_retval = foundCommand);
892 sbPlaylistCommandsHelper::GetCommandObjectForGUID
893 (PRUint16 aTargetFlag,
894 const nsAString &aMediaListGUID,
895 const nsAString &aCommandId,
898 NS_ENSURE_ARG_POINTER(_retval);
901 TRACE_FUNCTION(
"getting object with id \'%s\' from medialist guid \'%s\'",
902 NS_ConvertUTF16toUTF8(aCommandId).
get(),
903 NS_ConvertUTF16toUTF8(aMediaListGUID).
get());
905 nsCOMPtr<sbIPlaylistCommands> foundCommand;
906 rv = GetCommandObject(aTargetFlag,
910 getter_AddRefs(foundCommand));
911 NS_ENSURE_SUCCESS(rv, rv);
913 NS_IF_ADDREF(*_retval = foundCommand);
#define SONGBIRD_PlaylistCommandsManager_CONTRACTID
A helper used to construct sbIPlaylistCommands interfaces.
#define SB_PRLOG_SETUP(x)
NS_IMPL_THREADSAFE_ISUPPORTS1(sbPlaylistCommandsVisibility, sbIPlaylistCommandsBuilderPCCallback)
NS_DECL_SBIPLAYLISTCOMMANDSBUILDERPCCALLBACK
sbPlaylistCommandsHelper()
virtual ~sbPlaylistCommandsVisibility()
The interface for giving context to playlist builder callbacks.
NS_DECL_SBIPLAYLISTCOMMANDSBUILDERPCCALLBACK
virtual ~sbPlaylistCommandsHidden()
A callback interface used to receive callbacks from an sbIPlaylistCommandsBuilder object relating to ...
const unsigned short TARGET_TOOLBAR
A flag referring to the toolbar at the bottom of a medialist view.
const unsigned short TARGET_ALL
A convenience flag referring to all locations that a sbIPlaylistCommands object can appear...
const unsigned short TARGET_MEDIAITEM_CONTEXT_MENU
A flag referring to the context menu that appears from mediaitems displayed in the medialist...
An interface used to receive generic callbacks from an sbIPlaylistCommandsBuilder object...
A helper service to add and remove playlistCommands.
Songbird PlaylistCommandsManager Component Definition.
#define TRACE_FUNCTION(...)
An interface that represents the set of command buttons and context menu items available on a display...
sbPlaylistCommandsHidden(const char *aHiddenHost, sbIPlaylistCommandsBuilderPCCallback *aCallback)
StringArrayEnumerator prototype hasMore
const unsigned short TARGET_SERVICEPANE_MENU
A flag referring to the context menu that appears from the service pane node.
Songbird PlaylistCommandsHelper Component Definition.
sbPlaylistCommandsVisibility(const char *aVisibleHost)
_updateTextAndScrollDataForFrame aData