Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / addons / GUIViewStateAddonBrowser.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIViewStateAddonBrowser.h"
22 #include "FileItem.h"
23 #include "guilib/GraphicContext.h"
24 #include "guilib/WindowIDs.h"
25 #include "view/ViewState.h"
26 #include "addons/Addon.h"
27 #include "addons/AddonManager.h"
28 #include "AddonDatabase.h"
29
30 using namespace XFILE;
31 using namespace ADDON;
32
33 CGUIViewStateAddonBrowser::CGUIViewStateAddonBrowser(const CFileItemList& items) : CGUIViewState(items)
34 {
35   AddSortMethod(SortByLabel, SortAttributeIgnoreFolders, 551, LABEL_MASKS("%L", "%I", "%L", ""));  // Filename, Size | Foldername, empty
36   AddSortMethod(SortByDate, 552, LABEL_MASKS("%L", "%J", "%L", "%J"));  // Filename, Date | Foldername, Date
37   SetSortMethod(SortByLabel, SortAttributeIgnoreFolders);
38
39   SetViewAsControl(DEFAULT_VIEW_AUTO);
40
41   SetSortOrder(SortOrderAscending);
42   LoadViewState(items.GetPath(), WINDOW_ADDON_BROWSER);
43 }
44
45 void CGUIViewStateAddonBrowser::SaveViewState()
46 {
47   SaveViewToDb(m_items.GetPath(), WINDOW_ADDON_BROWSER);
48 }
49
50 CStdString CGUIViewStateAddonBrowser::GetExtensions()
51 {
52   return "";
53 }
54
55 VECSOURCES& CGUIViewStateAddonBrowser::GetSources()
56 {
57   m_sources.clear();
58
59   // we always have some enabled addons
60   {
61     CMediaSource share;
62     share.strPath = "addons://enabled/";
63     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
64     share.strName = g_localizeStrings.Get(24062);
65     m_sources.push_back(share);
66   }
67   CAddonDatabase db;
68   if (db.Open() && db.HasDisabledAddons())
69   {
70     CMediaSource share;
71     share.strPath = "addons://disabled/";
72     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
73     share.strName = g_localizeStrings.Get(24039);
74     m_sources.push_back(share);
75   }
76   if (CAddonMgr::Get().HasOutdatedAddons())
77   {
78     CMediaSource share;
79     share.strPath = "addons://outdated/";
80     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
81     share.strName = g_localizeStrings.Get(24043);
82     m_sources.push_back(share);
83   }
84   if (CAddonMgr::Get().HasAddons(ADDON_REPOSITORY,true))
85   {
86     CMediaSource share;
87     share.strPath = "addons://repos/";
88     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
89     share.strName = g_localizeStrings.Get(24033);
90     m_sources.push_back(share);
91   }
92   // add "install from zip"
93   {
94     CMediaSource share;
95     share.strPath = "addons://install/";
96     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
97     share.strName = g_localizeStrings.Get(24041);
98     m_sources.push_back(share);
99   }
100   // add "search"
101   {
102     CMediaSource share;
103     share.strPath = "addons://search/";
104     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
105     share.strName = g_localizeStrings.Get(137);
106     m_sources.push_back(share);
107   }
108
109   return CGUIViewState::GetSources();
110 }
111