This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackend.cpp
163 lines (147 loc) · 4.28 KB
/
backend.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Copyright 2013 AG3
*
* This file is part of WeChatAudioManager.
*
* WeChatAudioManager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WeChatAudioManager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeChatAudioManager. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backend.h"
#include<QDebug>
Backend::Backend(QObject *parent) :
QObject(parent)
{
flag=false;
ind=0;
AFIM=new AudioFileInfoModel();
//AFIM->addAudioFileInfo(AudioFileInfo("时长 ","创建日期",0));
player=new QMediaPlayer();
connect(player,SIGNAL(durationChanged(qint64)),this,SLOT(getDuration(qint64)),Qt::DirectConnection);
}
void Backend::findFile(QString path)
{
QDir t(path);
QFileInfoList fileName=t.entryInfoList(QDir::Files|QDir::NoDotAndDotDot);
for(int i=0;i<fileName.size();i++)
{
resList.append(fileName[i]);
}
fileName=t.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot);
for(int i=0;i<fileName.size();i++)
{
findFile(t.absolutePath()+"/"+fileName[i].fileName());
}
return;
}
inline bool compare(QFileInfo a,QFileInfo b)
{
return a.created()>b.created();
}
void Backend::searchAudioFile()
{
resList.clear();
flag=false;
QDir dir("/sdcard/tencent/MicroMsg");
QFileInfoList firstLevel,sdCardList=dir.entryInfoList(QDir::NoDotAndDotDot|QDir::Dirs);
int len=10;
for(int i=0;i<sdCardList.size();i++)
{
if(sdCardList[i].fileName().size()>len)
{
firstLevel.append(sdCardList[i]);
}
}
for(int j=0;j<firstLevel.size();j++)
{
dir.setPath(dir.absolutePath()+"/"+firstLevel[j].fileName());
sdCardList=dir.entryInfoList(QStringList("voice*"));
for(int i=0;i<sdCardList.size();i++)
{
findFile(dir.absolutePath()+"/"+sdCardList[i].fileName());
}
}
qSort(resList.begin(),resList.end(),compare);
reqDuration(ind);
}
void Backend::playSound(QString ind)
{
flag=true;
if(player->state()==QMediaPlayer::PlayingState)
{
player->stop();
}
else
{
player->setMedia(QUrl::fromLocalFile(resList[ind.toInt()-1].absoluteFilePath()));
player->setVolume(100);
player->play();
}
}
void Backend::getDuration(qint64 d)
{
if(flag==false && d!=0)
{
if((d/100)%10>=5)
q.push_back(d/1000+1);
else
q.push_back(d/1000);
ind++;
reqDuration(ind);
}
}
void Backend::reqDuration(int index)
{
if(index>=resList.size())
{
addItems();
return;
}
player->setMedia(QUrl::fromLocalFile(resList[index].absoluteFilePath()));
player->duration();
return;
}
void Backend::addItems()
{
ind=0;
while(!q.empty())
{
if(q.front()<10) t="0"+QString::number(q.front());
else t=QString::number(q.front());
q.pop_front();
AFIM->addAudioFileInfo(AudioFileInfo(t+"秒",resList[ind].created().toString("MM月dd日 hh:mm:ss"),ind+1));
ind++;
}
}
void Backend::copyFile(QString ind)
{
//qDebug()<<"!!!";
int index=ind.toInt()-1;
QDir myDir("/sdcard/");
if(!QDir(myDir.absolutePath()+"WeChatAudioManager").exists())
myDir.mkdir("WeChatAudioManager");
myDir.setPath("/sdcard/WeChatAudioManager/");
QFile::copy(resList[index].absoluteFilePath(),myDir.absolutePath()+"/"+resList[index].fileName());
//QMessageBox::information(0,"文件拷贝成功","当前语音消息已拷贝至"+myDir.absolutePath()+"中!请用文件管理器查看!",QMessageBox::Yes);
}
QByteArray Backend::getAd()
{
QDir dir(":/tools/output.txt");
QTime t;
t=QTime::currentTime();
qsrand(t.msec()+t.second()*1000);
adFile=new QFile(dir.absolutePath());
char buffer[1024];
adFile->open(QIODevice::ReadOnly);
while(adFile->readLine(buffer,1024)>0){adList.append(QString(buffer));}
return adList[qrand()%70].toUtf8();
}