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