-
Notifications
You must be signed in to change notification settings - Fork 1
/
locfilesystemmodel.cpp
45 lines (44 loc) · 1.62 KB
/
locfilesystemmodel.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
#include "locfilesystemmodel.h"
LocFileSystemModel::LocFileSystemModel(void)
{
codec=nullptr;
systemcodec=nullptr;
}
/*!
* \brief LocFileSystemModel::data overrides the default data function to return decoded file names
* \param index model index
* \param role role of data
* \return decoded data
*/
QVariant LocFileSystemModel::data(const QModelIndex &index, int role) const{
QVariant dat=QFileSystemModel::data(index,role);//get data from base class
//did I want to add some other check here?
if(role==Qt::DisplayRole&&codec&&systemcodec){
QByteArray str=systemcodec->fromUnicode(dat.toString());
QByteArray cname=systemcodec->name();
if(cname=="UTF-16"||cname=="UTF-16LE"||cname=="UTF-16BE"){
str.remove(0,2);//remove byte order mark
}
else if(cname=="UTF-32"||cname=="UTF-32LE"||cname=="UTF-32BE"){
str.remove(0,4);//remove byte order mark
}
dat=QVariant(codec->toUnicode(str));
}
return dat;
}
/*!
* \brief LocFileSystemModel::setEncoding sets the actual encoding of filenames
* \param enc The name of the encoding in a string form
*/
void LocFileSystemModel::setEncoding(QByteArray enc){
codec=QTextCodec::codecForName(enc);
QFileSystemModel::layoutChanged();//update display
}
/*!
* \brief LocFileSystemModel::setSysEncoding sets the encoding that the operating system is interpreting the filenames in
* \param enc The name of the encoding in a string form
*/
void LocFileSystemModel::setSysEncoding(QByteArray enc){
systemcodec=QTextCodec::codecForName(enc);
QFileSystemModel::layoutChanged();//update display
}