toTemplate::toTemplate(TODock *parent)
        : QWidget(parent), toHelpContext(QString::fromLatin1("template.html"))
{
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->setSpacing(0);
    vbox->setContentsMargins(0, 0, 0, 0);

    Toolbar = toAllocBar(this, tr("Template Toolbar"));
    vbox->addWidget(Toolbar);

    List = new toListView(this);
    List->addColumn(tr("Template"));
    List->setRootIsDecorated(true);
    List->setSorting(0);
    List->setShowSortIndicator(false);
    List->setTreeStepSize(10);
    List->setSelectionMode(toTreeWidget::Single);
    List->setResizeMode(toTreeWidget::AllColumns);
    Result = toAllocDock(tr("Template result"),
                         QString::null,
                         *TemplateTool.toolbarImage());
    // fixes warning from QMainWindow::saveState
    Result->setObjectName("templateResult");
    vbox->addWidget(List);
    Frame = new toTemplateResult(Result, this);

    connect(List, SIGNAL(expanded(toTreeWidgetItem *)), this, SLOT(expand(toTreeWidgetItem *)));
    connect(List, SIGNAL(collapsed(toTreeWidgetItem *)), this, SLOT(collapse(toTreeWidgetItem *)));
    connect(List,
            SIGNAL(clicked(toTreeWidgetItem *)),
            this,
            SLOT(selected(toTreeWidgetItem *)));

    if (toTemplateProvider::Providers)
        for (std::list<toTemplateProvider *>::iterator i = toTemplateProvider::Providers->begin();
                i != toTemplateProvider::Providers->end();
                i++)
            (*i)->insertItems(List, Toolbar);

    Toolbar->addWidget(new toSpacer());

    WidgetExtra = NULL;
    setWidget(NULL);

    setFocusProxy(List);
    toAttachDock(parent, this, Qt::LeftDockWidgetArea);
    toAttachDock(Result, Frame, Qt::BottomDockWidgetArea);

    setLayout(vbox);
}
toAWR::toAWR(/*toTool *tool,*/ QWidget *parent, toConnection &_connection)
	: toToolWidget(/* *tool*/AWRTool, "simplequery.html", parent, _connection, "toAWR")
{
	QToolBar *toolbar=toAllocBar(this, tr("Simple Query"));
	layout()->addWidget(toolbar);
	
	toolbar->addWidget(new QLabel("Inst:", toolbar));
	dbid = new toResultCombo(toolbar, "AWR toolbar");
	fsnap = new toResultCombo(toolbar, "AWR toolbar");	fsnap->setSelectionPolicy(toResultCombo::LastButOne);
	tsnap = new toResultCombo(toolbar, "AWR toolbar");	tsnap->setSelectionPolicy(toResultCombo::Last);

	startdate = new QDateTimeEdit(QDate::currentDate());	startdate->setCalendarPopup(true);
	enddate = new QDateTimeEdit(QDate::currentDate());	enddate->setCalendarPopup(true);

	connect(dbid, SIGNAL(activated(int)), this, SLOT(instanceChanged(int)));
	connect(dbid, SIGNAL(done()), this, SLOT(instanceRead()));
	connect(startdate, SIGNAL(dateChanged(QDate)), this, SLOT(startDateChanged(QDate)));
	connect(enddate, SIGNAL(dateChanged(QDate)), this, SLOT(endDateChanged(QDate)));
	
	toolbar->addWidget(dbid);
	toolbar->addWidget(startdate);
	toolbar->addWidget(fsnap);
	toolbar->addWidget(enddate);
	toolbar->addWidget(tsnap);

	try
	{
		dbid->query(toSQL::sql("toAWR:DBInstances", connection()));
	}
	TOCATCH;

	toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(execute_xpm))),
			   tr("Generate report"),
			   this,
			   SLOT(execute()));
	toolbar->addWidget(new toSpacer());
	
	QAction *executeAct = new QAction(QPixmap(execute_xpm), tr("Execute_ current statement"), this);
        executeAct->setShortcut(QKeySequence::Refresh);
	connect(executeAct, SIGNAL(triggered()), this, SLOT(refresh(void)));

	new toChangeConnection(toolbar);
 
	Tabs = new QTabWidget(this);
	layout()->addWidget(Tabs);	
}
Example #3
0
toMain::toMain()
        : toMainWindow()
{
    qApp->setMainWidget ( this );
    setDockMenuEnabled ( true );

    Edit = NULL;

    FileMenu = new QPopupMenu ( this );
    FileMenu->insertItem ( QPixmap ( ( const char ** ) connect_xpm ),
                           "&New Connection...", TO_NEW_CONNECTION );
    FileMenu->insertItem ( QPixmap ( ( const char ** ) disconnect_xpm ),
                           "&Close Connection", this, SLOT ( delConnection() ), 0, TO_CLOSE_CONNECTION );
    FileMenu->insertSeparator();
    FileMenu->insertItem ( QPixmap ( ( const char ** ) commit_xpm ), "&Commit Connection", TO_FILE_COMMIT );
    FileMenu->insertItem ( QPixmap ( ( const char ** ) rollback_xpm ), "&Rollback Connection", TO_FILE_ROLLBACK );
    FileMenu->insertItem ( "C&urrent Connection", TO_FILE_CURRENT );
    FileMenu->insertItem ( QPixmap ( ( const char ** ) trash_xpm ), "Reread Object Cache", TO_FILE_CLEARCACHE );
    FileMenu->insertSeparator();
    FileMenu->insertItem ( QPixmap ( ( const char ** ) fileopen_xpm ), "&Open File...", TO_FILE_OPEN );
    FileMenu->insertItem ( QPixmap ( ( const char ** ) filesave_xpm ), "&Save", TO_FILE_SAVE );
    FileMenu->insertItem ( "Save A&s...", TO_FILE_SAVE_AS );
    FileMenu->insertSeparator();
    FileMenu->insertItem ( QPixmap ( ( const char ** ) print_xpm ), "&Print..", TO_FILE_PRINT );
    FileMenu->insertSeparator();
    FileMenu->insertItem ( "&Quit", TO_FILE_QUIT );
    menuBar() ->insertItem ( "&File", FileMenu, TO_FILE_MENU );
    FileMenu->setAccel ( Key_G | CTRL, TO_NEW_CONNECTION );
    FileMenu->setAccel ( Key_O | CTRL, TO_FILE_OPEN );
    FileMenu->setAccel ( Key_S | CTRL, TO_FILE_SAVE );
    FileMenu->setAccel ( Key_W | CTRL, TO_FILE_COMMIT );
    FileMenu->setAccel ( Key_R | CTRL, TO_FILE_ROLLBACK );
    FileMenu->setAccel ( Key_U | CTRL, TO_FILE_CURRENT );
    connect ( FileMenu, SIGNAL ( aboutToShow() ), this, SLOT ( editFileMenu() ) );

    EditMenu = new QPopupMenu ( this );
    EditMenu->insertItem ( QPixmap ( ( const char ** ) undo_xpm ), "&Undo", TO_EDIT_UNDO );
    EditMenu->insertItem ( QPixmap ( ( const char ** ) redo_xpm ), "&Redo", TO_EDIT_REDO );
    EditMenu->insertSeparator();
    EditMenu->insertItem ( QPixmap ( ( const char ** ) cut_xpm ), "Cu&t", TO_EDIT_CUT );
    EditMenu->insertItem ( QPixmap ( ( const char ** ) copy_xpm ), "&Copy", TO_EDIT_COPY );
    EditMenu->insertItem ( QPixmap ( ( const char ** ) paste_xpm ), "&Paste", TO_EDIT_PASTE );
    EditMenu->insertSeparator();
    EditMenu->insertItem ( "&Search && Replace", TO_EDIT_SEARCH );
    EditMenu->insertItem ( "Search &Next", TO_EDIT_SEARCH_NEXT );
    EditMenu->insertItem ( "Select &All", TO_EDIT_SELECT_ALL );
    EditMenu->insertItem ( "Read All &Items", TO_EDIT_READ_ALL );
    EditMenu->insertSeparator();
    EditMenu->insertItem ( "&Options...", TO_EDIT_OPTIONS );
    EditMenu->setAccel ( Key_Z | CTRL, TO_EDIT_UNDO );
    EditMenu->setAccel ( Key_Y | CTRL, TO_EDIT_REDO );
    EditMenu->setAccel ( Key_X | CTRL, TO_EDIT_CUT );
    EditMenu->setAccel ( Key_C | CTRL, TO_EDIT_COPY );
    EditMenu->setAccel ( Key_V | CTRL, TO_EDIT_PASTE );
    EditMenu->setAccel ( Key_F | CTRL, TO_EDIT_SEARCH );
    EditMenu->setAccel ( Key_F3, TO_EDIT_SEARCH_NEXT );
    connect ( EditMenu, SIGNAL ( aboutToShow() ), this, SLOT ( editFileMenu() ) );
    menuBar() ->insertItem ( "&Edit", EditMenu, TO_EDIT_MENU );

    std::map<QString, toTool *> &tools = toTool::tools();

    QToolBar *toolbar = toAllocBar ( this, "Application", QString::null );

    LoadButton = new QToolButton ( QPixmap ( ( const char ** ) fileopen_xpm ),
                                   "Load file into editor",
                                   "Load file into editor",
                                   this, SLOT ( loadButton() ), toolbar );
    SaveButton = new QToolButton ( QPixmap ( ( const char ** ) filesave_xpm ),
                                   "Save file from editor",
                                   "Save file from editor",
                                   this, SLOT ( saveButton() ), toolbar );
    PrintButton = new QToolButton ( QPixmap ( ( const char ** ) print_xpm ),
                                    "Print",
                                    "Print",
                                    this, SLOT ( printButton() ), toolbar );
    PrintButton->setEnabled ( false );
    LoadButton->setEnabled ( false );
    SaveButton->setEnabled ( false );
    toolbar->addSeparator();
    UndoButton = new QToolButton ( QPixmap ( ( const char ** ) undo_xpm ),
                                   "Undo",
                                   "Undo",
                                   this, SLOT ( undoButton() ), toolbar );
    RedoButton = new QToolButton ( QPixmap ( ( const char ** ) redo_xpm ),
                                   "Redo",
                                   "Redo",
                                   this, SLOT ( redoButton() ), toolbar );
    CutButton = new QToolButton ( QPixmap ( ( const char ** ) cut_xpm ),
                                  "Cut to clipboard",
                                  "Cut to clipboard",
                                  this, SLOT ( cutButton() ), toolbar );
    CopyButton = new QToolButton ( QPixmap ( ( const char ** ) copy_xpm ),
                                   "Copy to clipboard",
                                   "Copy to clipboard",
                                   this, SLOT ( copyButton() ), toolbar );
    PasteButton = new QToolButton ( QPixmap ( ( const char ** ) paste_xpm ),
                                    "Paste from clipboard",
                                    "Paste from clipboard",
                                    this, SLOT ( pasteButton() ), toolbar );
    UndoButton->setEnabled ( false );
    RedoButton->setEnabled ( false );
    CutButton->setEnabled ( false );
    CopyButton->setEnabled ( false );
    PasteButton->setEnabled ( false );

    ToolsMenu = new QPopupMenu ( this );

#ifdef TOOL_TOOLBAR
    toolbar = new toAllocBar ( this, "Tools", QString::null );
#else
    toolbar->addSeparator();
#endif

    int toolID = TO_TOOLS;
    int lastPriorityPix = 0;
    int lastPriorityMenu = 0;
    SQLEditor = -1;
    DefaultTool = toolID;
    QString defName = toTool::globalConfig ( CONF_DEFAULT_TOOL, "" );

    HelpMenu = new QPopupMenu ( this );
    HelpMenu->insertItem ( "C&urrent Context", TO_HELP_CONTEXT );
    HelpMenu->insertItem ( "&Contents", TO_HELP_CONTENTS );
    HelpMenu->insertSeparator();
    HelpMenu->insertItem ( "&About TOra", TO_HELP_ABOUT );
    HelpMenu->insertItem ( "&License", TO_HELP_LICENSE );
    HelpMenu->insertItem ( "&Quotes", TO_HELP_QUOTES );
    HelpMenu->setAccel ( Key_F1, TO_HELP_CONTEXT );
    if ( !toFreeware() ) {
        HelpMenu->insertSeparator();
        HelpMenu->insertItem ( "&Register", TO_HELP_REGISTER );
    }
    QPopupMenu *toolAbout = NULL;

    for ( std::map<QString, toTool *>::iterator i = tools.begin();i != tools.end();i++ ) {
        const QPixmap *pixmap = ( *i ).second->toolbarImage();
        const char *toolTip = ( *i ).second->toolbarTip();
        const char *menuName = ( *i ).second->menuItem();

        QString tmp = ( *i ).second->name();
        tmp += CONF_TOOL_ENABLE;
        if ( toTool::globalConfig ( tmp, "Yes" ).isEmpty() )
            continue;

        if ( defName == menuName )
            DefaultTool = toolID;

        int priority = ( *i ).second->priority();
        if ( priority / 100 != lastPriorityPix / 100 &&
                pixmap ) {
            toolbar->addSeparator();
            lastPriorityPix = priority;
        }
        if ( priority / 100 != lastPriorityMenu / 100 &&
                menuName ) {
            ToolsMenu->insertSeparator();
            lastPriorityMenu = priority;
        }

        if ( pixmap ) {
            if ( !toolTip )
                toolTip = "";
            NeedConnection[new QToolButton ( *pixmap,
                                             toolTip,
                                             toolTip,
                                             ( *i ).second,
                                             SLOT ( createWindow ( void ) ),
                                             toolbar ) ] = ( *i ).second;
        }

        if ( menuName ) {
            if ( pixmap )
                ToolsMenu->insertItem ( *pixmap, menuName, toolID );
            else
                ToolsMenu->insertItem ( menuName, toolID );
            ToolsMenu->setItemEnabled ( toolID, false );
        }

        if ( ( *i ).second->hasAbout() && menuName ) {
            if ( !toolAbout ) {
                toolAbout = new QPopupMenu ( this );
                HelpMenu->insertItem ( "Tools", toolAbout );
            }
            if ( pixmap )
                toolAbout->insertItem ( *pixmap, menuName, toolID + TO_ABOUT_ID_OFFSET );
            else
                toolAbout->insertItem ( menuName, toolID + TO_ABOUT_ID_OFFSET );
        }

        Tools[toolID] = ( *i ).second;

        toolID++;
    }

#ifndef TOOL_TOOLBAR
    toolbar->setStretchableWidget ( new QLabel ( "", toolbar ) );
#endif

    new QToolButton ( QPixmap ( ( const char ** ) connect_xpm ),
                      "Connect to database",
                      "Connect to database",
                      this, SLOT ( addConnection() ), toolbar );
    DisconnectButton = new QToolButton ( QPixmap ( ( const char ** ) disconnect_xpm ),
                                         "Disconnect current connection",
                                         "Disconnect current connection",
                                         this, SLOT ( delConnection() ), toolbar );
    DisconnectButton->setEnabled ( false );
    toolbar->addSeparator();
    NeedConnection[new QToolButton ( QPixmap ( ( const char ** ) commit_xpm ),
                                     "Commit connection",
                                     "Commit connection",
                                     this,SLOT ( commitButton() ),toolbar ) ] = NULL;
    NeedConnection[new QToolButton ( QPixmap ( ( const char ** ) rollback_xpm ),
                                     "Rollback connection",
                                     "Rollback connection",
                                     this,SLOT ( rollbackButton() ),toolbar ) ] = NULL;
    toolbar->addSeparator();
    ConnectionSelection = new QComboBox ( toolbar );
    ConnectionSelection->setFixedWidth ( 200 );
    ConnectionSelection->setFocusPolicy ( NoFocus );
    connect ( ConnectionSelection, SIGNAL ( activated ( int ) ), this, SLOT ( changeConnection() ) );

    menuBar() ->insertItem ( "&Tools", ToolsMenu, TO_TOOLS_MENU );

    WindowsMenu = new QPopupMenu ( this );
    WindowsMenu->setCheckable ( true );
    connect ( WindowsMenu, SIGNAL ( aboutToShow() ), this, SLOT ( windowsMenu() ) );
    menuBar() ->insertItem ( "&Window", WindowsMenu, TO_WINDOWS_MENU );

    menuBar() ->insertSeparator();

    menuBar() ->insertItem ( "&Help", HelpMenu, TO_HELP_MENU );

    char buffer[100];
    sprintf ( buffer, DEFAULT_TITLE, TOVERSION );
    setCaption ( buffer );

#ifdef TO_KDE
    KDockWidget *mainDock = createDockWidget ( buffer, QPixmap ( ( const char ** ) toramini_xpm ) );
    Workspace = new QWorkspace ( mainDock );
    mainDock->setWidget ( Workspace );
    setView ( mainDock );
    setMainDockWidget ( mainDock );
    mainDock->setEnableDocking ( KDockWidget::DockNone );
#else
    Workspace = new QWorkspace ( this );
    setCentralWidget ( Workspace );
#endif
    setIcon ( QPixmap ( ( const char ** ) toramini_xpm ) );

    statusBar() ->message ( "Ready" );
    menuBar() ->setItemEnabled ( TO_CLOSE_CONNECTION, false );
    menuBar() ->setItemEnabled ( TO_FILE_COMMIT, false );
    menuBar() ->setItemEnabled ( TO_FILE_ROLLBACK, false );
    menuBar() ->setItemEnabled ( TO_FILE_CLEARCACHE, false );
    DisconnectButton->setEnabled ( false );

    for ( std::map<QToolButton *, toTool *>::iterator j = NeedConnection.begin();
            j != NeedConnection.end();j++ )
        ( *j ).first->setEnabled ( false );

    connect ( menuBar(), SIGNAL ( activated ( int ) ), this, SLOT ( commandCallback ( int ) ) );

    RowLabel = new QLabel ( statusBar() );
    statusBar() ->addWidget ( RowLabel, 0, true );
    RowLabel->setMinimumWidth ( 60 );
    RowLabel->hide();

    ColumnLabel = new QLabel ( statusBar() );
    statusBar() ->addWidget ( ColumnLabel, 0, true );
    ColumnLabel->setMinimumWidth ( 60 );
    ColumnLabel->hide();

    QToolButton *dispStatus = new toPopupButton ( statusBar() );
    dispStatus->setIconSet ( QPixmap ( ( const char ** ) up_xpm ) );
    statusBar() ->addWidget ( dispStatus, 0, true );
    StatusMenu = new QPopupMenu ( dispStatus );
    dispStatus->setPopup ( StatusMenu );
    connect ( StatusMenu, SIGNAL ( aboutToShow() ),
              this, SLOT ( statusMenu() ) );
    connect ( StatusMenu, SIGNAL ( activated ( int ) ), this, SLOT ( commandCallback ( int ) ) );

    toolID = TO_TOOLS;
    for ( std::map<QString, toTool *>::iterator k = tools.begin();k != tools.end();k++ ) {
        ( *k ).second->customSetup ( toolID );
        toolID++;
    }
    Search = NULL;

    if ( !toTool::globalConfig ( CONF_MAXIMIZE_MAIN, "Yes" ).isEmpty() )
        showMaximized();
    show();

    QString welcome;

    do {
        welcome = toCheckLicense ( false );
    } while ( welcome.isNull() );

    toStatusMessage ( welcome, true );

    connect ( &Poll, SIGNAL ( timeout() ), this, SLOT ( checkCaching() ) );

    try {
        toNewConnection newConnection ( this, "First connection", true );

        toConnection *conn;

        do {
            conn = NULL;
            if ( newConnection.exec() ) {
                conn = newConnection.makeConnection();
            } else {
                break;
            }
        } while ( !conn );

        if ( conn )
            addConnection ( conn );
    }
    TOCATCH
    connect ( toMainWidget() ->workspace(), SIGNAL ( windowActivated ( QWidget * ) ),
              this, SLOT ( windowActivated ( QWidget * ) ) );
}
Example #4
0
toProject::toProject(toProjectTemplateItem *top, QWidget *parent)
    : QWidget(parent)
{
    Root = top;

    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->setSpacing(0);
    vbox->setContentsMargins(0, 0, 0, 0);

    QToolBar *toolbar = toAllocBar(this, tr("SQL project"));
    vbox->addWidget(toolbar);

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(addproject_xpm))),
                       tr("Add file to project"),
                       this,
                       SLOT(addFile()));

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(filesave_xpm))),
                       tr("Save project"),
                       this,
                       SLOT(saveProject()));

    DelFile = toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(trash_xpm))),
                                 tr("Remove file from project"),
                                 this,
                                 SLOT(delFile()));

    toolbar->addSeparator();

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(new_xpm))),
                       tr("Add new subproject"),
                       this,
                       SLOT(newProject()));

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(sql_xpm))),
                       tr("Generate SQL for this project"),
                       this,
                       SLOT(generateSQL()));

    toolbar->addSeparator();

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(up_xpm))),
                       tr("Move up in project"),
                       this,
                       SLOT(moveUp()));

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(down_xpm))),
                       tr("Move down in project"),
                       this,
                       SLOT(moveDown()));

    toolbar->addWidget(new toSpacer());

    Project = new toListView(this);
    Project->addColumn(tr("File"));
    Project->addColumn(tr("Size"));
    Project->setSelectionMode(toTreeWidget::Single);
    Project->setRootIsDecorated(true);
    Project->setSorting(0);
    connect(Project,
            SIGNAL(selectionChanged()),
            this,
            SLOT(selectionChanged()));
    vbox->addWidget(Project);

    setLayout(vbox);
    update();
}
toAlert::toAlert(QWidget *main, toConnection &connection)
        : toToolWidget(AlertTool, "alert.html", main, connection, "toAlert")
        , Connection(connection)
{
    QToolBar *toolbar = toAllocBar(this, tr("Alert Messenger"));
    layout()->addWidget(toolbar);

    QString def;
    try
    {
        toQList lst = toQuery::readQuery(connection, SQLHost);
        def += toShift(lst);
        if (!def.isEmpty())
            def += QString::fromLatin1(":");
    }
    catch (...)
        {}
    def += connection.user();

    toolbar->addWidget(
        new QLabel(tr("Registered") + " ", toolbar));

    Registered = new QComboBox(toolbar);
    Registered->addItem(def);
    Registered->setEditable(true);
    Registered->setDuplicatesEnabled(false);
    Registered->setCurrentIndex(0);
    connect(Registered, SIGNAL(activated(int)), this, SLOT(add()));
    toolbar->addWidget(Registered);

    AddNames.insert(AddNames.end(), def);

    addAct =
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(commit_xpm))),
                           tr("Register current"),
                           this,
                           SLOT(add()));
    addAct->setShortcut(Qt::ALT + Qt::Key_R);

    removeAct =
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(trash_xpm))),
                           tr("Remove registered"),
                           this,
                           SLOT(remove()));
    removeAct->setShortcut(Qt::CTRL + Qt::Key_Backspace);

    toolbar->addSeparator();

    toolbar->addWidget(
        new QLabel(tr("Name") + " ", toolbar));

    toolbar->addWidget(
        Name = new QLineEdit(toolbar));
    Name->setText(def);
    connect(Name, SIGNAL(returnPressed()), this, SLOT(send()));

    toolbar->addWidget(
        new QLabel(tr("Message") + " ", toolbar));

    Message = new QLineEdit(toolbar);
    connect(Message, SIGNAL(returnPressed()), this, SLOT(send()));
    Message->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
                                       QSizePolicy::Minimum));

    toolbar->addWidget(Message);

    memoEditAct =
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(toworksheet_xpm))),
                           tr("Edit message in memo"),
                           this,
                           SLOT(memo()));
    memoEditAct->setShortcut(Qt::CTRL + Qt::Key_M);

    sendAct =
        toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(return_xpm))),
                           tr("Send alert"),
                           this,
                           SLOT(send()));
    sendAct->setShortcut(Qt::CTRL + Qt::Key_Return);

    connect(&Timer, SIGNAL(timeout()), this, SLOT(poll()));
    Timer.start(TIMEOUT*1000);

    Alerts = new toListView(this);
    Alerts->addColumn(tr("Time"));
    Alerts->addColumn(tr("Name"));
    Alerts->addColumn(tr("Message"));
    layout()->addWidget(Alerts);

    ToolMenu = NULL;
    connect(toMainWidget()->workspace(), SIGNAL(subWindowActivated(QMdiSubWindow *)),
            this, SLOT(windowActivated(QMdiSubWindow *)));

    State = Started;
    try
    {
        toThread *thread = new toThread(new pollTask(*this));
        thread->start();
    }
    catch (...)
    {
        toStatusMessage(tr("Failed to start polling thread, try closing "
                           "some other tools and restart Alert Messenger"));
    }

    setFocusProxy(Message);
}
toBackup::toBackup(toTool* tool, QWidget *main, toConnection &connection)
        : toToolWidget(*tool, "backup.html", main, connection, "toBackup")
        , tool_(tool)
{
    QToolBar *toolbar = toAllocBar(this, tr("Backup Manager"));
    layout()->addWidget(toolbar);

    updateAct = new QAction(QPixmap(const_cast<const char**>(refresh_xpm)),
                            tr("Update"), this);
    updateAct->setShortcut(QKeySequence::Refresh);
    connect(updateAct, SIGNAL(triggered()), this, SLOT(refresh(void)));
    toolbar->addAction(updateAct);

    toolbar->addWidget(new toSpacer());

    new toChangeConnection(toolbar, TO_TOOLBAR_WIDGET_NAME);

    Tabs = new QTabWidget(this);
    layout()->addWidget(Tabs);

    QWidget *box = new QWidget(Tabs);
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->setSpacing(0);
    vbox->setContentsMargins(0, 0, 0, 0);
    box->setLayout(vbox);

    vbox->addWidget(new QLabel(tr("Logswitches per day and hour"), box));
    LogSwitches = new toResultTableView(true, false, box);
    LogSwitches->setSQL(SQLLogSwitches);
    vbox->addWidget(LogSwitches);
    Tabs->addTab(box, tr("Redo Switches"));

    LogHistory = new toResultTableView(true, false, Tabs);
    LogHistory->setSQL(SQLLogHistory);
    Tabs->addTab(LogHistory, tr("Archived Logs"));

    box = new QWidget(Tabs);
    vbox = new QVBoxLayout;
    vbox->setSpacing(0);
    vbox->setContentsMargins(0, 0, 0, 0);
    box->setLayout(vbox);

    LastLabel = new QLabel(box);
    vbox->addWidget(LastLabel);
    LastBackup = new toResultTableView(true, false, box);
    vbox->addWidget(LastBackup);
    LastBackup->setSQL(SQLLastBackup);
    Tabs->addTab(box, tr("Last Backup"));

    CurrentBackup = new toResultTableView(true, false, Tabs);
    CurrentBackup->setSQL(SQLCurrentBackup);
    Tabs->addTab(CurrentBackup, tr("Backup Progress"));

    ToolMenu = NULL;
    connect(toMainWidget()->workspace(), SIGNAL(subWindowActivated(QMdiSubWindow *)),
            this, SLOT(windowActivated(QMdiSubWindow *)));

    refresh();

    setFocusProxy(Tabs);
}
toProfiler::toProfiler(QWidget *parent, toConnection &connection)
        : toToolWidget(ProfilerTool, "toprofiler.html", parent, connection, "toProfiler")
{
    QToolBar *toolbar = toAllocBar(this, tr("PL/SQL Profiler"));
    layout()->addWidget(toolbar);

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(refresh_xpm))),
                       tr("Refresh list"),
                       this,
                       SLOT(refresh()));

    toolbar->addSeparator();

    toolbar->addWidget(
        new QLabel(tr("Repeat run") + " ", toolbar));

    Repeat = new QSpinBox(toolbar);
    Repeat->setValue(5);
    Repeat->setMaximum(1000);
    toolbar->addWidget(Repeat);

    toolbar->addSeparator();

    toolbar->addWidget(new QLabel(tr("Comment") + " ", toolbar));

    Comment = new QLineEdit(toolbar);
    Comment->setText(tr("Unknown"));
    toolbar->addWidget(Comment);

    toolbar->addSeparator();

#if 0
    Background = new QToolButton(toolbar);
    Background->setToggleButton(true);
    Background->setIconSet(QIcon(QPixmap(const_cast<const char**>(background_xpm))));
    QToolTip::add
    (Background, tr("Run profiling in background"));

    toolbar->addSeparator();
#endif

    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(execute_xpm))),
                       tr("Execute current profiling"),
                       this,
                       SLOT(execute()));

    toolbar->addWidget(new toSpacer());

    new toChangeConnection(toolbar, TO_TOOLBAR_WIDGET_NAME);

    Tabs = new QTabWidget(this);
    layout()->addWidget(Tabs);

    Script = new toWorksheetWidget(Tabs, NULL, connection);
    Tabs->addTab(Script, tr("Script"));

    Result = new QSplitter(Tabs);
    Tabs->addTab(Result, tr("Result"));

    QWidget *box = new QWidget(Result);
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->setSpacing(0);
    vbox->setContentsMargins(0, 0, 0, 0);
    box->setLayout(vbox);
    Run = new QComboBox(box);
    vbox->addWidget(Run);
    QSplitter *vsplit = new QSplitter(Qt::Vertical, box);
    vbox->addWidget(vsplit);
    Info = new toResultItem(2, vsplit);
    Info->setSQL(SQLRunInfo);
    connect(Run, SIGNAL(activated(int)), this, SLOT(changeRun()));
    Units = new toProfilerUnits(vsplit);
    Units->setReadAll(true);
    Units->setSelectionMode(toTreeWidget::Single);
    connect(Units, SIGNAL(selectionChanged()), this, SLOT(changeObject()));
    Lines = new toProfilerSource(Result);
    Lines->setReadAll(true);
    connect(Lines, SIGNAL(done()), this, SLOT(calcTotals()));

    LastUnit = CurrentRun = 0;
//     show();

    try
    {
        toQuery query(connection, SQLProfilerDetect);
    }
    catch (const QString &)
    {
        int ret = TOMessageBox::warning(this,
                                        tr("Profiler tables doesn't exist"),
                                        tr("Profiler tables doesn't exist. Should TOra\n"
                                           "try to create them in the current schema?"),
                                        tr("&Yes"), tr("&No"), QString::null, 0, 1);
        if (ret == 0)
        {
            try
            {
                connection.execute(SQLProfilerRuns);
                connection.execute(SQLProfilerUnits);
                connection.execute(SQLProfilerData);
                connection.execute(SQLProfilerNumber);
            }
            catch (const QString &str)
            {
                toStatusMessage(str);
                QTimer::singleShot(1, this, SLOT(noTables()));
                return ;
            }
        }
        else
        {
            QTimer::singleShot(1, this, SLOT(noTables()));
            return ;
        }
    }

    refresh();
}
toPLSQLEditor::toPLSQLEditor(QWidget *main, toConnection &connection)
        : toToolWidget(PLSQLEditorTool, "plsqleditor.html", main, connection, "toPLSQLEditor")
{
    createActions();
    QToolBar *toolbar = toAllocBar(this, tr("PLSQLEditor"));
    layout()->addWidget(toolbar);

    toolbar->addAction(refreshAct);

    toolbar->addSeparator();

    Schema = new QComboBox(toolbar);
    Schema->setObjectName("PLSQLEditorSchemaCombo");
    toolbar->addWidget(Schema);
    connect(Schema,
            SIGNAL(activated(int)),
            this,
            SLOT(changeSchema(int)));

    toolbar->addSeparator();

    toolbar->addAction(newSheetAct);
    toolbar->addAction(compileAct);
    toolbar->addAction(compileWarnAct);
    // only show static check button when static checker is specified
    if (!toConfigurationSingle::Instance().staticChecker().isEmpty())
    {
        toolbar->addAction(checkCodeAct);
    }

    toolbar->addSeparator();

    toolbar->addAction(nextErrorAct);
    toolbar->addAction(previousErrorAct);
    toolbar->addAction(describeAct);

    toolbar->addWidget(new toSpacer());

    splitter = new QSplitter(Qt::Horizontal, this);
    layout()->addWidget(splitter);

    Objects = new QTreeView(splitter);
    CodeModel = new toCodeModel(Objects);
    Objects->setModel(CodeModel);
    QString selected = Schema->currentText();
    if (!selected.isEmpty())
        CodeModel->refresh(connection, selected);
    // even better (?) for reopening the tabs
//     connect(Objects->selectionModel(),
//             SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
//             this,
//             SLOT(changePackage(const QModelIndex &, const QModelIndex &)));
    connect(Objects, SIGNAL(doubleClicked(const QModelIndex &)),
            this, SLOT(changePackage(const QModelIndex &)));

    splitter->addWidget(Objects);

    Editors = new QTabWidget(this);
#if QT_VERSION >= 0x040500
    Editors->setTabsClosable(true);
    connect(Editors, SIGNAL(tabCloseRequested(int)),
            this, SLOT(closeEditor(int)));
#endif
    splitter->addWidget(Editors);
    Editors->setTabPosition(QTabWidget::North);

    QToolButton *closeButton = new toPopupButton(Editors);
    closeButton->setIcon(QPixmap(const_cast<const char**>(close_xpm)));
    closeButton->setFixedSize(20, 18);
    // HACK: disable closing the editor tabs with the global shortcut.
    // it raises: "QAction::eventFilter: Ambiguous shortcut overload: Ctrl+W"
    // on some systems. But it rejects to close unfinished.unsaved work.
    // - <*****@*****.**>
    closeButton->setShortcut(QKeySequence::Close);
    connect(closeButton, SIGNAL(clicked()), this, SLOT(closeEditor()));

    Editors->setCornerWidget(closeButton);

    setFocusProxy(Editors);
    newSheet();

    ToolMenu = NULL;
    connect(toMainWidget()->workspace(), SIGNAL(subWindowActivated(QMdiSubWindow *)),
            this, SLOT(windowActivated(QMdiSubWindow *)));

    QSettings s;
    s.beginGroup("toPLSQLEditor");
    splitter->restoreState(s.value("splitter").toByteArray());
    s.endGroup();

    conn = &connection;

    refresh();
}
toSGATrace::toSGATrace(QWidget *main, toConnection &connection)
        : toToolWidget(SGATraceTool, "trace.html", main, connection, "toSGATrace")
{
    QToolBar *toolbar = toAllocBar(this, tr("SGA trace"));
    layout()->addWidget(toolbar);

    FetchAct = new QAction(QPixmap(const_cast<const char**>(refresh_xpm)),
                           tr("Fetch statements in SGA"), this);
    FetchAct->setShortcut(QKeySequence::Refresh);
    connect(FetchAct, SIGNAL(triggered()), this, SLOT(refresh(void)));
    toolbar->addAction(FetchAct);

    toolbar->addSeparator();

    QLabel * labSchema = new QLabel(tr("Schema") + " ", toolbar);
    toolbar->addWidget(labSchema);

    Schema = new toResultCombo(toolbar);
    Schema->additionalItem(tr("Any"));
    Schema->setSelected(connection.user().toUpper());
    Schema->query(toSQL::sql(toSQL::TOSQL_USERLIST));
    toolbar->addWidget(Schema);

    connect(Schema, SIGNAL(activated(const QString &)), this, SLOT(changeSchema(const QString &)));

    toolbar->addSeparator();

    QLabel * labRef = new QLabel(tr("Refresh") + " ", toolbar);
    toolbar->addWidget(labRef);
    connect(Refresh = toRefreshCreate(toolbar, TO_TOOLBAR_WIDGET_NAME),
            SIGNAL(activated(const QString &)), this, SLOT(changeRefresh(const QString &)));
    toolbar->addWidget(Refresh);

    toolbar->addSeparator();

    QLabel * labType = new QLabel(tr("Type") + " ", toolbar);
    toolbar->addWidget(labType);

    Type = new QComboBox(toolbar);
    Type->addItem(tr("SGA"));
    Type->addItem(tr("Long operations"));
    toolbar->addWidget(Type);

    toolbar->addSeparator();

    QLabel * labSelect = new QLabel(tr("Selection") + " ", toolbar);
    toolbar->addWidget(labSelect);

    Limit = new QComboBox(toolbar);
    Limit->addItem(tr("All"));
    Limit->addItem(tr("Unfinished"));
    Limit->addItem(tr("1 execution, 1 parse"));
    Limit->addItem(tr("Top executions"));
    Limit->addItem(tr("Top sorts"));
    Limit->addItem(tr("Top diskreads"));
    Limit->addItem(tr("Top buffergets"));
    Limit->addItem(tr("Top rows"));
    Limit->addItem(tr("Top sorts/exec"));
    Limit->addItem(tr("Top diskreads/exec"));
    Limit->addItem(tr("Top buffergets/exec"));
    Limit->addItem(tr("Top rows/exec"));
    Limit->addItem(tr("Top buffers/row"));
    toolbar->addWidget(Limit);

    toolbar->addWidget(new toSpacer());

    new toChangeConnection(toolbar, TO_TOOLBAR_WIDGET_NAME);

    QSplitter *splitter = new QSplitter(Qt::Vertical, this);
    layout()->addWidget(splitter);

    Trace = new toResultTableView(false, false, splitter);

    QList<int> list;
    list.append(75);
    splitter->setSizes(list);

    Trace->setReadAll(true);
    Statement = new toSGAStatement(splitter);

    connect(Trace, SIGNAL(selectionChanged()),
            this, SLOT(changeItem()));
    CurrentSchema = connection.user().toUpper();
    updateSchemas();

    try
    {
        connect(timer(), SIGNAL(timeout(void)), this, SLOT(refresh(void)));
        toRefreshParse(timer(), toConfigurationSingle::Instance().refresh());
    }
    TOCATCH;

    setFocusProxy(Trace);
}