5 QString
suffixToIconName(QString suffix
)
7 // only formats that are understood by File Browser or Sailfish get a special icon
14 if (suffix
== "png" || suffix
== "jpeg" || suffix
== "jpg" ||
17 if (suffix
== "wav" || suffix
== "mp3" || suffix
== "flac" ||
18 suffix
== "aac" || suffix
== "ogg" || suffix
== "m4a")
20 if (suffix
== "mp4" || suffix
== "m4v")
26 QString
permissionsToString(QFile::Permissions permissions
)
28 char str
[] = "---------";
29 if (permissions
& 0x4000) str
[0] = 'r';
30 if (permissions
& 0x2000) str
[1] = 'w';
31 if (permissions
& 0x1000) str
[2] = 'x';
32 if (permissions
& 0x0040) str
[3] = 'r';
33 if (permissions
& 0x0020) str
[4] = 'w';
34 if (permissions
& 0x0010) str
[5] = 'x';
35 if (permissions
& 0x0004) str
[6] = 'r';
36 if (permissions
& 0x0002) str
[7] = 'w';
37 if (permissions
& 0x0001) str
[8] = 'x';
38 return QString::fromLatin1(str
);
41 QString
filesizeToString(qint64 filesize
)
43 // convert to kB, MB, GB: use 1000 instead of 1024 as divisor because it seems to be
44 // the usual way to display file size (like on Ubuntu)
46 if (filesize
< 1000LL)
47 return locale
.toString(filesize
)+" bytes";
49 if (filesize
< 1000000LL)
50 return locale
.toString((double)filesize
/1000.0, 'f', 2)+" kB";
52 if (filesize
< 1000000000LL)
53 return locale
.toString((double)filesize
/1000000.0, 'f', 2)+" MB";
55 return locale
.toString((double)filesize
/1000000000.0, 'f', 2)+" GB";
58 QString
datetimeToString(QDateTime datetime
)
62 // return time for today or date for older
63 if (datetime
.date() == QDate::currentDate())
64 return locale
.toString(datetime
.time(), QLocale::NarrowFormat
);
66 return locale
.toString(datetime
.date(), QLocale::NarrowFormat
);
69 QString
infoToFileKind(QFileInfo info
)
71 if (info
.isDir()) return "d";
72 if (info
.isSymLink()) return "l";
73 if (info
.isFile()) return "-";
77 QString
infoToIconName(QFileInfo info
)
79 if (info
.isDir()) return "folder";
80 if (info
.isSymLink()) return "link";
82 QString suffix
= info
.suffix().toLower();
83 return suffixToIconName(suffix
);
88 int access(QString filename
, int how
)
90 QByteArray fab
= filename
.toUtf8();
91 char *fn
= fab
.data();
92 return access(fn
, how
);
95 QString
execute(QString command
, QStringList arguments
, bool mergeErrorStream
)
98 process
.setReadChannel(QProcess::StandardOutput
);
100 process
.setProcessChannelMode(QProcess::MergedChannels
);
101 process
.start(command
, arguments
);
102 if (!process
.waitForStarted())
104 if (!process
.waitForFinished())
107 QByteArray result
= process
.readAll();
108 return QString::fromUtf8(result
);