• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • tools
  • speaker-files
tools/speaker-files/main.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
36 #include <QCoreApplication>
37 #include <QString>
38 #include <QDebug>
39 #include <QFileInfo>
40 #include <QDir>
41 #include <QVariant>
42 #include <QTemporaryFile>
43 #include <QProcess>
44 
45 #include <QSqlDatabase>
46 #include <QSqlQuery>
47 #include <QSqlError>
48 
49 QStringList tomTomFiles()
50 {
51  QStringList result;
52  result << "100.ogg";
53  result << "200.ogg";
54  result << "2ndLeft.ogg";
55  result << "2ndRight.ogg";
56  result << "300.ogg";
57  result << "3rdLeft.ogg";
58  result << "3rdRight.ogg";
59  result << "400.ogg";
60  result << "500.ogg";
61  result << "50.ogg";
62  result << "600.ogg";
63  result << "700.ogg";
64  result << "800.ogg";
65  result << "80.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";
111  return result;
112 }
113 
114 QStringList marbleFiles()
115 {
116  QStringList result;
117  result << "Marble.ogg";
118  result << "RouteCalculated.ogg";
119  result << "RouteDeviated.ogg";
120  result << "GpsFound.ogg";
121  result << "GpsLost.ogg";
122  return result;
123 }
124 
125 void usage( const QString &application )
126 {
127  qDebug() << "Usage: " << application << " /path/to/input/directory /path/to/output/directory /path/to/newstuff.xml";
128 }
129 
130 void extract( const QString &zip, const QString &output )
131 {
132  QProcess::execute( "unzip", QStringList() << "-q" << "-j" << "-d" << output << zip );
133 }
134 
135 void normalize( const QString &output )
136 {
137  QProcess vorbisgain;
138  vorbisgain.setWorkingDirectory( output );
139  vorbisgain.start( "vorbisgain", QStringList() << "-a" << tomTomFiles() << marbleFiles() );
140  vorbisgain.waitForFinished();
141 }
142 
143 void createLegalFiles( const QString &directory, const QString &name, const QString &email )
144 {
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 << ">";
150  }
151  authorsFile.close();
152 
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.";
158  }
159  licenseFile.close();
160 
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.";
168  }
169  installFile.close();
170 }
171 
172 void convertToNewStuffFormat( const QString &input, const QString &output )
173 {
174  QDir inputDirectory( input );
175  QStringList files;
176  files << tomTomFiles() << marbleFiles();
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 );
182  }
183  arguments << "/usr/share/common-licenses/CC-BY-SA-3.0";
184 
185  QProcess::execute( "tar", arguments );
186 }
187 
188 void convertToMarbleFormat( const QString &input, const QString &output )
189 {
190  QDir inputDirectory( input );
191  QStringList files;
192  files << tomTomFiles() << marbleFiles();
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 );
198  }
199  arguments << "/usr/share/common-licenses/CC-BY-SA-3.0";
200 
201  QProcess::execute( "zip", arguments );
202 }
203 
204 void convertToTomTomFormat( const QString &input, const QString &output, const QString &nick, const QString &simpleNick, int index, bool male, const QString &lang )
205 {
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;
211  QProcess viftool;
212  viftool.setWorkingDirectory( input );
213  viftool.execute( "viftool", arguments );
214 
215  QFile vifFile( vif );
216  if ( vifFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
217  QTextStream stream( &vifFile );
218  stream << nick << "\n"; // Name
219  stream << ( male ? 2 : 1 ) << "\n"; // gender index
221  stream << 2 << "\n"; // Language index
222  stream << 114 << "\n"; // Flag index
223  stream << "1\n"; // Version number
224  }
225  vifFile.close();
226 
227  QDir inputDirectory( input );
228  QStringList files;
229  files << vif << chk;
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;
236  }
237  zipArguments << "/usr/share/common-licenses/CC-BY-SA-3.0";
238 
239  QProcess::execute( "zip", zipArguments );
240 }
241 
242 int process( const QDir &input, const QDir &output, const QString &xml )
243 {
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" );
248  return 3;
249  }
250 
251  output.mkdir( "files.kde.org" );
252  QSqlQuery query( "SELECT * FROM speakers ORDER BY Id" );
253 
254  QFile xmlFile( xml );
255  if ( !xmlFile.open( QFile::WriteOnly | QFile::Truncate ) ) {
256  qDebug() << "Failed to write to " << xmlFile.fileName();
257  return 3;
258  }
259 
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";
265 
266  int index = 71;
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;
279  tmpFile.open();
280  QString const extracted = tmpFile.fileName();
281  tmpFile.remove();
282  QDir::root().mkdir( extracted );
283  qDebug() << "Name: " << name;
284 
285  QString const simpleNick = QString( nick ).replace( QLatin1Char(' '), QLatin1Char('-') );
286  QString const nickDir = output.filePath( "files.kde.org" ) + '/' + simpleNick;
287  QDir::root().mkdir( nickDir );
288  extract( zip, extracted );
289  normalize( extracted );
290  createLegalFiles( extracted, name, email );
291  QFile::copy( extracted + "/Marble.ogg", nickDir + '/' + lang + '-' + simpleNick + ".ogg" );
292  convertToMarbleFormat( extracted, nickDir + '/' + lang + '-' + simpleNick + ".zip" );
293  convertToTomTomFormat( extracted, nickDir, nick, simpleNick, index, gender == "male", lang );
294  convertToNewStuffFormat( extracted, nickDir + '/' + lang + '-' + simpleNick + ".tar.gz" );
295 
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";
309 
310  ++index;
311  }
312 
313  xmlOut << "</knewstuff>\n";
314  xmlFile.close();
315  return 0;
316 }
317 
318 int main(int argc, char *argv[])
319 {
320  QCoreApplication a(argc, argv);
321 
322  if ( argc < 4 ) {
323  usage( argv[0] );
324  return 1;
325  }
326 
327  QFileInfo input( argv[1] );
328  if ( !input.exists() || !input.isDir() ) {
329  qDebug() << "Incorrect input directory " << argv[1];
330  usage( argv[0] );
331  return 1;
332  }
333 
334  QFileInfo output( argv[2] );
335  if ( !output.exists() || !output.isWritable() ) {
336  qDebug() << "Incorrect output directory " << argv[1];
337  usage( argv[0] );
338  return 1;
339  }
340 
341  QFileInfo xmlFile( argv[3] );
342  return process( QDir( input.absoluteFilePath() ), QDir( output.absoluteFilePath() ), xmlFile.absoluteFilePath() );
343 }
QProcess::execute
int execute(const QString &program, const QStringList &arguments)
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
createLegalFiles
void createLegalFiles(const QString &directory, const QString &name, const QString &email)
Definition: tools/speaker-files/main.cpp:143
convertToMarbleFormat
void convertToMarbleFormat(const QString &input, const QString &output)
Definition: tools/speaker-files/main.cpp:188
QFile::remove
bool remove()
QCoreApplication
QFile::fileName
QString fileName() const
QDir::filePath
QString filePath(const QString &fileName) const
QSqlDatabase::addDatabase
QSqlDatabase addDatabase(const QString &type, const QString &connectionName)
main
int main(int argc, char *argv[])
Definition: tools/speaker-files/main.cpp:318
extract
void extract(const QString &zip, const QString &output)
Definition: tools/speaker-files/main.cpp:130
QDir::root
QDir root()
QFile
QSqlDatabase
QFile::copy
bool copy(const QString &newName)
QTextStream
convertToNewStuffFormat
void convertToNewStuffFormat(const QString &input, const QString &output)
Definition: tools/speaker-files/main.cpp:172
convertToTomTomFormat
void convertToTomTomFormat(const QString &input, const QString &output, const QString &nick, const QString &simpleNick, int index, bool male, const QString &lang)
Definition: tools/speaker-files/main.cpp:204
QString::number
QString number(int n, int base)
normalize
void normalize(const QString &output)
Definition: tools/speaker-files/main.cpp:135
QFileInfo::isDir
bool isDir() const
QSqlQuery::value
QVariant value(int index) const
QProcess
QFileInfo::absoluteFilePath
QString absoluteFilePath() const
QSqlQuery
QSqlQuery::next
bool next()
usage
void usage(const QString &application)
Definition: tools/speaker-files/main.cpp:125
QSqlDatabase::open
bool open()
QString
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QStringList
QFileInfo
QFileInfo::exists
bool exists() const
QLatin1Char
QProcess::setWorkingDirectory
void setWorkingDirectory(const QString &dir)
QFile::close
virtual void close()
QTemporaryFile::fileName
QString fileName() const
QDir
QString::replace
QString & replace(int position, int n, QChar after)
QString::mid
QString mid(int position, int n) const
QDir::mkdir
bool mkdir(const QString &dirName) const
process
int process(const QDir &input, const QDir &output, const QString &xml)
Definition: tools/speaker-files/main.cpp:242
tomTomFiles
QStringList tomTomFiles()
Takes an .sqlite database with metadata about voice guidance speakers and associated ...
Definition: tools/speaker-files/main.cpp:49
QFileInfo::isWritable
bool isWritable() const
QSqlDatabase::setDatabaseName
void setDatabaseName(const QString &name)
QTemporaryFile
QTemporaryFile::open
bool open()
QVariant::toString
QString toString() const
QProcess::start
void start(const QString &program, const QStringList &arguments, QFlags< QIODevice::OpenModeFlag > mode)
marbleFiles
QStringList marbleFiles()
Definition: tools/speaker-files/main.cpp:114
QProcess::waitForFinished
bool waitForFinished(int msecs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal