This file is indexed.

/usr/lib/gdesklets/config/ConfigDialog.py is in gdesklets 0.36.1-5.

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

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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
from ConfigBoolean import ConfigBoolean
from ConfigButton import ConfigButton
from ConfigColor import ConfigColor
from ConfigDate import ConfigDate
from ConfigEnum import ConfigEnum
from ConfigFloat import ConfigFloat
from ConfigFont import ConfigFont
from ConfigInfo import ConfigInfo
from ConfigInteger import ConfigInteger
from ConfigList import ConfigList
from ConfigRadio import ConfigRadio
from ConfigString import ConfigString
from ConfigTitle import ConfigTitle
from ConfigUnit import ConfigUnit
from ConfigURI import ConfigURI

from ConfigDPI import ConfigDPI
from ConfigKeyBinding import ConfigKeyBinding

from utils.HIGDialog import HIGDialog

import gtk
import gobject
import os
import os.path


class ConfigDialog(HIGDialog):
    """
      Class for the configuration dialog. This class handles the visualization
      of the dialog and loading / saving the configuration.
    """

    # mapping between item types and their widgets
    __ITEM_TABLE = {"boolean": ConfigBoolean,
                    "button": ConfigButton,
                    "color": ConfigColor,
                    "date": ConfigDate,
                    "enum": ConfigEnum,
                    "float": ConfigFloat,
                    "font": ConfigFont,
                    "info": ConfigInfo,
                    "integer": ConfigInteger,
                    "list": ConfigList,
                    "radio": ConfigRadio,
                    "string": ConfigString,
                    "title": ConfigTitle,
                    "unit": ConfigUnit,
                    "uri": ConfigURI,
                    
                    "dpi": ConfigDPI,
                    "keybinding": ConfigKeyBinding
                    }


    def __init__(self, path):

        # the instantiated items
        self.__children = []

        # getter, setter, and caller for getting and settings values and
        # calling callbacks
        self.__getter = None
        self.__setter = None
        self.__caller = None

        self.__close_callback = None

        # a banner
        self.__banner = None

        self.__path = path

        HIGDialog.__init__(self, buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE),
                           self_destroy = False)

        self.__tooltips = gtk.Tooltips()
        self.__tooltips.enable()


        def destroy(*args):
            if (self.__close_callback): self.__close_callback()
            
            self.hide()
            return True  # return True so that the window doesn't get destroyed

        self.connect("response", destroy)
        self.connect("delete-event", destroy)  # catch the close button as well


    def _set_setter(self, setter): self.__setter = setter
    def _set_getter(self, getter): self.__getter = getter
    def _set_caller(self, caller): self.__caller = caller

    def set_close_callback(self, handler): self.__close_callback = handler


    def _set_value(self, key, value, datatype):

        self.__setter(key, value, datatype)


    def _get_value(self, key):

        return self.__getter(key)


    def _invoke_callback(self, name, *args):

        try:
            self.__caller(name, *args)
        except KeyError:
            raise UserError(_("Invalid Function Call"),
                           _("There is no function called <b>%s</b>.\nThis "
                             "means that there's an error in the desklet's "
                             "code. You should inform the author of the "
                             "desklet about this problem." % (name,)))

        except StandardError, exc:
            log("An unknown error occured: %s" % (exc,))



    #
    # Creates a banner. This method has to be called before building the dialog
    # if a banner is desired.
    #
    def set_banner(self, icon, text):

        self.__banner = gtk.Frame()
        self.__banner.set_shadow_type(gtk.SHADOW_IN)
        self.__banner.show()

        b_box = gtk.HBox(spacing = 12)
        b_box.set_border_width(6)
        b_box.show()
        self.__banner.add(b_box)

        if (icon):
            try:
                # for him who loves small try blocks: you don't gain anything
                # from splitting up this block except for badly readable code ;)
                from utils import vfs
                data = vfs.read_entire_file(icon)
                loader = gtk.gdk.PixbufLoader()
                loader.write(data, len(data))
                loader.close()
                pbuf = loader.get_pixbuf()

                # scale icon down while preserving aspect ratio
                width = pbuf.get_width()
                height = pbuf.get_height()
                scale = 48 / float(height)
                width *= scale
                if (abs(scale - 1.0) > 0.001):
                    pbuf = pbuf.scale_simple(int(width), 48, 3)

                b_icon = gtk.Image()
                b_icon.set_from_pixbuf(pbuf)
                b_icon.show()
                b_box.pack_start(b_icon, False, False)

            except:
                pass

        #end if

        b_label = gtk.Label(text)
        b_label.set_use_markup(True)
        b_label.show()
        b_box.pack_start(b_label, True, True)



    #
    # Creates a configuration item of the given type.
    #
    def __create_config_item(self, itype, settings):

        try:
            itemclass = self.__ITEM_TABLE[itype]
        except KeyError:
            log("No such preferences item: %s" % (itype,))
            return None

        item = itemclass(itype, self._get_value, self._set_value,
                         self._invoke_callback)

        return item



    #
    # Adds a line of configuration widgets to the given page.
    #
    def __add_line(self, page, page_lines, indent, widgets, help):

        ebox = gtk.EventBox()
        ebox.show()

        if (len(widgets) == 2):

            page.attach(widgets[0], 0, 1, page_lines - 1, page_lines,
                        gtk.FILL, gtk.FILL, indent, 3)
            ebox.add(widgets[1])
            page.attach(ebox, 1, 2, page_lines - 1, page_lines,
                        gtk.EXPAND | gtk.FILL, 0, indent, 3)

        else:
            ebox.add(widgets[0])
            page.attach(ebox, 0, 2, page_lines - 1, page_lines,
                        gtk.EXPAND | gtk.FILL, 0, indent, 3)

        if (help):
            self.__tooltips.set_tip(ebox, help)



    #
    # Builds up the dialog. This must be done before loading the configuration.
    #
    def build(self, items):

        if (self.__banner):
            self.vbox.pack_start(self.__banner, False, False)

        if (not items):
            label = gtk.Label(_("This desklet is not configurable."))
            label.show()
            self.vbox.pack_start(label, False, False)

        page_lines = 0
        page = gtk.Table(1, 2)
        page.show()
        notebook = None
        item_list = []
        self.__children = []

        for itype, settings in items:
            if (itype == "page"):
                if (not notebook):
                    align = gtk.Alignment(0.0, 0.0, 0.0, 0.0)
                    align.show()
                    notebook = gtk.Notebook()
                    notebook.set_property("border-width", 6)
                    notebook.show()
                    align.add(notebook)
                    self.vbox.pack_start(align, False, False, 0)

                label = settings.get("label", "")
                tab = gtk.HBox(False, 0)
                tab.set_border_width(2)

                labelbox = gtk.Label(label)

                tab.pack_end(labelbox, True, True, 3)

                image = gtk.Image()
                icon = settings.get("icon", "")
                if (icon):
                    icon = os.path.join(self.__path, icon)

                # scale down images that are higher than the label
                if os.path.exists(icon):
                    (labelx, labely) = labelbox.size_request()
                    pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.realpath(icon))
                    icon_width = pixbuf.get_width()
                    icon_height = pixbuf.get_height()
                    if (icon_height > labely):
                        icon_aspectratio = float(icon_width) / icon_height
                        icon_height = labely
                        icon_width = int(icon_aspectratio * icon_height)
                    scaled_buf = pixbuf.scale_simple(icon_width,icon_height,gtk.gdk.INTERP_BILINEAR)
                    image.set_from_pixbuf(scaled_buf)
                    tab.pack_start(image, False, False, 3)
                    image.show()

                labelbox.show() 
                tab.show()
                box = gtk.VBox()
                box.set_property("border-width", 12)
                box.show()
                box.add(page)
                notebook.append_page(box, tab)

                # create a new page
                page_lines = 0
                page = gtk.Table(1, 2)
                page.show()

            elif (itype == "item"):
                label = settings.get("label", "")
                value = settings.get("value", "")
                item_list.append((label, value))

            else:
                configitem = self.__create_config_item(itype, settings)
                if (not configitem): continue

                if (itype == "radio"): widgets = configitem.get_widgets(item_list)
                else: widgets = configitem.get_widgets()

                if (itype not in ("title", "button")):
                    configitem.set_prop_from_string("bind", settings["bind"])
                if (itype == "enum"): configitem.set_prop("items", item_list)
                if (itype == "list"): configitem.set_prop("items", item_list)
                if (itype == "radio"): configitem.set_prop("items", item_list)
                for k, v in settings.items():
                    configitem.set_prop_from_string(k, v)

                help = settings.get("help", "")

                indent = (itype != "title") and 12 or 0
                page_lines += 1
                page.resize(page_lines, 2)
                if (itype == "title" and page_lines != 1):
                    # keep some HIGgy space above the title, but not if it's
                    # the first line
                    w, h = widgets[0].size_request()
                    widgets[0].set_size_request(-1, h + 12)
                self.__add_line(page, page_lines, indent, widgets, help)
                if (itype != "title"):
                    self.__children.append(configitem)

                item_list = []

            #end if

        #end for

        # add the only page manually if there's no notebook
        if (not notebook):
            self.vbox.pack_start(page, False, False, 0)


    #
    # Returns a list of the config items.
    #
    def get_config_items(self):

        return self.__children


    #
    # Sets the current working directory.
    #
    def set_path(self, path):

        for c in self.get_config_items(): c.set_path(path)


    #
    # Refine the show() method to update the configuration widgets.
    #
    def show(self):

        # have the children update themselves
        for c in self.get_config_items(): c.update()

        self.present()

        # run the updater
        gobject.timeout_add(500, self.__updater)



    def __updater(self):

        for c in self.get_config_items(): c.update()

        # stop the timer if the dialog is no longer visible
        if (self.get_property("visible")):
            return True
        else:
            return False