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

📄 admindlg.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//####COPYRIGHTBEGIN####//// ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.// Copyright (C) 2003 John Dallaway//// This program is part of the eCos host tools.//// 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.//// ----------------------------------------------------------------------------////####COPYRIGHTEND####// admindlg.cpp :////===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s):   julians,jld// Contact(s):  julians// Date:        2000/09/28// Version:     $Id: admindlg.cpp,v 1.6 2001/08/22 16:50:32 julians Exp $// Purpose:// Description: Implementation file for ecAdminDialog// Requires:// Provides:// See also:// Known bugs:// Usage:////####DESCRIPTIONEND####////===========================================================================// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------#ifdef __GNUG__#pragma implementation "admindlg.h"#endif// Includes other headers for precompiled compilation#include "ecpch.h"#ifdef __BORLANDC__#pragma hdrstop#endif// For registry access functions in GetUserToolsPath#ifdef __WXMSW__#include <windows.h>#include "wx/msw/winundef.h"#endif#include "wx/cshelp.h"#include "wx/filedlg.h"#include "wx/file.h"#include "wx/filefn.h"#include "wx/progdlg.h"#include "configtool.h"#include "admindlg.h"#include "configtooldoc.h"#include "licensedlg.h"#include "ecutils.h"#ifdef __WXGTK__#include "bitmaps/package_open.xpm"#include "bitmaps/package_version.xpm"#endifBEGIN_EVENT_TABLE(ecAdminDialog, ecDialog)    EVT_BUTTON(wxID_OK, ecAdminDialog::OnClose)    EVT_BUTTON(ecID_ADMIN_DIALOG_ADD, ecAdminDialog::OnAdd)    EVT_BUTTON(ecID_ADMIN_DIALOG_REMOVE, ecAdminDialog::OnRemove)    EVT_INIT_DIALOG(ecAdminDialog::OnInitDialog)END_EVENT_TABLE()// ----------------------------------------------------------------------------// main frame// ----------------------------------------------------------------------------// Frame constructorecAdminDialog::ecAdminDialog(wxWindow* parent, const wxString& repository, const wxString& userTools):    m_imageList(16, 16, 1){    m_strRepository = repository;    m_strUserTools = userTools;	m_CdlPkgData = NULL;    SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);    ecDialog::Create(parent, ecID_ADMIN_DIALOG, _("Administration"),        wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);    CreateControls(this);    m_imageList.Add(wxICON(package_open));    m_imageList.Add(wxICON(package_version));    m_treeCtrl->SetImageList(& m_imageList);    Centre(wxBOTH);}ecAdminDialog::~ecAdminDialog(){	ClearPackageTree ();	// free memory allocated to the CDL database	if (m_CdlPkgData)		delete m_CdlPkgData;    m_treeCtrl->SetImageList(NULL);}void ecAdminDialog::OnInitDialog(wxInitDialogEvent& event){    // setup the path to the user tools (tar and gunzip)        if ((! m_strUserTools.IsEmpty()) || FindUserToolsPath ()) // if the user tools can be located    {        wxString path;        wxGetEnv(wxT("PATH"), & path);                // TODO: this may not work on all platforms        path = path + wxString(wxPATH_SEP) + m_strUserTools;        wxSetEnv(wxT("PATH"), path);    }        // populate the package tree    if (!PopulatePackageTree (m_strRepository))    {        m_strRepository = wxT("");        // TODO        // OnPkgadminRepository (); // prompt the user for the repository location    }}void ecAdminDialog::CreateControls(wxWindow* parent){    m_treeCtrl = new wxTreeCtrl(parent, ecID_ADMIN_DIALOG_TREE,        wxDefaultPosition, wxSize(380, 290), wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);    wxSizer *item0 = new wxBoxSizer( wxHORIZONTAL );    wxSizer *item1 = new wxBoxSizer( wxVERTICAL );    wxStaticText *item2 = new wxStaticText( parent, wxID_STATIC, _("&Installed packages:"), wxDefaultPosition, wxDefaultSize, 0 );    item1->Add( item2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );    wxWindow *item3 = parent->FindWindow( ecID_ADMIN_DIALOG_TREE );    wxASSERT( item3 );    item1->Add( item3, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );    item0->Add( item1, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );    wxSizer *item4 = new wxBoxSizer( wxVERTICAL );    wxButton *item5 = new wxButton( parent, ecID_ADMIN_DIALOG_ADD, _("&Add..."), wxDefaultPosition, wxDefaultSize, 0 );    item4->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );    wxButton *item6 = new wxButton( parent, ecID_ADMIN_DIALOG_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0 );    item4->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );    item4->Add( 20, 20, 1, wxALIGN_CENTRE|wxALL, 5 );    wxButton *item7 = new wxButton( parent, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );    item4->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );#ifdef __WXGTK__    wxButton *contextButton = new wxContextHelpButton( parent );    item4->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );#endif    item0->Add( item4, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5 );        item7->SetDefault(); // Make Close the default button    parent->SetAutoLayout( TRUE );    parent->SetSizer( item0 );    parent->Layout();    item0->Fit( parent );    //item0->SetSizeHints( parent );    // Add context-sensitive help text    parent->FindWindow( ecID_ADMIN_DIALOG_TREE)->SetHelpText(_("Displays the set of packages currently in the eCos component repository."));    parent->FindWindow( ecID_ADMIN_DIALOG_ADD)->SetHelpText(_("Adds the contents of an eCos package file to the eCos component repository."));    parent->FindWindow( ecID_ADMIN_DIALOG_REMOVE)->SetHelpText(_("Removes the currently selected package from the eCos component repository."));    parent->FindWindow( wxID_OK )->SetHelpText(_("Closes the dialog and saves any changes you have made."));#if __WXGTK__    parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));#endif}void ecAdminDialog::OnAdd(wxCommandEvent& event){    wxString defaultDir; // TODO    wxString defaultFile;    wxString wildcard = wxT("eCos Package Files (*.epk)|*.epk");    wxFileDialog dlg(this, _("Open eCos Package Files"), defaultDir, defaultFile, wildcard, wxOPEN|wxMULTIPLE);    if (wxID_OK == dlg.ShowModal ())    {        bool bRepositoryChanged = FALSE;        //POSITION posPathName = dlg.GetStartPosition ();        wxArrayString filenames;        dlg.GetPaths(filenames);        size_t i;        for (i = (size_t) 0; i < filenames.GetCount(); i++)        {            wxString strPathName(filenames[i]);            if (!wxFileExists(strPathName))            {                wxString msg;                msg.Printf(_("Cannot open %s"), (const wxChar*) strPathName);                wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);            }            else            {                                // get an eCos package distribution file                                // extract the licence file                wxString strCommand;                strCommand.Printf(wxT("add %s --extract_license"), (const wxChar*) strPathName);                strCommand.Replace(wxT("\\"), wxT("/")); // backslashes -> forward slashes for Tcl_EvalFile                EvalTclFile (3, strCommand, _("Adding package"));                wxString strLicenseFile = m_strRepository + wxString(wxFILE_SEP_PATH) + wxT("pkgadd.txt");#ifdef __WXMSW__                strLicenseFile.Replace (wxT("/"), wxT("\\")); // forward slashes -> backslashes for Win32#endif                // read the license file                wxFile fileLicenseFile;                if (fileLicenseFile.Exists (strLicenseFile) && fileLicenseFile.Open (strLicenseFile, wxFile::read))                {                    //TRACE (_T("License file found at %s\n"), strLicenseFile);                    const off_t dwLicenseLength = fileLicenseFile.Length ();                    char* pszBuffer = new char [dwLicenseLength + 1]; // allocate a buffer                    fileLicenseFile.Read ((void*) pszBuffer, dwLicenseLength);                    fileLicenseFile.Close ();                    wxRemoveFile (strLicenseFile); // delete the license file when read                    pszBuffer [dwLicenseLength] = 0; // terminate the string in the buffer                    wxString strLicenseText (pszBuffer); // copy into a wxString to convert to Unicode                    delete [] pszBuffer;#ifdef __WXMSW__                    if (-1 == strLicenseText.Find (wxT("\r\n"))) // if the file has LF line endings...                        strLicenseText.Replace (_T("\n"), _T("\r\n")); // ... replace with CRLF line endings#else                    strLicenseText.Replace (_T("\r"), wxEmptyString); // remove CR characters#endif                    // display the license text                    ecLicenseDialog dlgLicense (strLicenseText, this, ecID_LICENSE_DIALOG, strPathName + _(" - Add Packages"));                    if (wxID_OK != dlgLicense.ShowModal ()) // if license not accepted by user                        continue; // try the next file                }                                // add the contents of the package distribution file                

⌨️ 快捷键说明

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