[tracker/miner-web: 4/7] tracker-preferences: Add a tab to manage web miners, though there's no logic yet



commit 2ed840d8bbb38de6a4978146553d3f4640bcc22d
Author: Adrien Bustany <madcat mymadcat com>
Date:   Fri Nov 6 09:09:37 2009 -0300

    tracker-preferences: Add a tab to manage web miners, though there's no logic yet
    
    Web miners requires a preliminary association step to be functional. This tab
    presents a list of the web miners and allows to associate them with their
    respective web services.

 src/tracker-preferences/Makefile.am              |    2 +-
 src/tracker-preferences/tracker-preferences.ui   |  260 +++++++++++++++++++++-
 src/tracker-preferences/tracker-preferences.vala |  137 +++++++++++-
 3 files changed, 393 insertions(+), 6 deletions(-)
---
diff --git a/src/tracker-preferences/Makefile.am b/src/tracker-preferences/Makefile.am
index c734724..c2ca39d 100644
--- a/src/tracker-preferences/Makefile.am
+++ b/src/tracker-preferences/Makefile.am
@@ -56,7 +56,7 @@ EXTRA_DIST = 								\
 	$(tracker_preferences_VALASOURCES)
 
 tracker-preferences.vala.stamp: $(tracker_preferences_VALASOURCES) tracker-config.vapi tracker-status-icon-config.vapi config.vapi
-	$(AM_V_GEN)$(VALAC) --pkg gtk+-2.0 --pkg gmodule-2.0 -C $(VALAFLAGS) $^
+	$(AM_V_GEN)$(VALAC) --pkg gtk+-2.0 --pkg gmodule-2.0 --pkg dbus-glib-1 --vapidir $(top_srcdir)/src/libtracker-miner --pkg tracker-miner-web-$(TRACKER_API_VERSION) -C $(VALAFLAGS) $^
 	$(AM_V_GEN)touch $@
 
 CLEANFILES = $(desktop_DATA)
diff --git a/src/tracker-preferences/tracker-preferences.ui b/src/tracker-preferences/tracker-preferences.ui
index 3af1d3a..2bb3ba7 100644
--- a/src/tracker-preferences/tracker-preferences.ui
+++ b/src/tracker-preferences/tracker-preferences.ui
@@ -32,6 +32,18 @@
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="liststore_miners">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name dbus_name -->
+      <column type="gchararray"/>
+      <!-- column-name dbus_path -->
+      <column type="gchararray"/>
+      <!-- column-name association_type -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="tracker-preferences">
     <property name="width_request">500</property>
     <property name="border_width">5</property>
@@ -1167,6 +1179,252 @@ Most commonly this is used to ignore directories like *~, *.o, *.la, etc</proper
                 <property name="tab_fill">False</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkHPaned" id="hpaned1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <child>
+                  <object class="GtkTreeView" id="treeview_miners">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">liststore_miners</property>
+                  </object>
+                  <packing>
+                    <property name="resize">False</property>
+                    <property name="shrink">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkVBox" id="vbox10">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">12</property>
+                    <child>
+                      <object class="GtkLabel" id="label_miner_info">
+                        <property name="visible">True</property>
+                        <property name="xalign">0</property>
+                        <property name="ypad">12</property>
+                        <property name="label" translatable="yes">&lt;i&gt;Select a miner to view its status&lt;/i&gt;</property>
+                        <property name="use_markup">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkVBox" id="vbox_miners">
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkFrame" id="frame2">
+                            <property name="visible">True</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <object class="GtkAlignment" id="alignment7">
+                                <property name="visible">True</property>
+                                <property name="top_padding">6</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <object class="GtkHBox" id="hbox7">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkImage" id="image_miner_status">
+                                        <property name="visible">True</property>
+                                        <property name="stock">gtk-dialog-error</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label_miner_status">
+                                        <property name="visible">True</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">Running</property>
+                                      </object>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label13">
+                                <property name="visible">True</property>
+                                <property name="ypad">12</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Miner status&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkFrame" id="frame_miner_association">
+                            <property name="visible">True</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <object class="GtkAlignment" id="alignment8">
+                                <property name="visible">True</property>
+                                <property name="top_padding">6</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <object class="GtkVBox" id="vbox11">
+                                    <property name="visible">True</property>
+                                    <property name="orientation">vertical</property>
+                                    <child>
+                                      <object class="GtkVBox" id="vbox_miner_tokenassociation">
+                                        <property name="visible">True</property>
+                                        <property name="orientation">vertical</property>
+                                        <property name="spacing">6</property>
+                                        <child>
+                                          <object class="GtkLabel" id="label_miner_associated">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">0</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkButton" id="button_miner_associate">
+                                            <property name="label">Associate</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="receives_default">True</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkTable" id="table_miner_userassociation">
+                                        <property name="visible">True</property>
+                                        <property name="n_rows">3</property>
+                                        <property name="n_columns">2</property>
+                                        <child>
+                                          <placeholder/>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label15">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label" translatable="yes">Username:</property>
+                                          </object>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label16">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label" translatable="yes">Password:</property>
+                                          </object>
+                                          <packing>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="entry_miner_username">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">&#x25CF;</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="entry_miner_password">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">&#x25CF;</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkButton" id="button_miner_save">
+                                            <property name="label">gtk-apply</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="receives_default">True</property>
+                                            <property name="use_stock">True</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">2</property>
+                                            <property name="bottom_attach">3</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label14">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Association&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="resize">True</property>
+                    <property name="shrink">True</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label12">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Web miners</property>
+              </object>
+              <packing>
+                <property name="position">3</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">1</property>
@@ -1244,8 +1502,8 @@ Most commonly this is used to ignore directories like *~, *.o, *.la, etc</proper
   </object>
   <object class="GtkSizeGroup" id="sizegroup_indexing">
     <widgets>
-      <widget name="label_disk_space_limit"/>
       <widget name="label_throttle"/>
+      <widget name="label_disk_space_limit"/>
     </widgets>
   </object>
 </interface>
diff --git a/src/tracker-preferences/tracker-preferences.vala b/src/tracker-preferences/tracker-preferences.vala
index 0a96af4..ad961dd 100644
--- a/src/tracker-preferences/tracker-preferences.vala
+++ b/src/tracker-preferences/tracker-preferences.vala
@@ -26,8 +26,12 @@ using Tracker;
 
 public static Config config = null;
 public static IconConfig icon_config = null;
+public static DBus.Connection dbus_conn;
 
 public const string HOME_STRING = "$HOME";
+public const string DESKTOP_GROUP = "Desktop Entry";
+public const string MINER_ON_ICON = "gtk-yes";
+public const string MINER_OFF_ICON = "gtk-no";
 
 public static Window window;
 public static CheckButton checkbutton_enable_index_on_battery_first_time;
@@ -53,6 +57,17 @@ public static ToggleButton togglebutton_home;
 public static RadioButton radiobutton_display_never;
 public static RadioButton radiobutton_display_active;
 public static RadioButton radiobutton_display_always;
+public static ListStore liststore_miners;
+public static TreeView treeview_miners;
+public static Image image_miner_status;
+public static Label label_miner_status;
+public static Label label_miner_info;
+public static Label label_miner_associated;
+public static Button button_miner_associate;
+public static VBox vbox_miners;
+public static Frame frame_miner_association;
+public static VBox vbox_miner_tokenassociation;
+public static Table table_miner_userassociation;
 
 public static void radiobutton_visibility_toggled_cb (RadioButton source) {
 	if (radiobutton_display_never.active) {
@@ -152,7 +167,7 @@ public static void add_freevalue (ListStore model) {
 
 public static void add_dir (ListStore model)
 {
-	FileChooserDialog dialog = new FileChooserDialog (_("Select directory"), window, 
+	FileChooserDialog dialog = new FileChooserDialog (_("Select directory"), window,
 	                                              FileChooserAction.SELECT_FOLDER,
 	                                              STOCK_CANCEL, ResponseType.CANCEL,
 	                                              STOCK_OK, ResponseType.ACCEPT);
@@ -321,12 +336,103 @@ fill_in_model (ListStore model, SList<string> list)
 static void
 setup_standard_treeview (TreeView view, string title)
 {
-	TreeViewColumn column = new TreeViewColumn.with_attributes (title, 
-	                                                            new CellRendererText (), 
+	TreeViewColumn column = new TreeViewColumn.with_attributes (title,
+	                                                            new CellRendererText (),
 	                                                            "text", 0);
 	view.append_column (column);
 }
 
+static void
+fill_in_miners_model ()
+{
+	string miners_folder_path = Path.build_filename (TRACKER_DATADIR, "miners");
+	try {
+		Dir miners_dir = Dir.open (miners_folder_path);
+		int position = 0;
+		string current_filename;
+		while ((current_filename = miners_dir.read_name ()) != null) {
+			string desktop_path = Path.build_filename (TRACKER_DATADIR, "miners", current_filename);
+			KeyFile desktop_file = new KeyFile ();
+			try {
+				desktop_file.load_from_file (desktop_path, KeyFileFlags.NONE);
+				if (!desktop_file.has_key (DESKTOP_GROUP, "X-Tracker-Bridge-AuthScheme")) {
+					// Only web miners should have this key defined
+					continue;
+				}
+				liststore_miners.insert_with_values (null, position++,
+				                                     0 /* Name */, desktop_file.get_string (DESKTOP_GROUP, "Name"),
+				                                     1 /* DBus name */, desktop_file.get_string (DESKTOP_GROUP, "DBusName"),
+				                                     2 /* DBus path */, desktop_file.get_string (DESKTOP_GROUP, "DBusPath"));
+			} catch (Error e) {
+				warning ("Couldn't load miner %s : %s", current_filename, e.message);
+			}
+		}
+	} catch (Error e) {
+		warning ("Couldn't list miners : %s", e.message);
+	}
+}
+
+static void
+update_miner_status_panel (string dbus_name, string dbus_path, string association_type)
+{
+	dynamic DBus.Object miner = dbus_conn.get_object (dbus_name, dbus_path, MINER_WEB_DBUS_INTERFACE);
+
+	try {
+		MinerWeb.AssociationStatus miner_status = miner.GetAssociationStatus ();
+
+		switch (miner_status) {
+			case MinerWeb.AssociationStatus.ASSOCIATED:
+				image_miner_status.set_from_stock (STOCK_YES, IconSize.MENU);
+				label_miner_status.set_text (_("Running"));
+				label_miner_associated.set_text (_("The bridge is associated"));
+				button_miner_associate.set_label (_("Associate as another user"));
+				break;
+			case MinerWeb.AssociationStatus.UNASSOCIATED:
+				image_miner_status.set_from_stock (STOCK_NO, IconSize.MENU);
+				label_miner_status.set_text (_("Needs association"));
+				label_miner_associated.set_text (_("The bridge is not associated yet"));
+				button_miner_associate.set_label (_("Associate"));
+				break;
+		}
+		frame_miner_association.show ();
+
+		switch (association_type) {
+			case "Token":
+				vbox_miner_tokenassociation.show ();
+				table_miner_userassociation.hide ();
+				break;
+			case "UserPass":
+				vbox_miner_tokenassociation.hide ();
+				table_miner_userassociation.show ();
+				break;
+			default:
+				break;
+		}
+	} catch (Error e) {
+		warning ("Error while contacting miner : %s", e.message);
+		image_miner_status.set_from_stock (STOCK_DIALOG_ERROR, IconSize.MENU);
+		label_miner_status.set_text (_("Error while contacting the bridge"));
+		frame_miner_association.hide ();
+	}
+
+	vbox_miners.show ();
+}
+
+static void
+treeview_miners_selection_changed ()
+{
+	label_miner_info.hide ();
+
+	TreeIter iter = TreeIter ();
+	if (treeview_miners.get_selection ().get_selected (null, out iter)) {
+		Value dbus_name, dbus_path, association_type;
+		liststore_miners.get_value (iter, 1, out dbus_name);
+		liststore_miners.get_value (iter, 2, out dbus_path);
+		liststore_miners.get_value (iter, 3, out association_type);
+		update_miner_status_panel (dbus_name.get_string (), dbus_path.get_string (), association_type.get_string ());
+	}
+}
+
 static int main (string[] args) {
 	Gtk.init (ref args);
 
@@ -370,12 +476,24 @@ static int main (string[] args) {
 		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;
+		treeview_miners = builder.get_object ("treeview_miners") as TreeView;
+
+		label_miner_info = builder.get_object ("label_miner_info") as Label;
+		image_miner_status = builder.get_object ("image_miner_status") as Image;
+		label_miner_status = builder.get_object ("label_miner_status") as Label;
+		label_miner_associated = builder.get_object ("label_miner_associated") as Label;
+		vbox_miners = builder.get_object ("vbox_miners") as VBox;
+		frame_miner_association = builder.get_object ("frame_miner_association") as Frame;
+		vbox_miner_tokenassociation = builder.get_object ("vbox_miner_tokenassociation") as VBox;
+		table_miner_userassociation = builder.get_object ("table_miner_userassociation") as Table;
 
 		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"));
+		setup_standard_treeview (treeview_miners, _("Miner"));
+		treeview_miners.get_selection ().changed.connect (treeview_miners_selection_changed);
 
 		liststore_index_recursively = builder.get_object ("liststore_index_recursively") as ListStore;
 		fill_in_model (liststore_index_recursively, config.index_recursive_directories);
@@ -394,14 +512,25 @@ static int main (string[] args) {
 		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);
 
+		liststore_miners = builder.get_object ("liststore_miners") as ListStore;
+		fill_in_miners_model ();
+
 		builder.connect_signals (null);
 
+		try {
+			dbus_conn = DBus.Bus.get (DBus.BusType.SESSION);
+		} catch (Error e) {
+			critical ("Couldn't connect to session bus : %s", e.message);
+		}
+
 		window.show_all ();
+		vbox_miners.hide ();
+
 		Gtk.main ();
 	} catch (Error e) {
 		stderr.printf ("Could not load UI: %s\n", e.message);
 		return 1;
-	} 
+	}
 
 	return 0;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]