7 FileInfo::FileInfo(QObject
*parent
) :
17 void FileInfo::setFile(QString file
)
26 bool FileInfo::isDir() const
28 return m_fileInfo
.isDir();
31 QString
FileInfo::kind() const
33 if (m_fileInfo
.isSymLink()) return "l";
34 if (m_fileInfo
.isDir()) return "d";
35 if (m_fileInfo
.isFile()) return "-";
39 QString
FileInfo::icon() const
41 if (m_fileInfo
.isSymLink() && m_fileInfo
.isDir()) return "folder-link";
42 if (m_fileInfo
.isDir()) return "folder";
43 if (m_fileInfo
.isSymLink()) return "link";
44 if (m_fileInfo
.isFile()) {
45 QString suffix
= m_fileInfo
.suffix().toLower();
46 return suffixToIconName(suffix
);
51 QString
FileInfo::permissions() const
53 return permissionsToString(m_fileInfo
.permissions());
56 QString
FileInfo::owner() const
58 QString owner
= m_fileInfo
.owner();
60 owner
= QString::number(m_fileInfo
.ownerId());
64 QString
FileInfo::group() const
66 QString group
= m_fileInfo
.group();
68 group
= QString::number(m_fileInfo
.groupId());
72 QString
FileInfo::size() const
74 if (m_fileInfo
.isDir()) return "-";
75 return filesizeToString(m_fileInfo
.size());
78 QString
FileInfo::modified() const
80 return datetimeToString(m_fileInfo
.lastModified());
83 QString
FileInfo::created() const
85 return datetimeToString(m_fileInfo
.created());
88 QString
FileInfo::absolutePath() const
90 return m_fileInfo
.absolutePath();
93 QString
FileInfo::name() const
95 return m_fileInfo
.fileName();
98 QString
FileInfo::suffix() const
100 return m_fileInfo
.suffix().toLower();
103 QString
FileInfo::symLinkTarget() const
105 return m_fileInfo
.symLinkTarget();
108 QString
FileInfo::errorMessage() const
110 return m_errorMessage
;
113 QString
FileInfo::processOutput() const
115 return m_processOutput
;
118 void FileInfo::refresh()
123 void FileInfo::executeCommand(QString command
, QStringList arguments
)
125 m_processOutput
.clear();
126 emit
processOutputChanged();
128 // process is killed when Page is closed - should run this in bg thread to allow command finish(?)
129 m_process
= new QProcess(this);
130 m_process
->setReadChannel(QProcess::StandardOutput
);
131 m_process
->setProcessChannelMode(QProcess::MergedChannels
); // merged stderr channel with stdout channel
132 connect(m_process
, SIGNAL(readyReadStandardOutput()), this, SLOT(readProcessChannels()));
133 connect(m_process
, SIGNAL(finished(int, QProcess::ExitStatus
)), this, SLOT(handleProcessFinish(int, QProcess::ExitStatus
)));
134 connect(m_process
, SIGNAL(error(QProcess::ProcessError
)), this, SLOT(handleProcessError(QProcess::ProcessError
)));
135 m_process
->start(command
, arguments
);
138 void FileInfo::readProcessChannels()
140 while (m_process
->canReadLine()) {
141 QString line
= m_process
->readLine();
142 m_processOutput
+= line
;
144 emit
processOutputChanged();
147 void FileInfo::handleProcessFinish(int exitCode
, QProcess::ExitStatus status
)
149 if (status
== QProcess::CrashExit
) // if it crashed, then use some error exit code
151 emit
processExited(exitCode
);
154 void FileInfo::handleProcessError(QProcess::ProcessError error
)
157 emit
processExited(-88888); // if error, then use some error exit code
160 void FileInfo::readFile()
164 m_fileInfo
= QFileInfo(m_file
);
165 if (!m_fileInfo
.exists())
166 m_errorMessage
= tr("File does not exist");
172 emit
permissionsChanged();
176 emit
modifiedChanged();
177 emit
createdChanged();
178 emit
absolutePathChanged();
180 emit
suffixChanged();
181 emit
symLinkTargetChanged();
182 emit
errorMessageChanged();