Example #1
0
Element* Bank::writeProgram( Program* program )
{
	Element* programElement = new Element( "Program" );

	programElement->SetAttribute( "name",     program->name_ );
    programElement->SetAttribute( "category", program->category_ );
    programElement->SetAttribute( "comment",  program->comment_ );
	programElement->SetAttribute( "voices",   program->numVoices_ );
    if( program->numUnison_ > 1 )
    {
        programElement->SetAttribute( "unison",   program->numUnison_ );
        programElement->SetAttribute( "sprd",     program->unisonSpread_ );
    }
    if( program->hold_ ) 
        programElement->SetAttribute( "hold", program->hold_ );
    if( program->retrigger_ ) 
        programElement->SetAttribute( "retrig", program->retrigger_ );
    if( program->legato_ ) 
        programElement->SetAttribute( "legato", program->legato_ );

	for( Program::iterator itProgram = program->begin(); itProgram != program->end(); itProgram++ ) 
	{
        Element* moduleElement = writeModule( *itProgram );
        programElement->LinkEndChild( moduleElement );
	}
	return programElement;
}
Example #2
0
void Bank::getXml( ModuleData* data, ostringstream& result )
{
    Document doc;
    Element* element = writeModule( data );
    doc.LinkEndChild( element );

    result << doc;
}
Example #3
0
void Writer::writePipeline ()
{
	NoiseAssert (!mModuleVec.empty(), mModuleVec);
	NoiseAssert (mModuleCount == mModules.size(), mModuleCount);
	NoiseAssert (mModuleCount == mModuleVec.size(), mModuleCount);

	unsigned char ver = NOISE_FILE_VERSION;
	mStream.write (ver);
	mStream.write (mModuleCount);
	// writing module properties
	for (ModuleVector::iterator it=mModuleVec.begin();it!=mModuleVec.end();++it)
		writeModule(*it);
	// writing module relations
	for (ModuleVector::iterator it=mModuleVec.begin();it!=mModuleVec.end();++it)
		writeModuleRel(*it);
}
Example #4
0
LogConsole& LogConsole::operator <<( LogConsole::State inState )
{
    switch( inState.type )
    {
        case 4:
        {
            std::cout << std::endl;
            break;
        }

        default:
        {
            writeModule(inState.module,inState.type);
            break;
        }
    }

    return (*this);
}
Example #5
0
void CodeGenerator::writeAndFreeLLModule(const char *filename) {
  ir_->DBuilder.Finalize();

  emitLinkerOptions(*ir_, ir_->module, ir_->context());

  // Emit ldc version as llvm.ident metadata.
  llvm::NamedMDNode *IdentMetadata =
      ir_->module.getOrInsertNamedMetadata("llvm.ident");
  std::string Version("ldc version ");
  Version.append(global.ldc_version);
#if LDC_LLVM_VER >= 306
  llvm::Metadata *IdentNode[] =
#else
  llvm::Value *IdentNode[] =
#endif
      {llvm::MDString::get(ir_->context(), Version)};
  IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode));

  writeModule(&ir_->module, filename);
  delete ir_;
  ir_ = nullptr;
}
Example #6
0
void TTRssFetcher::storeCategories()
{
    auto db = DatabaseManager::instance();
    QString dashboardId = "ttrss";

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    if (jsonObj["content"].isArray()) {
        QJsonArray arr = jsonObj["content"].toArray();
        int end = arr.count();
#else
        if (jsonObj["content"].type()==QVariant::List) {
            QVariantList::const_iterator i = jsonObj["content"].toList().constBegin();
            QVariantList::const_iterator end = jsonObj["content"].toList().constEnd();
#endif
        for (int i = 0; i < end; ++i) {
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
            QJsonObject obj = arr.at(i).toObject();
#else
            QVariantMap obj = (*i).toMap();
#endif
            if (obj["id"].toInt() >= 0) {
                DatabaseManager::Tab t;
                t.id = obj["id"].isString() ? obj["id"].toString() : QString::number(obj["id"].toInt());
                t.dashboardId = dashboardId;
                t.title = obj["title"].toString();
                db->writeTab(t);
            }
        }
    } else {
        qWarning() << "No categories found";
    }
}

void TTRssFetcher::storeFeeds()
{
    auto s = Settings::instance();
    auto db = DatabaseManager::instance();

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    if (jsonObj["content"].isArray()) {
        QJsonArray arr = jsonObj["content"].toArray();
        int end = arr.count();
#else
    if (jsonObj["content"].type()==QVariant::List) {
        QVariantList::const_iterator i = jsonObj["content"].toList().constBegin();
        QVariantList::const_iterator end = jsonObj["content"].toList().constEnd();
#endif
        for (int i = 0; i < end; ++i) {
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
            QJsonObject obj = arr.at(i).toObject();
#else
            QVariantMap obj = (*i).toMap();
#endif
            DatabaseManager::Stream st;
            st.id = obj["id"].isString() ? obj["id"].toString() : QString::number(obj["id"].toInt());
            st.title = obj["title"].toString();
            st.link = obj["feed_url"].toString();
            st.query = st.link;
            st.content = "";
            st.type = "";
            st.unread = 0;
            st.saved = 0;
            st.read = 0;
            st.slow = 0;
            st.newestItemAddedAt = obj["last_updated"].toInt();
            st.updateAt = st.newestItemAddedAt;
            st.lastUpdate = QDateTime::currentDateTimeUtc().toTime_t();
            if (obj["has_icon"].toBool()) {
                st.icon = s->getUrl() + "/" + iconsUrl + "/" + st.id + ".ico";
                DatabaseManager::CacheItem item;
                item.origUrl = st.icon;
                item.finalUrl = st.icon;
                item.type = "icon";
                emit addDownload(item);
            }

            db->writeStream(st);

            DatabaseManager::Module m;
            m.id = st.id;
            m.name = st.title;
            m.title = st.title;
            m.status = "";
            m.widgetId = "";
            m.pageId = "";
            m.tabId = obj["id"].isString() ? obj["cat_id"].toString() : QString::number(obj["cat_id"].toInt());
            m.streamList.append(st.id);
            db->writeModule(m);
        }
    } else {
        qWarning() << "No feeds found";
    }
}

void TTRssFetcher::storeStream()
{
    auto s = Settings::instance();
    auto db = DatabaseManager::instance();
    auto dm = DownloadManager::instance();

    int count = 0;

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    if (jsonObj["content"].isArray()) {
        QJsonArray arr = jsonObj["content"].toArray();
        int end = arr.count();
        count = end;
#else
    if (jsonObj["content"].type()==QVariant::List) {
        QVariantList::const_iterator i = jsonObj["content"].toList().constBegin();
        QVariantList::const_iterator end = jsonObj["content"].toList().constEnd();
#endif

        for (int i = 0; i < arr.count(); ++i) {
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
            QJsonObject obj = arr.at(i).toObject();
#else
            QVariantMap obj = (*i).toMap();
            ++count;
#endif

            DatabaseManager::Entry e;
            e.id = obj["id"].isString() ? obj["id"].toString() : QString::number(obj["id"].toInt());
            e.streamId = obj["feed_id"].isString() ? obj["feed_id"].toString() : QString::number(obj["feed_id"].toInt());
            e.title = obj["title"].toString();
            e.author = obj["author"].toString();

            if (obj["content"].isString())
                e.content = obj["content"].toString();

            e.link = obj["link"].toString();
            e.read = obj["unread"].toBool() ? 0 : 1;
            e.saved = obj["marked"].toBool() ? 1 : 0;
            e.publishedAt = obj["updated"].toInt();
            e.createdAt = obj["updated"].toInt();
            e.cached = 0;
            e.fresh = 1;
            e.broadcast = obj["published"].toBool() ? 1 : 0;
            e.timestamp = obj["updated"].toInt();

            QRegExp rx("<img\\s[^>]*src\\s*=\\s*(\"[^\"]*\"|'[^']*')", Qt::CaseInsensitive);
            if (rx.indexIn(e.content)!=-1) {
                QString imgSrc = rx.cap(1); imgSrc = imgSrc.mid(1,imgSrc.length()-2);
                if (!imgSrc.isEmpty()) {
                    imgSrc.replace("&amp;","&", Qt::CaseInsensitive);
                    if (s->getCachingMode() == 2 || (s->getCachingMode() == 1 && dm->isWLANConnected())) {
                        if (!db->isCacheExistsByFinalUrl(Utils::hash(imgSrc))) {
                            DatabaseManager::CacheItem item;
                            item.origUrl = imgSrc;
                            item.finalUrl = imgSrc;
                            item.type = "entry-image";
                            emit addDownload(item);
                        }
                    }
                    e.image = imgSrc;
                }
            }

            db->writeEntry(e);
            if (!e.saved && !e.broadcast && s->getRetentionDays() > 0) {
                int date = QDateTime::fromTime_t(e.timestamp).daysTo(QDateTime::currentDateTimeUtc());
                if (date > lastDate)
                    lastDate = date;
            }
        }

        lastCount = count;
    }
}

void TTRssFetcher::uploadActions()
{
    if (!actionsList.isEmpty()) {
        emit uploading();
        setAction();
    }
}

void TTRssFetcher::setAction()
{
    auto db = DatabaseManager::instance();
    DatabaseManager::Action action = actionsList.first();

    QString ids;
    int mode, field;

    switch (action.type)
    {
    case DatabaseManager::SetRead:
    case DatabaseManager::UnSetRead:
    {
        ids = action.id1.replace('&', ',');
        mode = action.type == DatabaseManager::SetRead ? 0 : 1;
        field = 2;
        break;
    }
    case DatabaseManager::SetSaved:
    case DatabaseManager::UnSetSaved:
    {
        ids = action.id1.replace('&', ',');
        mode = action.type == DatabaseManager::SetSaved ? 1 : 0;
        field = 0;
        break;
    }
    case DatabaseManager::SetBroadcast:
    case DatabaseManager::UnSetBroadcast:
    {
        ids = action.id1.replace('&', ',');
        mode = action.type == DatabaseManager::SetBroadcast ? 1 : 0;
        field = 1;
        break;
    }
    case DatabaseManager::SetStreamReadAll:
    case DatabaseManager::UnSetStreamReadAll:
    {
        ids = mergeEntryIds(db->readEntriesByStream(action.id1, 0, db->countEntriesByStream(action.id1)),
                            action.type == DatabaseManager::SetStreamReadAll);
        mode = action.type == DatabaseManager::SetStreamReadAll ? 0 : 1;
        field = 2;
        break;
    }
    case DatabaseManager::SetTabReadAll:
    case DatabaseManager::UnSetTabReadAll:
    {
        QList<QString> streams = db->readStreamIdsByTab(action.id1);
        for (int i = 0; i < streams.count(); ++i) {
            QString streamIds = mergeEntryIds(db->readEntriesByStream(streams[i], 0, db->countEntriesByStream(streams[i])),
                                              action.type == DatabaseManager::SetTabReadAll);
            if (!streamIds.isEmpty()) {
                if (!ids.isEmpty())
                    ids += ",";
                ids += streamIds;
            }
        }

        mode = action.type == DatabaseManager::SetTabReadAll ? 0 : 1;
        field = 2;
        break;
    }
    case DatabaseManager::SetAllRead:
    case DatabaseManager::UnSetAllRead:
    {
        QList<DatabaseManager::Stream> streams = db->readStreamsByDashboard(action.id1);
        for (int i = 0; i < streams.count(); ++i) {
            QString streamIds = mergeEntryIds(db->readEntriesByStream(streams[i].id, 0, db->countEntriesByStream(streams[i].id)),
                                              action.type == DatabaseManager::SetAllRead);
            if (!streamIds.isEmpty()) {
                if (!ids.isEmpty())
                    ids += ",";
                ids += streamIds;
            }
        }

        mode = action.type == DatabaseManager::SetAllRead ? 0 : 1;
        field = 2;
        break;
    }
    case DatabaseManager::SetListRead:
    case DatabaseManager::UnSetListRead:
    {
        ids = action.id1.replace('&', ',');
        mode = action.type == DatabaseManager::SetListRead ? 0 : 1;
        field = 2;
        break;
    }
    case DatabaseManager::SetListSaved:
    case DatabaseManager::UnSetListSaved:
    {
        ids = action.id1.replace('&', ',');
        mode = action.type == DatabaseManager::SetListSaved ? 1 : 0;
        field = 1;
        break;
    }
    default:
        qWarning() << "Unknown action type: " << action.type;
        finishedSetAction();
        return;
    }

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    QJsonObject params;
    params["article_ids"] = ids;
    params["mode"] = mode;
    params["field"] = field;
#else
    QString params = "\"article_ids\":\"" + ids + "\",\"mode\":" + QString::number(mode) +
        ",\"field\":" + QString::number(field);
#endif

    sendApiCall("updateArticle", params, FETCHER_SLOT(finishedSetAction));
}