added: initial work on mixed mode smart playlists
[xbmc:paulepanters-xbmc.git] / xbmc / FileSystem / SmartPlaylistDirectory.cpp
1 #include "stdafx.h"
2 #include "SmartPlaylistDirectory.h"
3 #include "../utils/log.h"
4 #include "../SmartPlaylist.h"
5 #include "../MusicDatabase.h"
6 #include "../VideoDatabase.h"
7 #include "../Util.h"
8
9 using namespace PLAYLIST;
10
11 namespace DIRECTORY
12 {
13   CSmartPlaylistDirectory::CSmartPlaylistDirectory()
14   {
15   }
16
17   CSmartPlaylistDirectory::~CSmartPlaylistDirectory()
18   {
19   }
20
21   bool CSmartPlaylistDirectory::GetDirectory(const CStdString& strPath, CFileItemList& items)
22   {
23     // Load in the SmartPlaylist and get the WHERE query
24     CSmartPlaylist playlist;
25     if (!playlist.Load(strPath))
26       return false;
27     bool success;
28     if (playlist.GetType().Equals("music") || playlist.GetType().Equals("mixed"))
29     {
30       CMusicDatabase db;
31       db.Open();
32       CStdString type=playlist.GetType();
33       if (playlist.GetType().Equals("mixed"))
34         playlist.SetType("music");
35
36       CStdString whereOrder = playlist.GetWhereClause() + " " + playlist.GetOrderClause();
37       success = db.GetSongsByWhere("", whereOrder, items);
38       db.Close();
39       playlist.SetType(type);
40     }
41     if (playlist.GetType().Equals("video") || playlist.GetType().Equals("mixed"))
42     {
43       CVideoDatabase db;
44       db.Open();
45       CStdString type=playlist.GetType();
46       if (playlist.GetType().Equals("mixed"))
47         playlist.SetType("video");
48       CStdString whereOrder = playlist.GetWhereClause() + " " + playlist.GetOrderClause();
49       CFileItemList items2;
50       success = db.GetMusicVideosByWhere("videodb://3/2/", whereOrder, items2);
51       db.Close();
52       items.Append(items2);
53       playlist.SetType(type);
54     }
55
56     return success;
57   }
58
59   bool CSmartPlaylistDirectory::ContainsFiles(const CStdString& strPath)
60   {
61     // smart playlists always have files??
62     return true;
63   }
64
65   CStdString CSmartPlaylistDirectory::GetPlaylistByName(const CStdString& name)
66   {
67     CFileItemList list;
68     if (CDirectory::GetDirectory("special://musicplaylists/", list, "*.xsp"))
69     {
70       for (int i = 0; i < list.Size(); i++)
71       {
72         CFileItem *item = list[i];
73         if (item->GetLabel().CompareNoCase(name) == 0)
74         { // found :)
75           return item->m_strPath;
76         } 
77       }
78     }
79     return "";
80   }
81 }