bool kvoctrainDoc::saveToLex (QTextStream& os, QString & /*title*/) { os << LEX_IDENT_50 "\n"; os << "LEX|" << getOriginalIdent() << "|" << getIdent(1) << "|" << "259 260 1 1 1 0 0 268 0 1 1 1 1 "; os << (int) vocabulary.size(); os << " 9 5 1999 255 1 1 653 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 1 1 0 0 |#3" << "\n"; os << "-11 700 0 0 0 0 0 0 0 0 0 0" << "\n"; os << "System\n"; os << getTitle() << "\n"; os << "1 1 der die das|he she it|" << "\n"; os << "1 1 eine einer eines einen einem|has have had is be|" << "\n"; os << "1 1 er sie es|his him her its|" << "\n"; os << "1 1 wir ihr euch|in to into on at too|" << "\n"; os << "1 1 in an auf bei|the a an|" << "\n"; os << "1 1 zu um zur zum|out by with of off|" << "\n"; os << "1 1 ist sind seid|something someone some|" << "\n"; os << "1 1 dies dieser dieses|under below|" << "\n"; os << "1 1 ||" << "\n"; os << "1 1 ||" << "\n"; os << "der die das ein eine einer eines einen einem|the a an|" << "\n"; if (!saveTypeNameLex (os)) return false; if (!saveLessonLex (os)) return false; os << "32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32" << "\n"; int ent_no = 0; int ent_percent = (int) vocabulary.size () / 100; float f_ent_percent = (int) vocabulary.size () / 100.0; emit progressChanged(this, 0); vector<kvoctrainExpr>::const_iterator first = vocabulary.begin (); while (first != vocabulary.end ()) { ent_no++; if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) emit progressChanged(this, int(ent_no / f_ent_percent)); os << "0" // type << " " << "255 255 255 255 255 255 255" << " " << QMIN (2, (*first).getGrade(false)) << " " << QMIN (2, (*first).getGrade(true)) << " " << (*first).getLesson() << " " << (*first).getOriginal() << " " << "||||" // synonyms << (*first).getTranslation(1) << "||||" // synonyms << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << "\n"; first++; } setModified (false); return os.device()->status() == IO_Ok; }
void TestM3UPlaylist::initTestCase() { qRegisterMetaType<Meta::TrackPtr>( "Meta::TrackPtr" ); /* Collection manager needs to be instantiated in the main thread, but * MetaProxy::Tracks used by playlist may trigger its creation in a different thread. * Pre-create it explicitly */ CollectionManager::instance(); const KUrl url = dataPath( "data/playlists/test.m3u" ); QFile playlistFile1( url.toLocalFile() ); QTextStream playlistStream; QString tempPath = KStandardDirs::locateLocal( "tmp", "test.m3u" ); QFile::remove( tempPath ); QVERIFY( QFile::copy( url.toLocalFile(), tempPath ) ); QVERIFY( QFile::exists( tempPath ) ); QVERIFY( playlistFile1.open( QFile::ReadOnly ) ); playlistStream.setDevice( &playlistFile1 ); QVERIFY( playlistStream.device() ); m_testPlaylist = new Playlists::M3UPlaylist( tempPath ); QVERIFY( m_testPlaylist ); QVERIFY( m_testPlaylist->load( playlistStream ) ); QCOMPARE( m_testPlaylist->tracks().size(), 10 ); playlistFile1.close(); }
void QtMessageOutput(QtMsgType type, const char *msg) { if(w_g) w_g->writeToConsoleQt( type, msg ); if (qt_debug_output.device()!=NULL) qt_debug_output << msg << "\n"; }
QString DeploymentData::addFilesFromDeploymentFile(const QString &deploymentFilePath, const QString &sourceDir) { const QString sourcePrefix = sourceDir.endsWith('/') ? sourceDir : sourceDir + '/'; QFile deploymentFile(deploymentFilePath); QTextStream deploymentStream; QString deploymentPrefix; if (!deploymentFile.open(QFile::ReadOnly | QFile::Text)) return deploymentPrefix; deploymentStream.setDevice(&deploymentFile); deploymentPrefix = deploymentStream.readLine(); if (!deploymentPrefix.endsWith('/')) deploymentPrefix.append('/'); if (deploymentStream.device()) { while (!deploymentStream.atEnd()) { QString line = deploymentStream.readLine(); if (!line.contains(':')) continue; QStringList file = line.split(':'); QString sourceFile = file.at(0); if (QFileInfo(sourceFile).isRelative()) sourceFile.prepend(sourcePrefix); QString targetFile = file.at(1); if (QFileInfo(targetFile).isRelative()) targetFile.prepend(deploymentPrefix); addFile(sourceFile, targetFile); } } return deploymentPrefix; }
bool ClassGenerator::finishStreams(const QString& baseName, QTextStream& headerStream, QTextStream& sourceStream) { closeIncludeGuard(baseName, headerStream); writeFileFooter(headerStream); writeFileFooter(sourceStream); QIODevice* device = headerStream.device(); headerStream.unsetDevice(); delete device; device = sourceStream.device(); sourceStream.unsetDevice(); delete device; return true; }
void CloseHeader(QTextStream &file, const QString &pre_name_withoutpath) { // close the file file.device()->close(); delete file.device(); QString pre_name; if (outputtoinputdir) pre_name = currentInputDir + pre_name_withoutpath; else pre_name = pre_name_withoutpath; // create the real target file name QString post_name = pre_name.right(pre_name.length() - preHeaderLeader.length()); unsigned int pre_cksum; FileContentsChecksum(pre_name, &pre_cksum); unsigned int post_cksum; bool havePostFile = FileContentsChecksum(post_name, &post_cksum); if (havePostFile) { if (post_cksum == pre_cksum) { // Since the new header file is the same as the old, don't // touch the old and remove the new (pre) one. QFile(pre_name).remove(); cOut << "Note: Header file \"" << post_name << "\" did NOT change." << Endl; } else { // Since the new headeer file is different from the old, // remove the old one and rename the new one. QFile(post_name).remove(); QFile(pre_name).rename(post_name); cOut << "Note: Header file \"" << post_name << "\" changed." << Endl; } } else { QFile(pre_name).rename(post_name); } }
ConversionStatus GettextImportPlugin::readHeader(QTextStream& stream) { CatalogItem temp; int filePos=stream.device()->at(); ConversionStatus status=readEntry(stream); if(status==OK || status==RECOVERED_PARSE_ERROR) { // test if this is the header if(!_msgid.first().isEmpty()) { stream.device()->at(filePos); } return status; } return PARSE_ERROR; }
bool kvoctrainDoc::saveTypeNameLex (QTextStream &os) { int i; for (i = 0; i < (int) type_descr.size() && i < LEX_MAX_ATTR; i++) os << getTypeName(i) << "|\n"; while (i++ < LEX_MAX_ATTR) os << "|\n"; return os.device()->status() == IO_Ok; }
bool kvoctrainDoc::saveLessonLex (QTextStream &os) { int i; for (i = 0; i < (int) lesson_descr.size() && i < LEX_MAX_LESSON; i++) os << lesson_descr[i] << "|\n"; while (i++ < LEX_MAX_LESSON) os << "|\n"; return os.device()->status() == IO_Ok; }
void TestM3UPlaylist::initTestCase() { const KUrl url = dataPath( "data/playlists/test.m3u" ); QFile playlistFile1( url.toLocalFile() ); QTextStream playlistStream; QVERIFY( playlistFile1.open( QFile::ReadOnly ) ); playlistStream.setDevice( &playlistFile1 ); QVERIFY( playlistStream.device() ); m_testPlaylist = new Playlists::M3UPlaylist( url ); QVERIFY( m_testPlaylist->load( playlistStream ) ); QCOMPARE( m_testPlaylist->tracks().size(), 10 ); playlistFile1.close(); }
bool kvoctrainDoc::loadLessonLex (QTextStream &is) { QString s; QString lesson; lesson_descr.clear(); for (int i = 0; i < LEX_MAX_LESSON; i++) { s = is.readLine(); lesson = extract (s); if (lesson.stripWhiteSpace().isEmpty()) { lesson = "#" + QString::number(i+1); } lesson_descr.push_back (lesson); } return is.device()->status() == IO_Ok; }
bool kvoctrainDoc::loadTypeNameLex (QTextStream &is) { QString s; QString attr; type_descr.clear(); for (int i = 0; i < LEX_MAX_ATTR; i++) { s = is.readLine(); attr = extract (s); /* if (attr.stripWhiteSpace().isEmpty()) { attr.setNum (i+1); attr.insert (0, "#"); } */ type_descr.push_back (attr); } return is.device()->status() == IO_Ok; }
bool ProjectGenerator::writeMakefile(QTextStream &t) { t << "######################################################################" << endl; t << "# Automatically generated by qmake (" QMAKE_VERSION_STR ") " << QDateTime::currentDateTime().toString() << endl; t << "######################################################################" << endl << endl; if (!Option::globals->precmds.isEmpty()) t << Option::globals->precmds << endl; t << getWritableVar("TEMPLATE_ASSIGN", false); if(project->first("TEMPLATE_ASSIGN") == "subdirs") { t << endl << "# Directories" << "\n" << getWritableVar("SUBDIRS"); } else { //figure out target QString ofn = QFileInfo(static_cast<QFile *>(t.device())->fileName()).completeBaseName(); if (ofn.isEmpty() || ofn == "-") ofn = "unknown"; project->values("TARGET_ASSIGN") = ProStringList(ofn); t << getWritableVar("TARGET_ASSIGN") << getWritableVar("CONFIG", false) << getWritableVar("CONFIG_REMOVE", false) << getWritableVar("INCLUDEPATH") << endl; t << "# Input" << "\n"; t << getWritableVar("HEADERS") << getWritableVar("FORMS") << getWritableVar("LEXSOURCES") << getWritableVar("YACCSOURCES") << getWritableVar("SOURCES") << getWritableVar("RESOURCES") << getWritableVar("TRANSLATIONS"); } if (!Option::globals->postcmds.isEmpty()) t << Option::globals->postcmds << endl; return true; }
ConversionStatus GettextImportPlugin::readEntry(QTextStream& stream) { //kdDebug( KBABEL ) << k_funcinfo << " START" << endl; enum {Begin,Comment,Msgctxt,Msgid,Msgstr} part=Begin; QString line; bool error=false; bool recoverableError=false; bool seenMsgctxt=false; _msgstr.clear(); _msgstr.append(QString()); _msgid.clear(); _msgid.append(QString()); _msgctxt=QString(); _comment=QString(); _gettextPluralForm=false; _obsolete=false; QStringList::Iterator msgstrIt=_msgstr.begin(); while( !stream.eof() ) { const int pos=stream.device()->at(); line=stream.readLine(); //kdDebug() << "Parsing line: " << line << endl; // ### Qt4: no need of a such a check if(line.isNull()) // file end break; else if ( line.startsWith( "<<<<<<<" ) || line.startsWith( "=======" ) || line.startsWith( ">>>>>>>" ) ) { // We have found a CVS/SVN conflict marker. Abort. // (It cannot be any useful data of the PO file, as otherwise the line would start with at least a quote) kdError(KBABEL) << "CVS/SVN conflict marker found! Aborting!" << endl << line << endl; return PARSE_ERROR; } // remove whitespaces from beginning and end of line line=line.stripWhiteSpace(); if(part==Begin) { // ignore trailing newlines if(line.isEmpty()) continue; if(line.startsWith("#~")) { _obsolete=true; part=Comment; _comment=line; } else if(line.startsWith("#")) { part=Comment; _comment=line; } else if(line.find(QRegExp("^msgctxt\\s*\".*\"$")) != -1) { part=Msgctxt; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgctxt\\s*\"")); line.remove(QRegExp("\"$")); _msgctxt=line; seenMsgctxt=true; } else if(line.find(QRegExp("^msgid\\s*\".*\"$")) != -1) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"")); line.remove(QRegExp("\"$")); (*(_msgid).begin())=line; } // one of the quotation marks is missing else if(line.find(QRegExp("^msgid\\s*\"?.*\"?$")) != -1) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"?")); line.remove(QRegExp("\"$")); (*(_msgid).begin())=line; if(!line.isEmpty()) recoverableError=true; } else { kdDebug(KBABEL) << "no comment, msgctxt or msgid found after a comment: " << line << endl; error=true; break; } } else if(part==Comment) { if(line.isEmpty() && _obsolete ) return OK; if(line.isEmpty() ) continue; else if(line.startsWith("#~")) { _comment+=("\n"+line); _obsolete=true; } else if(line.startsWith("#")) { _comment+=("\n"+line); } else if(line.find(QRegExp("^msgctxt\\s*\".*\"$")) != -1) { part=Msgctxt; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgctxt\\s*\"")); line.remove(QRegExp("\"$")); _msgctxt=line; seenMsgctxt=true; } else if(line.find(QRegExp("^msgid\\s*\".*\"$")) != -1) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"")); line.remove(QRegExp("\"$")); (*(_msgid).begin())=line; } // one of the quotation marks is missing else if(line.find(QRegExp("^msgid\\s*\"?.*\"?$")) != -1) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"?")); line.remove(QRegExp("\"$")); (*(_msgid).begin())=line; if(!line.isEmpty()) recoverableError=true; } else { kdDebug(KBABEL) << "no comment or msgid found after a comment while parsing: " << _comment << endl; error=true; break; } } else if(part==Msgctxt) { if(line.isEmpty()) continue; else if(line.find(QRegExp("^\".*\\n?\"$")) != -1) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^\"")); line.remove(QRegExp("\"$")); // add Msgctxt line to item if(_msgctxt.isEmpty()) _msgctxt=line; else _msgctxt+=("\n"+line); } else if(line.find(QRegExp("^msgid\\s*\".*\"$")) != -1) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"")); line.remove(QRegExp("\"$")); (*(_msgid).begin())=line; } // one of the quotation marks is missing else if(line.find(QRegExp("^msgid\\s*\"?.*\"?$")) != -1) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"?")); line.remove(QRegExp("\"$")); (*(_msgid).begin())=line; if(!line.isEmpty()) recoverableError=true; } else { kdDebug(KBABEL) << "no msgid found after a msgctxt while parsing: " << _msgctxt << endl; error=true; break; } } else if(part==Msgid) { if(line.isEmpty()) continue; else if(line.find(QRegExp("^\".*\\n?\"$")) != -1) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^\"")); line.remove(QRegExp("\"$")); QStringList::Iterator it; if(_gettextPluralForm) it = _msgid.fromLast(); else it = _msgid.begin(); // add Msgid line to item if((*it).isEmpty()) (*it)=line; else (*it)+=("\n"+line); } else if(line.find(QRegExp("^msgid_plural\\s*\".*\"$")) != -1) { part=Msgid; _gettextPluralForm = true; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid_plural\\s*\"")); line.remove(QRegExp("\"$")); _msgid.append(line); } // one of the quotation marks is missing else if(line.find(QRegExp("^msgid_plural\\s*\"?.*\"?$")) != -1) { part=Msgid; _gettextPluralForm = true; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid_plural\\s*\"?")); line.remove(QRegExp("\"$")); _msgid.append(line); if(!line.isEmpty()) recoverableError=true; } else if(!_gettextPluralForm && (line.find(QRegExp("^msgstr\\s*\".*\\n?\"$")) != -1)) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\s*\"?")); line.remove(QRegExp("\"$")); (*msgstrIt)=line; } else if(!_gettextPluralForm && line.find(QRegExp("^msgstr\\s*\"?.*\\n?\"?$")) != -1) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\s*\"?")); line.remove(QRegExp("\"$")); (*msgstrIt)=line; if(!line.isEmpty()) recoverableError=true; } else if( _gettextPluralForm && (line.find(QRegExp("^msgstr\\[0\\]\\s*\".*\\n?\"$")) != -1)) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[0\\]\\s*\"?")); line.remove(QRegExp("\"$")); (*msgstrIt)=line; } else if( _gettextPluralForm && (line.find(QRegExp("^msgstr\\[0\\]\\s*\"?.*\\n?\"?$")) != -1)) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[0\\]\\s*\"?")); line.remove(QRegExp("\"$")); (*msgstrIt)=line; if(!line.isEmpty()) recoverableError=true; } else if ( line.startsWith( "#" ) ) { // ### TODO: could this be considered recoverable? kdDebug(KBABEL) << "comment found after a msgid while parsing: " << _msgid.first() << endl; error=true; break; } else if ( line.startsWith( "msgid" ) ) { kdDebug(KBABEL) << "Another msgid found after a msgid while parsing: " << _msgid.first() << endl; error=true; break; } // a line of the msgid with a missing quotation mark else if(line.find(QRegExp("^\"?.+\\n?\"?$")) != -1) { recoverableError=true; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^\"")); line.remove(QRegExp("\"$")); QStringList::Iterator it; if( _gettextPluralForm ) it = _msgid.fromLast(); else it = _msgid.begin(); // add Msgid line to item if((*it).isEmpty()) (*it)=line; else (*it)+=("\n"+line); } else { kdDebug(KBABEL) << "no msgstr found after a msgid while parsing: " << _msgid.first() << endl; error=true; break; } } else if(part==Msgstr) { if(line.isEmpty()) continue; // another line of the msgstr else if(line.find(QRegExp("^\".*\\n?\"$")) != -1) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^\"")); line.remove(QRegExp("\"$")); if((*msgstrIt).isEmpty()) (*msgstrIt)=line; else (*msgstrIt)+=("\n"+line); } else if( _gettextPluralForm && (line.find(QRegExp("^msgstr\\[[0-9]+\\]\\s*\".*\\n?\"$")) != -1)) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[[0-9]+\\]\\s*\"?")); line.remove(QRegExp("\"$")); msgstrIt=_msgstr.append(line); } else if( _gettextPluralForm && (line.find(QRegExp("^msgstr\\[[0-9]\\]\\s*\"?.*\\n?\"?$")) != -1)) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[[0-9]\\]\\s*\"?")); line.remove(QRegExp("\"$")); msgstrIt=_msgstr.append(line); if(!line.isEmpty()) recoverableError=true; } else if((line.find(QRegExp("^\\s*msgid")) != -1) || (line.find(QRegExp("^\\s*#")) != -1)) { // We have read successfully one entry, so end loop. stream.device()->at(pos);// reset position in stream to beginning of this line break; } else if(line.startsWith("msgstr")) { kdDebug(KBABEL) << "Another msgstr found after a msgstr while parsing: " << _msgstr.last() << endl; error=true; break; } // another line of the msgstr with a missing quotation mark else if(line.find(QRegExp("^\"?.+\\n?\"?$")) != -1) { recoverableError=true; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^\"")); line.remove(QRegExp("\"$")); if((*msgstrIt).isEmpty()) (*msgstrIt)=line; else (*msgstrIt)+=("\n"+line); } else { kdDebug(KBABEL) << "no msgid or comment found after a msgstr while parsing: " << _msgstr.last() << endl; error=true; break; } } } /* if(_gettextPluralForm) { kdDebug(KBABEL) << "gettext plural form:\n" << "msgid:\n" << _msgid.first() << "\n" << "msgid_plural:\n" << _msgid.last() << "\n" << endl; int counter=0; for(QStringList::Iterator it = _msgstr.begin(); it != _msgstr.end(); ++it) { kdDebug(KBABEL) << "msgstr[" << counter << "]:\n" << (*it) << endl; counter++; } } */ //kdDebug( KBABEL ) << k_funcinfo << " NEAR RETURN" << endl; if(error) return PARSE_ERROR; else if(recoverableError) return RECOVERED_PARSE_ERROR; else { return OK; } }
// FIXME: Does the logic in this routine actually work correctly? For example, // on non-Solaris systems which do not use /etc/timezone? void Tzone::save() { QStringList selectedZones(tzonelist->selection()); if (selectedZones.count() > 0) { // Find untranslated selected zone QString selectedzone(selectedZones[0]); #if defined(USE_SOLARIS) // MARCO KTempFile tf( locateLocal( "tmp", "kde-tzone" ) ); tf.setAutoDelete( true ); QTextStream *ts = tf.textStream(); # ifndef INITFILE # define INITFILE "/etc/default/init" # endif QFile fTimezoneFile(INITFILE); bool updatedFile = false; if (tf.status() == 0 && fTimezoneFile.open(IO_ReadOnly)) { bool found = false; QTextStream is(&fTimezoneFile); for (QString line = is.readLine(); !line.isNull(); line = is.readLine()) { if (line.find("TZ=") == 0) { *ts << "TZ=" << selectedzone << endl; found = true; } else { *ts << line << endl; } } if (!found) { *ts << "TZ=" << selectedzone << endl; } updatedFile = true; fTimezoneFile.close(); } if (updatedFile) { ts->device()->reset(); fTimezoneFile.remove(); if (fTimezoneFile.open(IO_WriteOnly | IO_Truncate)) { QTextStream os(&fTimezoneFile); for (QString line = ts->readLine(); !line.isNull(); line = ts->readLine()) { os << line << endl; } fchmod(fTimezoneFile.handle(), S_IXUSR | S_IRUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); fTimezoneFile.close(); } } QString val = selectedzone; #else QFile fTimezoneFile("/etc/timezone"); if (fTimezoneFile.open(IO_WriteOnly | IO_Truncate) ) { QTextStream t(&fTimezoneFile); t << selectedzone; fTimezoneFile.close(); } QString tz = "/usr/share/zoneinfo/" + selectedzone; kdDebug() << "Set time zone " << tz << endl; if (!QFile::remove("/etc/localtime")) { //After the KDE 3.2 release, need to add an error message } else if (!KIO::NetAccess::file_copy(KURL(tz),KURL("/etc/localtime"))) KMessageBox::error( 0, i18n("Error setting new timezone."), i18n("Timezone Error")); QString val = ":" + tz; #endif // !USE_SOLARIS setenv("TZ", val.ascii(), 1); tzset(); } else { #if !defined(USE_SOLARIS) // Do not update the System! unlink( "/etc/timezone" ); unlink( "/etc/localtime" ); setenv("TZ", "", 1); tzset(); #endif // !USE SOLARIS } currentZone(); }
bool kvoctrainDoc::loadFromLex (QTextStream& is) { langs.clear(); vocabulary.clear(); QString version, info1, s_dummy, title, f_keys, ident, orgID, transID; int i_dummy, type, f_grade, t_grade, lesson; int lines = 10000000; version = is.readLine(); info1 = is.readLine(); ident = extract (info1); orgID = extract (info1); if (orgID.isEmpty()) orgID = "original"; transID = extract (info1); if (transID.isEmpty()) transID = "translation"; if (ident != "LEX" || version != LEX_IDENT_50) { errorLex (1, "invalid file format"); return false; } // first two chars usually give language code: // english ==> en // Deutsch ==> de // italano ==> it langs.push_back (orgID.left(2).lower()); langs.push_back (transID.left(2).lower()); QTextStream params (info1, IO_ReadOnly); params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> i_dummy; params >> lines; s_dummy = is.readLine(); // Font s_dummy = is.readLine(); // Font title = is.readLine(); setTitle (title); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); s_dummy = is.readLine(); if (!loadTypeNameLex (is)) return false; if (!loadLessonLex (is)) return false; f_keys = is.readLine(); int ent_percent = (int) lines / 100; float f_ent_percent = (int) lines / 100.0; emit progressChanged(this, 0); for (int i = 0; !is.eof() && i < lines; i++) { if (ent_percent != 0 && (i % ent_percent) == 0 ) { emit progressChanged(this, int(i / f_ent_percent)); } is >> type; is >> i_dummy; is >> i_dummy; is >> i_dummy; is >> i_dummy; is >> i_dummy; is >> i_dummy; is >> i_dummy; is >> t_grade; is >> f_grade; is >> lesson; QString line = is.readLine(); QString s; QString original = extract (line); for (int i = 0; i < 3; i++) { s = extract (line); if (!s.isEmpty()) original += ", " +s; } QString translation = extract (line); for (int i = 0; i < 3; i++) { s = extract (line); if (!s.isEmpty()) translation += ", " +s; } /* ignore rest >> "||||||||||||||||||||||||||||||||||||||||||||||||||||||||" >> "\n"; */ kvoctrainExpr kve (original); kve.setGrade (1, t_grade, false); kve.setGrade (1, f_grade, true); kve.setLesson (lesson); kve.addTranslation (translation); // FIXME: convert attribute to word type ? vocabulary.push_back(kve); } setModified (false); return is.device()->status() == IO_Ok; }
int main (int argc, char** argv) { // Initialize ROS ros::init (argc, argv, "placeDetectionISL"); ros::NodeHandle nh; ros::NodeHandle pnh("~"); image_transport::ImageTransport it(nh); image_transport::TransportHints hints("compressed"); detector.tau_w = 1; detector.tau_n = 1; detector.tau_p = 20; detector.tau_avgdiff = 0.45; std::string camera_topic = ""; int img_width = 640; int img_height = 480; detector.focalLengthPixels = 525; detector.satLower = 30; detector.satUpper = 230; detector.valLower = 30; detector.valUpper = 230; detector.noHarmonics = 10; detector.image_counter = 1; detector.shouldProcess = false; detector.debugMode = false; detector.usePreviousMemory = false; std_msgs::String filterPath; pnh.getParam("tau_w",detector.tau_w); pnh.getParam("tau_n",detector.tau_n); pnh.getParam("tau_p",detector.tau_p); pnh.getParam("tau_inv",detector.tau_inv); pnh.getParam("tau_avgdiff",detector.tau_avgdiff); pnh.getParam("camera_topic",camera_topic); pnh.getParam("image_width",img_width); pnh.getParam("image_height",img_height); pnh.getParam("focal_length_pixels",detector.focalLengthPixels); pnh.getParam("tau_val_mean",detector.tau_val_mean); pnh.getParam("tau_val_var",detector.tau_val_var); pnh.getParam("sat_lower",detector.satLower); pnh.getParam("sat_upper",detector.satUpper); pnh.getParam("val_lower",detector.valLower); pnh.getParam("val_upper",detector.valUpper); /***** GET THE DEBUG MODE ****************/ pnh.getParam("debug_mode",detector.debugMode); /*******************************************/ /*************GET DEBUG FILE PATH ************************/ std_msgs::String file_path; pnh.getParam("file_path", detector.debugFilePath); //detector.debugFilePath = file_path.data; /******************************************/ /*** Get the number of files that will be processed**/ pnh.getParam("file_number",detector.debugFileNo); /***********************************************************/ qDebug()<<"Saturation and Value thresholds"<<detector.satLower<<detector.satUpper<<detector.valLower<<detector.valUpper<<detector.tau_avgdiff; if(detector.debugMode) { qDebug()<<"Debug mode is on!! File Path"<<QString::fromStdString(detector.debugFilePath)<<"No of files to be processed"<<detector.debugFileNo; } /****** GET THE USE PREVIOUS MEMORY PARAM ****/ pnh.getParam("use_previous_memory",detector.usePreviousMemory); if(detector.usePreviousMemory) { pnh.getParam("previous_memory_path", detector.previousMemoryPath); } /********************************************/ //pnh.getParam("filter_path",filterPath.data); // dbmanager.openDB("/home/hakan/Development/ISL/Datasets/Own/deneme/db1.db"); /*Place place = DatabaseManager::getPlace(1); qDebug()<<place.meanInvariant.at<float>(500,0)<<place.memberIds.at<int>(50,0);*/ // This should be done before starting the process bubbleProcess::calculateImagePanAngles(detector.focalLengthPixels,img_width,img_height); bubbleProcess::calculateImageTiltAngles(detector.focalLengthPixels,img_width,img_height); QString basepath = QDir::homePath(); basepath.append("/visual_filters"); // QString basepath(filterPath.data.data()); QString path(basepath); path.append("/filtre0.txt"); qDebug()<<path; ImageProcess::readFilter(path,29,false,false,false); path.clear(); path = basepath; path.append("/filtre6.txt"); qDebug()<<path; ImageProcess::readFilter(path,29,false,false,false); path.clear(); path = basepath; path.append("/filtre12.txt"); qDebug()<<path; ImageProcess::readFilter(path,29,false,false,false); path.clear(); path = basepath; path.append("/filtre18.txt"); qDebug()<<path; ImageProcess::readFilter(path,29,false,false,false); path.clear(); path = basepath; path.append("/filtre36.txt"); qDebug()<<path; ImageProcess::readFilter(path,29,false,false,false); image_transport::Subscriber imageSub = it.subscribe(camera_topic.data(), 1, imageCallback,hints); ros::Subscriber sssub = nh.subscribe("placeDetectionISL/nodecontrol",1, startStopCallback); placedetectionPublisher = nh.advertise<std_msgs::Int16>("placeDetectionISL/placeID",5); filePathPublisher = nh.advertise<std_msgs::String>("placeDetectionISL/mainFilePath",2); // timer = nh.createTimer(ros::Duration(0.25), timerCallback); //ros::Publisher pub = nh.advertise<std_msgs::String>("hello",5); // Create a ROS subscriber for the input point cloud //ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb); // QDir dirr("/home/hakan/Development/ISL/Datasets/Own/jaguar/tour1"); /*dirr.setSorting(QDir::LocaleAware); QStringList filter("*.jpg");*/ /* QStringList list = dirr.entryList(filter,QDir::Files); qSort(list.begin(), list.end(), qGreater<QString>());*/ //list.sort(); // qDebug()<<list; ros::Rate loop(50); while(ros::ok()) { ros::spinOnce(); loop.sleep(); if(detector.shouldProcess) { if(!detector.debugMode) { detector.shouldProcess = false; detector.processImage(); if(sendLastPlaceandShutdown) { if(detector.currentPlace && detector.currentPlace->id > 0 && detector.currentPlace->members.size() > 0) { detector.currentPlace->calculateMeanInvariant(); // qDebug()<<"Current place mean invariant: "<<currentPlace->meanInvariant.rows<<currentPlace->meanInvariant.cols<<currentPlace->meanInvariant.at<float>(50,0); if(detector.currentPlace->memberIds.rows >= detector.tau_p){ dbmanager.insertPlace(*detector.currentPlace); detector.detectedPlaces.push_back(*detector.currentPlace); std_msgs::Int16 plID; plID.data = detector.placeID; placedetectionPublisher.publish(plID); ros::spinOnce(); // loop.sleep(); detector.placeID++; } delete detector.currentPlace; detector.currentPlace = 0; } ros::shutdown(); } } else { QString processingPerImageFilePath = mainDirectoryPath; processingPerImageFilePath = processingPerImageFilePath.append("/pperImage.txt"); QFile file(processingPerImageFilePath); QTextStream strm; if(file.open(QFile::WriteOnly)) { qDebug()<<"Processing per Image file Path has been opened"; strm.setDevice(&file); } // FOR DEBUGGING for(int i = 1; i <= detector.debugFileNo; i++) { // QString path("/home/hakan/fromJaguars/downloadedItems/jaguarY/2015-01-30-15:39:47/images/"); QString path = QString::fromStdString(detector.debugFilePath); path.append("rgb_").append(QString::number(i)).append(".jpg"); Mat imm = imread(path.toStdString().data(),CV_LOAD_IMAGE_COLOR); qint64 starttime = QDateTime::currentMSecsSinceEpoch(); cv::Rect rect(0,0,imm.cols,(imm.rows/2)); detector.currentImage = imm(rect); detector.processImage(); qint64 stoptime = QDateTime::currentMSecsSinceEpoch(); qDebug()<<(float)(stoptime-starttime); if(strm.device() != NULL) strm<<(float)(stoptime-starttime)<<"\n"; ros::spinOnce(); loop.sleep(); if(!ros::ok()) break; // qDebug()<<i; } if(detector.currentPlace && detector.currentPlace->id > 0 && detector.currentPlace->members.size() > 0) { qDebug()<<"I am here"; detector.currentPlace->calculateMeanInvariant(); qDebug()<<"Current place mean invariant: "<<detector.currentPlace->meanInvariant.rows<<detector.currentPlace->meanInvariant.cols<<detector.currentPlace->members.size(); if(detector.currentPlace->memberIds.rows >= detector.tau_p) { dbmanager.insertPlace(*detector.currentPlace); detector.detectedPlaces.push_back(*detector.currentPlace); std_msgs::Int16 plID; plID.data = detector.placeID; placedetectionPublisher.publish(plID); ros::spinOnce(); // loop.sleep(); detector.placeID++; } delete detector.currentPlace; detector.currentPlace = 0; detector.shouldProcess = false; ros::shutdown(); } // end if detector.currentPlace file.close(); } // end else } // end if detector.should Process // qDebug()<<"New Place"; } // while(ros::ok()) /// Delete the current place if(detector.currentPlace) { delete detector.currentPlace; detector.currentPlace = 0; } /// Insert basepoints to the database if(detector.wholebasepoints.size()>0) dbmanager.insertBasePoints(detector.wholebasepoints); dbmanager.closeDB(); return 0; }