This file is indexed.

/usr/share/cinnamon/cinnamon-settings/bin/XletSettings.py is in cinnamon-common 2.8.6-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/usr/bin/env python2

import sys

try:
    import os
    import glob
    import gettext
    import json
    import collections
    import XletSettingsWidgets
    import dbus
    from SettingsWidgets import SectionBg
    from gi.repository import Gio, Gtk, GObject, GdkPixbuf
except Exception, detail:
    print detail
    sys.exit(1)

home = os.path.expanduser("~")

translations = {}

def translate(uuid, string):
    #check for a translation for this xlet
    if uuid not in translations:
        try:
            translations[uuid] = gettext.translation(uuid, home + "/.local/share/locale").ugettext
        except IOError:
            try:
                translations[uuid] = gettext.translation(uuid, "/usr/share/locale").ugettext
            except IOError:
                translations[uuid] = None

    #do not translate whitespaces
    if not string.strip():
        return string

    if translations[uuid]:
        result = translations[uuid](string)
        if result != string:
            return result
    return _(string)

class XletSetting:

    def __init__(self, uuid, parent, _type):
        self.parent = parent
        self.type = _type
        self.current_id = None
        self.builder = Gtk.Builder()
        self.builder.add_from_file("/usr/share/cinnamon/cinnamon-settings/bin/xlet-settings.ui")
        self.content = self.builder.get_object("content")
        self.back_to_list_button = self.builder.get_object("back_to_list")
        self.highlight_button = self.builder.get_object("highlight_button")
        self.more_button = self.builder.get_object("more_button")
        self.remove_button = self.builder.get_object("remove_xlet")
        self.uuid = uuid
        self.content.connect("hide", self.on_hide)

        self.applet_meta = {}
        self.applet_settings = collections.OrderedDict()
        self.setting_factories = collections.OrderedDict()
        self.load_applet_data (self.uuid)
        if "icon" in self.applet_meta:
            image = Gtk.Image().new_from_icon_name(self.applet_meta["icon"], Gtk.IconSize.BUTTON)
            self.back_to_list_button.set_image(image)
            self.back_to_list_button.get_property('image').set_padding(5, 0)
        self.back_to_list_button.set_label(translate(uuid, self.applet_meta["name"]))
        self.back_to_list_button.set_tooltip_text(_("Back to list"))
        self.more_button.set_tooltip_text(_("More actions..."))
        self.remove_button.set_label(_("Remove"))
        self.remove_button.set_tooltip_text(_("Remove the current instance of this %s") % self.type)
        self.highlight_button.set_label(_("Highlight"))
        self.highlight_button.set_tooltip_text(_("Momentarily highlight the %s on your desktop") % self.type)
        if len(self.applet_settings.keys()) > 1:
            self.build_notebook()
        else:
            self.build_single()
        self.back_to_list_button.connect("clicked", self.on_back_to_list_button_clicked)
        if self.type != "extension":
            self.highlight_button.connect("clicked", self.on_highlight_button_clicked)
            self.highlight_button.show()
        else:
            self.highlight_button.hide()
        self.more_button.connect("clicked", self.on_more_button_clicked)
        self.remove_button.connect("clicked", self.on_remove_button_clicked)

    def show (self):
        self.content.show_all()
        try:
            self.back_to_list_button.get_property('image').show()
        except:
            pass

    def on_hide (self, widget):
        self.content.hide()
        self.content.destroy()
        self.applet_meta = None
        self.applet_settings = None
        for _id in self.setting_factories.keys():
            self.setting_factories[_id].pause_monitor()
        self.setting_factories = None

    def load_applet_data (self, uuid):
        found = self.get_meta_data_for_applet("/usr/share/cinnamon/%ss/%s" % (self.type, uuid))
        if not found:
            found = self.get_meta_data_for_applet("%s/.local/share/cinnamon/%ss/%s" % (home, self.type, uuid))
        if not found:
            print("Could not find %s metadata - are you sure it's installed correctly?" % self.type)
            return
        found = self.get_settings_for_applet("%s/.cinnamon/configs/%s" % (home, uuid))
        if not found:
            print("Could not find any instance settings data for this %s - are you sure it is loaded, and supports settings?" % self.type)

    def get_meta_data_for_applet(self, path):
        if os.path.exists(path) and os.path.isdir(path):
            if os.path.exists("%s/metadata.json" % path):
                raw_data = open("%s/metadata.json" % path).read()
                self.applet_meta = json.loads(raw_data.decode('utf-8'))
                return True
        return False

    def get_settings_for_applet(self, path):
        if "max-instances" in self.applet_meta:
            try:
                self.multi_instance = int(self.applet_meta["max-instances"]) != 1
            except:
                self.multi_instance = False
        else:
            self.multi_instance = False
        if os.path.exists(path) and os.path.isdir(path):
            instances = sorted(os.listdir(path))
            if len(instances) != 0:
                for instance in instances:
                    raw_data = open("%s/%s" % (path, instance)).read()
                    try:
                        js = json.loads(raw_data.decode('utf-8'), object_pairs_hook=collections.OrderedDict)
                    except:
                        raise Exception("Failed to parse settings JSON data for %s %s" % (self.type, self.uuid))
                    instance_id = instance.split(".json")[0]
                    self.applet_settings[instance_id] = js
                    self.setting_factories[instance_id] = XletSettingsWidgets.Factory("%s/%s" % (path, instance), instance_id, self.multi_instance, self.uuid)
                return True
            else:
                raise Exception("Could not find any active setting files for %s %s" % (self.type, self.uuid))
        return False

    def build_single(self):
        self.nb = None
        self.view = SectionBg()
        self.content_box = Gtk.VBox()
        self.view.add(self.content_box)
        self.content_box.set_border_width(5)

        for instance_key in self.applet_settings.keys():
            for setting_key in self.applet_settings[instance_key].keys():
                if setting_key == "__md5__" or self.applet_settings[instance_key][setting_key]["type"] == "generic":
                    continue
                self.setting_factories[instance_key].create(setting_key,
                                                            self.applet_settings[instance_key][setting_key]["type"],
                                                            self.uuid)
            widgets = self.setting_factories[instance_key].widgets
            for widget_key in widgets.keys():
                if widgets[widget_key].get_indented():
                    indent = XletSettingsWidgets.IndentedHBox()
                    indent.add_fill(widgets[widget_key])
                    self.content_box.pack_start(indent, False, False, 2)
                else:
                    self.content_box.pack_start(widgets[widget_key], False, False, 2)
                if len(widgets[widget_key].dependents) > 0:
                    widgets[widget_key].update_dependents()
            self.current_id = instance_key
        self.content.pack_start(self.view, True, True, 2)

    def build_notebook(self):
        self.nb = Gtk.Notebook()
        i = 0
        target_instance = -1
        target_page = -1
        if len(sys.argv) > 3:
            target_instance = sys.argv[3]

        for instance_key in self.applet_settings.keys():

            view = Gtk.ScrolledWindow()
            content_box = Gtk.VBox()
            view.add_with_viewport(content_box)
            content_box.set_border_width(5)
            for setting_key in self.applet_settings[instance_key].keys():
                if setting_key == "__md5__" or self.applet_settings[instance_key][setting_key]["type"] == "generic":
                    continue
                self.setting_factories[instance_key].create(setting_key,
                                                            self.applet_settings[instance_key][setting_key]["type"],
                                                            self.uuid)
            widgets = self.setting_factories[instance_key].widgets
            for widget_key in widgets.keys():
                if widgets[widget_key].get_indented():
                    indent = XletSettingsWidgets.IndentedHBox()
                    indent.add_fill(widgets[widget_key])
                    content_box.pack_start(indent, False, False, 2)
                else:
                    content_box.pack_start(widgets[widget_key], False, False, 2)
                if len(widgets[widget_key].dependents) > 0:
                    widgets[widget_key].update_dependents()
            view.show()
            self.nb.append_page(view, Gtk.Label.new(_("Instance %d") % (i + 1)))
            view.key = instance_key
            
            if target_instance == -1:
                target_instance = instance_key
                self.current_id = instance_key

            if view.key == target_instance:
                target_page = i

            i += 1

        self.content.pack_start(self.nb, True, True, 2)
        self.nb.set_scrollable(True)

        if target_page != -1:
            self.nb.set_current_page(target_page)

        self.nb.connect("switch-page", self.on_page_changed)

    def on_page_changed(self, nb, page, num):
        self.current_id = page.key

    def on_highlight_button_clicked(self, widget):
        session_bus = dbus.SessionBus()
        cinnamon_dbus = session_bus.get_object("org.Cinnamon", "/org/Cinnamon")
        highlight_applet = cinnamon_dbus.get_dbus_method('highlightApplet', 'org.Cinnamon')
        highlight_applet(self.uuid, self.current_id)

    def on_back_to_list_button_clicked(self, widget):
        self.parent._close_configure(self)

    def on_remove_button_clicked(self, widget):
        settings = Gio.Settings.new("org.cinnamon")
        if self.type == "applet":
            enabled_xlets = settings.get_strv("enabled-applets")
        elif self.type == "desklet":
            enabled_xlets = settings.get_strv("enabled-desklets")
        elif self.type == "extension":
            enabled_xlets = settings.get_strv("enabled-extensions")
        else:
            return
        new_enabled = []
        for xlet in enabled_xlets:
            if self.uuid not in xlet:
                new_enabled.append(xlet)
            elif self.multi_instance and self.current_id not in xlet:
                new_enabled.append(xlet)

        if self.nb is None or (self.nb is not None and self.nb.get_n_pages() == 1):
            self.parent._close_configure(self)
        else:
            current_index = self.nb.get_current_page()
            tab = self.nb.get_nth_page(current_index)
            self.setting_factories[self.current_id].pause_monitor()
            self.nb.remove_page(current_index)
            tab.destroy()
            self.nb.set_current_page(0)

        if self.type == "applet":
            settings.set_strv("enabled-applets", new_enabled)
        elif self.type == "desklet":
            settings.set_strv("enabled-desklets", new_enabled)
        elif self.type == "extension":
            settings.set_strv("enabled-extensions", new_enabled)


    def on_more_button_clicked(self, widget):
        popup = Gtk.Menu()
        popup.attach_to_widget(widget, None)

        reset_option = Gtk.MenuItem(_("Reset to defaults"))
        popup.append(reset_option)
        reset_option.connect("activate", self.on_reset_defaults)
        reset_option.show()

        import_option = Gtk.MenuItem(_("Import from a file"))
        popup.append(import_option)
        import_option.connect("activate", self.on_import)
        import_option.show()

        export_option = Gtk.MenuItem(_("Export to a file"))
        popup.append(export_option)
        export_option.connect("activate", self.on_export)
        export_option.show()

        popup.popup(None, None, None, None, 0, 0)

    def on_reset_defaults(self, popup):
        self.setting_factories[self.current_id].reset_to_defaults()

    def on_import(self, popup):
        dialog = Gtk.FileChooserDialog(_("Select a JSON file to import"),
                                       None,
                                       Gtk.FileChooserAction.OPEN,
                                      (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        filter_text = Gtk.FileFilter()
        filter_text.add_pattern("*.json")
        filter_text.set_name(_("JSON files"))
        dialog.add_filter(filter_text)

        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            filename = dialog.get_filename()
            self.setting_factories[self.current_id].load_from_file(filename)

        dialog.destroy()

    def on_export(self, popup):
        dialog = Gtk.FileChooserDialog(_("Select or enter file to export to"),
                                       None,
                                       Gtk.FileChooserAction.SAVE,
                                      (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                       Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT))
        dialog.set_do_overwrite_confirmation(True)
        filter_text = Gtk.FileFilter()
        filter_text.add_pattern("*.json")
        filter_text.set_name(_("JSON files"))
        dialog.add_filter(filter_text)

        response = dialog.run()

        if response == Gtk.ResponseType.ACCEPT:
            filename = dialog.get_filename()
            if ".json" not in filename:
                filename = filename + ".json"
            self.setting_factories[self.current_id].export_to_file(filename)

        dialog.destroy()