no message
[xbmc:xbmc-antiquated.git] / xbmc / FileSystem / VirtualDirectory.cpp
1 #include "virtualdirectory.h"
2 #include "FactoryDirectory.h"
3 #include "../settings.h"
4 #include "file.h"
5 #include "../util.h"
6
7 using namespace DIRECTORY;
8 using namespace XFILE;
9
10 CVirtualDirectory::CVirtualDirectory(void)
11 {
12 }
13
14 CVirtualDirectory::~CVirtualDirectory(void)
15 {
16 }
17
18 void CVirtualDirectory::SetShares(VECSHARES& vecShares)
19 {
20   m_vecShares.erase(m_vecShares.begin(),m_vecShares.end());
21   for (int i=0; i < (int)vecShares.size(); ++i)
22   {
23     CShare share=vecShares[i];
24     m_vecShares.push_back( share );
25   }
26 }
27
28 bool CVirtualDirectory::GetDirectory(const CStdString& strPath,VECFILEITEMS &items)
29 {
30   CStdString strPath2=strPath;
31   CStdString strPath3=strPath;
32         strPath2 += "/";
33         strPath3 += "\\";
34         for (int i=0; i < (int)m_vecShares.size(); ++i)
35         {
36                 CShare& share=m_vecShares[i];
37                 if ( share.strPath == strPath.Left( share.strPath.size() )  ||
38                            share.strPath == strPath2.Left( share.strPath.size() )  ||
39                                  share.strPath == strPath3.Left( share.strPath.size() ) )
40                 {
41                         CFactoryDirectory factory;
42                         CDirectory *pDirectory=factory.Create(share.strPath);
43                         if (!pDirectory) return false;
44       pDirectory->SetMask(m_strFileMask);
45                         bool bResult=pDirectory->GetDirectory(strPath,items);
46       CacheThumbs(items);
47                         delete pDirectory;
48                         return bResult;
49                 }
50         }
51
52  items.erase(items.begin(),items.end());
53  for (int i=0; i < (int)m_vecShares.size(); ++i)
54         {
55                 CShare& share=m_vecShares[i];
56                 CFileItem* pItem = new CFileItem(share.strName);
57                 pItem->m_bIsFolder=true;
58                 pItem->m_strPath=share.strPath;
59
60                 CStdString strIcon;
61                 if (CUtil::IsRemote(pItem->m_strPath) )
62                         strIcon="defaultNetwork.png";   
63                 else if (CUtil::IsDVD(pItem->m_strPath) )
64                         strIcon="defaultDVDRom.png";
65                 else 
66                         strIcon="defaultHardDisk.png";
67
68                 pItem->SetIconImage(strIcon);
69                 pItem->m_bIsShareOrDrive=true;
70                 CStdString strBig;
71                 int iPos=strIcon.Find(".");
72                 strBig=strIcon.Left(iPos);
73                 strBig+="Big";
74                 strBig+=strIcon.Right(strIcon.size()-(iPos));
75                 pItem->SetThumbnailImage(strBig);
76                 items.push_back(pItem);
77         }
78
79   return true;
80 }
81
82
83 bool CVirtualDirectory::IsShare(const CStdString& strPath) const
84 {
85         for (int i=0; i < (int)m_vecShares.size(); ++i)
86         {
87                 const CShare& share=m_vecShares[i];
88                 if (share.strPath==strPath) return true;
89         }
90         return false;
91 }
92
93 void  CVirtualDirectory::CacheThumbs(VECFILEITEMS &items)
94 {
95   CStdString strThumb;
96   for (int i=0; i < (int)items.size(); ++i)
97   {
98     CFileItem* pItem=items[i];
99                 pItem->m_bIsShareOrDrive=false;
100                 if (pItem->m_bIsFolder)
101                 {
102                 }
103                 else
104                 {
105                         if (CUtil::IsPicture(pItem->m_strPath) )
106                         {
107                                 pItem->SetIconImage("defaultPicture.png");
108                         }
109                         if (CUtil::IsAudio(pItem->m_strPath) )
110                         {
111                                 pItem->SetIconImage("defaultAudio.png");
112                         }
113                         if (CUtil::IsXBE(pItem->m_strPath) )
114                         {
115                                 pItem->SetIconImage("defaultProgram.png");
116                         }
117
118                         if (CUtil::IsVideo(pItem->m_strPath) )
119                         {
120                                 pItem->SetIconImage("defaultVideo.png");
121                         }
122                 }
123                 
124                 if (pItem->HasThumbnail() )
125                 {
126                         CUtil::GetThumbnail( pItem->m_strPath,strThumb);
127       
128                         CFile file;
129                         CStdString strThumbnailFileName;
130                         CUtil::ReplaceExtension(pItem->m_strPath,".tbn", strThumbnailFileName);
131                         if ( file.Cache(strThumbnailFileName.c_str(), strThumb.c_str()))
132                         {
133                                 pItem->SetThumbnailImage(strThumb);
134                         }
135                         else
136                         {
137                                 
138                                 CUtil::GetThumbnail(pItem->m_strPath,strThumb);
139                                 if (CUtil::FileExists(strThumb) )
140                                 {
141                                         pItem->SetThumbnailImage(strThumb);
142                                 }
143                         }
144                 }
145                 else
146                 {
147                         CUtil::GetThumbnail(pItem->m_strPath,strThumb);
148                         if (CUtil::FileExists(strThumb))
149                         {
150                                 pItem->SetThumbnailImage(strThumb);
151                         }
152                 }
153
154                 
155                 if (pItem->GetThumbnailImage()=="")
156                 {
157                         if (pItem->GetIconImage()=="")
158                         {
159                                 if (pItem->m_bIsFolder)
160                                 {
161                                         pItem->SetIconImage("defaultFolder.png");
162                                 }
163                                 else
164                                 {
165                                         CStdString strExtension;
166                                         CUtil::GetExtension(pItem->m_strPath,strExtension);
167                                         
168                                         for (int i=0; i < (int)g_settings.m_vecIcons.size(); ++i)
169                                         {
170                                                 CFileTypeIcon& icon=g_settings.m_vecIcons[i];
171
172                                                 if (CUtil::cmpnocase(strExtension.c_str(), icon.m_strName)==0)
173                                                 {
174                                                         pItem->SetIconImage(icon.m_strIcon);
175                                                         break;
176                                                 }
177                                         }
178                                 }
179                         }
180
181                         if (pItem->GetIconImage()!="")
182                         {
183                                 CStdString strBig;
184                                 int iPos=pItem->GetIconImage().Find(".");
185                                 strBig=pItem->GetIconImage().Left(iPos);
186                                 strBig+="Big";
187                                 strBig+=pItem->GetIconImage().Right(pItem->GetIconImage().size()-(iPos));
188                                 pItem->SetThumbnailImage(strBig);
189                         }
190                 }
191   }
192 }