Le 25/02/2011 00:48, Guillaume Lelarge a écrit :
> Le 24/02/2011 23:52, Dave Page a écrit :
>> On Thu, Feb 24, 2011 at 10:38 PM, Guillaume Lelarge
>> <[email protected]> wrote:
>>> Le 24/02/2011 21:08, Massa, Harald Armin a écrit :
>>>> [...]
>>>> is there any deep technical reason why pgAdmin does not support
>>>> connections via service-names corresponding to pg_service.conf, or is
>>>> it just sth in the level "nobody asked for it before / we did not get
>>>> around to do it" ?
>>>>
>>>
>>> The latter.
>>>
>>> I added a ticket to work on this once we'll have some time.
>>
>> Why? Nobody ever asked for it before, and there are 101 other things
>> that people have asked for that we haven't got to yet! Given the
>> current lack of interest, I don't think we should expend the time to
>> develop or the additional maintenance burden.
>>
> 
> I don't expect to work on this any time soon, but I don't want to forget
> about it. This would be an interesting feature.
> 

See attached path. Harald, if you can try it, it would be great.


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
>From 90b562f624432e60a45f179a5da428766592025e Mon Sep 17 00:00:00 2001
From: Guillaume Lelarge <[email protected]>
Date: Sat, 2 Apr 2011 15:52:18 +0200
Subject: [PATCH] Add support to pg_service connection type

---
 pgadmin/db/pgConn.cpp               |   24 +++++++++++----
 pgadmin/dlg/dlgSelectConnection.cpp |    4 +-
 pgadmin/dlg/dlgServer.cpp           |   24 ++++++++++----
 pgadmin/frm/frmMain.cpp             |    1 +
 pgadmin/frm/frmStatus.cpp           |    6 ++-
 pgadmin/include/db/pgConn.h         |    8 ++++-
 pgadmin/include/schema/pgServer.h   |   12 ++++++-
 pgadmin/pgscript/pgsApplication.cpp |    2 +-
 pgadmin/schema/pgRole.cpp           |    1 +
 pgadmin/schema/pgServer.cpp         |   57 +++++++++++++++++++++++-----------
 pgadmin/ui/dlgServer.xrc            |   20 ++++++++++--
 11 files changed, 114 insertions(+), 45 deletions(-)

diff --git a/pgadmin/db/pgConn.cpp b/pgadmin/db/pgConn.cpp
index 4bce7ad..7927828 100644
--- a/pgadmin/db/pgConn.cpp
+++ b/pgadmin/db/pgConn.cpp
@@ -49,13 +49,14 @@ static void pgNoticeProcessor(void *arg, const char *message)
 	((pgConn *)arg)->Notice(message);
 }
 
-pgConn::pgConn(const wxString &server, const wxString &database, const wxString &username, const wxString &password,
+pgConn::pgConn(const wxString &server, const wxString &service, const wxString &database, const wxString &username, const wxString &password,
                int port, const wxString &rolename, int sslmode, OID oid, const wxString &applicationname,
                const wxString &sslcert, const wxString &sslkey, const wxString &sslrootcert, const wxString &sslcrl)
 {
 	wxString msg;
 
 	save_server = server;
+	save_service = service;
 	save_database = database;
 	save_username = username;
 	save_password = password;
@@ -87,6 +88,11 @@ pgConn::pgConn(const wxString &server, const wxString &database, const wxString
 		connstr.Append(wxT(" host="));
 		connstr.Append(qtConnString(server));
 	}
+	if (!service.IsEmpty())
+	{
+		connstr.Append(wxT(" service="));
+		connstr.Append(qtConnString(service));
+	}
 	if (!database.IsEmpty())
 	{
 		connstr.Append(wxT(" dbname="));
@@ -330,7 +336,7 @@ bool pgConn::Reconnect()
 
 pgConn *pgConn::Duplicate()
 {
-	return new pgConn(wxString(save_server), wxString(save_database), wxString(save_username), wxString(save_password),
+	return new pgConn(wxString(save_server), wxString(save_service), wxString(save_database), wxString(save_username), wxString(save_password),
 	                  save_port, save_rolename, save_sslmode, save_oid,
 	                  save_applicationname, save_sslcert, save_sslkey, save_sslrootcert, save_sslcrl);
 }
@@ -582,10 +588,16 @@ void pgConn::ExamineLibpqVersion()
 wxString pgConn::GetName() const
 {
 	wxString str;
-	if (dbHost.IsEmpty())
-		str.Printf(_("%s on local socket"), save_database.c_str());
-	else
-		str.Printf(_("%s on %s@%s:%d"), save_database.c_str(), GetUser().c_str(), dbHost.c_str(), GetPort());
+    if (save_service.IsEmpty())
+    {
+        if (dbHost.IsEmpty())
+            str.Printf(_("%s on local socket"), save_database.c_str());
+        else
+            str.Printf(_("%s on %s@%s:%d"), save_database.c_str(), GetUser().c_str(), dbHost.c_str(), GetPort());
+    }
+    else
+        str.Printf(_("service %s"), save_service.c_str());
+    
 
 	if (!GetRole().IsEmpty())
 		str += wxT(" ~") + GetRole();
diff --git a/pgadmin/dlg/dlgSelectConnection.cpp b/pgadmin/dlg/dlgSelectConnection.cpp
index 0427f68..c4cdc0f 100644
--- a/pgadmin/dlg/dlgSelectConnection.cpp
+++ b/pgadmin/dlg/dlgSelectConnection.cpp
@@ -265,7 +265,7 @@ pgConn *dlgSelectConnection::CreateConn(wxString &applicationname, bool &created
 pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxString &username, int port, wxString &rolename, int sslmode, wxString &applicationname, bool writeMRU)
 {
 	pgConn *newconn;
-	newconn = new pgConn(server, dbname, username, wxT(""), port, rolename, sslmode, 0, applicationname);
+	newconn = new pgConn(server, wxEmptyString, dbname, username, wxT(""), port, rolename, sslmode, 0, applicationname);
 	if (newconn->GetStatus() != PGCONN_OK &&
 	        newconn->GetLastError().Cmp(wxString(PQnoPasswordSupplied, wxConvUTF8)) == 0)
 	{
@@ -279,7 +279,7 @@ pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxSt
 		if (dlg.Go() != wxID_OK)
 			return NULL;
 
-		newconn = new pgConn(server, dbname, username, dlg.GetPassword(), port, rolename, sslmode, 0, applicationname);
+		newconn = new pgConn(server, wxEmptyString, dbname, username, dlg.GetPassword(), port, rolename, sslmode, 0, applicationname);
 	}
 
 	if (newconn)
diff --git a/pgadmin/dlg/dlgServer.cpp b/pgadmin/dlg/dlgServer.cpp
index e80512c..c783d94 100644
--- a/pgadmin/dlg/dlgServer.cpp
+++ b/pgadmin/dlg/dlgServer.cpp
@@ -30,6 +30,7 @@
 // pointer to controls
 #define txtDescription    CTRL_TEXT("txtDescription")
 #define txtService        CTRL_TEXT("txtService")
+#define txtServiceID      CTRL_TEXT("txtServiceID")
 #define cbDatabase        CTRL_COMBOBOX("cbDatabase")
 #define txtPort           CTRL_TEXT("txtPort")
 #define cbSSL             CTRL_COMBOBOX("cbSSL")
@@ -56,6 +57,7 @@ BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
 	EVT_NOTEBOOK_PAGE_CHANGED(XRCID("nbNotebook"),     dlgServer::OnPageSelect)
 	EVT_TEXT(XRCID("txtDescription"),                  dlgProperty::OnChange)
 	EVT_TEXT(XRCID("txtService"),                      dlgProperty::OnChange)
+	EVT_TEXT(XRCID("txtServiceID"),                    dlgProperty::OnChange)
 	EVT_TEXT(XRCID("cbDatabase"),                      dlgProperty::OnChange)
 	EVT_COMBOBOX(XRCID("cbDatabase"),                  dlgProperty::OnChange)
 	EVT_TEXT(XRCID("txtPort")  ,                       dlgProperty::OnChange)
@@ -170,10 +172,11 @@ void dlgServer::OnOK(wxCommandEvent &ev)
 	{
 		server->iSetName(GetName());
 		server->iSetDescription(txtDescription->GetValue());
-		if (txtService->GetValue() != server->GetServiceID())
+        server->iSetService(txtService->GetValue());
+		if (txtServiceID->GetValue() != server->GetServiceID())
 		{
 			mainForm->StartMsg(_("Checking server status"));
-			server->iSetServiceID(txtService->GetValue());
+			server->iSetServiceID(txtServiceID->GetValue());
 			mainForm->EndMsg();
 		}
 		server->iSetPort(StrToLong(txtPort->GetValue()));
@@ -206,6 +209,7 @@ void dlgServer::OnOK(wxCommandEvent &ev)
 			pgServer *newserver = new pgServer(
 			    server->GetName(),
 			    server->GetDescription(),
+			    server->GetService(),
 			    server->GetDatabaseName(),
 			    server->GetUsername(),
 			    server->GetPort(),
@@ -373,7 +377,8 @@ int dlgServer::Go(bool modal)
 		if (cbDatabase->FindString(server->GetDatabaseName()) < 0)
 			cbDatabase->Append(server->GetDatabaseName());
 		txtDescription->SetValue(server->GetDescription());
-		txtService->SetValue(server->GetServiceID());
+		txtService->SetValue(server->GetService());
+		txtServiceID->SetValue(server->GetServiceID());
 		txtPort->SetValue(NumToStr((long)server->GetPort()));
 		cbSSL->SetSelection(server->GetSSL());
 		cbDatabase->SetValue(server->GetDatabaseName());
@@ -396,6 +401,7 @@ int dlgServer::Go(bool modal)
 		{
 			txtDescription->Disable();
 			txtService->Disable();
+			txtServiceID->Disable();
 			txtName->Disable();
 			cbDatabase->Disable();
 			txtPort->Disable();
@@ -438,7 +444,7 @@ pgObject *dlgServer::CreateObject(pgCollection *collection)
 {
 	wxString name = GetName();
 
-	pgServer *obj = new pgServer(GetName(), txtDescription->GetValue(), cbDatabase->GetValue(),
+	pgServer *obj = new pgServer(GetName(), txtDescription->GetValue(), txtService->GetValue(), cbDatabase->GetValue(),
 	                             txtUsername->GetValue(), StrToLong(txtPort->GetValue()),
 	                             chkTryConnect->GetValue() && chkStorePwd->GetValue(),
 	                             txtRolename->GetValue(), chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
@@ -477,7 +483,8 @@ void dlgServer::CheckChange()
 
 		enable =  name != server->GetName()
 		          || txtDescription->GetValue() != server->GetDescription()
-		          || txtService->GetValue() != server->GetServiceID()
+		          || txtService->GetValue() != server->GetService()
+		          || txtServiceID->GetValue() != server->GetServiceID()
 		          || StrToLong(txtPort->GetValue()) != server->GetPort()
 		          || cbDatabase->GetValue() != server->GetDatabaseName()
 		          || txtUsername->GetValue() != server->GetUsername()
@@ -501,8 +508,11 @@ void dlgServer::CheckChange()
 	cbSSL->Enable(!isPipe && !connection);
 #endif
 	CheckValid(enable, !txtDescription->GetValue().IsEmpty(), _("Please specify description."));
-	CheckValid(enable, StrToLong(txtPort->GetValue()) > 0, _("Please specify port."));
-	CheckValid(enable, !txtUsername->GetValue().IsEmpty(), _("Please specify user name"));
+    if (txtService->GetValue().IsEmpty())
+    {
+        CheckValid(enable, StrToLong(txtPort->GetValue()) > 0, _("Please specify port."));
+        CheckValid(enable, !txtUsername->GetValue().IsEmpty(), _("Please specify user name"));
+    }
 	CheckValid(enable, dbRestrictionOk, _("Restriction not valid."));
 
 	EnableOK(enable && !connection);
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index ea58697..7b2b61c 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -1109,6 +1109,7 @@ void frmMain::StoreServers()
 					key.Printf(wxT("Servers/%d/"), numServers);
 					settings->Write(key + wxT("Server"), server->GetName());
 					settings->Write(key + wxT("Description"), server->GetDescription());
+					settings->Write(key + wxT("Service"), server->GetService());
 					settings->Write(key + wxT("ServiceID"), server->GetServiceID());
 					settings->Write(key + wxT("DiscoveryID"), server->GetDiscoveryID());
 					settings->WriteInt(key + wxT("Port"), server->GetPort());
diff --git a/pgadmin/frm/frmStatus.cpp b/pgadmin/frm/frmStatus.cpp
index 22c6db3..137372c 100644
--- a/pgadmin/frm/frmStatus.cpp
+++ b/pgadmin/frm/frmStatus.cpp
@@ -480,7 +480,7 @@ void frmStatus::OnChangeDatabase(wxCommandEvent &ev)
 		delete locks_connection;
 	}
 
-	locks_connection = new pgConn(connection->GetHostName(), cbDatabase->GetValue(),
+	locks_connection = new pgConn(connection->GetHostName(), connection->GetService(), cbDatabase->GetValue(),
 	                              connection->GetUser(), connection->GetPassword(), connection->GetPort(), connection->GetRole(), connection->GetSslMode(),
 	                              0, connection->GetApplicationName(), connection->GetSSLCert(), connection->GetSSLKey(), connection->GetSSLRootCert(), connection->GetSSLCrl());
 
@@ -989,7 +989,7 @@ void frmStatus::OnCopyQuery(wxCommandEvent &ev)
 	if (text.Length() > 0 && dbname.Length() > 0
 	        && text.Trim() != wxT("<IDLE>") && text.Trim() != wxT("<IDLE in transaction>"))
 	{
-		pgConn *conn = new pgConn(connection->GetHostName(), dbname,
+		pgConn *conn = new pgConn(connection->GetHostName(), connection->GetService(), dbname,
 		                          connection->GetUser(), connection->GetPassword(),
 		                          connection->GetPort(), connection->GetRole(), connection->GetSslMode(), connection->GetDbOid(),
 		                          connection->GetApplicationName(),
@@ -2597,6 +2597,7 @@ void frmStatus::OnCommit(wxCommandEvent &event)
 		if (connection->GetDbname() != xactList->GetText(item, 4))
 		{
 			pgConn *tmpConn = new pgConn(connection->GetHost(),
+			                             connection->GetService(),
 			                             xactList->GetText(item, 4),
 			                             connection->GetUser(),
 			                             connection->GetPassword(),
@@ -2652,6 +2653,7 @@ void frmStatus::OnRollback(wxCommandEvent &event)
 		if (connection->GetDbname() != xactList->GetText(item, 4))
 		{
 			pgConn *tmpConn = new pgConn(connection->GetHost(),
+			                             connection->GetService(),
 			                             xactList->GetText(item, 4),
 			                             connection->GetUser(),
 			                             connection->GetPassword(),
diff --git a/pgadmin/include/db/pgConn.h b/pgadmin/include/db/pgConn.h
index 402357a..cc510cb 100644
--- a/pgadmin/include/db/pgConn.h
+++ b/pgadmin/include/db/pgConn.h
@@ -83,7 +83,7 @@ typedef struct pgError
 class pgConn
 {
 public:
-	pgConn(const wxString &server = wxT(""), const wxString &database = wxT(""), const wxString &username = wxT(""), const wxString &password = wxT(""),
+	pgConn(const wxString &server = wxT(""), const wxString &service = wxT(""), const wxString &database = wxT(""), const wxString &username = wxT(""), const wxString &password = wxT(""),
 	       int port = 5432, const wxString &rolename = wxT(""), int sslmode = 0, OID oid = 0,
 	       const wxString &applicationname = wxT("pgAdmin"),
 	       const wxString &sslcert = wxT(""), const wxString &sslkey = wxT(""), const wxString &sslrootcert = wxT(""), const wxString &sslcrl = wxT(""));
@@ -125,6 +125,10 @@ public:
 	bool ExecuteVoid(const wxString &sql, bool reportError = true);
 	wxString ExecuteScalar(const wxString &sql);
 	pgSet *ExecuteSet(const wxString &sql);
+	wxString GetService() const
+	{
+		return save_service;
+	}
 	wxString GetUser() const
 	{
 		return wxString(PQuser(conn), *conv);
@@ -268,7 +272,7 @@ private:
 	wxString reservedNamespaces;
 	wxString connstr;
 
-	wxString save_server, save_database, save_username, save_password, save_rolename, save_applicationname;
+	wxString save_server, save_service, save_database, save_username, save_password, save_rolename, save_applicationname;
 	wxString save_sslcert, save_sslkey, save_sslrootcert, save_sslcrl;
 	int save_port, save_sslmode;
 	OID save_oid;
diff --git a/pgadmin/include/schema/pgServer.h b/pgadmin/include/schema/pgServer.h
index 27bfbdf..883ccdb 100644
--- a/pgadmin/include/schema/pgServer.h
+++ b/pgadmin/include/schema/pgServer.h
@@ -41,7 +41,7 @@ extern pgServerFactory serverFactory;
 class pgServer : public pgObject
 {
 public:
-	pgServer(const wxString &newServer = wxT(""), const wxString &newDescription = wxT(""), const wxString &newDatabase = wxT(""), const wxString &newUsername = wxT(""), int newPort = 5432, bool storePwd = false, const wxString &newRolename = wxT(""), bool restore = true, int sslMode = 0, const wxString &colour = wxT("#FFFFFF"), const wxString &group = wxEmptyString);
+	pgServer(const wxString &newServer = wxT(""), const wxString &newDescription = wxT(""), const wxString &newService = wxT(""), const wxString &newDatabase = wxT(""), const wxString &newUsername = wxT(""), int newPort = 5432, bool storePwd = false, const wxString &newRolename = wxT(""), bool restore = true, int sslMode = 0, const wxString &colour = wxT("#FFFFFF"), const wxString &group = wxEmptyString);
 	~pgServer();
 	int GetIconId();
 
@@ -75,6 +75,10 @@ public:
 	wxString GetVersionString();
 	wxString GetVersionNumber();
 	OID GetLastSystemOID();
+	wxString GetService() const
+	{
+		return service;
+	}
 	wxString GetDatabaseName() const
 	{
 		return database;
@@ -255,6 +259,10 @@ public:
 	{
 		return connected;
 	}
+	void iSetService(const wxString &newVal)
+	{
+		service = newVal;
+	}
 	void iSetDatabase(const wxString &newVal)
 	{
 		database = newVal;
@@ -417,7 +425,7 @@ private:
 	pgConn *conn;
 	long serverIndex;
 	bool connected, passwordValid, autovacuumRunning;
-	wxString database, username, password, rolename, ver, error;
+	wxString service, database, username, password, rolename, ver, error;
 	wxString lastDatabase, lastSchema, description, serviceId, discoveryId;
 	wxDateTime upSince;
 	int port, ssl;
diff --git a/pgadmin/pgscript/pgsApplication.cpp b/pgadmin/pgscript/pgsApplication.cpp
index 79a4168..f5dcfe8 100644
--- a/pgadmin/pgscript/pgsApplication.cpp
+++ b/pgadmin/pgscript/pgsApplication.cpp
@@ -19,7 +19,7 @@
 
 pgsApplication::pgsApplication(const wxString &host, const wxString &database,
                                const wxString &user, const wxString &password, int port) :
-	m_mutex(1, 1), m_stream(1, 1), m_connection(pnew pgConn(host, database, user,
+	m_mutex(1, 1), m_stream(1, 1), m_connection(pnew pgConn(host, wxEmptyString, database, user,
 	        password, port)), m_defined_conn(true), m_thread(0), m_caller(0)
 {
 	if (m_connection->GetStatus() != PGCONN_OK)
diff --git a/pgadmin/schema/pgRole.cpp b/pgadmin/schema/pgRole.cpp
index d7d1b8f..0686b42 100644
--- a/pgadmin/schema/pgRole.cpp
+++ b/pgadmin/schema/pgRole.cpp
@@ -434,6 +434,7 @@ void pgRole::ReassignDropOwnedTo(frmMain *form)
 	{
 		pgConn *conn;
 		conn = new pgConn(GetConnection()->GetHost(),
+		                  GetConnection()->GetService(),
 		                  rdo.GetDatabase(),
 		                  GetConnection()->GetUser(),
 		                  GetConnection()->GetPassword(),
diff --git a/pgadmin/schema/pgServer.cpp b/pgadmin/schema/pgServer.cpp
index 111a78a..b13b644 100644
--- a/pgadmin/schema/pgServer.cpp
+++ b/pgadmin/schema/pgServer.cpp
@@ -40,10 +40,11 @@
 
 #define DEFAULT_PG_DATABASE wxT("postgres")
 
-pgServer::pgServer(const wxString &newName, const wxString &newDescription, const wxString &newDatabase, const wxString &newUsername, int newPort, bool _storePwd, const wxString &newRolename, bool _restore, int _ssl, const wxString &_colour, const wxString &_group)
+pgServer::pgServer(const wxString &newName, const wxString &newDescription, const wxString &newService, const wxString &newDatabase, const wxString &newUsername, int newPort, bool _storePwd, const wxString &newRolename, bool _restore, int _ssl, const wxString &_colour, const wxString &_group)
 	: pgObject(serverFactory, newName)
 {
 	description = newDescription;
+	service = newService;
 	database = newDatabase;
 	username = newUsername;
 	port = newPort;
@@ -186,7 +187,7 @@ pgConn *pgServer::CreateConn(wxString dbName, OID oid, wxString applicationname)
 		dbName = GetDatabaseName();
 		oid = dbOid;
 	}
-	pgConn *conn = new pgConn(GetName(), dbName, username, password, port, rolename, ssl, oid, applicationname, sslcert, sslkey, sslrootcert, sslcrl);
+	pgConn *conn = new pgConn(GetName(), service, dbName, username, password, port, rolename, ssl, oid, applicationname, sslcert, sslkey, sslrootcert, sslcrl);
 
 	if (conn && conn->GetStatus() != PGCONN_OK)
 	{
@@ -663,21 +664,21 @@ int pgServer::Connect(frmMain *form, bool askPassword, const wxString &pwd, bool
 
 		if (database.IsEmpty())
 		{
-			conn = new pgConn(GetName(), DEFAULT_PG_DATABASE, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
+			conn = new pgConn(GetName(), service, DEFAULT_PG_DATABASE, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
 			if (conn->GetStatus() == PGCONN_OK)
 				database = DEFAULT_PG_DATABASE;
 			else if (conn->GetStatus() == PGCONN_BAD && conn->GetLastError().Find(
 			             wxT("database \"") DEFAULT_PG_DATABASE wxT("\" does not exist")) >= 0)
 			{
 				delete conn;
-				conn = new pgConn(GetName(), wxT("template1"), username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
+				conn = new pgConn(GetName(), service, wxT("template1"), username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
 				if (conn && conn->GetStatus() == PGCONN_OK)
 					database = wxT("template1");
 			}
 		}
 		else
 		{
-			conn = new pgConn(GetName(), database, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
+			conn = new pgConn(GetName(), service, database, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
 			if (!conn)
 			{
 				form->EndMsg(false);
@@ -801,12 +802,17 @@ int pgServer::Connect(frmMain *form, bool askPassword, const wxString &pwd, bool
 wxString pgServer::GetIdentifier() const
 {
 	wxString idstr;
-	if (GetName().IsEmpty())
-		idstr.Printf(wxT("local:.s.PGSQL.%d"), port);
-	else if (GetName().StartsWith(wxT("/")))
-		idstr.Printf(wxT("local:%s/.s.PGSQL.%d"), GetName().c_str(), port);
-	else
-		idstr.Printf(wxT("%s:%d"), GetName().c_str(), port);
+    if (GetService().IsEmpty())
+    {
+        if (GetName().IsEmpty())
+            idstr.Printf(wxT("local:.s.PGSQL.%d"), port);
+        else if (GetName().StartsWith(wxT("/")))
+            idstr.Printf(wxT("local:%s/.s.PGSQL.%d"), GetName().c_str(), port);
+        else
+            idstr.Printf(wxT("%s:%d"), GetName().c_str(), port);
+    }
+    else
+        idstr.Printf(_("service %s"), GetService().c_str());
 	return idstr;
 }
 
@@ -977,15 +983,26 @@ void pgServer::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *prop
 		// Display the Server properties
 
 		properties->AppendItem(_("Description"), GetDescription());
+		properties->AppendItem(_("Service"), GetService());
 		if (GetName().IsEmpty() || GetName().StartsWith(wxT("/")))
 		{
-			properties->AppendItem(_("Hostname"), wxT("local:") + GetName());
-			properties->AppendItem(_("Port"), (long)GetPort());
+            if (GetName().IsEmpty() && !GetService().IsEmpty())
+                properties->AppendItem(_("Hostname"), wxEmptyString);
+            else
+                properties->AppendItem(_("Hostname"), wxT("local:") + GetName());
+
+            if (GetPort() == 0 && !GetService().IsEmpty())
+                properties->AppendItem(_("Port"), wxEmptyString);
+            else
+                properties->AppendItem(_("Port"), (long)GetPort());
 		}
 		else
 		{
 			properties->AppendItem(_("Hostname"), GetName());
-			properties->AppendItem(_("Port"), (long)GetPort());
+            if (GetPort() == 0 && !GetService().IsEmpty())
+                properties->AppendItem(_("Port"), wxEmptyString);
+            else
+                properties->AppendItem(_("Port"), (long)GetPort());
 #ifdef SSL
 			if (GetConnected())
 			{
@@ -1028,7 +1045,7 @@ void pgServer::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *prop
 #endif
 		}
 		if (!serviceId.IsEmpty())
-			properties->AppendItem(_("Service"), serviceId);
+			properties->AppendItem(_("Service ID"), serviceId);
 
 		properties->AppendItem(_("Maintenance database"), GetDatabaseName());
 		properties->AppendItem(_("Username"), GetUsername());
@@ -1265,7 +1282,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 	long numServers = settings->Read(wxT("Servers/Count"), 0L);
 
 	long loop, port, ssl = 0;
-	wxString key, servername, description, database, username, lastDatabase, lastSchema;
+	wxString key, servername, description, service, database, username, lastDatabase, lastSchema;
 	wxString storePwd, rolename, restore, serviceID, discoveryID, dbRestriction, colour;
 	wxString group, sslcert, sslkey, sslrootcert, sslcrl;
 	pgServer *server = 0;
@@ -1285,6 +1302,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 		key.Printf(wxT("Servers/%d/"), loop);
 
 		settings->Read(key + wxT("Server"), &servername, wxEmptyString);
+		settings->Read(key + wxT("Service"), &service, wxEmptyString);
 		settings->Read(key + wxT("ServiceID"), &serviceID, wxEmptyString);
 		settings->Read(key + wxT("DiscoveryID"), &discoveryID, serviceID);
 		settings->Read(key + wxT("Description"), &description, wxEmptyString);
@@ -1337,9 +1355,10 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 		}
 
 		// Add the Server node
-		server = new pgServer(servername, description, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl);
+		server = new pgServer(servername, description, service, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl);
 		server->iSetLastDatabase(lastDatabase);
 		server->iSetLastSchema(lastSchema);
+		server->iSetService(service);
 		server->iSetServiceID(serviceID);
 		server->iSetDiscoveryID(discoveryID);
 		server->iSetDiscovered(false);
@@ -1514,7 +1533,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 					// Add the item, if it looks sane
 					if (port != 0 && username != wxEmptyString)
 					{
-						server = new pgServer(servername, description, wxT("postgres"), username, port, false, rolename, 0);
+						server = new pgServer(servername, description, wxEmptyString, wxT("postgres"), username, port, false, rolename, 0);
 						server->iSetDiscoveryID(cnf->GetPath() + wxT("/") + version);
 						server->iSetDiscovered(true);
 						server->iSetGroup(group);
@@ -1567,7 +1586,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 					// Add the item, if it looks sane
 					if (port != 0 && username != wxEmptyString)
 					{
-						server = new pgServer(servername, description, wxT("edb"), username, port, false, rolename, 0);
+						server = new pgServer(servername, description, wxEmptyString, wxT("edb"), username, port, false, rolename, 0);
 						server->iSetDiscoveryID(cnf->GetPath() + wxT("/") + version);
 						server->iSetDiscovered(true);
 						browser->AppendItem(browser->GetFirstChild(obj->GetId(), groupcookie), server->GetFullName(), server->GetIconId(), -1, server);
diff --git a/pgadmin/ui/dlgServer.xrc b/pgadmin/ui/dlgServer.xrc
index c8632f2..ee01f98 100644
--- a/pgadmin/ui/dlgServer.xrc
+++ b/pgadmin/ui/dlgServer.xrc
@@ -17,7 +17,7 @@
             <object class="wxPanel" name="pnlProperties">
               <object class="wxFlexGridSizer">
                 <cols>2</cols>
-                <rows>9</rows>
+                <rows>10</rows>
                 <vgap>5</vgap>
                 <hgap>5</hgap>
                 <growablecols>1</growablecols>
@@ -34,6 +34,18 @@
                   <border>4</border>
                 </object>
                 <object class="sizeritem">
+                  <object class="wxStaticText" name="stService">
+                    <label>Service</label>
+                  </object>
+                  <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxTextCtrl" name="txtService"/>
+                  <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
                   <object class="wxStaticText" name="stName">
                     <label>Host</label>
                   </object>
@@ -296,14 +308,14 @@
                   <border>4</border>
                 </object>
                 <object class="sizeritem">
-                  <object class="wxStaticText" name="stService">
-                    <label>Service</label>
+                  <object class="wxStaticText" name="stServiceID">
+                    <label>Service ID</label>
                   </object>
                   <flag>wxALIGN_CENTRE_VERTICAL|wxALL</flag>
                   <border>4</border>
                 </object>
                 <object class="sizeritem">
-                  <object class="wxTextCtrl" name="txtService"/>
+                  <object class="wxTextCtrl" name="txtServiceID"/>
                   <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
                   <border>4</border>
                 </object>
-- 
1.7.1

-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to