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