1 /* Demo Recorder for MAEMO 5
2 * Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2,
5 * or (at your option) any later version, as published by the Free
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 public class ProjectSettingsDialog : Hildon.Dialog {
22 Hildon.Entry name_entry;
23 Hildon.Button directory_btn;
24 Hildon.Button filename_btn;
28 public string get_project_name() {
29 return name_entry.get_text();
31 public void set_project_name(string project_name) {
32 name_entry.set_text(project_name);
36 public string get_project_directory() {
37 return directory_btn.get_value();
39 public void set_project_directory(string project_directory) {
40 directory_btn.set_value(project_directory);
44 public string get_project_filename() {
45 return filename_btn.get_value();
47 public void set_project_filename(string project_filename) {
48 filename_btn.set_value(project_filename);
52 public ProjectSettingsDialog(Gtk.Widget parent, string title) {
53 this.user_set = false;
54 this.set_parent(parent);
55 this.set_title(title);
56 this.set_default_response(Gtk.ResponseType.CANCEL);
57 construct_interface("", "", "");
59 public ProjectSettingsDialog.with_values(Gtk.Widget parent, string title, string project_name, string project_directory, string project_filename, string root_folder) {
60 user_set = (0 < project_directory.length && 0 < project_filename.length);
61 this.root_folder = root_folder;
62 this.set_parent(parent);
63 this.set_title(title);
64 this.set_default_response(Gtk.ResponseType.CANCEL);
65 construct_interface(project_name, project_directory, project_filename);
68 private void construct_interface(string name, string dir, string filename) {
69 this.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
71 Gtk.VBox control_area = (Gtk.VBox)this.get_content_area();
73 Gtk.HBox name_bar = new Gtk.HBox(false, 4);
75 Gtk.Label name_label = new Gtk.Label("Name");
76 name_bar.pack_start(name_label, false, false, 2);
77 name_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
78 name_entry.set_text(name);
79 name_entry.set_placeholder("Project name");
80 name_entry.changed.connect(name_entry_changed);
81 name_bar.pack_start(name_entry, true, true, 2);
83 control_area.pack_start(name_bar, true, true, 4);
85 directory_btn = new Hildon.Button.with_text(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.HALFSCREEN_WIDTH, Hildon.ButtonArrangement.VERTICAL, "Working folder", dir);
86 directory_btn.set_style(Hildon.ButtonStyle.PICKER);
87 directory_btn.set_alignment(0, 0, 1, 1);
88 directory_btn.set_value(dir);
89 directory_btn.clicked.connect(select_directory);
91 control_area.pack_start(directory_btn, true, true, 4);
93 filename_btn = new Hildon.Button.with_text(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.HALFSCREEN_WIDTH, Hildon.ButtonArrangement.VERTICAL, "Settings file", dir);
94 filename_btn.set_style(Hildon.ButtonStyle.PICKER);
95 filename_btn.set_alignment(0, 0, 1, 1);
96 filename_btn.set_value(filename);
97 filename_btn.clicked.connect(select_filename);
99 control_area.pack_start(filename_btn, true, true, 4);
106 private void name_entry_changed() {
108 this.directory_btn.value = root_folder + "/" + get_project_name();
109 this.filename_btn.value = this.directory_btn.value + "/project.xml";
114 private void validate() {
116 good &= (0 < get_project_name().length);
117 good &= (0 < get_project_directory().length);
118 good &= (0 < get_project_filename().length);
119 this.set_response_sensitive(Gtk.ResponseType.OK, good);
122 private void select_directory() {
124 Hildon.FileChooserDialog file_chooser = new Hildon.FileChooserDialog(this, Gtk.FileChooserAction.SELECT_FOLDER);
125 file_chooser.set_show_upnp(false);
126 file_chooser.set_safe_folder(this.root_folder);
127 file_chooser.set_current_folder(this.root_folder);
128 if (0 < this.directory_btn.value.length) {
130 //file_chooser.set_current_folder(this.directory_btn.value);
133 Gtk.ResponseType ret = (Gtk.ResponseType) file_chooser.run();
134 if (Gtk.ResponseType.OK == ret) {
136 this.directory_btn.value = file_chooser.get_filename();
137 if ("" == this.filename_btn.value) {
138 this.filename_btn.value = this.directory_btn.value + "/project.xml";
141 file_chooser.destroy ();
145 private void select_filename() {
147 Hildon.FileChooserDialog file_chooser = new Hildon.FileChooserDialog(this, Gtk.FileChooserAction.SAVE);
148 file_chooser.set_show_upnp(false);
149 file_chooser.set_current_folder(this.root_folder);
150 file_chooser.set_current_name("project.xml");
151 if (0 < this.filename_btn.value.length) {
152 //file_chooser.set_filename(this.filename_btn.value);
153 file_chooser.set_safe_folder(root_folder);
154 /// TODO // file_chooser.set_current_folder(this.filename_btn.value);
156 Gtk.ResponseType ret = (Gtk.ResponseType) file_chooser.run();
157 if (Gtk.ResponseType.OK == ret) {
159 this.filename_btn.value = file_chooser.get_filename();
161 file_chooser.destroy ();