blob: 1f4702437d843d16baefda9edb0f0c647aea02b2 [file] [log] [blame]
agsantos3fcc6212021-08-18 17:11:29 -03001/**
2 * Copyright (C) 2021 Savoir-faire Linux Inc.
3 *
4 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "PluginPreferenceHandler.h"
22
23#include "WatermarkMediaHandler.h"
24#include "pluglog.h"
25
26const char sep = separator();
27const std::string TAG = "WaterMarkAcc";
28
29#define NAME "WaterMarkAcc"
30
31namespace jami {
32
33PluginPreferenceHandler::PluginPreferenceHandler(
34 const JAMI_PluginAPI* api,
35 std::map<std::string, std::map<std::string, std::string>>&& preferences,
36 const std::string& dataPath)
37 : api_ {api}
38 , datapath_ {dataPath}
39{
40 preferences_ = preferences;
41 setId(datapath_);
42};
43
44std::map<std::string, std::string>
45PluginPreferenceHandler::getHandlerDetails()
46{
47 return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.svg"}, {"pluginId", id()}};
48}
49
50void
51PluginPreferenceHandler::setPreferenceAttribute(const std::string& accountId,
52 const std::string& key,
53 const std::string& value)
54{
Aline Gondim Santos46c74062022-10-11 09:42:29 -030055 if (accountId.empty()) {
56 for (auto& prefMap : preferences_) {
57 auto it = prefMap.second.find(key);
58 if (it != prefMap.second.end() && it->second != value) {
59 it->second = value;
60 }
61 }
62 } else {
63 auto accIt = preferences_.find("default");
agsantos3fcc6212021-08-18 17:11:29 -030064 accIt = preferences_.emplace(accountId, preferences_["default"]).first;
Aline Gondim Santos46c74062022-10-11 09:42:29 -030065 auto it = accIt->second.find(key);
66 if (it != accIt->second.end() && it->second != value) {
67 it->second = value;
68 }
agsantos3fcc6212021-08-18 17:11:29 -030069 }
Aline Gondim Santos46c74062022-10-11 09:42:29 -030070
agsantos3fcc6212021-08-18 17:11:29 -030071 wmh_->setParameters(accountId);
72}
73
74void
75PluginPreferenceHandler::resetPreferenceAttributes(const std::string& accountId)
76{
77 std::lock_guard<std::mutex> lk(mtx_);
78 if (accountId.empty()) {
79 preferences_.clear();
80 api_->invokeService(api_, "getPluginAccPreferences", &preferences_);
81 } else
82 preferences_[accountId] = preferences_["default"];
83 wmh_->setParameters(accountId);
84}
85
86bool
87PluginPreferenceHandler::preferenceMapHasKey(const std::string& key)
88{
89 return (key == "showlogo" || key == "mark" || key == "markbackground" || key == "logosize"
90 || key == "showinfos" || key == "location" || key == "date" || key == "time"
91 || key == "infosposition" || key == "logoposition" || key == "timeformat"
92 || key == "timezone" || key == "dateformat" || key == "fontsize");
93}
94
95std::map<std::string, std::string>
96PluginPreferenceHandler::getPreferences(const std::string& accountId)
97{
98 std::lock_guard<std::mutex> lk(mtx_);
99 return preferences_.emplace(accountId, preferences_["default"]).first->second;
100}
101
102PluginPreferenceHandler::~PluginPreferenceHandler()
103{
104 preferences_.clear();
105}
106
107void
108PluginPreferenceHandler::setWaterMarkHandler(WatermarkMediaHandler* handler)
109{
110 wmh_ = handler;
111}
112} // namespace jami