~hakermania/synapse-project/synapse-project

« back to all changes in this revision

Viewing changes to src/ui/settings.vala

  • Committer: Rico Tzschichholz
  • Date: 2016-02-27 15:10:45 UTC
  • Revision ID: ricotz@ubuntu.com-20160227151045-752y5rjoadmyieo3
src: Drop "using Gtk;"

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 *
20
20
 */
21
21
 
22
 
using Gtk;
23
 
 
24
22
namespace Synapse.Gui
25
23
{
26
24
  public class SettingsWindow : Gtk.Window
143
141
      this.title = _("Synapse - Settings");
144
142
      this.data_sink = data_sink;
145
143
      this.key_combo_config = key_combo_config;
146
 
      this.set_position (WindowPosition.CENTER);
 
144
      this.set_position (Gtk.WindowPosition.CENTER);
147
145
      this.set_size_request (500, 450);
148
146
      this.resizable = false;
149
147
      this.delete_event.connect (this.hide_on_delete);
269
267
          string cannot_bind = _("Shortcut already in use");
270
268
          cannot_bind = "%s: \"%s\"".printf (cannot_bind, keyname);
271
269
          warning (cannot_bind);
272
 
          var d = new Gtk.MessageDialog (this, 0, MessageType.ERROR,
273
 
                                         ButtonsType.CLOSE,
 
270
          var d = new Gtk.MessageDialog (this, 0, Gtk.MessageType.ERROR,
 
271
                                         Gtk.ButtonsType.CLOSE,
274
272
                                         "%s", cannot_bind);
275
273
          d.run ();
276
274
          d.destroy ();
282
280
 
283
281
    private void build_ui ()
284
282
    {
285
 
      var main_vbox = new Box (Gtk.Orientation.VERTICAL, 12);
 
283
      var main_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 12);
286
284
      main_vbox.border_width = 12;
287
285
      this.add (main_vbox);
288
286
 
289
287
      var tabs = new Gtk.Notebook ();
290
 
      var general_tab = new Box (Gtk.Orientation.VERTICAL, 6);
 
288
      var general_tab = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
291
289
      general_tab.border_width = 12;
292
 
      var plugin_tab = new Box (Gtk.Orientation.VERTICAL, 6);
 
290
      var plugin_tab = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
293
291
      plugin_tab.border_width = 12;
294
292
      main_vbox.pack_start (tabs);
295
 
      tabs.append_page (general_tab, new Label (_("General")));
296
 
      tabs.append_page (plugin_tab, new Label (_("Plugins")));
 
293
      tabs.append_page (general_tab, new Gtk.Label (_("General")));
 
294
      tabs.append_page (plugin_tab, new Gtk.Label (_("Plugins")));
297
295
 
298
296
      /* General Tab */
299
 
      var theme_frame = new Frame (null);
 
297
      var theme_frame = new Gtk.Frame (null);
300
298
      theme_frame.set_shadow_type (Gtk.ShadowType.NONE);
301
 
      var theme_frame_label = new Label (null);
 
299
      var theme_frame_label = new Gtk.Label (null);
302
300
      theme_frame_label.set_markup (Markup.printf_escaped ("<b>%s</b>", _("Behavior & Look")));
303
301
      theme_frame.set_label_widget (theme_frame_label);
304
302
 
305
 
      var behavior_vbox = new Box (Gtk.Orientation.VERTICAL, 6);
306
 
      var align = new Alignment (0.5f, 0.5f, 1.0f, 1.0f);
 
303
      var behavior_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
 
304
      var align = new Gtk.Alignment (0.5f, 0.5f, 1.0f, 1.0f);
307
305
      align.set_padding (6, 12, 12, 12);
308
306
      align.add (behavior_vbox);
309
307
      theme_frame.add (align);
310
308
 
311
309
      /* Select theme combobox row */
312
 
      var row = new Box (Gtk.Orientation.HORIZONTAL, 6);
 
310
      var row = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
313
311
      behavior_vbox.pack_start (row, false);
314
 
      var select_theme_label = new Label (_("Theme:"));
 
312
      var select_theme_label = new Gtk.Label (_("Theme:"));
315
313
      row.pack_start (select_theme_label, false, false);
316
314
      row.pack_end (build_theme_combo (), false, false);
317
315
 
318
316
      /* Autostart checkbox */
319
 
      var autostart = new CheckButton.with_label (_("Startup on login"));
 
317
      var autostart = new Gtk.CheckButton.with_label (_("Startup on login"));
320
318
      autostart.active = autostart_exists ();
321
319
      autostart.toggled.connect (this.autostart_toggled);
322
320
      behavior_vbox.pack_start (autostart, false);
323
321
 
324
322
      /* Notification icon */
325
 
      var notification = new CheckButton.with_label (_("Show notification icon"));
 
323
      var notification = new Gtk.CheckButton.with_label (_("Show notification icon"));
326
324
      notification.active = config.show_indicator;
327
325
      notification.toggled.connect ((tb) => {
328
326
        config.show_indicator = tb.get_active ();
333
331
      general_tab.pack_start (theme_frame, false);
334
332
 
335
333
      /* Keybinding treeview */
336
 
      var shortcut_frame = new Frame (null);
 
334
      var shortcut_frame = new Gtk.Frame (null);
337
335
      shortcut_frame.set_shadow_type (Gtk.ShadowType.NONE);
338
 
      var shortcut_frame_label = new Label (null);
 
336
      var shortcut_frame_label = new Gtk.Label (null);
339
337
      shortcut_frame_label.set_markup (Markup.printf_escaped ("<b>%s</b>", _("Shortcuts")));
340
338
      shortcut_frame.set_label_widget (shortcut_frame_label);
341
 
      align = new Alignment (0.5f, 0.5f, 1.0f, 1.0f);
 
339
      align = new Gtk.Alignment (0.5f, 0.5f, 1.0f, 1.0f);
342
340
      align.set_padding (6, 12, 12, 12);
343
341
 
344
342
      var shortcut_scroll = new Gtk.ScrolledWindow (null, null);
345
 
      shortcut_scroll.set_shadow_type (ShadowType.IN);
346
 
      shortcut_scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
347
 
      var tree_vbox = new Box (Gtk.Orientation.VERTICAL, 6);
 
343
      shortcut_scroll.set_shadow_type (Gtk.ShadowType.IN);
 
344
      shortcut_scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
 
345
      var tree_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
348
346
      Gtk.TreeView treeview = new Gtk.TreeView ();
349
347
      tree_vbox.pack_start (shortcut_scroll);
350
348
      shortcut_scroll.add (treeview);
355
353
      model = new Gtk.ListStore (2, typeof (string), typeof (string));
356
354
      treeview.set_model (model);
357
355
 
358
 
      var col = new TreeViewColumn.with_attributes (_("Action"), new CellRendererText (), "text", 0);
 
356
      var col = new Gtk.TreeViewColumn.with_attributes (_("Action"), new Gtk.CellRendererText (), "text", 0);
359
357
      treeview.append_column (col);
360
358
 
361
 
      var ren = new CellRendererAccel ();
 
359
      var ren = new Gtk.CellRendererAccel ();
362
360
      ren.editable = true;
363
361
      ren.accel_mode = Gtk.CellRendererAccelMode.OTHER;
364
362
      ren.accel_edited.connect ((a, path, accel_key, accel_mods, keycode) => {
388
386
        int index = int.parse (path);
389
387
        if (index == 0) this.set_keybinding ("");
390
388
      });
391
 
      col = new TreeViewColumn.with_attributes (_("Shortcut"), ren, "text",1);
 
389
      col = new Gtk.TreeViewColumn.with_attributes (_("Shortcut"), ren, "text",1);
392
390
      treeview.append_column (col);
393
391
 
394
392
      // add the actual item
403
401
 
404
402
      /* Add info */
405
403
 
406
 
      var info_box = new Box (Gtk.Orientation.HORIZONTAL, 6);
407
 
      var info_image = new Image.from_stock (Gtk.Stock.INFO, IconSize.MENU);
 
404
      var info_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
 
405
      var info_image = new Gtk.Image.from_stock (Gtk.Stock.INFO, Gtk.IconSize.MENU);
408
406
      info_box.pack_start (info_image, false);
409
 
      var info_label = new Label (Markup.printf_escaped ("<span size=\"small\">%s</span>",
 
407
      var info_label = new Gtk.Label (Markup.printf_escaped ("<span size=\"small\">%s</span>",
410
408
            _("Click the shortcut you wish to change and press the new shortcut.")));
411
409
      info_label.set_use_markup(true);
412
410
      info_label.set_alignment (0.0f, 0.5f);
457
455
      if (emit) keybinding_changed (key);
458
456
    }
459
457
 
460
 
    private ComboBox build_theme_combo ()
 
458
    private Gtk.ComboBox build_theme_combo ()
461
459
    {
462
 
      var cb_themes = new ComboBoxText ();
 
460
      var cb_themes = new Gtk.ComboBoxText ();
463
461
      /* Pack data into the model and select current theme */
464
462
      if (!themes.has_key (selected_theme)) selected_theme = "default";
465
463
      foreach (Gee.Map.Entry<string,Theme?> e in themes.entries)
495
493
      return FileUtils.test (autostart_file, FileTest.EXISTS);
496
494
    }
497
495
 
498
 
    private void autostart_toggled (Widget w)
 
496
    private void autostart_toggled (Gtk.Widget w)
499
497
    {
500
 
      CheckButton check = w as CheckButton;
 
498
      Gtk.CheckButton check = w as Gtk.CheckButton;
501
499
      bool active = check.active;
502
500
      if (!active && autostart_exists ())
503
501
      {
529
527
        }
530
528
        catch (Error err)
531
529
        {
532
 
          var d = new MessageDialog (this, 0, MessageType.ERROR,
533
 
                                     ButtonsType.CLOSE,
 
530
          var d = new Gtk.MessageDialog (this, 0, Gtk.MessageType.ERROR,
 
531
                                     Gtk.ButtonsType.CLOSE,
534
532
                                     "%s", err.message);
535
533
          d.run ();
536
534
          d.destroy ();