void toListView::editPrint(void)
{
#if 0
    TOPrinter printer;

    std::map<int, int> PageColumns;
    std::map<int, toTreeWidgetItem *> PageItems;

    int column = 0;
    int tree = rootIsDecorated() ? treeStepSize() : 0;
    int page = 1;
    PageColumns[1] = 0;
    toTreeWidgetItem *item = PageItems[1] = firstChild();

    printer.setCreator(tr(TOAPPNAME));
    QPainter painter(&printer);

    while ((item = printPage(&printer, &painter, item, column, tree, page++, false)))
    {
        PageColumns[page] = column;
        PageItems[page] = item;
    }

    printer.setMinMax(1, page - 1);
    printer.setFromTo(1, page - 1);
    if (printer.setup())
    {
        QList<int> pages;
        for (int i = printer.fromPage(); i <= printer.toPage() || (printer.toPage() == 0 && i < page); i++)
            pages += i;

        for (QList<int>::iterator pageit = pages.begin(); pageit != pages.end(); pageit++)
        {
            page = *pageit;
            item = PageItems[page];
            column = PageColumns[page];

            printPage(&printer, &painter, item, column, tree, page, true);
            printer.newPage();
            painter.resetXForm();
            qApp->processEvents();
            QString str = tr("Printing page %1").arg(page);
            toStatusMessage(str, false, false);
        }
        painter.end();
        toStatusMessage(tr("Done printing"), false, false);
    }
#endif
}
void toTemplateSQLObject::poll(void)
{
    try
    {
        if (QApplication::activeModalWidget()) // Template is never in widget
            return ;
        if (Query && Query->poll())
        {
            toQDescList desc = Query->describe();
            while (Query->poll() && !Query->eof())
            {
                toTreeWidgetItem *item = Parent->createChild(Query->readValue());
                for (unsigned int j = 1;j < desc.size();j++)
                    item->setText(j, Query->readValue());
            }
            if (Query->eof())
            {
                delete Query;
                Query = NULL;
                Poll.stop();
            }
        }
    }
    catch (const QString &str)
    {
        delete Query;
        Query = NULL;
        Poll.stop();
        toStatusMessage(str);
    }
}
void toAlert::poll(void)
{
    try
    {
        toLocker lock (Lock)
        ;
        if (!Error.isNull())
        {
            toStatusMessage(Error);
            Error = QString::null;
        }
        std::list<QString>::iterator i = NewAlerts.begin();
        std::list<QString>::iterator j = NewMessages.begin();
        while (i != NewAlerts.end() && j != NewMessages.end())
        {
            toTreeWidgetItem *item = new toResultViewMLine(Alerts, NULL, toNow(connection()));
            item->setText(1, *i);
            item->setText(2, *j);
            i++;
            j++;
        }
        NewAlerts.clear();
        NewMessages.clear();
    }
    TOCATCH
}
void toProfiler::execute(void)
{
    try
    {
        QString exc;
        exc = toSQL::string(SQLStartProfiler, connection());
        for (int i = 0;i < Repeat->value();i++)
        {
            exc += Script->editor()->text();
            exc += QString::fromLatin1("\n");
        }
        exc += toSQL::string(SQLStopProfiler, connection());

        toQuery query(connection(),
                      exc,
                      Comment->text(),
                      tr("%1 runs").arg(Repeat->value()));
        CurrentRun = query.readValue().toInt();
        if (CurrentRun > 0)
        {
            Tabs->setCurrentIndex(Tabs->indexOf(Result));
            refresh();
        }
        else
            toStatusMessage(tr("Something went wrong collecting statistics"));
    }
    TOCATCH
}
Example #5
0
 void toSetSessionType(const QString &str)
 {
     QStyle *style = QStyleFactory::create(str);
     if (style)
         qApp->setStyle(style);
     else
         toStatusMessage(qApp->translate("toSetSessionType", "Failed to find style %1").arg(str));
 }
bool toPLSQLEditor::viewSource(const QString &schema, const QString &name, const QString &type,
                               int line, bool setCurrent)
{
    try
    {
        toPLSQLWidget *editor = NULL;
        int row = line - 1;
        int col = 0;
        for (int i = 0; i < Editors->count(); i++)
        {
            QString tabname = editorName(schema, name, type);
            toPLSQLWidget *te = dynamic_cast<toPLSQLWidget *>(Editors->widget(i));
            te->setObjectName(tabname);
            if (Editors->tabText(Editors->indexOf(te)) == tabname)
            {
                editor = te;
                break;
            }
            if (Editors->tabText(Editors->indexOf(te)) == tr("Unknown") && !te->editor()->isModified())
                editor = te;
        }
        if (!editor)
        {
            editor = new toPLSQLWidget(Editors);
            Editors->addTab(editor, editorName(editor));
            editor->setObjectName(editorName(editor));
        }
        else
        {
            editor->editor()->getCursorPosition(&row, &col);
        }
        // set pointer to this PLSQLEditor to be used when saving packages/types
        editor->editor()->setEditor(this);
        if (editor->editor()->lines() <= 1)
        {
            editor->editor()->setData(schema, type, name);
            editor->editor()->readData(connection()/*, StackTrace*/);
            Editors->setTabText(Editors->indexOf(editor), editorName(editor));
            editor->setObjectName(editorName(editor));
            if (editor->editor()->hasErrors())
                Editors->setTabIcon(Editors->indexOf(editor),
                                    QIcon(QPixmap(const_cast<const char**>(nextbug_xpm))));
            else
                Editors->setTabIcon(Editors->indexOf(editor), QIcon());
        }
        Editors->setCurrentIndex(Editors->indexOf(editor));
        editor->editor()->setCursorPosition(row, col);
        if (setCurrent)
            editor->editor()->setCurrent(line - 1);
        editor->setFocus();
        return true;
    }
    catch (const QString &str)
    {
        toStatusMessage(str);
        return false;
    }
}
void toTemplateEdit::updateFromMap(void)
{
    try
    {
        while (Templates->firstChild())
            delete Templates->firstChild();
        toTreeWidgetItem *last = NULL;
        int lastLevel = 0;
        QStringList lstCtx;
        for (std::map<QString, QString>::iterator i = TemplateMap.begin();i != TemplateMap.end();i++)
        {
            QStringList ctx = (*i).first.split(":");
            if (last)
            {
                while (last && lastLevel >= int(ctx.count()))
                {
                    last = last->parent();
                    lastLevel--;
                }
                while (last && lastLevel >= 0 && !toCompareLists(lstCtx, ctx, (unsigned int)lastLevel))
                {
                    last = last->parent();
                    lastLevel--;
                }
            }
            if (lastLevel < 0)
                throw qApp->translate("toTemplateEdit", "Internal error, lastLevel < 0");
            while (lastLevel < int(ctx.count()) - 1)
            {
                if (last)
                    last = new toTreeWidgetItem(last, ctx[lastLevel]);
                else
                    last = new toTreeWidgetItem(Templates, ctx[lastLevel]);
                last->setOpen(true);
                lastLevel++;
            }
            if (last)
                last = new toTreeWidgetItem(last, ctx[lastLevel]);
            else
                last = new toTreeWidgetItem(Templates, ctx[lastLevel]);
            last->setOpen(true);
            if (i == LastTemplate)
                last->setSelected(true);
            lstCtx = ctx;
            lastLevel++;
        }
    }
    catch (const QString &str)
    {
        toStatusMessage(str);
        reject();
    }
}
void toResultStorage::poll(void)
{
    try
    {
        if (!toCheckModal(this))
            return ;
        if (Tablespaces && Tablespaces->poll())
        {
            int cols = Tablespaces->describe().size();
            while (Tablespaces->poll() && !Tablespaces->eof())
            {
                for (int i = 0;i < cols && !Tablespaces->eof();i++)
                    toPush(TablespaceValues, QString(Tablespaces->readValue()));
            }
            updateList();
            if (Tablespaces->eof())
            {
                delete Tablespaces;
                Tablespaces = NULL;
            }
        }

        if (Files && Files->poll())
        {
            int cols = Files->describe().size();
            while (Files->poll() && !Files->eof())
            {
                for (int i = 0;i < cols && !Files->eof();i++)
                    toPush(FileValues, QString(Files->readValue()));
            }
            if (Files->eof())
            {
                delete Files;
                Files = NULL;
            }
        }

        if (Tablespaces == NULL && Files == NULL)
        {
            updateList();
            Poll.stop();
        }
    }
    catch (const QString &exc)
    {
        delete Tablespaces;
        Tablespaces = NULL;
        delete Files;
        Files = NULL;
        Poll.stop();
        toStatusMessage(exc);
    }
}
Example #9
0
void toProjectTemplateItem::setup(const QString &name, bool open)
{
    Order = -1;
    setFilename(name);
    if (project() && !Filename.isEmpty() && open)
    {
        try
        {
            // read in Filename (encoded according to locale settings)
            QString data = toReadFile(Filename);
            QStringList files = data.split(QRegExp(QString::fromLatin1("\n")));
            toProjectTemplateItem *last = NULL;
            for (int i = 0; i < files.count(); i++)
                last = new toProjectTemplateItem(this, last, files[i]);
        }
        catch (const QString &exc)
        {
            toStatusMessage(exc);
        }
    }
}
void toChangeConnection::changeConnection(QAction *act)
{
    // the act of clicking the menu will invert the checked flag
    if (!act->isChecked())
        return;

    std::list<QString> cons = toMainWidget()->connections();

    try
    {
        for (std::list<QString>::iterator i = cons.begin(); i != cons.end(); i++)
        {
            if (act->text() == (*i))
            {

                QWidget *cur = parentWidget();
                while (cur)
                {
                    toToolWidget *tool = dynamic_cast<toToolWidget *>(cur);

                    if (tool)
                    {
                        tool->setConnection(toMainWidget()->connection(*i));
                        toMainWidget()->windowActivated(qobject_cast<QMdiSubWindow*>(tool->parent()));
                        toMainWidget()->changeConnection();
                        return;
                    }
                    cur = cur->parentWidget();
                }
                throw tr("Couldn't find parent connection. Internal error.");
            }
        }
    }
    TOCATCH;

    toStatusMessage("Couldn't find selected connection");
}
toSMTP::toSMTP(const QString &from,
               const QString &to,
               const QString &subject,
               const QString &body)
{
    From      = from;
    Recipient = to;
    State     = Init;
    Stream    = 0;

    Socket = new QTcpSocket(this);
    connect(Socket, SIGNAL(readyRead()),
            this, SLOT(readyRead()));
    connect(Socket, SIGNAL(connected()),
            this, SLOT(connected()));

    Message = QString::fromLatin1("From: ") + from +
              QString::fromLatin1("\nTo: ") + to +
              QString::fromLatin1("\nSubject: ") + subject +
              QString::fromLatin1("\n\n") + body + "\n";
    Message.replace(QRegExp(QString::fromLatin1("\n")),
                    QString::fromLatin1("\r\n"));
    Message.replace(QRegExp(QString::fromLatin1("\r\n.\r\n")),
                    QString::fromLatin1("\r\n..\r\n"));

    QString server(toConfigurationSingle::Instance().smtp());
    int port = toConfigurationSingle::Instance().smtpPort();

    if (server.isNull() || server.isEmpty())
        toStatusMessage("No SMTP Server configured. Please check the preferences dialog.");
    else
    {
        Socket->connectToHost(server, port);
        Stream = new QTextStream(Socket);
    }
}
void toSMTP::readyRead()
{
    // SMTP is line-oriented
    if (!Socket->canReadLine())
        return ;

    QString responseLine;
    do
    {
        responseLine = Socket->readLine();
        Response += responseLine;
    }
    while (Socket->canReadLine() && responseLine[3] != ' ');
    responseLine.truncate(3);

    if (State == Init && responseLine[0] == '2')
    {
        // banner was okay, let's go on
        *Stream << "HELO there\r\n";
        State = Mail;
    }
    else if (State == Mail && responseLine[0] == '2')
    {
        // HELO response was okay (well, it has to be)
        *Stream << "MAIL FROM: <" << From << ">\r\n";
        State = Rcpt;
    }
    else if (State == Rcpt && responseLine[0] == '2')
    {
        *Stream << "RCPT TO: <" << Recipient << ">\r\n";
        State = Data;
    }
    else if (State == Data && responseLine[0] == '2')
    {
        *Stream << "DATA\r\n";
        State = Body;
    }
    else if (State == Body && responseLine[0] == '3')
    {
        *Stream << Message << ".\r\n";
        State = Quit;
    }
    else if (State == Quit && responseLine[0] == '2')
    {
        *Stream << "QUIT\r\n";
        // here, we just close.
        State = Close;
        toStatusMessage(tr("Message sent"), false, false);
    }
    else if (State == Close)
    {
        delete this;
    }
    else
    {
        toStatusMessage(tr("Unexpected reply from SMTP server:\n\n") +
                        Response);
        State = Close;
    }

    Response = "";
}
void toResultField::poll(void)
{
    try
    {
        if (!toCheckModal(this))
            return ;
        if (Query && Query->poll())
        {
            while (Query->poll() && !Query->eof())
            {
                // For some MySQL statements (say "show create function aaa.bbb") more than one column is returned
                // and it is not possible to control that (or I do not know how to do it). This workaround will get
                // a required field (say 3rd) from a result set returned.
                int fieldNo = whichResultField; // by default this would be set to 1 in constructor
                while (fieldNo > 1)
                {
                    fieldNo--;
                    Query->readValue();
                }
                Unapplied += Query->readValue();

                // Read any remaining columns for queries with specific field to fetch.
                // This is primarily used for MySQL statements like "show create..." which
                // return different uncontrollable number of fields for different users.
                // If remaining fields are not fetched polling thread will loop.
                if (whichResultField > 1)
                    while (!Query->eof())
                        Query->readValue();
            }
            if (Unapplied.length() > THRESHOLD)
            {
                append(Unapplied);
                Unapplied = QString::null;
            }
            if (Query->eof())
            {
                delete Query;
                Query = NULL;
                Poll.stop();
                try
                {
                    // Code is formatted if it is set in preferences (Preferences->Editor Extensions) to
                    // indent (format) a read only code AND! if it is not a MySQL code because current
                    // TOra code parser/indenter does not work correctly with MySQL code (routines)
                    if (toConfigurationSingle::Instance().autoIndentRo() && !toIsMySQL(connection()))
                        setText(toSQLParse::indent(text() + Unapplied));
                    else
                        append(Unapplied);
                }
                TOCATCH
                Unapplied = QString::null;
            }
        }
    }
    catch (const QString &exc)
    {
        delete Query;
        Query = NULL;
        Poll.stop();
        toStatusMessage(exc);
    }
}
Example #14
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 * ) ) );
}
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);
}
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();
}
void toSMTP::connected()
{
    toStatusMessage(tr("Connected to %1").arg(Socket->peerName()), false, false);
}
void toSGATrace::refresh(void)
{
    try
    {
        updateSchemas();

        QString select;
        switch (Type->currentIndex())
        {
        case 0:
            select = toSQL::string(SQLSGATrace, connection());
            break;
        case 1:
            select = toSQL::string(SQLLongOps, connection());
            break;
        default:
            toStatusMessage(tr("Unknown type of trace"));
            return ;
        }
        if (!CurrentSchema.isEmpty())
            select.append(QString::fromLatin1("\n   and b.username = :f1<char[101]>"));

        QString order;
        switch (Limit->currentIndex())
        {
        case 0:
            break;
        case 1:
            if (Type->currentIndex() == 1)
                select += QString::fromLatin1("\n   and b.sofar != b.totalwork");
            else
                toStatusMessage(tr("Unfinished is only available for long operations"));
            break;
        case 2:
            select += QString::fromLatin1("\n   and a.executions = 1 and a.parse = 1");
            break;
        case 3:
            order = QString::fromLatin1("a.Executions");
            break;
        case 4:
            order = QString::fromLatin1("a.Sorts");
            break;
        case 5:
            order = QString::fromLatin1("a.Disk_Reads");
            break;
        case 6:
            order = QString::fromLatin1("a.Buffer_Gets");
            break;
        case 7:
            order = QString::fromLatin1("a.Rows_Processed");
            break;
        case 8:
            order = QString::fromLatin1("DECODE(a.Executions,0,0,a.Sorts/a.Executions)");
            break;
        case 9:
            order = QString::fromLatin1("DECODE(a.Executions,0,0,a.Disk_Reads/a.Executions)");
            break;
        case 10:
            order = QString::fromLatin1("DECODE(a.Executions,0,0,a.Buffer_Gets/a.Executions)");
            break;
        case 11:
            order = QString::fromLatin1("DECODE(a.Executions,0,0,a.Rows_Processed/a.Executions)");
            break;
        case 12:
            order = QString::fromLatin1("DECODE(a.Rows_Processed,0,0,a.Buffer_Gets/a.Rows_Processed)");
            break;
        default:
            toStatusMessage(tr("Unknown selection"));
            break;
        }

        if (!order.isEmpty())
            select = QString("SELECT * FROM (\n") + select +
                     QString("\n ORDER BY " + order + " DESC)\n WHERE ROWNUM < 20");

        Trace->setSQL(QString::null);
        if (!CurrentSchema.isEmpty())
        {
            toQList p;
            p.insert(p.end(), CurrentSchema);
            Trace->query(select, p);
        }
        else
            Trace->query(select);

        Statement->refresh();
    }
    TOCATCH;
}