Mercurial > hg > digilib-old
comparison xul/content/sidebar/installer.js @ 203:bf945fcf9105
restarting with version control of xul sidebar/toolbar
author | luginbue |
---|---|
date | Fri, 27 Feb 2004 11:24:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
202:7501034e54e1 | 203:bf945fcf9105 |
---|---|
1 //@@@@@@@@@@@@@@@@ | |
2 function MOZ_SidebarInstaller //<c><a>public<d>Mozilla Sidebar installer class | |
3 ( | |
4 _title, //<p>string<d>Sidebar title | |
5 _url, //<p>string<d>Sidebar URL | |
6 _customize //<p>string<d>Sidebar customization | |
7 ){ | |
8 const | |
9 INTERFACES = Components.interfaces, | |
10 nsIRDFRemoteDataSource = INTERFACES.nsIRDFRemoteDataSource, | |
11 nsIRDFService = INTERFACES.nsIRDFService, RDF_CID = "@mozilla.org/rdf/rdf-service;1", | |
12 nsIRDFContainer = INTERFACES.nsIRDFContainer, CONTAINER_CID = "@mozilla.org/rdf/container;1", | |
13 nsIProperties = INTERFACES.nsIProperties, DIR_SERV_CID = "@mozilla.org/file/directory_service;1", | |
14 nsIIOService = INTERFACES.nsIIOService, IO_SERVICE_CID = '@mozilla.org/network/io-service;1', | |
15 NC_NAMESPACE = 'http://home.netscape.com/NC-rdf#', | |
16 SIDEBAR_PANEL_URN = NC_NAMESPACE + 'panel-list', | |
17 SIDEBAR_CUR_URN = 'urn:sidebar:current-panel-list', | |
18 SIDEBAR_3RD_URN = 'urn:sidebar:3rdparty-panel:', | |
19 PANELS_RDF_FILE = "UPnls"; //directory services property to find panels.rdf | |
20 const | |
21 MSG_PANEL_IN_LIST = ' panel is already in Sidebar list\nSelect it in the Tabs > Customize Sidebar... menu', | |
22 MSG_PANEL_REFRESHED = ' panel successfully refreshed', | |
23 MSG_PANEL_ADDED = ' panel has been successfully added to your sidebar', | |
24 MSG_PANEL_SOURCE = 'Sidebar datasource is busted', | |
25 MSG_NO_RDF_FILE = 'panels.rdf file does not exist in your profile\nInstallation aborted'; | |
26 | |
27 | |
28 | |
29 //================ | |
30 this.MOZ_SidebarInstaller = function //<m>void<a>private<d>class constructor | |
31 ( | |
32 title, //<p>string<d>Sidebar panel title | |
33 url, //<p>string<d>Sidebar panel URL | |
34 customize //<p>string<d>Sidebar panel customization preferences | |
35 ){ | |
36 this.className = 'MOZ_SidebarInstaller'; | |
37 this.title = title; | |
38 this.url = url; | |
39 this.customize = customize; | |
40 this.setIn(); | |
41 }//</m>MOZ_SidebarInstaller | |
42 | |
43 | |
44 | |
45 //================ | |
46 this.setIn = function //<m>void<a>private<d>Instance i12n | |
47 (){ | |
48 this.rdf = Components.classes[RDF_CID].getService(nsIRDFService); | |
49 this.container = Components.classes[CONTAINER_CID].createInstance(nsIRDFContainer); | |
50 this.source = this.rdf.GetDataSource(this.getSource()); | |
51 this.currentResource = this.rdf.GetResource(SIDEBAR_CUR_URN); | |
52 this.installResource = this.rdf.GetResource(SIDEBAR_3RD_URN + this.url); | |
53 }//</m>setIn | |
54 | |
55 | |
56 | |
57 //================ | |
58 this.setUp = function //<m>void<a>public<d>Installation execution method | |
59 (){ | |
60 if(!this.source) return; | |
61 this.container.Init(this.source, this.getPanelList()); | |
62 if (this.container.IndexOf(this.installResource) == -1) { | |
63 this.setPanelResource(this.installResource); | |
64 this.setPanelRefresh(); | |
65 this.setOutput(this.title + MSG_PANEL_ADDED); | |
66 } else { | |
67 this.setPanelRefresh(); | |
68 this.setOutput(this.title + MSG_PANEL_REFRESHED); | |
69 } | |
70 }//</m>setUp | |
71 | |
72 | |
73 | |
74 //================ | |
75 this.setPanelResource = function //<m>void<a>public<d>Create a resource for the new panel and add it to the sidebar panel list | |
76 ( | |
77 resource //<p>Object<d>Sidebar panel RDF resource | |
78 ){ | |
79 this.setRDFTriple(resource, 'title', this.title, true); | |
80 this.setRDFTriple(resource, 'content', this.url, true); | |
81 if(this.customize) this.setRDFTriple(resource, 'customize', this.customize, true); | |
82 this.container.AppendElement(resource); | |
83 }//</m>setPanelResource | |
84 | |
85 | |
86 | |
87 //================ | |
88 this.setPanelRefresh = function //<m>void<a>public<d>Refresh Sidebar panels | |
89 (){ | |
90 this.setRDFTriple(this.currentResource, 'refresh', 'true', true); | |
91 this.setRDFTriple(this.currentResource, 'refresh', 'false', false); | |
92 this.source.QueryInterface(nsIRDFRemoteDataSource).Flush(); | |
93 }//</m>setPanelRefresh<d>& | |
94 /* | |
95 We pass a "refresh" event to all sidebars observers watching for this assertion (in sidebarOverlay.js) | |
96 */ | |
97 | |
98 | |
99 | |
100 //================ | |
101 this.getPanelList = function //<m>Object<a>public<d>Get Sidebar panel resource | |
102 (){ | |
103 var | |
104 panelList = this.source.GetTarget(this.currentResource, this.rdf.GetResource(SIDEBAR_PANEL_URN), true); | |
105 if(panelList) panelList.QueryInterface(INTERFACES.nsIRDFResource); | |
106 else this.setOutput(MSG_PANEL_SOURCE); | |
107 return panelList; | |
108 }//</m>getPanelList | |
109 | |
110 | |
111 | |
112 //================ | |
113 this.getSource = function //<m>string<a>private<d>Get the Sidebar panels.rdf datasource URL | |
114 (){ | |
115 try{ | |
116 var | |
117 dirService = Components.classes[DIR_SERV_CID].getService(); | |
118 dirService = dirService.QueryInterface(nsIProperties); | |
119 var | |
120 sidebarFile = dirService.get(PANELS_RDF_FILE, INTERFACES.nsIFile); | |
121 if(!sidebarFile.exists()) throw MSG_NO_RDF_FILE; | |
122 var | |
123 ioService = Components.classes[IO_SERVICE_CID].getService(nsIIOService), | |
124 fileURL = ioService.newFileURI(sidebarFile); | |
125 fileURL = fileURL.QueryInterface(INTERFACES.nsIFileURL); | |
126 return fileURL.spec; | |
127 } | |
128 catch(e){ | |
129 return this.setOutput(e); | |
130 } | |
131 }//</m>getSource<d>& | |
132 /* | |
133 panels.rdf file is located in the user profile directory | |
134 If the file does not exist already, it is copied from /bin/defaults/profile/panels.rdf | |
135 */ | |
136 | |
137 | |
138 | |
139 //================ | |
140 this.setRDFTriple = function //<m>void<a>private<d>Setup an assertion in the RDF datasource member | |
141 ( | |
142 subject, //<p>string<d>Assertion subject | |
143 property, //<p>string<d>Assertion property | |
144 object, //<p>string<d>Assertion object | |
145 asserting //<p>boolean<d>Set or remove Assertion | |
146 ){ | |
147 this.source[asserting ? 'Assert' : 'Unassert'](subject, this.rdf.GetResource(NC_NAMESPACE + property), this.rdf.GetLiteral(object), true); | |
148 }//</m>setRDFTriple | |
149 | |
150 | |
151 | |
152 //================ | |
153 this.setOutput = function //<m>boolean<a>private<d>Dump message to output console | |
154 ( | |
155 output //<p>string<d>Message to output | |
156 ){ | |
157 var | |
158 /*string*/out = //'[' + this.className + ']\n' + | |
159 output + '\n'; | |
160 window.alert(out); //dump(output); | |
161 return null; | |
162 }//</m>setOutput<d>& | |
163 /* | |
164 Use either console or window alert output | |
165 */ | |
166 | |
167 | |
168 | |
169 this.MOZ_SidebarInstaller(_title, _url, _customize); | |
170 }//</c>MOZ_SidebarInstaller | |
171 | |
172 | |
173 |