xref: /OK3568_Linux_fs/app/forlinx/flapp/src/plugins/allwinner/music/common/commonfunction.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*!
2  * @file src/commonfunction.cpp
3  * Copyright (c) 2018
4  * @brief des
5  * detailed des
6  *
7  * @date 2018
8  * @author lee
9  */
10 #include "commonfunction.h"
11 #include "frmmessagebox.h"
12 #include <QDebug>
13 #include "musicplayer.h"
14 #include <QTextCodec>
15 /**************************************
16 Function:
17 Description:
18 ***************************************/
CommonFunction()19 CommonFunction::CommonFunction()
20 {
21 
22 }
23 
24 /**************************************
25 Function:
26 Description:
27 ***************************************/
fileExistOrNot(QString path)28 bool CommonFunction::fileExistOrNot(QString path)
29 {
30     if(path.isEmpty()){
31         qDebug()<<"path is empty, please check";
32         return false;
33     }
34     if((access((char*)path.toLatin1().data(),F_OK)) != -1){
35         qDebug()<<"file exist";
36         return true;
37     }else{
38         qDebug()<<"this file is not exist";
39         return false;
40     }
41 }
42 
43 /**************************************
44 Function:
45 Description:
46 ***************************************/
video_support_or_not(QWidget * parent_widget,QString path)47 bool CommonFunction::video_support_or_not(QWidget* parent_widget,QString path)
48 {
49     AUTPlayer *ap = NULL;
50     if(ap == NULL){
51         qDebug()<<"video_support_or_not"<<path;
52         ap = new AUTPlayer();
53         int ret = ap->setUrl((char*)path.toLatin1().data());
54         if (ret < 0){
55             qDebug()<<"setUrl is error-------------------";
56             frmMessageBox *msg = new frmMessageBox(parent_widget);
57             msg->SetMessage(QString("媒体不支持!"),0);
58             msg->exec();
59             if(ap != NULL){
60                 delete ap;
61                  ap = NULL;
62             }
63             return false;
64         }else{
65             if(ap != NULL){
66                 delete ap;
67                  ap = NULL;
68             }
69             qDebug()<<"this video is support";
70             return true;
71         }
72     }
73     return true;
74 }
75 
76 /**************************************
77 Function:
78 Description:
79 ***************************************/
print_info(unsigned char tmp[],int tmp2)80 QString CommonFunction::print_info(unsigned char tmp[],int tmp2)
81 {
82     //tmp
83     QString str = "";
84     for(int i = 0;i < tmp2 && i < 64;i++)
85     {
86         if(tmp[i] == 0)
87             continue;
88         str += tmp[i];
89     }
90     return QObject::trUtf8(str.toLatin1().data());
91 }
92 
93 
94 
95 /**************************************
96 Function:
97 Description:
98 ***************************************/
getTimeStr(qint64 x,qint64 range)99 QString getTimeStr(qint64 x,qint64 range)
100 {
101     QString tStr = "";
102     QString format = "mm:ss";
103     if(range >  3600) format = "hh:mm:ss";
104 
105     QTime currentTime((x / 3600) % 60, (x / 60) % 60, \
106                       x % 60, (x * 1000) % 1000);
107 
108 
109     tStr = currentTime.toString(format);
110 
111     return tStr;
112 }
113 
114 /**************************************
115 Function:
116 Description:
117 ***************************************/
autCb_func(int msgType,void * user,void * data,int len)118 int autCb_func(int msgType, void *user,void* data,int len)
119 {
120 
121 //    if(pGlobalMediaHome->distype==1){
122 //        //emit pStaticVideoPlayer->msgSignal(msgType,user,data,len);
123 //    }
124 //    else if(pGlobalMediaHome->distype==2){
125 //        //emit pStaticMusicPlayer->msgSignal(msgType,user,data,len);
126 //    }
127 
128 
129 }
130 
131 /**************************************
132 Function:
133 Description:
134 ***************************************/
UTF82GBK(const QString & inStr)135 QString UTF82GBK(const QString &inStr)
136 {
137 
138     QString str;
139 
140     QTextCodec *gbk = QTextCodec::codecForName("gbk");
141     QTextCodec *utf8 = QTextCodec::codecForName("UTF-8");
142 
143     str = utf8->toUnicode(inStr.toLocal8Bit());
144 
145     qDebug()<<"UTF82GBK " << str;
146 
147     QString utf2gbk = QString(gbk->fromUnicode(str));
148 
149     qDebug()<<"UTF82GBK " << utf2gbk;
150 
151     return utf2gbk;
152 }
153