summaryrefslogtreecommitdiffstats
path: root/xbmc/view/GUIViewState.cpp
blob: 358bb6309209cd80364ab8531672442c115c9c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "view/GUIViewState.h"

#include "AutoSwitch.h"
#include "FileItem.h"
#include "GUIPassword.h"
#include "PlayListPlayer.h"
#include "ServiceBroker.h"
#include "URL.h"
#include "ViewDatabase.h"
#include "addons/Addon.h"
#include "addons/AddonManager.h"
#include "addons/PluginSource.h"
#include "addons/addoninfo/AddonType.h"
#include "addons/gui/GUIViewStateAddonBrowser.h"
#include "dialogs/GUIDialogSelect.h"
#include "events/windows/GUIViewStateEventLog.h"
#include "favourites/GUIViewStateFavourites.h"
#include "games/windows/GUIViewStateWindowGames.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "guilib/TextureManager.h"
#include "music/GUIViewStateMusic.h"
#include "pictures/GUIViewStatePictures.h"
#include "profiles/ProfileManager.h"
#include "programs/GUIViewStatePrograms.h"
#include "pvr/windows/GUIViewStatePVR.h"
#include "settings/MediaSourceSettings.h"
#include "settings/SettingUtils.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "settings/lib/Setting.h"
#include "utils/URIUtils.h"
#include "video/GUIViewStateVideo.h"
#include "view/ViewState.h"

#define PROPERTY_SORT_ORDER         "sort.order"
#define PROPERTY_SORT_ASCENDING     "sort.ascending"

using namespace KODI;
using namespace ADDON;
using namespace PVR;

std::string CGUIViewState::m_strPlaylistDirectory;
VECSOURCES CGUIViewState::m_sources;

static const int SETTING_AUTOPLAYNEXT_MUSICVIDEOS = 0;
static const int SETTING_AUTOPLAYNEXT_TVSHOWS = 1;
static const int SETTING_AUTOPLAYNEXT_EPISODES = 2;
static const int SETTING_AUTOPLAYNEXT_MOVIES = 3;
static const int SETTING_AUTOPLAYNEXT_UNCATEGORIZED = 4;

CGUIViewState* CGUIViewState::GetViewState(int windowId, const CFileItemList& items)
{
  // don't expect derived classes to clear the sources
  m_sources.clear();

  if (windowId == 0)
    return GetViewState(CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(),items);

  const CURL url=items.GetURL();

  if (items.IsAddonsPath())
    return new CGUIViewStateAddonBrowser(items);

  if (items.HasSortDetails())
    return new CGUIViewStateFromItems(items);

  if (url.IsProtocol("musicdb"))
    return new CGUIViewStateMusicDatabase(items);

  if (url.IsProtocol("musicsearch"))
    return new CGUIViewStateMusicSearch(items);

  if (items.IsSmartPlayList() || url.IsProtocol("upnp") ||
      items.IsLibraryFolder())
  {
    if (items.GetContent() == "songs" ||
        items.GetContent() == "albums" ||
        items.GetContent() == "mixed")
      return new CGUIViewStateMusicSmartPlaylist(items);
    else if (items.GetContent() == "musicvideos")
      return new CGUIViewStateVideoMusicVideos(items);
    else if (items.GetContent() == "tvshows")
      return new CGUIViewStateVideoTVShows(items);
    else if (items.GetContent() == "episodes")
      return new CGUIViewStateVideoEpisodes(items);
    else if (items.GetContent() == "movies")
      return new CGUIViewStateVideoMovies(items);
  }

  if (url.IsProtocol("library"))
    return new CGUIViewStateLibrary(items);

  if (items.IsPlayList())
  {
    // Playlists (like .strm) can be music or video type
    if (windowId == WINDOW_VIDEO_NAV)
      return new CGUIViewStateVideoPlaylist(items);
    else
      return new CGUIViewStateMusicPlaylist(items);
  }

  if (items.GetPath() == "special://musicplaylists/")
    return new CGUIViewStateWindowMusicNav(items);

  if (url.IsProtocol("androidapp"))
    return new CGUIViewStateWindowPrograms(items);

  if (url.IsProtocol("activities"))
    return new CGUIViewStateEventLog(items);

  if (windowId == WINDOW_MUSIC_NAV)
    return new CGUIViewStateWindowMusicNav(items);

  if (windowId == WINDOW_MUSIC_PLAYLIST)
    return new CGUIViewStateWindowMusicPlaylist(items);

  if (windowId == WINDOW_MUSIC_PLAYLIST_EDITOR)
    return new CGUIViewStateWindowMusicNav(items);

  if (windowId == WINDOW_VIDEO_NAV)
    return new CGUIViewStateWindowVideoNav(items);

  if (windowId == WINDOW_VIDEO_PLAYLIST)
    return new CGUIViewStateWindowVideoPlaylist(items);

  if (windowId == WINDOW_TV_CHANNELS)
    return new CGUIViewStateWindowPVRChannels(windowId, items);

  if (windowId == WINDOW_TV_RECORDINGS)
    return new CGUIViewStateWindowPVRRecordings(windowId, items);

  if (windowId == WINDOW_TV_GUIDE)
    return new CGUIViewStateWindowPVRGuide(windowId, items);

  if (windowId == WINDOW_TV_TIMERS)
    return new CGUIViewStateWindowPVRTimers(windowId, items);

  if (windowId == WINDOW_TV_TIMER_RULES)
    return new CGUIViewStateWindowPVRTimers(windowId, items);

  if (windowId == WINDOW_TV_SEARCH)
    return new CGUIViewStateWindowPVRSearch(windowId, items);

  if (windowId == WINDOW_RADIO_CHANNELS)
      return new CGUIViewStateWindowPVRChannels(windowId, items);

  if (windowId == WINDOW_RADIO_RECORDINGS)
    return new CGUIViewStateWindowPVRRecordings(windowId, items);

  if (windowId == WINDOW_RADIO_GUIDE)
    return new CGUIViewStateWindowPVRGuide(windowId, items);

  if (windowId == WINDOW_RADIO_TIMERS)
    return new CGUIViewStateWindowPVRTimers(windowId, items);

  if (windowId == WINDOW_RADIO_TIMER_RULES)
    return new CGUIViewStateWindowPVRTimers(windowId, items);

  if (windowId == WINDOW_RADIO_SEARCH)
    return new CGUIViewStateWindowPVRSearch(windowId, items);

  if (windowId == WINDOW_PICTURES)
    return new CGUIViewStateWindowPictures(items);

  if (windowId == WINDOW_PROGRAMS)
    return new CGUIViewStateWindowPrograms(items);

  if (windowId == WINDOW_GAMES)
    return new GAME::CGUIViewStateWindowGames(items);

  if (windowId == WINDOW_ADDON_BROWSER)
    return new CGUIViewStateAddonBrowser(items);

  if (windowId == WINDOW_EVENT_LOG)
    return new CGUIViewStateEventLog(items);

  if (windowId == WINDOW_FAVOURITES)
    return new CGUIViewStateFavourites(items);

  //  Use as fallback/default
  return new CGUIViewStateGeneral(items);
}

CGUIViewState::CGUIViewState(const CFileItemList& items) : m_items(items)
{
  m_currentViewAsControl = 0;
  m_currentSortMethod = 0;
  m_playlist = PLAYLIST::TYPE_NONE;
}

CGUIViewState::~CGUIViewState() = default;

SortOrder CGUIViewState::SetNextSortOrder()
{
  if (GetSortOrder() == SortOrderAscending)
    SetSortOrder(SortOrderDescending);
  else
    SetSortOrder(SortOrderAscending);

  SaveViewState();

  return GetSortOrder();
}

SortOrder CGUIViewState::GetSortOrder() const
{
  if (m_currentSortMethod >= 0 && m_currentSortMethod < (int)m_sortMethods.size())
    return m_sortMethods[m_currentSortMethod].m_sortDescription.sortOrder;

  return SortOrderAscending;
}

int CGUIViewState::GetSortOrderLabel() const
{
  if (m_currentSortMethod >= 0 && m_currentSortMethod < (int)m_sortMethods.size())
    if (m_sortMethods[m_currentSortMethod].m_sortDescription.sortOrder == SortOrderDescending)
      return 585;

  return 584; // default sort order label 'Ascending'
}

int CGUIViewState::GetViewAsControl() const
{
  return m_currentViewAsControl;
}

void CGUIViewState::SetViewAsControl(int viewAsControl)
{
  if (viewAsControl == DEFAULT_VIEW_AUTO)
    m_currentViewAsControl = CAutoSwitch::GetView(m_items);
  else
    m_currentViewAsControl = viewAsControl;
}

void CGUIViewState::SaveViewAsControl(int viewAsControl)
{
  SetViewAsControl(viewAsControl);
  SaveViewState();
}

SortDescription CGUIViewState::GetSortMethod() const
{
  SortDescription sorting;
  if (m_currentSortMethod >= 0 && m_currentSortMethod < (int)m_sortMethods.size())
    sorting = m_sortMethods[m_currentSortMethod].m_sortDescription;

  return sorting;
}

bool CGUIViewState::HasMultipleSortMethods() const
{
  return m_sortMethods.size() > 1;
}

int CGUIViewState::GetSortMethodLabel() const
{
  if (m_currentSortMethod >= 0 && m_currentSortMethod < (int)m_sortMethods.size())
    return m_sortMethods[m_currentSortMethod].m_buttonLabel;

  return 551; // default sort method label 'Name'
}

void CGUIViewState::GetSortMethodLabelMasks(LABEL_MASKS& masks) const
{
  if (m_currentSortMethod >= 0 && m_currentSortMethod < (int)m_sortMethods.size())
  {
    masks = m_sortMethods[m_currentSortMethod].m_labelMasks;
    return;
  }

  masks.m_strLabelFile.clear();
  masks.m_strLabel2File.clear();
  masks.m_strLabelFolder.clear();
  masks.m_strLabel2Folder.clear();
}

std::vector<SortDescription> CGUIViewState::GetSortDescriptions() const
{
  std::vector<SortDescription> descriptions;
  for (const auto& desc : m_sortMethods)
  {
    descriptions.emplace_back(desc.m_sortDescription);
  }
  return descriptions;
}

void CGUIViewState::AddSortMethod(SortBy sortBy, int buttonLabel, const LABEL_MASKS &labelMasks, SortAttribute sortAttributes /* = SortAttributeNone */, SortOrder sortOrder /* = SortOrderNone */)
{
  AddSortMethod(sortBy, sortAttributes, buttonLabel, labelMasks, sortOrder);
}

void CGUIViewState::AddSortMethod(SortBy sortBy, SortAttribute sortAttributes, int buttonLabel, const LABEL_MASKS &labelMasks, SortOrder sortOrder /* = SortOrderNone */)
{
  for (size_t i = 0; i < m_sortMethods.size(); ++i)
    if (m_sortMethods[i].m_sortDescription.sortBy == sortBy)
      return;

  // handle unspecified sort order
  if (sortBy != SortByNone && sortOrder == SortOrderNone)
  {
    // the following sort methods are sorted in descending order by default
    if (sortBy == SortByDate || sortBy == SortBySize || sortBy == SortByPlaycount ||
        sortBy == SortByRating || sortBy == SortByProgramCount ||
        sortBy == SortByBitrate || sortBy == SortByListeners ||
        sortBy == SortByUserRating || sortBy == SortByLastPlayed)
      sortOrder = SortOrderDescending;
    else
      sortOrder = SortOrderAscending;
  }

  GUIViewSortDetails sort;
  sort.m_sortDescription.sortBy = sortBy;
  sort.m_sortDescription.sortOrder = sortOrder;
  sort.m_sortDescription.sortAttributes = sortAttributes;
  sort.m_buttonLabel = buttonLabel;
  sort.m_labelMasks = labelMasks;
  m_sortMethods.push_back(sort);
}

void CGUIViewState::AddSortMethod(SortDescription sortDescription, int buttonLabel, const LABEL_MASKS &labelMasks)
{
  AddSortMethod(sortDescription.sortBy, sortDescription.sortAttributes, buttonLabel, labelMasks, sortDescription.sortOrder);
}

void CGUIViewState::SetCurrentSortMethod(int method)
{
  SortBy sortBy = (SortBy)method;
  if (sortBy < SortByNone || sortBy > SortByLastUsed)
    return; // invalid

  SetSortMethod(sortBy);
  SaveViewState();
}

void CGUIViewState::SetSortMethod(SortBy sortBy, SortOrder sortOrder /* = SortOrderNone */)
{
  for (int i = 0; i < (int)m_sortMethods.size(); ++i)
  {
    if (m_sortMethods[i].m_sortDescription.sortBy == sortBy)
    {
      m_currentSortMethod = i;
      break;
    }
  }

  if (sortOrder != SortOrderNone)
    SetSortOrder(sortOrder);
}

void CGUIViewState::SetSortMethod(SortDescription sortDescription)
{
  return SetSortMethod(sortDescription.sortBy, sortDescription.sortOrder);
}

bool CGUIViewState::ChooseSortMethod()
{

  CGUIDialogSelect *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT);
  if (!dialog)
    return false;
  dialog->Reset();
  dialog->SetHeading(CVariant{ 39010 }); // Label "Sort by"
  for (auto &sortMethod : m_sortMethods)
    dialog->Add(g_localizeStrings.Get(sortMethod.m_buttonLabel));
  dialog->SetSelected(m_currentSortMethod);
  dialog->Open();
  int newSelected = dialog->GetSelectedItem();
  // check if selection has changed
  if (!dialog->IsConfirmed() || newSelected < 0 || newSelected == m_currentSortMethod)
    return false;

  m_currentSortMethod = newSelected;
  SaveViewState();
  return true;
}

SortDescription CGUIViewState::SetNextSortMethod(int direction /* = 1 */)
{
  m_currentSortMethod += direction;

  if (m_currentSortMethod >= (int)m_sortMethods.size())
    m_currentSortMethod = 0;
  if (m_currentSortMethod < 0)
    m_currentSortMethod = m_sortMethods.size() ? (int)m_sortMethods.size() - 1 : 0;

  SaveViewState();

  return GetSortMethod();
}

bool CGUIViewState::HideExtensions()
{
  return !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_SHOWEXTENSIONS);
}

bool CGUIViewState::HideParentDirItems()
{
  return !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_SHOWPARENTDIRITEMS);
}

bool CGUIViewState::DisableAddSourceButtons()
{
  const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();

  if (profileManager->GetCurrentProfile().canWriteSources() || g_passwordManager.bMasterUser)
    return !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_SHOWADDSOURCEBUTTONS);

  return true;
}

PLAYLIST::Id CGUIViewState::GetPlaylist() const
{
  return m_playlist;
}

const std::string& CGUIViewState::GetPlaylistDirectory()
{
  return m_strPlaylistDirectory;
}

void CGUIViewState::SetPlaylistDirectory(const std::string& strDirectory)
{
  m_strPlaylistDirectory = strDirectory;
  URIUtils::RemoveSlashAtEnd(m_strPlaylistDirectory);
}

bool CGUIViewState::IsCurrentPlaylistDirectory(const std::string& strDirectory)
{
  if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist()!=GetPlaylist())
    return false;

  std::string strDir = strDirectory;
  URIUtils::RemoveSlashAtEnd(strDir);

  return m_strPlaylistDirectory == strDir;
}

bool CGUIViewState::AutoPlayNextItem()
{
  return false;
}

std::string CGUIViewState::GetLockType()
{
  return "";
}

std::string CGUIViewState::GetExtensions()
{
  return "";
}

VECSOURCES& CGUIViewState::GetSources()
{
  return m_sources;
}

void CGUIViewState::AddLiveTVSources()
{
  VECSOURCES *sources = CMediaSourceSettings::GetInstance().GetSources("video");
  for (IVECSOURCES it = sources->begin(); it != sources->end(); it++)
  {
    if (URIUtils::IsLiveTV((*it).strPath))
    {
      CMediaSource source;
      source.strPath = (*it).strPath;
      source.strName = (*it).strName;
      source.vecPaths = (*it).vecPaths;
      source.m_strThumbnailImage = "";
      source.FromNameAndPaths("video", source.strName, source.vecPaths);
      m_sources.push_back(source);
    }
  }
}

void CGUIViewState::SetSortOrder(SortOrder sortOrder)
{
  if (sortOrder == SortOrderNone)
    return;

  if (m_currentSortMethod < 0 || m_currentSortMethod >= (int)m_sortMethods.size())
    return;

  m_sortMethods[m_currentSortMethod].m_sortDescription.sortOrder = sortOrder;
}

bool CGUIViewState::AutoPlayNextVideoItem() const
{
  if (GetPlaylist() != PLAYLIST::TYPE_VIDEO)
    return false;

  int settingValue(-1);
  if (m_items.GetContent() == "musicvideos")
    settingValue = SETTING_AUTOPLAYNEXT_MUSICVIDEOS;
  else if (m_items.GetContent() == "tvshows")
    settingValue = SETTING_AUTOPLAYNEXT_TVSHOWS;
  else if (m_items.GetContent() == "episodes")
    settingValue = SETTING_AUTOPLAYNEXT_EPISODES;
  else if (m_items.GetContent() == "movies")
    settingValue = SETTING_AUTOPLAYNEXT_MOVIES;
  else
    settingValue = SETTING_AUTOPLAYNEXT_UNCATEGORIZED;

  const auto setting = std::dynamic_pointer_cast<CSettingList>(
      CServiceBroker::GetSettingsComponent()->GetSettings()->GetSetting(
          CSettings::SETTING_VIDEOPLAYER_AUTOPLAYNEXTITEM));

  return settingValue >= 0 && setting != nullptr &&
         CSettingUtils::FindIntInList(setting, settingValue);
}

void CGUIViewState::LoadViewState(const std::string &path, int windowID)
{ // get our view state from the db
  CViewDatabase db;
  if (!db.Open())
    return;

  CViewState state;
  if (db.GetViewState(path, windowID, state, CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN)) ||
      db.GetViewState(path, windowID, state, ""))
  {
    SetViewAsControl(state.m_viewMode);
    SetSortMethod(state.m_sortDescription);
  }
}

void CGUIViewState::SaveViewToDb(const std::string &path, int windowID, CViewState *viewState)
{
  CViewDatabase db;
  if (!db.Open())
    return;

  SortDescription sorting = GetSortMethod();
  CViewState state(m_currentViewAsControl, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes);
  if (viewState != NULL)
    *viewState = state;

  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  db.SetViewState(path, windowID, state, settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN));
  db.Close();

  if (viewState != NULL)
    settings->Save();
}

void CGUIViewState::AddPlaylistOrder(const CFileItemList& items, const LABEL_MASKS& label_masks)
{
  SortBy sortBy = SortByPlaylistOrder;
  int sortLabel = 559;
  SortOrder sortOrder = SortOrderAscending;
  if (items.HasProperty(PROPERTY_SORT_ORDER))
  {
    sortBy = (SortBy)items.GetProperty(PROPERTY_SORT_ORDER).asInteger();
    if (sortBy != SortByNone)
    {
      sortLabel = SortUtils::GetSortLabel(sortBy);
      sortOrder = items.GetProperty(PROPERTY_SORT_ASCENDING).asBoolean() ? SortOrderAscending : SortOrderDescending;
    }
  }

  AddSortMethod(sortBy, sortLabel, label_masks, SortAttributeNone, sortOrder);
  SetSortMethod(sortBy, sortOrder);
}

CGUIViewStateGeneral::CGUIViewStateGeneral(const CFileItemList& items) : CGUIViewState(items)
{
  AddSortMethod(SortByLabel, 551, LABEL_MASKS("%F", "%I", "%L", ""));  // Filename, size | Foldername, empty
  SetSortMethod(SortByLabel);

  SetViewAsControl(DEFAULT_VIEW_LIST);
}

CGUIViewStateFromItems::CGUIViewStateFromItems(const CFileItemList &items) : CGUIViewState(items)
{
  const std::vector<GUIViewSortDetails> &details = items.GetSortDetails();
  for (unsigned int i = 0; i < details.size(); i++)
  {
    const GUIViewSortDetails& sort = details[i];
    AddSortMethod(sort.m_sortDescription, sort.m_buttonLabel, sort.m_labelMasks);
  }
  //! @todo Should default sort/view mode be specified?
  m_currentSortMethod = 0;

  SetViewAsControl(DEFAULT_VIEW_LIST);

  if (items.IsPlugin())
  {
    CURL url(items.GetPath());
    AddonPtr addon;
    if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::PLUGIN,
                                               OnlyEnabled::CHOICE_YES))
    {
      const auto plugin = std::static_pointer_cast<CPluginSource>(addon);
      if (plugin->Provides(CPluginSource::AUDIO))
        m_playlist = PLAYLIST::TYPE_MUSIC;
      if (plugin->Provides(CPluginSource::VIDEO))
        m_playlist = PLAYLIST::TYPE_VIDEO;
    }
  }

  LoadViewState(items.GetPath(), CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow());
}

bool CGUIViewStateFromItems::AutoPlayNextItem()
{
  return AutoPlayNextVideoItem();
}

void CGUIViewStateFromItems::SaveViewState()
{
  SaveViewToDb(m_items.GetPath(), CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow());
}

CGUIViewStateLibrary::CGUIViewStateLibrary(const CFileItemList &items) : CGUIViewState(items)
{
  AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "%I", "%L", ""));  // Filename, Size | Foldername, empty
  SetSortMethod(SortByNone);

  SetViewAsControl(DEFAULT_VIEW_LIST);

  LoadViewState(items.GetPath(), CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow());
}

void CGUIViewStateLibrary::SaveViewState()
{
  SaveViewToDb(m_items.GetPath(), CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow());
}