Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Ark
Commits
3981425a
Commit
3981425a
authored
Apr 21, 2022
by
Andrey Butirsky
Browse files
Calculate total directory size
BUG: 452352
parent
3b2a6e23
Pipeline
#166853
passed with stage
in 5 minutes and 14 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
part/archivemodel.cpp
View file @
3981425a
...
...
@@ -71,12 +71,7 @@ QVariant ArchiveModel::data(const QModelIndex &index, int role) const
case
FullPath
:
return
entry
->
name
();
case
Size
:
if
(
entry
->
isDir
())
{
uint
dirs
;
uint
files
;
entry
->
countChildren
(
dirs
,
files
);
return
KIO
::
itemsSummaryString
(
dirs
+
files
,
files
,
dirs
,
0
,
false
);
}
else
if
(
!
entry
->
property
(
"link"
).
toString
().
isEmpty
())
{
if
(
!
entry
->
property
(
"link"
).
toString
().
isEmpty
())
{
return
QVariant
();
}
else
{
return
KIO
::
convertSize
(
entry
->
property
(
"size"
).
toULongLong
());
...
...
@@ -829,28 +824,30 @@ void ArchiveModel::countEntriesAndSize()
m_numberOfFiles
=
0
;
m_numberOfFolders
=
0
;
m_uncompressedSize
=
0
;
QElapsedTimer
timer
;
timer
.
start
();
traverseAndCo
untDirNode
(
m_rootEntry
.
data
());
traverseAndCo
mputeDirSizes
(
m_rootEntry
.
data
());
qCDebug
(
ARK
)
<<
"Time to count entries and size:"
<<
timer
.
elapsed
()
<<
"ms"
;
}
void
ArchiveModel
::
traverseAndCo
untDirNode
(
Archive
::
Entry
*
dir
)
qulonglong
ArchiveModel
::
traverseAndCo
mputeDirSizes
(
Archive
::
Entry
*
dir
)
{
const
auto
entries
=
dir
->
entries
();
qulonglong
uncompressedSize
=
0
;
for
(
Archive
::
Entry
*
entry
:
entries
)
{
if
(
entry
->
isDir
())
{
traverseAndCountDirNode
(
entry
);
m_numberOfFolders
++
;
uncompressedSize
+=
traverseAndComputeDirSizes
(
entry
);
}
else
{
m_numberOfFiles
++
;
m_
uncompressedSize
+=
entry
->
property
(
"size"
).
toULongLong
();
uncompressedSize
+=
entry
->
property
(
"size"
).
toULongLong
();
}
}
dir
->
setProperty
(
"size"
,
uncompressedSize
);
return
uncompressedSize
;
}
qulonglong
ArchiveModel
::
numberOfFiles
()
const
...
...
@@ -865,7 +862,7 @@ qulonglong ArchiveModel::numberOfFolders() const
qulonglong
ArchiveModel
::
uncompressedSize
()
const
{
return
m_
uncompressedSize
;
return
m_
rootEntry
.
data
()
->
property
(
"size"
).
toULongLong
()
;
}
QList
<
int
>
ArchiveModel
::
shownColumns
()
const
...
...
part/archivemodel.h
View file @
3981425a
...
...
@@ -162,7 +162,7 @@ private:
void
insertEntry
(
Archive
::
Entry
*
entry
,
InsertBehaviour
behaviour
=
NotifyViews
);
void
newEntry
(
Kerfuffle
::
Archive
::
Entry
*
receivedEntry
,
InsertBehaviour
behaviour
);
void
traverseAndCo
untDirNode
(
Archive
::
Entry
*
dir
);
qulonglong
traverseAndCo
mputeDirSizes
(
Archive
::
Entry
*
dir
);
QList
<
int
>
m_showColumns
;
QScopedPointer
<
Kerfuffle
::
Archive
>
m_archive
;
...
...
@@ -174,7 +174,6 @@ private:
qulonglong
m_numberOfFiles
;
qulonglong
m_numberOfFolders
;
qulonglong
m_uncompressedSize
;
// Whether a file entry has been listed. Used to ensure all relevant columns are shown,
// since directories might have fewer columns than files.
...
...
part/infopanel.cpp
View file @
3981425a
...
...
@@ -98,7 +98,7 @@ void InfoPanel::setIndex(const QModelIndex& index)
uint
dirs
;
uint
files
;
entry
->
countChildren
(
dirs
,
files
);
additionalInfo
->
setText
(
KIO
::
itemsSummaryString
(
dirs
+
files
,
files
,
dirs
,
0
,
fals
e
));
additionalInfo
->
setText
(
KIO
::
itemsSummaryString
(
dirs
+
files
,
files
,
dirs
,
entry
->
property
(
"size"
).
toULongLong
(),
tru
e
));
}
else
if
(
!
entry
->
property
(
"link"
).
toString
().
isEmpty
())
{
additionalInfo
->
setText
(
i18n
(
"Symbolic Link"
));
}
else
{
...
...
part/part.cpp
View file @
3981425a
...
...
@@ -898,12 +898,13 @@ void Part::slotCompleted()
if
(
m_model
->
rowCount
()
==
0
)
{
qCWarning
(
ARK
)
<<
"No entry listed by the plugin"
;
displayMsgWidget
(
KMessageWidget
::
Warning
,
xi18nc
(
"@info"
,
"The archive is empty or Ark could not open its content."
));
}
else
if
(
m_model
->
rowCount
()
==
1
)
{
if
(
m_model
->
archive
()
->
mimeType
().
inherits
(
QStringLiteral
(
"application/x-cd-image"
))
&&
m_model
->
entryForIndex
(
m_model
->
index
(
0
,
0
))
->
fullPath
()
==
QLatin1String
(
"README.TXT"
))
{
qCWarning
(
ARK
)
<<
"Detected ISO image with UDF filesystem"
;
displayMsgWidget
(
KMessageWidget
::
Warning
,
xi18nc
(
"@info"
,
"Ark does not currently support ISO files with UDF filesystem."
));
}
}
else
if
(
m_model
->
rowCount
()
==
1
&&
m_model
->
archive
()
->
mimeType
().
inherits
(
QStringLiteral
(
"application/x-cd-image"
))
&&
m_model
->
entryForIndex
(
m_model
->
index
(
0
,
0
))
->
fullPath
()
==
QLatin1String
(
"README.TXT"
))
{
qCWarning
(
ARK
)
<<
"Detected ISO image with UDF filesystem"
;
displayMsgWidget
(
KMessageWidget
::
Warning
,
xi18nc
(
"@info"
,
"Ark does not currently support ISO files with UDF filesystem."
));
}
else
{
m_model
->
countEntriesAndSize
();
}
if
(
arguments
().
metaData
()[
QStringLiteral
(
"showExtractDialog"
)]
==
QLatin1String
(
"true"
))
{
...
...
@@ -1599,6 +1600,8 @@ void Part::slotAddFilesDone(KJob* job)
setArguments
(
args
);
openUrl
(
QUrl
::
fromLocalFile
(
m_model
->
archive
()
->
multiVolumeName
()));
}
else
{
m_model
->
countEntriesAndSize
();
}
}
m_cutIndexes
.
clear
();
...
...
@@ -1610,6 +1613,8 @@ void Part::slotPasteFilesDone(KJob *job)
{
if
(
job
->
error
()
&&
job
->
error
()
!=
KJob
::
KilledJobError
)
{
KMessageBox
::
error
(
widget
(),
job
->
errorString
());
}
else
{
m_model
->
countEntriesAndSize
();
}
m_cutIndexes
.
clear
();
m_model
->
filesToMove
.
clear
();
...
...
@@ -1620,6 +1625,8 @@ void Part::slotDeleteFilesDone(KJob* job)
{
if
(
job
->
error
()
&&
job
->
error
()
!=
KJob
::
KilledJobError
)
{
KMessageBox
::
error
(
widget
(),
job
->
errorString
());
}
else
{
m_model
->
countEntriesAndSize
();
}
m_cutIndexes
.
clear
();
m_model
->
filesToMove
.
clear
();
...
...
@@ -1654,7 +1661,6 @@ void Part::slotDeleteFiles()
void
Part
::
slotShowProperties
()
{
m_model
->
countEntriesAndSize
();
QPointer
<
Kerfuffle
::
PropertiesDialog
>
dialog
(
new
Kerfuffle
::
PropertiesDialog
(
nullptr
,
m_model
->
archive
(),
m_model
->
numberOfFiles
(),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment