From 3c7fe2b4436853052cda11a34b0dc3318ef96244 Mon Sep 17 00:00:00 2001
From: Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
Date: Mon, 10 Jan 2011 12:15:38 +0100
Subject: [PATCH] Info on not supported features

---
 pgadmin/agent/dlgJob.cpp    |   11 ++++-------
 pgadmin/db/pgConn.cpp       |   38 ++++++++++++++++++++++++++++++++++++++
 pgadmin/dlg/dlgDatabase.cpp |    6 +++---
 pgadmin/dlg/dlgTable.cpp    |    8 +++++++-
 pgadmin/include/db/pgConn.h |    6 ++++++
 5 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/pgadmin/agent/dlgJob.cpp b/pgadmin/agent/dlgJob.cpp
index 835c810..ed544e3 100644
--- a/pgadmin/agent/dlgJob.cpp
+++ b/pgadmin/agent/dlgJob.cpp
@@ -125,6 +125,7 @@ int dlgJob::Go(bool modal)
 {
 	int returncode;
 
+
 	pgSet *jcl = connection->ExecuteSet(wxT("SELECT jclname FROM pgagent.pga_jobclass"));
 	if (jcl)
 	{
@@ -135,7 +136,8 @@ int dlgJob::Go(bool modal)
 		}
 		delete jcl;
 	}
-	if(connection->pgAgentMinimumSchemaVersion(4)) 
+
+	if(connection->pgAgentMinimumSchemaVersion(4, txtEmailNotRecp) || connection->pgAgentMinimumSchemaVersion(4, cbEmailNotType)) 
 	{
 		pgSet *mnk = connection->ExecuteSet(wxT("SELECT jmntypename FROM pgagent.pga_jobmailnottype"));
 		if(mnk) 
@@ -148,12 +150,7 @@ int dlgJob::Go(bool modal)
 			delete mnk;
 		}
 				
-	}
-	else 
-	{
-		txtEmailNotRecp->Disable();
-		cbEmailNotType->Disable();
-	}
+	}	
 
 	if (job)
 	{
diff --git a/pgadmin/db/pgConn.cpp b/pgadmin/db/pgConn.cpp
index 86aa318..e4f6c17 100644
--- a/pgadmin/db/pgConn.cpp
+++ b/pgadmin/db/pgConn.cpp
@@ -379,6 +379,33 @@ bool pgConn::HasPrivilege(const wxString &objTyp, const wxString &objName, const
 	return StrToBool(res);
 }
 
+void pgConn::DisableControl(wxControl* control, wxString &versionInfo) 
+{
+
+	if(!control->IsShown())
+		return;
+	wxWindow *parent = control->GetParent();
+	if(parent) 
+	{		
+		wxStaticText *tb = new wxStaticText(parent, wxID_ANY, versionInfo);		
+		wxSizer *t = control->GetContainingSizer();
+		t->Replace(control, tb, true);	
+		control->Hide();		
+	}
+	else {
+		control->Disable();
+	}
+}
+
+bool pgConn::BackendMinimumVersion(int major, int minor, wxControl* control)
+{
+	if(!BackendMinimumVersion(major, minor)) {		
+		wxString versionInfo = wxString::Format(wxT("Supported in PostgreSQL %i.%i"), major, minor);
+		DisableControl(control, versionInfo);
+		return false;
+	}
+	return true;
+}
 
 
 
@@ -484,6 +511,17 @@ bool pgConn::HasFeature(int featureNo)
 	return features[featureNo];
 }
 
+bool pgConn::pgAgentMinimumSchemaVersion(const int version, wxControl* control) 
+{
+	if(!pgAgentMinimumSchemaVersion(version)) 
+	{
+		wxString versionInfo = wxString::Format(wxT("Supported in pgAgent Supported in pgAgent Supported in pgAgent Supported in pgAgent %i"), version);
+		DisableControl(control, versionInfo);
+		return false;
+	}
+	return true;
+}
+
 bool pgConn::pgAgentMinimumSchemaVersion(const int version) 
 {
 
diff --git a/pgadmin/dlg/dlgDatabase.cpp b/pgadmin/dlg/dlgDatabase.cpp
index 85f8c06..72b15c4 100644
--- a/pgadmin/dlg/dlgDatabase.cpp
+++ b/pgadmin/dlg/dlgDatabase.cpp
@@ -123,10 +123,10 @@ int dlgDatabase::Go(bool modal)
 	else
 		cbVarUsername->Enable(false);
 
-	if (connection->BackendMinimumVersion(8, 0))
+	if (connection->BackendMinimumVersion(9, 0, txtPath))
 	{
-		stPath->Hide();
-		txtPath->Hide();
+		//stPath->Hide();
+		//txtPath->Hide();
 	}
 	else
 	{
diff --git a/pgadmin/dlg/dlgTable.cpp b/pgadmin/dlg/dlgTable.cpp
index d57b819..2c07670 100644
--- a/pgadmin/dlg/dlgTable.cpp
+++ b/pgadmin/dlg/dlgTable.cpp
@@ -380,7 +380,13 @@ int dlgTable::Go(bool modal)
 		cbTablespace->SetSelection(0);
 	}
 
-	chkUnlogged->Enable(connection->BackendMinimumVersion(9, 1) && !table);
+	//chkUnlogged->Enable(connection->BackendMinimumVersion(9, 1) && !table);
+
+	if(!table)
+		connection->BackendMinimumVersion(9, 1, chkUnlogged);
+
+	
+
 	cbOfType->Enable(connection->BackendMinimumVersion(9, 0) && !table);
 	cbTables->Enable(connection->BackendMinimumVersion(8, 2) && cbOfType->GetCurrentSelection() == 0);
 
diff --git a/pgadmin/include/db/pgConn.h b/pgadmin/include/db/pgConn.h
index 72e8644..a125c57 100644
--- a/pgadmin/include/db/pgConn.h
+++ b/pgadmin/include/db/pgConn.h
@@ -90,6 +90,9 @@ public:
 	bool HasFeature(int feature = 0);
 	bool BackendMinimumVersion(int major, int minor);
 	bool BackendMinimumVersion(int major, int minor, int patch);
+	bool BackendMinimumVersion(int major, int minor, wxControl* control);
+	
+
 	bool EdbMinimumVersion(int major, int minor);
 	wxString SystemNamespaceRestriction(const wxString &nsp);
 	int GetMajorVersion() const
@@ -215,6 +218,7 @@ public:
 
 	bool TableHasColumn(wxString schemaname, wxString tblname, const wxString &colname);
 	bool pgAgentMinimumSchemaVersion(const int version);
+	bool pgAgentMinimumSchemaVersion(const int version, wxControl* control);
 	wxString CheckpgAgentMailFeature(const wxString host);
 
 protected:
@@ -238,6 +242,8 @@ protected:
 
 	friend class pgQueryThread;
 
+	void DisableControl(wxControl* control, wxString &versionInfo);
+
 private:
 	bool DoConnect();
 
-- 
1.7.3.1.msysgit.0
