1#!/usr/local/bin/python3.8
2
3# Copyright (C) 2007-2010 www.stani.be
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see http://www.gnu.org/licenses/
17
18import platform
19import os
20
21from gi.repository import Gio, GObject
22
23
24class CManager():
25    def __init__(self):
26        self.extension_point = Gio.io_extension_point_register ("cinnamon-control-center-1")
27        self.modules = []
28
29        architecture = platform.machine()
30        paths = ["/usr/local/lib"]
31
32        # On x86 archs, iterate through multiple paths
33        # For instance, on a Mint i686 box, the path is actually /usr/local/lib/i386-linux-gnu
34        x86archs = ["i386", "i486", "i586", "i686"]
35        if architecture in x86archs:
36            for arch in x86archs:
37                paths += ["/usr/local/lib/%s" % arch, "/usr/local/lib/%s-linux-gnu" % arch]
38        elif architecture == "x86_64":
39            paths += ["/usr/local/lib/x86_64", "/usr/local/lib/x86_64-linux-gnu", "/usr/local/lib64"]
40        else:
41            paths += ["/usr/local/lib/%s" % architecture, "/usr/local/lib/%s-linux-gnu" % architecture]
42
43        for path in paths:
44            if not os.path.islink(path):
45                path = os.path.join(path, "cinnamon-control-center-1/panels")
46                if os.path.exists(path):
47                    try:
48                        self.modules = self.modules + Gio.io_modules_load_all_in_directory(path)
49                    except Exception as e:
50                        print("capi failed to load multiarch modules from %s: " % path, e)
51
52    def get_c_widget(self, mod_id):
53        extension = self.extension_point.get_extension_by_name(mod_id)
54        if extension is None:
55            print("Could not load %s module; is the cinnamon-control-center package installed?" % mod_id)
56            return None
57        panel_type = extension.get_type()
58        return GObject.new(panel_type)
59
60    def lookup_c_module(self, mod_id):
61        extension = self.extension_point.get_extension_by_name(mod_id)
62        if extension is None:
63            print("Could not find %s module; is the cinnamon-control-center package installed?" % mod_id)
64            return False
65        else:
66            return True
67