[gnome-boxes] Make MediaManager a singleton
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Make MediaManager a singleton
- Date: Mon, 26 Nov 2012 16:21:25 +0000 (UTC)
commit ca2c92684c3f05aa43e7091b0e8652dfe90dd0f7
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Oct 5 05:06:55 2012 +0300
Make MediaManager a singleton
https://bugzilla.gnome.org/show_bug.cgi?id=688770
src/media-manager.vala | 26 +++++++++++++++++---------
src/wizard.vala | 2 +-
2 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/src/media-manager.vala b/src/media-manager.vala
index 601ed4c..ea46a61 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -5,6 +5,7 @@ using GUdev;
using Tracker;
private class Boxes.MediaManager : Object {
+ private static MediaManager media_manager;
private const string SPARQL_QUERY = "SELECT nie:url(?iso) nie:title(?iso) osinfo:id(?iso) osinfo:mediaId(?iso)" +
" { ?iso nfo:isBootable true }";
@@ -13,15 +14,11 @@ private class Boxes.MediaManager : Object {
private Sparql.Connection connection;
- public MediaManager () {
- client = new GUdev.Client ({"block"});
- os_db = new OSDatabase ();
- os_db.load.begin ();
- try {
- connection = Sparql.Connection.get ();
- } catch (GLib.Error error) {
- critical ("Error connecting to Tracker: %s", error.message);
- }
+ public static MediaManager get_instance () {
+ if (media_manager == null)
+ media_manager = new MediaManager ();
+
+ return media_manager;
}
public async InstallerMedia create_installer_media_for_path (string path,
@@ -83,6 +80,17 @@ private class Boxes.MediaManager : Object {
return list;
}
+ private MediaManager () {
+ client = new GUdev.Client ({"block"});
+ os_db = new OSDatabase ();
+ os_db.load.begin ();
+ try {
+ connection = Sparql.Connection.get ();
+ } catch (GLib.Error error) {
+ critical ("Error connecting to Tracker: %s", error.message);
+ }
+ }
+
private static int compare_media (InstallerMedia media_a, InstallerMedia media_b) {
return strcmp (media_a.label, media_b.label);
}
diff --git a/src/wizard.vala b/src/wizard.vala
index c187132..ec22c3e 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -129,7 +129,7 @@ private class Boxes.Wizard: Boxes.UI {
construct {
steps = new GenericArray<Gtk.Label> ();
steps.length = WizardPage.LAST;
- media_manager = new MediaManager ();
+ media_manager = MediaManager.get_instance ();
}
private void wizard_source_update_next () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]