示例#1
0
void DatabaseImportForm::captureThreadError(Exception e)
{
	destroyModelWidget();
	finishImport(trUtf8("Importing process aborted!"));
	ico_lbl->setPixmap(QPixmap(QString(":/icones/icones/msgbox_erro.png")));
	throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
}
void DatabaseImportForm::captureThreadError(Exception e)
{
	QPixmap ico;
	QTreeWidgetItem *item=nullptr;

	if(!create_model)
		model_wgt->rearrangeSchemas(QPointF(origin_sb->value(), origin_sb->value()),
									tabs_per_row_sb->value(), sch_per_row_sb->value(), obj_spacing_sb->value());

	destroyModelWidget();
	finishImport(trUtf8("Importing process aborted!"));

	ico=QPixmap(PgModelerUiNS::getIconPath("msgbox_erro"));
	ico_lbl->setPixmap(ico);

	item=PgModelerUiNS::createOutputTreeItem(output_trw, PgModelerUiNS::formatMessage(e.getErrorMessage()), ico, nullptr, false, true);
	PgModelerUiNS::createExceptionsTree(output_trw, e, item);

	//Destroy the current import thread and helper to avoid reuse
	destroyThread();

	//Recreates a new import thread and helper to force user to reconfigure the import
	createThread();

	database_cmb->setCurrentIndex(0);
	throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
}
示例#3
0
void SoftwareImporters::importKNotes()
{
    QString dirPath = KStandardDirs::locateLocal("appdata", "") + "/../knotes/"; // I thing the assumption is good
    QDir dir(dirPath, QString::null, QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);

    QStringList list = dir.entryList();
    for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {   // For each file
        if (!(*it).endsWith(QLatin1String(".ics")))    // Don't process *.ics~ and other files
            continue;
        QFile file(dirPath + *it);
        if (file.open(QIODevice::ReadOnly)) {
            QTextStream stream(&file);
            stream.setCodec("UTF-8");

            // First create a basket for it:
            BasketFactory::newBasket(/*icon=*/"knotes", /*name=*/i18n("From KNotes"), /*backgroundImage=*/"", /*backgroundColor=*/QColor(), /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/0);
            BasketScene *basket = Global::bnpView->currentBasket();
            basket->load();

            bool inVJournal    = false;
            bool inDescription = false;
            bool isRichText    = false;
            QString title, body;
            QString buf;
            while (1) {
                buf = stream.readLine();
                if (buf.isNull()) // OEF
                    break;

                if (!buf.isNull() && buf == "BEGIN:VJOURNAL") {
                    inVJournal = true;
                } else if (inVJournal && buf.startsWith(QLatin1String("SUMMARY:"))) {
                    title = buf.mid(8, buf.length());
                } else if (inVJournal && buf.startsWith(QLatin1String("DESCRIPTION:"))) {
                    body = buf.mid(12, buf.length());
                    inDescription = true;
                } else if (inDescription && buf.startsWith(QLatin1String(" "))) {
                    body += buf.mid(1, buf.length());
                } else if (buf.startsWith(QLatin1String("X-KDE-KNotes-RichText:"))) {
                    isRichText = XMLWork::trueOrFalse(buf.mid(22, buf.length() - 22).trimmed(), "false");
                } else if (buf == "END:VJOURNAL") {
                    insertTitledNote(basket, fromICS(title), fromICS(body), (isRichText ? Qt::RichText : Qt::PlainText));
                    inVJournal    = false;
                    inDescription = false;
                    isRichText    = false;
                    title = "";
                    body = "";
                } else
                    inDescription = false;
            }

            // Bouh : duplicate code
            // In case of unvalide ICAL file!
            if (! body.isEmpty())   // Add the ending note
                insertTitledNote(basket, fromICS(title), fromICS(body), (isRichText ? Qt::RichText : Qt::PlainText));
            file.close();
            finishImport(basket);
        }
    }
}
示例#4
0
void SoftwareImporters::importJreepadFile(){
    typedef QPair<BasketScene *, QDomElement> basketAndElementPair;

    QString fileName = KFileDialog::getOpenFileName(KUrl("kfiledialog:///:ImportJreepadFile"),
                                                    "*.xml|XML files");
    if (fileName.isEmpty()) {
        return;
    }

    basketAndElementPair newElement;
    basketAndElementPair currentElement;
    QList<basketAndElementPair> elements;
    QList<BasketScene*> basketList;

    QDomDocument *doc = XMLWork::openFile("node", fileName);
    newElement.second = doc->documentElement();

    BasketScene *basket = 0;
    BasketFactory::newBasket(/*icon=*/"xml", /*name=*/doc->documentElement().attribute("title"), 
                             /*backgroundImage=*/"", /*backgroundColor=*/QColor(), 
                             /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/0);
    basket = Global::bnpView->currentBasket();
    basket->load();
    basketList << basket;
    newElement.first = basket;

    elements << newElement;

    while ( !elements.isEmpty() ) {
        currentElement = elements.takeFirst();
        for (QDomNode n = currentElement.second.firstChild(); !n.isNull(); n = n.nextSibling()) {
            if ( n.isText() ) {
                basket = currentElement.first;
                Note *note = NoteFactory::createNoteFromText(n.toText().data(), basket);
                basket->insertNote(note, basket->firstNote(), 
                                   Note::BottomColumn, QPoint(), /*animate=*/false);
            } else if ( n.isElement() ) {
                BasketFactory::newBasket(/*icon=*/"xml", /*name=*/n.toElement().attribute("title"), 
                                         /*backgroundImage=*/"", /*backgroundColor=*/QColor(), 
                                         /*textColor=*/QColor(), /*templateName=*/"1column", 
                                         /*createIn=*/currentElement.first);
                basket = Global::bnpView->currentBasket();
                basket->load();
                basketList << basket;
                newElement.first = basket;
                newElement.second = n.toElement();
                elements << newElement;
            }
        }
    }
    
    foreach (basket, basketList) {
        finishImport(basket);
    }
void DatabaseImportForm::handleImportCanceled(void)
{
	QPixmap ico=QPixmap(PgModelerUiNS::getIconPath("msgbox_alerta"));
	QString msg=trUtf8("Importing process canceled by user!");

	if(!create_model)
		model_wgt->rearrangeSchemas(QPointF(origin_sb->value(), origin_sb->value()),
									tabs_per_row_sb->value(), sch_per_row_sb->value(), obj_spacing_sb->value());

	destroyModelWidget();
	finishImport(msg);
	ico_lbl->setPixmap(ico);

	PgModelerUiNS::createOutputTreeItem(output_trw, msg, ico);
}
示例#6
0
void DatabaseImportForm::handleImportFinished(Exception e)
{	
	if(!e.getErrorMessage().isEmpty())
	{
		Messagebox msgbox;
		msgbox.show(e, e.getErrorMessage(), Messagebox::ALERT_ICON);
	}

	model_wgt->rearrangeSchemas(QPointF(origin_sb->value(), origin_sb->value()),
															tabs_per_row_sb->value(), sch_per_row_sb->value(), obj_spacing_sb->value());

	finishImport(trUtf8("Importing process sucessfuly ended!"));
	ico_lbl->setPixmap(QPixmap(QString(":/icones/icones/msgbox_info.png")));

  import_helper.closeConnection();
  import_thread->quit();
  timer.stop();

	this->accept();
}
void DatabaseImportForm::handleImportFinished(Exception e)
{	
	if(!e.getErrorMessage().isEmpty())
	{
		Messagebox msgbox;
		msgbox.show(e, e.getErrorMessage(), Messagebox::ALERT_ICON);
	}

	model_wgt->rearrangeSchemas(QPointF(origin_sb->value(), origin_sb->value()),
															tabs_per_row_sb->value(), sch_per_row_sb->value(), obj_spacing_sb->value());
	model_wgt->getDatabaseModel()->setInvalidated(false);

	finishImport(trUtf8("Importing process sucessfuly ended!"));
	ico_lbl->setPixmap(QPixmap(PgModelerUiNS::getIconPath("msgbox_info")));

	import_helper->closeConnection();
	import_thread->quit();
	import_thread->wait();

	this->accept();
}
示例#8
0
void SoftwareImporters::importStickyNotes()
{
    // Sticky Notes file is usually located in ~/.gnome2/stickynotes_applet
    // We will search all directories in "~/" that contain "gnome" in the name,
    // and will search for "stickynotes_applet" file (that should be XML file with <stickynotes> root.
    QDir dir(QDir::home().absolutePath(), QString::null, QDir::Name | QDir::IgnoreCase,
             QDir::Dirs | QDir::NoSymLinks | QDir::Hidden);
    QStringList founds;

    QStringList list = dir.entryList();
    for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {   // For each folder
        if ((*it).contains("gnome", Qt::CaseInsensitive)) {
            QString fullPath = QDir::home().absolutePath() + "/" + (*it) + "/stickynotes_applet";
            if (dir.exists(fullPath))
                founds += fullPath;
        }
    }

    for (QStringList::Iterator it = founds.begin(); it != founds.end(); ++it) {   // For each file
        QFile file(*it);
        QDomDocument *doc = XMLWork::openFile("stickynotes", *it);
        if (doc == 0)
            continue;

        // First create a basket for it:
        BasketFactory::newBasket(/*icon=*/"gnome", /*name=*/i18n("From Sticky Notes"), /*backgroundImage=*/"", /*backgroundColor=*/QColor(), /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/0);
        BasketScene *basket = Global::bnpView->currentBasket();
        basket->load();

        QDomElement docElem = doc->documentElement();
        for (QDomNode n = docElem.firstChild(); !n.isNull(); n = n.nextSibling()) {
            QDomElement e = n.toElement();
            if ((!e.isNull()) && e.tagName() == "note")
                insertTitledNote(basket, e.attribute("title"), e.text());
        }
        finishImport(basket);
    }
}
示例#9
0
文件: Mesh.cpp 项目: cybersphinx/WMIT
Mesh::Mesh(const Pie3Level& p3)
{
    std::vector<Pie3Polygon>::const_iterator itL;

    typedef std::set<WZMPoint, compareWZMPoint_less_wEps> t_tupleSet;
    t_tupleSet tupleSet;
    std::pair<t_tupleSet::iterator, bool> inResult;

    std::vector<unsigned> mapping;
    std::vector<unsigned>::iterator itMap;

    IndexedTri iTri;
    WZMVertex tmpNrm;

    defaultConstructor();

    /*
     *	Try to prevent duplicate vertices
     *	(remember, different UV's, or animations,
     *	 will cause unavoidable duplication)
     *	so that our transformed vertex cache isn't
     *	completely useless.
     */

    // For each pie3 polygon
    for (itL = p3.m_polygons.begin(); itL != p3.m_polygons.end(); ++itL)
    {
        // pie2 integer-type problem?
        if (itL->getIndex(0) == itL->getIndex(1) || itL->getIndex(1) == itL->getIndex(2) || itL->getIndex(0) == itL->getIndex(2))
        {
            continue;
        }
        if (itL->m_texCoords[0] == itL->m_texCoords[1] || itL->m_texCoords[1] == itL->m_texCoords[2] || itL->m_texCoords[0] == itL->m_texCoords[2])
        {
            continue;
        }

        tmpNrm = normalizeVector(WZMVertex(WZMVertex(p3.m_points[itL->getIndex(1)]) - WZMVertex(p3.m_points[itL->getIndex(0)]))
                                 .crossProduct(WZMVertex(p3.m_points[itL->getIndex(2)]) - WZMVertex(p3.m_points[itL->getIndex(0)])));;

        // For all 3 vertices of the triangle
        for (int i = 0; i < 3; ++i)
        {
            inResult = tupleSet.insert(WZMPoint(p3.m_points[itL->getIndex(i)], itL->getUV(i, 0), tmpNrm));

            if (!inResult.second)
            {
                iTri.operator[](i) = mapping[std::distance(tupleSet.begin(), inResult.first)];
            }
            else
            {
                itMap = mapping.begin();
                std::advance(itMap, std::distance(tupleSet.begin(), inResult.first));
                mapping.insert(itMap, vertices());
                iTri.operator[](i) = vertices();
                addPoint(*inResult.first);
            }
        }
        addIndices(iTri);
    }

    std::list<Pie3Connector>::const_iterator itC;

    // For each pie3 connector
    for (itC = p3.m_connectors.begin(); itC != p3.m_connectors.end(); ++itC)
    {
        addConnector(WZMConnector(itC->pos.operator[](0),
                                  itC->pos.operator[](1),
                                  itC->pos.operator[](2)));
    }

    finishImport();
    recalculateBoundData();
}
示例#10
0
void DatabaseImportForm::handleImportCanceled(void)
{
	destroyModelWidget();
	finishImport(trUtf8("Importing process canceled by user!"));
	ico_lbl->setPixmap(QPixmap(QString(":/icones/icones/msgbox_alerta.png")));
}
示例#11
0
void SoftwareImporters::importTomboy()
{
    /* A notebook becomes a basket.
    What can be improved: separate big text into notes by "\n\n";
    remove "\n" from lists - we don't need <br> between two <li>s */

    BasketScene *basketFromTomboy = 0; // Create the basket ONLY if we found at least one note to add!
    BasketScene *subBasket; // Where are we adding current note? (can equal basketFromTomboy if the note is in generic notebook)
    QMap<QString, BasketScene*> subBuskets; // "notebook name - basket" correspondence

    QString possibleLocations[2] = { "/.tomboy/", "/.local/share/tomboy/" };
    for (int L=0; L<2; L++) {

        QString dirPath = QDir::home().absolutePath() + possibleLocations[L];
        QDir dir(dirPath, QString::null, QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
        DEBUG_WIN << "Tomboy import: Checking " + dirPath;

        QStringList list = dir.entryList();
        for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {   // For each file
            if (!(*it).endsWith(QLatin1String(".note")))
                continue;
            QDomDocument *doc = XMLWork::openFile("note", dirPath + *it);
            if (doc == 0)
                continue;

            if (basketFromTomboy == 0) {
                // First create a basket for it:
                BasketFactory::newBasket(/*icon=*/IconNames::TOMBOY, /*name=*/i18n("From Tomboy"), /*backgroundImage=*/"", /*backgroundColor=*/QColor(), /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/0);
                basketFromTomboy = Global::bnpView->currentBasket();
                basketFromTomboy->load();
            }

            QDomElement docElem = doc->documentElement();
            QString title = XMLWork::getElementText(docElem, "title");
            QString notebook = getFirstTomboyTag(docElem); //!< Tomboy notebook name

            // Find subbasket or create a new one
            if (notebook.length() > 0) {
                if (subBuskets.contains(notebook))
                    subBasket = subBuskets[notebook]; else
                {
                    BasketFactory::newBasket(IconNames::TOMBOY, notebook, "", QColor(), QColor(), "1column", /*createIn=*/basketFromTomboy);
                    subBasket = Global::bnpView->currentBasket(); //TODO: ? change newBasket() so that it returns pointer and we don't have to load it
                    subBasket->load();

                    subBuskets.insert(notebook, subBasket);
                }
            } else
                subBasket = basketFromTomboy; // will insert to the root basket


            // DOES NOT REALLY WORKS:
            //QDomElement contentElement = XMLWork::getElement(docElem, "text/note-content");
            //QString content = XMLWork::innerXml(contentElement);

            // Isolate "<note-content version="0.1">CONTENT</note-content>"!
            QString xml = loadUtf8FileToString(dirPath + *it);
            xml = xml.mid(xml.indexOf("<note-content"));
            xml = xml.mid(xml.indexOf(">") + 1);
            xml = xml.mid(0, xml.indexOf("</note-content>"));

            if (!title.isEmpty() && !/*content*/xml.isEmpty()) {
                insertTitledNote(subBasket, title, fromTomboy(xml/*content*/), Qt::RichText);
                DEBUG_WIN << QString("Tomboy import: Inserting note '%1' into '%2'").arg(title, notebook);
            }
        }

    }

    if (basketFromTomboy)
        finishImport(basketFromTomboy);
}
示例#12
0
void SoftwareImporters::importKJots()
{
    QString dirPath = KStandardDirs::locateLocal("appdata", "") + "/../kjots/"; // I think the assumption is good
    QDir dir(dirPath, QString::null, QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);

    QStringList list = dir.entryList();
    if (list.isEmpty())
        return;

    BasketFactory::newBasket(/*icon=*/"kjots", /*name=*/i18n("From KJots"), /*backgroundImage=*/"", /*backgroundColor=*/QColor(), /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/0);
    BasketScene *kjotsBasket = Global::bnpView->currentBasket();

    for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {   // For each file
        QFile file(dirPath + *it);
        if (file.open(QIODevice::ReadOnly)) {
            QTextStream stream(&file);
            QString buf = stream.readLine();

            // IT IS A NOTEBOOK FILE, AT THE VERION 0.6.x and older:
            if (!buf.isNull() && buf.left(9) == "\\NewEntry") {

                // First create a basket for it:
                BasketFactory::newBasket(/*icon=*/"kjots", /*name=*/KUrl(file.fileName()).fileName(), /*backgroundImage=*/"", /*backgroundColor=*/QColor(), /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/kjotsBasket);
                BasketScene *basket = Global::bnpView->currentBasket();
                basket->load();

                QString title, body;
                bool haveAnEntry = false;
                while (1) {
                    if (buf.left(9) == "\\NewEntry") {
                        if (haveAnEntry) // Do not add note the first time
                            insertTitledNote(basket, title, Tools::stripEndWhiteSpaces(body));
                        title = buf.mid(10, buf.length());          // Problem : basket will be saved
                        body = ""; // New note will then be created //  EACH time a note is imported
                        haveAnEntry = true;
                    } else if (buf.left(3) != "\\ID") { // Don't care of the ID
                        // Remove escaped '\' characters and append the text to the body
                        int pos = 0;
                        while ((pos = buf.indexOf('\\', pos)) != -1)
                            if (buf[++pos] == '\\')
                                buf.remove(pos, 1);
                        body.append(buf + "\n");
                    }
                    buf = stream.readLine();
                    if (buf.isNull()) // OEF
                        break;
                }
                // Add the ending note (there isn't any other "\\NewEntry" to do it):
                if (haveAnEntry)
                    insertTitledNote(basket, title, Tools::stripEndWhiteSpaces(body));
                finishImport(basket);

                // IT IS A NOTEBOOK XML FILE, AT THE VERION 0.7.0 and later:
            } else if ((*it).endsWith(QLatin1String(".book")) /*&& !buf.isNull() && (buf.left(2) == "<!" / *<!DOCTYPE...* / || buf.left(2) == "<?" / *<?xml...* /)*/) {

                QDomDocument *doc = XMLWork::openFile("KJots", dirPath + *it);
                if (doc == 0)
                    continue;

                QString bookTitle = XMLWork::getElementText(doc->documentElement(), "KJotsBook/Title");

                // First create a basket for it:
                BasketFactory::newBasket(/*icon=*/"kjots", /*name=*/bookTitle, /*backgroundImage=*/"", /*backgroundColor=*/QColor(), /*textColor=*/QColor(), /*templateName=*/"1column", /*createIn=*/kjotsBasket);
                BasketScene *basket = Global::bnpView->currentBasket();
                basket->load();

                QDomElement docElem = XMLWork::getElement(doc->documentElement(), "KJotsBook");
                for (QDomNode n = docElem.firstChild(); !n.isNull(); n = n.nextSibling()) {
                    QDomElement e = n.toElement();
                    if ((!e.isNull()) && e.tagName() == "KJotsPage")
                        insertTitledNote(basket, XMLWork::getElementText(e, "Title"), XMLWork::getElementText(e, "Text"));
                }
                finishImport(basket);

            }

            file.close();
        }
    }
}