This commit is contained in:
Myk Melez 2008-07-27 15:17:13 -07:00
Родитель e19700db03
Коммит 37e93febae
6 изменённых файлов: 54 добавлений и 45 удалений

Просмотреть файл

@ -183,6 +183,7 @@ let Subscriber = {
twitter.subscribe(credentials);
},
//**************************************************************************//
// OPML Import

Просмотреть файл

@ -42,6 +42,7 @@ let SnowlDatastore = {
type: TABLE_TYPE_NORMAL,
columns: [
"id INTEGER PRIMARY KEY",
"type TEXT NOT NULL",
"name TEXT NOT NULL",
// XXX Call these URL instead of URI, since they are unambiguously
// locations, not names (and thus never URNs)?

Просмотреть файл

@ -47,6 +47,8 @@ function SnowlFeed(aID, aName, aMachineURI, aHumanURI, aLastRefreshed, aImportan
}
SnowlFeed.prototype = {
constructor: SnowlFeed,
__proto__: SnowlSource.prototype,
_log: Log4Moz.Service.getLogger("Snowl.Feed"),
@ -538,27 +540,12 @@ SnowlFeed.prototype = {
if (!this.name)
this.name = feed.title.plainText();
this.humanURI = feed.link;
// Add the source to the database.
let statement =
SnowlDatastore.createStatement("INSERT INTO sources (name, machineURI, humanURI) " +
"VALUES (:name, :machineURI, :humanURI)");
try {
statement.params.name = this.name;
statement.params.machineURI = this.machineURI.spec;
statement.params.humanURI = this.humanURI.spec;
statement.step();
}
finally {
statement.reset();
}
// Extract the ID of the source from the newly-created database record.
this.id = SnowlDatastore.dbConnection.lastInsertRowID;
this.persist();
// Let observers know about the new source.
this._obsSvc.notifyObservers(null, "sources:changed", null);
// Refresh the feed to import all its items.
this.onRefreshResult(aResult);
}

Просмотреть файл

@ -9,6 +9,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://snowl/modules/log4moz.js");
Cu.import("resource://snowl/modules/datastore.js");
Cu.import("resource://snowl/modules/feed.js");
Cu.import("resource://snowl/modules/twitter.js");
Cu.import("resource://snowl/modules/source.js");
Cu.import("resource://snowl/modules/URI.js");
@ -173,7 +174,7 @@ let SnowlService = {
get _getSourcesStatement() {
let statement = SnowlDatastore.createStatement(
"SELECT id, name, machineURI, humanURI, lastRefreshed, importance FROM sources"
"SELECT id, type, name, machineURI, humanURI, lastRefreshed, importance FROM sources"
);
delete this._getSourcesStatement;
this._getSourcesStatement = statement;
@ -186,12 +187,19 @@ let SnowlService = {
try {
while (this._getSourcesStatement.step()) {
let row = this._getSourcesStatement.row;
sources.push(new SnowlFeed(row.id,
row.name,
URI.get(row.machineURI),
URI.get(row.humanURI),
new Date(row.lastRefreshed),
row.importance));
let constructor = eval(row.type);
if (!constructor) {
this._log.error("no constructor for type " + row.type);
continue;
}
sources.push(new constructor(row.id,
row.name,
URI.get(row.machineURI),
URI.get(row.humanURI),
new Date(row.lastRefreshed),
row.importance));
}
}
finally {

Просмотреть файл

@ -145,5 +145,28 @@ SnowlSource.prototype = {
// FIXME: once we support other types of sources, override this
// with a type-specific icon.
return URI.get("chrome://browser/skin/feeds/feedIcon16.png");
},
persist: function() {
let statement =
SnowlDatastore.createStatement(
"INSERT INTO sources (name, type, machineURI, humanURI) " +
"VALUES (:name, :type, :machineURI, :humanURI)"
);
try {
statement.params.name = this.name;
statement.params.type = this.constructor.name;
statement.params.machineURI = this.machineURI.spec;
statement.params.humanURI = this.humanURI.spec;
statement.step();
}
finally {
statement.reset();
}
// Extract the ID of the source from the newly-created database record.
this.id = SnowlDatastore.dbConnection.lastInsertRowID;
}
};

Просмотреть файл

@ -1,4 +1,4 @@
EXPORTED_SYMBOLS = ["SnowlTwitter"];
let EXPORTED_SYMBOLS = ["SnowlTwitter"];
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -36,6 +36,8 @@ function SnowlTwitter(aID, aLastRefreshed, aImportance) {
}
SnowlTwitter.prototype = {
constructor: SnowlTwitter,
__proto__: SnowlSource.prototype,
_log: Log4Moz.Service.getLogger("Snowl.Twitter"),
@ -209,27 +211,12 @@ SnowlTwitter.prototype = {
if (this._authInfo)
this._saveLogin();
// Add the source to the database.
// FIXME: factor this out with the identical code in feed.js.
let statement =
SnowlDatastore.createStatement("INSERT INTO sources (name, machineURI, humanURI) " +
"VALUES (:name, :machineURI, :humanURI)");
try {
statement.params.name = this.name;
statement.params.machineURI = this.machineURI.spec;
statement.params.humanURI = this.humanURI.spec;
statement.step();
}
finally {
statement.reset();
}
// Save the source to the database.
this.persist();
// Extract the ID of the source from the newly-created database record.
this.id = SnowlDatastore.dbConnection.lastInsertRowID;
// Let observers know about the new source.
this._obsSvc.notifyObservers(null, "sources:changed", null);
this.refresh();
},
@ -358,6 +345,8 @@ SnowlTwitter.prototype = {
if (messagesChanged)
this._obsSvc.notifyObservers(null, "messages:changed", null);
// FIXME: if we added people, refresh the collections view too.
Observers.notify(this, "snowl:subscribe:get:end", null);
},