1 #include "soundfilesmanager.h"
2 #include <QtGui/QStandardItemModel>
3 #include <QtCore/QStringList>
5 #include <QtXml/QDomElement>
6 #include <QtCore/QDebug> //Debug pro informace
7 SoundFilesManager::SoundFilesManager(QObject *parent) :
12 bool SoundFilesManager::Init(QDomElement root)
14 if(InitModel() == false)
23 Used to initialize the model for store names and paths to music files.
25 bool SoundFilesManager::InitModel()
27 model_of_files = new QStandardItemModel(this);
28 //QDir dir("/usr/share/sounds");
29 QDir dir("/home/user/MyDocs/.sounds/Ringtones");
30 QFileInfoList list_of_in_home = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
31 QFileInfoList list_of_maemo_sounds = QFileInfoList();
32 //////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " budou se pridavat soubory" ;
33 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/NokiaTune.aac"));
34 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Beeb.aac"));
35 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Emailalert1.aac"));
36 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Emailalert2.aac"));
37 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Message1.aac"));
38 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Message2.aac"));
39 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Message3.aac"));
40 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Message4.aac"));
41 appendFile(&list_of_maemo_sounds,QFileInfo("/usr/share/sounds/Message5.aac"));
43 list_of_maemo_sounds += list_of_in_home;
44 appendToModel(&list_of_maemo_sounds);
49 append item into model of files
51 void SoundFilesManager::appendToModel(QFileInfoList * list_of_files)
53 QList<QStandardItem *> items;
54 foreach(QFileInfo file, *list_of_files)
56 if(checkFileInModelAndExist(file)){
57 //////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " bude se pridavat do modelu toto" << file.absoluteFilePath();
58 items.append(new QStandardItem(file.fileName()));
59 items.append(new QStandardItem(file.absoluteFilePath()));
60 model_of_files->appendRow(items);
67 append item into list of files
69 void SoundFilesManager::appendFile(QFileInfoList * list_of_files, QFileInfo inf)
71 if(inf.exists()) list_of_files->append(inf);
74 /** checkFileInModelAndExist().
75 Check if file exist and if is its in model
77 bool SoundFilesManager::checkFileInModelAndExist(QFileInfo inf)
79 if(!inf.exists()) return false;
80 if(!model_of_files->findItems(inf.absoluteFilePath(),Qt::MatchExactly, 1).empty()) return false;
87 void SoundFilesManager::filesFromXmlDB(QDomElement root)
89 qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "ted z xml";
90 QFileInfoList list_of_files;
91 QDomElement first = root.firstChildElement();
92 qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "sml neni nulll";
94 while(!first.isNull()) {
95 qDebug() << "|Jmeno profilu" << first.tagName();
96 qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "bude se pridavat z xml" << first.firstChildElement("email.alert.tone").tagName();
97 appendFile(&list_of_files, QFileInfo(first.firstChildElement("email.alert.tone").text()));
98 appendFile(&list_of_files, QFileInfo(first.firstChildElement("im.alert.tone").text()));
99 appendFile(&list_of_files, QFileInfo(first.firstChildElement("ringing.alert.tone").text()));
100 appendFile(&list_of_files, QFileInfo(first.firstChildElement("sms.alert.tone").text()));
101 first = first.nextSiblingElement();
103 appendToModel(&list_of_files);
107 Returns a reference to the model of music files.
109 QStandardItemModel * SoundFilesManager::GetModel()
111 return model_of_files;