Skip to content

Commit

Permalink
Report appointment categories in Microsoft Outlook (PR #11598)
Browse files Browse the repository at this point in the history
Outlook appointments could have multiple categories (or colors) assigned to them.
Fetch the categories from the object model and report them after other appointment details.
  • Loading branch information
LeonarddeR authored Mar 26, 2021
1 parent 6a0839d commit 9a1cca5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
47 changes: 40 additions & 7 deletions source/appModules/outlook.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#appModules/outlook.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2006-2018 NV Access Limited, Yogesh Kumar, Manish Agrawal, Joseph Lee, Davy Kager, Babbage B.V.
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2006-2021 NV Access Limited, Yogesh Kumar, Manish Agrawal, Joseph Lee, Davy Kager,
# Babbage B.V., Leonard de Ruijter
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

from comtypes import COMError
from comtypes.hresult import S_OK
Expand Down Expand Up @@ -36,6 +36,8 @@
from NVDAObjects.behaviors import RowWithFakeNavigation, Dialog
from NVDAObjects.UIA import UIA
from NVDAObjects.UIA.wordDocument import WordDocument as UIAWordDocument
import languageHandler
from gettext import ngettext

PR_LAST_VERB_EXECUTED=0x10810003
VERB_REPLYTOSENDER=102
Expand Down Expand Up @@ -334,6 +336,30 @@ def _generateTimeRangeText(self,startTime,endTime):
# Translators: a message reporting the time range (i.e. start time to end time) of an Outlook calendar entry
return _("{startTime} to {endTime}").format(startTime=startText,endTime=endText)

@staticmethod
def _generateCategoriesText(appointment):
categories = appointment.Categories
if not categories:
return None
# Categories is a delimited string of category names that have been assigned to an Outlook item.
# This property uses the user locale's list separator to separate entries.
# See also https://docs.microsoft.com/en-us/office/vba/api/outlook.appointmentitem.categories
bufLength = 4
separatorBuf = ctypes.create_unicode_buffer(bufLength)
if ctypes.windll.kernel32.GetLocaleInfoW(
languageHandler.LOCALE_USER_DEFAULT,
languageHandler.LOCALE_SLIST,
separatorBuf,
bufLength
) == 0:
raise ctypes.WinError()
categoriesCount = len(categories.split(f"{separatorBuf.value} "))

# Translators: Part of a message reported when on a calendar appointment with one or more categories
# in Microsoft Outlook.
categoriesText = ngettext("category", "categories", categoriesCount)
return f"{categoriesText} {categories}"

def isDuplicateIAccessibleEvent(self,obj):
return False

Expand All @@ -355,8 +381,15 @@ def reportFocus(self):
except COMError:
return super(CalendarView,self).reportFocus()
t=self._generateTimeRangeText(start,end)
# Translators: A message reported when on a calendar appointment in Microsoft Outlook
ui.message(_("Appointment {subject}, {time}").format(subject=p.subject,time=t))
# Translators: A message reported when on a calendar appointment with category in Microsoft Outlook
message = _("Appointment {subject}, {time}").format(subject=p.subject, time=t)
try:
categoriesText = self._generateCategoriesText(p)
except COMError:
categoriesText = None
if categoriesText is not None:
message = f"{message}, {categoriesText}"
ui.message(message)
else:
v=e.currentView
try:
Expand Down
2 changes: 2 additions & 0 deletions source/languageHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#a few Windows locale constants
LOCALE_SLANGUAGE=0x2
LOCALE_SLIST = 0xC
LOCALE_SLANGDISPLAYNAME=0x6f
LOCALE_USER_DEFAULT = 0x400
LOCALE_CUSTOM_UNSPECIFIED = 0x1000
#: Returned from L{localeNameToWindowsLCID} when the locale name cannot be mapped to a locale identifier.
#: This might be because Windows doesn't know about the locale (e.g. "an"),
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Plus many other important bug fixes and improvements.
- Added the --copy-portable-config command line parameter that allows you to automatically copy the provided configuration to the user account when silently installing NVDA. (#9676)
- Braille routing is now supported with the Braille Viewer for mouse users, hover to route to a braille cell. (#11804)
- NVDA will now automatically detect the Humanware Brailliant BI 40X and 20X devices via both USB and Bluetooth. (#11819)
- NVDA now reports the categories assigned to an appointment in Microsoft Outlook, if any. (#11598)


== Changes ==
Expand Down

0 comments on commit 9a1cca5

Please sign in to comment.