You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
8.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the dRowAudio JUCE module
  4. Copyright 2004-13 by dRowAudio.
  5. ------------------------------------------------------------------------------
  6. dRowAudio is provided under the terms of The MIT License (MIT):
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. ==============================================================================
  23. */
  24. #ifndef __DROWAUDIO_MUSICLIBRARYTABLE_H__
  25. #define __DROWAUDIO_MUSICLIBRARYTABLE_H__
  26. #include "../audio/dRowAudio_AudioUtility.h"
  27. #include "../utility/dRowAudio_ITunesLibrary.h"
  28. #include "../utility/dRowAudio_Comparators.h"
  29. //==============================================================================
  30. /**
  31. Table to display and interact with a music library.
  32. The easiest way to use this is to load a default or saved iTunes library like so:
  33. @code
  34. MusicLibraryTable table;
  35. table.setLibraryToUse (ITunesLibrary::getInstance());
  36. File parsedLibraryFile (File::getSpecialLocation (File::userDesktopDirectory).getChildFile ("saved_library_file.xml"));
  37. ValueTree libraryTree (readValueTreeFromFile (parsedLibraryFile));
  38. ITunesLibrary::getInstance()->setLibraryTree (libraryTree);
  39. ITunesLibrary::getInstance()->setLibraryFile (ITunesLibrary::getDefaultITunesLibraryFile());
  40. @endcode
  41. */
  42. class MusicLibraryTable : public Component,
  43. public TableListBoxModel,
  44. public ITunesLibrary::Listener
  45. {
  46. public:
  47. //==============================================================================
  48. /** Create the MusicLibraryTable.
  49. This will initially be blank, set an ITunesLibrary to use first with
  50. setLibraryToUse(). The table will then be continually updated as the library
  51. is parsed.
  52. */
  53. MusicLibraryTable();
  54. /** Destructor.
  55. */
  56. ~MusicLibraryTable();
  57. /** Sets the ITunesLibrary to use.
  58. */
  59. void setLibraryToUse (ITunesLibrary* library);
  60. /** Filters the table to only rows containing the given text.
  61. */
  62. void setFilterText (const String& filterText);
  63. /** Returns the table list box component.
  64. */
  65. TableListBox& getTableListBox() { return table; };
  66. //==============================================================================
  67. /** A set of colour IDs to use to change the colour of various aspects of the main table.
  68. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  69. methods. TextEditor
  70. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  71. */
  72. enum ColourIds
  73. {
  74. backgroundColourId = 0x2000000, /**< The colour to use for the cell's background - this can be
  75. transparent if necessary. */
  76. unfocusedBackgroundColourId = 0x2000001, /**< The colour to use for the cell's background
  77. when the table is unfocused. */
  78. selectedBackgroundColourId = 0x2000002, /**< The colour to use for the cell's background if the
  79. row is selected. */
  80. selectedUnfocusedBackgroundColourId = 0x2000003, /**< The colour to use for the cell's background if the
  81. row is selected and the table is unfocused. */
  82. textColourId = 0x2000004, /**< The colour that will be used for the cell's text. */
  83. selectedTextColourId = 0x2000005, /**< The colour with which to draw the text in selected
  84. cells. */
  85. unfocusedTextColourId = 0x2000006, /**< The colour with which to draw the text in cells when
  86. the table is unfocused. */
  87. selectedUnfocusedTextColourId = 0x2000007, /**< The colour with which to draw the text in selected
  88. cells when the table is unfocused. */
  89. outlineColourId = 0x2000008, /**< The colour used to draw an outline around the cells. */
  90. selectedOutlineColourId = 0x2000009, /**< The colour used to draw an outline around selected cells. */
  91. unfocusedOutlineColourId = 0x2000010, /**< The colour used to draw an outline around the cells when
  92. the table is unfocused. */
  93. selectedUnfocusedOutlineColourId = 0x2000011, /**< The colour used to draw an outline around selected cells
  94. when the table is unfocused. */
  95. };
  96. //==============================================================================
  97. /** @internal */
  98. void libraryChanged (ITunesLibrary* library);
  99. /** @internal */
  100. void libraryUpdated (ITunesLibrary* library);
  101. /** @internal */
  102. void libraryFinished (ITunesLibrary* library);
  103. //==============================================================================
  104. /** Returns the number of rows currently bein displayed in the table.
  105. */
  106. int getNumRows();
  107. /** @internal */
  108. void paintRowBackground (Graphics& g, int rowNumber,
  109. int width, int height, bool rowIsSelected);
  110. /** @internal */
  111. void paintCell (Graphics& g,
  112. int rowNumber,
  113. int columnId,
  114. int width, int height,
  115. bool rowIsSelected);
  116. /** @internal */
  117. void sortOrderChanged (int newSortColumnId, bool isForwards);
  118. /** @internal */
  119. int getColumnAutoSizeWidth (int columnId);
  120. //==============================================================================
  121. /** @internal */
  122. void resized();
  123. /** @internal */
  124. void focusOfChildComponentChanged (FocusChangeType cause);
  125. /** @internal */
  126. var getDragSourceDescription (const SparseSet<int>& currentlySelectedRows);
  127. private:
  128. //==============================================================================
  129. Font font;
  130. ITunesLibrary* currentLibrary;
  131. TableListBox table;
  132. String currentFilterText;
  133. ValueTree dataList;
  134. ValueTree filteredDataList;
  135. SortedSet<int> selectedRowsLibIds;
  136. int filteredNumRows;
  137. bool finishedLoading;
  138. //==============================================================================
  139. void updateTableFilteredAndSorted();
  140. void findSelectedRows();
  141. void setSelectedRows();
  142. //==============================================================================
  143. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MusicLibraryTable);
  144. };
  145. #endif // __DROWAUDIO_MUSICLIBRARYTABLE_H__