Re: A new feature patch and a bug fix - Mailing list pgadmin-hackers

From Guillaume Lelarge
Subject Re: A new feature patch and a bug fix
Date
Msg-id 47A83066.7010801@lelarge.info
Whole thread Raw
In response to Re: A new feature patch and a bug fix  ("Dave Page" <dpage@postgresql.org>)
Responses Re: A new feature patch and a bug fix
List pgadmin-hackers
Hi Dave,

Finally, I found some time to work on my patches :)

Dave Page wrote:
> On 22/12/2007, Guillaume Lelarge <guillaume@lelarge.info> wrote:
>> I've finally done it. It's the first time I create a new dialog, so it
>> probably need some tweaks. I attached the patch and a tar.gz file for
>> the new files.
>
> Finally, some feedback for you!!
>
> - In pgRole::ReassignDropOwnedTo, objets should be objects.
>

Oops, I used the french word.

> - In pgRole::ReassignDropOwnedTo an error should be raised if the
> connection cannot be opened.
>
> - The database selection in dlgReassignDropOwned should respect the DB
> restriction setting for the server.
>
> - Remember to append a 'd' to all size/position values in XRC files to
> denote cross-platform friendly dialog units.
>

All are done.

> - The dialog needs some work. Get yourself a copy of XRCed - it will
> help enormously. Try to keep the layout and sizing in line with other
> dialogues. Use sizers to keep everything in line rather than absolute
> positioning (new dialogues do this, older ones might not). It's a bit
> fiddly until you get the hang of them, but it does make things much
> easier to get right across platforms.
>

I'm not sure I get this right. It took me much more time than the four
previous stuff. XRCed is not really easy getting used to. So bad there's
no better (free) XRC editor out there. Anyways, I've done something I'm
quite happy with. But perhaps I need to add more sizers ?

Cheers.


--
Guillaume.
  http://www.postgresqlfr.org
  http://dalibo.com
Index: pgadmin/include/schema/pgRole.h
===================================================================
--- pgadmin/include/schema/pgRole.h    (révision 7050)
+++ pgadmin/include/schema/pgRole.h    (copie de travail)
@@ -75,8 +75,9 @@
     void iSetUpdateCatalog(const bool b) { updateCatalog=b; }
     wxArrayString& GetRolesIn() { return rolesIn; }
     wxArrayString& GetConfigList() { return configList; }
+
+    void ReassignDropOwnedTo(frmMain *form);

-
     // Tree object creation
     void ShowTreeDetail(ctlTree *browser, frmMain *form=0, ctlListView *properties=0, ctlSQLBox *sqlPane=0);
     void ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where);
@@ -112,6 +113,12 @@
     pgGroupRole(const wxString& newName = wxT(""));
 };

+class reassignDropOwnedFactory : public contextActionFactory
+{
+public:
+    reassignDropOwnedFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar);
+    wxWindow *StartDialog(frmMain *form, pgObject *obj);
+    bool CheckEnable(pgObject *obj);
+};

-
 #endif
Index: pgadmin/frm/frmMain.cpp
===================================================================
--- pgadmin/frm/frmMain.cpp    (révision 7050)
+++ pgadmin/frm/frmMain.cpp    (copie de travail)
@@ -67,6 +67,7 @@
 #include "schema/pgTable.h"
 #include "schema/pgIndex.h"
 #include "schema/pgTrigger.h"
+#include "schema/pgRole.h"
 #include "schema/pgRule.h"
 #include "schema/pgServer.h"
 #include "slony/slCluster.h"
@@ -326,6 +327,7 @@
     new dropCascadedFactory(menuFactories, editMenu, 0);
     new truncateFactory(menuFactories, editMenu, 0);
     new truncateCascadedFactory(menuFactories, editMenu, 0);
+    new reassignDropOwnedFactory(menuFactories, editMenu, 0);
     editMenu->AppendSeparator();

     new separatorFactory(menuFactories);
Index: pgadmin/schema/pgRole.cpp
===================================================================
--- pgadmin/schema/pgRole.cpp    (révision 7050)
+++ pgadmin/schema/pgRole.cpp    (copie de travail)
@@ -11,12 +11,15 @@

 // wxWindows headers
 #include <wx/wx.h>
+#include <wx/choicdlg.h>

 // App headers
 #include "pgAdmin3.h"
 #include "utils/misc.h"
 #include "schema/pgRole.h"
 #include "frm/frmMain.h"
+#include "dlg/dlgReassignDropOwned.h"
+#include "dlg/dlgSelectConnection.h"
 #include "utils/pgDefs.h"
 #include "schema/pgDatabase.h"
 #include "schema/pgTablespace.h"
@@ -51,7 +54,7 @@

 bool pgRole::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
 {
-    if (GetUpdateCatalog())
+    if (GetUpdateCatalog())
     {
         wxMessageDialog dlg(frame,
             _("Deleting a superuser might result in unwanted behaviour (e.g. when restoring the database).\nAre you
sure?"),
@@ -276,8 +279,47 @@
     }
 }

+void pgRole::ReassignDropOwnedTo(frmMain *form)
+{
+    wxString query;
+
+    dlgReassignDropOwned rdo(form, GetConnection(), this, GetServer()->GetDbRestriction());
+    if (rdo.ShowModal() != wxID_CANCEL)
+    {
+        pgConn *conn;
+        conn = new pgConn(GetConnection()->GetHost(),
+                     rdo.GetDatabase(),
+                     GetConnection()->GetUser(),
+                     GetConnection()->GetPassword(),
+                     GetConnection()->GetPort(),
+                     GetConnection()->GetSslMode());
+
+        if (conn->GetStatus() == PGCONN_OK)
+        {
+            if (rdo.IsReassign())
+            {
+                if (wxMessageBox(_("Are you sure you wish to reassign all objects owned by the selected role?"),
_("Reassignobjects"), wxYES_NO) == wxNO) 
+                    return;

+                query = wxT("REASSIGN OWNED BY ") + GetQuotedFullIdentifier() + wxT(" TO ") + rdo.GetRole();
+            }
+            else
+            {
+                if (wxMessageBox(_("Are you sure you wish to drop all objects owned by the selected role?"), _("Drop
objects"),wxYES_NO) == wxNO) 
+                    return;

+                query = wxT("DROP OWNED BY ") + GetQuotedFullIdentifier();
+            }
+            conn->ExecuteVoid(query);
+        }
+        else
+        {
+            wxMessageBox(wxT("Connection failed: ") + conn->GetLastError());
+        }
+    }
+}
+
+
 pgObject *pgRole::Refresh(ctlTree *browser, const wxTreeItemId item)
 {
     pgObject *role=0;
@@ -394,3 +436,22 @@

 pgGroupRoleFactory groupRoleFactory;
 static pgaCollectionFactory gcf(&groupRoleFactory, __("Group Roles"), roles_xpm);
+
+
+reassignDropOwnedFactory::reassignDropOwnedFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) :
contextActionFactory(list)
+{
+    mnu->Append(id, _("Reassign/Drop Owned..."), _("Reassigned or drop objects owned by the selected role."));
+}
+
+
+wxWindow *reassignDropOwnedFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+    ((pgRole*)obj)->ReassignDropOwnedTo(form);
+
+    return 0;
+}
+
+bool reassignDropOwnedFactory::CheckEnable(pgObject *obj)
+{
+    return obj && obj->IsCreatedBy(loginRoleFactory) && ((pgRole*)obj)->GetConnection()->BackendMinimumVersion(8, 2);
+}
Index: pgadmin/dlg/module.mk
===================================================================
--- pgadmin/dlg/module.mk    (révision 7050)
+++ pgadmin/dlg/module.mk    (copie de travail)
@@ -35,6 +35,7 @@
     $(srcdir)/dlg/dlgPackage.cpp \
     $(srcdir)/dlg/dlgPgpassConfig.cpp \
     $(srcdir)/dlg/dlgProperty.cpp \
+    $(srcdir)/dlg/dlgReassignDropOwned.cpp \
     $(srcdir)/dlg/dlgRole.cpp \
     $(srcdir)/dlg/dlgRule.cpp \
     $(srcdir)/dlg/dlgSchema.cpp \
Index: pgadmin/ui/module.mk
===================================================================
--- pgadmin/ui/module.mk    (révision 7050)
+++ pgadmin/ui/module.mk    (copie de travail)
@@ -39,6 +39,7 @@
     $(srcdir)/ui/dlgOperator.xrc \
     $(srcdir)/ui/dlgPackage.xrc \
     $(srcdir)/ui/dlgPgpassConfig.xrc \
+    $(srcdir)/ui/dlgReassignDropOwned.xrc \
     $(srcdir)/ui/dlgRepCluster.xrc \
     $(srcdir)/ui/dlgRepClusterUpgrade.xrc \
     $(srcdir)/ui/dlgRepListen.xrc \

Attachment

pgadmin-hackers by date:

Previous
From: svn@pgadmin.org
Date:
Subject: SVN Commit by dpage: r7050 - in trunk/pgadmin3: . pgadmin/debugger
Next
From: Guillaume Lelarge
Date:
Subject: Re: Fwd: Filter by Selection on Grid