| 1 |
/* AbiSource Application Framework |
| 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 |
#include "xap_Dlg_PluginManager.h" |
| 21 |
#include "xap_ModuleManager.h" |
| 22 |
|
| 23 |
#include "ut_vector.h" |
| 24 |
#include "ut_assert.h" |
| 25 |
#include "ut_go_file.h" |
| 26 |
|
| 27 |
XAP_Dialog_PluginManager::XAP_Dialog_PluginManager (XAP_DialogFactory * pDlgFactory, |
| 28 |
XAP_Dialog_Id id) |
| 29 |
: XAP_Dialog_NonPersistent(pDlgFactory,id, "interface/dialogplugins") |
| 30 |
{ |
| 31 |
} |
| 32 |
|
| 33 |
XAP_Dialog_PluginManager::~XAP_Dialog_PluginManager () |
| 34 |
{ |
| 35 |
} |
| 36 |
|
| 37 |
bool XAP_Dialog_PluginManager::activatePlugin (const char * szURI) const |
| 38 |
{ |
| 39 |
UT_return_val_if_fail (szURI, false); |
| 40 |
|
| 41 |
char * szName = UT_go_filename_from_uri(szURI); |
| 42 |
if(szName) { |
| 43 |
bool loaded = XAP_ModuleManager::instance ().loadModule (szName); |
| 44 |
g_free(szName); |
| 45 |
return loaded; |
| 46 |
} |
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
bool XAP_Dialog_PluginManager::deactivatePlugin (XAP_Module * which) const |
| 51 |
{ |
| 52 |
UT_return_val_if_fail (which, false); |
| 53 |
XAP_ModuleManager::instance ().unloadModule (which); |
| 54 |
return true; |
| 55 |
} |
| 56 |
|
| 57 |
bool XAP_Dialog_PluginManager::deactivateAllPlugins () const |
| 58 |
{ |
| 59 |
const UT_GenericVector<XAP_Module*> * pVec = XAP_ModuleManager::instance().enumModules (); |
| 60 |
|
| 61 |
UT_ASSERT (pVec); |
| 62 |
if (pVec == 0) return false; |
| 63 |
|
| 64 |
while (UT_sint32 size = pVec->size ()) |
| 65 |
{ |
| 66 |
if (XAP_Module * pMod = pVec->getNthItem (0)) |
| 67 |
{ |
| 68 |
deactivatePlugin (pMod); |
| 69 |
} |
| 70 |
if (pVec->size () == size) // huh? |
| 71 |
{ |
| 72 |
UT_ASSERT (UT_SHOULD_NOT_HAPPEN); |
| 73 |
break; |
| 74 |
} |
| 75 |
} |
| 76 |
return true; |
| 77 |
} |