blob: b9dcdc8382743d0dbc49afb50e4e83ecbc475bed [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{
55 auto accIt = preferences_.find("default");
56 if (!accountId.empty())
57 accIt = preferences_.emplace(accountId, preferences_["default"]).first;
58
59 auto it = accIt->second.find(key);
60 if (it != accIt->second.end() && it->second != value) {
61 it->second = value;
62 }
63 wmh_->setParameters(accountId);
64}
65
66void
67PluginPreferenceHandler::resetPreferenceAttributes(const std::string& accountId)
68{
69 std::lock_guard<std::mutex> lk(mtx_);
70 if (accountId.empty()) {
71 preferences_.clear();
72 api_->invokeService(api_, "getPluginAccPreferences", &preferences_);
73 } else
74 preferences_[accountId] = preferences_["default"];
75 wmh_->setParameters(accountId);
76}
77
78bool
79PluginPreferenceHandler::preferenceMapHasKey(const std::string& key)
80{
81 return (key == "showlogo" || key == "mark" || key == "markbackground" || key == "logosize"
82 || key == "showinfos" || key == "location" || key == "date" || key == "time"
83 || key == "infosposition" || key == "logoposition" || key == "timeformat"
84 || key == "timezone" || key == "dateformat" || key == "fontsize");
85}
86
87std::map<std::string, std::string>
88PluginPreferenceHandler::getPreferences(const std::string& accountId)
89{
90 std::lock_guard<std::mutex> lk(mtx_);
91 return preferences_.emplace(accountId, preferences_["default"]).first->second;
92}
93
94PluginPreferenceHandler::~PluginPreferenceHandler()
95{
96 preferences_.clear();
97}
98
99void
100PluginPreferenceHandler::setWaterMarkHandler(WatermarkMediaHandler* handler)
101{
102 wmh_ = handler;
103}
104} // namespace jami