~ubuntu-branches/debian/squeeze/pgadmin3/squeeze

« back to all changes in this revision

Viewing changes to src/frm/frmPassword.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2008-02-07 00:56:22 UTC
  • mto: (2.1.6 hardy) (6.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080207005622-c2ail8p4d0sk3dnw
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// pgAdmin III - PostgreSQL Tools
4
 
// RCS-ID:      $Id: frmPassword.cpp 4874 2006-01-06 17:33:27Z dpage $
5
 
// Copyright (C) 2002 - 2006, The pgAdmin Development Team
6
 
// This software is released under the Artistic Licence
7
 
//
8
 
// frmPassword.cpp - Change password
9
 
//
10
 
//////////////////////////////////////////////////////////////////////////
11
 
 
12
 
// wxWindows headers
13
 
#include <wx/wx.h>
14
 
#include <wx/xrc/xmlres.h>
15
 
 
16
 
 
17
 
// App headers
18
 
#include "pgAdmin3.h"
19
 
#include "frmPassword.h"
20
 
#include "pgServer.h"
21
 
 
22
 
#include "images/connect.xpm"
23
 
 
24
 
#define txtCurrent      CTRL_TEXT("txtCurrent")
25
 
#define txtNew          CTRL_TEXT("txtNew")
26
 
#define txtConfirm      CTRL_TEXT("txtConfirm")
27
 
 
28
 
 
29
 
BEGIN_EVENT_TABLE(frmPassword, pgDialog)
30
 
    EVT_BUTTON (wxID_HELP,            frmPassword::OnHelp)
31
 
    EVT_BUTTON (wxID_OK,              frmPassword::OnOK)
32
 
    EVT_BUTTON (wxID_CANCEL,          frmPassword::OnCancel)
33
 
END_EVENT_TABLE()
34
 
 
35
 
 
36
 
frmPassword::frmPassword(wxFrame *parent, pgObject *obj)
37
 
{
38
 
    wxLogInfo(wxT("Creating a change password dialogue"));
39
 
 
40
 
    wxWindowBase::SetFont(settings->GetSystemFont());
41
 
    LoadResource(parent, wxT("frmPassword")); 
42
 
 
43
 
    server = obj->GetServer();
44
 
    // Icon
45
 
    SetIcon(wxIcon(connect_xpm));
46
 
    CenterOnParent();
47
 
}
48
 
 
49
 
frmPassword::~frmPassword()
50
 
{
51
 
    wxLogInfo(wxT("Destroying a change password dialogue"));
52
 
}
53
 
 
54
 
 
55
 
void frmPassword::OnHelp(wxCommandEvent &ev)
56
 
{
57
 
    DisplayHelp(this, wxT("password"));
58
 
}
59
 
 
60
 
 
61
 
void frmPassword::OnOK(wxCommandEvent& event)
62
 
{
63
 
 
64
 
    // Is the old password right?
65
 
    if (txtCurrent->GetValue() != server->GetPassword()) {
66
 
        wxLogError(__("Incorrect password!"));
67
 
        return;
68
 
    }
69
 
 
70
 
    // Did we confirm the password OK?
71
 
    if (txtNew->GetValue() != txtConfirm->GetValue()) {
72
 
        wxLogError(__("Passwords do not match!"));
73
 
        return;
74
 
    }
75
 
 
76
 
    // Set the new password
77
 
    if (!server->SetPassword(txtNew->GetValue()))
78
 
    {
79
 
        wxLogError(__("The password could not be changed!"));
80
 
        return;
81
 
    }
82
 
 
83
 
    // All must have gone well!
84
 
    wxLogMessage(__("Password successfully changed!"));
85
 
    this->Destroy();
86
 
}
87
 
 
88
 
 
89
 
void frmPassword::OnCancel(wxCommandEvent& event)
90
 
{
91
 
    Destroy();
92
 
}
93
 
 
94
 
 
95
 
passwordFactory::passwordFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : actionFactory(list)
96
 
{
97
 
    mnu->Append(id, _("C&hange password..."), _("Change your password."));
98
 
}
99
 
 
100
 
 
101
 
wxWindow *passwordFactory::StartDialog(frmMain *form, pgObject *obj)
102
 
{
103
 
    frmPassword *frm=new frmPassword((pgFrame*)form, obj);
104
 
    frm->Show();
105
 
    return 0;
106
 
}
107
 
 
108
 
 
109
 
bool passwordFactory::CheckEnable(pgObject *obj)
110
 
{
111
 
    if (obj)
112
 
    {
113
 
        pgServer *server = obj->GetServer();
114
 
        return server && server->GetConnected();
115
 
    }
116
 
    return false;
117
 
}