@@ -40,152 +40,152 @@ |
||
40 | 40 | use OCP\PreConditionNotMetException; |
41 | 41 | |
42 | 42 | class BackgroundService { |
43 | - public const THEMING_MODE_DARK = 'dark'; |
|
43 | + public const THEMING_MODE_DARK = 'dark'; |
|
44 | 44 | |
45 | - public const SHIPPED_BACKGROUNDS = [ |
|
46 | - 'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [ |
|
47 | - 'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)', |
|
48 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg', |
|
49 | - ], |
|
50 | - 'bernie-cetonia-aurata-take-off-composition.jpg' => [ |
|
51 | - 'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)', |
|
52 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg', |
|
53 | - 'theming' => self::THEMING_MODE_DARK, |
|
54 | - ], |
|
55 | - 'dejan-krsmanovic-ribbed-red-metal.jpg' => [ |
|
56 | - 'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)', |
|
57 | - 'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/', |
|
58 | - ], |
|
59 | - 'eduardo-neves-pedra-azul.jpg' => [ |
|
60 | - 'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)', |
|
61 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg', |
|
62 | - ], |
|
63 | - 'european-space-agency-barents-bloom.jpg' => [ |
|
64 | - 'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)', |
|
65 | - 'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom', |
|
66 | - ], |
|
67 | - 'hannes-fritz-flippity-floppity.jpg' => [ |
|
68 | - 'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)', |
|
69 | - 'attribution_url' => 'http://hannes.photos/flippity-floppity', |
|
70 | - ], |
|
71 | - 'hannes-fritz-roulette.jpg' => [ |
|
72 | - 'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)', |
|
73 | - 'attribution_url' => 'http://hannes.photos/roulette', |
|
74 | - ], |
|
75 | - 'hannes-fritz-sea-spray.jpg' => [ |
|
76 | - 'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)', |
|
77 | - 'attribution_url' => 'http://hannes.photos/sea-spray', |
|
78 | - ], |
|
79 | - 'kamil-porembinski-clouds.jpg' => [ |
|
80 | - 'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)', |
|
81 | - 'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/', |
|
82 | - ], |
|
83 | - 'bernard-spragg-new-zealand-fern.jpg' => [ |
|
84 | - 'attribution' => 'New zealand fern (Bernard Spragg, CC0)', |
|
85 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg', |
|
86 | - ], |
|
87 | - 'rawpixel-pink-tapioca-bubbles.jpg' => [ |
|
88 | - 'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)', |
|
89 | - 'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/', |
|
90 | - 'theming' => self::THEMING_MODE_DARK, |
|
91 | - ], |
|
92 | - 'nasa-waxing-crescent-moon.jpg' => [ |
|
93 | - 'attribution' => 'Waxing crescent moon (NASA, Public Domain)', |
|
94 | - 'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon', |
|
95 | - ], |
|
96 | - 'tommy-chau-already.jpg' => [ |
|
97 | - 'attribution' => 'Cityscape (Tommy Chau, CC BY)', |
|
98 | - 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368', |
|
99 | - ], |
|
100 | - 'tommy-chau-lion-rock-hill.jpg' => [ |
|
101 | - 'attribution' => 'Lion rock hill (Tommy Chau, CC BY)', |
|
102 | - 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246', |
|
103 | - 'theming' => self::THEMING_MODE_DARK, |
|
104 | - ], |
|
105 | - 'lali-masriera-yellow-bricks.jpg' => [ |
|
106 | - 'attribution' => 'Yellow bricks (Lali Masriera, CC BY)', |
|
107 | - 'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447', |
|
108 | - 'theming' => self::THEMING_MODE_DARK, |
|
109 | - ] |
|
110 | - ]; |
|
111 | - /** |
|
112 | - * @var IRootFolder |
|
113 | - */ |
|
114 | - private $rootFolder; |
|
115 | - /** |
|
116 | - * @var IAppData |
|
117 | - */ |
|
118 | - private $appData; |
|
119 | - /** |
|
120 | - * @var IConfig |
|
121 | - */ |
|
122 | - private $config; |
|
123 | - private $userId; |
|
45 | + public const SHIPPED_BACKGROUNDS = [ |
|
46 | + 'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [ |
|
47 | + 'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)', |
|
48 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg', |
|
49 | + ], |
|
50 | + 'bernie-cetonia-aurata-take-off-composition.jpg' => [ |
|
51 | + 'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)', |
|
52 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg', |
|
53 | + 'theming' => self::THEMING_MODE_DARK, |
|
54 | + ], |
|
55 | + 'dejan-krsmanovic-ribbed-red-metal.jpg' => [ |
|
56 | + 'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)', |
|
57 | + 'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/', |
|
58 | + ], |
|
59 | + 'eduardo-neves-pedra-azul.jpg' => [ |
|
60 | + 'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)', |
|
61 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg', |
|
62 | + ], |
|
63 | + 'european-space-agency-barents-bloom.jpg' => [ |
|
64 | + 'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)', |
|
65 | + 'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom', |
|
66 | + ], |
|
67 | + 'hannes-fritz-flippity-floppity.jpg' => [ |
|
68 | + 'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)', |
|
69 | + 'attribution_url' => 'http://hannes.photos/flippity-floppity', |
|
70 | + ], |
|
71 | + 'hannes-fritz-roulette.jpg' => [ |
|
72 | + 'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)', |
|
73 | + 'attribution_url' => 'http://hannes.photos/roulette', |
|
74 | + ], |
|
75 | + 'hannes-fritz-sea-spray.jpg' => [ |
|
76 | + 'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)', |
|
77 | + 'attribution_url' => 'http://hannes.photos/sea-spray', |
|
78 | + ], |
|
79 | + 'kamil-porembinski-clouds.jpg' => [ |
|
80 | + 'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)', |
|
81 | + 'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/', |
|
82 | + ], |
|
83 | + 'bernard-spragg-new-zealand-fern.jpg' => [ |
|
84 | + 'attribution' => 'New zealand fern (Bernard Spragg, CC0)', |
|
85 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg', |
|
86 | + ], |
|
87 | + 'rawpixel-pink-tapioca-bubbles.jpg' => [ |
|
88 | + 'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)', |
|
89 | + 'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/', |
|
90 | + 'theming' => self::THEMING_MODE_DARK, |
|
91 | + ], |
|
92 | + 'nasa-waxing-crescent-moon.jpg' => [ |
|
93 | + 'attribution' => 'Waxing crescent moon (NASA, Public Domain)', |
|
94 | + 'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon', |
|
95 | + ], |
|
96 | + 'tommy-chau-already.jpg' => [ |
|
97 | + 'attribution' => 'Cityscape (Tommy Chau, CC BY)', |
|
98 | + 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368', |
|
99 | + ], |
|
100 | + 'tommy-chau-lion-rock-hill.jpg' => [ |
|
101 | + 'attribution' => 'Lion rock hill (Tommy Chau, CC BY)', |
|
102 | + 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246', |
|
103 | + 'theming' => self::THEMING_MODE_DARK, |
|
104 | + ], |
|
105 | + 'lali-masriera-yellow-bricks.jpg' => [ |
|
106 | + 'attribution' => 'Yellow bricks (Lali Masriera, CC BY)', |
|
107 | + 'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447', |
|
108 | + 'theming' => self::THEMING_MODE_DARK, |
|
109 | + ] |
|
110 | + ]; |
|
111 | + /** |
|
112 | + * @var IRootFolder |
|
113 | + */ |
|
114 | + private $rootFolder; |
|
115 | + /** |
|
116 | + * @var IAppData |
|
117 | + */ |
|
118 | + private $appData; |
|
119 | + /** |
|
120 | + * @var IConfig |
|
121 | + */ |
|
122 | + private $config; |
|
123 | + private $userId; |
|
124 | 124 | |
125 | - public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, $userId) { |
|
126 | - if ($userId === null) { |
|
127 | - return; |
|
128 | - } |
|
129 | - $this->rootFolder = $rootFolder; |
|
130 | - $this->appData = $appData; |
|
131 | - $this->config = $config; |
|
132 | - $this->userId = $userId; |
|
133 | - } |
|
125 | + public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, $userId) { |
|
126 | + if ($userId === null) { |
|
127 | + return; |
|
128 | + } |
|
129 | + $this->rootFolder = $rootFolder; |
|
130 | + $this->appData = $appData; |
|
131 | + $this->config = $config; |
|
132 | + $this->userId = $userId; |
|
133 | + } |
|
134 | 134 | |
135 | - public function setDefaultBackground(): void { |
|
136 | - $this->config->deleteUserValue($this->userId, 'dashboard', 'background'); |
|
137 | - } |
|
135 | + public function setDefaultBackground(): void { |
|
136 | + $this->config->deleteUserValue($this->userId, 'dashboard', 'background'); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param $path |
|
141 | - * @throws NotFoundException |
|
142 | - * @throws NotPermittedException |
|
143 | - * @throws LockedException |
|
144 | - * @throws PreConditionNotMetException |
|
145 | - * @throws NoUserException |
|
146 | - */ |
|
147 | - public function setFileBackground($path): void { |
|
148 | - $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom'); |
|
149 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
150 | - /** @var File $file */ |
|
151 | - $file = $userFolder->get($path); |
|
152 | - $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r')); |
|
153 | - } |
|
139 | + /** |
|
140 | + * @param $path |
|
141 | + * @throws NotFoundException |
|
142 | + * @throws NotPermittedException |
|
143 | + * @throws LockedException |
|
144 | + * @throws PreConditionNotMetException |
|
145 | + * @throws NoUserException |
|
146 | + */ |
|
147 | + public function setFileBackground($path): void { |
|
148 | + $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom'); |
|
149 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
150 | + /** @var File $file */ |
|
151 | + $file = $userFolder->get($path); |
|
152 | + $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r')); |
|
153 | + } |
|
154 | 154 | |
155 | - public function setShippedBackground($fileName): void { |
|
156 | - if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) { |
|
157 | - throw new InvalidArgumentException('The given file name is invalid'); |
|
158 | - } |
|
159 | - $this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName); |
|
160 | - } |
|
155 | + public function setShippedBackground($fileName): void { |
|
156 | + if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) { |
|
157 | + throw new InvalidArgumentException('The given file name is invalid'); |
|
158 | + } |
|
159 | + $this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName); |
|
160 | + } |
|
161 | 161 | |
162 | - public function setColorBackground(string $color): void { |
|
163 | - if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
164 | - throw new InvalidArgumentException('The given color is invalid'); |
|
165 | - } |
|
166 | - $this->config->setUserValue($this->userId, 'dashboard', 'background', $color); |
|
167 | - } |
|
162 | + public function setColorBackground(string $color): void { |
|
163 | + if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
164 | + throw new InvalidArgumentException('The given color is invalid'); |
|
165 | + } |
|
166 | + $this->config->setUserValue($this->userId, 'dashboard', 'background', $color); |
|
167 | + } |
|
168 | 168 | |
169 | - public function getBackground(): ?ISimpleFile { |
|
170 | - $background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'); |
|
171 | - if ($background === 'custom') { |
|
172 | - try { |
|
173 | - return $this->getAppDataFolder()->getFile('background.jpg'); |
|
174 | - } catch (NotFoundException | NotPermittedException $e) { |
|
175 | - } |
|
176 | - } |
|
177 | - return null; |
|
178 | - } |
|
169 | + public function getBackground(): ?ISimpleFile { |
|
170 | + $background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'); |
|
171 | + if ($background === 'custom') { |
|
172 | + try { |
|
173 | + return $this->getAppDataFolder()->getFile('background.jpg'); |
|
174 | + } catch (NotFoundException | NotPermittedException $e) { |
|
175 | + } |
|
176 | + } |
|
177 | + return null; |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * @return ISimpleFolder |
|
182 | - * @throws NotPermittedException |
|
183 | - */ |
|
184 | - private function getAppDataFolder(): ISimpleFolder { |
|
185 | - try { |
|
186 | - return $this->appData->getFolder($this->userId); |
|
187 | - } catch (NotFoundException $e) { |
|
188 | - return $this->appData->newFolder($this->userId); |
|
189 | - } |
|
190 | - } |
|
180 | + /** |
|
181 | + * @return ISimpleFolder |
|
182 | + * @throws NotPermittedException |
|
183 | + */ |
|
184 | + private function getAppDataFolder(): ISimpleFolder { |
|
185 | + try { |
|
186 | + return $this->appData->getFolder($this->userId); |
|
187 | + } catch (NotFoundException $e) { |
|
188 | + return $this->appData->newFolder($this->userId); |
|
189 | + } |
|
190 | + } |
|
191 | 191 | } |