aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/features/FeatureTabSheet.java
Commit message (Collapse)AuthorAgeFilesLines
* Removed old Feature Browser from demo package, simpler but better ↵Jani Laakso2007-10-181-91/+0
| | | | | | functioning demo will be added soon. svn changeset:2549/svn branch:trunk
* Fixed Jani Laakso2007-02-121-1/+1
| | | | | | | | #410 (Typo or bad img tag in Selects texts) #412 (Typo or bad img tag in Container text) #413 (Typo or bad img tag in Tabsheet text) svn changeset:695/svn branch:toolkit
* Took the liberty to change some graphics.Jani Laakso2007-02-121-2/+2
| | | | | | | - faster loading / user experience through "slow" links - better lookin IMO svn changeset:676/svn branch:toolkit
* Many language fixes.Jani Laakso2007-02-121-8/+20
| | | | | | | | | | | | | | | | | | | | | Removed TODO's. Added documentational content. Removed most pictures which are no longer required. - also this slows down loading of the application on "slow" links. - pictures were not that good anyway. Property panel is now also applicable. Fixed: #387 FeatureBrowser is full of descriptions saying TODO #337 FeatureBrowser: Source tabs in "features" that do not have source #374 FeatureBrowser: When opening a feature with no properties, hide propertypanel (on Java) #395 FeatureBrowser: Hide non-working features #375 FeatureBrowser: Should start from welcome (?) and select it from tree svn changeset:674/svn branch:toolkit
* Javadoc now has content.Jani Laakso2007-02-091-0/+2
| | | | | | Fixed #336 (FeatureBrowser: Javadoc tabs are empty) svn changeset:618/svn branch:toolkit
* Removed "root" panel from Feature Components.Jani Laakso2007-02-051-6/+1
| | | | | | Disabled "FrameWindow", not targeted for first public release (now). svn changeset:470/svn branch:toolkit
* Indentation changes.Jani Laakso2007-02-021-36/+35
| | | | | | Layout changed. svn changeset:426/svn branch:toolkit
* Fixed typo: "Intarfaces" => "Interfaces"Jani Laakso2007-01-121-2/+2
| | | | svn changeset:255/svn branch:toolkit
* Fixed typo: "Intarfaces" => "Interfaces"Jani Laakso2007-01-121-1/+1
| | | | svn changeset:238/svn branch:toolkit
* Refactoring: Enably -> IT Mill ToolkitJoonas Lehtinen2006-11-011-0/+83
svn changeset:92/svn branch:toolkit
e='backport/43252/stable26'>backport/43252/stable26 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Helper.php
blob: b1439ac7fa508dba91e8c6de0e9017010298f42a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php

/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-only
 */
namespace OCA\Files;

use OC\Files\Filesystem;
use OCP\Files\FileInfo;
use OCP\Util;

/**
 * Helper class for manipulating file information
 */
class Helper {
	/**
	 * Comparator function to sort files alphabetically and have
	 * the directories appear first
	 *
	 * @param FileInfo $a file
	 * @param FileInfo $b file
	 * @return int -1 if $a must come before $b, 1 otherwise
	 */
	public static function compareFileNames(FileInfo $a, FileInfo $b) {
		$aType = $a->getType();
		$bType = $b->getType();
		if ($aType === 'dir' and $bType !== 'dir') {
			return -1;
		} elseif ($aType !== 'dir' and $bType === 'dir') {
			return 1;
		} else {
			return Util::naturalSortCompare($a->getName(), $b->getName());
		}
	}

	/**
	 * Comparator function to sort files by date
	 *
	 * @param FileInfo $a file
	 * @param FileInfo $b file
	 * @return int -1 if $a must come before $b, 1 otherwise
	 */
	public static function compareTimestamp(FileInfo $a, FileInfo $b) {
		$aTime = $a->getMTime();
		$bTime = $b->getMTime();
		return ($aTime < $bTime) ? -1 : 1;
	}

	/**
	 * Comparator function to sort files by size
	 *
	 * @param FileInfo $a file
	 * @param FileInfo $b file
	 * @return int -1 if $a must come before $b, 1 otherwise
	 */
	public static function compareSize(FileInfo $a, FileInfo $b) {
		$aSize = $a->getSize();
		$bSize = $b->getSize();
		return ($aSize < $bSize) ? -1 : 1;
	}

	/**
	 * Formats the file info to be returned as JSON to the client.
	 *
	 * @param FileInfo $i
	 * @return array formatted file info
	 */
	public static function formatFileInfo(FileInfo $i) {
		$entry = [];

		$entry['id'] = $i->getId();
		$entry['parentId'] = $i->getParentId();
		$entry['mtime'] = $i->getMtime() * 1000;
		// only pick out the needed attributes
		$entry['name'] = $i->getName();
		$entry['permissions'] = $i->getPermissions();
		$entry['mimetype'] = $i->getMimetype();
		$entry['size'] = $i->getSize();
		$entry['type'] = $i->getType();
		$entry['etag'] = $i->getEtag();
		// TODO: this is using the private implementation of FileInfo
		// the array access is not part of the public interface
		if (isset($i['tags'])) {
			$entry['tags'] = $i['tags'];
		}
		if (isset($i['displayname_owner'])) {
			$entry['shareOwner'] = $i['displayname_owner'];
		}
		if (isset($i['is_share_mount_point'])) {
			$entry['isShareMountPoint'] = $i['is_share_mount_point'];
		}
		if (isset($i['extraData'])) {
			$entry['extraData'] = $i['extraData'];
		}

		$mountType = null;
		$mount = $i->getMountPoint();
		$mountType = $mount->getMountType();
		if ($mountType !== '') {
			if ($i->getInternalPath() === '') {
				$mountType .= '-root';
			}
			$entry['mountType'] = $mountType;
		}
		return $entry;
	}

	/**
	 * Retrieves the contents of the given directory and
	 * returns it as a sorted array of FileInfo.
	 *
	 * @param string $dir path to the directory
	 * @param string $sortAttribute attribute to sort on
	 * @param bool $sortDescending true for descending sort, false otherwise
	 * @param string $mimetypeFilter limit returned content to this mimetype or mimepart
	 * @return FileInfo[] files
	 */
	public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '') {
		$content = Filesystem::getDirectoryContent($dir, $mimetypeFilter);

		return self::sortFiles($content, $sortAttribute, $sortDescending);
	}

	/**
	 * Sort the given file info array
	 *
	 * @param FileInfo[] $files files to sort
	 * @param string $sortAttribute attribute to sort on
	 * @param bool $sortDescending true for descending sort, false otherwise
	 * @return FileInfo[] sorted files
	 */
	public static function sortFiles($files, $sortAttribute = 'name', $sortDescending = false) {
		$sortFunc = 'compareFileNames';
		if ($sortAttribute === 'mtime') {
			$sortFunc = 'compareTimestamp';
		} elseif ($sortAttribute === 'size') {
			$sortFunc = 'compareSize';
		}
		usort($files, [Helper::class, $sortFunc]);
		if ($sortDescending) {
			$files = array_reverse($files);
		}
		return $files;
	}
}