HTTP Libraries: Add support for descriptions of sublibraries
This commit is contained in:
parent
7ed755ac61
commit
17891f7a1d
|
@ -143,8 +143,15 @@ bool HTTP_LIB_CONNECTION::syncCategories()
|
|||
{
|
||||
HTTP_LIB_CATEGORY category;
|
||||
|
||||
category.id = item.value()["id"].get<std::string>();
|
||||
category.name = item.value()["name"].get<std::string>();
|
||||
auto& value = item.value();
|
||||
category.id = value["id"].get<std::string>();
|
||||
category.name = value["name"].get<std::string>();
|
||||
|
||||
if( value.contains( "description" ) )
|
||||
{
|
||||
category.description = value["description"].get<std::string>();
|
||||
m_categoryDescriptions[category.name] = category.description;
|
||||
}
|
||||
|
||||
m_categories.push_back( category );
|
||||
}
|
||||
|
@ -179,12 +186,12 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
|
|||
if( m_cachedParts.find( aPartID ) != m_cachedParts.end() )
|
||||
{
|
||||
// check if it's outdated, if so re-fetch
|
||||
if( std::difftime( std::time( nullptr ), m_cachedParts[aPartID].lastCached ) < m_source.timeout_parts )
|
||||
if( std::difftime( std::time( nullptr ), m_cachedParts[aPartID].lastCached )
|
||||
< m_source.timeout_parts )
|
||||
{
|
||||
aFetchedPart = m_cachedParts[aPartID];
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string res = "";
|
||||
|
@ -299,7 +306,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
|
|||
}
|
||||
|
||||
|
||||
bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
|
||||
bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
|
||||
std::vector<HTTP_LIB_PART>& aParts )
|
||||
{
|
||||
if( !IsValidEndpoint() )
|
||||
|
|
|
@ -193,6 +193,10 @@ void SCH_IO_HTTP_LIB::GetSubLibraryNames( std::vector<wxString>& aNames )
|
|||
}
|
||||
}
|
||||
|
||||
wxString SCH_IO_HTTP_LIB::GetSubLibraryDescription( const wxString& aName )
|
||||
{
|
||||
return m_conn->getCategoryDescription( std::string( aName.mb_str() ) );
|
||||
}
|
||||
|
||||
void SCH_IO_HTTP_LIB::GetAvailableSymbolFields( std::vector<wxString>& aNames )
|
||||
{
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
|
||||
void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
|
||||
|
||||
wxString GetSubLibraryDescription( const wxString& aName ) override;
|
||||
|
||||
void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
|
||||
|
||||
void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
|
||||
|
|
|
@ -301,6 +301,17 @@ public:
|
|||
*/
|
||||
virtual void GetSubLibraryNames( std::vector<wxString>& aNames ) {}
|
||||
|
||||
/**
|
||||
* Gets a description of a sublibrary.
|
||||
*
|
||||
* Has no effect if SupportsSubLibraries() returns false.
|
||||
*
|
||||
* @param aName contains the name of the sublibrary for which the description is retrieved
|
||||
*
|
||||
* @return the description of the sublibrary
|
||||
*/
|
||||
virtual wxString GetSubLibraryDescription( const wxString& aName ) { return wxEmptyString; }
|
||||
|
||||
/**
|
||||
* Retrieves a list of (custom) field names that are present on symbols in this library.
|
||||
* The plugin is responsible for guaranteeing that this list contains the set of unique
|
||||
|
|
|
@ -104,6 +104,15 @@ void SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames( std::vector<wxString>& aNames ) c
|
|||
}
|
||||
|
||||
|
||||
wxString SYMBOL_LIB_TABLE_ROW::GetSubLibraryDescription( const wxString& aName ) const
|
||||
{
|
||||
if( !plugin )
|
||||
return wxEmptyString;
|
||||
|
||||
return plugin->GetSubLibraryDescription( aName );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE_ROW::ShowSettingsDialog( wxWindow* aParent ) const
|
||||
{
|
||||
wxCHECK( plugin, /* void */ );
|
||||
|
|
|
@ -95,6 +95,8 @@ public:
|
|||
|
||||
void GetSubLibraryNames( std::vector<wxString>& aNames ) const;
|
||||
|
||||
wxString GetSubLibraryDescription( const wxString& aName ) const;
|
||||
|
||||
/**
|
||||
* @see SCH_IO::GetAvailableSymbolFields
|
||||
*/
|
||||
|
|
|
@ -158,10 +158,11 @@ bool SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNick
|
|||
wxString suffix = lib.IsEmpty() ? wxString( wxT( "" ) )
|
||||
: wxString::Format( wxT( " - %s" ), lib );
|
||||
wxString name = wxString::Format( wxT( "%s%s" ), libNickname, suffix );
|
||||
wxString desc;
|
||||
wxString desc = row->GetSubLibraryDescription( lib );
|
||||
|
||||
if( !parentDesc.IsEmpty() )
|
||||
desc = wxString::Format( wxT( "%s (%s)" ), parentDesc, lib );
|
||||
desc = wxString::Format( wxT( "%s (%s)" ), parentDesc,
|
||||
( desc.IsEmpty() ) ? lib : desc );
|
||||
|
||||
UTF8 utf8Lib( lib );
|
||||
|
||||
|
|
|
@ -60,15 +60,18 @@ public:
|
|||
|
||||
std::vector<HTTP_LIB_CATEGORY> getCategories() const { return m_categories; }
|
||||
|
||||
std::string getCategoryDescription( const std::string& aCategoryName ) const
|
||||
{
|
||||
return m_categoryDescriptions.at( aCategoryName );
|
||||
}
|
||||
|
||||
auto getCachedParts() { return m_cache; }
|
||||
|
||||
private:
|
||||
|
||||
// This is clunky but at the moment the only way to free the pointer after use without KiCad crashing.
|
||||
// at this point we can't use smart pointers as there is a problem with the order of how things are deleted/freed
|
||||
std::unique_ptr<KICAD_CURL_EASY> createCurlEasyObject()
|
||||
{
|
||||
|
||||
std::unique_ptr<KICAD_CURL_EASY> aCurl( new KICAD_CURL_EASY() );
|
||||
|
||||
// prepare curl
|
||||
|
@ -88,7 +91,7 @@ private:
|
|||
|
||||
wxString httpErrorCodeDescription( uint16_t aHttpCode );
|
||||
|
||||
HTTP_LIB_SOURCE m_source;
|
||||
HTTP_LIB_SOURCE m_source;
|
||||
|
||||
// part.id part
|
||||
std::map<std::string, HTTP_LIB_PART> m_cachedParts;
|
||||
|
@ -100,7 +103,8 @@ private:
|
|||
|
||||
std::string m_lastError;
|
||||
|
||||
std::vector<HTTP_LIB_CATEGORY> m_categories;
|
||||
std::vector<HTTP_LIB_CATEGORY> m_categories;
|
||||
std::map<std::string, std::string> m_categoryDescriptions;
|
||||
|
||||
std::map<std::string, std::string> m_parts;
|
||||
|
||||
|
@ -108,7 +112,6 @@ private:
|
|||
const std::string http_endpoint_parts = "parts";
|
||||
const std::string http_endpoint_settings = "settings";
|
||||
const std::string http_endpoint_auth = "authentication";
|
||||
|
||||
};
|
||||
|
||||
#endif //KICAD_HTTP_LIB_CONNECTION_H
|
||||
|
|
|
@ -61,8 +61,9 @@ struct HTTP_LIB_PART
|
|||
|
||||
struct HTTP_LIB_CATEGORY
|
||||
{
|
||||
std::string id; ///< id of category
|
||||
std::string name; ///< name of category
|
||||
std::string id; ///< id of category
|
||||
std::string name; ///< name of category
|
||||
std::string description; ///< description of category
|
||||
|
||||
std::time_t lastCached = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue