~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to tocurrent.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****
2
 
*
3
 
* TOra - An Oracle Toolkit for DBA's and developers
4
 
* Copyright (C) 2003-2005 Quest Software, Inc
5
 
* Portions Copyright (C) 2005 Other Contributors
6
 
7
 
* This program is free software; you can redistribute it and/or
8
 
* modify it under the terms of the GNU General Public License
9
 
* as published by the Free Software Foundation;  only version 2 of
10
 
* the License is valid for this program.
11
 
12
 
* This program is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
* GNU General Public License for more details.
16
 
17
 
* You should have received a copy of the GNU General Public License
18
 
* along with this program; if not, write to the Free Software
19
 
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*
21
 
*      As a special exception, you have permission to link this program
22
 
*      with the Oracle Client libraries and distribute executables, as long
23
 
*      as you follow the requirements of the GNU GPL in regard to all of the
24
 
*      software in the executable aside from Oracle client libraries.
25
 
*
26
 
*      Specifically you are not permitted to link this program with the
27
 
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
 
*      And you are not permitted to distribute binaries compiled against
29
 
*      these libraries without written consent from Quest Software, Inc.
30
 
*      Observe that this does not disallow linking to the Qt Free Edition.
31
 
*
32
 
*      You may link this product with any GPL'd Qt library such as Qt/Free
33
 
*
34
 
* All trademarks belong to their respective owners.
35
 
*
36
 
*****/
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#include "tochangeconnection.h"
41
 
#include "toconnection.h"
42
 
#include "toconf.h"
43
 
#include "tocurrent.h"
44
 
#include "tomain.h"
45
 
#include "tonoblockquery.h"
46
 
#include "toresultlong.h"
47
 
#include "toresultparam.h"
48
 
#include "toresultstats.h"
49
 
#include "toresultview.h"
50
 
#include "tosql.h"
51
 
#include "totool.h"
52
 
 
53
 
#ifdef TO_KDE
54
 
#  include <kmenubar.h>
55
 
#endif
56
 
 
57
 
#include <qlabel.h>
58
 
#include <qmenubar.h>
59
 
#include <qpopupmenu.h>
60
 
#include <qtabwidget.h>
61
 
#include <qtoolbar.h>
62
 
#include <qtoolbutton.h>
63
 
#include <qworkspace.h>
64
 
 
65
 
#include "tocurrent.moc"
66
 
 
67
 
#include "icons/refresh.xpm"
68
 
#include "icons/tocurrent.xpm"
69
 
 
70
 
class toCurrentInfoTool : public toTool
71
 
{
72
 
protected:
73
 
    std::map<toConnection *, QWidget *> Windows;
74
 
 
75
 
    virtual const char **pictureXPM(void)
76
 
    {
77
 
        return const_cast<const char**>(tocurrent_xpm);
78
 
    }
79
 
public:
80
 
    toCurrentInfoTool()
81
 
            : toTool(240, "Current Session")
82
 
    { }
83
 
    virtual const char *menuItem()
84
 
    {
85
 
        return "Current Session";
86
 
    }
87
 
    virtual QWidget *toolWindow(QWidget *parent, toConnection &connection)
88
 
    {
89
 
        std::map<toConnection *, QWidget *>::iterator i = Windows.find(&connection);
90
 
        if (i != Windows.end())
91
 
        {
92
 
            (*i).second->raise();
93
 
            (*i).second->setFocus();
94
 
            return NULL;
95
 
        }
96
 
        else
97
 
        {
98
 
            QWidget *window = new toCurrent(parent, connection);
99
 
            Windows[&connection] = window;
100
 
            return window;
101
 
        }
102
 
    }
103
 
    void closeWindow(toConnection &connection)
104
 
    {
105
 
        std::map<toConnection *, QWidget *>::iterator i = Windows.find(&connection);
106
 
        if (i != Windows.end())
107
 
            Windows.erase(i);
108
 
    }
109
 
};
110
 
 
111
 
static toCurrentInfoTool CurrentTool;
112
 
 
113
 
static toSQL SQLVersion("toCurrent:Version",
114
 
                        "select banner \"Version\" from v$version",
115
 
                        "Display version of Oracle");
116
 
 
117
 
static toSQL SQLResourceLimit("toCurrent:ResourceLimit",
118
 
                              "SELECT * FROM v$resource_limit ORDER BY resource_name",
119
 
                              "List resource limits");
120
 
 
121
 
toCurrent::toCurrent(QWidget *main, toConnection &connection)
122
 
        : toToolWidget(CurrentTool, "current.html", main, connection)
123
 
{
124
 
    QToolBar *toolbar = toAllocBar(this, tr("Current Session"));
125
 
 
126
 
    new QToolButton(QPixmap(const_cast<const char**>(refresh_xpm)),
127
 
                    tr("Update"),
128
 
                    tr("Update"),
129
 
                    this, SLOT(refresh(void)),
130
 
                    toolbar);
131
 
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
132
 
    new toChangeConnection(toolbar, TO_KDE_TOOLBAR_WIDGET);
133
 
 
134
 
    Tabs = new QTabWidget(this);
135
 
 
136
 
    Grants = new toListView(Tabs);
137
 
    Grants->setSorting(0);
138
 
    Grants->addColumn(tr("Privilege"));
139
 
    Grants->addColumn(tr("Type"));
140
 
    Grants->addColumn(tr("Grantable"));
141
 
    Grants->setRootIsDecorated(true);
142
 
    Tabs->addTab(Grants, tr("Privileges"));
143
 
 
144
 
    Version = new toResultLong(true, false, toQuery::Background, Tabs);
145
 
    Version->setSQL(SQLVersion);
146
 
    Tabs->addTab(Version, tr("Version"));
147
 
 
148
 
    Parameters = new toResultParam(Tabs);
149
 
    Tabs->addTab(Parameters, tr("Parameters"));
150
 
 
151
 
    Statistics = new toResultStats(false, Tabs);
152
 
    Tabs->addTab(Statistics, tr("Statistics"));
153
 
 
154
 
    ResourceLimit = new toResultLong(true, false, toQuery::Background, Tabs, "resource");
155
 
    ResourceLimit->setSQL(SQLResourceLimit);
156
 
    Tabs->addTab(ResourceLimit, tr("Resource Limits"));
157
 
 
158
 
    ToolMenu = NULL;
159
 
    connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
160
 
            this, SLOT(windowActivated(QWidget *)));
161
 
 
162
 
    connect(&Poll, SIGNAL(timeout()), this, SLOT(poll()));
163
 
 
164
 
    Query = NULL;
165
 
    refresh();
166
 
 
167
 
    setFocusProxy(Tabs);
168
 
}
169
 
 
170
 
void toCurrent::windowActivated(QWidget *widget)
171
 
{
172
 
    if (widget == this)
173
 
    {
174
 
        if (!ToolMenu)
175
 
        {
176
 
            ToolMenu = new QPopupMenu(this);
177
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(refresh_xpm)), tr("&Refresh"),
178
 
                                 this, SLOT(refresh(void)),
179
 
                                 toKeySequence(tr("F5", "Current session|Refresh")));
180
 
            toMainWidget()->menuBar()->insertItem(tr("&Current Session"), ToolMenu, -1, toToolMenuIndex());
181
 
        }
182
 
    }
183
 
    else
184
 
    {
185
 
        delete ToolMenu;
186
 
        ToolMenu = NULL;
187
 
    }
188
 
}
189
 
 
190
 
toCurrent::~toCurrent()
191
 
{
192
 
    try
193
 
    {
194
 
        CurrentTool.closeWindow(connection());
195
 
    }
196
 
    TOCATCH
197
 
}
198
 
 
199
 
static toSQL SQLRoleTabPrivs("toCurrent:RoleTabPrivs",
200
 
                             "select privilege||' on '||owner||'.'||table_name,grantable from role_tab_privs where role = :role<char[100]>",
201
 
                             "Get information about privileges granted on objects to a role, must have same binds and columns");
202
 
 
203
 
static toSQL SQLRoleSysPrivs("toCurrent:RoleSysPrivs",
204
 
                             "select privilege,admin_option from role_sys_privs where role = :role<char[100]>",
205
 
                             "Get information about system privileges granted to role, must have same binds and columns");
206
 
 
207
 
static toSQL SQLRoleRolePrivs("toCurrent:RoleRolePrivs",
208
 
                              "select granted_role,admin_option from role_role_privs where role = :role<char[100]>",
209
 
                              "Get information about roles granted to a role, must have same binds and columns");
210
 
 
211
 
static toSQL SQLUserTabPrivs("toCurrent:UserTabPrivs",
212
 
                             "select privilege || ' on ' || owner||'.'||table_name,grantable from user_tab_privs",
213
 
                             "Get information about privileges granted on objects to a user, must have same columns");
214
 
 
215
 
static toSQL SQLUserSysPrivs("toCurrent:UserSysPrivs",
216
 
                             "select privilege,admin_option from user_sys_privs",
217
 
                             "Get information about system privileges granted to user, must have same columns");
218
 
 
219
 
static toSQL SQLUserRolePrivs("toCurrent:UserRolePrivs",
220
 
                              "select granted_role,admin_option from user_role_privs",
221
 
                              "Get information about roles granted to a user, must have same columns");
222
 
 
223
 
void toCurrent::addList(bool isrole, QListViewItem *parent, const QString &type, const toSQL &sql, const QString &role)
224
 
{
225
 
    Updates.insert(Updates.end(), update(isrole, parent, type, sql(connection()), role));
226
 
}
227
 
 
228
 
void toCurrent::poll()
229
 
{
230
 
    try
231
 
    {
232
 
        if (Query)
233
 
        {
234
 
            while (Query && Query->poll())
235
 
            {
236
 
                if (Query->eof())
237
 
                {
238
 
                    delete Query;
239
 
                    Query = NULL;
240
 
                }
241
 
                else
242
 
                {
243
 
                    QListViewItem *item;
244
 
                    if (CurrentUpdate.Parent)
245
 
                        item = new toResultViewItem(CurrentUpdate.Parent, NULL);
246
 
                    else
247
 
                        item = new toResultViewItem(Grants, NULL);
248
 
                    item->setText(0, Query->readValue());
249
 
                    item->setText(1, CurrentUpdate.Type);
250
 
                    item->setText(2, Query->readValue());
251
 
                    if (CurrentUpdate.IsRole)
252
 
                    {
253
 
                        addList(false, item, tr("System"), SQLRoleSysPrivs, item->text(0));
254
 
                        addList(false, item, tr("Object"), SQLRoleTabPrivs, item->text(0));
255
 
                        addList(true, item, tr("Role"), SQLRoleRolePrivs, item->text(0));
256
 
                    }
257
 
                }
258
 
            }
259
 
        }
260
 
 
261
 
        if (!Query)
262
 
        {
263
 
            if ( Updates.empty() )
264
 
            {
265
 
                Poll.stop();
266
 
                return ;
267
 
            }
268
 
 
269
 
            CurrentUpdate = toShift(Updates);
270
 
 
271
 
            toQList param;
272
 
            if (!CurrentUpdate.Role.isEmpty())
273
 
                toPush(param, toQValue(CurrentUpdate.Role));
274
 
            Query = new toNoBlockQuery(connection(),
275
 
                                       toQuery::Background,
276
 
                                       CurrentUpdate.SQL,
277
 
                                       param);
278
 
        }
279
 
    }
280
 
    catch (const QString &exc)
281
 
    {
282
 
        toStatusMessage(exc);
283
 
        delete Query;
284
 
        Query = NULL;
285
 
    }
286
 
}
287
 
 
288
 
void toCurrent::refresh()
289
 
{
290
 
    try
291
 
    {
292
 
        Parameters->refresh();
293
 
        Version->refresh();
294
 
        Statistics->refreshStats();
295
 
        Grants->clear();
296
 
        ResourceLimit->refresh();
297
 
 
298
 
        Updates.clear();
299
 
        delete Query;
300
 
        Query = NULL;
301
 
 
302
 
        addList(false, NULL, tr("System"), SQLUserSysPrivs);
303
 
        addList(false, NULL, tr("Object"), SQLUserTabPrivs);
304
 
        addList(true, NULL, tr("Role"), SQLUserRolePrivs);
305
 
 
306
 
        poll();
307
 
        Poll.start(100);
308
 
    }
309
 
    TOCATCH
310
 
}