Songbook-Client  0.7
This application is a manager of customguitar songbooks
 All Classes Files Functions Variables Enumerations Enumerator Pages
library.hh
Go to the documentation of this file.
1 // Copyright (C) 2009-2011, Romain Goffe <romain.goffe@gmail.com>
2 // Copyright (C) 2009-2011, Alexandre Dupas <alexandre.dupas@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301, USA.
18 //******************************************************************************
19 
20 #ifndef __LIBRARY_HH__
21 #define __LIBRARY_HH__
22 
23 #include "song.hh"
24 
25 #include <QAbstractTableModel>
26 #include <QString>
27 #include <QDir>
28 #include <QLocale>
29 #include <QMetaType>
30 
31 class QAbstractListModel;
32 class QStringListModel;
33 
34 class QPixmap;
35 class CMainWindow;
36 
52 class CLibrary : public QAbstractTableModel
53 {
54  Q_OBJECT
55  Q_PROPERTY(QDir directory READ directory WRITE setDirectory)
56 
57 public:
63  enum Roles {
64  TitleRole = Qt::UserRole + 1,
65  ArtistRole = Qt::UserRole + 2,
66  AlbumRole = Qt::UserRole + 3,
67  CoverRole = Qt::UserRole + 4,
68  LilypondRole = Qt::UserRole + 5,
69  LanguageRole = Qt::UserRole + 6,
70  PathRole = Qt::UserRole + 7,
71  CoverSmallRole = Qt::UserRole + 8,
72  CoverFullRole = Qt::UserRole + 9,
73  RelativePathRole = Qt::UserRole + 10,
74  MaxRole = RelativePathRole
75  };
76 
78  CLibrary(CMainWindow* parent);
80  ~CLibrary();
81 
82  void writeSettings();
83 
84  bool checkSongbookPath(const QString & path);
85  QString findSongbookPath();
86 
91  QDir directory() const;
92 
97  void setDirectory(const QString &directory);
98 
103  void setDirectory(const QDir &directory);
104 
108  QStringList templates() const;
109 
116  QAbstractListModel * completionModel() const;
117 
123  QAbstractListModel * artistCompletionModel() const;
124 
130  QAbstractListModel * albumCompletionModel() const;
131 
136  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
137 
143  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
144 
150  virtual int rowCount(const QModelIndex &index = QModelIndex()) const;
151 
158  virtual int columnCount(const QModelIndex &index = QModelIndex()) const;
159 
165  QString pathToSong(const QString &artist, const QString &title) const;
166 
171  QString pathToSong(Song &song) const;
172 
178  void addSong(const Song &song, bool reset=false);
179 
185  void addSong(const QString &path);
186 
192  void addSongs(const QStringList &paths);
193 
198  bool containsSong(const QString &path);
199 
204  void removeSong(const QString &path);
205 
210  int getSongIndex(const QString &path) const;
211 
216  Song getSong(const QString &path) const;
217 
221  void loadSong(const QString &path, Song *song);
222 
226  void createArtistDirectory(Song &song);
227 
232  void saveSong(Song &song);
233 
238  void saveCover(Song &song, const QImage &cover);
239 
243  void deleteSong(const QString &path);
244 
245 public slots:
246  void readSettings();
247  void update();
248 
249 signals:
250  void wasModified();
251  void directoryChanged(const QDir &directory);
252 
253 protected:
254 
255 private:
256  CMainWindow *m_parent;
257  QDir m_directory;
258 
259  QStringListModel *m_completionModel;
260  QStringListModel *m_artistCompletionModel;
261  QStringListModel *m_albumCompletionModel;
262 
263  QStringList m_templates;
264  QList< Song > m_songs;
265 };
266 
267 Q_DECLARE_METATYPE(QLocale::Language)
268 
269 #endif // __LIBRARY_HH__