Fawkes API  Fawkes Development Version
config_editor_plugin.cpp
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_builder
00061  * Gtk Builder created from the UI 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 ui_file a Gtk Builder file which contains the definition the
00076  * plugin's GUI components
00077  */
00078 ConfigEditorPlugin::ConfigEditorPlugin(string config_path, string ui_file)
00079 {
00080   m_config_path = config_path;
00081   m_builder = Gtk::Builder::create_from_file(ui_file);
00082 }
00083 
00084 /** Destructor. */
00085 ConfigEditorPlugin::~ConfigEditorPlugin()
00086 {
00087 }
00088 
00089 /** Get the config prefix specified for this config editor plugin.
00090  * @return the config prefix
00091  */
00092 std::string
00093 ConfigEditorPlugin::get_config_path() const
00094 {
00095   return m_config_path;
00096 }
00097 
00098 /** Set the configuration for the plugin to work on.
00099  * @param config the configuration
00100  */
00101 void
00102 ConfigEditorPlugin::set_config( fawkes::Configuration* config )
00103 {
00104   m_config = config;
00105 }
00106 
00107 /** Initialize the plugin.
00108  * This method needs to be called before the plugin can be used.
00109  */
00110 void
00111 ConfigEditorPlugin::initialize()
00112 {
00113   m_dialog = load_dialog();
00114 }
00115 
00116 /** Run the plugin.
00117  * Usually, this means opening a dialog where config values can be
00118  * manipulated and on closing these are written to the config.
00119  */
00120 void
00121 ConfigEditorPlugin::run()
00122 {
00123   pre_run();
00124   int response = m_dialog->run();
00125   post_run( response );
00126   m_dialog->hide();
00127 }