36 #include <QCoreApplication>
42 #include <QTemporaryFile>
45 #include <QSqlDatabase>
54 result <<
"2ndLeft.ogg";
55 result <<
"2ndRight.ogg";
57 result <<
"3rdLeft.ogg";
58 result <<
"3rdRight.ogg";
66 result <<
"After.ogg";
67 result <<
"AhExitLeft.ogg";
68 result <<
"AhExit.ogg";
69 result <<
"AhExitRight.ogg";
70 result <<
"AhFerry.ogg";
71 result <<
"AhKeepLeft.ogg";
72 result <<
"AhKeepRight.ogg";
73 result <<
"AhLeftTurn.ogg";
74 result <<
"AhRightTurn.ogg";
75 result <<
"AhUTurn.ogg";
76 result <<
"Arrive.ogg";
77 result <<
"BearLeft.ogg";
78 result <<
"BearRight.ogg";
79 result <<
"Charge.ogg";
80 result <<
"Depart.ogg";
81 result <<
"KeepLeft.ogg";
82 result <<
"KeepRight.ogg";
83 result <<
"LnLeft.ogg";
84 result <<
"LnRight.ogg";
85 result <<
"Meters.ogg";
86 result <<
"MwEnter.ogg";
87 result <<
"MwExitLeft.ogg";
88 result <<
"MwExit.ogg";
89 result <<
"MwExitRight.ogg";
90 result <<
"RbBack.ogg";
91 result <<
"RbCross.ogg";
92 result <<
"RbExit1.ogg";
93 result <<
"RbExit2.ogg";
94 result <<
"RbExit3.ogg";
95 result <<
"RbExit4.ogg";
96 result <<
"RbExit5.ogg";
97 result <<
"RbExit6.ogg";
98 result <<
"RbLeft.ogg";
99 result <<
"RbRight.ogg";
100 result <<
"RoadEnd.ogg";
101 result <<
"SharpLeft.ogg";
102 result <<
"SharpRight.ogg";
103 result <<
"Straight.ogg";
104 result <<
"TakeFerry.ogg";
105 result <<
"Then.ogg";
106 result <<
"TryUTurn.ogg";
107 result <<
"TurnLeft.ogg";
108 result <<
"TurnRight.ogg";
109 result <<
"UTurn.ogg";
110 result <<
"Yards.ogg";
117 result <<
"Marble.ogg";
118 result <<
"RouteCalculated.ogg";
119 result <<
"RouteDeviated.ogg";
120 result <<
"GpsFound.ogg";
121 result <<
"GpsLost.ogg";
125 void usage(
const QString &application )
127 qDebug() <<
"Usage: " << application <<
" /path/to/input/directory /path/to/output/directory /path/to/newstuff.xml";
130 void extract(
const QString &zip,
const QString &output )
132 QProcess::execute(
"unzip", QStringList() <<
"-q" <<
"-j" <<
"-d" << output << zip );
138 vorbisgain.setWorkingDirectory( output );
140 vorbisgain.waitForFinished();
143 void createLegalFiles(
const QString &directory,
const QString &name,
const QString &email )
145 QDir input( directory );
146 QFile authorsFile( input.filePath(
"AUTHORS.txt" ) );
147 if ( authorsFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
148 QTextStream stream( &authorsFile );
149 stream << name <<
" <" << email <<
">";
153 QFile licenseFile( input.filePath(
"LICENSE.txt" ) );
154 if ( licenseFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
155 QTextStream stream( &licenseFile );
156 stream <<
"The ogg files in this directory are licensed under the creative commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license. ";
157 stream <<
"See http://creativecommons.org/licenses/by-sa/3.0/ and the file CC-BY-SA-3.0 in this directory.";
161 QFile installFile( input.filePath(
"INSTALL.txt" ) );
162 if ( installFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
163 QTextStream stream( &installFile );
164 stream <<
"To install this voice guidance speaker in Marble, copy the entire directory to the audio/speakers/ directory in Marble's data path.\n\n";
165 stream <<
"For example, if this directory is called 'MySpeaker' and you want to use it on the Nokia N900, copy the directory with all files to /home/user/MyDocs/.local/share/marble/audio/speakers/MySpeaker\n\n";
166 stream <<
"Afterwards start Marble on the N900 and press the routing info box (four icons on the bottom) for two seconds with the pen. Enter the configuration dialog and choose the 'MySpeaker' speaker.\n\n";
167 stream <<
"Check http://edu.kde.org/marble/speakers.php for updates and more speakers.";
174 QDir inputDirectory( input );
177 files <<
"AUTHORS.txt" <<
"INSTALL.txt" <<
"LICENSE.txt";
178 QStringList arguments;
179 arguments <<
"-czf" << output;
180 foreach(
const QString &file, files ) {
181 arguments << inputDirectory.filePath( file );
183 arguments <<
"/usr/share/common-licenses/CC-BY-SA-3.0";
185 QProcess::execute(
"tar", arguments );
190 QDir inputDirectory( input );
193 files <<
"AUTHORS.txt" <<
"INSTALL.txt" <<
"LICENSE.txt";
194 QStringList arguments;
195 arguments <<
"-q" <<
"-j" << output;
196 foreach(
const QString &file, files ) {
197 arguments << inputDirectory.filePath( file );
199 arguments <<
"/usr/share/common-licenses/CC-BY-SA-3.0";
201 QProcess::execute(
"zip", arguments );
204 void convertToTomTomFormat(
const QString &input,
const QString &output,
const QString &nick,
const QString &simpleNick,
int index,
bool male,
const QString &lang )
206 QStringList arguments;
207 QString
const prefix = input +
"/data" + QString::number( index );
208 QString
const vif = prefix +
".vif";
209 QString
const chk = prefix +
".chk";
210 arguments <<
"join" << QString::number( index ) << nick << vif;
212 viftool.setWorkingDirectory( input );
213 viftool.execute(
"viftool", arguments );
215 QFile vifFile( vif );
216 if ( vifFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
217 QTextStream stream( &vifFile );
218 stream << nick <<
"\n";
219 stream << ( male ? 2 : 1 ) <<
"\n";
222 stream << 114 <<
"\n";
227 QDir inputDirectory( input );
230 files <<
"AUTHORS.txt" <<
"LICENSE.txt";
231 QStringList zipArguments;
232 zipArguments <<
"-q" <<
"-j" << ( output +
'/' + lang +
'-' + simpleNick +
"-TomTom.zip" );
233 foreach(
const QString &file, files ) {
234 QString
const filePath = inputDirectory.filePath( file );
235 zipArguments << filePath;
237 zipArguments <<
"/usr/share/common-licenses/CC-BY-SA-3.0";
239 QProcess::execute(
"zip", zipArguments );
242 int process(
const QDir &input,
const QDir &output,
const QString &xml )
244 QSqlDatabase database = QSqlDatabase::addDatabase(
"QSQLITE" );
245 database.setDatabaseName( input.filePath(
"speakers.db" ) );
246 if ( !database.open() ) {
247 qDebug() <<
"Failed to connect to database " << input.filePath(
"speakers.db" );
251 output.mkdir(
"files.kde.org" );
252 QSqlQuery query(
"SELECT * FROM speakers ORDER BY Id" );
254 QFile xmlFile( xml );
255 if ( !xmlFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
256 qDebug() <<
"Failed to write to " << xmlFile.fileName();
260 QTextStream xmlOut( &xmlFile );
261 xmlOut <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
262 xmlOut <<
"<!DOCTYPE knewstuff SYSTEM \"knewstuff.dtd\">\n";
263 xmlOut <<
"<?xml-stylesheet type=\"text/xsl\" href=\"speakers.xsl\" ?>\n";
264 xmlOut <<
"<knewstuff>\n";
267 while (query.next()) {
268 QString
const name = query.value(1).toString();
269 QString
const email = query.value(2).toString();
270 QString
const nick = query.value(3).toString();
271 QString
const gender = query.value(4).toString();
272 QString
const language = query.value(5).toString();
273 QString
const lang = language.mid( 0, language.indexOf(
"(" )-1 ).replace( QLatin1Char(
' '), QLatin1Char(
'-') );
274 QString
const description = query.value(6).toString();
275 QString
const token = query.value(7).toString();
276 QString
const date = query.value(8).toString();
277 QString
const zip = input.filePath( token );
278 QTemporaryFile tmpFile;
280 QString
const extracted = tmpFile.fileName();
282 QDir::root().mkdir( extracted );
283 qDebug() <<
"Name: " << name;
285 QString
const simpleNick = QString( nick ).replace( QLatin1Char(
' '), QLatin1Char(
'-') );
286 QString
const nickDir = output.filePath(
"files.kde.org" ) +
'/' + simpleNick;
287 QDir::root().mkdir( nickDir );
291 QFile::copy( extracted +
"/Marble.ogg", nickDir +
'/' + lang +
'-' + simpleNick +
".ogg" );
296 xmlOut <<
" <stuff category=\"marble/data/audio\">\n";
297 xmlOut <<
" <name lang=\"en\">" << language <<
" - " << nick <<
" (" << gender <<
")" <<
"</name>\n";
298 xmlOut <<
" <author>" << name <<
"</author>\n";
299 xmlOut <<
" <licence>CC-By-SA 3.0</licence>\n";
300 xmlOut <<
" <summary lang=\"en\">" << description <<
"</summary>\n";
301 xmlOut <<
" <version>0.1</version>\n";
302 xmlOut <<
" <releasedate>" << date <<
"</releasedate>\n";
303 xmlOut <<
" <preview lang=\"en\">http://edu.kde.org/marble/speaker-" << gender <<
".png</preview>\n";
304 xmlOut <<
" <payload lang=\"en\">http://files.kde.org/marble/audio/speakers/" << simpleNick <<
"/" << lang <<
"-" << simpleNick <<
".tar.gz</payload>\n";
305 xmlOut <<
" <payload lang=\"ogg\">http://files.kde.org/marble/audio/speakers/" << simpleNick <<
"/" << lang <<
"-" << simpleNick <<
".ogg</payload>\n";
306 xmlOut <<
" <payload lang=\"zip\">http://files.kde.org/marble/audio/speakers/" << simpleNick <<
"/" << lang <<
"-" << simpleNick <<
".zip</payload>\n";
307 xmlOut <<
" <payload lang=\"tomtom\">http://files.kde.org/marble/audio/speakers/" << simpleNick <<
"/" << lang <<
"-" << simpleNick <<
"-TomTom.zip</payload>\n";
308 xmlOut <<
" </stuff>\n";
313 xmlOut <<
"</knewstuff>\n";
318 int main(
int argc,
char *argv[])
327 QFileInfo input( argv[1] );
328 if ( !input.exists() || !input.isDir() ) {
329 qDebug() <<
"Incorrect input directory " << argv[1];
334 QFileInfo output( argv[2] );
335 if ( !output.exists() || !output.isWritable() ) {
336 qDebug() <<
"Incorrect output directory " << argv[1];
341 QFileInfo xmlFile( argv[3] );
342 return process( QDir( input.absoluteFilePath() ), QDir( output.absoluteFilePath() ), xmlFile.absoluteFilePath() );
void createLegalFiles(const QString &directory, const QString &name, const QString &email)
void convertToMarbleFormat(const QString &input, const QString &output)
int main(int argc, char *argv[])
void extract(const QString &zip, const QString &output)
void convertToNewStuffFormat(const QString &input, const QString &output)
void convertToTomTomFormat(const QString &input, const QString &output, const QString &nick, const QString &simpleNick, int index, bool male, const QString &lang)
void normalize(const QString &output)
void usage(const QString &application)
int process(const QDir &input, const QDir &output, const QString &xml)
QStringList tomTomFiles()
Takes an .sqlite database with metadata about voice guidance speakers and associated ...
QStringList marbleFiles()