Add json support for linux.

Добавлена поддержка json формата для Linux.
sysSetting поддерживает чтение/запись в файл расширенных настроек pgadmin3opt.json.
This commit is contained in:
lsv 2024-08-05 15:43:19 +05:00 committed by lsv
parent bebc9bee52
commit b0e9e1bf84
12 changed files with 100 additions and 36 deletions

View file

@ -31,7 +31,7 @@ enum
#if !defined(NO_WXJSON_GIT)
#if wxUSE_WEBREQUEST
ctlGitPanel::ctlGitPanel(wxWindow* parent, frmMain* form, wxJSONValue cf) :
wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
{
@ -1113,3 +1113,4 @@ void ctlGitPanel::OnNotebookPageChanged(wxBookCtrlEvent& event)
}
#endif
#endif

View file

@ -176,11 +176,13 @@ frmMain::frmMain(const wxString &title)
dependencies = new ctlListView(listViews, CTL_DEPVIEW, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER);
dependents = new ctlListView(listViews, CTL_REFVIEW, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER);
#if !defined(NO_WXJSON_GIT)
#if wxUSE_WEBREQUEST
git = NULL;
wxJSONValue cfg=ctlGitPanel::GetConfig();
if (!cfg.IsNull()) git = new ctlGitPanel(listViews, this,cfg);
#endif
#endif
// Switch back to the native list control.
@ -193,10 +195,11 @@ frmMain::frmMain(const wxString &title)
listViews->AddPage(dependencies, _("Dependencies")); // NBP_DEPENDENCIES
listViews->AddPage(dependents, _("Dependents")); // NBP_DEPENDENTS
#if !defined(NO_WXJSON_GIT)
#if wxUSE_WEBREQUEST
if (git) {
listViews->AddPage(git, _("Git")); //
}
#endif
#endif
properties->SetImageList(imageList, wxIMAGE_LIST_SMALL);
statistics->SetImageList(imageList, wxIMAGE_LIST_SMALL);
@ -879,14 +882,15 @@ void frmMain::ShowObjStatistics(pgObject *data, wxWindow *ctrl)
dependents->Thaw();
}
#if !defined(NO_WXJSON_GIT)
#if wxUSE_WEBREQUEST
if ((!ctrl && git && git->IsShownOnScreen()) || ctrl == git)
{
//data->ShowDependents(this, dependents);
if (git && data) git->ShowPage(data);
}
#endif
#endif
#endif
}

View file

@ -215,7 +215,9 @@ private:
ctlListView *statistics;
ctlListView *dependents, *dependencies;
#if !defined(NO_WXJSON_GIT)
#if wxUSE_WEBREQUEST
ctlGitPanel* git;
#endif
#endif
FunctionPGHelper hhelp;
ctlAuiNotebook *listViews;

View file

@ -7,8 +7,6 @@
// Copyright: (c) 2007 Luciano Cattani
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#if !defined(NO_WXJSON_GIT)
#ifndef _WX_JSON_DEFS_H_
#define _WX_JSON_DEFS_H_
@ -205,6 +203,3 @@
#endif // _WX_JSON_DEFS_H_
#endif

View file

@ -7,15 +7,13 @@
// Copyright: (c) 2007 Luciano Cattani
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#if !defined(NO_WXJSON_GIT)
#include "pgAdmin3.h"
#if !defined( _WX_JSONREADER_H )
#define _WX_JSONREADER_H
#ifdef __GNUG__
#pragma interface "jsonreader.h"
//#pragma interface "jsonreader.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
@ -145,5 +143,4 @@ protected:
#endif // not defined _WX_JSONREADER_H
#endif

View file

@ -7,13 +7,12 @@
// Copyright: (c) 2007 Luciano Cattani
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#if !defined(NO_WXJSON_GIT)
#if !defined( _WX_JSONVAL_H )
#define _WX_JSONVAL_H
#ifdef __GNUG__
#pragma interface "jsonval.h"
//#pragma interface "jsonval.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
@ -437,5 +436,4 @@ public:
#endif // not defined _WX_JSONVAL_H
#endif

View file

@ -7,7 +7,6 @@
// Copyright: (c) 2007 Luciano Cattani
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#if !defined(NO_WXJSON_GIT)
#include "pgAdmin3.h"
@ -16,7 +15,7 @@
#define _WX_JSONWRITER_H
#ifdef __GNUG__
#pragma interface "jsonwriter.h"
//#pragma interface "jsonwriter.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
@ -117,7 +116,6 @@ private:
#endif // not defined _WX_JSONWRITER_H
#endif

View file

@ -13,7 +13,7 @@
#define SYSSETTINGS_H
#include "utils/sysLogger.h"
#include "utils/json/jsonval.h"
// wxWindows headers
#include <wx/wx.h>
#include <wx/config.h>
@ -894,6 +894,10 @@ public:
bool WriteBool(const wxString &key, bool value);
bool WritePoint(const wxString &key, const wxPoint &value);
bool WriteSize(const wxString &key, const wxSize &value);
bool WriteJsonObect(const wxString& key, wxJSONValue& value);
bool WriteJsonFile();
bool ReloadJsonFileIfNeed();
bool ReadJsonObect(const wxString& key, wxJSONValue& value, wxJSONValue& defvalue);
bool WriteSizePoint(const wxString &key, const wxSize &size, const wxPoint &point)
{
WritePoint(key, point);
@ -934,6 +938,9 @@ private:
wxFileConfig *defaultSettings;
wxString appName;
wxJSONValue jsoncfg;
bool jsonchange = false;
wxDateTime jsonfilemod;
};
#endif

View file

@ -9,11 +9,11 @@
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "jsonreader.cpp"
//#pragma implementation "jsonreader.cpp"
#endif
#include "pgAdmin3.h"
#if !defined(NO_WXJSON_GIT)
#include <wx/mstream.h>
#include <wx/sstream.h>
@ -2127,6 +2127,3 @@ wxJSONReader::DoStrto_ll(const wxString& str, wxUint64* ui64, wxChar* sign)
}
*/
#endif

View file

@ -8,11 +8,11 @@
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "jsonval.cpp"
//#pragma implementation "jsonval.cpp"
#endif
#include "pgAdmin3.h"
#if !defined(NO_WXJSON_GIT)
// For compilers that support precompilation, includes "wx.h".
@ -3554,4 +3554,4 @@ wxJSONValue::operator = (wxUint64 ui)
}
*/
#endif

View file

@ -8,12 +8,11 @@
// Licence: wxWidgets licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "jsonwriter.cpp"
//#pragma implementation "jsonwriter.cpp"
#endif
#include "pgAdmin3.h"
#if !defined(NO_WXJSON_GIT)
#include <wx/sstream.h>
#include <wx/mstream.h>
@ -1271,7 +1270,3 @@ wxJSONWriter::IsPunctuation(wxChar ch)
}
*/
#endif

View file

@ -29,7 +29,10 @@
#include "utils/sysSettings.h"
#include "utils/sysLogger.h"
#include "utils/misc.h"
sysSettings::sysSettings(const wxString &name) : wxConfig(name)
#include "utils/json/jsonval.h"
#include "utils/json/jsonreader.h"
#include "utils/json/jsonwriter.h"
sysSettings::sysSettings(const wxString& name) : wxConfig(name)
{
appName = name;
// Open the default settings file
@ -39,7 +42,6 @@ sysSettings::sysSettings(const wxString &name) : wxConfig(name)
wxFileInputStream fst(settingsIni);
defaultSettings = new wxFileConfig(fst);
}
// Convert settings from pre-1.5
long i, serverCount;
Read(wxT("Servers/Count"), &serverCount, 0L);
@ -75,6 +77,7 @@ sysSettings::~sysSettings()
delete defaultSettings;
defaultSettings = NULL;
}
if (!jsoncfg.IsNull()) WriteJsonFile();
}
bool sysSettings::GetDisplayOption(const wxString &objtype, bool GetDefault)
@ -453,6 +456,73 @@ bool sysSettings::WriteSize(const wxString &key, const wxSize &value)
return rc;
}
// Write a json object
bool sysSettings::WriteJsonObect(const wxString& key, wxJSONValue& value)
{
//wxJSONValue d(wxJSONTYPE_OBJECT);
if (jsoncfg.IsNull()) jsoncfg.SetType(wxJSONTYPE_OBJECT);
jsoncfg[key] = value;
//value =jsoncfg.Get(key,d);
jsonchange = true;
return true;
}
bool sysSettings::ReloadJsonFileIfNeed() {
wxString path = wxStandardPaths::Get().GetUserConfigDir() + sepPath + "postgresql" + sepPath + "pgadmin3opt.json";
if (wxFileExists(path)) {
wxDateTime fmod = wxFileName(path).GetModificationTime();
if (!jsonfilemod.IsValid() || fmod != jsonfilemod) {
// load json file
wxFileInputStream input(path);
if (input.IsOk()) {
jsonchange = false;
wxJSONReader reader;
int errnum = reader.Parse(input, &jsoncfg);
if (errnum > 0) {
wxLogError("Parse json file %s errors. Number errors %d", path, errnum);
}
else {
jsonfilemod = fmod;
return true;
}
}
}
}
return false;
}
bool sysSettings::WriteJsonFile()
{
if (!jsoncfg.IsNull() && jsonchange) {
//wxString s = jsoncfg.Dump(true, 0);
{
wxString p = wxStandardPaths::Get().GetUserConfigDir() + sepPath + "postgresql" + sepPath + "pgadmin3opt.json";
{
wxFileOutputStream out(p);
if (out.IsOk()) {
wxJSONWriter writer(wxJSONWRITER_STYLED | wxJSONWRITER_WRITE_COMMENTS);
writer.Write(jsoncfg, out);
//writer.Write(jsoncfg, s);
out.Close();
jsonchange = false;
return true;
}
}
}
}
return false;
}
bool sysSettings::ReadJsonObect(const wxString& key, wxJSONValue& value, wxJSONValue& defvalue)
{
if (jsoncfg.IsNull()|| (!jsoncfg.HasMember(key))) {
value = defvalue;
WriteJsonObect(key, defvalue);
return true;
}
value=jsoncfg.Get(key,defvalue);
return true;
}
//////////////////////////////////////////////////////////////////////////
// Log