making calling bookmarks actually work :)
authorRobert Kaiser <robert@notebook.(none)>
Sun, 2 Aug 2009 19:53:09 +0000 (21:53 +0200)
committerRobert Kaiser <robert@notebook.(none)>
Sun, 2 Aug 2009 19:53:09 +0000 (21:53 +0200)
xulapp/chrome/mandelbrot/content/mandelbrot.js

index d07345e..c0a8c1c 100644 (file)
@@ -516,8 +516,35 @@ function callBookmark(evtarget) {
     adjustCoordsAndDraw(new complex(0,0), new complex(0,0));
     return;
   }
-  alert(evtarget.getAttribute('label') + ', ' + evtarget.getAttribute('bmRowID'));
-  //gPref.setIntPref("mandelbrot.iteration_max", iterMax);
+
+  if (evtarget.getAttribute('bmRowID')) {
+    let iterMax = 0;
+    let C_min = null;
+    let C_max = null;
+
+    let file = Components.classes["@mozilla.org/file/directory_service;1"]
+                         .getService(Components.interfaces.nsIProperties)
+                         .get("ProfD", Components.interfaces.nsIFile);
+    file.append("mandelbookmarks.sqlite");
+    let connection = Components.classes["@mozilla.org/storage/service;1"]
+                               .getService(Components.interfaces.mozIStorageService)
+                               .openDatabase(file);
+    let statement = connection.createStatement(
+        "SELECT iteration_max,Cr_min,Cr_max,Ci_min,Ci_max FROM bookmarks WHERE ROWID=?1");
+    statement.bindStringParameter(0, evtarget.getAttribute('bmRowID'));
+    while (statement.executeStep()) {
+      iterMax = statement.getInt32(0);
+      C_min = new complex(statement.getDouble(1), statement.getDouble(3));
+      C_max = new complex(statement.getDouble(2), statement.getDouble(4));
+    }
+    statement.finalize();
+    connection.close();
+
+    if (iterMax && C_min && C_max) {
+      gPref.setIntPref("mandelbrot.iteration_max", iterMax);
+      adjustCoordsAndDraw(C_min, C_max);
+    }
+  }
 }
 
 function saveBookmark() {