jimbo
7th March 2015, 13:21
Hello,
Debian Wheezy 4.0.5
Qt 4.8.2 - GCC 4.6 or 4.8
Qt Creator 2.5.0
10999
I'm trying to understand QFileInfo.
The problem I've got is that an entry 'alsamixer' that shows as a directory when I think it
should be a .desktop file.
Its quite probable that I don't understand the 'linux' file system or I'm making a mistake.
Perhaps some one could take a look at the code and tell me where I've gone wrong.
Regards
A minimal program that shows this is on dropbox https://www.dropbox.com/sh/dzrqnqu40ep7z49/AAD7-rdxqN21wgerA0RpkI48a?dl=0
private:
QListWidget *subMenu;
QStringList *fileList[19], *base;
QDir baseDir[19];
QStringList base1;
base1 << "/usr/local/share/applications" // 0
<< "/usr/share/applications" // 1
<< "/home/pi/.local/share/applications"; // 2
base = new QStringList();
base->append(base1);
baseDir[1].setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); //| QDir::NoSymLinks);
baseDir[2].setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
baseDir[1] = base[1];
baseDir[2] = base[2];
fileList[1] = new QStringList();
fileList[2] = new QStringList();
fileList[1]->append(baseDir[1].entryList());
fileList[2]->append(baseDir[2].entryList());
//qDebug() << *fileList[1] << "\n";
//qDebug() << *fileList[2] << "\n\n";
QString file1;
for (int i = 0; i < fileList[1]->count(); i++) {
file1 = baseDir[1].path() + "/" + fileList[1]->at(i);
QFileInfo checkFile(file1);
fileType(checkFile, i);
}
for (int i = 0; i < fileList[2]->count(); i++) {
file1 = baseDir[2].path() + "/" + fileList[2]->at(i);
QFileInfo checkFile(file1);
fileType(checkFile, i);
}
subMenu->addItems(*fileList[1]);
subMenu->addItems(*fileList[2]);
subMenu->sortItems();
fileTypeColour();
void menu::fileType(QFileInfo checkFile, int i)
{
if (checkFile.isSymLink()) fileList[1]->replaceInStrings(fileList[1]->at(i), "Symlink - " +
fileList[1]->at(i) +
" - Target = " +
checkFile.symLinkTarget());
else if (checkFile.isDir()) fileList[1]->replaceInStrings(fileList[1]->at(i), "Directory - " +
fileList[1]->at(i));
}
void menu::fileTypeColour()
{
for (int i = 0; i < subMenu->count(); i++) {
if (subMenu->item(i)->text().startsWith("Symlink")) subMenu->item(i)->setForeground(*(new QBrush(Qt::darkCyan)));
else if (subMenu->item(i)->text().startsWith("Directory")) subMenu->item(i)->setForeground(*(new QBrush(Qt::magenta)));
}
}
Debian Wheezy 4.0.5
Qt 4.8.2 - GCC 4.6 or 4.8
Qt Creator 2.5.0
10999
I'm trying to understand QFileInfo.
The problem I've got is that an entry 'alsamixer' that shows as a directory when I think it
should be a .desktop file.
Its quite probable that I don't understand the 'linux' file system or I'm making a mistake.
Perhaps some one could take a look at the code and tell me where I've gone wrong.
Regards
A minimal program that shows this is on dropbox https://www.dropbox.com/sh/dzrqnqu40ep7z49/AAD7-rdxqN21wgerA0RpkI48a?dl=0
private:
QListWidget *subMenu;
QStringList *fileList[19], *base;
QDir baseDir[19];
QStringList base1;
base1 << "/usr/local/share/applications" // 0
<< "/usr/share/applications" // 1
<< "/home/pi/.local/share/applications"; // 2
base = new QStringList();
base->append(base1);
baseDir[1].setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); //| QDir::NoSymLinks);
baseDir[2].setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
baseDir[1] = base[1];
baseDir[2] = base[2];
fileList[1] = new QStringList();
fileList[2] = new QStringList();
fileList[1]->append(baseDir[1].entryList());
fileList[2]->append(baseDir[2].entryList());
//qDebug() << *fileList[1] << "\n";
//qDebug() << *fileList[2] << "\n\n";
QString file1;
for (int i = 0; i < fileList[1]->count(); i++) {
file1 = baseDir[1].path() + "/" + fileList[1]->at(i);
QFileInfo checkFile(file1);
fileType(checkFile, i);
}
for (int i = 0; i < fileList[2]->count(); i++) {
file1 = baseDir[2].path() + "/" + fileList[2]->at(i);
QFileInfo checkFile(file1);
fileType(checkFile, i);
}
subMenu->addItems(*fileList[1]);
subMenu->addItems(*fileList[2]);
subMenu->sortItems();
fileTypeColour();
void menu::fileType(QFileInfo checkFile, int i)
{
if (checkFile.isSymLink()) fileList[1]->replaceInStrings(fileList[1]->at(i), "Symlink - " +
fileList[1]->at(i) +
" - Target = " +
checkFile.symLinkTarget());
else if (checkFile.isDir()) fileList[1]->replaceInStrings(fileList[1]->at(i), "Directory - " +
fileList[1]->at(i));
}
void menu::fileTypeColour()
{
for (int i = 0; i < subMenu->count(); i++) {
if (subMenu->item(i)->text().startsWith("Symlink")) subMenu->item(i)->setForeground(*(new QBrush(Qt::darkCyan)));
else if (subMenu->item(i)->text().startsWith("Directory")) subMenu->item(i)->setForeground(*(new QBrush(Qt::magenta)));
}
}