| 1 |
/* |
| 2 |
* Copyright (C) 2005-2020 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowPictures.h" |
| 10 |
|
| 11 |
#include "Autorun.h" |
| 12 |
#include "FileItem.h" |
| 13 |
#include "GUIDialogPictureInfo.h" |
| 14 |
#include "GUIPassword.h" |
| 15 |
#include "GUIWindowSlideShow.h" |
| 16 |
#include "PictureInfoLoader.h" |
| 17 |
#include "ServiceBroker.h" |
| 18 |
#include "URL.h" |
| 19 |
#include "Util.h" |
| 20 |
#include "addons/gui/GUIDialogAddonInfo.h" |
| 21 |
#include "application/Application.h" |
| 22 |
#include "application/ApplicationComponents.h" |
| 23 |
#include "application/ApplicationPlayer.h" |
| 24 |
#include "dialogs/GUIDialogMediaSource.h" |
| 25 |
#include "dialogs/GUIDialogProgress.h" |
| 26 |
#include "guilib/GUIComponent.h" |
| 27 |
#include "guilib/GUIWindowManager.h" |
| 28 |
#include "input/actions/ActionIDs.h" |
| 29 |
#include "media/MediaLockState.h" |
| 30 |
#include "messaging/helpers/DialogOKHelper.h" |
| 31 |
#include "pictures/SlideShowDelegator.h" |
| 32 |
#include "playlists/PlayList.h" |
| 33 |
#include "playlists/PlayListFactory.h" |
| 34 |
#include "settings/MediaSourceSettings.h" |
| 35 |
#include "settings/Settings.h" |
| 36 |
#include "settings/SettingsComponent.h" |
| 37 |
#include "utils/SortUtils.h" |
| 38 |
#include "utils/StringUtils.h" |
| 39 |
#include "utils/URIUtils.h" |
| 40 |
#include "utils/Variant.h" |
| 41 |
#include "utils/XTimeUtils.h" |
| 42 |
#include "utils/log.h" |
| 43 |
#include "view/GUIViewState.h" |
| 44 |
|
| 45 |
#define CONTROL_BTNSORTASC 4 |
| 46 |
#define CONTROL_LABELFILES 12 |
| 47 |
|
| 48 |
using namespace XFILE; |
| 49 |
using namespace KODI::MESSAGING; |
| 50 |
|
| 51 |
using namespace std::chrono_literals; |
| 52 |
|
| 53 |
#define CONTROL_BTNSLIDESHOW 6 |
| 54 |
#define CONTROL_BTNSLIDESHOW_RECURSIVE 7 |
| 55 |
#define CONTROL_SHUFFLE 9 |
| 56 |
|
| 57 |
CGUIWindowPictures::CGUIWindowPictures(void) |
| 58 |
: CGUIMediaWindow(WINDOW_PICTURES, "MyPics.xml") |
| 59 |
{ |
| 60 |
m_thumbLoader.SetObserver(this); |
| 61 |
m_slideShowStarted = false; |
| 62 |
m_dlgProgress = NULL; |
| 63 |
} |
| 64 |
|
| 65 |
void CGUIWindowPictures::OnInitWindow() |
| 66 |
{ |
| 67 |
CGUIMediaWindow::OnInitWindow(); |
| 68 |
if (m_slideShowStarted) |
| 69 |
{ |
| 70 |
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator(); |
| 71 |
std::string path; |
| 72 |
if (slideShow.GetCurrentSlide()) |
| 73 |
path = URIUtils::GetDirectory(slideShow.GetCurrentSlide()->GetPath()); |
| 74 |
if (m_vecItems->IsPath(path)) |
| 75 |
{ |
| 76 |
if (slideShow.GetCurrentSlide()) |
| 77 |
m_viewControl.SetSelectedItem(slideShow.GetCurrentSlide()->GetPath()); |
| 78 |
SaveSelectedItemInHistory(); |
| 79 |
} |
| 80 |
m_slideShowStarted = false; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
CGUIWindowPictures::~CGUIWindowPictures(void) = default; |
| 85 |
|
| 86 |
bool CGUIWindowPictures::OnMessage(CGUIMessage& message) |
| 87 |
{ |
| 88 |
switch ( message.GetMessage() ) |
| 89 |
{ |
| 90 |
case GUI_MSG_WINDOW_DEINIT: |
| 91 |
{ |
| 92 |
if (m_thumbLoader.IsLoading()) |
| 93 |
m_thumbLoader.StopThread(); |
| 94 |
|
| 95 |
} |
| 96 |
break; |
| 97 |
|
| 98 |
case GUI_MSG_WINDOW_INIT: |
| 99 |
{ |
| 100 |
// is this the first time accessing this window? |
| 101 |
if (m_vecItems->GetPath() == "?" && message.GetStringParam().empty()) |
| 102 |
message.SetStringParam(CMediaSourceSettings::GetInstance().GetDefaultSource("pictures")); |
| 103 |
|
| 104 |
m_dlgProgress = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogProgress>(WINDOW_DIALOG_PROGRESS); |
| 105 |
} |
| 106 |
break; |
| 107 |
|
| 108 |
case GUI_MSG_CLICKED: |
| 109 |
{ |
| 110 |
int iControl = message.GetSenderId(); |
| 111 |
if (iControl == CONTROL_BTNSLIDESHOW) // Slide Show |
| 112 |
{ |
| 113 |
OnSlideShow(); |
| 114 |
} |
| 115 |
else if (iControl == CONTROL_BTNSLIDESHOW_RECURSIVE) // Recursive Slide Show |
| 116 |
{ |
| 117 |
OnSlideShowRecursive(); |
| 118 |
} |
| 119 |
else if (iControl == CONTROL_SHUFFLE) |
| 120 |
{ |
| 121 |
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); |
| 122 |
settings->ToggleBool(CSettings::SETTING_SLIDESHOW_SHUFFLE); |
| 123 |
settings->Save(); |
| 124 |
} |
| 125 |
else if (m_viewControl.HasControl(iControl)) // list/thumb control |
| 126 |
{ |
| 127 |
int iItem = m_viewControl.GetSelectedItem(); |
| 128 |
int iAction = message.GetParam1(); |
| 129 |
|
| 130 |
// iItem is checked for validity inside these routines |
| 131 |
if (iAction == ACTION_DELETE_ITEM) |
| 132 |
{ |
| 133 |
// is delete allowed? |
| 134 |
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_ALLOWFILEDELETION)) |
| 135 |
OnDeleteItem(iItem); |
| 136 |
else |
| 137 |
return false; |
| 138 |
} |
| 139 |
else if (iAction == ACTION_PLAYER_PLAY) |
| 140 |
{ |
| 141 |
ShowPicture(iItem, true); |
| 142 |
return true; |
| 143 |
} |
| 144 |
else if (iAction == ACTION_SHOW_INFO) |
| 145 |
{ |
| 146 |
OnItemInfo(iItem); |
| 147 |
return true; |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
break; |
| 152 |
} |
| 153 |
return CGUIMediaWindow::OnMessage(message); |
| 154 |
} |
| 155 |
|
| 156 |
void CGUIWindowPictures::UpdateButtons() |
| 157 |
{ |
| 158 |
CGUIMediaWindow::UpdateButtons(); |
| 159 |
|
| 160 |
// Update the shuffle button |
| 161 |
SET_CONTROL_SELECTED(GetID(), CONTROL_SHUFFLE, CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_SLIDESHOW_SHUFFLE)); |
| 162 |
|
| 163 |
// check we can slideshow or recursive slideshow |
| 164 |
int nFolders = m_vecItems->GetFolderCount(); |
| 165 |
if (nFolders == m_vecItems->Size() || |
| 166 |
m_vecItems->GetPath() == "addons://sources/image/") |
| 167 |
{ |
| 168 |
CONTROL_DISABLE(CONTROL_BTNSLIDESHOW); |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
CONTROL_ENABLE(CONTROL_BTNSLIDESHOW); |
| 173 |
} |
| 174 |
if (m_guiState.get() && !m_guiState->HideParentDirItems()) |
| 175 |
nFolders--; |
| 176 |
if (m_vecItems->Size() == 0 || nFolders == 0 || |
| 177 |
m_vecItems->GetPath() == "addons://sources/image/") |
| 178 |
{ |
| 179 |
CONTROL_DISABLE(CONTROL_BTNSLIDESHOW_RECURSIVE); |
| 180 |
} |
| 181 |
else |
| 182 |
{ |
| 183 |
CONTROL_ENABLE(CONTROL_BTNSLIDESHOW_RECURSIVE); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
void CGUIWindowPictures::OnPrepareFileItems(CFileItemList& items) |
| 188 |
{ |
| 189 |
CGUIMediaWindow::OnPrepareFileItems(items); |
| 190 |
|
| 191 |
for (int i=0;i<items.Size();++i ) |
| 192 |
if (StringUtils::EqualsNoCase(items[i]->GetLabel(), "folder.jpg")) |
| 193 |
items.Remove(i); |
| 194 |
|
| 195 |
if (items.GetFolderCount() == items.Size() || !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_PICTURES_USETAGS)) |
| 196 |
return; |
| 197 |
|
| 198 |
// Start the music info loader thread |
| 199 |
CPictureInfoLoader loader; |
| 200 |
loader.SetProgressCallback(m_dlgProgress); |
| 201 |
loader.Load(items); |
| 202 |
|
| 203 |
bool bShowProgress = !CServiceBroker::GetGUI()->GetWindowManager().HasModalDialog(true); |
| 204 |
bool bProgressVisible = false; |
| 205 |
|
| 206 |
auto start = std::chrono::steady_clock::now(); |
| 207 |
|
| 208 |
while (loader.IsLoading() && m_dlgProgress && !m_dlgProgress->IsCanceled()) |
| 209 |
{ |
| 210 |
if (bShowProgress) |
| 211 |
{ // Do we have to init a progress dialog? |
| 212 |
auto end = std::chrono::steady_clock::now(); |
| 213 |
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); |
| 214 |
|
| 215 |
if (!bProgressVisible && duration.count() > 1500 && m_dlgProgress) |
| 216 |
{ // tag loading takes more then 1.5 secs, show a progress dialog |
| 217 |
CURL url(items.GetPath()); |
| 218 |
|
| 219 |
m_dlgProgress->SetHeading(CVariant{189}); |
| 220 |
m_dlgProgress->SetLine(0, CVariant{505}); |
| 221 |
m_dlgProgress->SetLine(1, CVariant{""}); |
| 222 |
m_dlgProgress->SetLine(2, CVariant{url.GetWithoutUserDetails()}); |
| 223 |
m_dlgProgress->Open(); |
| 224 |
m_dlgProgress->ShowProgressBar(true); |
| 225 |
bProgressVisible = true; |
| 226 |
} |
| 227 |
|
| 228 |
if (bProgressVisible && m_dlgProgress) |
| 229 |
{ // keep GUI alive |
| 230 |
m_dlgProgress->Progress(); |
| 231 |
} |
| 232 |
} // if (bShowProgress) |
| 233 |
KODI::TIME::Sleep(1ms); |
| 234 |
} // while (loader.IsLoading()) |
| 235 |
|
| 236 |
if (bProgressVisible && m_dlgProgress) |
| 237 |
m_dlgProgress->Close(); |
| 238 |
} |
| 239 |
|
| 240 |
bool CGUIWindowPictures::Update(const std::string &strDirectory, bool updateFilterPath /* = true */) |
| 241 |
{ |
| 242 |
if (m_thumbLoader.IsLoading()) |
| 243 |
m_thumbLoader.StopThread(); |
| 244 |
|
| 245 |
if (!CGUIMediaWindow::Update(strDirectory, updateFilterPath)) |
| 246 |
return false; |
| 247 |
|
| 248 |
m_vecItems->SetArt("thumb", ""); |
| 249 |
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_PICTURES_GENERATETHUMBS)) |
| 250 |
m_thumbLoader.Load(*m_vecItems); |
| 251 |
|
| 252 |
CPictureThumbLoader thumbLoader; |
| 253 |
std::string thumb = thumbLoader.GetCachedImage(*m_vecItems, "thumb"); |
| 254 |
m_vecItems->SetArt("thumb", thumb); |
| 255 |
|
| 256 |
return true; |
| 257 |
} |
| 258 |
|
| 259 |
bool CGUIWindowPictures::OnClick(int iItem, const std::string &player) |
| 260 |
{ |
| 261 |
if ( iItem < 0 || iItem >= m_vecItems->Size() ) return true; |
| 262 |
CFileItemPtr pItem = m_vecItems->Get(iItem); |
| 263 |
|
| 264 |
if (pItem->IsCBZ() || pItem->IsCBR()) |
| 265 |
{ |
| 266 |
CURL pathToUrl; |
| 267 |
if (pItem->IsCBZ()) |
| 268 |
pathToUrl = URIUtils::CreateArchivePath("zip", pItem->GetURL(), ""); |
| 269 |
else |
| 270 |
pathToUrl = URIUtils::CreateArchivePath("rar", pItem->GetURL(), ""); |
| 271 |
|
| 272 |
OnShowPictureRecursive(pathToUrl.Get()); |
| 273 |
return true; |
| 274 |
} |
| 275 |
else if (CGUIMediaWindow::OnClick(iItem, player)) |
| 276 |
return true; |
| 277 |
|
| 278 |
return false; |
| 279 |
} |
| 280 |
|
| 281 |
bool CGUIWindowPictures::GetDirectory(const std::string &strDirectory, CFileItemList& items) |
| 282 |
{ |
| 283 |
if (!CGUIMediaWindow::GetDirectory(strDirectory, items)) |
| 284 |
return false; |
| 285 |
|
| 286 |
std::string label; |
| 287 |
if (items.GetLabel().empty() && m_rootDir.IsSource(items.GetPath(), CMediaSourceSettings::GetInstance().GetSources("pictures"), &label)) |
| 288 |
items.SetLabel(label); |
| 289 |
|
| 290 |
if (items.GetContent().empty() && !items.IsVirtualDirectoryRoot() && !items.IsPlugin()) |
| 291 |
items.SetContent("images"); |
| 292 |
return true; |
| 293 |
} |
| 294 |
|
| 295 |
bool CGUIWindowPictures::OnPlayMedia(int iItem, const std::string &player) |
| 296 |
{ |
| 297 |
if (m_vecItems->Get(iItem)->IsVideo()) |
| 298 |
return CGUIMediaWindow::OnPlayMedia(iItem); |
| 299 |
|
| 300 |
return ShowPicture(iItem, false); |
| 301 |
} |
| 302 |
|
| 303 |
bool CGUIWindowPictures::ShowPicture(int iItem, bool startSlideShow) |
| 304 |
{ |
| 305 |
if ( iItem < 0 || iItem >= m_vecItems->Size() ) return false; |
| 306 |
CFileItemPtr pItem = m_vecItems->Get(iItem); |
| 307 |
std::string strPicture = pItem->GetPath(); |
| 308 |
|
| 309 |
#ifdef HAS_OPTICAL_DRIVE |
| 310 |
if (pItem->IsDVD()) |
| 311 |
return MEDIA_DETECT::CAutorun::PlayDiscAskResume(m_vecItems->Get(iItem)->GetPath()); |
| 312 |
#endif |
| 313 |
|
| 314 |
if (pItem->m_bIsShareOrDrive) |
| 315 |
return false; |
| 316 |
|
| 317 |
//! @todo this should be reactive, based on a given event app player should stop the playback |
| 318 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 319 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 320 |
if (appPlayer->IsPlayingVideo()) |
| 321 |
g_application.StopPlaying(); |
| 322 |
|
| 323 |
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator(); |
| 324 |
slideShow.Reset(); |
| 325 |
bool bShowVideos = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_PICTURES_SHOWVIDEOS); |
| 326 |
for (const auto& pItem : *m_vecItems) |
| 327 |
{ |
| 328 |
if (!pItem->m_bIsFolder && |
| 329 |
!(URIUtils::IsRAR(pItem->GetPath()) || URIUtils::IsZIP(pItem->GetPath())) && |
| 330 |
(pItem->IsPicture() || (bShowVideos && pItem->IsVideo()))) |
| 331 |
{ |
| 332 |
slideShow.Add(pItem.get()); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
if (slideShow.NumSlides() == 0) |
| 337 |
return false; |
| 338 |
|
| 339 |
slideShow.Select(strPicture); |
| 340 |
|
| 341 |
if (startSlideShow) |
| 342 |
slideShow.StartSlideShow(); |
| 343 |
else |
| 344 |
{ |
| 345 |
slideShow.PlayPicture(); |
| 346 |
} |
| 347 |
|
| 348 |
//! @todo this should trigger some event that should led the window manager to activate another window |
| 349 |
// look into using OnPlay announce! |
| 350 |
m_slideShowStarted = true; |
| 351 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SLIDESHOW); |
| 352 |
|
| 353 |
return true; |
| 354 |
} |
| 355 |
|
| 356 |
void CGUIWindowPictures::OnShowPictureRecursive(const std::string& strPath) |
| 357 |
{ |
| 358 |
// stop any video |
| 359 |
//! @todo this should be reactive, based on a given event app player should stop the playback |
| 360 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 361 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 362 |
if (appPlayer->IsPlayingVideo()) |
| 363 |
g_application.StopPlaying(); |
| 364 |
|
| 365 |
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator(); |
| 366 |
SortDescription sorting = m_guiState->GetSortMethod(); |
| 367 |
slideShow.AddFromPath(strPath, true, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes); |
| 368 |
//! @todo window manager should react to a given event and start the window itself! |
| 369 |
if (slideShow.NumSlides()) |
| 370 |
{ |
| 371 |
m_slideShowStarted = true; |
| 372 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SLIDESHOW); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
void CGUIWindowPictures::OnSlideShowRecursive(const std::string &strPicture) |
| 377 |
{ |
| 378 |
|
| 379 |
std::string strExtensions; |
| 380 |
CFileItemList items; |
| 381 |
CGUIViewState* viewState=CGUIViewState::GetViewState(GetID(), items); |
| 382 |
if (viewState) |
| 383 |
{ |
| 384 |
strExtensions = viewState->GetExtensions(); |
| 385 |
delete viewState; |
| 386 |
} |
| 387 |
m_slideShowStarted = true; |
| 388 |
|
| 389 |
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator(); |
| 390 |
SortDescription sorting = m_guiState->GetSortMethod(); |
| 391 |
slideShow.RunSlideShow(strPicture, true, |
| 392 |
CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( |
| 393 |
CSettings::SETTING_SLIDESHOW_SHUFFLE), |
| 394 |
false, "", true, sorting.sortBy, sorting.sortOrder, |
| 395 |
sorting.sortAttributes, strExtensions); |
| 396 |
} |
| 397 |
|
| 398 |
void CGUIWindowPictures::OnSlideShowRecursive() |
| 399 |
{ |
| 400 |
OnSlideShowRecursive(m_vecItems->GetPath()); |
| 401 |
} |
| 402 |
|
| 403 |
void CGUIWindowPictures::OnSlideShow() |
| 404 |
{ |
| 405 |
OnSlideShow(m_vecItems->GetPath()); |
| 406 |
} |
| 407 |
|
| 408 |
void CGUIWindowPictures::OnSlideShow(const std::string &strPicture) |
| 409 |
{ |
| 410 |
std::string strExtensions; |
| 411 |
CFileItemList items; |
| 412 |
CGUIViewState* viewState = CGUIViewState::GetViewState(GetID(), items); |
| 413 |
if (viewState) |
| 414 |
{ |
| 415 |
strExtensions = viewState->GetExtensions(); |
| 416 |
delete viewState; |
| 417 |
} |
| 418 |
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator(); |
| 419 |
m_slideShowStarted = true; |
| 420 |
SortDescription sorting = m_guiState->GetSortMethod(); |
| 421 |
slideShow.RunSlideShow(strPicture, false, false, false, "", true, sorting.sortBy, |
| 422 |
sorting.sortOrder, sorting.sortAttributes, strExtensions); |
| 423 |
} |
| 424 |
|
| 425 |
void CGUIWindowPictures::OnRegenerateThumbs() |
| 426 |
{ |
| 427 |
if (m_thumbLoader.IsLoading()) return; |
| 428 |
m_thumbLoader.SetRegenerateThumbs(true); |
| 429 |
m_thumbLoader.Load(*m_vecItems); |
| 430 |
} |
| 431 |
|
| 432 |
void CGUIWindowPictures::GetContextButtons(int itemNumber, CContextButtons &buttons) |
| 433 |
{ |
| 434 |
CFileItemPtr item; |
| 435 |
if (itemNumber >= 0 && itemNumber < m_vecItems->Size()) |
| 436 |
item = m_vecItems->Get(itemNumber); |
| 437 |
|
| 438 |
if (item) |
| 439 |
{ |
| 440 |
if ( m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://pictures/" ) |
| 441 |
{ |
| 442 |
CGUIDialogContextMenu::GetContextButtons("pictures", item, buttons); |
| 443 |
} |
| 444 |
else |
| 445 |
{ |
| 446 |
if (item) |
| 447 |
{ |
| 448 |
if (!(item->m_bIsFolder || item->IsZIP() || item->IsRAR() || item->IsCBZ() || item->IsCBR() || item->IsScript())) |
| 449 |
{ |
| 450 |
if (item->IsPicture()) |
| 451 |
buttons.Add(CONTEXT_BUTTON_INFO, 13406); // picture info |
| 452 |
buttons.Add(CONTEXT_BUTTON_VIEW_SLIDESHOW, item->m_bIsFolder ? 13317 : 13422); // View Slideshow |
| 453 |
} |
| 454 |
if (item->m_bIsFolder) |
| 455 |
buttons.Add(CONTEXT_BUTTON_RECURSIVE_SLIDESHOW, 13318); // Recursive Slideshow |
| 456 |
|
| 457 |
if (!m_thumbLoader.IsLoading()) |
| 458 |
buttons.Add(CONTEXT_BUTTON_REFRESH_THUMBS, 13315); // Create Thumbnails |
| 459 |
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_ALLOWFILEDELETION) && !item->IsReadOnly()) |
| 460 |
{ |
| 461 |
buttons.Add(CONTEXT_BUTTON_DELETE, 117); |
| 462 |
buttons.Add(CONTEXT_BUTTON_RENAME, 118); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
if (!item->IsPlugin() && !item->IsScript() && !m_vecItems->IsPlugin()) |
| 467 |
buttons.Add(CONTEXT_BUTTON_SWITCH_MEDIA, 523); |
| 468 |
} |
| 469 |
} |
| 470 |
CGUIMediaWindow::GetContextButtons(itemNumber, buttons); |
| 471 |
} |
| 472 |
|
| 473 |
bool CGUIWindowPictures::OnContextButton(int itemNumber, CONTEXT_BUTTON button) |
| 474 |
{ |
| 475 |
CFileItemPtr item = (itemNumber >= 0 && itemNumber < m_vecItems->Size()) ? m_vecItems->Get(itemNumber) : CFileItemPtr(); |
| 476 |
if (CGUIDialogContextMenu::OnContextButton("pictures", item, button)) |
| 477 |
{ |
| 478 |
Update(""); |
| 479 |
return true; |
| 480 |
} |
| 481 |
switch (button) |
| 482 |
{ |
| 483 |
case CONTEXT_BUTTON_VIEW_SLIDESHOW: |
| 484 |
if (item && item->m_bIsFolder) |
| 485 |
OnSlideShow(item->GetPath()); |
| 486 |
else |
| 487 |
ShowPicture(itemNumber, true); |
| 488 |
return true; |
| 489 |
case CONTEXT_BUTTON_RECURSIVE_SLIDESHOW: |
| 490 |
if (item) |
| 491 |
OnSlideShowRecursive(item->GetPath()); |
| 492 |
return true; |
| 493 |
case CONTEXT_BUTTON_INFO: |
| 494 |
OnItemInfo(itemNumber); |
| 495 |
return true; |
| 496 |
case CONTEXT_BUTTON_REFRESH_THUMBS: |
| 497 |
OnRegenerateThumbs(); |
| 498 |
return true; |
| 499 |
case CONTEXT_BUTTON_DELETE: |
| 500 |
OnDeleteItem(itemNumber); |
| 501 |
return true; |
| 502 |
case CONTEXT_BUTTON_RENAME: |
| 503 |
OnRenameItem(itemNumber); |
| 504 |
return true; |
| 505 |
case CONTEXT_BUTTON_SWITCH_MEDIA: |
| 506 |
CGUIDialogContextMenu::SwitchMedia("pictures", m_vecItems->GetPath()); |
| 507 |
return true; |
| 508 |
default: |
| 509 |
break; |
| 510 |
} |
| 511 |
return CGUIMediaWindow::OnContextButton(itemNumber, button); |
| 512 |
} |
| 513 |
|
| 514 |
bool CGUIWindowPictures::OnAddMediaSource() |
| 515 |
{ |
| 516 |
return CGUIDialogMediaSource::ShowAndAddMediaSource("pictures"); |
| 517 |
} |
| 518 |
|
| 519 |
void CGUIWindowPictures::OnItemLoaded(CFileItem *pItem) |
| 520 |
{ |
| 521 |
CPictureThumbLoader::ProcessFoldersAndArchives(pItem); |
| 522 |
} |
| 523 |
|
| 524 |
void CGUIWindowPictures::LoadPlayList(const std::string& strPlayList) |
| 525 |
{ |
| 526 |
CLog::Log(LOGDEBUG, |
| 527 |
"CGUIWindowPictures::LoadPlayList()... converting playlist into slideshow: {}", |
| 528 |
strPlayList); |
| 529 |
std::unique_ptr<PLAYLIST::CPlayList> pPlayList(PLAYLIST::CPlayListFactory::Create(strPlayList)); |
| 530 |
if (nullptr != pPlayList) |
| 531 |
{ |
| 532 |
if (!pPlayList->Load(strPlayList)) |
| 533 |
{ |
| 534 |
HELPERS::ShowOKDialogText(CVariant{6}, CVariant{477}); |
| 535 |
return ; //hmmm unable to load playlist? |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
PLAYLIST::CPlayList playlist = *pPlayList; |
| 540 |
if (playlist.size() > 0) |
| 541 |
{ |
| 542 |
//! @todo this should be reactive, based on a given event app player should stop the playback |
| 543 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 544 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 545 |
if (appPlayer->IsPlayingVideo()) |
| 546 |
g_application.StopPlaying(); |
| 547 |
|
| 548 |
CSlideShowDelegator& slideShow = CServiceBroker::GetSlideShowDelegator(); |
| 549 |
// convert playlist items into slideshow items |
| 550 |
slideShow.Reset(); |
| 551 |
for (int i = 0; i < playlist.size(); ++i) |
| 552 |
{ |
| 553 |
CFileItemPtr pItem = playlist[i]; |
| 554 |
//CLog::Log(LOGDEBUG,"-- playlist item: {}", pItem->GetPath()); |
| 555 |
if (pItem->IsPicture() && !(pItem->IsZIP() || pItem->IsRAR() || pItem->IsCBZ() || pItem->IsCBR())) |
| 556 |
{ |
| 557 |
slideShow.Add(pItem.get()); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
// start slideshow if there are items |
| 562 |
slideShow.StartSlideShow(); |
| 563 |
//! @todo this should be reactive based on a triggered event the window manager is the only component |
| 564 |
// that should be responsible to activate the slideshow window |
| 565 |
if (slideShow.NumSlides()) |
| 566 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SLIDESHOW); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
void CGUIWindowPictures::OnItemInfo(int itemNumber) |
| 571 |
{ |
| 572 |
CFileItemPtr item = m_vecItems->Get(itemNumber); |
| 573 |
if (!item) |
| 574 |
return; |
| 575 |
if (!m_vecItems->IsPlugin() && (item->IsPlugin() || item->IsScript())) |
| 576 |
{ |
| 577 |
CGUIDialogAddonInfo::ShowForItem(item); |
| 578 |
return; |
| 579 |
} |
| 580 |
if (item->m_bIsFolder || item->IsZIP() || item->IsRAR() || item->IsCBZ() || item->IsCBR() || !item->IsPicture()) |
| 581 |
return; |
| 582 |
CGUIDialogPictureInfo *pictureInfo = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPictureInfo>(WINDOW_DIALOG_PICTURE_INFO); |
| 583 |
if (pictureInfo) |
| 584 |
{ |
| 585 |
pictureInfo->SetPicture(item.get()); |
| 586 |
pictureInfo->Open(); |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
std::string CGUIWindowPictures::GetStartFolder(const std::string &dir) |
| 591 |
{ |
| 592 |
if (StringUtils::EqualsNoCase(dir, "plugins") || |
| 593 |
StringUtils::EqualsNoCase(dir, "addons")) |
| 594 |
return "addons://sources/image/"; |
| 595 |
|
| 596 |
SetupShares(); |
| 597 |
VECSOURCES shares; |
| 598 |
m_rootDir.GetSources(shares); |
| 599 |
bool bIsSourceName = false; |
| 600 |
int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); |
| 601 |
if (iIndex > -1) |
| 602 |
{ |
| 603 |
if (iIndex < static_cast<int>(shares.size()) && shares[iIndex].m_iHasLock == LOCK_STATE_LOCKED) |
| 604 |
{ |
| 605 |
CFileItem item(shares[iIndex]); |
| 606 |
if (!g_passwordManager.IsItemUnlocked(&item,"pictures")) |
| 607 |
return ""; |
| 608 |
} |
| 609 |
if (bIsSourceName) |
| 610 |
return shares[iIndex].strPath; |
| 611 |
return dir; |
| 612 |
} |
| 613 |
return CGUIMediaWindow::GetStartFolder(dir); |
| 614 |
} |