forked from sanshao27/apktool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileimageprovider.cpp
68 lines (61 loc) · 2.53 KB
/
fileimageprovider.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
#include "fileimageprovider.h"
#include <QFileInfo>
#include <QProcess>
#include <QPainter>
FileImageProvider::FileImageProvider():QQuickImageProvider(QQuickImageProvider::Pixmap)
{
}
QPixmap FileImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize){
int width = 100;
int height = 100;
if (size)
*size = QSize(width, height);
QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width,
requestedSize.height() > 0 ? requestedSize.height() : height);
QFileInfo f(id);
if(id=="task_running")
pixmap.load(":/icons/task_running.png");
else if(id=="task_ok")
pixmap.load(":/icons/task_ok.png");
else if(id=="task_error")
pixmap.load(":/icons/task_error.png");
else if(id=="task_terminate")
pixmap.load(":/icons/task_terminate.png");
else if(f.isDir()&&f.isReadable())
pixmap.load(":/icons/folder.png");
else if(f.isDir()&&!f.isReadable())
pixmap.load(":/icons/folder-grey.png");
else if(f.isFile()){
if(id.endsWith(".apk", Qt::CaseInsensitive)){
QProcess proc;
QProcessEnvironment env = proc.processEnvironment();
QString path = env.value("PATH");
env.insert("PATH", "/data/data/per.pqy.apktool/apktool/openjdk/bin:"+path);
proc.setProcessEnvironment(env);
QString cmd = "aapt5.0 d --values badging " + id + "|busybox grep application-icon|busybox tail -1|busybox awk -F: '{print $2}' ";
proc.start("sh", QStringList()<<"-c"<<cmd);
proc.waitForFinished(-1);
QByteArray icon = proc.readAllStandardOutput();
if(icon.length()==0)
pixmap.load(":/icons/unknown.png");
else{
cmd = "busybox unzip -p " + id + " " + icon;
proc.start("sh", QStringList()<<"-c"<<cmd);
proc.waitForFinished(-1);
icon = proc.readAllStandardOutput();
pixmap.loadFromData(icon,"png");
}
}else if(id.endsWith(".jpg", Qt::CaseInsensitive)||id.endsWith(".png", Qt::CaseInsensitive)){
pixmap.load(id);
}else pixmap.load(":/icons/file.png");
}
else
pixmap.load(":/icons/unknown.png");
if(pixmap.isNull())
pixmap.load(":/icons/unknown.png");
if(f.isSymLink()){
QPainter painter(&pixmap);
painter.drawPixmap(0, 0, pixmap.width()/2, pixmap.height()/2, QPixmap(":/icons/symlink.png"));
}
return pixmap;
}