[tracker/tracker-preferences-for-gsettings: 1/2] tracker-preferences: Refactored the Vala code and cleaned things up a bit
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-preferences-for-gsettings: 1/2] tracker-preferences: Refactored the Vala code and cleaned things up a bit
- Date: Thu, 10 Mar 2011 11:16:34 +0000 (UTC)
commit c91dcaa0913ce6c70ed602eb3692d94c4809cec5
Author: Martyn Russell <martyn lanedo com>
Date: Wed Mar 9 15:16:50 2011 +0000
tracker-preferences: Refactored the Vala code and cleaned things up a bit
src/tracker-preferences/Makefile.am | 7 +-
src/tracker-preferences/config.vapi | 33 +-
src/tracker-preferences/tracker-preferences.ui | 45 +-
src/tracker-preferences/tracker-preferences.vala | 712 +++++++++++++---------
4 files changed, 465 insertions(+), 332 deletions(-)
---
diff --git a/src/tracker-preferences/Makefile.am b/src/tracker-preferences/Makefile.am
index 78b6590..f76ace5 100644
--- a/src/tracker-preferences/Makefile.am
+++ b/src/tracker-preferences/Makefile.am
@@ -19,10 +19,11 @@ AM_CPPFLAGS = \
$(BUILD_CFLAGS) \
-I$(top_srcdir)/src \
-I$(top_builddir)/src \
- -DTRACKER_DATADIR=\""$(datadir)/tracker"\" \
+ -DTRACKER_UI_DIR=\"$(datadir)/tracker/\" \
-DLOCALEDIR=\""$(localedir)"\" \
- -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
- $(TRACKER_PREFERENCES_CFLAGS)
+ -DSRCDIR=\"$(abs_srcdir)/\" \
+ $(TRACKER_PREFERENCES_CFLAGS) \
+ -include config.h
LDADD = \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
diff --git a/src/tracker-preferences/config.vapi b/src/tracker-preferences/config.vapi
index da2a171..0f801f5 100644
--- a/src/tracker-preferences/config.vapi
+++ b/src/tracker-preferences/config.vapi
@@ -1,4 +1,29 @@
-[CCode (cheader_filename = "config.h")]
-public const string TRACKER_DATADIR;
-public const string GETTEXT_PACKAGE;
-public const string LOCALEDIR;
+// config.vapi
+//
+// Copyright (C) 2011 Martyn Russell <martyn lanedo com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
+//
+
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config
+{
+ public const string GETTEXT_PACKAGE;
+ public const string PACKAGE_NAME;
+ public const string PACKAGE_VERSION;
+ public const string APP_PATH;
+ public const string LOCALEDIR;
+}
diff --git a/src/tracker-preferences/tracker-preferences.ui b/src/tracker-preferences/tracker-preferences.ui
index c17030f..760a8a1 100644
--- a/src/tracker-preferences/tracker-preferences.ui
+++ b/src/tracker-preferences/tracker-preferences.ui
@@ -39,6 +39,7 @@
<property name="icon_name">system-search</property>
<property name="type_hint">normal</property>
<signal name="close" handler="gtk_main_quit"/>
+ <signal name="response" handler="tracker_preferences_response_cb"/>
<signal name="delete_event" handler="gtk_main_quit"/>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
@@ -95,7 +96,7 @@
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
- <signal name="value_changed" handler="spinbutton_delay_value_changed_cb"/>
+ <signal name="value_changed" handler="tracker_preferences_spinbutton_delay_value_changed_cb"/>
</object>
<packing>
<property name="position">0</property>
@@ -188,7 +189,7 @@
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
- <signal name="toggled" handler="checkbutton_enable_monitoring_toggled_cb"/>
+ <signal name="toggled" handler="tracker_preferences_checkbutton_enable_monitoring_toggled_cb"/>
</object>
<packing>
<property name="expand">False</property>
@@ -204,7 +205,7 @@
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
- <signal name="toggled" handler="checkbutton_enable_index_on_battery_toggled_cb"/>
+ <signal name="toggled" handler="tracker_preferences_checkbutton_enable_index_on_battery_toggled_cb"/>
</object>
<packing>
<property name="expand">False</property>
@@ -225,7 +226,7 @@
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
- <signal name="toggled" handler="checkbutton_enable_index_on_battery_first_time_toggled_cb"/>
+ <signal name="toggled" handler="tracker_preferences_checkbutton_enable_index_on_battery_first_time_toggled_cb"/>
</object>
</child>
</object>
@@ -244,7 +245,7 @@
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
- <signal name="toggled" handler="checkbutton_index_removable_media_toggled_cb"/>
+ <signal name="toggled" handler="tracker_preferences_checkbutton_index_removable_media_toggled_cb"/>
</object>
<packing>
<property name="expand">False</property>
@@ -265,7 +266,7 @@
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
- <signal name="toggled" handler="checkbutton_index_optical_discs_toggled_cb"/>
+ <signal name="toggled" handler="tracker_preferences_checkbutton_index_optical_discs_toggled_cb"/>
</object>
</child>
</object>
@@ -329,7 +330,7 @@
<property name="can_focus">True</property>
<property name="adjustment">adjustment_disk_space_limit</property>
<property name="digits">0</property>
- <signal name="format_value" handler="hscale_disk_space_limit_format_value_cb"/>
+ <signal name="format_value" handler="tracker_preferences_hscale_disk_space_limit_format_value_cb"/>
</object>
<packing>
<property name="position">1</property>
@@ -392,7 +393,7 @@
<property name="inverted">True</property>
<property name="digits">0</property>
<property name="draw_value">False</property>
- <signal name="format_value" handler="hscale_throttle_format_value_cb"/>
+ <signal name="format_value" handler="tracker_preferences_hscale_throttle_format_value_cb"/>
</object>
<packing>
<property name="right_attach">2</property>
@@ -428,7 +429,7 @@
<property name="can_focus">True</property>
<property name="adjustment">adjustment_drop_device_threshold</property>
<property name="digits">0</property>
- <signal name="format_value" handler="hscale_drop_device_threshold_format_value_cb"/>
+ <signal name="format_value" handler="tracker_preferences_hscale_drop_device_threshold_format_value_cb"/>
</object>
<packing>
<property name="position">0</property>
@@ -556,7 +557,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_index_recursively_add_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_index_recursively_add_clicked_cb"/>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
@@ -574,7 +575,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_index_recursively_remove_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_index_recursively_remove_clicked_cb"/>
<child>
<object class="GtkImage" id="image4">
<property name="visible">True</property>
@@ -594,7 +595,7 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">When toggled, this makes sure your home directory is included in the list.</property>
<property name="active">True</property>
- <signal name="toggled" handler="togglebutton_home_toggled_cb"/>
+ <signal name="toggled" handler="tracker_preferences_togglebutton_home_toggled_cb"/>
<child>
<object class="GtkImage" id="image11">
<property name="visible">True</property>
@@ -698,7 +699,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_index_single_add_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_index_single_add_clicked_cb"/>
<child>
<object class="GtkImage" id="image5">
<property name="visible">True</property>
@@ -716,7 +717,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_index_single_remove_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_index_single_remove_clicked_cb"/>
<child>
<object class="GtkImage" id="image10">
<property name="visible">True</property>
@@ -848,7 +849,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Opens text entry for glob patterns</property>
- <signal name="clicked" handler="button_ignored_directories_globs_add_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_directories_globs_add_clicked_cb"/>
<child>
<object class="GtkImage" id="image6">
<property name="visible">True</property>
@@ -866,7 +867,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_ignored_directories_remove_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_directories_remove_clicked_cb"/>
<child>
<object class="GtkImage" id="image7">
<property name="visible">True</property>
@@ -885,7 +886,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Opens the filechooser dialogue</property>
- <signal name="clicked" handler="button_ignored_directories_add_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_directories_add_clicked_cb"/>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
@@ -964,7 +965,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_ignored_directories_with_content_add_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_directories_with_content_add_clicked_cb"/>
<child>
<object class="GtkImage" id="image12">
<property name="visible">True</property>
@@ -982,7 +983,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_ignored_directories_with_content_remove_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_directories_with_content_remove_clicked_cb"/>
<child>
<object class="GtkImage" id="image13">
<property name="visible">True</property>
@@ -1095,7 +1096,7 @@ Most commonly this is used to ignore directories like *~, *.o, *.la, etc</proper
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_ignored_files_add_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_files_add_clicked_cb"/>
<child>
<object class="GtkImage" id="image8">
<property name="visible">True</property>
@@ -1113,7 +1114,7 @@ Most commonly this is used to ignore directories like *~, *.o, *.la, etc</proper
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="button_ignored_files_remove_clicked_cb"/>
+ <signal name="clicked" handler="tracker_preferences_button_ignored_files_remove_clicked_cb"/>
<child>
<object class="GtkImage" id="image9">
<property name="visible">True</property>
@@ -1189,7 +1190,6 @@ Most commonly this is used to ignore directories like *~, *.o, *.la, etc</proper
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <signal name="clicked" handler="button_apply_clicked_cb"/>
</object>
<packing>
<property name="expand">False</property>
@@ -1204,7 +1204,6 @@ Most commonly this is used to ignore directories like *~, *.o, *.la, etc</proper
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <signal name="clicked" handler="button_close_clicked_cb"/>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/tracker-preferences/tracker-preferences.vala b/src/tracker-preferences/tracker-preferences.vala
index 1ca2b87..edbc4bc 100644
--- a/src/tracker-preferences/tracker-preferences.vala
+++ b/src/tracker-preferences/tracker-preferences.vala
@@ -16,399 +16,507 @@
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
- *
- * Author: Philip Van Hoof <philip codeminded be>
*/
using Gtk;
using GLib;
using Tracker;
-public static Config config = null;
-
-public const string HOME_STRING = "$HOME";
-
-public static Window window;
-public static CheckButton checkbutton_enable_index_on_battery_first_time;
-public static CheckButton checkbutton_enable_index_on_battery;
-public static SpinButton spinbutton_delay;
-public static CheckButton checkbutton_enable_monitoring;
-public static CheckButton checkbutton_index_removable_media;
-public static CheckButton checkbutton_index_optical_discs;
-public static Scale hscale_disk_space_limit;
-public static Scale hscale_throttle;
-public static Scale hscale_drop_device_threshold;
-public static ListStore liststore_index_recursively;
-public static ListStore liststore_index_single;
-public static ListStore liststore_ignored_directories;
-public static ListStore liststore_ignored_files;
-public static ListStore liststore_gnored_directories_with_content;
-public static TreeView treeview_index_recursively;
-public static TreeView treeview_index_single;
-public static TreeView treeview_ignored_directories;
-public static TreeView treeview_ignored_directories_with_content;
-public static TreeView treeview_ignored_files;
-public static ToggleButton togglebutton_home;
-public static Notebook notebook;
-public static RadioButton radiobutton_display_never;
-public static RadioButton radiobutton_display_active;
-public static RadioButton radiobutton_display_always;
-
-public static void spinbutton_delay_value_changed_cb (SpinButton source) {
- config.initial_sleep = source.get_value_as_int ();
-}
+[CCode (cname = "TRACKER_UI_DIR")]
+extern static const string UIDIR;
+
+[CCode (cname = "SRCDIR")]
+extern static const string SRCDIR;
+
+public class Tracker.Preferences {
+ private Config config = null;
+
+ private const string UI_FILE = "tracker-preferences.ui";
+ private const string HOME_STRING = "$HOME";
+
+ private Window window;
+ private CheckButton checkbutton_enable_index_on_battery_first_time;
+ private CheckButton checkbutton_enable_index_on_battery;
+ private SpinButton spinbutton_delay;
+ private CheckButton checkbutton_enable_monitoring;
+ private CheckButton checkbutton_index_removable_media;
+ private CheckButton checkbutton_index_optical_discs;
+ private Scale hscale_disk_space_limit;
+ private Scale hscale_throttle;
+ private Scale hscale_drop_device_threshold;
+ private ListStore liststore_index_recursively;
+ private ListStore liststore_index_single;
+ private ListStore liststore_ignored_directories;
+ private ListStore liststore_ignored_files;
+ private ListStore liststore_gnored_directories_with_content;
+ private TreeView treeview_index_recursively;
+ private TreeView treeview_index_single;
+ private TreeView treeview_ignored_directories;
+ private TreeView treeview_ignored_directories_with_content;
+ private TreeView treeview_ignored_files;
+ private ToggleButton togglebutton_home;
+ private Notebook notebook;
+
+ public Preferences () {
+ config = new Config ();
+ }
-public static void checkbutton_enable_monitoring_toggled_cb (CheckButton source) {
- config.enable_monitors = source.active;
-}
+ public void setup_ui () {
+ var builder = new Gtk.Builder ();
-public static void checkbutton_enable_index_on_battery_toggled_cb (CheckButton source) {
- config.index_on_battery = source.active;
- checkbutton_enable_index_on_battery_first_time.set_sensitive (!source.active);
-}
+ try {
+ builder.add_from_file (SRCDIR + UI_FILE);
+ } catch (GLib.Error e) {
+ //now the install location
+ try {
+ builder.add_from_file (UIDIR + UI_FILE);
+ } catch (GLib.Error e) {
+ var msg = new MessageDialog (null,
+ DialogFlags.MODAL,
+ MessageType.ERROR,
+ ButtonsType.CANCEL,
+ "Failed to load UI file, %s\n",
+ e.message);
+ msg.run ();
+ Gtk.main_quit();
+ }
+ }
-public static void checkbutton_enable_index_on_battery_first_time_toggled_cb (CheckButton source) {
- config.index_on_battery_first_time = source.active;
-}
+ // Get widgets from .ui file
+ window = builder.get_object ("tracker-preferences") as Window;
+ notebook = builder.get_object ("notebook") as Notebook;
-public static void checkbutton_index_removable_media_toggled_cb (CheckButton source) {
- config.index_removable_devices = source.active;
- checkbutton_index_optical_discs.set_sensitive (source.active);
-}
+ checkbutton_enable_monitoring = builder.get_object ("checkbutton_enable_monitoring") as CheckButton;
+ checkbutton_enable_index_on_battery = builder.get_object ("checkbutton_enable_index_on_battery") as CheckButton;
+ checkbutton_enable_index_on_battery_first_time = builder.get_object ("checkbutton_enable_index_on_battery_first_time") as CheckButton;
+ spinbutton_delay = builder.get_object ("spinbutton_delay") as SpinButton;
+ checkbutton_index_removable_media = builder.get_object ("checkbutton_index_removable_media") as CheckButton;
+ checkbutton_index_optical_discs = builder.get_object ("checkbutton_index_optical_discs") as CheckButton;
+ checkbutton_index_optical_discs.set_sensitive (checkbutton_index_removable_media.active);
+ hscale_disk_space_limit = builder.get_object ("hscale_disk_space_limit") as Scale;
+ hscale_throttle = builder.get_object ("hscale_throttle") as Scale;
+ hscale_drop_device_threshold = builder.get_object ("hscale_drop_device_threshold") as Scale;
+ togglebutton_home = builder.get_object ("togglebutton_home") as ToggleButton;
-public static void checkbutton_index_optical_discs_toggled_cb (CheckButton source) {
- config.index_optical_discs = source.active;
-}
+ treeview_index_recursively = builder.get_object ("treeview_index_recursively") as TreeView;
+ treeview_index_single = builder.get_object ("treeview_index_single") as TreeView;
+ treeview_ignored_directories = builder.get_object ("treeview_ignored_directories") as TreeView;
+ treeview_ignored_directories_with_content = builder.get_object ("treeview_ignored_directories_with_content") as TreeView;
+ treeview_ignored_files = builder.get_object ("treeview_ignored_files") as TreeView;
-public static string hscale_disk_space_limit_format_value_cb (Scale source, double value) {
- if (((int) value) == -1) {
- return _("Disabled");
- }
+ setup_standard_treeview (treeview_index_recursively, _("Directory"));
+ setup_standard_treeview (treeview_index_single, _("Directory"));
+ setup_standard_treeview (treeview_ignored_directories, _("Directory"));
+ setup_standard_treeview (treeview_ignored_directories_with_content, _("Directory"));
+ setup_standard_treeview (treeview_ignored_files, _("File"));
- return _("%d%%").printf ((int) value);
-}
+ liststore_index_recursively = builder.get_object ("liststore_index_recursively") as ListStore;
+ liststore_index_single = builder.get_object ("liststore_index_single") as ListStore;
+ liststore_ignored_directories = builder.get_object ("liststore_ignored_directories") as ListStore;
+ liststore_ignored_files = builder.get_object ("liststore_ignored_files") as ListStore;
+ liststore_gnored_directories_with_content = builder.get_object ("liststore_gnored_directories_with_content") as ListStore;
-public static string hscale_throttle_format_value_cb (Scale source, double value) {
- return _("%d/20").printf ((int) value);
-}
+ // Set initial values
+ checkbutton_enable_index_on_battery.active = config.index_on_battery;
+ checkbutton_enable_index_on_battery_first_time.set_sensitive (!checkbutton_enable_index_on_battery.active);
+ checkbutton_enable_index_on_battery_first_time.active = config.index_on_battery_first_time;
+ spinbutton_delay.set_increments (1, 1);
+ spinbutton_delay.value = (double) config.initial_sleep;
+ checkbutton_enable_monitoring.active = config.enable_monitors;
+ checkbutton_index_removable_media.active = config.index_removable_devices;
+ checkbutton_index_optical_discs.active = config.index_optical_discs;
+ hscale_disk_space_limit.set_value ((double) config.low_disk_space_limit);
+ hscale_throttle.set_value ((double) config.throttle);
+ hscale_drop_device_threshold.set_value ((double) config.removable_days_threshold);
-public static string hscale_drop_device_threshold_format_value_cb (Scale source, double value) {
- if (((int) value) == 0) {
- return _("Disabled");
- }
+ fill_in_model (liststore_index_recursively, config.index_recursive_directories_unfiltered);
+ togglebutton_home.active = model_contains (liststore_index_recursively, HOME_STRING);
+ fill_in_model (liststore_index_single, config.index_single_directories_unfiltered);
+ fill_in_model (liststore_ignored_directories, config.ignored_directories);
+ fill_in_model (liststore_ignored_files, config.ignored_files);
+ fill_in_model (liststore_gnored_directories_with_content, config.ignored_directories_with_content);
- return _("%d").printf ((int) value);
-}
+ // We hide this page because it contains the start up
+ // delay which is not necessary to display for most people.
+ notebook.remove_page (0);
-public static void add_freevalue (ListStore model) {
- Dialog dialog;
- Entry entry;
- Container content_area;
+ // Connect signals
+ // builder.connect_signals (null);
+ builder.connect_signals_full (connect_signals);
+ }
- dialog = new Dialog.with_buttons (_("Enter value"),
- window,
- DialogFlags.DESTROY_WITH_PARENT,
- Stock.CANCEL, ResponseType.CANCEL,
- Stock.OK, ResponseType.ACCEPT);
+ public void show () {
+ setup_ui ();
- dialog.set_default_response(ResponseType.ACCEPT);
- content_area = (Container) dialog.get_content_area ();
- entry = new Entry ();
- entry.set_activates_default (true);
- entry.show ();
- content_area.add (entry);
+ window.show ();
+ }
- if (dialog.run () == ResponseType.ACCEPT) {
- string text = entry.get_text ();
- if (text != null && text != "") {
- TreeIter iter;
- model.append (out iter);
- var v = Value (typeof (string));
- v.set_string (text);
- model.set_value (iter, 0, v);
+ // This function is used to fix up the parameter ordering for callbacks
+ // from the .ui file which has the callback names.
+ [CCode (instance_pos = -1)]
+ private void connect_signals (Gtk.Builder builder, GLib.Object object,
+ string signal_name, string handler_name,
+ GLib.Object? connect_object,
+ GLib.ConnectFlags flags) {
+ var module = Module.open (null, ModuleFlags.BIND_LAZY);
+ void* sym;
+
+ if (!module.symbol (handler_name, out sym)) {
+ stdout.printf ("Symbol not found! %s\n", handler_name);
+ } else {
+ Signal.connect (object, signal_name, (GLib.Callback) sym, this);
}
}
- dialog.destroy ();
-}
+ [CCode (instance_pos = -1)]
+ public void response_cb (Dialog source, int response_id) {
+ switch (response_id) {
+ case ResponseType.APPLY:
+ config.index_single_directories = model_to_slist (liststore_index_single);
+ config.ignored_directories = model_to_slist (liststore_ignored_directories);
+ config.ignored_files = model_to_slist (liststore_ignored_files);
+ config.ignored_directories_with_content = model_to_slist (liststore_gnored_directories_with_content);
+ config.index_recursive_directories = model_to_slist (liststore_index_recursively);
+ config.low_disk_space_limit = (int) hscale_disk_space_limit.get_value ();
+ config.throttle = (int) hscale_throttle.get_value ();
+ config.removable_days_threshold = (int) hscale_drop_device_threshold.get_value ();
-public static void add_dir (ListStore model)
-{
- FileChooserDialog dialog = new FileChooserDialog (_("Select directory"), window,
- FileChooserAction.SELECT_FOLDER,
- Stock.CANCEL, ResponseType.CANCEL,
- Stock.OK, ResponseType.ACCEPT);
+ config.save ();
- if (dialog.run () == ResponseType.ACCEPT) {
- TreeIter iter;
- File dir;
+ // TODO: restart the Application and Files miner (no idea how to cleanly do this atm)
- dir = dialog.get_file ();
+ // Fall through on purpose.
+ break;
- model.append (out iter);
- var v = Value (typeof (string));
- v.set_string (dir.get_path());
- model.set_value (iter, 0, v);
+ case ResponseType.CLOSE:
+ break;
+ }
+
+ Gtk.main_quit ();
}
- dialog.destroy ();
-}
+ [CCode (instance_pos = -1)]
+ public void spinbutton_delay_value_changed_cb (SpinButton source) {
+ config.initial_sleep = source.get_value_as_int ();
+ }
-public static void del_dir (TreeView view)
-{
- List<TreePath> list;
- ListStore store;
- TreeModel model;
+ [CCode (instance_pos = -1)]
+ public void checkbutton_enable_monitoring_toggled_cb (CheckButton source) {
+ config.enable_monitors = source.active;
+ }
- TreeSelection selection = view.get_selection ();
- list= selection.get_selected_rows (out model);
+ [CCode (instance_pos = -1)]
+ public void checkbutton_enable_index_on_battery_toggled_cb (CheckButton source) {
+ config.index_on_battery = source.active;
+ checkbutton_enable_index_on_battery_first_time.set_sensitive (!source.active);
+ }
- store = (ListStore) model;
+ [CCode (instance_pos = -1)]
+ public void checkbutton_enable_index_on_battery_first_time_toggled_cb (CheckButton source) {
+ config.index_on_battery_first_time = source.active;
+ }
- foreach (TreePath path in list) {
- TreeIter iter;
- if (model.get_iter (out iter, path)) {
- store.remove (iter);
+ [CCode (instance_pos = -1)]
+ public void checkbutton_index_removable_media_toggled_cb (CheckButton source) {
+ config.index_removable_devices = source.active;
+ checkbutton_index_optical_discs.set_sensitive (source.active);
+ }
+
+ [CCode (instance_pos = -1)]
+ public void checkbutton_index_optical_discs_toggled_cb (CheckButton source) {
+ config.index_optical_discs = source.active;
+ }
+
+ [CCode (instance_pos = -1)]
+ public string hscale_disk_space_limit_format_value_cb (Scale source, double value) {
+ if (((int) value) == -1) {
+ return _("Disabled");
}
+
+ return _("%d%%").printf ((int) value);
}
-}
-public static void button_index_recursively_add_clicked_cb (Button source) {
- add_dir (liststore_index_recursively);
-}
+ [CCode (instance_pos = -1)]
+ public string hscale_throttle_format_value_cb (Scale source, double value) {
+ return _("%d/20").printf ((int) value);
+ }
-public static void button_index_recursively_remove_clicked_cb (Button source) {
- del_dir (treeview_index_recursively);
-}
+ [CCode (instance_pos = -1)]
+ public string hscale_drop_device_threshold_format_value_cb (Scale source, double value) {
+ if (((int) value) == 0) {
+ return _("Disabled");
+ }
-public static void button_index_single_remove_clicked_cb (Button source) {
- del_dir (treeview_index_single);
-}
+ return _("%d").printf ((int) value);
+ }
-public static void button_index_single_add_clicked_cb (Button source) {
- add_dir (liststore_index_single);
-}
+ [CCode (instance_pos = -1)]
+ public void button_index_recursively_add_clicked_cb (Button source) {
+ add_dir (liststore_index_recursively);
+ }
-public static void button_ignored_directories_globs_add_clicked_cb (Button source) {
- add_freevalue (liststore_ignored_directories);
-}
+ [CCode (instance_pos = -1)]
+ public void button_index_recursively_remove_clicked_cb (Button source) {
+ del_dir (treeview_index_recursively);
+ }
-public static void button_ignored_directories_add_clicked_cb (Button source) {
- add_dir (liststore_ignored_directories);
-}
+ [CCode (instance_pos = -1)]
+ public void button_index_single_remove_clicked_cb (Button source) {
+ del_dir (treeview_index_single);
+ }
-public static void button_ignored_directories_remove_clicked_cb (Button source) {
- del_dir (treeview_ignored_directories);
-}
+ [CCode (instance_pos = -1)]
+ public void button_index_single_add_clicked_cb (Button source) {
+ add_dir (liststore_index_single);
+ }
-public static void button_ignored_directories_with_content_add_clicked_cb (Button source) {
- add_freevalue (liststore_gnored_directories_with_content);
-}
+ [CCode (instance_pos = -1)]
+ public void button_ignored_directories_globs_add_clicked_cb (Button source) {
+ add_freevalue (liststore_ignored_directories);
+ }
-public static void button_ignored_directories_with_content_remove_clicked_cb (Button source) {
- del_dir (treeview_ignored_directories_with_content);
-}
+ [CCode (instance_pos = -1)]
+ public void button_ignored_directories_add_clicked_cb (Button source) {
+ add_dir (liststore_ignored_directories);
+ }
-public static void button_ignored_files_add_clicked_cb (Button source) {
- add_freevalue (liststore_ignored_files);
-}
+ [CCode (instance_pos = -1)]
+ public void button_ignored_directories_remove_clicked_cb (Button source) {
+ del_dir (treeview_ignored_directories);
+ }
-public static void button_ignored_files_remove_clicked_cb (Button source) {
- del_dir (treeview_ignored_files);
-}
+ [CCode (instance_pos = -1)]
+ public void button_ignored_directories_with_content_add_clicked_cb (Button source) {
+ add_freevalue (liststore_gnored_directories_with_content);
+ }
-public static SList<string> model_to_slist (ListStore model)
-{
- bool valid;
- SList<string> list = new SList<string>();
- TreeIter iter;
+ [CCode (instance_pos = -1)]
+ public void button_ignored_directories_with_content_remove_clicked_cb (Button source) {
+ del_dir (treeview_ignored_directories_with_content);
+ }
- valid = model.get_iter_first (out iter);
- while (valid) {
- Value value;
- model.get_value (iter, 0, out value);
- list.append (value.get_string ());
- valid = model.iter_next (ref iter);
+ [CCode (instance_pos = -1)]
+ public void button_ignored_files_add_clicked_cb (Button source) {
+ add_freevalue (liststore_ignored_files);
}
- return list;
-}
+ [CCode (instance_pos = -1)]
+ public void button_ignored_files_remove_clicked_cb (Button source) {
+ del_dir (treeview_ignored_files);
+ }
+
+ [CCode (instance_pos = -1)]
+ public void togglebutton_home_toggled_cb (ToggleButton source) {
+ if (source.active && !model_contains (liststore_index_recursively, HOME_STRING)) {
+ TreeIter iter;
+ liststore_index_recursively.append (out iter);
+ var v = Value (typeof (string));
+ v.set_string (HOME_STRING);
+ liststore_index_recursively.set_value (iter, 0, v);
+ }
-public bool model_contains (TreeModel model, string needle) {
- bool valid;
- TreeIter iter;
+ if (!source.active && model_contains (liststore_index_recursively, HOME_STRING)) {
+ bool valid;
+ TreeIter iter;
- valid = model.get_iter_first (out iter);
- while (valid) {
- Value value;
- model.get_value (iter, 0, out value);
- if (value.get_string () == needle) {
- return true;
+ valid = liststore_index_recursively.get_iter_first (out iter);
+ while (valid) {
+ Value value;
+ liststore_index_recursively.get_value (iter, 0, out value);
+ if (value.get_string () == HOME_STRING) {
+ liststore_index_recursively.remove (iter);
+ valid = liststore_index_recursively.get_iter_first (out iter);
+ } else {
+ valid = liststore_index_recursively.iter_next (ref iter);
+ }
+ }
}
- valid = model.iter_next (ref iter);
}
- return false;
-}
-public static void button_apply_clicked_cb (Button source) {
+ private void add_freevalue (ListStore model) {
+ Dialog dialog;
+ Entry entry;
+ Container content_area;
+
+ dialog = new Dialog.with_buttons (_("Enter value"),
+ window,
+ DialogFlags.DESTROY_WITH_PARENT,
+ Stock.CANCEL, ResponseType.CANCEL,
+ Stock.OK, ResponseType.ACCEPT);
+
+ dialog.set_default_response(ResponseType.ACCEPT);
+ content_area = (Container) dialog.get_content_area ();
+ entry = new Entry ();
+ entry.set_activates_default (true);
+ entry.show ();
+ content_area.add (entry);
+
+ if (dialog.run () == ResponseType.ACCEPT) {
+ string text = entry.get_text ();
+
+ if (text != null && text != "") {
+ TreeIter iter;
+ model.append (out iter);
+ var v = Value (typeof (string));
+ v.set_string (text);
+ model.set_value (iter, 0, v);
+ }
+ }
+
+ dialog.destroy ();
+ }
+
+ private void add_dir (ListStore model) {
+ FileChooserDialog dialog = new FileChooserDialog (_("Select directory"), window,
+ FileChooserAction.SELECT_FOLDER,
+ Stock.CANCEL, ResponseType.CANCEL,
+ Stock.OK, ResponseType.ACCEPT);
- config.index_single_directories = model_to_slist (liststore_index_single);
- config.ignored_directories = model_to_slist (liststore_ignored_directories);
- config.ignored_files = model_to_slist (liststore_ignored_files);
- config.ignored_directories_with_content = model_to_slist (liststore_gnored_directories_with_content);
- config.index_recursive_directories = model_to_slist (liststore_index_recursively);
+ if (dialog.run () == ResponseType.ACCEPT) {
+ TreeIter iter;
+ File dir;
- config.low_disk_space_limit = (int) hscale_disk_space_limit.get_value ();
- config.throttle = (int) hscale_throttle.get_value ();
- config.removable_days_threshold = (int) hscale_drop_device_threshold.get_value ();
+ dir = dialog.get_file ();
- config.save ();
+ model.append (out iter);
+ var v = Value (typeof (string));
+ v.set_string (dir.get_path());
+ model.set_value (iter, 0, v);
+ }
- /* TODO: restart the Application and Files miner (no idea how to cleanly do this atm) */
-}
+ dialog.destroy ();
+ }
-public static void button_close_clicked_cb (Button source) {
- Gtk.main_quit ();
-}
+ private void del_dir (TreeView view) {
+ List<TreePath> list;
+ ListStore store;
+ TreeModel model;
+
+ TreeSelection selection = view.get_selection ();
+ list= selection.get_selected_rows (out model);
+
+ store = (ListStore) model;
-public static void togglebutton_home_toggled_cb (ToggleButton source) {
- if (source.active && !model_contains (liststore_index_recursively, HOME_STRING)) {
+ foreach (TreePath path in list) {
+ TreeIter iter;
+ if (model.get_iter (out iter, path)) {
+ store.remove (iter);
+ }
+ }
+ }
+
+ private SList<string> model_to_slist (ListStore model) {
+ bool valid;
+ SList<string> list = new SList<string>();
TreeIter iter;
- liststore_index_recursively.append (out iter);
- var v = Value (typeof (string));
- v.set_string (HOME_STRING);
- liststore_index_recursively.set_value (iter, 0, v);
+
+ valid = model.get_iter_first (out iter);
+ while (valid) {
+ Value value;
+ model.get_value (iter, 0, out value);
+ list.append (value.get_string ());
+ valid = model.iter_next (ref iter);
+ }
+
+ return list;
}
- if (!source.active && model_contains (liststore_index_recursively, HOME_STRING)) {
+ public bool model_contains (TreeModel model, string needle) {
bool valid;
TreeIter iter;
- valid = liststore_index_recursively.get_iter_first (out iter);
+ valid = model.get_iter_first (out iter);
while (valid) {
Value value;
- liststore_index_recursively.get_value (iter, 0, out value);
- if (value.get_string () == HOME_STRING) {
- liststore_index_recursively.remove (iter);
- valid = liststore_index_recursively.get_iter_first (out iter);
- } else {
- valid = liststore_index_recursively.iter_next (ref iter);
+ model.get_value (iter, 0, out value);
+ if (value.get_string () == needle) {
+ return true;
}
+ valid = model.iter_next (ref iter);
}
+ return false;
}
-}
-static void
-fill_in_model (ListStore model, SList<string> list)
-{
- int position = 0;
- foreach (string str in list) {
- try {
- model.insert_with_values (null,
- position++,
- 0,
- Filename.to_utf8 (str,
- -1,
- null,
- null));
- } catch (GLib.ConvertError e) {
- print ("%s", e.message);
+ private void fill_in_model (ListStore model, SList<string> list) {
+ int position = 0;
+ foreach (string str in list) {
+ try {
+ model.insert_with_values (null,
+ position++,
+ 0,
+ Filename.to_utf8 (str,
+ -1,
+ null,
+ null));
+ } catch (GLib.ConvertError e) {
+ print ("%s", e.message);
+ }
}
}
-}
-static void
-setup_standard_treeview (TreeView view, string title)
-{
- TreeViewColumn column = new TreeViewColumn.with_attributes (title,
- new CellRendererText (),
- "text", 0);
- view.append_column (column);
+ private void setup_standard_treeview (TreeView view, string title) {
+ TreeViewColumn column = new TreeViewColumn.with_attributes (title,
+ new CellRendererText (),
+ "text", 0);
+ view.append_column (column);
+ }
}
-static int main (string[] args) {
- Gtk.init (ref args);
-
- Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- Intl.textdomain (GETTEXT_PACKAGE);
+static bool print_version = false;
- try {
- config = new Config ();
+const OptionEntry[] options = {
+ { "version",
+ 'V',
+ 0,
+ OptionArg.NONE,
+ ref print_version,
+ N_("Print version"),
+ null },
+ { null }
+};
- var builder = new Builder ();
- builder.add_from_file (TRACKER_DATADIR + Path.DIR_SEPARATOR_S + "tracker-preferences.ui");
-
- window = builder.get_object ("tracker-preferences") as Window;
- checkbutton_enable_index_on_battery = builder.get_object ("checkbutton_enable_index_on_battery") as CheckButton;
- checkbutton_enable_index_on_battery_first_time = builder.get_object ("checkbutton_enable_index_on_battery_first_time") as CheckButton;
- checkbutton_enable_index_on_battery.active = config.index_on_battery;
- checkbutton_enable_index_on_battery_first_time.set_sensitive (!checkbutton_enable_index_on_battery.active);
- checkbutton_enable_index_on_battery_first_time.active = config.index_on_battery_first_time;
- spinbutton_delay = builder.get_object ("spinbutton_delay") as SpinButton;
- spinbutton_delay.set_increments (1, 1);
- spinbutton_delay.value = (double) config.initial_sleep;
- checkbutton_enable_monitoring = builder.get_object ("checkbutton_enable_monitoring") as CheckButton;
- checkbutton_enable_monitoring.active = config.enable_monitors;
- checkbutton_index_removable_media = builder.get_object ("checkbutton_index_removable_media") as CheckButton;
- checkbutton_index_removable_media.active = config.index_removable_devices;
- checkbutton_index_optical_discs = builder.get_object ("checkbutton_index_optical_discs") as CheckButton;
- checkbutton_index_optical_discs.set_sensitive (checkbutton_index_removable_media.active);
- checkbutton_index_optical_discs.active = config.index_optical_discs;
- hscale_disk_space_limit = builder.get_object ("hscale_disk_space_limit") as Scale;
- hscale_disk_space_limit.set_value ((double) config.low_disk_space_limit);
- hscale_throttle = builder.get_object ("hscale_throttle") as Scale;
- hscale_throttle.set_value ((double) config.throttle);
- hscale_drop_device_threshold = builder.get_object ("hscale_drop_device_threshold") as Scale;
- hscale_drop_device_threshold.set_value ((double) config.removable_days_threshold);
- togglebutton_home = builder.get_object ("togglebutton_home") as ToggleButton;
-
- notebook = builder.get_object ("notebook") as Notebook;
-
- // We hide this page because it contains the start up
- // delay which is not necessary to display for most people.
- notebook.remove_page (0);
-
- treeview_index_recursively = builder.get_object ("treeview_index_recursively") as TreeView;
- treeview_index_single = builder.get_object ("treeview_index_single") as TreeView;
- treeview_ignored_directories = builder.get_object ("treeview_ignored_directories") as TreeView;
- treeview_ignored_directories_with_content = builder.get_object ("treeview_ignored_directories_with_content") as TreeView;
- treeview_ignored_files = builder.get_object ("treeview_ignored_files") as TreeView;
+static int main (string[] args) {
+ OptionContext context = new OptionContext (_("Desktop Search preferences"));
- setup_standard_treeview (treeview_index_recursively, _("Directory"));
- setup_standard_treeview (treeview_index_single, _("Directory"));
- setup_standard_treeview (treeview_ignored_directories, _("Directory"));
- setup_standard_treeview (treeview_ignored_directories_with_content, _("Directory"));
- setup_standard_treeview (treeview_ignored_files, _("File"));
+ try {
+ context.set_help_enabled (true);
+ context.add_main_entries (options, null);
+ context.add_group (Gtk.get_option_group (true));
+ context.parse (ref args);
+ } catch (Error e) {
+ printerr (e.message + "\n\n");
+ printerr (context.get_help (true, null));
+ return 1;
+ }
- liststore_index_recursively = builder.get_object ("liststore_index_recursively") as ListStore;
- fill_in_model (liststore_index_recursively, config.index_recursive_directories_unfiltered);
+ if (print_version) {
+ string about = "";
+ string license = "";
- togglebutton_home.active = model_contains (liststore_index_recursively, HOME_STRING);
+ about += "Tracker " + Config.PACKAGE_VERSION + "\n";
- liststore_index_single = builder.get_object ("liststore_index_single") as ListStore;
- fill_in_model (liststore_index_single, config.index_single_directories_unfiltered);
-
- liststore_ignored_directories = builder.get_object ("liststore_ignored_directories") as ListStore;
- fill_in_model (liststore_ignored_directories, config.ignored_directories);
+ license += "This program is free software and comes without any warranty.\n";
+ license += "It is licensed under version 2 or later of the General Public ";
+ license += "License which can be viewed at:\n";
+ license += "\n";
+ license += " http://www.gnu.org/licenses/gpl.txt\n";
- liststore_ignored_files = builder.get_object ("liststore_ignored_files") as ListStore;
- fill_in_model (liststore_ignored_files, config.ignored_files);
+ print ("\n" + about + "\n" + license + "\n");
+ return 0;
+ }
- liststore_gnored_directories_with_content = builder.get_object ("liststore_gnored_directories_with_content") as ListStore;
- fill_in_model (liststore_gnored_directories_with_content, config.ignored_directories_with_content);
+ Gtk.init (ref args);
- builder.connect_signals (null);
+ Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+ Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+ Intl.textdomain (Config.GETTEXT_PACKAGE);
- window.show_all ();
+ Tracker.Preferences p = new Tracker.Preferences ();
+ p.show();
- Gtk.main ();
- } catch (Error e) {
- stderr.printf ("Could not load UI: %s\n", e.message);
- return 1;
- }
+ Gtk.main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]