-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMP3ListModel.cpp
More file actions
99 lines (89 loc) · 2.04 KB
/
Copy pathMP3ListModel.cpp
File metadata and controls
99 lines (89 loc) · 2.04 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "MP3ListModel.h"
#include <QFileInfo>
#include <QSize>
CMP3ListModel::CMP3ListModel(QObject *parent) :
QAbstractListModel(parent),
pipeToBtplay("/tmp/.btplay-cmdin"),
pipeFromBtplay("/tmp/.btplay-cmdout")
{
list.append("BBB/AAA_1");
list.append("BBB/AAA_2");
if(!pipeToBtplay.open(QIODevice::WriteOnly))
{
list.append("Can't connect to btplay");
}
else if(!pipeToBtplay.open(QIODevice::ReadOnly))
{
pipeToBtplay.close();
list.append("Can't connect to btplay");
}
cmdNum=0;
}
CMP3ListModel::~CMP3ListModel()
{
pipeToBtplay.close();
pipeFromBtplay.close();
}
int CMP3ListModel::rowCount(const QModelIndex &index ) const
{
int i=list.count();
return i;
}
int CMP3ListModel::columnCount(const QModelIndex &) const
{
return 1;
}
QVariant CMP3ListModel::data(const QModelIndex &index, int role) const
{
if(index.row()<list.count() && index.row()>=0)
{
switch(role)
{
case (Qt::SizeHintRole):
return QSize(-1,18);
break;
case (Qt::DisplayRole):
return QFileInfo(list[index.row()]).fileName();
case (Qt::UserRole):
return list[index.row()];
default:
break;
}
}
return 0;
}
bool CMP3ListModel::insertRows(int row, int count, const QModelIndex &parent)
{
beginInsertRows(parent,row,row+count);
for(int i=0;i<count;i++)
{
list.insert(row,"");
}
endInsertRows();
return true;
}
bool CMP3ListModel::removeRows(int row, int count, const QModelIndex &parent)
{
if(row+count<=list.count())
{
beginRemoveRows(parent,row,row+count);
for(int i=0;i<count;i++)
{
list.removeAt(row);
}
endRemoveRows();
return true;
}
return false;
}
bool CMP3ListModel::SendCmd(char* cmd)
{
char cmdbuf[128];
sprintf(cmdbuf,"[%d]%s",cmdNum++,cmd);
if(pipeToBtplay.isOpen())
{
pipeToBtplay.write(cmdbuf);
return true;
}
return false;
}