00001 00002 /*************************************************************************** 00003 * config_editor_plugin.cpp - Base class for config editor plugins 00004 * 00005 * Created: Sun Mar 29 13:26:56 2009 00006 * Copyright 2009 Daniel Beck 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include "config_editor_plugin.h" 00024 00025 using namespace std; 00026 using namespace fawkes; 00027 00028 /** @class ConfigEditorPlugin tools/config_editor/config_editor_plugin.h 00029 * Base class for plugins for the Fawkes config editor. A plugin 00030 * allows to manipulate a certain part of the configuration, most 00031 * often this is intended to be the config options for a Fawkes 00032 * plugin. 00033 * @author Daniel Beck 00034 */ 00035 00036 /** @fn void ConfigEditorPlugin::pre_run() 00037 * Config editor plugins need to implement this function. It is called 00038 * before the actual dialog is opened. Ususally, plugins want to parse 00039 * the configuration, here, and initialize the GUI elements of the 00040 * dialog. 00041 */ 00042 00043 /** @fn void ConfigEditorPlugin::post_run( int response ) 00044 * This method is called after the dialog is closed. Here, the input 00045 * the user has made needs to be handled. 00046 * @param response the response obtained from the run() method of the 00047 * dialog (Gtk::RESPONSE_OK or Gtk::RESPONSE_CANCEL) 00048 */ 00049 00050 /** @fn Gtk::Dialog* ConfigEditorPlugin::load_dialog() 00051 * In this function the (custom) dialog of the plugin needs to be 00052 * initialized. 00053 * @return pointer to the loaded dialog 00054 */ 00055 00056 /** @var ConfigEditorPlugin::m_dialog 00057 * The (main-) dialog of the plugin. 00058 */ 00059 00060 /** @var ConfigEditorPlugin::m_ref_xml 00061 * Glade XML object created from the Glade file of the plugin. 00062 */ 00063 00064 /** @var ConfigEditorPlugin:: m_config 00065 * The fawkes::Configuration. 00066 */ 00067 00068 /** @var ConfigEditorPlugin::m_config_path 00069 * The config prefix the plugin is attached to. 00070 */ 00071 00072 /** Constructor. 00073 * @param config_path the prefix of the part that can be configured 00074 * with this plugin 00075 * @param glade_file a Glade file which contains the definition the 00076 * plugin's GUI components 00077 */ 00078 ConfigEditorPlugin::ConfigEditorPlugin( string config_path, 00079 string glade_file ) 00080 { 00081 m_config_path = config_path; 00082 m_ref_xml = Gnome::Glade::Xml::create( glade_file ); 00083 } 00084 00085 /** Destructor. */ 00086 ConfigEditorPlugin::~ConfigEditorPlugin() 00087 { 00088 } 00089 00090 /** Get the config prefix specified for this config editor plugin. 00091 * @return the config prefix 00092 */ 00093 std::string 00094 ConfigEditorPlugin::get_config_path() const 00095 { 00096 return m_config_path; 00097 } 00098 00099 /** Set the configuration for the plugin to work on. 00100 * @param config the configuration 00101 */ 00102 void 00103 ConfigEditorPlugin::set_config( fawkes::Configuration* config ) 00104 { 00105 m_config = config; 00106 } 00107 00108 /** Initialize the plugin. 00109 * This method needs to be called before the plugin can be used. 00110 */ 00111 void 00112 ConfigEditorPlugin::initialize() 00113 { 00114 m_dialog = load_dialog(); 00115 } 00116 00117 /** Run the plugin. 00118 * Usually, this means opening a dialog where config values can be 00119 * manipulated and on closing these are written to the config. 00120 */ 00121 void 00122 ConfigEditorPlugin::run() 00123 { 00124 pre_run(); 00125 int response = m_dialog->run(); 00126 post_run( response ); 00127 m_dialog->hide(); 00128 }