12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- ########################################################################
- # Searx-Qt - Lightweight desktop application for Searx.
- # Copyright (C) 2020-2022 CYBERDEViL
- #
- # This file is part of Searx-Qt.
- #
- # Searx-Qt is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # Searx-Qt is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
- #
- ########################################################################
- from searxqt.translations import _
- def boolToStr(state):
- return _("Yes") if state else _("No")
- def listToStr(list_):
- return ", ".join(list_)
- def formatFileSize(fileSize):
- """
- @param fileSize: File size in bytes to format to string.
- @type fileSize: uint
- """
- sizeStr = ""
- KiB = 1024
- MiB = KiB ** 2
- GiB = KiB ** 3
- TiB = KiB ** 4
- if fileSize > TiB: # TiB
- sizeStr = "{0:.2f} TB".format(fileSize / TiB)
- elif fileSize > GiB: # GiB
- sizeStr = "{0:.2f} GB".format(fileSize / GiB)
- elif fileSize > MiB: # MiB
- sizeStr = "{0:.2f} MB".format(fileSize / MiB)
- elif fileSize > KiB: # KiB
- sizeStr = "{0:.2f} KB".format(fileSize / KiB)
- else:
- sizeStr = "{0} Bytes".format(fileSize)
- return sizeStr
- def formatFileCount(fileCount):
- """
- @param fileCount: File count to format to string.
- @type fileCount: uint
- """
- if fileCount == 1:
- return "1 " + _("file")
- return "{0} {1}".format(fileCount, _("files"))
|