Debian Codegraph @

src/af/xap/win/xap_Win32Dlg_PluginManager.cpp

raw
1 /* AbiWord
2 * Copyright (C) 2001 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <windows.h>
25 #include <commctrl.h>
26
27 #include "ut_string.h"
28 #include "ut_assert.h"
29 #include "ut_debugmsg.h"
30 #include "ut_Win32OS.h"
31
32 #include "xap_App.h"
33 #include "xap_Win32App.h"
34 #include "xap_Win32FrameImpl.h"
35
36 #include "xap_Dialog_Id.h"
37 #include "xap_Win32Dlg_FileOpenSaveAs.h"
38 #include "xap_Win32Dlg_PluginManager.h"
39 #include "xap_Win32DialogHelper.h"
40 #include "xap_Module.h"
41 #include "xap_ModuleManager.h"
42
43 #include "ie_types.h"
44 #include "ut_string_class.h"
45
46 #include "xap_Win32Resources.rc2"
47
48 /*****************************************************************/
49
50 XAP_Dialog * XAP_Win32Dialog_PluginManager::static_constructor(XAP_DialogFactory * pFactory,
51 XAP_Dialog_Id id)
52 {
53 XAP_Win32Dialog_PluginManager * p = new XAP_Win32Dialog_PluginManager(pFactory,id);
54 return p;
55 }
56
57 XAP_Win32Dialog_PluginManager::XAP_Win32Dialog_PluginManager(XAP_DialogFactory * pDlgFactory,
58 XAP_Dialog_Id id)
59 : XAP_Dialog_PluginManager(pDlgFactory,id),
60 m_curSelection(LB_ERR)
61 {
62 }
63
64 XAP_Win32Dialog_PluginManager::~XAP_Win32Dialog_PluginManager(void)
65 {
66 }
67
68 void XAP_Win32Dialog_PluginManager::runModal(XAP_Frame * pFrame)
69 {
70 UT_return_if_fail(pFrame);
71 UT_return_if_fail(m_id == XAP_DIALOG_ID_PLUGIN_MANAGER);
72
73 setDialog(this);
74 createModal(pFrame,MAKEINTRESOURCEW(XAP_RID_DIALOG_PLUGIN_MANAGER));
75 }
76
77 #define _DS(c,s) setDlgItemText(XAP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s))
78 #define _DSX(c,s) setDlgItemText(XAP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s))
79
80 BOOL XAP_Win32Dialog_PluginManager::_onInitDialog(HWND /*hWnd*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
81 {
82 const XAP_StringSet* pSS = m_pApp->getStringSet();
83
84 // Update the caption
85 setDialogTitle(pSS->getValue(XAP_STRING_ID_DLG_PLUGIN_MANAGER_TITLE));
86
87 // localize controls
88 localizeControlText(IDOK, XAP_STRING_ID_DLG_OK);
89 // _DSX(PLUGIN_MANAGER_BTN_OK, DLG_OK);
90 _DS(PLUGIN_MANAGER_BTN_ACTIVE, DLG_PLUGIN_MANAGER_ACTIVE);
91 _DS(PLUGIN_MANAGER_BTN_INSTALL, DLG_PLUGIN_MANAGER_INSTALL);
92 _DS(PLUGIN_MANAGER_LBL_NAME, DLG_PLUGIN_MANAGER_NAME);
93 _DS(PLUGIN_MANAGER_LBL_DESCRIPTION, DLG_PLUGIN_MANAGER_DESC);
94 _DS(PLUGIN_MANAGER_LBL_AUTHOR, DLG_PLUGIN_MANAGER_AUTHOR);
95 _DS(PLUGIN_MANAGER_LBL_VERSION, DLG_PLUGIN_MANAGER_VERSION);
96
97 refreshPluginList();
98
99 /* Default */
100 selectListItem(XAP_RID_DIALOG_PLUGIN_MANAGER_LBX_LIST, 0);
101 centerDialog();
102
103 return 1; // 1 == we did not call SetFocus()
104 }
105
106 BOOL XAP_Win32Dialog_PluginManager::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
107 {
108 // This handles WM_COMMAND message for the top-level dialog.
109
110 WORD wId = LOWORD(wParam);
111
112 switch (wId)
113 {
114 // LIST TAB
115 case XAP_RID_DIALOG_PLUGIN_MANAGER_BTN_ACTIVE:
116 return 0;
117
118 case XAP_RID_DIALOG_PLUGIN_MANAGER_BTN_INSTALL:
119 event_Load();
120 return 0;
121
122 case XAP_RID_DIALOG_PLUGIN_MANAGER_LBX_LIST:
123 {
124 m_curSelection = getListSelectedIndex( wId );
125 refreshPluginInfo();
126 return 0;
127 }
128
129 case IDOK:
130 case IDCANCEL:
131 EndDialog(hWnd,0);
132 return 0;
133
134 default: // we did not handle this notification
135 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
136 return 0; // return zero to let windows take care of it.
137 }
138 }
139
140 BOOL XAP_Win32Dialog_PluginManager::_onDeltaPos(NM_UPDOWN * /*pnmud*/)
141 {
142 return FALSE;
143 }
144
145 void XAP_Win32Dialog_PluginManager::event_Load()
146 {
147
148 const XAP_StringSet * pSS = m_pApp->getStringSet();
149
150 XAP_DialogFactory * pDialogFactory
151 = (XAP_DialogFactory *) getApp()->findValidFrame()->getDialogFactory();
152
153 XAP_Dialog_FileOpenSaveAs * pDialog
154 = (XAP_Dialog_FileOpenSaveAs *)(pDialogFactory->requestDialog(XAP_DIALOG_ID_FILE_OPEN));
155 UT_return_if_fail(pDialog);
156
157 // set the intial plugin directory to the user-local plugin directory
158 // could also set to: XAP_App::getApp()->getUserPrivateDirectory()\plugins
159 // could also set to: XAP_App::getApp()->getAbiSuiteLibDir()\plugins
160 UT_String pluginDir (XAP_App::getApp()->getAbiSuiteAppDir());
161 pluginDir += "\\plugins";
162 pDialog->setCurrentPathname (pluginDir.c_str());
163 pDialog->setSuggestFilename(false);
164
165 UT_uint32 filterCount = 1;
166 const char ** szDescList = (const char **) UT_calloc(filterCount + 1,
167 sizeof(char *));
168 UT_return_if_fail(szDescList);
169 const char ** szSuffixList = (const char **) UT_calloc(filterCount + 1,
170 sizeof(char *));
171 if(!szSuffixList)
172 {
173 UT_ASSERT_HARMLESS(szSuffixList);
174 FREEP(szDescList);
175 return;
176 }
177 IEFileType * nTypeList = (IEFileType *) UT_calloc(filterCount + 1,
178 sizeof(IEFileType));
179 if(!nTypeList)
180 {
181 UT_ASSERT_HARMLESS(nTypeList);
182 FREEP(szDescList);
183 FREEP(szSuffixList);
184 return;
185 }
186 // we probably shouldn't hardcode this
187 // HP-UX uses .sl, for instance
188 szDescList[0] = "AbiWord Plugin (.dll)";
189 szSuffixList[0] = "*.dll";
190 nTypeList[0] = (IEFileType)1;
191
192 pDialog->setFileTypeList(szDescList, szSuffixList,
193 (const UT_sint32 *) nTypeList);
194
195 pDialog->setDefaultFileType((IEFileType)1);
196
197 // todo: cd to the proper plugin directory
198
199 pDialog->runModal(getApp()->findValidFrame());
200
201 XAP_Dialog_FileOpenSaveAs::tAnswer ans = pDialog->getAnswer();
202 bool bOK = (ans == XAP_Dialog_FileOpenSaveAs::a_OK);
203
204 if (bOK)
205 {
206 const char * szResultPathname = pDialog->getPathname();
207 if (szResultPathname && *szResultPathname)
208 {
209 if( activatePlugin(szResultPathname) )
210 {
211 // worked!
212 refreshPluginList();
213 }
214 else
215 {
216 // error message
217 getApp()->findValidFrame()->showMessageBox( pSS->getValue(XAP_STRING_ID_DLG_PLUGIN_MANAGER_COULDNT_LOAD),
218 XAP_Dialog_MessageBox::b_O,
219 XAP_Dialog_MessageBox::a_OK );
220 }
221 }
222 }
223
224 FREEP(szDescList);
225 FREEP(szSuffixList);
226 FREEP(nTypeList);
227
228 pDialogFactory->releaseDialog(pDialog);
229 }
230
231 void XAP_Win32Dialog_PluginManager::refreshPluginList()
232 {
233 // Clear List Box
234 resetContent( XAP_RID_DIALOG_PLUGIN_MANAGER_LBX_LIST );
235
236 // Populate List Box
237 XAP_Module* pModule = 0;
238 const UT_GenericVector<class XAP_Module *> *pVec = XAP_ModuleManager::instance().enumModules();
239
240 for (UT_sint32 i = 0; i < pVec->size(); i++)
241 {
242 pModule = (XAP_Module *)pVec->getNthItem (i);
243 addItemToList( XAP_RID_DIALOG_PLUGIN_MANAGER_LBX_LIST, pModule->getModuleInfo()->name );
244 }
245 }
246
247 void XAP_Win32Dialog_PluginManager::refreshPluginInfo()
248 {
249
250 const char *pName, *pAuthor, *pDesc, *pVersion;
251 pName = pAuthor = pDesc = pVersion ="";
252 XAP_Module* pModule = NULL;
253
254 if (m_curSelection!=LB_ERR)
255 {
256 pModule = (XAP_Module *) XAP_ModuleManager::instance().enumModules()->getNthItem(m_curSelection);
257 }
258
259 if(pModule)
260 {
261 const XAP_ModuleInfo * mi = pModule->getModuleInfo();
262 if( mi )
263 {
264 pName = mi->name;
265 pAuthor = mi->author;
266 pDesc = mi->desc;
267 pVersion = mi->version;
268 }
269 }
270
271 setControlText(XAP_RID_DIALOG_PLUGIN_MANAGER_EBX_NAME, pName);
272 setControlText(XAP_RID_DIALOG_PLUGIN_MANAGER_EBX_DESCRIPTION, pDesc);
273 setControlText(XAP_RID_DIALOG_PLUGIN_MANAGER_EBX_AUTHOR, pAuthor);
274 setControlText(XAP_RID_DIALOG_PLUGIN_MANAGER_EBX_VERSION, pVersion);
275 }