xbmc
LabelFormatter.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 
14 namespace MUSIC_INFO
15 {
16  class CMusicInfoTag;
17 }
18 
19 class CFileItem; // forward
20 
22 {
23  LABEL_MASKS(const std::string& strLabelFile="", const std::string& strLabel2File="", const std::string& strLabelFolder="", const std::string& strLabel2Folder="") :
24  m_strLabelFile(strLabelFile),
25  m_strLabel2File(strLabel2File),
26  m_strLabelFolder(strLabelFolder),
27  m_strLabel2Folder(strLabel2Folder)
28  {}
29  std::string m_strLabelFile;
30  std::string m_strLabel2File;
31  std::string m_strLabelFolder;
32  std::string m_strLabel2Folder;
33 };
34 
36 {
37 public:
38  CLabelFormatter(const std::string &mask, const std::string &mask2);
39 
40  void FormatLabel(CFileItem *item) const;
41  void FormatLabel2(CFileItem *item) const;
42  void FormatLabels(CFileItem *item) const // convenient shorthand
43  {
44  FormatLabel(item);
45  FormatLabel2(item);
46  }
47 
48  bool FillMusicTag(const std::string &fileName, MUSIC_INFO::CMusicInfoTag *tag) const;
49 
50 private:
51  class CMaskString
52  {
53  public:
54  CMaskString(const std::string &prefix, char content, const std::string &postfix) :
55  m_prefix(prefix),
56  m_postfix(postfix),
57  m_content(content)
58  {};
59  std::string m_prefix;
60  std::string m_postfix;
61  char m_content;
62  };
63 
64  // functions for assembling the mask vectors
65  void AssembleMask(unsigned int label, const std::string &mask);
66  void SplitMask(unsigned int label, const std::string &mask);
67 
68  // functions for retrieving content based on our mask vectors
69  std::string GetContent(unsigned int label, const CFileItem *item) const;
70  std::string GetMaskContent(const CMaskString &mask, const CFileItem *item) const;
71  void FillMusicMaskContent(const char mask, const std::string &value, MUSIC_INFO::CMusicInfoTag *tag) const;
72 
73  std::vector<std::string> m_staticContent[2];
74  std::vector<CMaskString> m_dynamicContent[2];
75  bool m_hideFileExtensions;
76 };
Definition: LabelFormatter.h:21
Definition: LabelFormatter.h:35
Definition: MusicInfoTag.h:27
Represents a file on a share.
Definition: FileItem.h:102
Definition: Application.h:79