14#include <tools/datetime.hxx>
15#include <sfx2/strings.hrc>
16#include <osl/file.hxx>
21#include <svtools/strings.hrc>
28#include <bitmaps.hlst>
29#include <rtl/math.hxx>
33#define COLUMN_IMG_ISDEFAULT 0
35#define COLUMN_CATEGORY 2
36#define COLUMN_APPLICATION 3
37#define COLUMN_MODIFIED 4
39#define NUMBER_OF_COLUMNS 6
48 : mxTreeView(
std::move(xTreeView))
51 auto nDigitWidth =
mxTreeView->get_approximate_digit_width();
52 std::vector<int> aWidths{
53 static_cast<int>(nDigitWidth * 5),
54 static_cast<int>(nDigitWidth * 24),
55 static_cast<int>(nDigitWidth * 22),
56 static_cast<int>(nDigitWidth * 15),
57 static_cast<int>(nDigitWidth * 18)
64 mxTreeView->set_selection_mode(SelectionMode::Multiple);
70 const OUString& rPath,
bool bDefault)
73 OUString sPath = aUrl.
getFSysPath(FSysStyle::Detect);
77 pItem->maTitle = rTitle;
78 pItem->maSubtitle = rSubtitle;
80 pItem->maPath = rPath;
81 pItem->mbDefault = bDefault;
86 pItem->maDisplayPath = sPath;
92 AppendRow(sImage, pItem->maTitle, pItem->maSubtitle, pItem->maApplication,
93 pItem->maDisplayModify, pItem->maDisplaySize, pItem->maId);
99 const OUString& rApplication,
const OUString& rModify,
100 const OUString& rSize,
const OUString& rId)
102 std::unique_ptr<weld::TreeIter> xIter(
mxTreeView->make_iterator());
114 const OUString& rSubtitle,
const OUString& rApplication,
115 const OUString& rModify,
const OUString& rSize,
const OUString& rId)
133 if (pItem->mbDefault)
134 sImage = BMP_DEFAULT;
135 AppendRow(sImage, pItem->maTitle, pItem->maSubtitle, pItem->maApplication,
136 pItem->maDisplayModify, pItem->maDisplaySize, pItem->maId);
139 if (!sCursorId.isEmpty())
155 if (pItem->mbDefault)
156 sImage = BMP_DEFAULT;
157 UpdateRow(
nIndex, sImage, pItem->maTitle, pItem->maSubtitle, pItem->maApplication,
158 pItem->maDisplayModify, pItem->maDisplaySize, pItem->maId);
162 if (!sCursorId.isEmpty())
175 if (mnSortColumn >= 0 && mnSortColumn !=
col)
176 mxTreeView->set_sort_indicator(TriState::TRISTATE_INDET, mnSortColumn);
178 mxTreeView->set_sort_indicator((mxTreeView->get_sort_indicator(
col) == TriState::TRISTATE_TRUE
179 ? TriState::TRISTATE_FALSE
180 : TriState::TRISTATE_TRUE),
190 bool isAscending =
mxTreeView->get_sort_indicator(
col) != TriState::TRISTATE_FALSE;
192 auto comp = [&](std::unique_ptr<ListViewItem>
const& pItemA,
193 std::unique_ptr<ListViewItem>
const& pItemB) {
201 OUString sNameA = pItemA->maTitle;
202 OUString sNameB = pItemB->maTitle;
208 OUString sCategoryA = pItemA->maSubtitle;
209 OUString sCategoryB = pItemB->maSubtitle;
215 sal_uInt32 nModA, nModB;
216 nModA = pItemA->mnModify;
217 nModB = pItemB->mnModify;
221 else if (nModA > nModB)
227 sal_uInt64 nSizeA, nSizeB;
228 nSizeA = pItemA->mnSize;
229 nSizeB = pItemB->mnSize;
233 else if (nSizeA > nSizeB)
239 OUString sPathA = pItemA->maApplication;
240 OUString sPathB = pItemB->maApplication;
245 return isAscending ? (res > 0) : (res < 0);
261 if (pItem->mbDefault != bDefault)
263 pItem->mbDefault = bDefault;
266 sImage = BMP_DEFAULT;
276 if (pItem->maId == rId)
278 pItem->maTitle = rTitle;
291 OUString
sId = mxTreeView->get_id(rIter);
292 for (
const auto& pItem : mListViewItems)
294 if (pItem->maId ==
sId)
295 return pItem->maDisplayPath;
302 return static_cast<sal_uInt16
>(
mxTreeView->get_id(
pos).toInt32());
307 sal_uInt32 nModify = 0;
311 osl::DirectoryItem aItem;
312 if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
315 osl::FileStatus aStatus(osl_FileStatus_Mask_ModifyTime);
316 if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
319 TimeValue systemTimeValue = aStatus.getModifyTime();
321 nModify = systemTimeValue.Seconds;
329 osl::DirectoryItem aItem;
330 if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
333 osl::FileStatus aStatus(osl_FileStatus_Mask_ModifyTime);
334 if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
337 TimeValue systemTimeValue = aStatus.getModifyTime();
338 if (systemTimeValue.Seconds == 0)
340 TimeValue localTimeValue;
341 osl_getLocalTimeFromSystemTime(&systemTimeValue, &localTimeValue);
345 OUString aDisplayDateTime
346 = rLocaleWrapper.
getDate(aDateTime) +
", " + rLocaleWrapper.
getTime(aDateTime,
false);
347 return aDisplayDateTime;
355 osl::DirectoryItem aItem;
356 if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
359 osl::FileStatus aStatus(osl_FileStatus_Mask_FileSize);
360 if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
363 sal_uInt64 nSize = aStatus.getFileSize();
364 double fSize(
static_cast<double>(nSize));
367 sal_uInt64 nMega = 1024 * 1024;
368 sal_uInt64 nGiga = nMega * 1024;
370 OUString aUnitStr(
' ');
374 aUnitStr +=
SvtResId(STR_SVT_BYTES);
377 else if (nSize < nMega)
383 else if (nSize < nGiga)
397 = ::rtl::math::doubleToUString(fSize, rtl_math_StringFormat_F, nDec,
406 sal_uInt64 nSize = 0;
410 osl::DirectoryItem aItem;
411 if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
414 osl::FileStatus aStatus(osl_FileStatus_Mask_FileSize);
415 if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
418 nSize = aStatus.getFileSize();
427 if (aExt ==
"ott" || aExt ==
"stw" || aExt ==
"oth" || aExt ==
"dot" || aExt ==
"dotx")
431 else if (aExt ==
"ots" || aExt ==
"stc" || aExt ==
"xlt" || aExt ==
"xltm" || aExt ==
"xltx")
435 else if (aExt ==
"otp" || aExt ==
"sti" || aExt ==
"pot" || aExt ==
"potm" || aExt ==
"potx")
439 else if (aExt ==
"otg" || aExt ==
"std")
sal_Int32 compareString(const OUString &s1, const OUString &s2) const
static DateTime CreateFromUnixTime(const double fSecondsSinceEpoch)
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
const CollatorWrapper * getCollator() const
void rename(const OUString &rId, const OUString &rTitle)
void UpdateRow(int nIndex, const OUString &rImage, const OUString &rTitle, const OUString &rSubtitle, const OUString &rApplication, const OUString &rModify, const OUString &rSize, const OUString &rId)
std::vector< std::unique_ptr< ListViewItem > > mListViewItems
ListView(std::unique_ptr< weld::TreeView > xTreeView)
int get_selected_index() const
OUString get_id(int pos) const
void AppendItem(const OUString &rId, const OUString &rTitle, const OUString &rSubtitle, const OUString &rPath, bool bDefault)
std::unique_ptr< weld::TreeView > mxTreeView
void AppendRow(const OUString &rImage, const OUString &rTitle, const OUString &rSubtitle, const OUString &rApplication, const OUString &rModify, const OUString &rSize, const OUString &rId)
int get_cursor_index() const
void refreshDefaultColumn()
sal_uInt16 get_nId(int pos) const
void select_id(const OUString &sId)
void sortColumn(const int col)
OUString getDate(const Date &rDate) const
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
const LocaleDataWrapper & GetLocaleData() const
static bool IsDefaultTemplate(const OUString &rPath)
#define LINK(Instance, Class, Member)
static OUString getApplication(std::u16string_view rURL)
#define NUMBER_OF_COLUMNS
static OUString getDisplayFileModifyTime(const OUString &rURL)
#define COLUMN_APPLICATION
static OUString getDisplayFileSize(const OUString &rURL)
#define COLUMN_IMG_ISDEFAULT
static sal_uInt32 getFileModifyTime(const OUString &rURL)
IMPL_LINK(ListView, ColumnClickedHdl, const int, col, void)
static sal_uInt64 getFileSize(const OUString &rURL)
RttiCompleteObjectLocator col
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)
const LocaleDataWrapper & GetLocaleData()
OUString SfxResId(TranslateId aId)
SVT_DLLPUBLIC OUString SvtResId(TranslateId aId)
#define TEMPLATE_ITEM_MAX_HEIGHT_SUB
#define TEMPLATE_ITEM_MAX_WIDTH