-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundListModelItem.cpp
More file actions
45 lines (36 loc) · 930 Bytes
/
SoundListModelItem.cpp
File metadata and controls
45 lines (36 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "SoundListModelItem.h"
#include <QDebug>
#include <QDirIterator>
SoundListModelItem::SoundListModelItem(QObject *parent)
: QAbstractListModel{parent}
{
loadAlarmList();
}
int SoundListModelItem::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return alarmSoundList.count();
}
QVariant SoundListModelItem::data(const QModelIndex &index, int role) const
{
int nRow = index.row();
if ( nRow < 0 || nRow >= alarmSoundList.count() ) {
return QVariant();
}
switch (role) {
case Qt::DisplayRole:
return alarmSoundList.value(nRow);
}
return QVariant();
}
void SoundListModelItem::loadAlarmList()
{
QString sPath = "C:/Windows/Media";
QDirIterator it(sPath, QDir::Files);
while (it.hasNext()) {
it.next();
if ( it.fileName().indexOf("Alarm") != -1 ) {
alarmSoundList.append(it.fileName());
}
}
}