Exemple #1
0
/*
 * Called whenever tab/pane layout changes
 */
void GuiMainWindow::on_tabLayoutChanged()
{
    QWidget *w;
    GuiTerminalWindow *term;
    GuiSplitter *split;

    tabIndexMap.clear();
    widgetAtIndex.resize(tabArea->count());
    for (int i=0; i < tabArea->count(); i++) {
        split = NULL;
        term = NULL;
        w = tabArea->widget(i);
        tabIndexMap[w] = i;
        if ((term=qobject_cast<GuiTerminalWindow*>(w))) {
            term->on_sessionTitleChange(true);
        } else if ((split=qobject_cast<GuiSplitter*>(w))) {
            vector<GuiTerminalWindow*> list;
            split->populateAllTerminals(&list);
            for(auto it=list.begin(); it-list.end(); ++it) {
                tabIndexMap[*it] = i;
                (*it)->on_sessionTitleChange(true);
            }
        }
        widgetAtIndex[i] = std::pair<GuiSplitter*,GuiTerminalWindow*>(split, term);
    }
}
Exemple #2
0
void notify_remote_exit(void *frontend)
{
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    int exitcode = f->backend->exitcode(f->backhandle);

    if (f->userClosingTab || f->isSockDisconnected)
        return;

    if (exitcode >=0) {
        if (f->cfg.close_on_exit == FORCE_ON ||
            (f->cfg.close_on_exit == AUTO && exitcode != INT_MAX)) {
            f->closeTerminal();
        } else {
            /* exitcode == INT_MAX indicates that the connection was closed
             * by a fatal error, so an error box will be coming our way and
             * we should not generate this informational one. */
            if (exitcode != INT_MAX) {
                qt_message_box(frontend, APPNAME " Fatal Error",
                               "Connection closed by remote host");
                f->setSessionTitle(f->getSessionTitle() + " (inactive)");
                // prevent recursive calling
                f->isSockDisconnected = true;
            }
        }
    }
}
Exemple #3
0
void qutty_connection_fatal(void *frontend, char *msg)
{
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    if (f->userClosingTab || f->isSockDisconnected)
        return;

    // prevent recursive calling
    f->isSockDisconnected = true;

    qt_critical_msgbox(frontend, msg, NULL);

    if (f->cfg.close_on_exit == FORCE_ON)
        f->closeTerminal();
    f->setSessionTitle(f->getSessionTitle() + " (inactive)");
}
Exemple #4
0
void GuiFindToolBar::on_findClose()
{
    GuiTerminalWindow *t;

    findTextFlag = false;
    mainWnd->menuGetActionById(MENU_FIND_NEXT)->setEnabled(false);
    mainWnd->menuGetActionById(MENU_FIND_PREVIOUS)->setEnabled(false);
    mainWnd->findToolBar = NULL;
    this->deleteLater();

    if (t=mainWnd->getCurrentTerminal()) {
        t->viewport()->repaint();
        t->setFocus();
    }
}
void GuiMainWindow::createNewTab(Config *cfg, GuiBase::SplitType splittype)
{
    int rc;
    GuiTerminalWindow *newWnd = new GuiTerminalWindow(tabArea, this);
    newWnd->cfg = *cfg;

    if ((rc=newWnd->initTerminal()))
        goto err_exit;

    if (this->setupLayout(newWnd, splittype))
        goto err_exit;

    return;

err_exit:
    delete newWnd;
}
Exemple #6
0
/*
 * Ask whether the selected algorithm is acceptable (since it was
 * below the configured 'warn' threshold).
 */
int askalg(void *frontend, const char *algtype, const char *algname,
       void (* /*callback*/)(void *ctx, int result), void * /*ctx*/)
{
    assert(frontend);
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    QString msg = 	QString("The first " + QString(algtype) + " supported by the server\n"
                            "is "+ QString(algname) +", which is below the configured\n"
                            "warning threshold.\n"
                            "Do you want to continue with this connection?\n");
    switch (QMessageBox::warning(f->getMainWindow(), QString(APPNAME " Security Alert"),
                         msg,
                         QMessageBox::Yes | QMessageBox::No,
                         QMessageBox::No)) {
    case QMessageBox::Yes:      return 2;
    case QMessageBox::No:       return 1;
    default:                    return 0;
    }
}
void GuiMainWindow::tabCloseRequested (int index)
{
    // user cloing the tab
    GuiBase *base = dynamic_cast<GuiBase*>(tabArea->widget(index));
    GuiTerminalWindow *termWnd = dynamic_cast<GuiTerminalWindow*>(base);
    qutty_assert(base);
    if (termWnd) {
        // single terminal to close
        termWnd->reqCloseTerminal(false);
    } else if (base) {
        // multiple terminals to close
        if (QMessageBox::No == QMessageBox::question(this, "Exit Confirmation?",
                                "Are you sure you want to close all session panes?",
                                QMessageBox::Yes|QMessageBox::No))
            return;
        base->reqCloseTerminal(true);
        tabArea->removeTab(index);
    }
}
Exemple #8
0
void GuiMainWindow::contextMenuFind()
{
    if (!this->getCurrentTerminal())
        return;

    if (!findToolBar) {
        findToolBar = new GuiFindToolBar(this);
        findToolBar->show();

        GuiTerminalWindow *t = getCurrentTerminal();
        findToolBar->move(t->viewport()->width() - findToolBar->width(),
                          t->mapTo(this, QPoint(0,0)).y());

        menuGetActionById(MENU_FIND_NEXT)->setEnabled(true);
        menuGetActionById(MENU_FIND_PREVIOUS)->setEnabled(true);
    } else {
        findToolBar->on_findClose();
    }
}
Exemple #9
0
void GuiMainWindow::createNewTab(Config *cfg, GuiBase::SplitType splittype)
{
    int rc;
    GuiTerminalWindow *newWnd = new GuiTerminalWindow(tabArea, this);
    newWnd->cfg = *cfg;
    auto config_name = QString(cfg->config_name);
    auto hostname = QString(cfg->host);

    if ((rc=newWnd->initTerminal()))
        goto err_exit;

    if (this->setupLayout(newWnd, splittype))
        goto err_exit;

    // To set the current session to MRU list
    qutty_mru_sesslist.insertSession(config_name, hostname);

    return;

err_exit:
    delete newWnd;
}
Exemple #10
0
int GuiMainWindow::setupLayout(GuiTerminalWindow *newTerm, GuiBase::SplitType split, int tabind)
{
    // fallback to create tab
    if (tabArea->count() == 0)
        split = GuiBase::TYPE_LEAF;

    switch (split) {
    case GuiBase::TYPE_LEAF:
        newTerm->setParent(tabArea);
        this->tabInsert(tabind, newTerm, "");
        terminalList.append(newTerm);
        tabArea->setCurrentWidget(newTerm);
        newTerm->setWindowState(newTerm->windowState() | Qt::WindowMaximized);

        setupTerminalSize(newTerm);
        on_tabLayoutChanged();
        break;
    case GuiBase::TYPE_HORIZONTAL:
    case GuiBase::TYPE_VERTICAL:
    {
        GuiTerminalWindow *currTerm;
        if (!(currTerm = getCurrentTerminal()))
            goto err_exit;

        currTerm->createSplitLayout(split, newTerm);
        newTerm->setFocus();
        terminalList.append(newTerm);
        on_tabLayoutChanged();
        break;
    }
    default:
        assert(0);
        return -1;
    }
    return 0;

err_exit:
    return -1;
}
Exemple #11
0
int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
                        char *keystr, char *fingerprint,
                        void (* /*callback*/)(void *ctx, int result), void * /*ctx*/)
{
    assert(frontend);
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    int ret = 1;
    QString absentmsg =
        QString("The server's host key is not cached in the registry. You\n"
                "have no guarantee that the server is the computer you\n"
                "think it is.\n"
                "The server's " + QString(keytype) + " key fingerprint is:\n")
        + QString(fingerprint) + QString("\n"
                "If you trust this host, hit Yes to add the key to\n"
                APPNAME "'s cache and carry on connecting.\n"
                "If you want to carry on connecting just once, without\n"
                "adding the key to the cache, hit No.\n"
                "If you do not trust this host, hit Cancel to abandon the\n"
                "connection.\n");

    QString wrongmsg =
        QString("WARNING - POTENTIAL SECURITY BREACH!\n"
                "\n"
                "The server's host key does not match the one " APPNAME " has\n"
                "cached in the registry. This means that either the\n"
                "server administrator has changed the host key, or you\n"
                "have actually connected to another computer pretending\n"
                "to be the server.\n"
                "The new " + QString(keytype) + " key fingerprint is:\n"
                + QString(fingerprint) + "\n"
                "If you were expecting this change and trust the new key,\n"
                "hit Yes to update " APPNAME "'s cache and continue connecting.\n"
                "If you want to carry on connecting but without updating\n"
                "the cache, hit No.\n"
                "If you want to abandon the connection completely, hit\n"
                "Cancel. Hitting Cancel is the ONLY guaranteed safe\n" "choice.\n");

    /*
     * Verify the key against the registry.
     */
    ret = verify_host_key(host, port, keytype, keystr);
    if (ret == 0)		       /* success - key matched OK */
        return 1;
    else if (ret == 2) {	       /* key was different */
        switch (QMessageBox::critical(f->getMainWindow(), QString(APPNAME " Security Alert"),
                             wrongmsg,
                             QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
                             QMessageBox::Cancel)) {
        case QMessageBox::Yes:
            store_host_key(host, port, keytype, keystr);
            return 2;
        case QMessageBox::No:       return 1;
        default:                    return 0;
        }
    } else if (ret == 1) {	       /* key was absent */
        switch (QMessageBox::warning(f->getMainWindow(), QString(APPNAME " Security Alert"),
                             absentmsg,
                             QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
                             QMessageBox::Cancel)) {
        case QMessageBox::Yes:
            store_host_key(host, port, keytype, keystr);
            return 2;
        case QMessageBox::No:       return 1;
        default:                    return 0;
        }
    }
    return 0;	/* abandon the connection */
}
Exemple #12
0
size_t tmux_from_backend(void *frontend, int is_stderr, const char *data, int len)
{
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    return f->tmuxGateway()->fromBackend(is_stderr, data, len);
}
Exemple #13
0
/*
 * called to initalize tmux mode
 */
int tmux_init_tmux_mode(void *frontend, char *tmux_version) {
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    return f->initTmuxControllerMode(tmux_version);
}
Exemple #14
0
int from_backend(void *frontend, int is_stderr, const char *data, int len)
{
    GuiTerminalWindow *f = static_cast<GuiTerminalWindow*>(frontend);
    return f->from_backend(is_stderr, data, (size_t)len);
}
Exemple #15
0
void GuiFindToolBar::on_findDown()
{
    termline *line;
    tree234 *whichtree;
    unsigned long tchar;
    GuiTerminalWindow *gterm = mainWnd->getCurrentTerminal();
    Terminal *term;
    QScrollBar *scrollbar;
    QString str = "";
    int tempStartPosition = 0;
    int tempCol, tempRow;

    if (!gterm)
        return;

    term = gterm->term;
    scrollbar = gterm->verticalScrollBar();

    findTextFlag = true;
    if(getSearchedText() == "")
    {
        findTextFlag = false;
        gterm->viewport()->repaint();
        return;
    }
    tempCol = currentCol;
    tempRow = currentRow;
    currentCol = currentCol + currentSearchedText.length();

    if(getSearchedText().compare(currentSearchedText, Qt::CaseInsensitive))
    {
        pageStartPosition = scrollbar->value();
        currentSearchedText = getSearchedText();
        if(currentCol < 0)
            currentCol = 0;
        whichtree = NULL;
    }

    if(currentRow < 0)
        currentRow = scrollbar->value();

    while(1)
    {
        str = "";

        if(currentRow >= scrollbar->maximum()+term->rows)
        {
            currentRow = 0;
        }
        if(count234(term->scrollback) > currentRow)
        {
            whichtree = term->scrollback;
            unsigned char *cline = (unsigned char*)index234(whichtree, currentRow);
            line = (termline*) decompressline(cline, NULL);
        }
        else
        {
            whichtree = term->screen;
            line = (termline*)index234(whichtree, abs(currentRow - count234(term->scrollback)));
        }
        for(int i = 0; line && i < line->size; i++)
        {
            //qDebug() << line->chars[i].chr;
            tchar = line->chars[i].chr;
            switch (tchar & CSET_MASK)
            {
              case CSET_ASCII:
            tchar = term->ucsdata->unitab_line[tchar & 0xFF];
            break;
              case CSET_LINEDRW:
            tchar = term->ucsdata->unitab_xterm[tchar & 0xFF];
            break;
              case CSET_SCOACS:
            tchar = term->ucsdata->unitab_scoacs[tchar&0xFF];
            break;
            }
            str.append((char)tchar);
        }
        if(currentCol < term->cols && (currentCol = str.indexOf(currentSearchedText, currentCol, Qt::CaseInsensitive)) >= 0)
        {
            if(pageStartPosition != scrollbar->value())
                gterm->setScrollBar(scrollbar->maximum()+term->rows, pageStartPosition, term->rows);
            else
            {
                if(currentRow < scrollbar->value() || currentRow >= (scrollbar->value() + term->rows))
                {
                    gterm->setScrollBar(scrollbar->maximum()+term->rows, currentRow, term->rows);
                    pageStartPosition = scrollbar->value();
                }
            }
            currentSearchedText = str.mid(currentCol, currentSearchedText.length());
            tempStartPosition = pageStartPosition;
            break;
        }
        tempStartPosition++;
        if(tempStartPosition > (scrollbar->maximum()+term->rows))
        {
            findTextFlag = false;
            currentCol = tempCol;
            currentRow = tempRow;
            gterm->viewport()->repaint();
            return;
        }
        currentRow++;
        currentCol = 0;
    }
    gterm->viewport()->repaint();
}