Class: Dumon::GtkProfileDlg

Inherits:
ProfileDlg show all
Defined in:
lib/dumon/profile.rb

Overview

This class represents an user interface for profile management based on Gtk library.

Instance Method Summary collapse

Methods inherited from ProfileDlg

#apply_profile

Constructor Details

#initializeGtkProfileDlg

Constructor.



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
# File 'lib/dumon/profile.rb', line 51

def initialize
  super

  # create the dialog
  @dialog = Gtk::Dialog.new('Profile management', nil, Gtk::Dialog::MODAL, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])
  t = Gtk::Table.new(2, 2)
  t.row_spacings = 5
  t.column_spacings = 5

  # disable entry/button if no mode set (probably after start of Dumon)
  entry_store = Gtk::Entry.new
  btn_save = Gtk::Button.new(Gtk::Stock::SAVE)
  if Dumon::App.instance.current_profile.nil?
    entry_store.text = '<make a choice first>'
    entry_store.set_sensitive false
    btn_save.set_sensitive false
  end

  # save new profile
  btn_save.signal_connect('clicked') do
    if entry_store.text.size > 0
      @dumon_conf[:profiles][entry_store.text] = Dumon::App.instance.current_profile
      Dumon::App.instance.write_config(@dumon_conf)
      Dumon::logger.debug "Stored profile, name=#{entry_store.text}"
      @dialog.destroy
    end
  end

  t.attach(Gtk::HBox.new(false, 5).pack_start(Gtk::Label.new('Profile name:'), false, false).add(entry_store), 0, 1, 0, 1)
  t.attach(btn_save, 1, 2, 0, 1)

  # select/delete existing profile
  model = Gtk::ListStore.new(String)
  treeview = Gtk::TreeView.new(model)
  treeview.headers_visible = false
  renderer = Gtk::CellRendererText.new
  column = Gtk::TreeViewColumn.new('', renderer, :text => 0)
  treeview.append_column(column)

  @dumon_conf[:profiles].keys.each do |k|
    iter = model.append
    iter.set_value 0, k.to_s
  end

  # apply
  btn_apply = Gtk::Button.new(Gtk::Stock::APPLY)
  btn_apply.signal_connect('clicked') do
    selection = treeview.selection
    if iter = selection.selected
      apply_profile(iter[0])
      @dialog.destroy
    end
  end
  # double-click on treeview
  treeview.signal_connect("row-activated") do |view, path|
    if iter = view.model.get_iter(path)
      apply_profile(iter[0])
      @dialog.destroy
    end
  end
  # delete
  btn_delete = Gtk::Button.new(Gtk::Stock::DELETE)
  btn_delete.signal_connect('clicked') do
    selection = treeview.selection
    if iter = selection.selected
      prof_name = iter[0]
      @dumon_conf[:profiles].delete prof_name.to_sym
      Dumon::App.instance.write_config(@dumon_conf)
      Dumon::logger.debug "Deleted profile, name=#{prof_name}"
      @dialog.destroy
    end
  end

  t.attach(treeview, 0, 1, 1, 2)
  t.attach(Gtk::VBox.new(false, 5).pack_start(btn_apply, false, false).pack_start(btn_delete, false, false), 1, 2, 1, 2)

  @dialog.vbox.add t

  # ensure that the dialog box is destroyed when the user responds
  @dialog.signal_connect('response') do |w, code|
    if Gtk::Dialog::RESPONSE_OK.eql?(code) and entry.text.size > 0
      Dumon::App.instance.write(entry.text => Dumon::App.instance.current_profile)
    end

    @dialog.destroy
  end
end

Instance Method Details

#on_warn(msg) ⇒ Object

:nodoc:



143
144
145
146
147
148
149
150
151
152
# File 'lib/dumon/profile.rb', line 143

def on_warn(msg) #:nodoc:
  super(msg)
  md = Gtk::MessageDialog.new(
      @dialog,
      Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::WARNING,
      Gtk::MessageDialog::BUTTONS_CLOSE,
      msg.join("\n"))
  md.run
  md.destroy
end

#showObject

:nodoc:



139
140
141
# File 'lib/dumon/profile.rb', line 139

def show #:nodoc:
  @dialog.show_all
end