Debian Codegraph @

xbmc/pictures/GUIWindowSlideShow.cpp

raw
1 /*
2 * Copyright (C) 2005-2018 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 "GUIWindowSlideShow.h"
10
11 #include "FileItem.h"
12 #include "GUIDialogPictureInfo.h"
13 #include "GUIInfoManager.h"
14 #include "GUIUserMessages.h"
15 #include "ServiceBroker.h"
16 #include "TextureDatabase.h"
17 #include "URL.h"
18 #include "application/Application.h"
19 #include "application/ApplicationComponents.h"
20 #include "application/ApplicationPlayer.h"
21 #include "application/ApplicationPowerHandling.h"
22 #include "filesystem/Directory.h"
23 #include "guilib/GUIComponent.h"
24 #include "guilib/GUILabelControl.h"
25 #include "guilib/GUIWindowManager.h"
26 #include "guilib/LocalizeStrings.h"
27 #include "guilib/Texture.h"
28 #include "input/actions/Action.h"
29 #include "input/actions/ActionIDs.h"
30 #include "input/mouse/MouseEvent.h"
31 #include "interfaces/AnnouncementManager.h"
32 #include "pictures/GUIViewStatePictures.h"
33 #include "pictures/PictureThumbLoader.h"
34 #include "pictures/SlideShowDelegator.h"
35 #include "playlists/PlayListTypes.h"
36 #include "rendering/RenderSystem.h"
37 #include "settings/DisplaySettings.h"
38 #include "settings/Settings.h"
39 #include "settings/SettingsComponent.h"
40 #include "utils/Random.h"
41 #include "utils/URIUtils.h"
42 #include "utils/Variant.h"
43 #include "utils/XTimeUtils.h"
44 #include "utils/log.h"
45
46 #include <memory>
47 #include <random>
48
49 using namespace KODI;
50 using namespace MESSAGING;
51 using namespace XFILE;
52 using namespace std::chrono_literals;
53
54 #define MAX_ZOOM_FACTOR 10
55 #define MAX_PICTURE_SIZE 2048*2048
56
57 #define IMMEDIATE_TRANSITION_TIME 1
58
59 #define PICTURE_MOVE_AMOUNT 0.02f
60 #define PICTURE_MOVE_AMOUNT_ANALOG 0.01f
61 #define PICTURE_MOVE_AMOUNT_TOUCH 0.002f
62 #define PICTURE_VIEW_BOX_COLOR 0xffffff00 // YELLOW
63 #define PICTURE_VIEW_BOX_BACKGROUND 0xff000000 // BLACK
64
65 #define ROTATION_SNAP_RANGE 10.0f
66
67 #define LABEL_ROW1 10
68 #define CONTROL_PAUSE 13
69
70 static float zoomamount[10] = { 1.0f, 1.2f, 1.5f, 2.0f, 2.8f, 4.0f, 6.0f, 9.0f, 13.5f, 20.0f };
71
72 CBackgroundPicLoader::CBackgroundPicLoader() : CThread("BgPicLoader")
73 {
74 }
75
76 CBackgroundPicLoader::~CBackgroundPicLoader()
77 {
78 StopThread();
79 }
80
81 void CBackgroundPicLoader::Create(CGUIWindowSlideShow *pCallback)
82 {
83 m_pCallback = pCallback;
84 m_isLoading = false;
85 CThread::Create(false);
86 }
87
88 void CBackgroundPicLoader::Process()
89 {
90 auto totalTime = std::chrono::milliseconds(0);
91 unsigned int count = 0;
92 while (!m_bStop)
93 { // loop around forever, waiting for the app to call LoadPic
94 if (AbortableWait(m_loadPic, 10ms) == WAIT_SIGNALED)
95 {
96 if (m_pCallback)
97 {
98 auto start = std::chrono::steady_clock::now();
99 std::unique_ptr<CTexture> texture =
100 CTexture::LoadFromFile(m_strFileName, m_maxWidth, m_maxHeight);
101
102 auto end = std::chrono::steady_clock::now();
103 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
104
105 totalTime += duration;
106 count++;
107 // tell our parent
108 bool bFullSize = false;
109 if (texture)
110 {
111 bFullSize = ((int)texture->GetWidth() < m_maxWidth) && ((int)texture->GetHeight() < m_maxHeight);
112 if (!bFullSize)
113 {
114 int iSize = texture->GetWidth() * texture->GetHeight() - MAX_PICTURE_SIZE;
115 if ((iSize + (int)texture->GetWidth() > 0) || (iSize + (int)texture->GetHeight() > 0))
116 bFullSize = true;
117 if (!bFullSize && texture->GetWidth() == CServiceBroker::GetRenderSystem()->GetMaxTextureSize())
118 bFullSize = true;
119 if (!bFullSize && texture->GetHeight() == CServiceBroker::GetRenderSystem()->GetMaxTextureSize())
120 bFullSize = true;
121 }
122 }
123 m_pCallback->OnLoadPic(m_iPic, m_iSlideNumber, m_strFileName, std::move(texture),
124 bFullSize);
125 m_isLoading = false;
126 }
127 }
128 }
129 if (count > 0)
130 CLog::Log(LOGDEBUG, "Time for loading {} images: {} ms, average {} ms", count,
131 totalTime.count(), totalTime.count() / count);
132 }
133
134 void CBackgroundPicLoader::LoadPic(int iPic, int iSlideNumber, const std::string &strFileName, const int maxWidth, const int maxHeight)
135 {
136 m_iPic = iPic;
137 m_iSlideNumber = iSlideNumber;
138 m_strFileName = strFileName;
139 m_maxWidth = maxWidth;
140 m_maxHeight = maxHeight;
141 m_isLoading = true;
142 m_loadPic.Set();
143 }
144
145 CGUIWindowSlideShow::CGUIWindowSlideShow(void)
146 : CGUIDialog(WINDOW_SLIDESHOW, "SlideShow.xml")
147 {
148 m_Resolution = RES_INVALID;
149 m_loadType = KEEP_IN_MEMORY;
150 m_bLoadNextPic = false;
151 CServiceBroker::GetSlideShowDelegator().SetDelegate(this);
152 Reset();
153 }
154
155 CGUIWindowSlideShow::~CGUIWindowSlideShow()
156 {
157 CServiceBroker::GetSlideShowDelegator().ResetDelegate();
158 }
159
160 void CGUIWindowSlideShow::AnnouncePlayerPlay(const CFileItemPtr& item)
161 {
162 CVariant param;
163 param["player"]["speed"] = m_bSlideShow && !m_bPause ? 1 : 0;
164 param["player"]["playerid"] = PLAYLIST::TYPE_PICTURE;
165 CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Player, "OnPlay", item, param);
166 }
167
168 void CGUIWindowSlideShow::AnnouncePlayerPause(const CFileItemPtr& item)
169 {
170 CVariant param;
171 param["player"]["speed"] = 0;
172 param["player"]["playerid"] = PLAYLIST::TYPE_PICTURE;
173 CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Player, "OnPause", item, param);
174 }
175
176 void CGUIWindowSlideShow::AnnouncePlayerStop(const CFileItemPtr& item)
177 {
178 CVariant param;
179 param["player"]["playerid"] = PLAYLIST::TYPE_PICTURE;
180 param["end"] = true;
181 CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Player, "OnStop", item, param);
182 }
183
184 void CGUIWindowSlideShow::AnnouncePlaylistClear()
185 {
186 CVariant data;
187 data["playlistid"] = PLAYLIST::TYPE_PICTURE;
188 CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Playlist, "OnClear", data);
189 }
190
191 void CGUIWindowSlideShow::AnnouncePlaylistAdd(const CFileItemPtr& item, int pos)
192 {
193 CVariant data;
194 data["playlistid"] = PLAYLIST::TYPE_PICTURE;
195 data["position"] = pos;
196 CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Playlist, "OnAdd", item, data);
197 }
198
199 void CGUIWindowSlideShow::AnnouncePropertyChanged(const std::string &strProperty, const CVariant &value)
200 {
201 if (strProperty.empty() || value.isNull())
202 return;
203
204 CVariant data;
205 data["player"]["playerid"] = PLAYLIST::TYPE_PICTURE;
206 data["property"][strProperty] = value;
207 CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::Player, "OnPropertyChanged",
208 data);
209 }
210
211 bool CGUIWindowSlideShow::IsPlaying() const
212 {
213 return m_Image[m_iCurrentPic]->IsLoaded();
214 }
215
216 void CGUIWindowSlideShow::Reset()
217 {
218 m_bSlideShow = false;
219 m_bShuffled = false;
220 m_bPause = false;
221 m_bPlayingVideo = false;
222 m_bErrorMessage = false;
223
224 if (m_Image[0])
225 {
226 m_Image[0]->UnLoad();
227 m_Image[0]->Close();
228 }
229
230 m_Image[0] = CSlideShowPic::CreateSlideShowPicture();
231
232 if (m_Image[1])
233 {
234 m_Image[1]->UnLoad();
235 m_Image[1]->Close();
236 }
237
238 m_Image[1] = CSlideShowPic::CreateSlideShowPicture();
239
240 m_fRotate = 0.0f;
241 m_fInitialRotate = 0.0f;
242 m_iZoomFactor = 1;
243 m_fZoom = 1.0f;
244 m_fInitialZoom = 0.0f;
245 m_iCurrentSlide = 0;
246 m_iNextSlide = 1;
247 m_iCurrentPic = 0;
248 m_iDirection = 1;
249 m_iLastFailedNextSlide = -1;
250 m_slides.clear();
251 AnnouncePlaylistClear();
252 m_Resolution = CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution();
253 }
254
255 void CGUIWindowSlideShow::OnDeinitWindow(int nextWindowID)
256 {
257 if (m_Resolution != CDisplaySettings::GetInstance().GetCurrentResolution())
258 {
259 //FIXME: Use GUI resolution for now
260 //CServiceBroker::GetWinSystem()->GetGfxContext().SetVideoResolution(CDisplaySettings::GetInstance().GetCurrentResolution(), true);
261 }
262
263 if (nextWindowID != WINDOW_FULLSCREEN_VIDEO &&
264 nextWindowID != WINDOW_FULLSCREEN_GAME)
265 {
266 // wait for any outstanding picture loads
267 if (m_pBackgroundLoader)
268 {
269 // sleep until the loader finishes loading the current pic
270 CLog::Log(LOGDEBUG,"Waiting for BackgroundLoader thread to close");
271 while (m_pBackgroundLoader->IsLoading())
272 KODI::TIME::Sleep(10ms);
273 // stop the thread
274 CLog::Log(LOGDEBUG,"Stopping BackgroundLoader thread");
275 m_pBackgroundLoader->StopThread();
276 m_pBackgroundLoader.reset();
277 }
278 // and close the images.
279 m_Image[0]->Close();
280 m_Image[1]->Close();
281 }
282 CServiceBroker::GetGUI()->GetInfoManager().GetInfoProviders().GetPicturesInfoProvider().SetCurrentSlide(nullptr);
283 m_bSlideShow = false;
284
285 CGUIDialog::OnDeinitWindow(nextWindowID);
286 }
287
288 void CGUIWindowSlideShow::Add(const CFileItem *picture)
289 {
290 CFileItemPtr item(new CFileItem(*picture));
291 if (!item->HasVideoInfoTag() && !item->HasPictureInfoTag())
292 {
293 // item without tag; get mimetype then we can tell whether it's video item
294 item->FillInMimeType();
295
296 if (!item->IsVideo())
297 // then it is a picture and force tag generation
298 item->GetPictureInfoTag();
299 }
300 AnnouncePlaylistAdd(item, m_slides.size());
301
302 m_slides.emplace_back(std::move(item));
303 }
304
305 void CGUIWindowSlideShow::ShowNext()
306 {
307 if (m_slides.size() == 1)
308 return;
309
310 m_iDirection = 1;
311 m_iNextSlide = GetNextSlide();
312 m_iZoomFactor = 1;
313 m_fZoom = 1.0f;
314 m_fRotate = 0.0f;
315 m_bLoadNextPic = true;
316 }
317
318 void CGUIWindowSlideShow::ShowPrevious()
319 {
320 if (m_slides.size() == 1)
321 return;
322
323 m_iDirection = -1;
324 m_iNextSlide = GetNextSlide();
325 m_iZoomFactor = 1;
326 m_fZoom = 1.0f;
327 m_fRotate = 0.0f;
328 m_bLoadNextPic = true;
329 }
330
331 void CGUIWindowSlideShow::Select(const std::string& strPicture)
332 {
333 for (size_t i = 0; i < m_slides.size(); ++i)
334 {
335 const CFileItemPtr item = m_slides.at(i);
336 if (item->GetPath() == strPicture)
337 {
338 m_iDirection = 1;
339 if (!m_Image[m_iCurrentPic]->IsLoaded() &&
340 (!m_pBackgroundLoader || !m_pBackgroundLoader->IsLoading()))
341 {
342 // will trigger loading current slide when next Process call.
343 m_iCurrentSlide = i;
344 m_iNextSlide = GetNextSlide();
345 }
346 else
347 {
348 m_iNextSlide = i;
349 m_bLoadNextPic = true;
350 }
351 return ;
352 }
353 }
354 }
355
356 void CGUIWindowSlideShow::GetSlideShowContents(CFileItemList &list)
357 {
358 for (size_t index = 0; index < m_slides.size(); index++)
359 list.Add(std::make_shared<CFileItem>(*m_slides.at(index)));
360 }
361
362 std::shared_ptr<const CFileItem> CGUIWindowSlideShow::GetCurrentSlide()
363 {
364 if (m_iCurrentSlide >= 0 && m_iCurrentSlide < static_cast<int>(m_slides.size()))
365 return m_slides.at(m_iCurrentSlide);
366 return CFileItemPtr();
367 }
368
369 bool CGUIWindowSlideShow::InSlideShow() const
370 {
371 return m_bSlideShow;
372 }
373
374 void CGUIWindowSlideShow::StartSlideShow()
375 {
376 m_bSlideShow = true;
377 m_iDirection = 1;
378 if (m_slides.size())
379 AnnouncePlayerPlay(m_slides.at(m_iCurrentSlide));
380 }
381
382 void CGUIWindowSlideShow::SetDirection(int direction)
383 {
384 direction = direction >= 0 ? 1 : -1;
385 if (m_iDirection != direction)
386 {
387 m_iDirection = direction;
388 m_iNextSlide = GetNextSlide();
389 }
390 }
391
392 void CGUIWindowSlideShow::Process(unsigned int currentTime, CDirtyRegionList &regions)
393 {
394 const RESOLUTION_INFO res = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo();
395
396 // reset the screensaver if we're in a slideshow
397 // (unless we are the screensaver!)
398 auto& components = CServiceBroker::GetAppComponents();
399 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
400 if (m_bSlideShow && !m_bPause && !appPower->IsInScreenSaver())
401 appPower->ResetScreenSaver();
402 int iSlides = m_slides.size();
403 if (!iSlides)
404 return;
405
406 // if we haven't processed yet, we should mark the whole screen
407 if (!HasProcessed())
408 regions.emplace_back(CRect(
409 0.0f, 0.0f, static_cast<float>(CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth()),
410 static_cast<float>(CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight())));
411
412 if (m_iCurrentSlide < 0 || m_iCurrentSlide >= static_cast<int>(m_slides.size()))
413 m_iCurrentSlide = 0;
414 if (m_iNextSlide < 0 || m_iNextSlide >= static_cast<int>(m_slides.size()))
415 m_iNextSlide = GetNextSlide();
416
417 // Create our background loader if necessary
418 if (!m_pBackgroundLoader)
419 {
420 m_pBackgroundLoader = std::make_unique<CBackgroundPicLoader>();
421 m_pBackgroundLoader->Create(this);
422 }
423
424 bool bSlideShow = m_bSlideShow && !m_bPause && !m_bPlayingVideo;
425 if (bSlideShow && m_slides.at(m_iCurrentSlide)->HasProperty("unplayable"))
426 {
427 m_iNextSlide = GetNextSlide();
428 if (m_iCurrentSlide == m_iNextSlide)
429 return;
430 m_iCurrentSlide = m_iNextSlide;
431 m_iNextSlide = GetNextSlide();
432 }
433
434 if (m_bErrorMessage)
435 { // we have an error when loading either the current or next picture
436 // check to see if we have a picture loaded
437 CLog::Log(LOGDEBUG, "We have an error loading picture {}!", m_pBackgroundLoader->SlideNumber());
438 if (m_iCurrentSlide == m_pBackgroundLoader->SlideNumber())
439 {
440 if (m_Image[m_iCurrentPic]->IsLoaded())
441 {
442 // current image was already loaded, so we can ignore this error.
443 m_bErrorMessage = false;
444 }
445 else
446 {
447 CLog::Log(LOGERROR, "Error loading the current image {}: {}", m_iCurrentSlide,
448 m_slides.at(m_iCurrentSlide)->GetPath());
449 if (!m_slides.at(m_iCurrentPic)->IsVideo())
450 {
451 // try next if we are in slideshow
452 CLog::Log(LOGINFO, "set image {} unplayable", m_slides.at(m_iCurrentSlide)->GetPath());
453 m_slides.at(m_iCurrentSlide)->SetProperty("unplayable", true);
454 }
455 if (m_bLoadNextPic || (bSlideShow && !m_bPause && !m_slides.at(m_iCurrentPic)->IsVideo()))
456 {
457 // change to next item, wait loading.
458 m_iCurrentSlide = m_iNextSlide;
459 m_iNextSlide = GetNextSlide();
460 m_bErrorMessage = false;
461 }
462 // else just drop through - there's nothing we can do (error message will be displayed)
463 }
464 }
465 else if (m_iNextSlide == m_pBackgroundLoader->SlideNumber())
466 {
467 CLog::Log(LOGERROR, "Error loading the next image {}: {}", m_iNextSlide,
468 m_slides.at(m_iNextSlide)->GetPath());
469 // load next image failed, then skip to load next of next if next is not video.
470 if (!m_slides.at(m_iNextSlide)->IsVideo())
471 {
472 CLog::Log(LOGINFO, "set image {} unplayable", m_slides.at(m_iNextSlide)->GetPath());
473 m_slides.at(m_iNextSlide)->SetProperty("unplayable", true);
474 // change to next item, wait loading.
475 m_iNextSlide = GetNextSlide();
476 }
477 else
478 { // prevent reload the next pic and repeat fail.
479 m_iLastFailedNextSlide = m_iNextSlide;
480 }
481 m_bErrorMessage = false;
482 }
483 else
484 { // Non-current and non-next slide, just ignore error.
485 CLog::Log(LOGERROR, "Error loading the non-current non-next image {}/{}: {}", m_iNextSlide,
486 m_pBackgroundLoader->SlideNumber(), m_slides.at(m_iNextSlide)->GetPath());
487 m_bErrorMessage = false;
488 }
489 }
490
491 if (m_bErrorMessage)
492 { // hack, just mark it all
493 regions.emplace_back(CRect(
494 0.0f, 0.0f, static_cast<float>(CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth()),
495 static_cast<float>(CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight())));
496 return;
497 }
498
499 if (!m_Image[m_iCurrentPic]->IsLoaded() && !m_pBackgroundLoader->IsLoading())
500 { // load first image
501 CFileItemPtr item = m_slides.at(m_iCurrentSlide);
502 std::string picturePath = GetPicturePath(item.get());
503 if (!picturePath.empty())
504 {
505 if (item->IsVideo())
506 CLog::Log(LOGDEBUG, "Loading the thumb {} for current video {}: {}", picturePath,
507 m_iCurrentSlide, item->GetPath());
508 else
509 CLog::Log(LOGDEBUG, "Loading the current image {}: {}", m_iCurrentSlide, item->GetPath());
510
511 // load using the background loader
512 int maxWidth, maxHeight;
513
514 GetCheckedSize((float)res.iWidth * m_fZoom,
515 (float)res.iHeight * m_fZoom,
516 maxWidth, maxHeight);
517 m_pBackgroundLoader->LoadPic(m_iCurrentPic, m_iCurrentSlide, picturePath, maxWidth, maxHeight);
518 m_iLastFailedNextSlide = -1;
519 m_bLoadNextPic = false;
520 }
521 }
522
523 // check if we should discard an already loaded next slide
524 if (m_Image[1 - m_iCurrentPic]->IsLoaded() &&
525 m_Image[1 - m_iCurrentPic]->SlideNumber() != m_iNextSlide)
526 m_Image[1 - m_iCurrentPic]->Close();
527
528 if (m_iNextSlide != m_iCurrentSlide && m_Image[m_iCurrentPic]->IsLoaded() &&
529 !m_Image[1 - m_iCurrentPic]->IsLoaded() && !m_pBackgroundLoader->IsLoading() &&
530 m_iLastFailedNextSlide != m_iNextSlide)
531 { // load the next image
532 m_iLastFailedNextSlide = -1;
533 CFileItemPtr item = m_slides.at(m_iNextSlide);
534 std::string picturePath = GetPicturePath(item.get());
535 if (!picturePath.empty() && (!item->IsVideo() || !m_bSlideShow || m_bPause))
536 {
537 if (item->IsVideo())
538 CLog::Log(LOGDEBUG, "Loading the thumb {} for next video {}: {}", picturePath, m_iNextSlide,
539 item->GetPath());
540 else
541 CLog::Log(LOGDEBUG, "Loading the next image {}: {}", m_iNextSlide, item->GetPath());
542
543 int maxWidth, maxHeight;
544 GetCheckedSize((float)res.iWidth * m_fZoom,
545 (float)res.iHeight * m_fZoom,
546 maxWidth, maxHeight);
547 m_pBackgroundLoader->LoadPic(1 - m_iCurrentPic, m_iNextSlide, picturePath, maxWidth, maxHeight);
548 }
549 }
550
551 bool bPlayVideo = m_slides.at(m_iCurrentSlide)->IsVideo() && m_iVideoSlide != m_iCurrentSlide;
552 if (bPlayVideo)
553 bSlideShow = false;
554
555 // render the current image
556 if (m_Image[m_iCurrentPic]->IsLoaded())
557 {
558 m_Image[m_iCurrentPic]->SetInSlideshow(bSlideShow);
559 m_Image[m_iCurrentPic]->Pause(!bSlideShow);
560 m_Image[m_iCurrentPic]->Process(currentTime, regions);
561 }
562
563 // Check if we should be transitioning immediately
564 if (m_bLoadNextPic && m_Image[m_iCurrentPic]->IsLoaded())
565 {
566 CLog::Log(LOGDEBUG, "Starting immediate transition due to user wanting slide {}",
567 m_slides.at(m_iNextSlide)->GetPath());
568 if (m_Image[m_iCurrentPic]->StartTransition())
569 {
570 m_Image[m_iCurrentPic]->SetTransitionTime(1, IMMEDIATE_TRANSITION_TIME);
571 m_bLoadNextPic = false;
572 }
573 }
574
575 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
576
577 // render the next image
578 if (m_Image[m_iCurrentPic]->DrawNextImage())
579 {
580 if (m_bSlideShow && !m_bPause && m_slides.at(m_iNextSlide)->IsVideo())
581 {
582 // do not show thumb of video when playing slideshow
583 }
584 else if (m_Image[1 - m_iCurrentPic]->IsLoaded())
585 {
586 if (appPlayer->IsPlayingVideo())
587 appPlayer->ClosePlayer();
588 m_bPlayingVideo = false;
589 m_iVideoSlide = -1;
590
591 // first time render the next image, make sure using current display effect.
592 if (!m_Image[1 - m_iCurrentPic]->IsStarted())
593 {
594 CSlideShowPic::DISPLAY_EFFECT effect = GetDisplayEffect(m_iNextSlide);
595 if (m_Image[1 - m_iCurrentPic]->DisplayEffectNeedChange(effect))
596 m_Image[1 - m_iCurrentPic]->Reset(effect);
597 }
598 // set the appropriate transition time
599 m_Image[1 - m_iCurrentPic]->SetTransitionTime(0,
600 m_Image[m_iCurrentPic]->GetTransitionTime(1));
601 m_Image[1 - m_iCurrentPic]->Pause(!m_bSlideShow || m_bPause ||
602 m_slides.at(m_iNextSlide)->IsVideo());
603 m_Image[1 - m_iCurrentPic]->Process(currentTime, regions);
604 }
605 else // next pic isn't loaded. We should hang around if it is in progress
606 {
607 if (m_pBackgroundLoader->IsLoading())
608 {
609 // CLog::Log(LOGDEBUG, "Having to hold the current image ({}) while we load {}", m_vecSlides[m_iCurrentSlide], m_vecSlides[m_iNextSlide]);
610 m_Image[m_iCurrentPic]->Keep();
611 }
612 }
613 }
614
615 // check if we should swap images now
616 if (m_Image[m_iCurrentPic]->IsFinished() ||
617 (m_bLoadNextPic && !m_Image[m_iCurrentPic]->IsLoaded()))
618 {
619 m_bLoadNextPic = false;
620 if (m_Image[m_iCurrentPic]->IsFinished())
621 CLog::Log(LOGDEBUG, "Image {} is finished rendering, switching to {}",
622 m_slides.at(m_iCurrentSlide)->GetPath(), m_slides.at(m_iNextSlide)->GetPath());
623 else
624 // what if it's bg loading?
625 CLog::Log(LOGDEBUG, "Image {} is not loaded, switching to {}",
626 m_slides.at(m_iCurrentSlide)->GetPath(), m_slides.at(m_iNextSlide)->GetPath());
627
628 if (m_Image[m_iCurrentPic]->IsFinished() && m_iCurrentSlide == m_iNextSlide &&
629 m_Image[m_iCurrentPic]->SlideNumber() == m_iNextSlide)
630 m_Image[m_iCurrentPic]->Reset(GetDisplayEffect(m_iCurrentSlide));
631 else
632 {
633 if (m_Image[m_iCurrentPic]->IsLoaded())
634 m_Image[m_iCurrentPic]->Reset(GetDisplayEffect(m_iCurrentSlide));
635 else
636 m_Image[m_iCurrentPic]->Close();
637
638 if ((m_Image[1 - m_iCurrentPic]->IsLoaded() &&
639 m_Image[1 - m_iCurrentPic]->SlideNumber() == m_iNextSlide) ||
640 (m_pBackgroundLoader->IsLoading() && m_pBackgroundLoader->SlideNumber() == m_iNextSlide &&
641 m_pBackgroundLoader->Pic() == 1 - m_iCurrentPic))
642 {
643 m_iCurrentPic = 1 - m_iCurrentPic;
644 }
645 else
646 {
647 m_Image[1 - m_iCurrentPic]->Close();
648 m_iCurrentPic = 1 - m_iCurrentPic;
649 }
650 m_iCurrentSlide = m_iNextSlide;
651 m_iNextSlide = GetNextSlide();
652
653 bPlayVideo = m_slides.at(m_iCurrentSlide)->IsVideo() && m_iVideoSlide != m_iCurrentSlide;
654 }
655 AnnouncePlayerPlay(m_slides.at(m_iCurrentSlide));
656
657 m_iZoomFactor = 1;
658 m_fZoom = 1.0f;
659 m_fRotate = 0.0f;
660 }
661
662 if (bPlayVideo && !PlayVideo())
663 return;
664
665 if (m_Image[m_iCurrentPic]->IsLoaded())
666 CServiceBroker::GetGUI()->GetInfoManager().GetInfoProviders().GetPicturesInfoProvider().SetCurrentSlide(m_slides.at(m_iCurrentSlide).get());
667
668 RenderPause();
669 if (m_slides.at(m_iCurrentSlide)->IsVideo() && appPlayer && appPlayer->IsRenderingGuiLayer())
670 {
671 MarkDirtyRegion();
672 }
673 CGUIWindow::Process(currentTime, regions);
674 m_renderRegion.SetRect(0, 0, (float)CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth(), (float)CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight());
675 }
676
677 void CGUIWindowSlideShow::Render()
678 {
679 if (m_slides.empty())
680 return;
681
682 CGraphicContext& gfxCtx = CServiceBroker::GetWinSystem()->GetGfxContext();
683 gfxCtx.Clear(0xff000000);
684
685 if (m_slides.at(m_iCurrentSlide)->IsVideo())
686 {
687 gfxCtx.SetViewWindow(0, 0, m_coordsRes.iWidth, m_coordsRes.iHeight);
688 gfxCtx.SetRenderingResolution(gfxCtx.GetVideoResolution(), false);
689
690 auto& components = CServiceBroker::GetAppComponents();
691 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
692
693 if (appPlayer->IsRenderingVideoLayer())
694 {
695 const CRect old = gfxCtx.GetScissors();
696 CRect region = GetRenderRegion();
697 region.Intersect(old);
698 gfxCtx.SetScissors(region);
699 gfxCtx.Clear(0);
700 gfxCtx.SetScissors(old);
701 }
702 else if (appPlayer)
703 {
704 const ::UTILS::COLOR::Color alpha = gfxCtx.MergeAlpha(0xff000000) >> 24;
705 appPlayer->Render(false, alpha);
706 }
707
708 gfxCtx.SetRenderingResolution(m_coordsRes, m_needsScaling);
709 }
710 else
711 {
712 if (m_Image[m_iCurrentPic]->IsLoaded())
713 m_Image[m_iCurrentPic]->Render();
714
715 if (m_Image[m_iCurrentPic]->DrawNextImage() && m_Image[1 - m_iCurrentPic]->IsLoaded())
716 m_Image[1 - m_iCurrentPic]->Render();
717 }
718
719 RenderErrorMessage();
720 CGUIWindow::Render();
721 }
722
723 void CGUIWindowSlideShow::RenderEx()
724 {
725 if (m_slides.at(m_iCurrentSlide)->IsVideo())
726 {
727 auto& components = CServiceBroker::GetAppComponents();
728 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
729 appPlayer->Render(false, 255, false);
730 }
731
732 CGUIWindow::RenderEx();
733 }
734
735 int CGUIWindowSlideShow::GetNextSlide()
736 {
737 if (m_slides.size() <= 1)
738 return m_iCurrentSlide;
739 int step = m_iDirection >= 0 ? 1 : -1;
740 int nextSlide = (m_iCurrentSlide + step + m_slides.size()) % m_slides.size();
741 while (nextSlide != m_iCurrentSlide)
742 {
743 if (!m_slides.at(nextSlide)->HasProperty("unplayable"))
744 return nextSlide;
745 nextSlide = (nextSlide + step + m_slides.size()) % m_slides.size();
746 }
747 return m_iCurrentSlide;
748 }
749
750 EVENT_RESULT CGUIWindowSlideShow::OnMouseEvent(const CPoint& point, const MOUSE::CMouseEvent& event)
751 {
752 if (event.m_id == ACTION_GESTURE_NOTIFY)
753 {
754 int result = EVENT_RESULT_ROTATE | EVENT_RESULT_ZOOM;
755 if (m_iZoomFactor == 1 || !m_Image[m_iCurrentPic]->m_bCanMoveHorizontally)
756 result |= EVENT_RESULT_SWIPE;
757 else
758 result |= EVENT_RESULT_PAN_HORIZONTAL;
759
760 if (m_Image[m_iCurrentPic]->m_bCanMoveVertically)
761 result |= EVENT_RESULT_PAN_VERTICAL;
762
763 return (EVENT_RESULT)result;
764 }
765 else if (event.m_id == ACTION_GESTURE_BEGIN)
766 {
767 m_firstGesturePoint = point;
768 m_fInitialZoom = m_fZoom;
769 m_fInitialRotate = m_fRotate;
770 return EVENT_RESULT_HANDLED;
771 }
772 else if (event.m_id == ACTION_GESTURE_PAN)
773 {
774 // zoomed in - free move mode
775 if (m_iZoomFactor != 1 && (m_Image[m_iCurrentPic]->m_bCanMoveHorizontally ||
776 m_Image[m_iCurrentPic]->m_bCanMoveVertically))
777 {
778 Move(PICTURE_MOVE_AMOUNT_TOUCH / m_iZoomFactor * (m_firstGesturePoint.x - point.x), PICTURE_MOVE_AMOUNT_TOUCH / m_iZoomFactor * (m_firstGesturePoint.y - point.y));
779 m_firstGesturePoint = point;
780 }
781 return EVENT_RESULT_HANDLED;
782 }
783 else if (event.m_id == ACTION_GESTURE_SWIPE_LEFT || event.m_id == ACTION_GESTURE_SWIPE_RIGHT)
784 {
785 if (m_iZoomFactor == 1 || !m_Image[m_iCurrentPic]->m_bCanMoveHorizontally)
786 {
787 // on zoomlevel 1 just detect swipe left and right
788 if (event.m_id == ACTION_GESTURE_SWIPE_LEFT)
789 OnAction(CAction(ACTION_NEXT_PICTURE));
790 else
791 OnAction(CAction(ACTION_PREV_PICTURE));
792 }
793 }
794 else if (event.m_id == ACTION_GESTURE_END || event.m_id == ACTION_GESTURE_ABORT)
795 {
796 if (m_fRotate != 0.0f)
797 {
798 // "snap" to nearest of 0, 90, 180 and 270 if the
799 // difference in angle is +/-10 degrees
800 float reminder = fmodf(m_fRotate, 90.0f);
801 if (fabs(reminder) < ROTATION_SNAP_RANGE)
802 Rotate(-reminder);
803 else if (reminder > 90.0f - ROTATION_SNAP_RANGE)
804 Rotate(90.0f - reminder);
805 else if (-reminder > 90.0f - ROTATION_SNAP_RANGE)
806 Rotate(-90.0f - reminder);
807 }
808
809 m_fInitialZoom = 0.0f;
810 m_fInitialRotate = 0.0f;
811 return EVENT_RESULT_HANDLED;
812 }
813 else if (event.m_id == ACTION_GESTURE_ZOOM)
814 {
815 ZoomRelative(m_fInitialZoom * event.m_offsetX, true);
816 return EVENT_RESULT_HANDLED;
817 }
818 else if (event.m_id == ACTION_GESTURE_ROTATE)
819 {
820 Rotate(m_fInitialRotate + event.m_offsetX - m_fRotate, true);
821 return EVENT_RESULT_HANDLED;
822 }
823 return EVENT_RESULT_UNHANDLED;
824 }
825
826 bool CGUIWindowSlideShow::OnAction(const CAction &action)
827 {
828 switch (action.GetID())
829 {
830 case ACTION_SHOW_INFO:
831 {
832 CGUIDialogPictureInfo *pictureInfo = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPictureInfo>(WINDOW_DIALOG_PICTURE_INFO);
833 if (pictureInfo)
834 {
835 // no need to set the picture here, it's done in Render()
836 pictureInfo->Open();
837 }
838 }
839 break;
840 case ACTION_STOP:
841 {
842 if (m_slides.size())
843 AnnouncePlayerStop(m_slides.at(m_iCurrentSlide));
844 auto& components = CServiceBroker::GetAppComponents();
845 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
846 if (appPlayer->IsPlayingVideo())
847 appPlayer->ClosePlayer();
848 Close();
849 break;
850 }
851
852 case ACTION_NEXT_PICTURE:
853 ShowNext();
854 break;
855
856 case ACTION_PREV_PICTURE:
857 ShowPrevious();
858 break;
859
860 case ACTION_MOVE_RIGHT:
861 if (m_iZoomFactor == 1 || !m_Image[m_iCurrentPic]->m_bCanMoveHorizontally)
862 ShowNext();
863 else
864 Move(PICTURE_MOVE_AMOUNT, 0);
865 break;
866
867 case ACTION_MOVE_LEFT:
868 if (m_iZoomFactor == 1 || !m_Image[m_iCurrentPic]->m_bCanMoveHorizontally)
869 ShowPrevious();
870 else
871 Move( -PICTURE_MOVE_AMOUNT, 0);
872 break;
873
874 case ACTION_MOVE_DOWN:
875 Move(0, PICTURE_MOVE_AMOUNT);
876 break;
877
878 case ACTION_MOVE_UP:
879 Move(0, -PICTURE_MOVE_AMOUNT);
880 break;
881
882 case ACTION_PAUSE:
883 case ACTION_PLAYER_PLAY:
884 if (m_slides.size() == 0)
885 break;
886 if (m_slides.at(m_iCurrentSlide)->IsVideo())
887 {
888 if (!m_bPlayingVideo)
889 {
890 if (m_bSlideShow)
891 {
892 SetDirection(1);
893 m_bPause = false;
894 }
895 PlayVideo();
896 }
897 }
898 else if (!m_bSlideShow || m_bPause)
899 {
900 m_bSlideShow = true;
901 m_bPause = false;
902 SetDirection(1);
903 if (m_Image[m_iCurrentPic]->IsLoaded())
904 {
905 CSlideShowPic::DISPLAY_EFFECT effect = GetDisplayEffect(m_iCurrentSlide);
906 if (m_Image[m_iCurrentPic]->DisplayEffectNeedChange(effect))
907 m_Image[m_iCurrentPic]->Reset(effect);
908 }
909 AnnouncePlayerPlay(m_slides.at(m_iCurrentSlide));
910 }
911 else if (action.GetID() == ACTION_PAUSE)
912 {
913 m_bPause = true;
914 AnnouncePlayerPause(m_slides.at(m_iCurrentSlide));
915 }
916 break;
917
918 case ACTION_ZOOM_OUT:
919 Zoom(m_iZoomFactor - 1);
920 break;
921
922 case ACTION_ZOOM_IN:
923 Zoom(m_iZoomFactor + 1);
924 break;
925
926 case ACTION_GESTURE_SWIPE_UP:
927 case ACTION_GESTURE_SWIPE_DOWN:
928 if (m_iZoomFactor == 1 || !m_Image[m_iCurrentPic]->m_bCanMoveVertically)
929 {
930 bool swipeOnLeft = action.GetAmount() < CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth() / 2.0f;
931 bool swipeUp = action.GetID() == ACTION_GESTURE_SWIPE_UP;
932 if (swipeUp == swipeOnLeft)
933 Rotate(90.0f);
934 else
935 Rotate(-90.0f);
936 }
937 break;
938
939 case ACTION_ROTATE_PICTURE_CW:
940 Rotate(90.0f);
941 break;
942
943 case ACTION_ROTATE_PICTURE_CCW:
944 Rotate(-90.0f);
945 break;
946
947 case ACTION_ZOOM_LEVEL_NORMAL:
948 case ACTION_ZOOM_LEVEL_1:
949 case ACTION_ZOOM_LEVEL_2:
950 case ACTION_ZOOM_LEVEL_3:
951 case ACTION_ZOOM_LEVEL_4:
952 case ACTION_ZOOM_LEVEL_5:
953 case ACTION_ZOOM_LEVEL_6:
954 case ACTION_ZOOM_LEVEL_7:
955 case ACTION_ZOOM_LEVEL_8:
956 case ACTION_ZOOM_LEVEL_9:
957 Zoom((action.GetID() - ACTION_ZOOM_LEVEL_NORMAL) + 1);
958 break;
959
960 case ACTION_ANALOG_MOVE:
961 // this action is used and works, when CAction object provides both x and y coordinates
962 Move(action.GetAmount()*PICTURE_MOVE_AMOUNT_ANALOG, -action.GetAmount(1)*PICTURE_MOVE_AMOUNT_ANALOG);
963 break;
964 case ACTION_ANALOG_MOVE_X_LEFT:
965 Move(-action.GetAmount()*PICTURE_MOVE_AMOUNT_ANALOG, 0.0f);
966 break;
967 case ACTION_ANALOG_MOVE_X_RIGHT:
968 Move(action.GetAmount()*PICTURE_MOVE_AMOUNT_ANALOG, 0.0f);
969 break;
970 case ACTION_ANALOG_MOVE_Y_UP:
971 Move(0.0f, -action.GetAmount()*PICTURE_MOVE_AMOUNT_ANALOG);
972 break;
973 case ACTION_ANALOG_MOVE_Y_DOWN:
974 Move(0.0f, action.GetAmount()*PICTURE_MOVE_AMOUNT_ANALOG);
975 break;
976
977 default:
978 return CGUIDialog::OnAction(action);
979 }
980 return true;
981 }
982
983 void CGUIWindowSlideShow::RenderErrorMessage()
984 {
985 if (!m_bErrorMessage)
986 return ;
987
988 const CGUIControl *control = GetControl(LABEL_ROW1);
989 if (NULL == control || control->GetControlType() != CGUIControl::GUICONTROL_LABEL)
990 {
991 return;
992 }
993
994 CGUIFont *pFont = static_cast<const CGUILabelControl*>(control)->GetLabelInfo().font;
995 CGUITextLayout::DrawText(pFont, 0.5f*CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth(), 0.5f*CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight(), 0xffffffff, 0, g_localizeStrings.Get(747), XBFONT_CENTER_X | XBFONT_CENTER_Y);
996 }
997
998 bool CGUIWindowSlideShow::OnMessage(CGUIMessage& message)
999 {
1000 switch ( message.GetMessage() )
1001 {
1002 case GUI_MSG_WINDOW_INIT:
1003 {
1004 m_Resolution = (RESOLUTION) CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_PICTURES_DISPLAYRESOLUTION);
1005
1006 //FIXME: Use GUI resolution for now
1007 if (false /*m_Resolution != CDisplaySettings::GetInstance().GetCurrentResolution() && m_Resolution != INVALID && m_Resolution!=AUTORES*/)
1008 CServiceBroker::GetWinSystem()->GetGfxContext().SetVideoResolution(m_Resolution, false);
1009 else
1010 m_Resolution = CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution();
1011
1012 CGUIDialog::OnMessage(message);
1013
1014 // turn off slideshow if we only have 1 image
1015 if (m_slides.size() <= 1)
1016 m_bSlideShow = false;
1017
1018 return true;
1019 }
1020 break;
1021
1022 case GUI_MSG_SHOW_PICTURE:
1023 {
1024 const std::string& strFile = message.GetStringParam();
1025 Reset();
1026 CFileItem item(strFile, false);
1027 Add(&item);
1028 RunSlideShow("", false, false, true, "", false);
1029 }
1030 break;
1031
1032 case GUI_MSG_START_SLIDESHOW:
1033 {
1034 const std::string& strFolder = message.GetStringParam();
1035 unsigned int iParams = message.GetParam1();
1036 const std::string& beginSlidePath = message.GetStringParam(1);
1037 //decode params
1038 bool bRecursive = false;
1039 bool bRandom = false;
1040 bool bNotRandom = false;
1041 bool bPause = false;
1042 if (iParams > 0)
1043 {
1044 if ((iParams & 1) == 1)
1045 bRecursive = true;
1046 if ((iParams & 2) == 2)
1047 bRandom = true;
1048 if ((iParams & 4) == 4)
1049 bNotRandom = true;
1050 if ((iParams & 8) == 8)
1051 bPause = true;
1052 }
1053 RunSlideShow(strFolder, bRecursive, bRandom, bNotRandom, beginSlidePath, !bPause);
1054 }
1055 break;
1056
1057 case GUI_MSG_PLAYLISTPLAYER_STOPPED:
1058 {
1059 }
1060 break;
1061
1062 case GUI_MSG_PLAYBACK_STOPPED:
1063 {
1064 if (m_bPlayingVideo)
1065 {
1066 m_bPlayingVideo = false;
1067 m_iVideoSlide = -1;
1068 if (m_bSlideShow)
1069 m_bPause = true;
1070 }
1071 }
1072 break;
1073
1074 case GUI_MSG_PLAYBACK_ENDED:
1075 {
1076 if (m_bPlayingVideo)
1077 {
1078 m_bPlayingVideo = false;
1079 m_iVideoSlide = -1;
1080 if (m_bSlideShow)
1081 {
1082 m_bPause = false;
1083 if (m_iCurrentSlide == m_iNextSlide)
1084 break;
1085 m_Image[m_iCurrentPic]->Close();
1086 m_iCurrentPic = 1 - m_iCurrentPic;
1087 m_iCurrentSlide = m_iNextSlide;
1088 m_iNextSlide = GetNextSlide();
1089 AnnouncePlayerPlay(m_slides.at(m_iCurrentSlide));
1090 m_iZoomFactor = 1;
1091 m_fZoom = 1.0f;
1092 m_fRotate = 0.0f;
1093 }
1094 }
1095 }
1096 break;
1097 }
1098 return CGUIDialog::OnMessage(message);
1099 }
1100
1101 void CGUIWindowSlideShow::RenderPause()
1102 { // display the pause icon
1103 if (m_bPause)
1104 {
1105 SET_CONTROL_VISIBLE(CONTROL_PAUSE);
1106 }
1107 else
1108 {
1109 SET_CONTROL_HIDDEN(CONTROL_PAUSE);
1110 }
1111 }
1112
1113 void CGUIWindowSlideShow::Rotate(float fAngle, bool immediate /* = false */)
1114 {
1115 if (m_Image[m_iCurrentPic]->DrawNextImage())
1116 return;
1117
1118 m_fRotate += fAngle;
1119
1120 m_Image[m_iCurrentPic]->Rotate(fAngle, immediate);
1121 }
1122
1123 void CGUIWindowSlideShow::Zoom(int iZoom)
1124 {
1125 if (iZoom > MAX_ZOOM_FACTOR || iZoom < 1)
1126 return;
1127
1128 ZoomRelative(zoomamount[iZoom - 1]);
1129 }
1130
1131 void CGUIWindowSlideShow::ZoomRelative(float fZoom, bool immediate /* = false */)
1132 {
1133 if (fZoom < zoomamount[0])
1134 fZoom = zoomamount[0];
1135 else if (fZoom > zoomamount[MAX_ZOOM_FACTOR - 1])
1136 fZoom = zoomamount[MAX_ZOOM_FACTOR - 1];
1137
1138 if (m_Image[m_iCurrentPic]->DrawNextImage())
1139 return;
1140
1141 m_fZoom = fZoom;
1142
1143 // find the nearest zoom factor
1144 for (unsigned int i = 1; i < MAX_ZOOM_FACTOR; i++)
1145 {
1146 if (m_fZoom > zoomamount[i])
1147 continue;
1148
1149 if (fabs(m_fZoom - zoomamount[i - 1]) < fabs(m_fZoom - zoomamount[i]))
1150 m_iZoomFactor = i;
1151 else
1152 m_iZoomFactor = i + 1;
1153
1154 break;
1155 }
1156
1157 m_Image[m_iCurrentPic]->Zoom(m_fZoom, immediate);
1158 }
1159
1160 void CGUIWindowSlideShow::Move(float fX, float fY)
1161 {
1162 if (m_Image[m_iCurrentPic]->IsLoaded() && m_Image[m_iCurrentPic]->GetZoom() > 1)
1163 { // we move in the opposite direction, due to the fact we are moving
1164 // the viewing window, not the picture.
1165 m_Image[m_iCurrentPic]->Move(-fX, -fY);
1166 }
1167 }
1168
1169 bool CGUIWindowSlideShow::PlayVideo()
1170 {
1171 CFileItemPtr item = m_slides.at(m_iCurrentSlide);
1172 if (!item || !item->IsVideo())
1173 return false;
1174 CLog::Log(LOGDEBUG, "Playing current video slide {}", item->GetPath());
1175 m_bPlayingVideo = true;
1176 m_iVideoSlide = m_iCurrentSlide;
1177 bool ret = g_application.PlayFile(*item, "");
1178 if (ret == true)
1179 return true;
1180 else
1181 {
1182 CLog::Log(LOGINFO, "set video {} unplayable", item->GetPath());
1183 item->SetProperty("unplayable", true);
1184 }
1185 m_bPlayingVideo = false;
1186 m_iVideoSlide = -1;
1187 return false;
1188 }
1189
1190 CSlideShowPic::DISPLAY_EFFECT CGUIWindowSlideShow::GetDisplayEffect(int iSlideNumber) const
1191 {
1192 if (m_bSlideShow && !m_bPause && !m_slides.at(iSlideNumber)->IsVideo())
1193 return CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_SLIDESHOW_DISPLAYEFFECTS) ? CSlideShowPic::EFFECT_RANDOM : CSlideShowPic::EFFECT_NONE;
1194 else
1195 return CSlideShowPic::EFFECT_NO_TIMEOUT;
1196 }
1197
1198 void CGUIWindowSlideShow::OnLoadPic(int iPic,
1199 int iSlideNumber,
1200 const std::string& strFileName,
1201 std::unique_ptr<CTexture> pTexture,
1202 bool bFullSize)
1203 {
1204 if (pTexture)
1205 {
1206 // set the pic's texture + size etc.
1207 if (iSlideNumber >= static_cast<int>(m_slides.size()) || GetPicturePath(m_slides.at(iSlideNumber).get()) != strFileName)
1208 { // throw this away - we must have cleared the slideshow while we were still loading
1209 return;
1210 }
1211 CLog::Log(LOGDEBUG, "Finished background loading slot {}, {}: {}", iPic, iSlideNumber,
1212 m_slides.at(iSlideNumber)->GetPath());
1213 m_Image[iPic]->SetOriginalSize(pTexture->GetOriginalWidth(), pTexture->GetOriginalHeight(),
1214 bFullSize);
1215 m_Image[iPic]->SetTexture(iSlideNumber, std::move(pTexture), GetDisplayEffect(iSlideNumber));
1216
1217 m_Image[iPic]->m_bIsComic = false;
1218 if (URIUtils::IsInRAR(m_slides.at(m_iCurrentSlide)->GetPath()) || URIUtils::IsInZIP(m_slides.at(m_iCurrentSlide)->GetPath())) // move to top for cbr/cbz
1219 {
1220 CURL url(m_slides.at(m_iCurrentSlide)->GetPath());
1221 const std::string& strHostName = url.GetHostName();
1222 if (URIUtils::HasExtension(strHostName, ".cbr|.cbz"))
1223 {
1224 m_Image[iPic]->m_bIsComic = true;
1225 m_Image[iPic]->Move((float)m_Image[iPic]->GetOriginalWidth(),
1226 (float)m_Image[iPic]->GetOriginalHeight());
1227 }
1228 }
1229 }
1230 else if (iSlideNumber >= static_cast<int>(m_slides.size()) || GetPicturePath(m_slides.at(iSlideNumber).get()) != strFileName)
1231 { // Failed to load image. and not match values calling LoadPic, then something is changed, ignore.
1232 CLog::Log(LOGDEBUG,
1233 "CGUIWindowSlideShow::OnLoadPic({}, {}, {}) on failure not match current state (cur "
1234 "{}, next {}, curpic {}, pic[0, 1].slidenumber={}, {}, {})",
1235 iPic, iSlideNumber, strFileName, m_iCurrentSlide, m_iNextSlide, m_iCurrentPic,
1236 m_Image[0]->SlideNumber(), m_Image[1]->SlideNumber(),
1237 iSlideNumber >= static_cast<int>(m_slides.size())
1238 ? ""
1239 : m_slides.at(iSlideNumber)->GetPath());
1240 }
1241 else
1242 { // Failed to load image. What should be done??
1243 // We should wait for the current pic to finish rendering, then transition it out,
1244 // release the texture, and try and reload this pic from scratch
1245 m_bErrorMessage = true;
1246 }
1247 MarkDirtyRegion();
1248 }
1249
1250 void CGUIWindowSlideShow::Shuffle()
1251 {
1252 KODI::UTILS::RandomShuffle(m_slides.begin(), m_slides.end());
1253 m_iCurrentSlide = 0;
1254 m_iNextSlide = GetNextSlide();
1255 m_bShuffled = true;
1256
1257 AnnouncePropertyChanged("shuffled", true);
1258 }
1259
1260 int CGUIWindowSlideShow::NumSlides() const
1261 {
1262 return m_slides.size();
1263 }
1264
1265 int CGUIWindowSlideShow::CurrentSlide() const
1266 {
1267 return m_iCurrentSlide + 1;
1268 }
1269
1270 void CGUIWindowSlideShow::AddFromPath(const std::string &strPath,
1271 bool bRecursive,
1272 SortBy method, SortOrder order, SortAttribute sortAttributes,
1273 const std::string &strExtensions)
1274 {
1275 if (strPath!="")
1276 {
1277 // reset the slideshow
1278 Reset();
1279 if (bRecursive)
1280 {
1281 path_set recursivePaths;
1282 AddItems(strPath, &recursivePaths, method, order, sortAttributes);
1283 }
1284 else
1285 AddItems(strPath, NULL, method, order, sortAttributes);
1286 }
1287 }
1288
1289 void CGUIWindowSlideShow::RunSlideShow(const std::string &strPath,
1290 bool bRecursive /* = false */, bool bRandom /* = false */,
1291 bool bNotRandom /* = false */, const std::string &beginSlidePath /* = "" */,
1292 bool startSlideShow /* = true */, SortBy method /* = SortByLabel */,
1293 SortOrder order /* = SortOrderAscending */, SortAttribute sortAttributes /* = SortAttributeNone */,
1294 const std::string &strExtensions)
1295 {
1296 // stop any video
1297 const auto& components = CServiceBroker::GetAppComponents();
1298 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
1299 if (appPlayer->IsPlayingVideo())
1300 g_application.StopPlaying();
1301
1302 AddFromPath(strPath, bRecursive, method, order, sortAttributes, strExtensions);
1303
1304 if (!NumSlides())
1305 return;
1306
1307 // mutually exclusive options
1308 // if both are set, clear both and use the gui setting
1309 if (bRandom && bNotRandom)
1310 bRandom = bNotRandom = false;
1311
1312 // NotRandom overrides the window setting
1313 if ((!bNotRandom && CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_SLIDESHOW_SHUFFLE)) || bRandom)
1314 Shuffle();
1315
1316 if (!beginSlidePath.empty())
1317 Select(beginSlidePath);
1318
1319 if (startSlideShow)
1320 StartSlideShow();
1321 else
1322 {
1323 PlayPicture();
1324 }
1325
1326 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SLIDESHOW);
1327 }
1328
1329 void CGUIWindowSlideShow::PlayPicture()
1330 {
1331 if (m_iCurrentSlide >= 0 && m_iCurrentSlide < static_cast<int>(m_slides.size()))
1332 AnnouncePlayerPlay(m_slides.at(m_iCurrentSlide));
1333 }
1334
1335 void CGUIWindowSlideShow::AddItems(const std::string &strPath, path_set *recursivePaths, SortBy method, SortOrder order, SortAttribute sortAttributes)
1336 {
1337 // check whether we've already added this path
1338 if (recursivePaths)
1339 {
1340 std::string path(strPath);
1341 URIUtils::RemoveSlashAtEnd(path);
1342 if (recursivePaths->find(path) != recursivePaths->end())
1343 return;
1344 recursivePaths->insert(path);
1345 }
1346
1347 CFileItemList items;
1348 CGUIViewStateWindowPictures viewState(items);
1349
1350 // fetch directory and sort accordingly
1351 if (!CDirectory::GetDirectory(strPath, items, viewState.GetExtensions(), DIR_FLAG_NO_FILE_DIRS))
1352 return;
1353
1354 items.Sort(method, order, sortAttributes);
1355
1356 // need to go into all subdirs
1357 for (int i = 0; i < items.Size(); i++)
1358 {
1359 CFileItemPtr item = items[i];
1360 if (item->m_bIsFolder && recursivePaths)
1361 {
1362 AddItems(item->GetPath(), recursivePaths);
1363 }
1364 else if (!item->m_bIsFolder && !URIUtils::IsRAR(item->GetPath()) && !URIUtils::IsZIP(item->GetPath()))
1365 { // add to the slideshow
1366 Add(item.get());
1367 }
1368 }
1369 }
1370
1371 void CGUIWindowSlideShow::GetCheckedSize(float width, float height, int &maxWidth, int &maxHeight)
1372 {
1373 maxWidth = CServiceBroker::GetRenderSystem()->GetMaxTextureSize();
1374 maxHeight = CServiceBroker::GetRenderSystem()->GetMaxTextureSize();
1375 }
1376
1377 std::string CGUIWindowSlideShow::GetPicturePath(CFileItem *item)
1378 {
1379 bool isVideo = item->IsVideo();
1380 std::string picturePath = item->GetDynPath();
1381 if (isVideo)
1382 {
1383 picturePath = item->GetArt("thumb");
1384 if (picturePath.empty() && !item->HasProperty("nothumb"))
1385 {
1386 CPictureThumbLoader thumbLoader;
1387 thumbLoader.LoadItem(item);
1388 picturePath = item->GetArt("thumb");
1389 if (picturePath.empty())
1390 item->SetProperty("nothumb", true);
1391 }
1392 }
1393 return picturePath;
1394 }
1395
1396
1397 void CGUIWindowSlideShow::RunSlideShow(const std::vector<std::string>& paths, int start /* = 0*/)
1398 {
1399 auto dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIWindowSlideShow>(WINDOW_SLIDESHOW);
1400 if (dialog)
1401 {
1402 std::vector<CFileItemPtr> items;
1403 items.reserve(paths.size());
1404 for (const auto& path : paths)
1405 items.push_back(std::make_shared<CFileItem>(CTextureUtils::GetWrappedImageURL(path), false));
1406
1407 dialog->Reset();
1408 dialog->m_bPause = true;
1409 dialog->m_bSlideShow = false;
1410 dialog->m_iDirection = 1;
1411 dialog->m_iCurrentSlide = start;
1412 dialog->m_iNextSlide = (start + 1) % items.size();
1413 dialog->m_slides = std::move(items);
1414 dialog->Open();
1415 }
1416 }