[go: up one dir, main page]

File: tomain.h

package info (click to toggle)
tora 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 27,560 kB
  • ctags: 21,885
  • sloc: cpp: 189,278; sh: 17,561; makefile: 692; python: 159; xml: 69; ansic: 56
file content (662 lines) | stat: -rw-r--r-- 17,088 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662

/* BEGIN_COMMON_COPYRIGHT_HEADER
 *
 * TOra - An Oracle Toolkit for DBA's and developers
 * 
 * Shared/mixed copyright is held throughout files in this product
 * 
 * Portions Copyright (C) 2000-2001 Underscore AB
 * Portions Copyright (C) 2003-2005 Quest Software, Inc.
 * Portions Copyright (C) 2004-2009 Numerous Other Contributors
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation;  only version 2 of
 * the License is valid for this program.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 *      As a special exception, you have permission to link this program
 *      with the Oracle Client libraries and distribute executables, as long
 *      as you follow the requirements of the GNU GPL in regard to all of the
 *      software in the executable aside from Oracle client libraries.
 * 
 *      Specifically you are not permitted to link this program with the
 *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 *      And you are not permitted to distribute binaries compiled against
 *      these libraries. 
 * 
 *      You may link this product with any GPL'd Qt library.
 * 
 * All trademarks belong to their respective owners.
 *
 * END_COMMON_COPYRIGHT_HEADER */

#ifndef TOMAIN_H
#define TOMAIN_H

#include "config.h"
#include "tobackground.h"
#include "tobackuptool.h"

#include "tomainwindow.h"

#include <list>
#include <map>
#include <algorithm>

#include <qtimer.h>

#include <QLabel>
#include <QPointer>

#define TOMessageBox QMessageBox

class QComboBox;
class QLabel;
class toTreeWidget;
class toTreeWidgetItem;
class QToolBar;
class QToolButton;
class QMdiArea;
class QMdiSubWindow;
class toBackgroundLabel;
class toConnection;
class toEditWidget;
class toLineChart;
class toMarkedText;
class toSearchReplace;
class toTool;
class toToolWidget;
class toMessage;
class toDocklet;
class toDockbar;


/** This class defines the main window. Observe that this class will have different baseclass
 * depending on if TOra is a Qt or KDE application. In the case of Qt this will be a
 * QMainWindow descendant.
 */
class toMain : public toMainWindow
{
    Q_OBJECT;

private:
    std::auto_ptr<toBackupTool> toBackupTool_;
    /**
     * The connections that have been opened in TOra.
     */
    std::list<toConnection *> Connections;
    /**
     * Workspace of main window - MDI area.
     */
    QMdiArea *Workspace;
    /**
     * The last active sub window in workspace
     */
    QPointer<QMdiSubWindow> LastActiveWindow;
    /**
     * Handles available connections list in toolbar.
     */
    QComboBox *ConnectionSelection;
    /**
     * The ID of the tool providing the SQL editor.
     */
    QString SQLEditor;

    /**
     * A reference to the error dialog.
     */
    toMessage * Message;

    /**
     * Status message storage for status bar
     */
    std::list<QString> StatusMessages;

    /**
     * Edit buttons toolbar.
     */
    QToolBar *editToolbar;
    /**
     * Tool buttons toolbar.
     */
    QToolBar *toolsToolbar;
    /**
     * Connection buttons toolbar.
     */
    QToolBar *connectionToolbar;

    /**
     * Toolbar for minimizing docklets, left
     *
     */
    toDockbar *leftDockbar;

    /**
     * Toolbar for minimizing docklets, right
     *
     */
    toDockbar *rightDockbar;

    /**
     * File menu.
     */
    QMenu *fileMenu;
    /**
     * Recent files menu (child of fileMenu).
     */
    QMenu *recentMenu;
    /**
     * Edit menu.
     */
    QMenu *editMenu;
    /**
     * View menu.
     */
    QMenu *viewMenu;
    /**
     * Tools menu.
     */
    QMenu *toolsMenu;
    /**
     * Windows menu.
     */
    QMenu *windowsMenu;
    /**
     * Help menu.
     */
    QMenu *helpMenu;
    /**
     * Display latest status messages
     */
    QMenu *statusMenu;
    /**
     * Current column label.
     */
    QLabel *ColumnLabel;
    /**
     * Current row label.
     */
    QLabel *RowLabel;

    //! \brief Display current type of text edit selection (normal/block)
    QLabel * SelectionLabel;

    toBackground Poll;
    /**
     * Search & replace dialog if available.
     */
    toSearchReplace *Search;

    toBackgroundLabel* BackgroundLabel;

    toEditWidget *Edit;

    toEditWidget *findEdit(QWidget *edit);

    void updateRecent(void);

    /**
     * enable or disable buttons that need an active connection
     *
     */
    void enableConnectionActions(bool enabled);

    void editEnable(toEditWidget *edit,
                    bool open,
                    bool save,
                    bool print,
                    bool undo,
                    bool redo,
                    bool cut,
                    bool copy,
                    bool paste,
                    bool search,
                    bool selectAll,
                    bool readAll);

    QAction *newConnAct;
    QAction *closeConn;
    QAction *commitAct;
    QAction *rollbackAct;
    QAction *currentAct;
    QAction *stopAct;
    QAction *refreshAct;
    QAction *openAct;
    QAction *saveAct;
    QAction *saveAsAct;
    QAction *openSessionAct;
    QAction *saveSessionAct;
    QAction *restoreSessionAct;
    QAction *closeSessionAct;
    QAction *printAct;
    QAction *quitAct;
    QAction *undoAct;
    QAction *redoAct;
    QAction *cutAct;
    QAction *copyAct;
    QAction *pasteAct;
    QAction *searchReplaceAct;
    QAction *searchNextAct;
    QAction *selectAllAct;
#if 0
// TODO: this part is waiting for QScintilla backend feature (yet unimplemented).
    QAction *selectBlockAct;
#endif
    QAction *readAllAct;
    QAction *prefsAct;
    QAction *helpCurrentAct;
    QAction *helpContentsAct;
    QAction *aboutAct;
    QAction *aboutQtAct;
    QAction *licenseAct;
    QAction *windowCloseAct;
    QAction *windowCloseAllAct;
    QAction *cascadeAct;
    QAction *tileAct;

    void createActions();
    void createMenus();
    void createToolbars();
    void createStatusbar();
    void createToolMenus();
    void createDocklets();
    void createDockbars();
    //! \brief Sets tools displaying depending on preferences (tabs/windows)
    void handleToolsDisplay();

public:

    /**
     * Create main window. Always NULL as parent.
     */
    toMain();

    /**
     * Get the workspace widget of the main window.
     * @return Workspace widget.
     */
    QMdiArea *workspace() const
    {
        return Workspace;
    }

    toSearchReplace * searchDialog()
    {
        return Search;
    }

    /**
     * The last active sub window in workspace. MDI area is buggy as
     * hell and currentSubWindow will not tell you the correct window
     * if a menu is open, or if a tool has a custom widget (sql
     * editor), somebody sneezes, etc.
     *
     * Use this to find the last active sub window.
     */
    QMdiSubWindow* lastActiveWindow() const
    {
        return LastActiveWindow;
    }

    /**
     * Get the current database connection
     * @return Reference to current connection.
     */
    toConnection &currentConnection(void);

    /**
     * Set the widget to edit through menues and toolbar.
     */
    static void setEditWidget(toEditWidget *edit);
    /**
     * Set available menu items in user interface. It is not enough to just call
     * this function to make open for instance to actually work. It is a lot of
     * more especially in @ref commandCallback and @ref editFileMenu. Will only
     * update if this is the current editing widget.
     */
    static void editEnable(toEditWidget *edit);
    /**
     * Disable all the current available items in the user interface (That @ref
     * editEnable can enable). If specified widget has the focus the edit widget
     * is cleared.
     */
    static void editDisable(toEditWidget *edit);

    /** Get current edit widget
     */
    toEditWidget *editWidget()
    {
        return Edit;
    }

    /**
     * Create the default tool for the current connection.
     *
     * This is the tool with the highest priority, usually the SQL worksheet.
     */
    void createDefault(void);

    /**
     * Set coordinates in the statusbar.
     *
     * Used to indicate current cursor position by child widgets.
     */
    void setCoordinates(int, int);

    toBackgroundLabel* getBackgroundLabel();

    /**
     * Get a list of currently open connections.
     * @return List of connection names. The returned list can then be used by
     * @ref connection to get the actual connection.
     */
    std::list<QString> connections(void);
    /** Get a connection identified by a string.
     * @return A reference to a connection.
     * @exception QString If connection wasn't found.
     */
    toConnection &connection(const QString &);
    /** Set if a connection needs to be commited. Also updates visual feedback in interface.
     */
    void setNeedCommit(toConnection &conn, bool needCommit = true);

    /** Edit an SQL statement in the SQL editor if any connected.
     * @param str Identifier of the SQL to edit.
     */
    void editSQL(const QString &str);
    /**
     * Register a tool which to use as an SQL editor. When something
     * is to be edited first a toolwindow will be created and the @ref
     * sqlEditor will be emited, so the SQL editor must connect to
     * this signal as well.
     *
     * @param toolid Which tool identifier to register as the SQL
     *               editor. This is the value which is passed to the
     *               @ref toTool::customSetup member.
     */
    void registerSQLEditor(const QString &);

    /** Called by @ref toTool when a new tool is created.
     * @param tool The tool widget created.
     */
    void toolWidgetAdded(toToolWidget *tool);
    /** Called by @ref toToolWidget when a new tool is about to be destroyed.
     * @param tool The tool widget created.
     */
    void toolWidgetRemoved(toToolWidget *tool);

    /** Export data to a map.
     * @param data A map that can be used to recreate the session.
     * @param prefix Prefix to add to the map.
     */
    virtual void exportData(std::map < QString,
                            QString > &data,
                            const QString &prefix);
    /** Import data
     * @param data Data to read from a map.
     * @param prefix Prefix to read data from.
     */
    virtual void importData(std::map < QString,
                            QString > &data,
                            const QString &prefix);
    /** Added chart.
     */
    void addChart(toLineChart *chart);
    /** Removed chart.
     */
    void removeChart(toLineChart *chart);
    /** Setup chart.
     */
    void setupChart(toLineChart *chart);
    /** Add recent file
     */
    void addRecentFile(const QString &filename);

    /**
     * allow tools to add custom menus (ie. File, Edit, Sql Editor)
     * without giving away public access to menubars.
     *
     */
    void addCustomMenu(QMenu *);

    // access needed to some QActions for creating popup menus
    QAction* getUndoAction()
    {
        return undoAct;
    }

    QAction* getRedoAction()
    {
        return redoAct;
    }

    QAction* getCutAction()
    {
        return cutAct;
    }

    QAction* getCopyAction()
    {
        return copyAct;
    }

    QAction* getPasteAction()
    {
        return pasteAct;
    }

    QAction* getSelectAllAction()
    {
        return selectAllAct;
    }

    QMenu* getEditMenu()
    {
        return editMenu;
    }

    /**
     * add a button to the application toolbar
     \warning Do not use it. It screw realoading of the state of toolbars
     \warning The toolbar just after editToolbar the top row of the schema
     browser is migrating to the right - basically the whitespace after
     the editToolbar is expanding too far.
     */
    void addButtonApplication(QAction *);

    /**
     * Add a new connection. The connection itself must already be created.
     * Returns the connection or it's duplicate already opened connection.
     */
    toConnection *addConnection(toConnection *conn, bool def = true);

signals:
    /** Invoked to start editing an SQL identifier.
     * @param str Identifier to start editing.
     */
    void sqlEditor(const QString &str);
    /** Invoked when a new chart is created.
     */
    void chartAdded(toLineChart *chart);
    /** Invoked before a chart is destroyed.
     */
    void chartSetup(toLineChart *chart);
    /** Invoked before a chart is destroyed.
     */
    void chartRemoved(toLineChart *chart);
    /** Invoked when a connection is added.
     * @param str Connection identifier.
     */
    void addedConnection(const QString &str);
    /** Invoked when a connection is removed.
     * @param str Connection identifier.
     */
    void removedConnection(const QString &str);
    /** Invoked when a tool window is created.
     * @param tool The tool created.
     */
    void addedToolWidget(toToolWidget *tool);
    /** Invoked when a tool window is closed.
     * @param tool Tool about to be removed.
     */
    void removedToolWidget(toToolWidget *tool);
    /** Emitted before a commit or rollback is made to the current connection.
     * @param conn Connection that is commited
     * @param cmt True if commit, false if rollback.
     */
    void willCommit(toConnection &conn, bool cmt);
    /**
     * emitted when widgets related to editing.
     */
    void editEnabled(bool en);
    /**
     * emitted to internally handle status bar messages
     */
    void messageRequested(const QString &str, bool save, bool log);

public slots:
    /**
     * Close window
     * @param del If user interaction is allowed.
     * @return True if close was allowed, otherwise false.
     */
    //bool close();
    /** Used to enable/disable entries in the windows menu
     */
    void updateWindowsMenu();
    /** Called when active window is changed.
     */
    void windowActivated(QMdiSubWindow *);
    /** Used to enable/disable entries in the file menu
     */
    void showFileMenu(void);
    /** Check if object caching is done.
     */
    void checkCaching(void);
    /** Save the current TOra session
     */
    void saveSession(void);
    /** Load a session (Merge with current)
     */
    void loadSession(void);
    /** Close all windows and connections.
     */
    void closeSession(void);
    /** Change current connection
     */
    void changeConnection(void);
    /**
     * Show a statusbar message.
     *
     * @param str message to show
     * @param save save to messages menu
     * @param log
     */
    void showMessage(const QString &str, bool save, bool log);

    /**
     * Show a busy cursor or other indicators. Must be called from the
     * main thread.
     *
     * class toBusy calls this method.
     *
     */
    void showBusy(void);

    /**
     * Remove busy cursor or other indicators. Must be called from the
     * main thread.
     *
     * class toBusy calls this method.
     */
    void removeBusy(void);

    /**
     * Open a file in sql worksheet
     *
     */
    void editOpenFile(QString file);

    /**
     * Return the toDockbar that manages the docklet. If none
     * currently manages the docklet, returns what will if the docklet
     * is shown.
     *
     */
    toDockbar* dockbar(toDocklet *let);

    /**
     * Handles moving docklet to new dockbar
     *
     */
    void moveDocklet(toDocklet *let, Qt::DockWidgetArea area);

protected:
    /** intercept close event from parent
     */
    void closeEvent(QCloseEvent *event);

private slots:
    /** Add a connection
     */
    void addConnection(void);
    /** Remove a connection
     */
    bool delConnection(void);
    /** Handles menu selections
     * @param cmd Menu entry ID selected
     */
    void commandCallback(QAction *);

    /**
     * handles callbacks for recent files menu
     *
     */
    void recentCallback(QAction *);

    /**
     * handles callbacks for the status bar
     *
     */
    void statusCallback(QAction *action);

    /**
     * handles callbacks for the status bar
     *
     */
    void windowCallback(QAction *action);

    /**
     * handles callbacks for the view menu
     *
     */
    void viewCallback(QAction *action);

    void updateStatusMenu(void);

    /** Display status message
     */
    void displayMessage(void);

    /**
     * Internal slot for handling status bar messages
     *
     */
    void showMessageImpl(const QString &str, bool save, bool log);
};

/** Get a pointer to the main window
 * @return Pointer to main window.
 */
toMain *toMainWidget(void);

#endif