Пример #1
0
void TransformsGui::setCurrentChainConf(const QString &conf)
{
    if (conf.isEmpty())
        return;

    MessageDialog errorDialog(guiHelper);
    connect(transformFactory, SIGNAL(error(QString,QString)), &errorDialog, SLOT(logError(QString)));
    QXmlStreamReader reader(conf);

    TransformChain talist = transformFactory->loadConfFromXML(&reader);
    if (talist.isEmpty())
        QMessageBox::critical(this,tr("Error"),tr("The loaded chain is empty. Check the logs."),QMessageBox::Ok);
    else {
        if (errorDialog.hasMessages()) {
            errorDialog.setWindowTitle(tr("Error(s) while loading the configuration"));
            if (errorDialog.exec() == QDialog::Rejected) {
                while (!talist.isEmpty())
                    delete talist.takeLast();
                return;
            }
        }

        setCurrentTransformChain(talist);
        emit chainChanged(conf);
    }
}
Пример #2
0
void TransformsGui::onLoadState()
{
    MessageDialog errorDialog(guiHelper);
    connect(transformFactory, SIGNAL(error(QString,QString)), &errorDialog, SLOT(logError(QString)));

    QString fileName = QFileDialog::getOpenFileName(this,tr("Choose state file to load from"),"",tr("XML documents (*.xml);; All (*)"));

    if (fileName.isEmpty())
        return;

    TransformChain talist = transformFactory->loadConfFromFile(fileName);
    if (talist.isEmpty())
        QMessageBox::critical(this,tr("Error"),tr("The loaded chain is empty. Check the logs."),QMessageBox::Ok);
    else {
        if (errorDialog.hasMessages()) {
            errorDialog.setWindowTitle(tr("Error(s) while loading the state file"));
            if (errorDialog.exec() == QDialog::Rejected) {
                while (!talist.isEmpty())
                    delete talist.takeLast();
                return;
            }
        } else {
            logger->logStatus(tr("File %1 loaded").arg(fileName));
        }

        setCurrentTransformChain(talist);
        // not really efficient
        QString conf;
        QXmlStreamWriter writer(&conf);
        transformFactory->saveConfToXML(talist, &writer);
        emit chainChanged(conf);
    }
}
Пример #3
0
void TransformsGui::onSavedSelected(QString name)
{
    if (name.isEmpty()) {
        QMessageBox::critical(this,tr("Error"),tr("The selected name is empty T_T"),QMessageBox::Ok);
        qWarning() << tr("[TransformsGui] The selected name is empty T_T");
        return;
    }
    TransformChain tc = transformFactory->loadChainFromSaved(name);
    if (tc.isEmpty()) {
        QMessageBox::critical(this,tr("Error"),tr("The returned chain is empty. Check the logs."),QMessageBox::Ok);
    } else {
        resetAll();
        setCurrentTransformChain(tc);
        emit chainChanged(transformFactory->getSavedConfs().value(name));
    }
}
Пример #4
0
void GenericTabStateObj::run()
{
    GenericTab * gTab = dynamic_cast<GenericTab *> (tab);
    TabStateObj::run();
    if (flags & GuiConst::STATE_SAVE_REQUEST) {
        writer->writeAttribute(GuiConst::STATE_SEARCH_WIDGET, write(gTab->getSearchWidget()->text(),true));
        writer->writeAttribute(GuiConst::STATE_GOTOOFFSET_WIDGET, write(gTab->getGotoWidget()->text()));
        writer->writeAttribute(GuiConst::STATE_MESSAGE_PANEL, write(gTab->getMessagePanel()->toHTML(),true));
        writer->writeAttribute(GuiConst::STATE_MESSAGE_PANEL_VISIBLE, write(gTab->getMessagePanel()->isVisible()));
        writer->writeAttribute(GuiConst::STATE_SCROLL_INDEX, write(gTab->hexView->getHexTableView()->verticalScrollBar()->value()));
        writer->writeAttribute(GuiConst::STATE_CURRENT_INDEX, write(gTab->ui->tabWidget->currentIndex()));
        QList<GenericTab::ViewTab> tabs = gTab->tabData;
        int size = tabs.size();
        writer->writeStartElement(GuiConst::STATE_TABVIEWLIST);
        writer->writeAttribute(GuiConst::STATE_SIZE, write(tabs.size()));
        for (int i = 0; i < size ; i++) {
            writer->writeStartElement(GuiConst::STATE_TABVIEW);
            writer->writeAttribute(GuiConst::STATE_TYPE, write((int)tabs.at(i).type));
            // saving configuration
            QString conf;
            TransformChain list;
            if (tabs.at(i).transform != nullptr) {
                list.append(tabs.at(i).transform);
            }
            list.setName(tabs.at(i).tabName);
            QXmlStreamWriter streamin(&conf);
            tab->getHelper()->getTransformFactory()->saveConfToXML(list, &streamin);
            writer->writeAttribute(GuiConst::STATE_CONF, write(conf));
            writer->writeEndElement();
            list.clear(); // the transforms are not own by us, don't delete them
        }
        writer->writeEndElement(); // STATE_TABVIEWLIST
    } else {
        QXmlStreamAttributes attrList = reader->attributes();
        if (attrList.hasAttribute(GuiConst::STATE_SEARCH_WIDGET)) {
            gTab->getSearchWidget()->setText(readString(attrList.value(GuiConst::STATE_SEARCH_WIDGET)));
        }

        if (attrList.hasAttribute(GuiConst::STATE_GOTOOFFSET_WIDGET)) {
            gTab->getGotoWidget()->setText(readString(attrList.value(GuiConst::STATE_GOTOOFFSET_WIDGET)));
        }

        if (attrList.hasAttribute(GuiConst::STATE_MESSAGE_PANEL)) {
            gTab->getMessagePanel()->setHTML(readString(attrList.value(GuiConst::STATE_MESSAGE_PANEL)));
        }

        if (attrList.hasAttribute(GuiConst::STATE_MESSAGE_PANEL_VISIBLE)) {
            gTab->getMessagePanel()->setVisible(readBool(attrList.value(GuiConst::STATE_MESSAGE_PANEL_VISIBLE)));
        }

        bool ok = false;
        int index = -1;
        GenericTabClosingStateObj *tempState = nullptr;
        if (attrList.hasAttribute(GuiConst::STATE_SCROLL_INDEX)) {
            index = readInt(attrList.value(GuiConst::STATE_SCROLL_INDEX), &ok);
            if (ok) {
                tempState = new(std::nothrow) GenericTabClosingStateObj(gTab);
                if (tempState == nullptr) {
                    qFatal("Cannot allocate memory for GenericTabClosingStateObj X{");
                }
                tempState->setScrollIndex(index);
            }
        }

        if (attrList.hasAttribute(GuiConst::STATE_CURRENT_INDEX)) {
            index = readInt(attrList.value(GuiConst::STATE_CURRENT_INDEX), &ok);
            if (ok) {
                if (tempState == nullptr) {
                    tempState = new(std::nothrow) GenericTabClosingStateObj(gTab);
                    if (tempState == nullptr) {
                        qFatal("Cannot allocate memory for GenericTabClosingStateObj X{");
                    }
                }
                tempState->setCurrentIndex(index);
            }
        }

        if (tempState != nullptr)
            emit addNewState(tempState);

        // restoring view tabs
        if (readNextStart(GuiConst::STATE_TABVIEWLIST)) {
            attrList = reader->attributes();
            if (attrList.hasAttribute(GuiConst::STATE_SIZE)) {
                ok = false;
                int size = readInt(attrList.value(GuiConst::STATE_SIZE),&ok);
                if (ok) {
                    for (int i = 0; i < size ; i++) {
                        GenericTab::ViewTab vt;
                        vt.transform = nullptr; // just initialising in case of screw up
                        if (readNextStart(GuiConst::STATE_TABVIEW)) {
                            attrList = reader->attributes();
                            readEndElement(GuiConst::STATE_TABVIEW); // closing now, because there is no child defined anyway
                            if (attrList.hasAttribute(GuiConst::STATE_TYPE)) {
                                int type = readInt(attrList.value(GuiConst::STATE_TYPE),&ok);
                                if (ok && (type == 0 || type == 1 || type == 2 || type == 3)) {
                                    vt.type = (GenericTab::ViewType) type;
                                } else {
                                    qWarning() << "Invalid state type for this view, skipping";
                                    continue;
                                }
                            } else {
                                qWarning() << "no state type for this view, skipping";
                                continue;
                            }
                            if (vt.type != GenericTab::DEFAULTTEXT) {
                                if (attrList.hasAttribute(GuiConst::STATE_CONF)) {
                                    QString conf = readString(attrList.value(GuiConst::STATE_CONF));
                                    if (!conf.isEmpty()) {
                                        TransformChain list = tab->getHelper()->getTransformFactory()->loadConfFromXML(conf);
                                        if (!list.isEmpty()) {
                                            vt.transform = list.at(0);
                                            vt.tabName = list.getName();
                                        } else {
                                            qWarning() << "Resulting transform list empty for this view, skipping";
                                            continue;
                                        }
                                    } else {
                                        qWarning() << "Empty conf for this view, skipping";
                                        continue;
                                    }
                                } else {
                                    qWarning() << "no conf for this view, skipping";
                                    continue;
                                }
                            } else {
                                vt.tabName = GenericTab::TEXT_TEXT;
                            }
                            gTab->addViewTab(vt);
                            // no deleting vt.transform here, the pointer is now owned by the tab.
                        }
                    }
                } else {
                    qCritical() << "Size value is not a number, giving up";
                }
            } else {
                 qCritical() << "No size value for the view size, giving up";
            }
        }
        readEndElement(GuiConst::STATE_TABVIEWLIST);
    }

    BaseStateAbstract *state = gTab->getSource(0)->getStateMngtObj();
    emit addNewState(state);
}