Compare commits
3 commits
main
...
2b342497a8
Author | SHA1 | Date | |
---|---|---|---|
2b342497a8 | |||
c4b7541da3 | |||
77806aa10c |
5 changed files with 120 additions and 16 deletions
|
@ -3,10 +3,10 @@ namespace Deskcandy.Candy {
|
|||
public string config_path { get; private set; }
|
||||
public string saver_path { get; private set; }
|
||||
|
||||
public List<XScreensaverConfig> configs;
|
||||
public Gee.HashMap<string, XScreensaverConfig> configs;
|
||||
|
||||
public XScreensaver() {
|
||||
this.configs = new List<XScreensaverConfig>();
|
||||
this.configs = new Gee.HashMap<string, XScreensaverConfig>();
|
||||
}
|
||||
|
||||
public override async void initialize() throws Error {
|
||||
|
@ -23,9 +23,9 @@ namespace Deskcandy.Candy {
|
|||
}
|
||||
|
||||
var config = yield new XScreensaverConfig(config_dir.resolve_relative_path(name));
|
||||
this.configs.append(config);
|
||||
this.configs.set(config.name, config);
|
||||
}
|
||||
message(@"Found $(this.configs.length()) screensavers.");
|
||||
message(@"Found $(this.configs.size) screensavers.");
|
||||
}
|
||||
|
||||
public override Subprocess launch(uint socket_id) throws Error {
|
||||
|
|
|
@ -17,16 +17,103 @@ namespace Deskcandy.Candy {
|
|||
|
||||
yield this.read_from_file_async(file);
|
||||
|
||||
var tag = this.get_child("command");
|
||||
this.arg = tag.get_attribute("arg");
|
||||
|
||||
tag = this.get_child("_description");
|
||||
this.description = tag.text_content.strip();
|
||||
this.arg = this.get_child("command").get_attribute("arg");
|
||||
this.description = this.get_child("_description").text_content.strip();
|
||||
debug(@"Loaded $this");
|
||||
}
|
||||
|
||||
public string to_string() {
|
||||
return @"Screensaver: $(this.label) [$(this.name)]";
|
||||
}
|
||||
|
||||
public Gtk.Box get_widgets() {
|
||||
var root = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
|
||||
this.get_widgets_internal(root, this);
|
||||
return root;
|
||||
}
|
||||
|
||||
private void get_widgets_internal(Gtk.Box parent, GXml.Element elem) {
|
||||
foreach (var child in elem.children) {
|
||||
var child_container = parent;
|
||||
if (child.has_attribute("_label") && child.tag_name != "boolean") {
|
||||
child_container = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
|
||||
|
||||
// todo: css?
|
||||
var label = new Gtk.Label("");
|
||||
label.xalign = 0.0f;
|
||||
label.use_markup = true;
|
||||
label.set_markup(@"<i>$(child.get_attribute("_label"))</i>");
|
||||
child_container.pack_start(label, false);
|
||||
parent.pack_start(child_container);
|
||||
}
|
||||
|
||||
switch (child.tag_name) {
|
||||
case "hgroup":
|
||||
var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 5);
|
||||
this.get_widgets_internal(hbox, (GXml.Element)child);
|
||||
child_container.pack_start(hbox, false);
|
||||
break;
|
||||
|
||||
case "vgroup":
|
||||
var vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
|
||||
this.get_widgets_internal(vbox, (GXml.Element)child);
|
||||
child_container.pack_start(vbox);
|
||||
break;
|
||||
|
||||
case "boolean":
|
||||
var widget = new Gtk.CheckButton.with_label(child.get_attribute("_label"));
|
||||
child_container.pack_start(widget);
|
||||
break;
|
||||
|
||||
case "number":
|
||||
Gtk.Widget widget = null;
|
||||
|
||||
var adjust = new Gtk.Adjustment(
|
||||
double.parse(child.get_attribute("default")),
|
||||
double.parse(child.get_attribute("low")),
|
||||
double.parse(child.get_attribute("high")),
|
||||
0.01, 0.0, 0.0);
|
||||
|
||||
switch (child.get_attribute("type")) {
|
||||
case "spinbutton":
|
||||
widget = new Gtk.SpinButton(adjust, 0.0, 1);
|
||||
break;
|
||||
case "slider":
|
||||
var scale = new Gtk.Scale(Gtk.Orientation.HORIZONTAL, adjust);
|
||||
scale.value_pos = Gtk.PositionType.LEFT;
|
||||
widget = scale;
|
||||
break;
|
||||
default:
|
||||
warning(@"unhandled number type $(child.get_attribute("type"))");
|
||||
continue;
|
||||
}
|
||||
|
||||
child_container.pack_start(widget);
|
||||
|
||||
break;
|
||||
|
||||
case "select":
|
||||
var model = new Gtk.ListStore(2, Type.STRING, Type.STRING);
|
||||
Gtk.TreeIter? iter = null;
|
||||
foreach (var option in child.get_elements_by_tag_name("option"))
|
||||
{
|
||||
model.insert_with_values(out iter, -1, 0, option.get_attribute("id"), 1, option.get_attribute("_label"));
|
||||
}
|
||||
|
||||
var select = new Gtk.ComboBox.with_model(model);
|
||||
select.id_column = 0;
|
||||
var select_text = new Gtk.CellRendererText();
|
||||
select.pack_start(select_text, true);
|
||||
select.add_attribute(select_text, "text", 1);
|
||||
select.active = 0;
|
||||
child_container.pack_start(select);
|
||||
break;
|
||||
case "file":
|
||||
var file_chooser = new Gtk.FileChooserButton(child.get_attribute("_label"), Gtk.FileChooserAction.OPEN);
|
||||
child_container.pack_start(file_chooser);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -266,6 +267,7 @@
|
|||
</template>
|
||||
<object class="GtkAdjustment" id="opacity_adjustment">
|
||||
<property name="upper">100</property>
|
||||
<property name="value">100</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="screensaver_form_container">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
@ -57,7 +57,7 @@
|
|||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -5,15 +5,19 @@ namespace Deskcandy {
|
|||
public class ScreensaverForm : Gtk.Bin {
|
||||
[GtkChild]
|
||||
private unowned Gtk.ListStore screensavers_liststore;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Box screensaver_form_container;
|
||||
|
||||
private unowned XScreensaver xss;
|
||||
|
||||
private Gtk.Box config_items;
|
||||
|
||||
public void on_initialized(XScreensaver xss) {
|
||||
this.xss = xss;
|
||||
|
||||
Gtk.TreeIter iter;
|
||||
this.screensavers_liststore.clear();
|
||||
foreach (XScreensaverConfig config in xss.configs) {
|
||||
foreach (var config in xss.configs.values) {
|
||||
this.screensavers_liststore.append(out iter);
|
||||
this.screensavers_liststore.set(iter, 0, config.label, 1, config.description, 2, config.name);
|
||||
}
|
||||
|
@ -22,11 +26,22 @@ namespace Deskcandy {
|
|||
[GtkCallback]
|
||||
private void on_screensaver_chooser_row_activated(Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn col) {
|
||||
Gtk.TreeIter iter;
|
||||
if (treeview.model.get_iter(out iter, path)) {
|
||||
string name;
|
||||
treeview.model.get(iter, 2, out name);
|
||||
this.xss.name = name;
|
||||
string name;
|
||||
if (!treeview.model.get_iter(out iter, path)) {
|
||||
warning("can't find path in model?");
|
||||
return;
|
||||
}
|
||||
|
||||
treeview.model.get(iter, 2, out name);
|
||||
this.xss.name = name;
|
||||
|
||||
if (this.config_items != null) {
|
||||
this.screensaver_form_container.remove(this.config_items);
|
||||
}
|
||||
|
||||
this.config_items = this.xss.configs.get(name).get_widgets();
|
||||
this.screensaver_form_container.pack_start(this.config_items, false);
|
||||
this.screensaver_form_container.show_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue