2015-01-15 20:01:53 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2017-06-13 23:47:05 +00:00
|
|
|
* Copyright (C) 2015-2017 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2015-01-15 20:01:53 +00:00
|
|
|
*
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GITHUB_GETLIBLIST_H_
|
|
|
|
#define GITHUB_GETLIBLIST_H_
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-20 07:14:44 +00:00
|
|
|
* Class GITHUB_GETLIBLIST
|
|
|
|
* implements a portion of pcbnew's PLUGIN interface to provide read only access
|
|
|
|
* to a github repo to extract pretty footprints library list, in json format,
|
|
|
|
* or extract 3D shapes libraries list (.3dshapes folders) and download the 3d shapes files
|
2015-01-15 20:01:53 +00:00
|
|
|
*
|
2015-08-20 07:14:44 +00:00
|
|
|
* To extract pretty footprints library list, this plugin simply reads in
|
|
|
|
* a zip file of the repo and unzips it from RAM as needed.
|
2017-06-26 07:11:21 +00:00
|
|
|
* Therefore this "Github" plugin is <b>read only</b> for accessing remote
|
|
|
|
* at "https://api.github.com/orgs/KiCad/repos"
|
2015-08-20 07:14:44 +00:00
|
|
|
*
|
|
|
|
* To extract 3D shapes libraries list (.3dshapes folders) we cannot use api.github.com
|
2017-06-26 07:11:21 +00:00
|
|
|
* to read this list, because it is in a subdirectory of "https://github.com/KiCad".
|
2015-08-20 07:14:44 +00:00
|
|
|
* The corresponding html page of the server is read, and URLs of all .3dshapes folders
|
|
|
|
* are extracted.
|
2017-06-26 07:11:21 +00:00
|
|
|
* files are then read from "https://raw.githubusercontent.com/<lib path>", but not zipped
|
2015-08-20 07:14:44 +00:00
|
|
|
* because they are not accessible in zipped form.
|
2015-01-15 20:01:53 +00:00
|
|
|
*/
|
|
|
|
class GITHUB_GETLIBLIST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// -----<API>----------------------------------------------------------
|
2015-08-20 07:14:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills aList by the name of footprint libraries found on the github repo
|
|
|
|
*/
|
|
|
|
bool GetFootprintLibraryList( wxArrayString& aList );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills aList by the URL of libraries found on the github repo
|
|
|
|
* @param aList = a reference to a wxArrayString to fill with names
|
|
|
|
* @param aFilter( const wxString& aData ) = a callback funtion to
|
|
|
|
* to filter URLs to put in aList.
|
|
|
|
* If NULL, no URL will be stored in aList
|
|
|
|
*/
|
|
|
|
bool Get3DshapesLibsList( wxArrayString* aList,
|
|
|
|
bool (*aFilter)( const wxString& aData ) );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the buffer which stores all the downloaded raw data
|
|
|
|
*/
|
|
|
|
std::string& GetBuffer() { return m_image; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the buffer which stores all the downloaded raw data
|
|
|
|
*/
|
|
|
|
void ClearBuffer() { m_image.clear(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The library names are expecting ending by .pretty
|
|
|
|
* SetLibraryExt set the extension to aExt
|
|
|
|
*/
|
|
|
|
void SetLibraryExt( const wxString& aExt ) { m_libs_ext = aExt; }
|
2015-01-15 20:01:53 +00:00
|
|
|
|
|
|
|
// -----</API>---------------------------------------------------------
|
|
|
|
|
|
|
|
GITHUB_GETLIBLIST( const wxString& aRepoURL );
|
|
|
|
~GITHUB_GETLIBLIST() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function repoURL2listURL
|
|
|
|
* translates a repo URL to the URL name which gives the state of repos URL
|
|
|
|
* as commonly seen on github.com
|
|
|
|
*
|
|
|
|
* @param aRepoURL points to the base of the repo.
|
|
|
|
* @param aFullURLCommand is URL the full URL command (URL+options).
|
2015-08-20 07:14:44 +00:00
|
|
|
* @param aItemCountMax is the max item count in a page,
|
2015-01-15 20:01:53 +00:00
|
|
|
* and is 100 for github repo.
|
|
|
|
* @param aPage is the page number, if there are more than one page in repo.
|
|
|
|
* @return bool - true if @a aRepoULR was parseable, else false
|
|
|
|
*/
|
|
|
|
bool repoURL2listURL( const wxString& aRepoURL, std::string* aFullURLCommand,
|
|
|
|
int aItemCountMax, int aPage = 1 );
|
|
|
|
|
|
|
|
/**
|
2015-12-21 20:30:33 +00:00
|
|
|
* Function remoteGetJSON
|
2015-01-15 20:01:53 +00:00
|
|
|
* Download a json text from a github repo. The text image
|
|
|
|
* is received into the m_input_stream.
|
|
|
|
* @param aFullURLCommand the full command, i.e. the url with options like
|
|
|
|
* "https://api.github.com/users/KiCad/repos?per_page=100?page=1"
|
|
|
|
* @param aMsgError a pointer to a wxString which can store an error message
|
|
|
|
* @return true if OK, false if error (which an error message in *aMsgError
|
|
|
|
*/
|
2015-12-21 20:30:33 +00:00
|
|
|
bool remoteGetJSON( const std::string& aFullURLCommand, wxString* aMsgError );
|
2015-01-15 20:01:53 +00:00
|
|
|
|
|
|
|
wxString m_github_path; ///< Something like https://api.github.com/orgs/KiCad
|
2015-08-20 07:14:44 +00:00
|
|
|
std::string m_image; ///< image of the downloaded data in its entirety.
|
|
|
|
wxString m_repoURL; ///< the URL of the Github repo
|
|
|
|
wxString m_libs_ext; ///< the extension of the name of libraries (default = .pretty)
|
|
|
|
char m_option_string[64]; ///< option for transfert type, like "application/json"
|
2015-01-15 20:01:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // GITHUB_GETLIBLIST_H_
|