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

« back to all changes in this revision

Viewing changes to src/toalert.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-04-07 13:16:05 UTC
  • mfrom: (1.2.7 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090407131605-u422yigfv7jgg0l0
Tags: 2.0.0-3
* Cleaned up packaging a little bit.
* Added homepage information to control file.
* Bumped Standards-Version to 3.8.1.
* Released to unstable.

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
 
*****/
 
1
 
 
2
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
3
 *
 
4
 * TOra - An Oracle Toolkit for DBA's and developers
 
5
 * 
 
6
 * Shared/mixed copyright is held throughout files in this product
 
7
 * 
 
8
 * Portions Copyright (C) 2000-2001 Underscore AB
 
9
 * Portions Copyright (C) 2003-2005 Quest Software, Inc.
 
10
 * Portions Copyright (C) 2004-2008 Numerous Other Contributors
 
11
 * 
 
12
 * This program is free software; you can redistribute it and/or
 
13
 * modify it under the terms of the GNU General Public License
 
14
 * as published by the Free Software Foundation;  only version 2 of
 
15
 * the License is valid for this program.
 
16
 * 
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 * 
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
25
 * 
 
26
 *      As a special exception, you have permission to link this program
 
27
 *      with the Oracle Client libraries and distribute executables, as long
 
28
 *      as you follow the requirements of the GNU GPL in regard to all of the
 
29
 *      software in the executable aside from Oracle client libraries.
 
30
 * 
 
31
 *      Specifically you are not permitted to link this program with the
 
32
 *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 
33
 *      And you are not permitted to distribute binaries compiled against
 
34
 *      these libraries. 
 
35
 * 
 
36
 *      You may link this product with any GPL'd Qt library.
 
37
 * 
 
38
 * All trademarks belong to their respective owners.
 
39
 *
 
40
 * END_COMMON_COPYRIGHT_HEADER */
37
41
 
38
42
#include "toalert.h"
39
43
 
42
46
#include "tomain.h"
43
47
#include "tomemoeditor.h"
44
48
#include "toresultview.h"
 
49
#include "toconnection.h"
45
50
 
46
 
#ifndef WIN32
 
51
#ifndef Q_OS_WIN32
47
52
#include <unistd.h>
48
53
#else
49
54
#include <windows.h>
56
61
#include <qlabel.h>
57
62
#include <qlineedit.h>
58
63
#include <qmenubar.h>
59
 
#include <qpopupmenu.h>
60
 
#include <qtoolbar.h>
61
64
#include <qtoolbutton.h>
62
 
#include <qworkspace.h>
 
65
#include <QMdiArea>
63
66
 
64
 
#include "toalert.moc"
 
67
#include <QPixmap>
65
68
 
66
69
#include "icons/commit.xpm"
67
70
#include "icons/return.xpm"
121
124
                     "Get hostname of current connection");
122
125
 
123
126
toAlert::toAlert(QWidget *main, toConnection &connection)
124
 
        : toToolWidget(AlertTool, "alert.html", main, connection), Connection(connection)
 
127
        : toToolWidget(AlertTool, "alert.html", main, connection, "toAlert")
 
128
        , Connection(connection)
125
129
{
126
130
    QToolBar *toolbar = toAllocBar(this, tr("Alert Messenger"));
 
131
    layout()->addWidget(toolbar);
127
132
 
128
133
    QString def;
129
134
    try
134
139
            def += QString::fromLatin1(":");
135
140
    }
136
141
    catch (...)
137
 
    {}
 
142
        {}
138
143
    def += connection.user();
139
144
 
140
 
    new QLabel(tr("Registered") + " ", toolbar, TO_TOOLBAR_WIDGET_NAME);
141
 
    Registered = new QComboBox(toolbar, TO_TOOLBAR_WIDGET_NAME);
142
 
    Registered->insertItem(def);
 
145
    toolbar->addWidget(
 
146
        new QLabel(tr("Registered") + " ", toolbar));
 
147
 
 
148
    Registered = new QComboBox(toolbar);
 
149
    Registered->addItem(def);
143
150
    Registered->setEditable(true);
144
151
    Registered->setDuplicatesEnabled(false);
145
 
    Registered->setCurrentItem(0);
146
 
    connect(Registered, SIGNAL(activated(int)), this, SLOT(add
147
 
            ()));
 
152
    Registered->setCurrentIndex(0);
 
153
    connect(Registered, SIGNAL(activated(int)), this, SLOT(add()));
 
154
    toolbar->addWidget(Registered);
148
155
 
149
156
    AddNames.insert(AddNames.end(), def);
150
157
 
151
 
    new QToolButton(QPixmap(const_cast<const char**>(commit_xpm)),
152
 
                    tr("Register current"),
153
 
                    tr("Register current"),
154
 
                    this, SLOT(add
155
 
                               ()),
156
 
                    toolbar);
 
158
    addAct =
 
159
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(commit_xpm))),
 
160
                           tr("Register current"),
 
161
                           this,
 
162
                           SLOT(add()));
 
163
    addAct->setShortcut(Qt::ALT + Qt::Key_R);
157
164
 
158
 
    new QToolButton(QPixmap(const_cast<const char**>(trash_xpm)),
159
 
                    tr("Remove registered"),
160
 
                    tr("Remove registered"),
161
 
                    this, SLOT(remove
162
 
                               ()),
163
 
                    toolbar);
 
165
    removeAct =
 
166
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(trash_xpm))),
 
167
                           tr("Remove registered"),
 
168
                           this,
 
169
                           SLOT(remove()));
 
170
    removeAct->setShortcut(Qt::CTRL + Qt::Key_Backspace);
164
171
 
165
172
    toolbar->addSeparator();
166
173
 
167
 
    new QLabel(tr("Name") + " ", toolbar, TO_TOOLBAR_WIDGET_NAME);
168
 
    Name = new QLineEdit(toolbar, TO_TOOLBAR_WIDGET_NAME);
 
174
    toolbar->addWidget(
 
175
        new QLabel(tr("Name") + " ", toolbar));
 
176
 
 
177
    toolbar->addWidget(
 
178
        Name = new QLineEdit(toolbar));
169
179
    Name->setText(def);
170
180
    connect(Name, SIGNAL(returnPressed()), this, SLOT(send()));
171
 
    new QLabel(tr("Message") + " ", toolbar, TO_TOOLBAR_WIDGET_NAME);
172
 
    Message = new QLineEdit(toolbar, TO_TOOLBAR_WIDGET_NAME);
 
181
 
 
182
    toolbar->addWidget(
 
183
        new QLabel(tr("Message") + " ", toolbar));
 
184
 
 
185
    Message = new QLineEdit(toolbar);
173
186
    connect(Message, SIGNAL(returnPressed()), this, SLOT(send()));
174
 
    new QToolButton(QPixmap(const_cast<const char**>(toworksheet_xpm)),
175
 
                    tr("Edit message in memo"),
176
 
                    tr("Edit message in memo"),
177
 
                    this, SLOT(memo()),
178
 
                    toolbar);
179
 
    toolbar->setStretchableWidget(Message);
180
 
    new QToolButton(QPixmap(const_cast<const char**>(return_xpm)),
181
 
                    tr("Send alert"),
182
 
                    tr("Send alert"),
183
 
                    this, SLOT(send()),
184
 
                    toolbar);
 
187
    Message->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
 
188
                                       QSizePolicy::Minimum));
 
189
 
 
190
    toolbar->addWidget(Message);
 
191
 
 
192
    memoEditAct =
 
193
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(toworksheet_xpm))),
 
194
                           tr("Edit message in memo"),
 
195
                           this,
 
196
                           SLOT(memo()));
 
197
    memoEditAct->setShortcut(Qt::CTRL + Qt::Key_M);
 
198
 
 
199
    sendAct =
 
200
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(return_xpm))),
 
201
                           tr("Send alert"),
 
202
                           this,
 
203
                           SLOT(send()));
 
204
    sendAct->setShortcut(Qt::CTRL + Qt::Key_Return);
185
205
 
186
206
    connect(&Timer, SIGNAL(timeout()), this, SLOT(poll()));
187
207
    Timer.start(TIMEOUT*1000);
190
210
    Alerts->addColumn(tr("Time"));
191
211
    Alerts->addColumn(tr("Name"));
192
212
    Alerts->addColumn(tr("Message"));
 
213
    layout()->addWidget(Alerts);
193
214
 
194
215
    ToolMenu = NULL;
195
 
    connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
196
 
            this, SLOT(windowActivated(QWidget *)));
 
216
    connect(toMainWidget()->workspace(), SIGNAL(subWindowActivated(QMdiSubWindow *)),
 
217
            this, SLOT(windowActivated(QMdiSubWindow *)));
197
218
 
198
219
    State = Started;
199
220
    try
203
224
    }
204
225
    catch (...)
205
226
    {
206
 
        toStatusMessage(tr("Failed to start polling thread, try closing some other tools and restart Alert Messenger"));
 
227
        toStatusMessage(tr("Failed to start polling thread, try closing "
 
228
                           "some other tools and restart Alert Messenger"));
207
229
    }
208
230
 
209
231
    setFocusProxy(Message);
210
232
}
211
233
 
212
 
void toAlert::windowActivated(QWidget *widget)
 
234
void toAlert::windowActivated(QMdiSubWindow *widget)
213
235
{
214
 
    if (widget == this)
 
236
    if (!widget)
 
237
        return;
 
238
    if (widget->widget() == this)
215
239
    {
216
240
        if (!ToolMenu)
217
241
        {
218
 
            ToolMenu = new QPopupMenu(this);
219
 
            ToolMenu->insertItem(tr("&Add name"), Registered, SLOT(setFocus()), toKeySequence(tr("Alt+R", "Alert|Add Name")));
220
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(trash_xpm)), tr("&Remove name"),
221
 
                                 this, SLOT(remove
222
 
                                            (void)), toKeySequence(tr("Ctrl+Backspace", "Alert|Remove name")));
223
 
            ToolMenu->insertSeparator();
224
 
            ToolMenu->insertItem(tr("Edit &name"), Name, SLOT(setFocus()), toKeySequence(tr("Alt+N", "Alert|Edit name")));
225
 
            ToolMenu->insertItem(tr("Edit &message"), Message, SLOT(setFocus()), toKeySequence(tr("Alt+M", "Alert|Message")));
226
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(toworksheet_xpm)), tr("&Message in memo..."),
227
 
                                 this, SLOT(memo(void)), toKeySequence(tr("Ctrl+M", "Alert|Message in memo")));
228
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(return_xpm)), tr("&Send alert"),
229
 
                                 this, SLOT(send(void)), toKeySequence(tr("Ctrl+Return", "Alert|Send alert")));
230
 
 
231
 
            toMainWidget()->menuBar()->insertItem(tr("&Alert"), ToolMenu, -1, toToolMenuIndex());
 
242
            ToolMenu = new QMenu(tr("&Alert"), this);
 
243
 
 
244
            ToolMenu->addAction(addAct);
 
245
            ToolMenu->addAction(removeAct);
 
246
 
 
247
            ToolMenu->addSeparator();
 
248
 
 
249
            ToolMenu->addAction(memoEditAct);
 
250
            ToolMenu->addAction(sendAct);
 
251
 
 
252
            toMainWidget()->addCustomMenu(ToolMenu);
232
253
        }
233
254
    }
234
255
    else
240
261
 
241
262
toAlert::~toAlert()
242
263
{
 
264
}
 
265
 
 
266
void toAlert::closeEvent(QCloseEvent *event)
 
267
{
243
268
    try
244
269
    {
245
270
        Lock.lock();
253
278
        Lock.unlock();
254
279
        AlertTool.closeWindow(connection());
255
280
    }
256
 
    TOCATCH
 
281
    TOCATCH;
257
282
}
258
283
 
259
284
static toSQL SQLRegister("toAlert:Register",
268
293
static toSQL SQLPoll("toAlert:PollAlert",
269
294
                     "BEGIN\n"
270
295
                     "  SYS.DBMS_ALERT.WAITANY(:name<char[4000],out>,:msg<char[4000],out>,\n"
271
 
                     "                         :stat<in,out>,:tim<char[10],in>);\n"
 
296
                     "                         :stat<int,out>,:tim<char[10],in>);\n"
272
297
                     "END;",
273
298
                     "Poll for alert, must have same binds");
274
299
static toSQL SQLSignal("toAlert:Signal",
288
313
        {
289
314
            {
290
315
                toLocker lock (Parent.Lock)
291
 
                    ;
 
316
                ;
292
317
                fatal = true;
293
318
                {
294
319
                    for (std::list<QString>::iterator i = Parent.AddNames.begin();
319
344
 
320
345
            {
321
346
                toLocker lock (Parent.Lock)
322
 
                    ;
 
347
                ;
323
348
                std::list<QString>::iterator i = Parent.SendAlerts.begin();
324
349
                std::list<QString>::iterator j = Parent.SendMessages.begin();
325
350
                while (i != Parent.SendAlerts.end() && j != Parent.SendMessages.end())
343
368
                if (query.readValue().toInt() == 0)
344
369
                {
345
370
                    toLocker lock (Parent.Lock)
346
 
                        ;
 
371
                    ;
347
372
                    Parent.NewAlerts.insert(Parent.NewAlerts.end(), name);
348
373
                    Parent.NewMessages.insert(Parent.NewMessages.end(), msg);
349
374
                }
351
376
            else
352
377
            {
353
378
                Parent.Lock.unlock();
354
 
#ifndef WIN32
355
 
 
 
379
#ifndef Q_OS_WIN32
356
380
                sleep(TIMEOUT);
357
381
#else
358
382
 
359
383
                Sleep(TIMEOUT*1000);
360
384
#endif
361
 
 
362
385
            }
363
386
        }
364
387
        catch (const QString &str)
365
388
        {
366
389
            Parent.Lock.lock();
367
 
            Parent.Error.sprintf("Exception in alert polling:\n%s", (const char *)str.latin1());
368
 
            fprintf(stderr, "%s\n", (const char *)Parent.Error);
 
390
            Parent.Error.sprintf("Exception in alert polling:\n%s", (const char *)str.toLatin1());
 
391
            fprintf(stderr, "%s\n", Parent.Error.toAscii().constData());
369
392
            Parent.Lock.unlock();
370
393
        }
371
394
        catch (...)
372
395
        {
373
396
            Parent.Lock.lock();
374
397
            Parent.Error.sprintf("Unexpected exception in alert in polling.");
375
 
            fprintf(stderr, "%s\n", (const char *)Parent.Error);
 
398
            fprintf(stderr, "%s\n", Parent.Error.toAscii().constData());
376
399
            Parent.Lock.unlock();
377
400
        }
378
401
 
384
407
            Parent.Connection.execute(SQLRemoveAll);
385
408
        }
386
409
        catch (...)
387
 
        {}
 
410
            {}
388
411
    Parent.State = Done;
389
412
    Parent.Semaphore.up();
390
413
    Parent.Lock.unlock();
395
418
    try
396
419
    {
397
420
        toLocker lock (Lock)
398
 
            ;
399
 
        if (Error)
 
421
        ;
 
422
        if (!Error.isNull())
400
423
        {
401
424
            toStatusMessage(Error);
402
425
            Error = QString::null;
405
428
        std::list<QString>::iterator j = NewMessages.begin();
406
429
        while (i != NewAlerts.end() && j != NewMessages.end())
407
430
        {
408
 
            QListViewItem *item = new toResultViewMLine(Alerts, NULL, toNow(connection()));
 
431
            toTreeWidgetItem *item = new toResultViewMLine(Alerts, NULL, toNow(connection()));
409
432
            item->setText(1, *i);
410
433
            item->setText(2, *j);
411
434
            i++;
422
445
    if (!Name->text().isEmpty() && !Message->text().isEmpty())
423
446
    {
424
447
        toLocker lock (Lock)
425
 
            ;
 
448
        ;
426
449
        SendAlerts.insert(SendAlerts.end(), Name->text());
427
450
        SendMessages.insert(SendMessages.end(), Message->text());
428
451
        Message->clear();
442
465
}
443
466
 
444
467
void toAlert::remove
445
 
    (void)
 
468
(void)
446
469
{
447
470
    toLocker lock (Lock)
448
 
        ;
 
471
    ;
449
472
    QString name = Registered->currentText();
450
473
    if (!name.isEmpty())
451
474
    {
461
484
    }
462
485
 
463
486
    if (Registered->count() > 0)
464
 
        Registered->removeItem(Registered->currentItem());
 
487
        Registered->removeItem(Registered->currentIndex());
465
488
    if (Registered->count() > 0)
466
 
        Registered->setCurrentItem(0);
 
489
        Registered->setCurrentIndex(0);
467
490
}
468
491
 
469
492
void toAlert::add
470
 
    (void)
 
493
(void)
471
494
{
472
495
    Registered->lineEdit()->selectAll();
473
496
    QString name = Registered->currentText();
493
516
    }
494
517
 
495
518
    for (int i = 0;i < Registered->count();i++)
496
 
        if (Registered->text(i) == name)
 
519
        if (Registered->itemText(i) == name)
497
520
            return ;
498
521
 
499
 
    Registered->insertItem(name);
 
522
    Registered->addItem(name);
500
523
    Name->setText(name);
501
524
}