Sayonara Player
XiphFrame.h
1 /* XiphFrame.h */
2 
3 /* Copyright (C) 2011-2017 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 
23 #ifndef ABSTRACT_XIPH_FRAME_H_
24 #define ABSTRACT_XIPH_FRAME_H_
25 
26 #include "Utils/Tagging/AbstractFrame.h"
27 #include <QString>
28 #include <taglib/tag.h>
29 #include <taglib/xiphcomment.h>
30 #include <taglib/tstring.h>
31 #include <taglib/tstringlist.h>
32 
33 namespace Xiph
34 {
35  template<typename Model_t>
36  class XiphFrame :
37  protected Tagging::AbstractFrame<TagLib::Ogg::XiphComment>
38  {
39  protected:
40  virtual bool map_tag_to_model(Model_t& model)=0;
41  virtual bool map_model_to_tag(const Model_t& model)=0;
42 
43  bool value(TagLib::String& str) const
44  {
45  TagLib::Ogg::XiphComment* tag = this->tag();
46  const TagLib::Ogg::FieldListMap& map = tag->fieldListMap();
47  TagLib::Ogg::FieldListMap::ConstIterator it = map.find( this->tag_key() );
48  if(it == map.end()){
49  str = TagLib::String();
50  return false;
51  }
52 
53  str = it->second.front();
54  return true;
55  }
56 
57  void set_value(const TagLib::String& value)
58  {
59  TagLib::Ogg::XiphComment* tag = this->tag();
60  tag->addField(this->tag_key(), value, true);
61  }
62 
63  void set_value(const QString& value)
64  {
65  TagLib::String str = this->cvt_string(value);
66  set_value(str);
67  }
68 
69  public:
70  XiphFrame(TagLib::Tag* tag, const QString& identifier) :
72 
73  virtual ~XiphFrame() {}
74 
75  bool read(Model_t& model)
76  {
77  if(!this->tag()){
78  return false;
79  }
80 
81  bool success = map_tag_to_model(model);
82 
83  return success;
84  }
85 
86  bool write(const Model_t& model)
87  {
88  TagLib::Ogg::XiphComment* tag = this->tag();
89  if(!tag) {
90  return false;
91  }
92 
93  tag->removeField( this->tag_key() );
94 
95  return map_model_to_tag(model);
96  }
97  };
98 }
99 
100 #endif // ABSTRACTFRAME_H
Definition: XiphFrame.h:36
Definition: AbstractFrame.h:57