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