2
#-*- encoding: utf-8 -*-
4
from win32com import universal
5
from win32com.server.exception import COMException
6
from win32com.client import gencache, DispatchWithEvents
9
from win32com.client import constants
12
from win32com.client import Dispatch
15
sys.path.append(os.path.abspath(os.path.dirname(__file__))) #outlook
16
sys.path.append(os.path.abspath(__file__)) #outlook/addin
19
from win32com.client import CastTo
21
from tiny_xmlrpc import *
24
locale.setlocale(locale.LC_NUMERIC, "C")
26
# Support for COM objects we use.
27
gencache.EnsureModule('{00062FFF-0000-0000-C000-000000000046}', 0, 9, 0, bForDemand=True) # Outlook 9
28
gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1, bForDemand=True) # Office 9
30
# The TLB defiining the interfaces we implement
31
universal.RegisterInterfaces('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0, ["_IDTExtensibility2"])
35
# Retrieves registered XMLRPC connection
37
d=Dispatch("Python.OpenERP.XMLRpcConn")
38
mngr = manager.GetManager()
42
def OnClick(self, button, cancel):
43
mngr = manager.GetManager()
48
def OnClick(self, button, cancel):
49
from win32com.client import Dispatch
51
mngr = manager.GetManager()
52
data=mngr.LoadConfig()
53
outlook = Dispatch("Outlook.Application")
54
ex = outlook.ActiveExplorer()
56
is_login = str(data['login'])
57
if is_login == 'False':
58
win32ui.MessageBox("Please login to the database first", "Database Connection", win32con.MB_ICONEXCLAMATION)
59
elif ex.Selection.Count == 1:
60
mngr = manager.GetManager()
61
mngr.ShowManager("IDD_SYNC")
62
elif ex.Selection.Count == 0:
63
win32ui.MessageBox("No mail selected to archive to OpenERP","",win32con.MB_ICONINFORMATION)
64
elif ex.Selection.Count > 1:
65
win32ui.MessageBox("Multiple selection not allowed. Please select only one mail at a time.","",win32con.MB_ICONINFORMATION)
69
_com_interfaces_ = ['_IDTExtensibility2']
70
_public_methods_ = ['OnConnection','GetAppDataPath']
71
_reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER
72
_reg_clsid_ = "{0F47D9F3-598B-4d24-B7E3-92AC15ED27E8}"
73
_reg_progid_ = "Python.OpenERP.OutlookAddin"
74
_reg_policy_spec_ = "win32com.server.policy.EventHandlerPolicy"
75
def OnConnection(self, application, connectMode, addin, custom):
76
# ActiveExplorer may be none when started without a UI (eg, WinCE synchronisation)
77
activeExplorer = application.ActiveExplorer()
78
if activeExplorer is not None:
79
bars = activeExplorer.CommandBars
81
menu_bar = bars.Item("Menu Bar")
82
tools_menu = menu_bar.Controls(5)
83
tools_menu = CastTo(tools_menu, "CommandBarPopup")
84
item = tools_menu.Controls.Add(Type=constants.msoControlButton, Temporary=True)
85
# Hook events for the item
86
item = self.menu_bar_Button = DispatchWithEvents(item, ButtonEvent)
87
item.Caption="OpenERP Configuration"
88
item.TooltipText = "Click to configure OpenERP"
91
toolbar = bars.Item("Standard")
92
item = toolbar.Controls.Add(Type=constants.msoControlButton, Temporary=True)
93
# Hook events for the item
94
item = self.toolbarButton = DispatchWithEvents(item, ArchiveEvent)
95
item.Caption="Archive to OpenERP"
96
item.TooltipText = "Click to archive to OpenERP"
99
def OnDisconnection(self, mode, custom):
100
mngr = manager.GetManager()
101
mngr.config['login'] = False
103
print "OnDisconnection"
104
def OnAddInsUpdate(self, custom):
105
print "OnAddInsUpdate", custom
106
def OnStartupComplete(self, custom):
107
print "OnStartupComplete", custom
108
def OnBeginShutdown(self, custom):
109
print "OnBeginShutdown", custom
110
def GetAppDataPath(self):
111
mngr = manager.GetManager()
112
return mngr.data_directory
114
def RegisterAddin(klass):
116
key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins")
117
subkey = _winreg.CreateKey(key, klass._reg_progid_)
118
_winreg.SetValueEx(subkey, "CommandLineSafe", 0, _winreg.REG_DWORD, 0)
119
_winreg.SetValueEx(subkey, "LoadBehavior", 0, _winreg.REG_DWORD, 3)
120
_winreg.SetValueEx(subkey, "Description", 0, _winreg.REG_SZ, klass._reg_progid_)
121
_winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, klass._reg_progid_)
123
def UnregisterAddin(klass):
126
_winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_)
130
def UnregisterXMLConn(klass):
133
_winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\XMLConnection" + klass._reg_progid_)
137
def RegisterXMLConn(klass):
139
key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\XMLConnection")
140
subkey = _winreg.CreateKey(key, klass._reg_progid_)
141
_winreg.SetValueEx(subkey, "CommandLineSafe", 0, _winreg.REG_DWORD, 0)
142
_winreg.SetValueEx(subkey, "LoadBehavior", 0, _winreg.REG_DWORD, 3)
143
_winreg.SetValueEx(subkey, "Description", 0, _winreg.REG_SZ, klass._reg_progid_)
144
_winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, klass._reg_progid_)
146
if __name__ == '__main__':
148
import win32com.server.register
150
win32com.server.register.UseCommandLine(OutlookAddin)
151
win32com.server.register.UseCommandLine(NewConn)
152
if "--unregister" in sys.argv:
153
UnregisterAddin(OutlookAddin)
154
UnregisterXMLConn(NewConn)
156
RegisterAddin(OutlookAddin)
157
RegisterXMLConn(NewConn)
b'\\ No newline at end of file'