[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / NfoFile.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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 // NfoFile.h: interface for the CNfoFile class.
21 //
22 //////////////////////////////////////////////////////////////////////
23
24 #if !defined(AFX_NfoFile_H__641CCF68_6D2A_426E_9204_C0E4BEF12D00__INCLUDED_)
25 #define AFX_NfoFile_H__641CCF68_6D2A_426E_9204_C0E4BEF12D00__INCLUDED_
26
27 #if _MSC_VER > 1000
28 #pragma once
29 #endif // _MSC_VER > 1000
30
31 #include "utils/XBMCTinyXML.h"
32 #include "addons/Scraper.h"
33 #include "utils/CharsetConverter.h"
34 #include "utils/XMLUtils.h"
35
36 class CNfoFile
37 {
38 public:
39   CNfoFile() : m_doc(NULL), m_headofdoc(NULL), m_type(ADDON::ADDON_UNKNOWN) {}
40   virtual ~CNfoFile() { Close(); }
41
42   enum NFOResult
43   {
44     NO_NFO       = 0,
45     FULL_NFO     = 1,
46     URL_NFO      = 2,
47     COMBINED_NFO = 3,
48     ERROR_NFO    = 4
49   };
50
51   NFOResult Create(const CStdString&, const ADDON::ScraperPtr&, int episode=-1,
52                    const CStdString& strPath2="");
53   template<class T>
54     bool GetDetails(T& details,const char* document=NULL, bool prioritise=false)
55   {
56     CXBMCTinyXML doc;
57     CStdString strDoc;
58     if (document)
59       strDoc = document;
60     else
61       strDoc = m_headofdoc;
62
63     CStdString encoding;
64     XMLUtils::GetEncoding(&doc, encoding);
65
66     CStdString strUtf8(strDoc);
67     if (encoding.IsEmpty())
68       g_charsetConverter.unknownToUTF8(strUtf8);
69     else
70       g_charsetConverter.stringCharsetToUtf8(encoding, strDoc, strUtf8);
71
72     doc.Clear();
73     doc.Parse(strUtf8.c_str(),0,TIXML_ENCODING_UTF8);
74     return details.Load(doc.RootElement(), true, prioritise);
75   }
76
77   void Close();
78   void SetScraperInfo(const ADDON::ScraperPtr& info) { m_info = info; }
79   const ADDON::ScraperPtr& GetScraperInfo() const { return m_info; }
80   const CScraperUrl &ScraperUrl() const { return m_scurl; }
81
82 private:
83   char* m_doc;
84   char* m_headofdoc;
85   ADDON::ScraperPtr m_info;
86   ADDON::TYPE m_type;
87   CScraperUrl m_scurl;
88
89   int Load(const CStdString&);
90   int Scrape(ADDON::ScraperPtr& scraper);
91 };
92
93 #endif // !defined(AFX_NfoFile_H__641CCF68_6D2A_426E_9204_C0E4BEF12D00__INCLUDED_)