This file is indexed.

/usr/bin/ladi-control-center is in laditools 1.0.1-2.

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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/usr/bin/python

# LADITools - Linux Audio Desktop Integration Tools
# ladi-control-center - A configuration GUI for your Linux Audio Desktop
# Copyright (C) 2011-2012 Alessio Treglia <quadrispro@ubuntu.com>
# Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
# Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
# Copyright (C) 2008, Krzysztof Foltman <wdev@foltman.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import gettext
import argparse

from laditools import _gettext_domain
gettext.install(_gettext_domain)

from laditools import get_version_string
from laditools import check_ladish
from laditools import LadishProxy
from laditools import LadishStatusType
from laditools import LadishProxyError
from laditools import JackConfigProxy
from laditools import JackConfigParameter as parameter
from laditools import LadiApp

from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject

from laditools.gtk import find_data_file

tooltips_active = True

(COLUMN_NAME,
 COLUMN_PARAMETER,
 COLUMN_SHORTDESC,
 COLUMN_LONGDESC,
 COLUMN_ISSET) = range (5)

def _check_ladish():
    try:
        ret = check_ladish()
    except LadishProxyError as e:
        sys.stderr.write("%s\n" % str(e))
        sys.stderr.flush()
        sys.exit(1)
    except Exception as e:
        sys.stderr.write(_("ladish proxy creation failed: %s\n") % str(e))
        sys.stderr.flush()
        sys.exit(1)
    if ret == LadishStatusType.STUDIO_STOPPED:
        # Everything is OK, there's no need to print out a message
        #sys.stderr.write(_("ladish studio is loaded and not started\n"))
        #sys.stderr.flush()
        return False
    elif ret == LadishStatusType.NOT_AVAILABLE:
        sys.stderr.write(_("ladish is not available\n"))
        sys.stderr.flush()
        sys.exit(1)
    else:
        if ret == LadishStatusType.NO_STUDIO_LOADED:
            msg = _("JACK can only be configured with a loaded and stopped studio. Please create a new studio or load and stop an existing one.")
            sys.stderr.write(msg + "\n")
            title = _("No studio present")
        elif ret == LadishStatusType.STUDIO_RUNNING:
            msg = _("JACK can only be configured with a stopped studio. Please stop your studio first.")
            sys.stderr.write(msg + "\n")
            title = _("Studio is running")
        else:
            sys.stderr(_("Unexpected error!\n"))
        try:
            mdlg = Gtk.MessageDialog(type = Gtk.MessageType.ERROR,
                                     buttons = Gtk.ButtonsType.CLOSE,
                                     message_format = msg)
            mdlg.set_title(title)
            mdlg.run()
            mdlg.hide()
        except:
            pass
        finally:
            sys.stderr.flush()
            sys.exit(1)

class configure_command(object):
    def __init__(self):
        pass

    def get_description(self):
        pass

    def get_window_title(self):
        return self.get_description();

    def run(self, args):
        return self.activate()

class parameter_enum_value(GObject.GObject):
    def __init__(self, is_fake_value, value, description):
        GObject.GObject.__init__(self)
        self.is_fake_value = is_fake_value
        self.value = value
        self.description = description

    def get_description(self):
        if self.is_fake_value:
            return self.description

        return str(self.value) + " - " + self.description

class parameter_store(GObject.GObject):
    def __init__(self, param):
        GObject.GObject.__init__(self)
        self.param = param
        self.name = self.param.get_name()
        self.is_set, self.default_value, self.value = self.param.get_value()
        self.modified = False
        self.has_range = self.param.has_range()
        self.is_strict = self.param.is_strict_enum()
        self.is_fake_value = self.param.is_fake_values_enum()

        self.enum_values = []

        if self.has_range:
            self.range_min, self.range_max = self.param.get_range()
        else:
            for enum_value in self.param.get_enum_values():
                self.enum_values.append(parameter_enum_value(self.is_fake_value, enum_value[0], enum_value[1]))

    def get_name(self):
        return self.name

    def get_type(self):
        return self.param.get_type()

    def get_value(self):
        return self.value

    def get_default_value(self):
        if not self.is_fake_value:
            return str(self.default_value)

        for enum_value in self.get_enum_values():
            if enum_value.value == self.default_value:
                return enum_value.get_description()

        return "???"

    def set_value(self, value):
        self.value = value
        self.modified = True

    def reset_value(self):
        self.value = self.default_value

    def get_short_description(self):
        return self.param.get_short_description()

    def maybe_save_value(self):
        if self.modified:
            self.param.set_value(self.value)
            self.modified = False

    def get_range(self):
        return self.range_min, self.range_max

    def has_enum(self):
        return len(self.enum_values) != 0

    def is_strict_enum(self):
        return self.is_strict

    def get_enum_values(self):
        return self.enum_values

GObject.type_register(parameter_store)

def combobox_get_active_text(combobox, model_index = 0):
    model = combobox.get_model()
    active = combobox.get_active()
    if active < 0:
        return None
    return model[active][model_index]

class cell_renderer_param(Gtk.CellRendererPixbuf):
    __gproperties__ = { "parameter": (GObject.TYPE_OBJECT,
                                      "Parameter",
                                      "Parameter",
                                      GObject.PARAM_READWRITE) }

    def __init__(self):
        Gtk.CellRendererPixbuf.__init__(self)
        self.parameter = None
        self.set_property('mode', Gtk.CellRendererMode.EDITABLE)
        self.set_property('mode', Gtk.CellRendererMode.ACTIVATABLE)
        self.renderer_text = Gtk.CellRendererText()
        self.renderer_toggle = Gtk.CellRendererToggle()
        self.renderer_combo = Gtk.CellRendererCombo()
        self.renderer_spinbutton = Gtk.CellRendererSpin()
        for r in (self.renderer_text, self.renderer_combo, self.renderer_spinbutton):
            r.connect("edited", self.on_edited)
        self.renderer = None
        self.edit_widget = None

    def do_set_property(self, pspec, value):
        if pspec.name == 'parameter':
            if value.get_type() == 'b':
                self.set_property('mode', Gtk.CellRendererMode.ACTIVATABLE)
            else: 
                self.set_property('mode', Gtk.CellRendererMode.EDITABLE)
        else:
            sys.stderr.write(pspec.name)
        setattr(self, pspec.name, value)

    def do_get_property(self, pspec):
        return getattr(self, pspec.name)

    def choose_renderer(self):
        typechar = self.parameter.get_type()
        value = self.parameter.get_value()

        if typechar == "b":
            self.renderer = self.renderer_toggle
            self.renderer.set_activatable(True)
            self.renderer.set_active(value)
            self.renderer.set_property("xalign", 0.0)
            return

        if self.parameter.has_enum():
            self.renderer = self.renderer_combo

            m = Gtk.ListStore(str, parameter_enum_value)

            for value in self.parameter.get_enum_values():
                m.append([value.get_description(), value])

            self.renderer.set_property("model",m)
            self.renderer.set_property('text-column', 0)
            self.renderer.set_property('editable', True)
            self.renderer.set_property('has_entry', not self.parameter.is_strict_enum())

            value = self.parameter.get_value()
            if self.parameter.is_fake_value:
                text = "???"
                for enum_value in self.parameter.get_enum_values():
                    if enum_value.value == value:
                        text = enum_value.get_description()
                        break
            else:
                text = str(value)

            self.renderer.set_property('text', text)

            return

        if typechar == 'u' or typechar == 'i':
            self.renderer = self.renderer_spinbutton
            self.renderer.set_property('text', str(value))
            self.renderer.set_property('editable', True)
            if self.parameter.has_range:
                range_min, range_max = self.parameter.get_range()
                self.renderer.set_property('adjustment', Gtk.Adjustment(value, range_min, range_max, 1, abs(int((range_max - range_min) / 10))))
            else:
                self.renderer.set_property('adjustment', Gtk.Adjustment(value, 0, 100000, 1, 1000))
            return

        self.renderer = self.renderer_text
        self.renderer.set_property('editable', True)
        self.renderer.set_property('text', self.parameter.get_value())

    def do_render(self, ctx, widget, bg_area, cell_area, flags):
        self.choose_renderer()
        return self.renderer.render(ctx, widget, bg_area, cell_area, flags)

    def do_get_size(self, widget, cell_area=None):
        self.choose_renderer()
        return self.renderer.get_size(widget, cell_area)

    def do_activate(self, event, widget, path, background_area, cell_area, flags):
        self.choose_renderer()
        if self.parameter.get_type() == 'b':
            self.parameter.set_value(not self.parameter.get_value())
            widget.get_model()[path][COLUMN_ISSET] = "modified"
        return True

    def on_edited(self, renderer, path, value_str):
        parameter = self.edit_parameter
        widget = self.edit_widget
        model = self.edit_tree.get_model()
        self.edit_widget = None
        typechar = parameter.get_type()
        if type(widget) == Gtk.ComboBox:
            value = combobox_get_active_text(widget, 1)
            if value == None:
                return
            value_str = value.value
        elif type(widget) == Gtk.ComboBoxText:
            enum_value = combobox_get_active_text(widget, 1)
            if enum_value:
                value_str = enum_value.value
            else:
                value_str = widget.get_active_text()

        if typechar == 'u' or typechar == 'i':
            try:
                value = int(value_str)
            except ValueError, e:
                # Hide the widget (because it may display something else than what user typed in)
                widget.hide()
                # Display the error
                mdlg = Gtk.MessageDialog(buttons = Gtk.ButtonsType.OK, message_format = "Invalid value. Please enter an integer number.")
                mdlg.run()
                mdlg.hide()
                # Return the focus back to the tree to prevent buttons from stealing it
                self.edit_tree.grab_focus()
                return
        else:
            value = value_str
        parameter.set_value(value)
        model[path][COLUMN_ISSET] = "modified"
        self.edit_tree.grab_focus()

    def do_start_editing(self, event, widget, path, background_area, cell_area, flags):
        # this happens when edit requested using keyboard
        if not event:
            event = Gdk.Event(Gdk.NOTHING)

        self.choose_renderer()
        ret = self.renderer.start_editing(event, widget, path, background_area, cell_area, flags)
        self.edit_widget = ret
        self.edit_tree = widget
        self.edit_parameter = self.parameter
        return ret

GObject.type_register(cell_renderer_param)

class jack_params_configure_command(configure_command):
    def __init__(self, jack, path):
        self.jack = jack
        self.path = path
        self.is_setting = False

    def reset_value(self, row_path):
        row = self.liststore[row_path]
        param = row[COLUMN_PARAMETER]
        param.reset_value()
        row[COLUMN_ISSET] = "reset"

    def do_row_activated(self, treeview, path, view_column):
        if view_column == self.tvcolumn_is_set:
            self.reset_value(path)
            
    def do_button_press_event(self, tree, event):
        if event.type != Gdk.EventType._2BUTTON_PRESS:
            return False
        # this is needed for proper double-click handling in the list; don't ask me why, I don't know
        # it's probably because _2BUTTON_PRESS event is still delivered to tree view, automatically deactivating
        # the newly created edit widget (which gets created on second BUTTON_PRESS but before _2BUTTON_PRESS)
        # deactivating the widget causes it to be deleted
        return True

    def do_key_press_event(self, tree, event):
        (row_path, cur) = self.treeview.get_cursor()

        # if Delete was pressed, reset the value
        #if event.get_state() == 0 and event.keyval == Gdk.KEY_Delete:
        if event.keyval == Gdk.KEY_Delete:
            self.reset_value(row_path)
            tree.queue_draw()
            return True

        # prevent ESC from activating the editor
        if event.string < " ":
            return False

        # single-key data entry: if the control is a text entry, spin button or combo box/combo box entry,
        # then edit the current and set the text value to what user has already typed in
        (row_path, cur) = self.treeview.get_cursor()
        param = self.liststore[row_path][COLUMN_PARAMETER]
        ptype = param.get_type()

        # we don't care about booleans
        if ptype == 'b':
            return False

        # accept only digits for integer input (or a minus, but only if it's a signed field)
        if ptype in ('i', 'u'):
            if not (event.string.isdigit() or (event.string == "-" and ptype == 'i')):
                return False

        # Start cell editing
        # MAYBE: call a specially crafted cell_renderer_param method for this
        self.treeview.set_cursor_on_cell(row_path, self.tvcolumn_value, self.renderer_value.renderer, True)

        # cell_renderer_param::on_start_editing() should set edit_widget.
        # if edit operation has failed (didn't create a widget), pass the key on
        # MAYBE: call a specially crafted cell_renderer_param method to do this check
        if self.renderer_value.edit_widget == None:
            return

        widget = self.renderer_value.edit_widget
        if type(widget) in (Gtk.Entry, Gtk.ComboBoxText):
            # (combo or plain) text entry - set the content and move the cursor to the end
            sl = len(event.string)
            widget.set_text(event.string)
            widget.select_region(sl, sl)
            return True

        if type(self.renderer_value.edit_widget) == Gtk.SpinButton:
            # spin button - set the value and move the cursor to the end
            if event.string == "-":
                # special case for minus sign (which can't be converted to float)
                widget.set_text(event.string)
            else:
                widget.set_value(float(event.string))
            sl = len(widget.get_text())
            widget.select_region(sl, sl)
            return True
            
        if type(self.renderer_value.edit_widget) == Gtk.ComboBox:
            # combo box - select the first item that starts with typed character
            model = widget.get_model()
            item = -1
            iter = model.get_iter_root()
            while iter != None:
                if model.get_value(iter, 0).startswith(event.string):
                    item = model.get_path(iter)[0]
                    break
                iter = model.iter_next(iter)
            widget.set_active(item)
            return True

        return False

    def on_cursor_changed(self, tree):
        (row_path, cur) = self.treeview.get_cursor()

        if not self.is_setting and cur != None and cur.get_title() != self.tvcolumn_value.get_title():
            self.is_setting = True
            try:
                self.treeview.set_cursor_on_cell(row_path, self.tvcolumn_value, self.renderer_value.renderer, False)
            finally:
                self.is_setting = False

    def ok_clicked(self, dlg):
        if self.renderer_value.edit_widget:
            self.renderer_value.edit_widget.editing_done()

    def _on_query_tooltip(self, treeview, x, y, keyboard_tip, tooltip):
        """Handle tooltips for the cells"""
        try:
            (path, column, out_x, out_y) = treeview.get_path_at_pos(x, y)
            if not path:
                return False
        except TypeError:
            return False

        # Horrible-fix to skip the treeview's header row
        intpath = int(path.to_string())
        if intpath == 0:
            return False
        elif intpath > 0:
            path = Gtk.TreePath(str(intpath - 1))

        text = ''
        if column.get_title() in (self.tvcolumn_value.get_title(),
                                  self.tvcolumn_parameter.get_title()):
            text = self.liststore[path][COLUMN_LONGDESC]
        elif column.get_title() == self.tvcolumn_is_set.get_title():
            if self.liststore[path][COLUMN_ISSET] == "default":
                return False
            if self.liststore[path][COLUMN_ISSET] == 'set':
                text += _("Double-click to schedule reset of value to %s") % \
                    self.liststore[path][COLUMN_PARAMETER].get_default_value()
            else:
                text = _("Value will be reset to %s") % \
                    self.liststore[path][COLUMN_PARAMETER].get_default_value()
        else:
            return False

        tooltip.set_text(text)
        return True

    def do_destroy(self, *args):
        for row in self.liststore:
            param = row[COLUMN_PARAMETER]
            reset = (row[COLUMN_ISSET] == "reset")
            if reset:
                param.param.reset_value()
            else:
                if param.modified:
                    param.maybe_save_value()

    def activate(self, *args, **kwargs):

        jack = self.jack

        self.liststore = Gtk.ListStore(GObject.TYPE_STRING,
            parameter_store,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING)
        self.treeview = Gtk.TreeView(self.liststore)
        self.treeview.set_rules_hint(True)
        self.treeview.set_has_tooltip(True)
        self.treeview.set_enable_search(False)

        renderer_text = Gtk.CellRendererText()
        renderer_toggle = Gtk.CellRendererToggle()
        renderer_value = cell_renderer_param()
        self.renderer_value = renderer_value # save for use in event handler methods

        self.tvcolumn_parameter = Gtk.TreeViewColumn('Parameter', renderer_text, text=COLUMN_NAME)
        self.tvcolumn_is_set = Gtk.TreeViewColumn('Status', renderer_text, text=COLUMN_ISSET)
        self.tvcolumn_value = Gtk.TreeViewColumn('Value', renderer_value, parameter=COLUMN_PARAMETER)
        self.tvcolumn_description = Gtk.TreeViewColumn('Description', renderer_text, text=COLUMN_SHORTDESC)

        self.tvcolumn_value.set_resizable(True)
        self.tvcolumn_value.set_min_width(100)

        self.treeview.append_column(self.tvcolumn_parameter)
        self.treeview.append_column(self.tvcolumn_is_set)
        self.treeview.append_column(self.tvcolumn_value)
        self.treeview.append_column(self.tvcolumn_description)

        param_names = jack.get_param_names(self.path)
        for name in param_names:
            param = parameter(jack, self.path + [name])
            store = parameter_store(param)
            if store.is_set:
                is_set = "set"
            else:
                is_set = "default"
            self.liststore.append([name,
                                   store,
                                   param.get_short_description(),
                                   param.get_long_description(),
                                   is_set])

        self.treeview.connect("row-activated", self.do_row_activated)
        self.treeview.connect("cursor-changed", self.on_cursor_changed)
        self.treeview.connect("key-press-event", self.do_key_press_event)
        self.treeview.connect("button-press-event", self.do_button_press_event)
        if tooltips_active:
            self.treeview.connect("query-tooltip", self._on_query_tooltip)
        self.treeview.connect("destroy", self.do_destroy)

        if len(param_names):
            # move cursor to first row and 'value' column
            self.treeview.set_cursor(Gtk.TreePath(path=0), # path
                                     self.tvcolumn_value,  # focus_column
                                     False)                # start_editing

        return self.treeview

class jack_engine_params_configure_command(jack_params_configure_command):
    def __init__(self, jack):
        jack_params_configure_command.__init__(self, jack, ['engine'])

    def get_description(self):
        return _('JACK engine')

class jack_driver_params_configure_command(jack_params_configure_command):
    def __init__(self, jack):
        jack_params_configure_command.__init__(self, jack, ['driver'])

    def get_description(self):
        return _('JACK driver')

    def get_window_title(self):
        return _('JACK "%s" driver') % jack.get_selected_driver()

class jack_internal_params_configure_command(jack_params_configure_command):
    def __init__(self, jack, name):
        self.name = name
        jack_params_configure_command.__init__(self, jack, ['internals', name])

    def get_description(self):
        return _('JACK "%s"') % self.name

class LadiControlCenter(LadiApp):

    _appname = 'ladi-control-center'
    _appname_long = _("LADI Control Center")
    _appid = 'org.linuxaudio.ladi.controlcenter'

    def quit(self, *args, **kwargs):
        self.window.destroy()
        Gtk.main_quit()

    @property
    def modules(self): return self._modules

    def __init__(self):

        LadiApp.__init__(self)
        jack = JackConfigProxy()

        # Init modules list
        modules = {'engine' : jack_engine_params_configure_command(jack),
                   'params' : jack_driver_params_configure_command(jack)}
        for internal in jack.read_container(['internals']):
            modules[str(internal)] = jack_internal_params_configure_command(jack, internal)
        self._modules = modules

    def _activate(self, **kwargs):

        if 'select' in kwargs:
            selected = kwargs['select']
        else:
            selected = None

        # Init UI
        self.window = window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        vbox = Gtk.VBox()
        hbox = Gtk.HBox()
        notebook = Gtk.Notebook()

        vbox.pack_start(hbox, True, True, 12)
        hbox.pack_start(notebook, True, True, 2)
        window.set_title("LADI Settings")
        window.set_icon_name('preferences-system')
        window.set_resizable(True)
        notebook.set_tab_pos(Gtk.PositionType.LEFT)

        page_count = 0

        modules = self.modules
        for mod in modules:
            treeview = modules[mod].run({})
            container = Gtk.ScrolledWindow()
            container.set_min_content_width(400)
            container.set_min_content_height(400)
            container.set_policy(hscrollbar_policy=Gtk.PolicyType.AUTOMATIC,
                                 vscrollbar_policy=Gtk.PolicyType.AUTOMATIC)
            container.add(treeview)
            container.show_all()
            #vbox.show_all()
            try:
                tab_label = modules[mod].get_window_title()
            except:
                tab_label = modules[mod].get_description()
            notebook.append_page(container, Gtk.Label(tab_label))
            if selected and selected == mod:
                notebook.set_current_page(page_count)
            page_count += 1

        window.add(vbox)
        window.connect('destroy', self.quit)

        self.connect_signals_quit()

    def run(self, **kwargs):
        self._activate(**kwargs)
        self.window.show_all()
        Gtk.main()

if __name__ == "__main__":
    _check_ladish()

    GObject.type_register(parameter_enum_value)

    parser = argparse.ArgumentParser(description=_('Convenient graphical interface for configuring JACK'),
                                     epilog=_('This program is part of the LADITools suite.'))
    parser.add_argument('-m',
                        '--module',
                        nargs=1,
                        metavar='MODULE',
                        help=_('select the module to configure'))
    parser.add_argument('-l',
                        '--list-modules',
                        action='store_true',
                        help=_('list available modules'))
    parser.add_argument('--version',
                        action='version',
                        version="%(prog)s " + get_version_string())

    options = parser.parse_args()

    app = LadiControlCenter()

    if options.list_modules and options.module:
        sys.stderr.write(_("Conflicting options, type %s --help for a list of options.") % sys.argv[0] + '\n')
        sys.stderr.flush()
        sys.exit(2)

    modules = app.modules
    if options.list_modules:
        sys.stderr.write(_("Available modules: "))
        sys.stderr.write(' '.join(modules) + '\n')
        sys.stderr.flush()
    elif options.module:
        module = options.module[0]
        if not module in modules:
            sys.stderr.write(_("Module %(mod)s is not available, type '%(cmd)s -l' for a list of available modules.") % {'mod' : module, 'cmd' : sys.argv[0]} + "\n")
            sys.stderr.flush()
            sys.exit(2)
        else:
            app.run(select=module)
    else:
        app.run()

    sys.exit(0)