~azzar1/unity/lock-autologin

« back to all changes in this revision

Viewing changes to tools/unity_active_plugins_safety_check.cpp

Add tools to enforce unityshell plugin for the current profile and add "move" and "resize" plugins as requirements. (LP: #1506023, #1605007)

Approved by: Marco Trevisan (Treviño)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
 
17
 */
 
18
 
 
19
#include <ccs.h>
 
20
#include <gio/gio.h>
 
21
 
 
22
#include <iostream>
 
23
#include <string>
 
24
 
 
25
extern const CCSInterfaceTable ccsDefaultInterfaceTable;
 
26
 
 
27
void PluginSetActiveWithDeps(CCSContext* context, std::string const& plugin_name)
 
28
{
 
29
  if (plugin_name.empty())
 
30
    return;
 
31
 
 
32
  auto plugin = ccsFindPlugin(context, plugin_name.c_str());
 
33
 
 
34
  if (!plugin)
 
35
    return;
 
36
 
 
37
  auto reqs = ccsPluginGetRequiresPlugins(plugin);
 
38
  for (auto req = reqs; req; req = req->next)
 
39
  {
 
40
    if (req->data && req->data->value)
 
41
    {
 
42
      std::string name = req->data->value;
 
43
      PluginSetActiveWithDeps(context, name.c_str());
 
44
    }
 
45
  }
 
46
 
 
47
  if (!ccsPluginIsActive(context, plugin_name.c_str())) {
 
48
    std::cout << "Setting plugin '" << plugin_name << "' to active" << std::endl;
 
49
    ccsPluginSetActive(plugin, true);
 
50
  }
 
51
 
 
52
  auto conflicts = ccsPluginGetConflictPlugins(plugin);
 
53
  for (auto con = conflicts; con; con = con->next)
 
54
  {
 
55
    if (con->data && con->data->value)
 
56
    {
 
57
      std::string name = con->data->value;
 
58
      auto plugin = ccsFindPlugin(context, name.c_str());
 
59
 
 
60
      if (ccsPluginIsActive(context, name.c_str()))
 
61
      {
 
62
        std::cout << "Setting plugin '" << name << "' to non-active" << std::endl;
 
63
        ccsPluginSetActive(plugin, false);
 
64
      }
 
65
    }
 
66
  }
 
67
}
 
68
 
 
69
int main()
 
70
{
 
71
  auto context = ccsContextNew (0, &ccsDefaultInterfaceTable);
 
72
 
 
73
  if (!context)
 
74
    return -1;
 
75
 
 
76
  PluginSetActiveWithDeps(context, "unityshell");
 
77
 
 
78
  ccsWriteChangedSettings(context);
 
79
  g_settings_sync();
 
80
  ccsFreeContext(context);
 
81
 
 
82
  return 0;
 
83
}