1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- ***** BEGIN LICENSE BLOCK *****
3 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 -
5 - The contents of this file are subject to the Mozilla Public License Version
6 - 1.1 (the "License"); you may not use this file except in compliance with
7 - the License. You may obtain a copy of the License at
8 - http://www.mozilla.org/MPL/
9 -
10 - Software distributed under the License is distributed on an "AS IS" basis,
11 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 - for the specific language governing rights and limitations under the
13 - License.
14 -
15 - The Original Code is Calendar view code.
16 -
17 - The Initial Developer of the Original Code is
18 - Joey Minta <jminta@gmail.com>
19 - Portions created by the Initial Developer are Copyright (C) 2007
20 - the Initial Developer. All Rights Reserved.
21 -
22 - Contributor(s):
23 - Dan Mosedale <dan.mosedale@oracle.com>
24 - Philipp Kewisch <mozilla@kewis.ch>
25 -
26 - Alternatively, the contents of this file may be used under the terms of
27 - either the GNU General Public License Version 2 or later (the "GPL"), or
28 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 - in which case the provisions of the GPL or the LGPL are applicable instead
30 - of those above. If you wish to allow use of your version of this file only
31 - under the terms of either the GPL or the LGPL, and not to allow others to
32 - use your version of this file under the terms of the MPL, indicate your
33 - decision by deleting the provisions above and replace them with the notice
34 - and other provisions required by the GPL or the LGPL. If you do not delete
35 - the provisions above, a recipient may use your version of this file under
36 - the terms of any one of the MPL, the GPL or the LGPL.
37 -
38 - ***** END LICENSE BLOCK ***** -->
39
40 <bindings id="calendar-specific-view-bindings"
41 xmlns="http://www.mozilla.org/xbl"
42 xmlns:html="http://www.w3.org/1999/xhtml"
43 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
44 xmlns:xbl="http://www.mozilla.org/xbl">
45
46 <binding id="calendar-decorated-multiday-base-view"
47 extends="chrome://calendar/content/calendar-decorated-base.xml#calendar-decorated-base-view">
48 <implementation implements="calIDecoratedView">
49 <constructor><![CDATA[
50 // get day start/end hour from prefs and set on the view
51 this.mDayStartMin = getPrefSafe(
52 "calendar.view.daystarthour", 8) * 60;
53 this.mDayEndMin = getPrefSafe(
54 "calendar.view.dayendhour", 17) * 60;
55 var viewElement = this.viewElem;
56 viewElement.setDayStartEndMinutes(this.mDayStartMin,
57 this.mDayEndMin);
58
59 // initially scroll to the day start hour in the view
60 viewElement.setFirstVisibleMinute(this.mDayStartMin);
61
62 // get visible hours from prefs and set on the view
63 var visibleMinutes = getPrefSafe(
64 "calendar.view.visiblehours", 9) * 60;
65 viewElement.setVisibleMinutes(visibleMinutes);
66
67 // add a preference observer to monitor changes
68 var pb2 = Components.classes["@mozilla.org/preferences-service;1"].
69 getService(Components.interfaces.nsIPrefBranch2);
70 pb2.addObserver("calendar.", this.mPrefObserver, false);
71
72 this.updateDaysOffPrefs();
73
74 return;
75 ]]></constructor>
76
77 <destructor><![CDATA[
78 var pb2 = Components.classes["@mozilla.org/preferences-service;1"].
79 getService(Components.interfaces.nsIPrefBranch2);
80 pb2.removeObserver("calendar.", this.mPrefObserver);
81 return;
82 ]]></destructor>
83
84 <field name="mDayStartMin">8*60</field>
85 <field name="mDayEndMin">17*60</field>
86
87 <field name="mPrefObserver"><![CDATA[
88 ({ calView: this,
89 observe: function calDecMultidayViewPrefChange(subj, topic, pref) {
90 this.calView.handlePreference(subj, topic, pref);
91 return;
92 }
93 })
94 ]]></field>
95
96 <!-- A preference handler which is called by the preference observer.
97 Can be overriden in derived bindings. -->
98 <method name="handlePreference">
99 <parameter name="aSubject"/>
100 <parameter name="aTopic"/>
101 <parameter name="aPreference"/>
102 <body><![CDATA[
103 this.handleCommonPreference(aSubject, aTopic, aPreference);
104 ]]></body>
105 </method>
106
107 <!-- A base implementation for the handling of common preferences.
108 Can be called in handlePreference from derived bindings. -->
109 <method name="handleCommonPreference">
110 <parameter name="aSubject"/>
111 <parameter name="aTopic"/>
112 <parameter name="aPreference"/>
113 <body><![CDATA[
114 aSubject.QueryInterface(Components.interfaces.nsIPrefBranch2);
115
116 switch (aPreference) {
117
118 case "calendar.week.d0sundaysoff":
119 case "calendar.week.d1mondaysoff":
120 case "calendar.week.d2tuesdaysoff":
121 case "calendar.week.d3wednesdaysoff":
122 case "calendar.week.d4thursdaysoff":
123 case "calendar.week.d5fridaysoff":
124 case "calendar.week.d6saturdaysoff":
125 this.updateDaysOffPrefs();
126 if (!this.startDay || !this.endDay) {
127 // don't refresh if we're not initialized
128 return;
129 }
130 this.goToDay(this.selectedDay);
131 break;
132
133 case "calendar.view.daystarthour":
134 this.mDayStartMin = aSubject.getIntPref(aPreference) * 60;
135 this.viewElem.setDayStartEndMinutes(this.mDayStartMin,
136 this.mDayEndMin);
137 if (!this.startDay || !this.endDay) {
138 // don't refresh if we're not initialized
139 return;
140 }
141 this.goToDay(this.selectedDay);
142 break;
143
144 case "calendar.view.dayendhour":
145 this.mDayEndMin = aSubject.getIntPref(aPreference) * 60;
146 this.viewElem.setDayStartEndMinutes(this.mDayStartMin,
147 this.mDayEndMin);
148 if (!this.startDay || !this.endDay) {
149 // don't refresh if we're not initialized
150 return;
151 }
152 this.goToDay(this.selectedDay);
153 break;
154
155 case "calendar.view.visiblehours":
156 var visibleMinutes = aSubject.getIntPref(aPreference) * 60;
157 this.viewElem.setVisibleMinutes(visibleMinutes);
158 if (!this.startDay || !this.endDay) {
159 // don't refresh if we're not initialized
160 return;
161 }
162 this.goToDay(this.selectedDay);
163 break;
164
165 case "calendar.timezone.local":
166 this.viewElem.timezone = calendarDefaultTimezone();
167 if (!this.startDay || !this.endDay) {
168 // don't refresh if we're not initialized
169 return;
170 }
171 this.goToDay(this.selectedDay);
172 break;
173
174 case "calendar.alarms.indicator.show":
175 if (this.startDay && this.endDay) {
176 // Refresh the view, the view core takes care of
177 // resetting the alarm image.
178 this.goToDay(this.selectedDay);
179 }
180 break;
181
182 default:
183 break;
184 }
185 return;
186 ]]></body>
187 </method>
188
189 <method name="updateDaysOffPrefs">
190 <body><![CDATA[
191 var prefNames = ["d0sundaysoff", "d1mondaysoff", "d2tuesdaysoff",
192 "d3wednesdaysoff", "d4thursdaysoff",
193 "d5fridaysoff", "d6saturdaysoff"];
194 var defaults = [true, false, false, false, false, false, true];
195 var daysOff = new Array();
196 const weekPrefix = "calendar.week.";
197 for (var i in prefNames) {
198 if (getPrefSafe(weekPrefix+prefNames[i], defaults[i])) {
199 daysOff.push(Number(i));
200 }
201 }
202 this.viewElem.daysOffArray = daysOff;
203 ]]></body>
204 </method>
205 </implementation>
206 </binding>
207 </bindings>