Make day + week views respect default start and end time preferences (bug 321769). r=<jminta@gmail.com>

This commit is contained in:
dmose%mozilla.org 2006-01-25 20:00:48 +00:00
Родитель 19ac043c95
Коммит 05111d0512
6 изменённых файлов: 160 добавлений и 24 удалений

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

@ -21,6 +21,7 @@
- the Initial Developer. All Rights Reserved. - the Initial Developer. All Rights Reserved.
- -
- Contributor(s): - Contributor(s):
- Dan Mosedale <dan.mosedale@oracle.com>
- -
- Alternatively, the contents of this file may be used under the terms of - Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or - either the GNU General Public License Version 2 or later (the "GPL"), or
@ -54,6 +55,76 @@
</content> </content>
<implementation implements="calIDecoratedView"> <implementation implements="calIDecoratedView">
<constructor><![CDATA[
var pb2 = Components.classes
["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
// get default start/end times from prefs and set on the
// view. if we hit an error (eg because sunbird's pref
// infrastructure hasn't created the pref yet), the
// defaults will do
try {
this.mStartMin = pb2.getIntPref(
"calendar.view.defaultstarthour") * 60;
this.mEndMin = pb2.getIntPref(
"calendar.view.defaultendhour") * 60;
} catch (ex) {
}
var viewElement = document.getAnonymousElementByAttribute(
this, "anonid", "view-element");
viewElement.setStartEndMinutes(this.mStartMin,
this.mEndMin);
// add a preference observer to monitor changes
pb2.addObserver("calendar.view.", this.mPrefObserver, false);
return;
]]></constructor>
<destructor><![CDATA[
var pb2 = Components.classes
["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
pb2.removeObserver("calendar.view.", this.mPrefObserver);
return;
]]></destructor>
<field name="mStartMin">8 * 60</field>
<field name="mEndMin">17 * 60</field>
<field name="mPrefObserver"><![CDATA[
({ calView: this,
observe: function calDecWeekViewPrefChange(subj, topic, pref) {
subj.QueryInterface(Components.interfaces.nsIPrefBranch2);
switch (pref) {
case "calendar.view.defaultstarthour":
this.calView.mStartMin = subj.getIntPref(pref) * 60;
var viewElem = document.getAnonymousElementByAttribute(
this.calView, "anonid", "view-element");
viewElem.setStartEndMinutes(this.calView.mStartMin,
this.calView.mEndMin);
break;
case "calendar.view.defaultendhour":
this.calView.mEndMin = subj.getIntPref(pref) * 60;
viewElem = document.getAnonymousElementByAttribute(
this.calView, "anonid", "view-element");
viewElem.setStartEndMinutes(this.calView.mStartMin,
this.calView.mEndMin);
break;
default:
break;
}
return;
}
})
]]></field>
<property name="observerID"> <property name="observerID">
<getter><![CDATA[ <getter><![CDATA[
return "day-view-observer"; return "day-view-observer";

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

@ -21,6 +21,7 @@
- the Initial Developer. All Rights Reserved. - the Initial Developer. All Rights Reserved.
- -
- Contributor(s): - Contributor(s):
- Dan Mosedale <dan.mosedale@oracle.com>
- -
- Alternatively, the contents of this file may be used under the terms of - Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or - either the GNU General Public License Version 2 or later (the "GPL"), or
@ -54,6 +55,76 @@
</content> </content>
<implementation implements="calIDecoratedView"> <implementation implements="calIDecoratedView">
<constructor><![CDATA[
var pb2 = Components.classes
["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
// get default start/end times from prefs and set on the
// view. if we hit an error (eg because sunbird's pref
// infrastructure hasn't created the pref yet), the
// defaults will do
try {
this.mStartMin = pb2.getIntPref(
"calendar.view.defaultstarthour") * 60;
this.mEndMin = pb2.getIntPref(
"calendar.view.defaultendhour") * 60;
} catch (ex) {
}
var viewElement = document.getAnonymousElementByAttribute(
this, "anonid", "view-element");
viewElement.setStartEndMinutes(this.mStartMin,
this.mEndMin);
// add a preference observer to monitor changes
pb2.addObserver("calendar.view.", this.mPrefObserver, false);
return;
]]></constructor>
<destructor><![CDATA[
var pb2 = Components.classes
["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2);
pb2.removeObserver("calendar.view.", this.mPrefObserver);
return;
]]></destructor>
<field name="mStartMin">8 * 60</field>
<field name="mEndMin">17 * 60</field>
<field name="mPrefObserver"><![CDATA[
({ calView: this,
observe: function calDecWeekViewPrefChange(subj, topic, pref) {
subj.QueryInterface(Components.interfaces.nsIPrefBranch2);
switch (pref) {
case "calendar.view.defaultstarthour":
this.calView.mStartMin = subj.getIntPref(pref) * 60;
var viewElem = document.getAnonymousElementByAttribute(
this.calView, "anonid", "view-element");
viewElem.setStartEndMinutes(this.calView.mStartMin,
this.calView.mEndMin);
break;
case "calendar.view.defaultendhour":
this.calView.mEndMin = subj.getIntPref(pref) * 60;
viewElem = document.getAnonymousElementByAttribute(
this.calView, "anonid", "view-element");
viewElem.setStartEndMinutes(this.calView.mStartMin,
this.calView.mEndMin);
break;
default:
break;
}
return;
}
})
]]></field>
<property name="observerID"> <property name="observerID">
<getter><![CDATA[ <getter><![CDATA[
return "week-view-observer"; return "week-view-observer";

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

@ -16,11 +16,12 @@
* *
* The Initial Developer of the Original Code is * The Initial Developer of the Original Code is
* Oracle Corporation * Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2001 * Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com> * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
* Dan Mosedale <dan.mosedale@oracle.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -44,6 +45,13 @@ interface calIDateTime;
interface calICalendarViewController; interface calICalendarViewController;
interface calIItemBase; interface calIItemBase;
/**
* An interface for view widgets containing calendaring data.
*
* @note Code that implements this interface is intended to be pure
* widgetry and thus not have any preference dependencies.
* Preferences and pref observers should live in the decorated views.
*/
[scriptable, uuid(3e567ccb-2ecf-4f59-b7ca-bf42b0fbf24a)] [scriptable, uuid(3e567ccb-2ecf-4f59-b7ca-bf42b0fbf24a)]
interface calICalendarView : nsISupports interface calICalendarView : nsISupports
{ {

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

@ -16,6 +16,8 @@
* *
* The Initial Developer of the Original Code is * The Initial Developer of the Original Code is
* Joey Minta <jminta@gmail.com> * Joey Minta <jminta@gmail.com>
* Dan Mosedale <dan.mosedale@oracle.com>
*
* Portions created by the Initial Developer are Copyright (C) 2005 * Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
@ -49,6 +51,12 @@ interface calIItemBase;
* Because it contains a calICalendarView as an anonymous node, not easily * Because it contains a calICalendarView as an anonymous node, not easily
* accessible, it must therefore expose several of that interface's methods and * accessible, it must therefore expose several of that interface's methods and
* attributes, as well as its own. * attributes, as well as its own.
*
* @note Implementations of this interface are intended to be the home
* for view preference handling. The lower-level views (ie
* implementers of calICalendarView) are intended to be pure widgetry,
* and this sort of view should be pluggable, meaning that callers
* shouldn't need to know about view-specific preferences.
*/ */
[scriptable, uuid(229049e0-e36f-4706-9fe1-37eb370273b9)] [scriptable, uuid(229049e0-e36f-4706-9fe1-37eb370273b9)]

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

@ -93,16 +93,6 @@ function ltnOnLoad(event)
document.getElementById("messengerWindow") document.getElementById("messengerWindow")
.addEventListener("unload", ltnFinish, false); .addEventListener("unload", ltnFinish, false);
// Set up the multiday-view to start/end at the correct hours, since this
// doesn't persist between startups. (Fails if pref undefined)
try {
var sHour = rootPrefBranch.getIntPref("calendar.view.defaultstarthour");
var eHour = rootPrefBranch.getIntPref("calendar.view.defaultendhour");
document.getElementById("calendar-multiday-view")
.setStartEndMinutes(sHour*60, eHour*60);
}
catch(ex) {}
return; return;
} }
@ -232,17 +222,6 @@ var ltnPrefObserver =
rootPrefBranch: null, rootPrefBranch: null,
observe: function(aSubject, aTopic, aPrefName) observe: function(aSubject, aTopic, aPrefName)
{ {
switch (aPrefName) {
case "calendar.view.defaultstarthour":
case "calendar.view.defaultendhour":
var sHour = this.rootPrefBranch.getIntPref
("calendar.view.defaultstarthour");
var eHour = this.rootPrefBranch.getIntPref
("calendar.view.defaultendhour");
document.getElementById("calendar-multiday-view")
.setStartEndMinutes(sHour*60, eHour*60);
break;
}
} }
} }

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

@ -21,6 +21,7 @@
* Contributor(s): Mike Potter <mikep@oeone.com> * Contributor(s): Mike Potter <mikep@oeone.com>
* ArentJan Banck <ajbanck@planet.nl> * ArentJan Banck <ajbanck@planet.nl>
* Eric Belhaire <belhaire@ief.u-psud.fr> * Eric Belhaire <belhaire@ief.u-psud.fr>
* Dan Mosedale <dan.mosedale@oracle.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -59,8 +60,6 @@ calendarPrefObserver.prototype =
// when calendar pref was changed, we reinitialize // when calendar pref was changed, we reinitialize
switch( prefName ) switch( prefName )
{ {
case "calendar.view.defaultstarthour":
case "calendar.view.defaultendhour":
case "calendar.previousweeks.inview": case "calendar.previousweeks.inview":
case "calendar.week.d0sundaysoff": case "calendar.week.d0sundaysoff":
case "calendar.week.d1mondaysoff": case "calendar.week.d1mondaysoff":