Compare commits

..

No commits in common. "2b342497a8fe1c14a30fbe9a3a28f108900edd6a" and "main" have entirely different histories.

5 changed files with 16 additions and 120 deletions

View file

@ -3,10 +3,10 @@ namespace Deskcandy.Candy {
public string config_path { get; private set; }
public string saver_path { get; private set; }
public Gee.HashMap<string, XScreensaverConfig> configs;
public List<XScreensaverConfig> configs;
public XScreensaver() {
this.configs = new Gee.HashMap<string, XScreensaverConfig>();
this.configs = new List<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.set(config.name, config);
this.configs.append(config);
}
message(@"Found $(this.configs.size) screensavers.");
message(@"Found $(this.configs.length()) screensavers.");
}
public override Subprocess launch(uint socket_id) throws Error {

View file

@ -17,103 +17,16 @@ namespace Deskcandy.Candy {
yield this.read_from_file_async(file);
this.arg = this.get_child("command").get_attribute("arg");
this.description = this.get_child("_description").text_content.strip();
var tag = this.get_child("command");
this.arg = tag.get_attribute("arg");
tag = this.get_child("_description");
this.description = tag.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;
}
}
}
}
}

View file

@ -163,7 +163,6 @@
<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>
@ -267,7 +266,6 @@
</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>

View file

@ -6,7 +6,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox" id="screensaver_form_container">
<object class="GtkBox">
<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">0</property>
<property name="position">1</property>
</packing>
</child>
</object>

View file

@ -5,19 +5,15 @@ 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 (var config in xss.configs.values) {
foreach (XScreensaverConfig config in xss.configs) {
this.screensavers_liststore.append(out iter);
this.screensavers_liststore.set(iter, 0, config.label, 1, config.description, 2, config.name);
}
@ -26,22 +22,11 @@ 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;
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();
}
}
}