|
10 | 10 |
|
11 | 11 | #include <SDL2/SDL.h>
|
12 | 12 |
|
| 13 | +#include "ProjectMSDLApplication.h" |
| 14 | + |
13 | 15 | RenderLoop::RenderLoop()
|
14 | 16 | : _audioCapture(Poco::Util::Application::instance().getSubsystem<AudioCapture>())
|
15 | 17 | , _projectMWrapper(Poco::Util::Application::instance().getSubsystem<ProjectMWrapper>())
|
@@ -103,6 +105,68 @@ void RenderLoop::PollEvents()
|
103 | 105 |
|
104 | 106 | break;
|
105 | 107 |
|
| 108 | + case SDL_DROPFILE: { |
| 109 | + char* droppedFilePath = event.drop.file; |
| 110 | + |
| 111 | + bool shuffle = projectm_playlist_get_shuffle(_playlistHandle); |
| 112 | + if (shuffle) |
| 113 | + { |
| 114 | + projectm_playlist_set_shuffle(_playlistHandle, false); |
| 115 | + } |
| 116 | + |
| 117 | + int index = projectm_playlist_get_position(_playlistHandle) + 1; |
| 118 | + |
| 119 | + do |
| 120 | + { |
| 121 | + Poco::File droppedFile(droppedFilePath); |
| 122 | + if (!droppedFile.isDirectory()) |
| 123 | + { |
| 124 | + // handle dropped preset file |
| 125 | + Poco::Path droppedFileP(droppedFilePath); |
| 126 | + if (!droppedFile.exists() || (droppedFileP.getExtension() != "milk" && droppedFileP.getExtension() != "prjm")) |
| 127 | + { |
| 128 | + std::string toastMessage = std::string("Invalid preset file: ") + droppedFilePath; |
| 129 | + Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage)); |
| 130 | + poco_information_f1(_logger, "%s", toastMessage); |
| 131 | + break; // exit the block and go to the shuffle check |
| 132 | + } |
| 133 | + |
| 134 | + if (projectm_playlist_insert_preset(_playlistHandle, droppedFilePath, index, true)) |
| 135 | + { |
| 136 | + projectm_playlist_play_next(_playlistHandle, true); |
| 137 | + poco_information_f1(_logger, "Added preset: %s", std::string(droppedFilePath)); |
| 138 | + // no need to toast single presets, as its obvious if a preset was loaded. |
| 139 | + } |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + uint32_t addedFilesCount = projectm_playlist_insert_path(_playlistHandle, droppedFilePath, index, true, true); |
| 144 | + if (addedFilesCount > 0) |
| 145 | + { |
| 146 | + std::string toastMessage = "Added " + std::to_string(addedFilesCount) + " presets from " + droppedFilePath; |
| 147 | + poco_information_f1(_logger, "%s", toastMessage); |
| 148 | + projectm_playlist_play_next(_playlistHandle, true); |
| 149 | + Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage)); |
| 150 | + } |
| 151 | + else |
| 152 | + { |
| 153 | + std::string toastMessage = std::string("No presets found in: ") + droppedFilePath; |
| 154 | + Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage)); |
| 155 | + poco_information_f1(_logger, "%s", toastMessage); |
| 156 | + } |
| 157 | + } |
| 158 | + } while (false); |
| 159 | + |
| 160 | + if (shuffle) |
| 161 | + { |
| 162 | + projectm_playlist_set_shuffle(_playlistHandle, true); |
| 163 | + } |
| 164 | + |
| 165 | + SDL_free(droppedFilePath); |
| 166 | + break; |
| 167 | + } |
| 168 | + |
| 169 | + |
106 | 170 | case SDL_QUIT:
|
107 | 171 | _wantsToQuit = true;
|
108 | 172 | break;
|
|
0 commit comments