コード例 #1
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
bool ContentNode::getContentNodeByUrl(QSqlDatabase& database,
                                      const QString & url,
                                      ContentNode & node)
{
    QSqlQuery query(database);
    query.prepare( "select id, name, location, title, authors, description, "
                   "last_access, publisher,  "
                   "rating, read_time, read_count, progress, attributes "
                   "from content where md5 = :md5" );
    query.bindValue(":md5", url);

    if (query.exec() && query.next())
    {
        int index = 0;
        node.id_ = query.value(index++).toInt();
        node.name_ = query.value(index++).toString();
        node.location_ = query.value(index++).toString();
        node.title_ = query.value(index++).toString();
        node.mutable_authors() = query.value(index++).toString();
        node.mutable_description() = query.value(index++).toString();
        node.mutable_last_access() = query.value(index++).toString();
        node.mutable_publisher() = query.value(index++).toString();
        node.mutable_md5() = url;
        node.mutable_rating() = query.value(index++).toInt();
        node.mutable_read_time() = query.value(index++).toInt();
        node.mutable_read_count() = query.value(index++).toInt();
        node.mutable_progress() = query.value(index++).toString();
        node.mutable_attributes() = query.value(index++).toByteArray();
        return true;
    }
    return false;
}
コード例 #2
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
void ContentNode::fromPath(ContentNode & node,const QString &path)
{
    node.clear();
    QFileInfo info(path);
    node.mutable_name() = info.fileName();
    node.mutable_location() = info.path();
    node.mutable_size() = info.size();
}
コード例 #3
0
bool ContentNode::hasItemNodes()
{
	int nContentNodes = getNContentNodes();
	for (int n=0; n<nContentNodes; n++) {
		ContentNode *cnode = getContentNode(n);
		if (cnode->isItemNode() == true)
			return true;
	}
	return false;
}
コード例 #4
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
bool ContentManager::addToRecentDocuments(const QString &doc_path)
{
    ContentNode node;
    getContentNode(node, doc_path);

    if (node.id() == CMS_INVALID_ID)
    {
        return false;
    }

    return addToRecentDocuments(node.id());
}
コード例 #5
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
/// Remove content metadata for given content node. Caller should no longer
/// use the content node. This function also removes the content node
/// from its parent categories.
bool ContentManager::removeContentNode(ContentNode& info)
{
    // Remove the options.
    ContentOptions::removeOptions(*database_, info.id());

    // Remove from content category table, which also removes
    // from recent document list.
    ContentCategory::removeContentCategory(*database_, info.id());

    // Remove the content itself.
    ContentNode::removeContentNode(*database_, info);
    return true;
}
コード例 #6
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
bool ContentNode::removeContentNode(QSqlDatabase& database,
                                    ContentNode& node)
{
    QSqlQuery query(database);
    query.prepare( "delete from content where id = ?");
    query.addBindValue(node.id());

    if (query.exec())
    {
        node.clear();
        return true;
    }
    return false;
}
コード例 #7
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
/// Remove child content from specified category.
bool ContentManager::removeChildContent(ContentCategory & category,
                                        const ContentNode & node)
{
    return ContentCategory::removeChildContent(*database_,
                                               category,
                                               node.id());
}
コード例 #8
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
/// Retrieve parent category id list that contains the content.
bool ContentManager::getParentCategories(const ContentNode &node,
                                         cms_ids & categories)
{
    return ContentCategory::getContentParentCategories(*database_,
                                                       node.id(),
                                                       categories);
}
コード例 #9
0
ContentNode *MediaPlayer::getContentDirectory(Device *dev)
{
	CyberXML::Node *rootNode = browseMetaData(dev, "0", "*", 0, 0, "");
	if (rootNode == NULL)
		return NULL;

	ContentNode *contentRootNode = new RootNode();
	contentRootNode->set(rootNode);
	delete rootNode;

	getContentDirectory(contentRootNode, dev, "0");
	if (Debug::isOn() == true)
		contentRootNode->print();

	return contentRootNode;
}
コード例 #10
0
ファイル: content_manager.cpp プロジェクト: HeryLong/booxsdk
bool ContentManager::removeRecentDocument(const QString &doc_path)
{
    ContentNode node;
    getContentNode(node, doc_path);

    if (node.id() == CMS_INVALID_ID)
    {
        return false;
    }

    if (!ContentCategory::removeChildContent(*database_,
                                             node.id()))
    {
        return false;
    }
    return true;
}
コード例 #11
0
ContentNode *ContentNode::findContentNodeByID(const char *id)
{
	if (id == NULL)
		return NULL;

	string idStr = id;
	const char *nodeID = getID();
	if (idStr.compare(nodeID) == 0)
		return this;

	int nodeCnt = getNContentNodes();
	for (int n=0; n<nodeCnt; n++) {
		ContentNode *cnode = getContentNode(n);
		ContentNode *fnode = cnode->findContentNodeByID(id);
		if (fnode != NULL)
			return fnode;	
	}
		
	return NULL;
}
コード例 #12
0
void UpdateItemList(int dirNum)
{
	ListView_DeleteAllItems(ghItemListWindow);

	MediaServer *mserver = gMediaGate->getMediaServer();
	Directory *dir = mserver->getContentDirectory(dirNum);
	if (dir == NULL)
		return;

	LVITEM item = {0};
	item.mask = 0;
	item.mask = LVIF_TEXT;
    TCHAR buf[512] = { 0 } ;
	int itemCnt = dir->getNContentNodes();
	for (int n=0 ; n<itemCnt ; n++) {
		ContentNode *conNode = dir->getContentNode(n);
		if (conNode->isItemNode() == false)
			continue;
		
		ItemNode *itemNode = (ItemNode *)conNode;

        FTL::CFConversion conv;
		item.pszText = (LPTSTR)conv.MBCS_TO_TCHAR(itemNode->getTitle());
		item.iItem = n;
		item.iSubItem = 0;
		ListView_InsertItem(ghItemListWindow , &item);

		item.pszText = (LPTSTR)conv.MBCS_TO_TCHAR(itemNode->getCreator());
		item.iSubItem = 1;
		ListView_SetItem(ghItemListWindow , &item);

		item.pszText = (LPTSTR)conv.MBCS_TO_TCHAR(itemNode->getDate());
		item.iSubItem = 2;
		ListView_SetItem(ghItemListWindow , &item);

		_stprintf(buf, TEXT("%ld"), itemNode->getStorageUsed());
		item.pszText = buf;
		item.iSubItem = 3;
		ListView_SetItem(ghItemListWindow , &item);
	}
}
コード例 #13
0
int MediaPlayer::getContentDirectory(ContentNode *parentNode, Device *dev, const char *objectID)
{
	if (objectID == NULL)
		return 0;

	CyberXML::Node *resultNode = browseDirectChildren(dev, objectID, "*", 0, 0, "");
	if (resultNode == NULL)
		return 0;

	BrowseResult browseResult(resultNode);
	//cout << browseResult.getNContentNodes() << endl;
	int nResultNode = 0;
	int nContents = browseResult.getNContentNodes();
	for (int n=0; n<nContents; n++) {
		Node *xmlNode = browseResult.getContentNode(n);
		ContentNode *contentNode = NULL;
		if (ContainerNode::isContainerNode(xmlNode) == true) {
			contentNode = new ContainerNode();
		}
		if (ItemNode::isItemNode(xmlNode) == true)
			contentNode = new BrowseResultNode();
		if (contentNode == NULL)
			continue;
		contentNode->set(xmlNode);
		parentNode->addContentNode(contentNode);
		nResultNode++;
		// Add Child Nodes
		if (contentNode->isContainerNode() == true) {
			ContainerNode *containerNode = (ContainerNode*)contentNode;
			int childCnt = containerNode->getChildCount();
			if (0 < childCnt) {
				const char *objid = containerNode->getID();
				getContentDirectory(contentNode, dev, objid);
			}
		}
	}
	delete resultNode;

	return nResultNode;
}
コード例 #14
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
QString ContentManager::latestReading()
{
    QString path;
    cms_ids all;
    if (!getRecentDocuments(all))
    {
        return path;
    }

    if (all.size() <= 0)
    {
        return path;
    }

    ContentNode node;
    if (!getContentNode(all.front(), node))
    {
        return path;
    }

    return node.nativeAbsolutePath();
}
コード例 #15
0
void DIDLLite::output(std::ostream& ps) 
{
	// Thanks for Brent Hills (10/26/04)
	//ps << SOAP::VERSION_HEADER;

	DIDLLiteNode didlNode;
	
	string name = didlNode.getName();
	string value = didlNode.getValue();
		
	ps << "<" << name;
	didlNode.outputAttributes(ps);
	ps << ">" << endl;

	int nNodes = getNContentNodes();
	for (int n=0; n<nNodes; n++) {
		ContentNode *contentNode = getContentNode(n);
		contentNode->output(ps, 1, false);
	}	

	ps << "</" << name << ">" << endl;
}
コード例 #16
0
void SourceListWidget::DropContentViewItems(QDropEvent *e)
{
    // accepting drops from contenttreeview
    QList<QUrl> urls = e->mimeData()->urls();
    for (int i = 0; i != urls.size(); i++)
    {
        ContentNode *n = ContentTreeView::QUrl2ContentNode(urls.at(i));
        if (n == NULL) {
            continue;
        } else if (n->ParseAsGroup() != NULL) {
            // group
            vector<Layer *> layers = _LayerManager().FetchAllLayer(n);
            for (unsigned int i = 0; i != layers.size(); i++) {
                AddLayer(layers[i]);
            }
        } else if (n->ParseAsLayer() != NULL) {
            // layer
            AddLayer(n->ParseAsLayer());
        } else {
            // undefined
        }
    }
}
コード例 #17
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
bool ContentManager::removeChildContent(ContentNode & node)
{
    // Retrieve parent categories from content_category table.
    return ContentCategory::removeChildContent(*database_, node.id());
}
コード例 #18
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
bool ContentNode::updateContentNode(QSqlDatabase& database,
                                    const ContentNode & node)
{
    QSqlQuery query(database);
    query.prepare ("update content set "
                   " name = ?, location = ?, title = ?, authors = ?, "
                   " description = ?, last_access = ?, publisher = ?, md5 = ?, "
                   " size = ?, rating = ?, read_time = ?, read_count = ?, "
                   " progress = ?, attributes = ? "
                   " where id = ?");

    query.addBindValue(node.name());
    query.addBindValue(node.location());
    query.addBindValue(node.title());
    query.addBindValue(node.authors());
    query.addBindValue(node.description());
    query.addBindValue(node.last_access());
    query.addBindValue(node.publisher());

    query.addBindValue(node.md5());
    query.addBindValue(node.size());
    query.addBindValue(node.rating());
    query.addBindValue(node.read_time());
    query.addBindValue(node.read_count());

    query.addBindValue(node.progress());
    query.addBindValue(node.attributes());

    query.addBindValue(node.id());

    return query.exec();
}
コード例 #19
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
bool ContentNode::createContentNode(QSqlDatabase& database,
                                    ContentNode & node)
{
    QSqlQuery query(database);
    query.prepare ("insert into content "
                   "(name, location, title, authors, description, "
                   "last_access, publisher, md5, "
                   "size, rating, read_time, read_count, progress, attributes ) "
                   " values "
                   "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

    query.addBindValue(node.name());
    query.addBindValue(node.location());
    query.addBindValue(node.title());
    query.addBindValue(node.authors());
    query.addBindValue(node.description());
    query.addBindValue(node.last_access());
    query.addBindValue(node.publisher());

    query.addBindValue(node.md5());
    query.addBindValue(node.size());
    query.addBindValue(node.rating());
    query.addBindValue(node.read_time());
    query.addBindValue(node.read_count());
    query.addBindValue(node.progress());
    query.addBindValue(node.attributes());

    if (query.exec())
    {
        node.id_ = query.lastInsertId().toInt();
        return true;
    }
    return false;
}
コード例 #20
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
/// Update content by url.
bool ContentNode::updateContentNodeByUrl(QSqlDatabase& database,
        const ContentNode & node,
        const QString & url)
{
    // Check at first.
    ContentNode tmp;
    bool found = getContentNodeByUrl(database, url, tmp);

    if (!found)
    {
        QSqlQuery query(database);
        query.prepare ("INSERT into content  "
                       " (name, location, title, authors, "
                       " description, last_access, publisher, md5, "
                       " size, rating, read_time, read_count, "
                       " progress, attributes) values "
                       " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");

        query.addBindValue(node.name());
        query.addBindValue(node.location());
        query.addBindValue(node.title());
        query.addBindValue(node.authors());
        query.addBindValue(node.description());
        query.addBindValue(node.last_access());
        query.addBindValue(node.publisher());
        query.addBindValue(url);
        query.addBindValue(node.size());
        query.addBindValue(node.rating());
        query.addBindValue(node.read_time());
        query.addBindValue(node.read_count());
        query.addBindValue(node.progress());
        query.addBindValue(node.attributes());

        if (!query.exec())
        {
            qDebug() << query.lastError();
            return false;
        }
    }
    else
    {
        QSqlQuery query(database);
        query.prepare ("update content set "
                       " name = ?, location = ?, title = ?, authors = ?, "
                       " description = ?, last_access = ?, publisher = ?,  "
                       " size = ?, rating = ?, read_time = ?, read_count = ?, "
                       " progress = ?, attributes = ? "
                       " where md5 = ?");

        query.addBindValue(node.name());
        query.addBindValue(node.location());
        query.addBindValue(node.title());
        query.addBindValue(node.authors());
        query.addBindValue(node.description());
        query.addBindValue(node.last_access());
        query.addBindValue(node.publisher());

        query.addBindValue(node.size());
        query.addBindValue(node.rating());
        query.addBindValue(node.read_time());
        query.addBindValue(node.read_count());

        query.addBindValue(node.progress());
        query.addBindValue(node.attributes());

        query.addBindValue(url);

        if (!query.exec())
        {
            qDebug() << query.lastError();
            return false;
        }
    }
    return true;
}
コード例 #21
0
ファイル: content_manager.cpp プロジェクト: peter-x/booxsdk
/// Add child content into specified category.
bool ContentManager::addChildContent(ContentCategory & category,
                                     const ContentNode & node)
{
    // Check it's already in the category or not.
    return ContentCategory::addChildContent(*database_, category, node.id());
}
コード例 #22
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
/// TODO, need a better way to identify the file.
/// Lookup the file name.
/// Check the location.
/// File content hash. (Which part to hash and length).
bool ContentNode::getContentNode(QSqlDatabase & database,
                                 ContentNode &node)
{
    QSqlQuery query(database);
    query.prepare( "select id, title, authors, description, "
                   "last_access, publisher, md5, "
                   "rating, read_time, read_count, progress, attributes "
                   "from content where name = :name and location = :location "
                   "and size = :size" );
    query.bindValue(":name", node.name());
    query.bindValue(":location", node.location());
    query.bindValue(":size", node.size());

    if (query.exec() && query.next())
    {
        int index = 0;
        node.id_ = query.value(index++).toInt();
        node.title_ = query.value(index++).toString();
        node.mutable_authors() = query.value(index++).toString();
        node.mutable_description() = query.value(index++).toString();
        node.mutable_last_access() = query.value(index++).toString();
        node.mutable_publisher() = query.value(index++).toString();
        node.mutable_md5() = query.value(index++).toString();
        node.mutable_rating() = query.value(index++).toInt();
        node.mutable_read_time() = query.value(index++).toInt();
        node.mutable_read_count() = query.value(index++).toInt();
        node.mutable_progress() = query.value(index++).toString();
        node.mutable_attributes() = query.value(index++).toByteArray();
        return true;
    }
    return false;
}
コード例 #23
0
ファイル: content_node.cpp プロジェクト: qbikez/booxsdk
// Need to define the search policy.
// - Match the name, location and size.
// - Otherwise, we just ignore the request.
// - We can also use the hash code to match the file.
/// Query the content node in the specified database.
/// \param database The sqlitepp wrapper of database.
/// \param info The content node information returned by this function.
/// \param absolute_path The absolute path of the node.
/// \param create Create the content node automatically if not found.
/// \return This function returns true if the content node is already in
/// the database, otherwise it returns false.
bool
ContentNode::getContentNode(QSqlDatabase &database,
                            ContentNode & node,
                            const QString & absolute_path,
                            bool create)
{
    // Initialize query parameters and initialize all stuff
    // that does not rely on the database.
    QFileInfo info(absolute_path);

    node.mutable_size() = info.size();
    node.mutable_location() = info.path();
    node.mutable_name() = info.fileName();

    // Query by name, location and size.
    QSqlQuery query(database);
    query.prepare( "select id, title, authors, description, "
                   "last_access, publisher, md5, "
                   "rating, read_time, read_count, progress, attributes "
                   "from content where name = :name and location = :location "
                   "and size = :size" );
    query.bindValue(":name", node.name());
    query.bindValue(":location", node.location());
    query.bindValue(":size", node.size());

    if (query.exec() && query.next())
    {
        int index = 0;
        node.id_ = query.value(index++).toInt();
        node.title_ = query.value(index++).toString();
        node.mutable_authors() = query.value(index++).toString();
        node.mutable_description() = query.value(index++).toString();
        node.mutable_last_access() = query.value(index++).toString();
        node.mutable_publisher() = query.value(index++).toString();
        node.mutable_md5() = query.value(index++).toString();
        node.mutable_rating() = query.value(index++).toInt();
        node.mutable_read_time() = query.value(index++).toInt();
        node.mutable_read_count() = query.value(index++).toInt();
        node.mutable_progress() = query.value(index++).toString();
        node.mutable_attributes() = query.value(index++).toByteArray();
        return true;
    }

    // File has been moved, check the name and size.
    /*
    {
        statement st(database);
        st  << "select id, title, authors, description, "
            << "last_access, publisher, md5, "
            << "rating, read_time, read_count "
            << "from content where name = :name and size = :size",
            node.id_),
            into(info.mutable_title()),
            into(info.mutable_authors()),
            into(info.mutable_description()),
            into(info.mutable_last_access()),
            into(info.mutable_publisher()),
            into(info.mutable_md5()),
            into(info.mutable_rating()),
            into(info.mutable_read_time()),
            into(info.mutable_read_count()),
            use(info.name()),
            use(info.size());
        if (st.exec())
        {
            return true;
        }
    }

    // File name has been changed, check the md5 only.
    // Check if the md5 is ready or not. Make sure md5
    // is calculated only once.
    // TODO, maybe just ignore the node as it's not important.
    if (info.md5().empty() &&
        FileMd5Sum(absolute_path, info.mutable_md5()))
    {
        statement st(database);
        st  << "select id, title, authors, description, "
            << "last_access, publisher, "
            << "rating, read_time, read_count "
            << "from content where md5 = :md5",
            into(info.id_),
            into(info.mutable_title()),
            into(info.mutable_authors()),
            into(info.mutable_description()),
            into(info.mutable_last_access()),
            into(info.mutable_publisher()),
            into(info.mutable_rating()),
            into(info.mutable_read_time()),
            into(info.mutable_read_count()),
            use(info.md5());
        if (st.exec())
        {
            return true;
        }
    }
    */

    // Insert into the database. Should change the function name.
    if (create)
    {
        createContentNode(database, node);
    }
    return false;
}