~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to openerp-outlook-plugin/plugin_5.0/addin.py

  • Committer: pap(openerp)
  • Date: 2010-04-16 05:15:29 UTC
  • mto: This revision was merged to the branch mainline in revision 4519.
  • Revision ID: pap@tinyerp.co.in-20100416051529-qmw0z79ioq4md7ka
[ADD]:added different plugins for trunk and 5.0 versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 #!/usr/bin/python
 
2
 #-*- encoding: utf-8 -*-
 
3
 
 
4
from win32com import universal
 
5
from win32com.server.exception import COMException
 
6
from win32com.client import gencache, DispatchWithEvents
 
7
import winerror
 
8
import pythoncom
 
9
from win32com.client import constants
 
10
import sys
 
11
import os
 
12
from win32com.client import Dispatch
 
13
import win32con
 
14
 
 
15
sys.path.append(os.path.abspath(os.path.dirname(__file__)))    #outlook
 
16
sys.path.append(os.path.abspath(__file__))                     #outlook/addin
 
17
 
 
18
import manager
 
19
from win32com.client import CastTo
 
20
import win32ui
 
21
from tiny_xmlrpc import *
 
22
 
 
23
import locale
 
24
locale.setlocale(locale.LC_NUMERIC, "C")
 
25
 
 
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
 
29
 
 
30
# The TLB defiining the interfaces we implement
 
31
universal.RegisterInterfaces('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0, ["_IDTExtensibility2"])
 
32
 
 
33
global NewConn
 
34
 
 
35
# Retrieves registered XMLRPC connection
 
36
def GetConn():
 
37
    d=Dispatch("Python.OpenERP.XMLRpcConn")
 
38
    mngr = manager.GetManager()
 
39
    return d
 
40
 
 
41
class ButtonEvent:
 
42
    def OnClick(self, button, cancel):
 
43
        mngr = manager.GetManager()
 
44
        mngr.ShowManager()
 
45
        return cancel
 
46
#
 
47
class ArchiveEvent:
 
48
    def OnClick(self, button, cancel):
 
49
        from win32com.client import Dispatch
 
50
        import win32con
 
51
        mngr = manager.GetManager()
 
52
        data=mngr.LoadConfig()
 
53
        outlook = Dispatch("Outlook.Application")
 
54
        ex = outlook.ActiveExplorer()
 
55
        if ex:
 
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)
 
66
        return cancel
 
67
 
 
68
class OutlookAddin:
 
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
 
80
 
 
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"
 
89
            item.Enabled = True
 
90
 
 
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"
 
97
            item.Enabled = True
 
98
 
 
99
    def OnDisconnection(self, mode, custom):
 
100
        mngr = manager.GetManager()
 
101
        mngr.config['login'] = False
 
102
        mngr.SaveConfig()
 
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
 
113
 
 
114
def RegisterAddin(klass):
 
115
    import _winreg
 
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_)
 
122
 
 
123
def UnregisterAddin(klass):
 
124
    import _winreg
 
125
    try:
 
126
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_)
 
127
    except WindowsError:
 
128
        pass
 
129
 
 
130
def UnregisterXMLConn(klass):
 
131
    import _winreg
 
132
    try:
 
133
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\XMLConnection" + klass._reg_progid_)
 
134
    except WindowsError:
 
135
        pass
 
136
 
 
137
def RegisterXMLConn(klass):
 
138
    import _winreg
 
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_)
 
145
 
 
146
if __name__ == '__main__':
 
147
 
 
148
    import win32com.server.register
 
149
    NewConn=XMLRpcConn()
 
150
    win32com.server.register.UseCommandLine(OutlookAddin)
 
151
    win32com.server.register.UseCommandLine(NewConn)
 
152
    if "--unregister" in sys.argv:
 
153
        UnregisterAddin(OutlookAddin)
 
154
        UnregisterXMLConn(NewConn)
 
155
    else:
 
156
        RegisterAddin(OutlookAddin)
 
157
        RegisterXMLConn(NewConn)
 
 
b'\\ No newline at end of file'