void LibraryCollectionLayer::changeCollection(int idItem)
{
    qDebug() << Q_FUNC_INFO;

    Screen::getInstance()->queueUpdates();
    LibraryCollectionItem* item = items[idItem];
    QString collectionName = item->getText();
    QHash<QString, double>::iterator it = m_bookCollections.find(collectionName);

    if(it != m_bookCollections.end() && it.key() == collectionName)
    {
        item->setChecked(false);
        it = m_bookCollections.erase(it);
        emit removeCollection(collectionName);
    }
    else
    {
        item->setChecked(true);
        double index = QBookApp::instance()->getModel()->getBooksInCollectionCount(collectionName) + 1;
        m_bookCollections.insert(collectionName, index);
        emit addCollection(collectionName, index);
    }
    paint();
    Screen::getInstance()->setMode(Screen::MODE_QUICK, true, FLAG_PARTIALSCREEN_UPDATE, Q_FUNC_INFO);
    Screen::getInstance()->setUpdateScheme(Screen::SCHEME_MERGE, true);
    Screen::getInstance()->flushUpdates();
}
void
OffsetCurveSetBuilder::add(const Geometry *g)
{
	if (g->isEmpty()) return;

	const Polygon *poly = dynamic_cast<const Polygon *>(g);
	if ( poly ) {
		addPolygon(poly);
		return;
	}

	const LineString *line = dynamic_cast<const LineString *>(g);
	if ( line ) {
		addLineString(line);
		return;
	}

	const Point *point = dynamic_cast<const Point *>(g);
	if ( point ) {
		addPoint(point);
		return;
	}

	const GeometryCollection *collection = dynamic_cast<const GeometryCollection *>(g);
	if ( collection ) {
		addCollection(collection);
		return;
	}

	string out=typeid(*g).name();
	throw new UnsupportedOperationException("GeometryGraph::add(Geometry *): unknown geometry type: "+out);
}
TEST_F(SwitchInputMapperTest, testConfigureDevice_noSwitches) {
    MockInputReportDefinition reportDef;
    MockInputDeviceNode deviceNode;

    EXPECT_CALL(reportDef, addCollection(_, _)).Times(0);
    EXPECT_CALL(reportDef, declareUsages(_, _, _)).Times(0);

    EXPECT_FALSE(mMapper->configureInputReport(&deviceNode, &reportDef));
}
TEST_F(SwitchInputMapperTest, testConfigureDevice) {
    MockInputReportDefinition reportDef;
    MockInputDeviceNode deviceNode;
    deviceNode.addSwitch(SW_LID);
    deviceNode.addSwitch(SW_CAMERA_LENS_COVER);

    EXPECT_CALL(reportDef, addCollection(INPUT_COLLECTION_ID_SWITCH, 1));
    EXPECT_CALL(reportDef, declareUsages(INPUT_COLLECTION_ID_SWITCH, _, 2))
    .With(Args<1,2>(UnorderedElementsAre(INPUT_USAGE_SWITCH_LID,
                                         INPUT_USAGE_SWITCH_CAMERA_LENS_COVER)));

    EXPECT_TRUE(mMapper->configureInputReport(&deviceNode, &reportDef));
}
void
GeometryGraph::add(const Geometry *g)
	//throw (UnsupportedOperationException *)
{
	if (g->isEmpty()) return;

	// check if this Geometry should obey the Boundary Determination Rule
	// all collections except MultiPolygons obey the rule
	if ( dynamic_cast<const MultiPolygon*>(g) )
		useBoundaryDeterminationRule = false;


	if ( dynamic_cast<const Polygon*>(g) )
		addPolygon((Polygon*) g);

	// LineString also handles LinearRings
	else if ( dynamic_cast<const LineString*>(g) )
		addLineString((LineString*) g);

	else if ( dynamic_cast<const Point*>(g) )
		addPoint((Point*) g);

	else if ( dynamic_cast<const MultiPoint*>(g) )
		addCollection((MultiPoint*) g);

	else if ( dynamic_cast<const MultiLineString*>(g) )
		addCollection((MultiLineString*) g);

	else if ( dynamic_cast<const MultiPolygon*>(g) )
		addCollection((MultiPolygon*) g);

	else if ( dynamic_cast<const GeometryCollection*>(g) )
		addCollection((GeometryCollection*) g);

	else {
		string out=typeid(*g).name();
		throw util::UnsupportedOperationException("GeometryGraph::add(Geometry *): unknown geometry type: "+out);
	}
}
Exemple #6
0
void CLRItemCollectionFamily::build(const BNFInstance& bnf)
{
    for (auto &sym : bnf.symbolSet) {
        if (sym.type == SyntaxSymbol::T_Terminal) {
            term2ID[sym.value] = (int)ID2Term.size();
            ID2Term.push_back(sym.value);
        }
    }

    vector<int> unhanldedState;
    {
        CLRItemCollection col;
        CLRItem item = {0, 0, term2ID[END_TERM]};
        col.items.insert(item.toInt());
        closure(bnf, col);
        int ns;
        addCollection(col, ns);
        unhanldedState.push_back(0);
    }
    while (!unhanldedState.empty()) {
        int state = unhanldedState.back();
        unhanldedState.pop_back();
        for (auto &sym : bnf.symbolSet) {
            const CLRItemCollection& col(ID2Collection[state]);
            CLRItemCollection newCol;
            transToNewItemCollection(bnf, col, newCol, sym);
            closure(bnf, newCol);
            if (!newCol.items.empty()) {
                int ns;
                if (addCollection(newCol, ns)) {
                    unhanldedState.push_back(ns);
                }
                dfa[state][sym] = ns;
            }
        }
    }
}
Exemple #7
0
    void MongoDatabase::handle(LoadCollectionNamesResponse *loaded)
    {
        if (loaded->isError())
            return;

        clearCollections();
        const std::vector<MongoCollectionInfo> &colectionsInfos = loaded->collectionInfos();
        for(std::vector<MongoCollectionInfo>::const_iterator it = colectionsInfos.begin() ;it!=colectionsInfos.end();++it)    {
            const MongoCollectionInfo &info = *it;
            MongoCollection *collection = new MongoCollection(this, info);
            addCollection(collection);
        }

        _bus->publish(new MongoDatabaseCollectionListLoadedEvent(this, _collections));
    }
Exemple #8
0
void CVirtualFS::mount(const string &mpoint, const string &target){
	CFileCollection fileCol;

	if(mpoint == "" || target == "")
		return;
	
	fileCol.mMountPoint = fixFileName(mpoint);
	if(target[target.size() - 1] == '/'){
		fileCol.colPath = target;
	} else {
		fileCol.colPath = target + "/";
	}
	fileCol.col_type = CFileCollection::Directory;
	addCollection(fileCol);

	if(getDebug())
		gcon.printf("CVirtualFS::mount(%s, %s)\n", fileCol.mMountPoint.c_str(), fileCol.colPath.c_str());
}
Exemple #9
0
void CVirtualFS::addCollection(const string &fname){
	CFileCollection fileCol;
	string fullName = fname;

	if(getDebug())
		gcon.printf("CVirtualFS::addCollection(%s)\n", fname.c_str());

	unzFile *col = (unzFile *)unzOpen(fullName.c_str());
	if(col){
		if(getDebug())
			gcon.printf("CVirtualFS : Adding %s \n",fullName.c_str());
		fileCol.colPath = fname;
		fileCol.col_type = CFileCollection::NativeCollection;
		fileCol.zh = col;
		addCollection(fileCol);
		return;
	}	
	return;
}
BookInfo* ModelBackendOneFile::loadDefaultInfo( const QString& path )
{
    qDebug() << Q_FUNC_INFO << "Path: " << path;

    BookInfo* bookInfo = new BookInfo();
    QString collection;

    if (MetaDataExtractor::getMetaData(path, bookInfo->title, bookInfo->author, bookInfo->publisher, bookInfo->publishTime, bookInfo->synopsis, bookInfo->format, bookInfo->isDRMFile , collection, bookInfo->language)==true) {
        if(bookInfo->title.isEmpty())
            bookInfo->title = QFileInfo(path).baseName();

        //New empty string for author field and use to translate the unknow author string.
        if(bookInfo->author.isEmpty())
            bookInfo->author = QString("---");

        if (!collection.isEmpty())
        {
            addCollection(collection);
            double index = MetaDataExtractor::getCollectionIndex(path);
            bookInfo->addCollection(collection, index);
        }
        bookInfo->setCSSFileList(MetaDataExtractor::extractCSS(path));
    } else {
        qWarning() << Q_FUNC_INFO << "Corrupted book: " << path;
        bookInfo->title = QFileInfo(path).baseName();
        bookInfo->corrupted = true;
        // FIXME: Get proper icon for this
        bookInfo->thumbnail = QString(":/res/corrupted_book_ico.png");
        // TODO: No están todos los atributos.
    }

    bookInfo->readingStatus = BookInfo::NO_READ_BOOK;
    bookInfo->path = path;
    QFileInfo bookFile(path);
    bookFile.refresh();
    bookInfo->size = bookFile.size();
    if (!path.toLower().endsWith(".pdf"))
         bookInfo->fontSize = 2;

    return bookInfo;
}
/*private*/
void
OffsetCurveSetBuilder::add(const Geometry& g)
{
  if (g.isEmpty()) {
#if GEOS_DEBUG
    std::cerr<<__FUNCTION__<<": skip empty geometry"<<std::endl;
#endif
    return;
  }

	const Polygon *poly = dynamic_cast<const Polygon *>(&g);
	if ( poly ) {
		addPolygon(poly);
		return;
	}

	const LineString *line = dynamic_cast<const LineString *>(&g);
	if ( line ) {
		addLineString(line);
		return;
	}

	const Point *point = dynamic_cast<const Point *>(&g);
	if ( point ) {
		addPoint(point);
		return;
	}

	const GeometryCollection *collection = dynamic_cast<const GeometryCollection *>(&g);
	if ( collection ) {
		addCollection(collection);
		return;
	}

	std::string out=typeid(g).name();
	throw util::UnsupportedOperationException("GeometryGraph::add(Geometry &): unknown geometry type: "+out);
}
BookInfo* ModelBackendOneFile::loadBook (QXmlStreamReader& xml)
{
    BookInfo * info = new BookInfo();

    while (!xml.atEnd() && !xml.hasError())
    {
        xml.readNext();
        if(xml.isEndElement())
        {
            if(xml.name() == "book")
                break;
        } else {
            QStringRef name = xml.name();
            if (name == "isbn") {
                info->isbn = xml.readElementText();
            } else if (name == "path") {
                info->path = xml.readElementText();
            } else if (name == "format") {
                info->format = xml.readElementText();
            } else if (name == "publisher") {
                info->publisher = xml.readElementText();
            } else if (name == "synopsis") {
                info->synopsis = xml.readElementText();
            } else if (name == "syncDate") {
                info->syncDate = QDateTime::fromString(xml.readElementText(), Qt::ISODate);
            } else if (name == "title") {
                info->title = xml.readElementText();
            } else if (name == "author") {
                info->author = xml.readElementText();
            }else if (name == "thumbnail") {
                info->thumbnail = xml.readElementText();
            }else if (name == "publish-time") {
                info->publishTime = QDateTime::fromString(xml.readElementText(), Qt::ISODate);
            } else if (name == "download-time") {
                info->downloadTime = QDateTime::fromString(xml.readElementText(), Qt::ISODate);
            } else if (name == "lastTimeRead") {
                QString lastTime = xml.readElementText();
                if(!lastTime.isEmpty())
                    info->lastTimeRead = QDateTime::fromString(lastTime, Qt::ISODate);
            } else if (name == "readingPercentage") {
                info->readingPercentage = xml.readElementText().toDouble();
            } else if (name == "readingProgress") {
                info->readingProgress = xml.readElementText().toDouble();
            } else if (name == "readingPeriod") {
                info->setReadingPeriod(xml.readElementText().toLong());
            } else if (name == "mark-count") {
                info->markCount = xml.readElementText().toInt();
            } else if (name == "note-count") {
                info->noteCount = xml.readElementText().toInt();
            } else if (name == "hili-count") {
                info->hiliCount = xml.readElementText().toInt();
            } else if (name == "page-count") {
                info->pageCount = xml.readElementText().toInt();
            } else if (name == "last-read-link") {
                info->lastReadLink = xml.readElementText();
            } else if (name == "last-read-page") {
                info->lastReadPage = xml.readElementText().toInt();
            } else if (name == "font-size") {
                info->fontSize = xml.readElementText().toDouble();
            } else if (name == "page-mode") {
                info->pageMode = xml.readElementText().toInt();
            } else if (name == "page-orientation") {
                info->orientation = (BookInfo::orientationEnum)xml.readElementText().toInt();
            } else if (name == "corrupted") {
                info->corrupted = xml.readElementText().toInt();
            } else if (name == "type") {
                info->m_type = (BookInfo::bookTypeEnum)xml.readElementText().toInt();
            } else if (name == "archived") {
                info->m_archived = xml.readElementText().toInt();
            } else if (name == "isDRMFile") {
                info->isDRMFile = xml.readElementText().toInt();
            } else if (name == "storePrice") {
                info->storePrice = xml.readElementText();
            } else if (name == "expirationDate") {
                info->m_expirationDate = QDateTime::fromString(xml.readElementText(), Qt::ISODate);
            } else if (name == "totalReadingTime") {
                info->totalReadingTime = xml.readElementText().toInt();
            } else if (name == "timestamp") {
                info->timestamp = xml.readElementText().toLongLong();
            } else if (name == "cssFiles") {
                info->setCSSFileList(xml.readElementText().split(";"));
            } else if (name == "percentageList") {
                info->percentageList = xml.readElementText();
            } else if (name == "readingStatus") {
                info->readingStatus = (BookInfo::readStateEnum)xml.readElementText().toInt();
            } else if (name == "size") {
                info->size = xml.readElementText().toInt();
            }else if (name == "language"){
                info->language = xml.readElementText();
            }else if (name == "marks") {
                while (!xml.atEnd() && !xml.hasError())
                {
                    xml.readNext();
                    if (xml.isEndElement()) {
                        if (xml.name() == "marks") break;
                    } else if (xml.isStartElement()) {
                        if (xml.name() == "mark") {
                            BookLocation* loc = loadMark(xml);
                            info->addLocation(loc->bookmark, loc);
                        }

                    }
                }
            }
            else if (name == "collections") {
                QString collection;
                while (!xml.atEnd() && !xml.hasError())
                {
                    xml.readNext();
                    double index = 0;
                    if (xml.isEndElement()) {
                        if (xml.name() == "collections") break;
                    } else
                    {
                        QStringRef name = xml.name();
                        if (name == "collection") {
                            collection = xml.readElementText();
                            info->addCollection(collection, index);
                            addCollection(collection);
                        }

                        else if(name == "index")
                        {
                            if(!collection.isEmpty())
                            {
                                index = xml.readElementText().toDouble();
                                info->addCollection(collection, index);
                                addCollection(collection);
                            }
                        }
                    }
                }
            }
        }
    }
    if(info->readingStatus == BookInfo::NONE)
    {
        if (info->lastTimeRead.isValid()) // reading ongoing
        {
            info->readingStatus = BookInfo::READING_BOOK;
        }
        else
        {
            if(info->lastReadLink.isEmpty()) // New ebooks ever opened
                info->readingStatus = BookInfo::NO_READ_BOOK;
            else // Closed ebooks
                info->readingStatus = BookInfo::READ_BOOK;
        }
    }

    if(info->size == 0)
    {
        QFileInfo bookFile(info->path);
        bookFile.refresh();
        info->size = bookFile.size();
    }

    //For added mobi books try to extract the metadata if the author has the previous empty string.
    if(info->format == "mobi" && info->author =="--")
    {
        info->author = "";
        info->title = "";
        info->thumbnail = "";
        QString collection = "";
        if(MetaDataExtractor::getMetaData(info->path, info->title, info->author, info->publisher, info->publishTime, info->synopsis, info->format, info->isDRMFile, collection, info->language) == true)
        {
            if(info->title.isEmpty())
                info->title = QFileInfo(info->path).baseName();

            if(info->author.isEmpty())
                info->author = QString("---");
            if(!collection.isEmpty())
            {
                double collectionIndex = MetaDataExtractor::getCollectionIndex(info->path);
                info->addCollection(collection, collectionIndex);
            }
            info->setCSSFileList(MetaDataExtractor::extractCSS(info->path));
        }
    }

    //Change the empty string for author to prevent extract the metadata again.
    else if(info->author == "--")
        info->author = QString("---");

    return info;
}
bool ModelBackendOneFile::loadMetaInfo( const QString& path )
{
    qDebug() << Q_FUNC_INFO;

    QFile file(path + QDir::separator() + BOOK_DATA_FILE);
    if (!file.open(QFile::ReadOnly))
    {
        if (!file.open(QFile::ReadOnly))
        {
            qDebug() << Q_FUNC_INFO << "Cannot open newly created model file";
            return true;
		}
    }

    QXmlStreamReader xml(&file);

    xml.readNext(); //Skip first tag
    xml.readNext();

    if(xml.hasError()){
        qWarning() << Q_FUNC_INFO << "XML error before loading";
        file.copy(file.fileName() + ".backup");
        file.remove();
        return true;
    }

    if(xml.name() == "books")
    {
        m_fileModelVersion = xml.attributes().value("model_version").toString().toUInt();
        qDebug() << Q_FUNC_INFO << "model version" << m_fileModelVersion;

        while (!xml.atEnd() && !xml.hasError())
        {
            xml.readNext();
            if(xml.name() == "collections")
            {
                while (!xml.atEnd() && !xml.hasError())
                {
                    xml.readNext();
                    if(xml.isEndElement())
                    {
                        if(xml.name() == "collections")
                            break;
                    }
                    if (xml.name() == "collection" && xml.isStartElement())
                    {
                        addCollection(xml.readElementText());
                    }
                }
            }

            if (xml.name() == "book" && xml.isStartElement())
            {
                BookInfo* info = loadBook(xml);
                m_infos.insert(info->path, info);
            }
        }
    }

    file.close();

    if(xml.hasError())
    {
        qWarning() << Q_FUNC_INFO << "XML with errors. Books loaded until errors:" << m_infos.size();
        file.copy(file.fileName() + ".backup");
        qWarning() << Q_FUNC_INFO << "file to remove:" << file.remove();
    }

    return true;
}