⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nutconfdoc.cpp

📁 含有完整TCP/IP PPP协议的嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ---------------------------------------------------------------------------- * Copyright (C) 2004-2005 by egnite Software GmbH * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * ---------------------------------------------------------------------------- * Parts are * * Copyright (C) 1998, 1999, 2000 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * ---------------------------------------------------------------------------- *//* * $Log: nutconfdoc.cpp,v $ * Revision 1.14  2005/11/24 09:44:30  haraldkipp * wxWidget failed to built with unicode support, which results in a number * of compile errors. Fixed by Torben Mikael Hansen. * * Revision 1.13  2005/10/07 22:12:28  hwmaier * Added bld_dir parameter to CreateSampleDirectory. * * Revision 1.12  2005/08/14 16:10:18  christianwelzel * Avoid compiler warnings under cygwin. * * Revision 1.11  2005/07/26 16:39:09  haraldkipp * Do not store default values. * * Revision 1.10  2005/04/22 15:19:45  haraldkipp * Added support for building ICCAVR applications in the sample tree. * * Revision 1.9  2004/11/24 15:36:53  haraldkipp * Release 1.1.1. * Do not store empty options. * Remove include files from the build tree, if they are no longer used. * Command line parameter 's' allows different settings. * Minor compiler warning fixed. * * Revision 1.8  2004/11/08 10:21:26  drsung * While creating the sample directory, CVS files are now not copied. * * Revision 1.7  2004/09/26 12:04:07  drsung * Fixed several hundred memory leaks :-). * Relative pathes can now be used for source, build and install directory. * * Revision 1.6  2004/09/19 15:12:22  haraldkipp * Set mod flag on all changes * * Revision 1.5  2004/09/17 13:02:39  haraldkipp * First and last directory added to sample dir * * Revision 1.4  2004/09/07 19:20:07  haraldkipp * Initial/default lib/inc dirs updated * * Revision 1.3  2004/08/18 13:34:20  haraldkipp * Now working on Linux * * Revision 1.2  2004/08/03 15:03:25  haraldkipp * Another change of everything * * Revision 1.1  2004/06/07 16:11:22  haraldkipp * Complete redesign based on eCos' configtool * */#include <wx/dir.h>#include <wx/file.h>#include <wx/filename.h>#include <wx/txtstrm.h>#include <wx/wfstream.h>#include "nutconf.h"#include "treeitemdata.h"#include "nutconfhint.h"#include "nutconfdoc.h"#ifdef __WXMSW__#define strcasecmp stricmp#endif/* * The doc/view framework will create instances of this class dynamically. */IMPLEMENT_DYNAMIC_CLASS(CNutConfDoc, wxDocument);/*! * \brief Default constructor. */CNutConfDoc::CNutConfDoc(){    m_root = NULL;}/*! * \brief Destructor. */CNutConfDoc::~CNutConfDoc(){    ReleaseRepository();    DeleteItems();}/*! * \brief Create a document from a specified file. * * \param path Pathname of the configuration file. */bool CNutConfDoc::OnCreate(const wxString & path, long flags){    bool rc = false;    wxString normPath(path);    normPath.Replace(wxT("\\"), wxT("/"));    wxGetApp().GetSettings()->m_configname = normPath;    wxGetApp().m_currentDoc = this;    if ((rc = ReadRepository(wxGetApp().GetSettings()->m_repositoryname, normPath)) == true) {        Modify(false);        SetDocumentSaved(false);        rc = wxDocument::OnCreate(path, flags);        if (rc) {            if (flags & wxDOC_NEW) {                wxBusyCursor wait;                CNutConfHint hint(NULL, nutSelChanged);                UpdateAllViews(NULL, &hint);                SetFilename(GetFilename(), true);            }        }    }    if(!rc) {        wxGetApp().m_currentDoc = NULL;    }    return rc;}/*! * \brief Create an empty document. * * \todo Doesn't do anything right now. */bool CNutConfDoc::OnNewDocument(){    return true;}/*! * \brief Open an existing document. * */bool CNutConfDoc::OnOpenDocument(const wxString & filename){    /*     * Check if the current document has been modified.     */    if (!OnSaveModified())        return false;    SetFilename(filename, true);    Modify(false);    UpdateAllViews();    return true;}void CNutConfDoc::SaveComponentOptions(FILE *fp, NUTCOMPONENT * compo){    while (compo) {        NUTCOMPONENTOPTION *opts = compo->nc_opts;        while (opts) {            if(opts->nco_enabled && opts->nco_active) {                if(opts->nco_value &&                   (opts->nco_default == NULL || strcmp(opts->nco_value, opts->nco_default))) {                    fprintf(fp, "%s = \"%s\"\n", opts->nco_name, opts->nco_value);                }                /* Do not save empty values. */                else if (opts->nco_flavor &&                         (strcasecmp(opts->nco_flavor, "boolean") == 0 ||                         strcasecmp(opts->nco_flavor, "booldata") == 0)) {                    fprintf(fp, "%s = \"\"\n", opts->nco_name);                }            }            opts = opts->nco_nxt;        }        SaveComponentOptions(fp, compo->nc_child);        compo = compo->nc_nxt;    }}bool CNutConfDoc::OnSaveDocument(const wxString& filename){    if (filename.IsEmpty()) {        return false;    }    FILE *fp = fopen(filename.fn_str(), "w");    if (fp) {        SaveComponentOptions(fp, m_root->nc_child);        fclose(fp);    }    Modify(false);    SetFilename(filename);    return true;}/*! * \brief Close the document. */bool CNutConfDoc::OnCloseDocument(){    if (wxDocument::OnCloseDocument()) {        DeleteItems();        return true;    }    return false;}void CNutConfDoc::ReleaseRepository(){	if (m_root)		ReleaseComponents(m_root);}/* * Delete all items. */void CNutConfDoc::DeleteItems(){    wxNode *node = m_items.GetFirst();    while (node) {        wxNode *next = node->GetNext();        node = next;    }}bool CNutConfDoc::ReadRepository(const wxString & repositoryname, const wxString & configname){    wxBusyCursor wait;    wxString str;    str = wxT("Loading ") + repositoryname;    wxGetApp().SetStatusText(str);    wxLogMessage(wxT("%s"), str.c_str());    NUTREPOSITORY *repo = OpenRepository(repositoryname.fn_str());    if(repo) {        m_root = LoadComponents(repo);        if(m_root) {            str = wxT("Loading ") + configname;            wxGetApp().SetStatusText(str);            wxLogMessage(wxT("%s"), str.c_str());            if(ConfigureComponents(repo, m_root, configname.fn_str())) {                wxLogMessage(wxT("%s"), GetScriptErrorString());            }            else {                RefreshComponents(m_root);                wxLogMessage(wxT("OK"));            }        }        else {            wxLogMessage(wxT("%s"), GetScriptErrorString());        }        CloseRepository(repo);    }    else {        wxLogError(wxT("Failed to open repository"));    }    wxDocument::OnNewDocument();    AddAllItems();    wxGetApp().SetStatusText(wxEmptyString);    return true;}void CNutConfDoc::AddChildItems(NUTCOMPONENT * compo, wxTreeItemId parent){    CConfigTree *treeCtrl = wxGetApp().GetMainFrame()->GetTreeCtrl();    if(compo) {        compo = compo->nc_child;        while (compo) {            CConfigItem *item = new CConfigItem(NULL, compo);            wxTreeItemId childId = treeCtrl->AppendItem(parent, wxT(""), -1, -1, new CTreeItemData(item));            item->SetTreeItem(childId);            item->UpdateTreeItem(*treeCtrl);            m_items.Append(item);            NUTCOMPONENTOPTION *opts = compo->nc_opts;            while (opts) {                item = new CConfigItem(item, opts);                wxTreeItemId optId = treeCtrl->AppendItem(childId, wxT(""), -1, -1, new CTreeItemData(item));                item->SetTreeItem(optId);                item->UpdateTreeItem(*treeCtrl);                m_items.Append(item);                opts = opts->nco_nxt;            }            AddChildItems(compo, childId);            compo = compo->nc_nxt;        }    }}/*! * \brief Create all configuration items. */void CNutConfDoc::AddAllItems(){    CConfigTree *treeCtrl = wxGetApp().GetMainFrame()->GetTreeCtrl();    wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(NULL);    treeCtrl->DeleteAllItems();    CConfigItem *item = new CConfigItem();    wxTreeItemId rootId = treeCtrl->AddRoot(wxT(""), -1, -1, new CTreeItemData(item));    item->SetTreeItem(rootId);    item->UpdateTreeItem(*treeCtrl);    m_items.Append(item);    AddChildItems(m_root, rootId);    UpdateAllViews();    if (GetItems().GetCount() > 0) {        wxGetApp().GetMainFrame()->GetTreeCtrl()->Expand(rootId);    }    wxGetApp().GetMainFrame()->GetTreeCtrl()->SetFocus();}/*! * \brief Return the list of items. */wxList & CNutConfDoc::GetItems(){    return m_items;}/*! * \brief Return a specified item. */CConfigItem *CNutConfDoc::GetItem(size_t i){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -