-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstdafx.cpp
270 lines (219 loc) · 6.55 KB
/
stdafx.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "stdafx.h"
void RefreshStyle(QWidget *widget, const char* name, QVariant value)
{
widget->setProperty(name, value);
//widget->parentWidget()->style()->unpolish(widget);
//widget->parentWidget()->style()->polish(widget);
//widget->update();
qApp->style()->unpolish(widget);
qApp->style()->polish(widget);
widget->update();
}
void LoadStyle(QWidget *widget, QString filePath)
{
QString styleSheet;
{
QFile file(":/Skin/common.qss");
//QFile file("Z:\\VC Project\\KadPlayer\\Project\\KadPlayer\\Resources\\Skin\\common.qss");
if(file.open(QFile::ReadOnly))
{
styleSheet.append(QString::fromLocal8Bit(file.readAll()));
file.close();
}
}
{
QFile file(filePath);
if(file.open(QFile::ReadOnly))
{
styleSheet.append(QString::fromLocal8Bit(file.readAll()));
file.close();
}
}
widget->setStyleSheet(styleSheet);
}
void LoadStyle(QString filePath)
{
QString styleSheet;
{
QFile file(":/Skin/common.qss");
//QFile file("Z:\\VC Project\\KadPlayer\\Project\\KadPlayer\\Resources\\Skin\\common.qss");
if(file.open(QFile::ReadOnly))
{
styleSheet.append(QString::fromLocal8Bit(file.readAll()));
file.close();
}
}
{
QFile file(filePath);
if(file.open(QFile::ReadOnly))
{
styleSheet.append(QString::fromLocal8Bit(file.readAll()));
file.close();
}
}
qApp->setStyleSheet(styleSheet);
}
QString GetHexString(const BYTE *pBuffer, int len)
{
QString result;
for(int i=0; i<len; i++)
{
result.append(QString("%1").arg(pBuffer[i], 2, 16, QLatin1Char('0')));
}
return result.trimmed().toUpper();
}
QString GetFileSize(unsigned __int64 size)
{
quint64 KB = 1024;
quint64 MB = 1024 * KB;
quint64 GB = 1024 * MB;
quint64 TB = 1024 * GB;
//转换成TB
if (size > TB)
{
return QString("%1 TB").arg((double)size / TB, 0, 'f', 2);
}
//转换成GB
else if (size > GB)
{
return QString("%1 GB").arg((double)size / GB, 0, 'f', 2);
}
//转换成MB
else if (size > MB)
{
return QString("%1 MB").arg((double)size / MB, 0, 'f', 2);
}
//转换成KB
else if (size > KB)
{
return QString("%1 KB").arg((double)size / KB, 0, 'f', 2);
}
else
{
return QString("%1 Byte").arg(size);
}
return QString("%1").arg(size);
}
QString GetFileType(const char *name)
{
if(g_attributeHash.empty())
{
// 影视Movie
g_attributeHash.insert(".rm", QObject::tr("Video"));
g_attributeHash.insert(".rmvb", QObject::tr("Video"));
g_attributeHash.insert(".mp4", QObject::tr("Video"));
g_attributeHash.insert(".mkv", QObject::tr("Video"));
g_attributeHash.insert(".mov", QObject::tr("Video"));
g_attributeHash.insert(".mpg", QObject::tr("Video"));
g_attributeHash.insert(".wmv", QObject::tr("Video"));
g_attributeHash.insert(".avi", QObject::tr("Video"));
g_attributeHash.insert(".3gp", QObject::tr("Video"));
g_attributeHash.insert(".flv", QObject::tr("Video"));
g_attributeHash.insert(".mpeg", QObject::tr("Video"));
g_attributeHash.insert(".asf", QObject::tr("Video"));
g_attributeHash.insert(".vob", QObject::tr("Video"));
g_attributeHash.insert(".ts", QObject::tr("Video"));
g_attributeHash.insert(".srt", QObject::tr("Subtitle"));
g_attributeHash.insert(".sub", QObject::tr("Subtitle"));
g_attributeHash.insert(".ass", QObject::tr("Subtitle"));
g_attributeHash.insert(".ssa", QObject::tr("Subtitle"));
// 音乐Music
g_attributeHash.insert(".mp3", QObject::tr("Audio"));
g_attributeHash.insert(".wma", QObject::tr("Audio"));
g_attributeHash.insert(".mid", QObject::tr("Audio"));
g_attributeHash.insert(".wav", QObject::tr("Audio"));
g_attributeHash.insert(".ape", QObject::tr("Audio"));
g_attributeHash.insert(".flac", QObject::tr("Audio"));
g_attributeHash.insert(".m4a", QObject::tr("Audio"));
g_attributeHash.insert(".lrc", QObject::tr("Lyric"));
g_attributeHash.insert(".qrc", QObject::tr("Lyric"));
g_attributeHash.insert(".krc", QObject::tr("Lyric"));
// 文件File
g_attributeHash.insert(".zip", QObject::tr("Zip"));
g_attributeHash.insert(".rar", QObject::tr("Zip"));
g_attributeHash.insert(".7z", QObject::tr("Zip"));
g_attributeHash.insert(".iso", QObject::tr("CD"));
g_attributeHash.insert(".mdf", QObject::tr("CD"));
g_attributeHash.insert(".dmg", QObject::tr("CD"));
// 其他Other
g_attributeHash.insert(".exe", QObject::tr("Program"));
g_attributeHash.insert(".com", QObject::tr("Program"));
g_attributeHash.insert(".bat", QObject::tr("Program"));
g_attributeHash.insert(".dll", QObject::tr("Program"));
g_attributeHash.insert(".txt", QObject::tr("Document"));
g_attributeHash.insert(".ini", QObject::tr("Document"));
g_attributeHash.insert(".pdf", QObject::tr("Document"));
g_attributeHash.insert(".chm", QObject::tr("Document"));
g_attributeHash.insert(".doc", QObject::tr("Document"));
g_attributeHash.insert(".xls", QObject::tr("Document"));
g_attributeHash.insert(".ppt", QObject::tr("Document"));
g_attributeHash.insert(".jpg", QObject::tr("Picture"));
g_attributeHash.insert(".gif", QObject::tr("Picture"));
g_attributeHash.insert(".bmp", QObject::tr("Picture"));
g_attributeHash.insert(".png", QObject::tr("Picture"));
g_attributeHash.insert(".mht", QObject::tr("Web"));
g_attributeHash.insert(".htm", QObject::tr("Web"));
g_attributeHash.insert(".html", QObject::tr("Web"));
g_attributeHash.insert(".epub", QObject::tr("Ebook"));
g_attributeHash.insert(".torrent", QObject::tr("Torrent"));
}
QString myName = QString::fromLocal8Bit(name);
int pos = myName.lastIndexOf(".");
if(pos != -1)
{
QString type = myName.mid(pos).toLower();
return g_attributeHash.value(type);
}
return "";
}
QString GetFileFormat(const char *name)
{
QString myName = QString::fromLocal8Bit(name);
int pos = myName.lastIndexOf(".");
if(pos != -1)
{
return myName.mid(pos + 1);
}
return "";
}
QString GetFileName(QString link)
{
QString fileName;
QRegExp linkReg("ed2k://\\|file\\|(.*)\\|.*\\|.*\\|/");
linkReg.setMinimal(true);
if(linkReg.indexIn(link) != -1)
{
fileName = linkReg.cap(1);
}
return fileName;
}
QString GetFileSize(QString link)
{
QString fileSize;
QRegExp linkReg("ed2k://\\|file\\|.*\\|(.*)\\|.*\\|/");
linkReg.setMinimal(true);
if(linkReg.indexIn(link) != -1)
{
fileSize = linkReg.cap(1);
}
return fileSize;
}
QString GetHash(QString link)
{
QString hash;
QRegExp linkReg("ed2k://\\|file\\|.*\\|.*\\|(.*)\\|/");
linkReg.setMinimal(true);
if(linkReg.indexIn(link) != -1)
{
hash = linkReg.cap(1);
}
return hash;
}
QString GetEd2k(const SRESULT &sResult)
{
QString link = QString("ed2k://|file|%1|%2|%3|/")
.arg(QString::fromLocal8Bit(sResult.Name))
.arg(sResult.Size)
.arg(GetHexString(sResult.Hash, 16));
return link;
}