sbMigrate14to17pre0.smartplaylist.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
26 Components.utils.import("resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
27 
28 const Cc = Components.classes;
29 const Ci = Components.interfaces;
30 const Cr = Components.results;
31 
32 const FROM_VERSION = 23;
33 const TO_VERSION = 24;
34 
35 function LOG(s) {
36  dump("----++++----++++sbLibraryMigration " +
37  FROM_VERSION + " to " + TO_VERSION + ": " +
38  s +
39  "\n----++++----++++\n");
40 }
41 
43 {
44  SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(this);
45  this._errors = [];
46 }
47 
48 //-----------------------------------------------------------------------------
49 // sbLocalDatabaseMigration Implementation
50 //-----------------------------------------------------------------------------
51 
52 sbLibraryMigration.prototype = {
53  __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
54  classDescription: 'Songbird Migration Handler, version ' +
55  FROM_VERSION + ' to ' + TO_VERSION,
56  classID: Components.ID("{6f74cb1d-49b5-4475-99ca-63ebb3696a40}"),
57  contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID +
58  FROM_VERSION + 'to' + TO_VERSION,
59 
60  fromVersion: FROM_VERSION,
61  toVersion: TO_VERSION,
62 
63  migrate: function sbLibraryMigration_migrate(aLibrary) {
64  try {
65  this._databaseGUID = aLibrary.databaseGuid;
66  this._databaseLocation = aLibrary.databaseLocation;
67 
68  // Get all the smart playlists
69  var dbQuery = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
70  .createInstance(Ci.sbIDatabaseQuery);
71  dbQuery.databaseLocation = aLibrary.databaseLocation;
72  dbQuery.setDatabaseGUID(aLibrary.databaseGuid);
73  dbQuery.addQuery(<>
74  SELECT guid FROM media_items
75  WHERE media_list_type_id = "2" AND is_list = "1";
76  </>);
77  dbQuery.setAsyncQuery(false);
78  if (dbQuery.execute() != 0) {
79  throw "Failed to get the smart playlists";
80  }
81 
82  // Insert all the smart playlist guids to the dirty db.
83  // sbSmartMediaListsUpdater will update them later.
84  var result = dbQuery.getResultObject();
85  var length = result.getRowCount();
86 
87  // Run a query that will mark the library as migrated
88  var query = this.createMigrationQuery(aLibrary);
89  query.addQuery("commit");
90  var retval;
91  query.setAsyncQuery(false);
92 
93  if (length == 0) {
94  query.execute(retval);
95  return;
96  }
97 
98  // Init the dirty db
99  var smartListQuery = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
100  .createInstance(Ci.sbIDatabaseQuery);
101  smartListQuery.setAsyncQuery(false);
102  smartListQuery.setDatabaseGUID("songbird");
103  smartListQuery.addQuery(
104  "CREATE TABLE IF NOT EXISTS smartplupd_update_video_lists " +
105  "(listguid TEXT UNIQUE NOT NULL)");
106 
107  var prepStatement = smartListQuery.prepareQuery(
108  "INSERT OR REPLACE INTO smartplupd_update_video_lists VALUES (?)");
109  var guid;
110  for (var i = 0; i < length; ++i) {
111  guid = result.getRowCell(i, 0);
112  smartListQuery.addPreparedStatement(prepStatement);
113  smartListQuery.bindStringParameter(0, guid);
114  }
115 
116  if (smartListQuery.execute() != 0) {
117  throw "Failed to insert the guid to the dirty db";
118  }
119 
120  query.execute(retval);
121  }
122  catch (e) {
123  LOG("Exception occured: " + e);
124  throw e;
125  }
126  },
127 };
128 
129 //-----------------------------------------------------------------------------
130 // Module
131 //-----------------------------------------------------------------------------
132 function NSGetModule(compMgr, fileSpec) {
133  return XPCOMUtils.generateModule([
135  ]);
136 }
137 
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function sbLibraryMigration()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
function NSGetModule(compMgr, fileSpec)
_getSelectedPageStyle s i