1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2018-2020 Matias De lellis <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @author Matias De lellis <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\FaceRecognition\Settings; |
26
|
|
|
|
27
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
28
|
|
|
use OCP\IL10N; |
29
|
|
|
use OCP\Settings\ISettings; |
30
|
|
|
use OCP\Util as OCP_Util; |
31
|
|
|
|
32
|
|
|
use OCA\FaceRecognition\Helper\MemoryLimits; |
33
|
|
|
|
34
|
|
|
use OCA\FaceRecognition\Model\IModel; |
35
|
|
|
use OCA\FaceRecognition\Model\ModelManager; |
36
|
|
|
|
37
|
|
|
use OCA\FaceRecognition\Service\SettingsService; |
38
|
|
|
|
39
|
|
|
class Admin implements ISettings { |
40
|
|
|
|
41
|
|
|
/** @var ModelManager */ |
42
|
|
|
public $modelManager; |
43
|
|
|
|
44
|
|
|
/** @var SettingsService */ |
45
|
|
|
public $settingsService; |
46
|
|
|
|
47
|
|
|
/** @var MemoryLimits */ |
48
|
|
|
public $memoryLimits; |
49
|
|
|
|
50
|
|
|
/** @var IL10N */ |
51
|
|
|
protected $l10n; |
52
|
|
|
|
53
|
|
|
public function __construct(ModelManager $modelManager, |
54
|
|
|
SettingsService $settingsService, |
55
|
|
|
MemoryLimits $memoryLimits, |
56
|
|
|
IL10N $l10n) |
57
|
|
|
{ |
58
|
|
|
$this->modelManager = $modelManager; |
59
|
|
|
$this->settingsService = $settingsService; |
60
|
|
|
$this->memoryLimits = $memoryLimits; |
61
|
|
|
$this->l10n = $l10n; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getPriority() { |
65
|
|
|
return 20; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getSection() { |
69
|
|
|
return 'facerecognition'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getForm() { |
73
|
|
|
|
74
|
|
|
$isConfigured = true; |
75
|
|
|
$maxImageRange = "8294400"; |
76
|
|
|
$resume = ''; |
77
|
|
|
|
78
|
|
|
$model = $this->modelManager->getCurrentModel(); |
79
|
|
|
if (!is_null($model)) { |
80
|
|
|
try { |
81
|
|
|
$model->open(); |
82
|
|
|
$maxImageRange = strval($model->getMaximumArea()); |
83
|
|
|
} catch (\Exception $e) { |
84
|
|
|
$resume .= $e->getMessage(); |
85
|
|
|
$isConfigured = false; |
86
|
|
|
} |
87
|
|
|
} else { |
88
|
|
|
$resume .= $this->l10n->t("It seems you don't have any model installed."); |
89
|
|
|
$isConfigured = false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$assignedMemory = $this->settingsService->getAssignedMemory(); |
93
|
|
|
if ($assignedMemory === SettingsService::DEFAULT_ASSIGNED_MEMORY) { |
94
|
|
|
$resume = $this->l10n->t("Seems that you still have to configure the assigned memory for image processing."); |
95
|
|
|
$isConfigured = false; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$params = [ |
99
|
|
|
'is-configured' => $isConfigured, |
100
|
|
|
'model-version' => is_null($model) ? $this->l10n->t("Not installed") : $model->getId(), |
101
|
|
|
'assigned-memory' => $assignedMemory > 0 ? OCP_Util::humanFileSize($assignedMemory) : $this->l10n->t("Not configured."), |
102
|
|
|
'max-image-range' => $maxImageRange, |
103
|
|
|
'resume' => $resume, |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
return new TemplateResponse('facerecognition', 'settings/admin', $params, ''); |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|