17.3.3.  FileTagger: Façade Example

[ fromfile: facade.xml id: facadeexample ]

In this section, we discuss a Qt-style façade for ID3Lib. To this end, we employ another pattern that is closely related to the façade.

Here are the requirements for FileTagger.

  1. It must safely allocate and free any resources that it uses (such as python objects)

  2. It should provide a QObject properties interface compatible with moc.

  3. It must expose all features of a tag library that we need to use, so that it is not necessary to include the tag library headers from any other source code module.

  4. It must provide a clean and simple interface with self-explanatory function names.

  5. It must have getters and setters for the standard tag items (artist, album, title, genre, preference, track number) as specified in the base class, Mp3File.

  6. It must not use C-style char arrays to represent strings. Instead, it should use Unicode QStrings.

  7. It should emit signals when its properties are changed.

  8. It should define slots for setting properties.

Example 17.24 shows the class definition for the FileTagger class.


In Example 17.25 we show the implementation details for some of the member functions. The setter for m_FileName not only assigns a value to that member but it also clears the ID3_Tag and establishes a link between that tag and the named file.

auto_ptr works as a smart pointer, managing the memory for us so that the destructor does not need to delete that memory.


The other setters and getters, shown in Example 17.26, make use of the C-style convenience functions from the ID3 misc_support library. Those functions have names like ID3_AddSomething() or ID3_GetSomething(), and each takes a regular pointer to an ID3_Tag. The auto_ptr has a get() function for returning that pointer.


Each of the id3 fields we plan to use is now mapped to a Qt property with a proper getter and a setter. No char* are needed to work with ID3 tags for any application that uses this class.



[53] When the same pattern is arrived at by different people, and given different names, its importance is emphasized.