Ejemplo n.º 1
0
bool eSettings::AddReplace(const wxString& pattern) {
	wxJSONValue& replacements = m_jsonRoot[wxT("replaceHistory")];

	// Don't add duplicates
	if (replacements.Size() > 0) {
		const wxJSONValue last = replacements.ItemAt(0);
		if (last.AsString() == pattern) return false;
		
		// Check if there should be a duplicate lower down
		for (int i = 0; i < replacements.Size(); ++i) {
			if (replacements[i].AsString() == pattern) {
				replacements.Remove(i);
				break;
			}
		}
	}
	
	// Add the new item
	replacements.Insert(0, pattern);

	// Limit number of items to save
	if (replacements.Size() > 20) replacements.Remove(replacements.Size()-1);

	return true;
}
Ejemplo n.º 2
0
bool eSettings::AddFilterCommand(const wxString& command) {
	wxJSONValue& values = m_jsonRoot[wxT("filterCommandHistory")];

	// Don't add duplicates
	if (values.Size() > 0) {
		const wxJSONValue last = values.ItemAt(0);
		if (last.AsString() == command) return false;
		
		// Check if there should be a duplicate lower down
		for (int i = 0; i < values.Size(); ++i) {
			if (values[i].AsString() == command) {
				values.Remove(i);
				break;
			}
		}
	}
	
	// Add the new item
	values.Insert(0, command);

	// Limit number of items to save
	if (values.Size() > 20) values.Remove(values.Size()-1);

	return true;
}
Ejemplo n.º 3
0
wxString eSettings::GetRemoteProfileName(size_t profile_id) const {
	const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
	wxASSERT((int)profile_id < remotes.Size());
	const wxJSONValue profile = remotes.ItemAt(profile_id);
	
	return profile.ItemAt(wxT("name")).AsString();
}
Ejemplo n.º 4
0
wxString eSettings::GetPagePath(size_t page_id) const {
	const wxJSONValue pages = m_jsonRoot.ItemAt(wxT("pages"));
	wxASSERT((int)page_id < pages.Size());
	const wxJSONValue page = pages.ItemAt(page_id);

	return page.ItemAt(wxT("path")).AsString();
}
Ejemplo n.º 5
0
//! Write the comment strings, if any.
int
wxJSONWriter::WriteComment( wxOutputStream& os, const wxJSONValue& value, bool indent )
{
    // the function returns the last character written which should be
    // a LF char or -1 in case of errors
    // if nothing is written, returns ZERO
    int lastChar = 0;

    // only write comments if the style include the WRITE_COMMENTS flag
    if ( (m_style & wxJSONWRITER_WRITE_COMMENTS ) == 0 ) {
        return lastChar;
    }

    const wxArrayString cmt = value.GetCommentArray();
    int cmtSize = cmt.GetCount();
    for ( int i = 0; i < cmtSize; i++ )    {
        if ( indent )    {
            WriteIndent( os );
        }
        else    {
            os.PutC( '\t' );
        }
        WriteString( os, cmt[i]);
        lastChar = cmt[i].Last();
        if ( lastChar != '\n' )   {
            os.PutC( '\n' );
            lastChar = '\n';
        }
    }
    return lastChar;
}
Ejemplo n.º 6
0
/*!
 This function is called for every value objects of INT type.
 This function uses the \n snprintf function to get the US-ASCII
 representation of the integer and simply copy it to the output stream.
 Returns -1 on stream errors or ZERO if no errors.
*/
int
wxJSONWriter::WriteIntValue( wxOutputStream& os, const wxJSONValue& value )
{
    int r = 0;
    char buffer[32];        // need to store 64-bits integers (max 20 digits)
    size_t len;

    wxJSONRefData* data = value.GetRefData();
    wxASSERT( data );

#if defined( wxJSON_64BIT_INT )

        // this is for wxW 2.8 Unicode: in order to use the cross-platform
        // format specifier, we use the wxString's sprintf() function and then
        // convert to UTF-8 before writing to the stream
        wxString s;
        s.Printf( _T("%") wxLongLongFmtSpec _T("d"),
                                                data->m_value.m_valInt64 );
        wxCharBuffer cb = s.ToUTF8();
        const char* cbData = cb.data();
        len = strlen( cbData );
        wxASSERT( len < 32 );
        memcpy( buffer, cbData, len );
        buffer[len] = 0;
    
#else
    snprintf( buffer, 32, "%ld", data->m_value.m_valLong );
#endif
    len = strlen( buffer );
    os.Write( buffer, len );
    if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
        r = -1;
    }
    return r;
}
Ejemplo n.º 7
0
void eSettings::GetSearch(size_t ndx, wxString& pattern, bool& isRegex, bool& matchCase) const {
	const wxJSONValue searches = m_jsonRoot.ItemAt(wxT("searchHistory"));
	wxASSERT((int)ndx < searches.Size());

	const wxJSONValue item = searches.ItemAt(ndx);
	pattern = item.ItemAt(wxT("pattern")).AsString();
	isRegex = item.ItemAt(wxT("isRegex")).AsBool();
	matchCase = item.ItemAt(wxT("matchCase")).AsBool();
}
Ejemplo n.º 8
0
bool eSettings::GetSettingBool(const wxString& name, bool& value) const {
	if (!m_jsonRoot.HasMember(wxT("settings"))) return false;

	const wxJSONValue settings = m_jsonRoot.ItemAt(wxT("settings"));
	if (!settings.HasMember(name)) return false;

	// old bool values may have been stored as ints
	const wxJSONValue val = settings.ItemAt(name);
	if (val.IsInt()) return (val.AsInt() > 0);

	if (!val.IsBool()) return false;

	value = val.AsBool();
	return true;
}
Ejemplo n.º 9
0
doc_id eSettings::GetPageDoc(size_t page_id) const {
	const wxJSONValue pages = m_jsonRoot.ItemAt(wxT("pages"));
	wxASSERT((int)page_id < pages.Size());
	const wxJSONValue page = pages.ItemAt(page_id);

	doc_id di;
	di.type = (doc_type)page.ItemAt(wxT("doc_type")).AsInt();
	di.document_id = page.ItemAt(wxT("doc_doc")).AsInt();
	di.version_id = page.ItemAt(wxT("doc_version")).AsInt();

	return di;
}
Ejemplo n.º 10
0
RemoteProfile* eSettings::DoGetRemoteProfile(size_t profile_id)  {
	// Check if profile is already in cache
	for (auto_vector<RemoteProfile>::iterator p = m_tempRemotes.begin(); p != m_tempRemotes.end(); ++p) {
		if ((*p)->m_id == (int)profile_id) return *p;
	}

	// Get the profile
	const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
	wxASSERT((int)profile_id < remotes.Size());
	const wxJSONValue profile = remotes.ItemAt(profile_id);
	
	// Add profile to cache
	auto_ptr<RemoteProfile> rp(new RemoteProfile());
	rp->m_id = profile_id;
	rp->m_protocol = profile.ItemAt(wxT("protocol")).AsString();
	rp->m_name = profile.ItemAt(wxT("name")).AsString();
	rp->m_address = profile.ItemAt(wxT("address")).AsString();
	rp->m_dir = profile.ItemAt(wxT("dir")).AsString();
	rp->m_username = profile.ItemAt(wxT("username")).AsString();
	rp->m_pwd = profile.ItemAt(wxT("pwd")).AsString();
	m_tempRemotes.push_back(rp);

	return m_tempRemotes.back();
}
Ejemplo n.º 11
0
/*!
 This function is called for every value objects of DOUBLE type.
 This function uses the \n snprintf function to get the US-ASCII
 representation of the integer and simply copy it to the output stream.
 Returns -1 on stream errors or ZERO if no errors.

 Note that writing a double to a decimal ASCII representation could
 lay to unexpected results depending on the format string used in the
 conversion.
 See SetDoubleFmtString for details.
*/
int
wxJSONWriter::WriteDoubleValue( wxOutputStream& os, const wxJSONValue& value )
{
    int r = 0;

    char buffer[32];
    wxJSONRefData* data = value.GetRefData();
    wxASSERT( data );
    snprintf( buffer, 32, m_fmt, data->m_value.m_valDouble );
    size_t len = strlen( buffer );
    os.Write( buffer, len );
    if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
        r = -1;
    }
    return r;
}
Ejemplo n.º 12
0
/*!
 This function is called for every value objects of UINT type.
 This function uses the \n snprintf function to get the US-ASCII
 representation of the integer and simply copy it to the output stream.
 The function prepends a \b plus \b sign if the \c wxJSONWRITER_RECOGNIZE_UNSIGNED
 flag is set in the \c m_flags data member.
 Returns -1 on stream errors or ZERO if no errors.
*/
int
wxJSONWriter::WriteUIntValue( wxOutputStream& os, const wxJSONValue& value )
{
    int r = 0; size_t len;

    // prepend a plus sign if the style specifies that unsigned integers
    // have to be recognized by the JSON reader
    if ( m_style & wxJSONWRITER_RECOGNIZE_UNSIGNED )  {
        os.PutC( '+' );
    }

    char buffer[32];        // need to store 64-bits integers (max 20 digits)
    wxJSONRefData* data = value.GetRefData();
    wxASSERT( data );

#if defined( wxJSON_64BIT_INT )
    #if wxCHECK_VERSION(2, 9, 0 ) || !defined( wxJSON_USE_UNICODE )
        // this is fine for wxW 2.9 and for wxW 2.8 ANSI
        snprintf( buffer, 32, "%" wxLongLongFmtSpec "u",
                data->m_value.m_valUInt64 );
    #elif wxCHECK_VERSION(3, 0, 0) || !defined( wxJSON_USE_UNICODE )
        snprintf( buffer, 32, "%" wxLongLongFmtSpec "u",
             data->m_value.m_valUInt64 );
    #else
        // this is for wxW 2.8 Unicode: in order to use the cross-platform
        // format specifier, we use the wxString's sprintf() function and then
        // convert to UTF-8 before writing to the stream
        wxString s;
        s.Printf( _T("%") wxLongLongFmtSpec _T("u"),
                data->m_value.m_valInt64 );
        wxCharBuffer cb = s.ToUTF8();
        const char* cbData = cb.data();
        len = strlen( cbData );
        wxASSERT( len < 32 );
        memcpy( buffer, cbData, len );
        buffer[len] = 0;
    #endif
#else
    snprintf( buffer, 32, "%lu", data->m_value.m_valULong );
#endif
    len = strlen( buffer );
    os.Write( buffer, len );
    if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
        r = -1;
    }
    return r;
}
Ejemplo n.º 13
0
bool eSettings::GetSettingString(const wxString& name, wxString& value) const {
	if (!m_jsonRoot.HasMember(wxT("settings"))) return false;

	const wxJSONValue settings = m_jsonRoot.ItemAt(wxT("settings"));
	if (!settings.HasMember(name)) return false;

	const wxJSONValue val = settings.ItemAt(name);
	if (!val.IsString()) return false;

	value = val.AsString();
	return true;
}
Ejemplo n.º 14
0
/*!
 This function is called for every value objects of DOUBLE type.
 This function uses the \n snprintf function to get the US-ASCII
 representation of the integer and simply copy it to the output stream.
 Returns -1 on stream errors or ZERO if no errors.

 Note that writing a double to a decimal ASCII representation could
 lay to unexpected results depending on the format string used in the
 conversion.
 See SetDoubleFmtString for details.
*/
int
wxJSONWriter::WriteDoubleValue( wxOutputStream& os, const wxJSONValue& value )
{
    int r = 0;

    wxJSONRefData* data = value.GetRefData();
    wxASSERT( data );

    char* writeBuff = 0;
    // the buffer that has to be written is either UTF-8 or ANSI c_str() depending
    // on the 'm_noUtf8' flag
    wxCharBuffer utf8CB = wxString::FromCDouble(data->m_value.m_valDouble, 10).ToUTF8();        // the UTF-8 buffer
#if !defined(wxJSON_USE_UNICODE)
    wxCharBuffer ansiCB(str.c_str());        // the ANSI buffer    
    if (m_noUtf8)    
    {
        writeBuff = ansiCB.data();
    }
    else    
    {
        writeBuff = utf8CB.data();
    }
   #else
       writeBuff = utf8CB.data();
   #endif
        
    // NOTE: in ANSI builds UTF-8 conversion may fail (see samples/test5.cpp,
    // test 7.3) although I do not know why
    if (writeBuff == 0)    
    {
        const char* err = "<wxJSONWriter::WriteComment(): error converting the double to UTF-8>";
        os.Write(err, strlen(err));
        return 0;
    }
    size_t len = strlen(writeBuff);
    
    os.Write(writeBuff, len);
    if (os.GetLastError() != wxSTREAM_NO_ERROR)    
    {
        r = -1;
    }
    return r;
}
Ejemplo n.º 15
0
/*!
 This function is called for every value objects of BOOL type.
 This function prints the literals \b true or \b false depending on the
 value in \c value.
 Returns -1 on stream errors or ZERO if no errors.
*/
int
wxJSONWriter::WriteBoolValue( wxOutputStream& os, const wxJSONValue& value )
{
    int r = 0;
    const char* f = "false"; const char* t = "true";
    wxJSONRefData* data = value.GetRefData();
    wxASSERT( data );

    const char* c = f;    // defaults to FALSE

    if ( data->m_value.m_valBool )    {
        c = t;
    }

    size_t len = strlen( c );
    os.Write( c, len );
    if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
        r = -1;
    }
    return r;
}
Ejemplo n.º 16
0
static bool ODVersionNewerThan(int major, int minor, int patch)
{
    wxJSONValue jMsg;
    wxJSONWriter writer;
    wxString    MsgString;
    jMsg[wxS("Source")] = wxS("WEATHER_ROUTING_PI");
    jMsg[wxT("Type")] = wxT("Request");
    jMsg[wxT("Msg")] = wxS("Version");
    jMsg[wxT("MsgId")] = wxS("version");
    writer.Write( jMsg, MsgString );
    SendPluginMessage( wxS("OCPN_DRAW_PI"), MsgString );

    if(!g_ReceivedODVersionJSONMsg.Size())
        return false;
    if(g_ReceivedODVersionJSONMsg[wxS("Major")].AsInt() > major) return true;
    if(g_ReceivedODVersionJSONMsg[wxS("Major")].AsInt() == major &&
        g_ReceivedODVersionJSONMsg[wxS("Minor")].AsInt() > minor) return true;
    if(g_ReceivedODVersionJSONMsg[wxS("Major")].AsInt() == major &&
        g_ReceivedODVersionJSONMsg[wxS("Minor")].AsInt() == minor &&
        g_ReceivedODVersionJSONMsg[wxS("Patch")].AsInt() >= patch) return true;
    return false;
}
Ejemplo n.º 17
0
void eSettings::AddToRecent(const wxString& key, wxJSONValue& jsonArray, size_t max) {
	const wxJSONValue value(key);

	// Check if value is already in array
	int ndx = -1;
	for (int i = 0; i < jsonArray.Size(); ++i) {
		if (value.IsSameAs(jsonArray.ItemAt(i))) {
			ndx = i;
			break;
		}
	}

	if (ndx == 0) return; // No need to do anything if path is already top
	
	if (ndx > 0) jsonArray.Remove(ndx); // remove duplicate entry

	// Insert value at top
	jsonArray.Insert(0, value);

	// Make sure we have no more than max entries
	if (jsonArray.Size() > (int)max) jsonArray.Remove(max);
}
Ejemplo n.º 18
0
size_t eSettings::GetSearchCount() const {
	if (!m_jsonRoot.HasMember(wxT("searchHistory"))) return 0;

	const wxJSONValue searches = m_jsonRoot.ItemAt(wxT("searchHistory"));
	return searches.Size();
}
Ejemplo n.º 19
0
/*!
 This is a recursive function that gets the type of the \c value object and
 calls several protected functions depending on the type:

 \li \c WriteNullvalue for type NULL
 \li \c WriteStringValue() for STRING and CSTRING types
 \li \c WriteIntValue for INT types
 \li \c WriteUIntValue for UINT types
 \li \c WriteBoolValue for BOOL types
 \li \c WriteDoubleValue for DOUBLE types
 \li \c WriteMemoryBuff for MEMORYBUFF types

 If the value is an array or key/value map (types ARRAY and OBJECT), the function
 iterates through all JSON value object in the array/map and calls itself for every
 item in the container.
*/
int
wxJSONWriter::DoWrite( wxOutputStream& os, const wxJSONValue& value, const wxString* key, bool comma )
{
    // note that this function is recursive

    // some variables that cannot be allocated in the switch statement
    const wxJSONInternalMap* map = 0;
    int size;
    m_colNo = 1; m_lineNo = 1;
    // determine the comment position; it is one of:
    //
    //  wxJSONVALUE_COMMENT_BEFORE
    //  wxJSONVALUE_COMMENT_AFTER
    //  wxJSONVALUE_COMMENT_INLINE
    //
    // or -1 if comments have not to be written
    int commentPos = -1;
    if ( value.GetCommentCount() > 0 && (m_style & wxJSONWRITER_WRITE_COMMENTS))  {
        commentPos = value.GetCommentPos();
        if ( ( m_style & wxJSONWRITER_COMMENTS_BEFORE) != 0 ) {
            commentPos = wxJSONVALUE_COMMENT_BEFORE;
        }
        else if ( (m_style & wxJSONWRITER_COMMENTS_AFTER) != 0 ) {
            commentPos = wxJSONVALUE_COMMENT_AFTER;
        }
    }

    int lastChar = 0;  // check if WriteComment() writes the last LF char

    // first write the comment if it is BEFORE
    if ( commentPos == wxJSONVALUE_COMMENT_BEFORE )   {
        lastChar = WriteComment( os, value, true );
        if ( lastChar < 0 )   {
            return lastChar;
        }
        else if ( lastChar != '\n' )  {
            WriteSeparator( os );
        }
    }

    lastChar = WriteIndent( os );
    if ( lastChar < 0 )   {
        return lastChar;
    }

    // now write the key if it is not NULL
    if ( key )   {
        lastChar = WriteKey( os, *key );
    }
    if ( lastChar < 0 )   {
        return lastChar;
    }

    // now write the value
    wxJSONInternalMap::const_iterator it;    // declare the map object
    long int count = 0;

    wxJSONType t = value.GetType();
    switch ( t )  {
    case wxJSONTYPE_INVALID :
        WriteInvalid( os );
        wxFAIL_MSG( _T("wxJSONWriter::WriteEmpty() cannot be called (not a valid JSON text"));
        break;

    case wxJSONTYPE_INT :
    case wxJSONTYPE_SHORT :
    case wxJSONTYPE_LONG :
    case wxJSONTYPE_INT64 :
        lastChar = WriteIntValue( os, value );
        break;

    case wxJSONTYPE_UINT :
    case wxJSONTYPE_USHORT :
    case wxJSONTYPE_ULONG :
    case wxJSONTYPE_UINT64 :
        lastChar = WriteUIntValue( os, value );
        break;

    case wxJSONTYPE_NULL :
        lastChar = WriteNullValue( os );
        break;
    case wxJSONTYPE_BOOL :
        lastChar = WriteBoolValue( os, value );
        break;

    case wxJSONTYPE_DOUBLE :
        lastChar = WriteDoubleValue( os, value );
        break;

    case wxJSONTYPE_STRING :
    case wxJSONTYPE_CSTRING :
        lastChar = WriteStringValue( os, value.AsString());
        break;

    case wxJSONTYPE_MEMORYBUFF :
        lastChar = WriteMemoryBuff( os, value.AsMemoryBuff());
        break;

    case wxJSONTYPE_ARRAY :
        ++m_level;
        os.PutC( '[' );
        // the inline comment for objects and arrays are printed in the open char
        if ( commentPos == wxJSONVALUE_COMMENT_INLINE )   {
            commentPos = -1;  // we have already written the comment
            lastChar = WriteComment( os, value, false );
            if ( lastChar < 0 )   {
                return lastChar;
            }
            if ( lastChar != '\n' )   {
                lastChar = WriteSeparator( os );
            }
        }
        else   {    // comment is not to be printed inline, so write a LF
            lastChar = WriteSeparator( os );
            if ( lastChar < 0 )   {
                return lastChar;
            }
        }

        // now iterate through all sub-items and call DoWrite() recursively
        size = value.Size();
        for ( int i = 0; i < size; i++ )  {
            bool comma = false;
            if ( i < size - 1 )  {
                comma = true;
            }
            wxJSONValue v = value.ItemAt( i );
            lastChar = DoWrite( os, v, 0, comma );
            if ( lastChar < 0 )  {
                return lastChar;
            }

        }
        --m_level;
        lastChar = WriteIndent( os );
        if ( lastChar < 0 )   {
            return lastChar;
        }
        os.PutC( ']' );
        break;

    case wxJSONTYPE_OBJECT :
        ++m_level;

        os.PutC( '{' );
        // the inline comment for objects and arrays are printed in the open char
        if ( commentPos == wxJSONVALUE_COMMENT_INLINE )   {
            commentPos = -1;  // we have already written the comment
            lastChar = WriteComment( os, value, false );
            if ( lastChar < 0 )   {
                return lastChar;
            }
            if ( lastChar != '\n' )   {
                WriteSeparator( os );
            }
        }
        else   {
            lastChar = WriteSeparator( os );
        }

        map = value.AsMap();
        size = value.Size();
        count = 0;
        for ( it = map->begin(); it != map->end(); ++it )  {
            // get the key and the value
            wxString key = it->first;
            const wxJSONValue& v = it->second;
            bool comma = false;
            if ( count < size - 1 )  {
                comma = true;
            }
            lastChar = DoWrite( os, v, &key, comma );
            if ( lastChar < 0 )  {
                return lastChar;
            }
            count++;
        }
        --m_level;
        lastChar = WriteIndent( os );
        if ( lastChar < 0 )   {
            return lastChar;
        }
        os.PutC( '}' );
        break;

    default :
        // a not yet defined wxJSONType: we FAIL
        wxFAIL_MSG( _T("wxJSONWriter::DoWrite() undefined wxJSONType type"));
        break;
    }

    // writes the comma character before the inline comment
    if ( comma )  {
        os.PutC( ',' );
    }

    if ( commentPos == wxJSONVALUE_COMMENT_INLINE )   {
        lastChar = WriteComment( os, value, false );
        if ( lastChar < 0 )   {
            return lastChar;
        }
    }
    else if ( commentPos == wxJSONVALUE_COMMENT_AFTER )   {
        WriteSeparator( os );
        lastChar = WriteComment( os, value, true );
        if ( lastChar < 0 )   {
            return lastChar;
        }
    }
    if ( lastChar != '\n' )  {
        lastChar = WriteSeparator( os );
    }
    return lastChar;
}
Ejemplo n.º 20
0
size_t eSettings::GetPageCount() const {
	if (!m_jsonRoot.HasMember(wxT("pages"))) return 0;

	const wxJSONValue pages = m_jsonRoot.ItemAt(wxT("pages"));
	return pages.Size();
}
Ejemplo n.º 21
0
void eSettings::GetRecents(const wxJSONValue& jarray, wxArrayString& recents) const {
	for (int i = 0; i < jarray.Size(); ++i) {
		recents.Add(jarray.ItemAt(i).AsString());
	}
}
Ejemplo n.º 22
0
size_t eSettings::GetRemoteProfileCount() const {
	if (!m_jsonRoot.HasMember(wxT("remoteProfiles"))) return 0;

	const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
	return remotes.Size();
}
Ejemplo n.º 23
0
void eSettings::GetPageSettings(size_t page_id, wxString& path, doc_id& di, int& pos, int& topline, wxString& syntax, vector<unsigned int>& folds, vector<unsigned int>& bookmarks) const {
	const wxJSONValue pages = m_jsonRoot.ItemAt(wxT("pages"));
	wxASSERT((int)page_id < pages.Size());
	const wxJSONValue page = pages.ItemAt(page_id);

	path = page.ItemAt(wxT("path")).AsString();
	pos = page.ItemAt(wxT("pos")).AsInt();
	topline = page.ItemAt(wxT("topline")).AsInt();
	syntax = page.ItemAt(wxT("syntax")).AsString();

	// doc_id
	di.type = (doc_type)page.ItemAt(wxT("doc_type")).AsInt();
	di.document_id = page.ItemAt(wxT("doc_doc")).AsInt();
	di.version_id = page.ItemAt(wxT("doc_version")).AsInt();

	// Set folds
	const wxJSONValue foldsArray = page.ItemAt(wxT("folds"));
	for (int f = 0; f < foldsArray.Size(); ++f) {
		folds.push_back(foldsArray.ItemAt(f).AsInt());
	}

	// Set bookmarks
	const wxJSONValue bookmarksArray = page.ItemAt(wxT("bookmarks"));
	for (int b = 0; b < bookmarksArray.Size(); ++b) {
		bookmarks.push_back(bookmarksArray.ItemAt(b).AsInt());
	}
}
Ejemplo n.º 24
0
wxString eSettings::GetFilterCommand(size_t ndx) const {
	const wxJSONValue values = m_jsonRoot.ItemAt(wxT("filterCommandHistory"));
	wxASSERT((int)ndx < values.Size());

	return values.ItemAt(ndx).AsString();
}
Ejemplo n.º 25
0
size_t eSettings::GetFilterCommandHistoryCount() const {
	if (!m_jsonRoot.HasMember(wxT("filterCommandHistory"))) return 0;

	const wxJSONValue values = m_jsonRoot.ItemAt(wxT("filterCommandHistory"));
	return values.Size();
}
Ejemplo n.º 26
0
const RemoteProfile* eSettings::GetRemoteProfileFromUrl(const wxString& url, bool withDir) {
	// Split url up in elements
	wxRegEx reUrl(wxT("([[:alpha:]]+)://(([^:@]*):([^:@]*)@)?([^/]+)(.*)"));
	if (!reUrl.Matches(url)) return NULL; // invalid url

	const wxString protocol = reUrl.GetMatch(url, 1);
	const wxString username = reUrl.GetMatch(url, 3);
	const wxString pwd = reUrl.GetMatch(url, 4);
	const wxString address = reUrl.GetMatch(url, 5);
	const wxString dir = reUrl.GetMatch(url, 6);
	const wxString sDir = StripSlashes(dir);

	// See if we can find a matching profile in cache
	for (auto_vector<RemoteProfile>::iterator p = m_tempRemotes.begin(); p != m_tempRemotes.end(); ++p) {
		RemoteProfile* rp = (*p);
		if (rp->IsActive() && rp->m_address == address && rp->m_protocol == protocol) {
			if (!username.empty() && rp->m_username != username) continue;
			if (withDir && StripSlashes(rp->m_dir) != sDir) continue;
			if (!pwd.empty() && rp->m_pwd != pwd) {
				rp->m_pwd = pwd; // Password may have changed
				if (!rp->IsTemp()) SaveRemoteProfile(rp);
			}
			return rp;
		}
	}

	// See if we can find a matching profile in settings
	const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
	const int profile_count = remotes.Size();
	for (int i = 0; i < profile_count; ++i) {
		const wxJSONValue profile = remotes.ItemAt(i);
		if (profile.ItemAt(wxT("address")).AsString() != address) continue;

		// Ftp is default protocol
		wxString prot = profile.ItemAt(wxT("protocol")).AsString();
		if (prot.empty()) prot = wxT("ftp");

		if (prot != protocol) continue; // ftp is default
		if (!username.empty() && profile.ItemAt(wxT("username")).AsString() != username) continue;

		RemoteProfile* rp = DoGetRemoteProfile(i);
		if (withDir && StripSlashes(rp->m_dir) != sDir) continue;

		// Password may have changed
		if (!pwd.empty() && rp->m_pwd != pwd) {
			rp->m_pwd = pwd;
			SaveRemoteProfile(rp);
		}

		return rp;
	}

	// Add new temp profile
	auto_ptr<RemoteProfile> newRp(new RemoteProfile());
	newRp->m_protocol = protocol;
	newRp->m_name = address;
	newRp->m_address = address;
	newRp->m_dir = dir;
	newRp->m_username = username;
	newRp->m_pwd = pwd;
	m_tempRemotes.push_back(newRp);
	return m_tempRemotes.back();
}
Ejemplo n.º 27
0
wxString eSettings::GetReplace(size_t ndx) const {
	const wxJSONValue replacements = m_jsonRoot.ItemAt(wxT("replaceHistory"));
	wxASSERT((int)ndx < replacements.Size());

	return replacements.ItemAt(ndx).AsString();
}
Ejemplo n.º 28
0
size_t eSettings::GetReplaceCount() const {
	if (!m_jsonRoot.HasMember(wxT("replaceHistory"))) return 0;

	const wxJSONValue replacements = m_jsonRoot.ItemAt(wxT("replaceHistory"));
	return replacements.Size();
}