00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qfiledialog.h>
00026 #include <qsqlcursor.h>
00027 #include <qregexp.h>
00028
00029 #include <qprocess.h>
00030 #include <qapplication.h>
00031 void CreateHtml::init() {
00032
00033 }
00034
00035 void CreateHtml::close()
00036 {
00037 QWidget::close();
00038 }
00039
00040 void CreateHtml::chooseDir()
00041 {
00042 QString d=QFileDialog::getExistingDirectory(QString::null, this, "Choose a directoy");
00043 if(d!=QString::null) dir->setText(d);
00044 }
00045
00046 QString CreateHtml::createHeader(QString title, QString menu) {
00047 QString i;
00048 i+="<html><head><title>";
00049 i+=title;
00050 i+="</title>";
00051 i+="<link rel=\"stylesheet\" type=\"text/css\" href=\"formate.css\"></head><body>";
00052 i+="<a href=\"index.html\">Home</a> ";
00053 i+="<a href=\"publindex.html\">Publication Index</a> ";
00054 i+="<a href=\"noteindex.html\">Note Index</a> ";
00055 i+="<a href=\"authorindex.html\">Author Index</a> ";
00056 i+="<h1 class=\"maintitle\">"+title+"</h1><br>";
00057 return i;
00058 }
00059
00060
00061 QString CreateHtml::createLinkList(QString query, QString title) {
00062 QString s;
00063 QSqlQuery q(query);
00064 if(q.size()<1) return s;
00065 s+="<h2 class=\"subtitle\">"+title+"</h2>";
00066 s+="<ul class=\"main\">";
00067 while(q.next()) {
00068 s+="<li><a href=\""+q.value(1).toString()+".html\">";
00069 s+=q.value(0).toString()+"</a>";
00070 }
00071 s+="</ul>";
00072 return s;
00073 }
00074
00075 QString CreateHtml::createMemo(QString memo) {
00076 QString s;
00077 s+="<h2 class=\"subtitle\">Memo</h2><br>";
00078 s+="<div class=\"note\">";
00079 s+=memo.remove(QRegExp("<html>|</html>|<body[^>]*>|</body>|<head>|</head>"));
00080 s+="</div><br><br>";
00081 return s;
00082 }
00083
00084 void CreateHtml::exportAuthors() {
00085 QSqlCursor cur("author");
00086 cur.select(cur.index("lastname"));
00087 progr_author->setTotalSteps(cur.size());
00088 QString index("<html><header><title>Author Index</title>");
00089 index+="<link rel=\"stylesheet\" type=\"text/css\" href=\"formate.css\"></header><body>";
00090 index+="<h1 class=\"maintitle\">Author Index</h1>";
00091 while(cur.next()) {
00092 qApp->processEvents();
00093 QString path=dir->text()+"/"+cur.value("no").toString()+".html";
00094 index+="<a href=\""+path+"\">"+cur.value("lastname").toString()+", "+cur.value("firstname").toString()+"</a><br>";
00095 QFile file(path);
00096 if ( file.open( IO_WriteOnly ) ) {
00097 progr_author->setProgress(cur.at()+1);
00098 QTextStream stream( &file );
00099 stream<<createHeader(cur.value("firstname").toString()+" "+cur.value("lastname").toString(), "<a href=\"authorindex.html\">Author Index</a>");
00100 stream<<"<ul class=\"main\">";
00101 stream<<"<li><b>born:</b>"+cur.value("born").toString()+"</li>";
00102 stream<<"<li><b>decesed:</b>"+cur.value("died").toString()+"</li>";
00103 stream<<"<li><b>pseudonym:</b>"+cur.value("pseudonym").toString()+"</li>";
00104 stream<<"<li><b>country:</b>"+cur.value("country").toString()+"</li>";
00105 stream<<"</ul>";
00106
00107
00108 stream<<createLinkList("select publication.title, publication.no from publication, publication_author where publication.no=publication_author.publication_no and publication_author.author_no="+cur.value("no").toString()+" order by title", "Publications");
00109
00110 stream<<createLinkList("select part.title, part.no from part, part_author where part.no=part_author.part_no and part_author.author_no="+cur.value("no").toString()+" order by title", "Parts");
00111
00112 stream<<createLinkList("select note.title, note.no from note, link where (link.obj_1="+cur.value("no").toString()+" and link.obj_2=note.no) or (link.obj_2="+cur.value("no").toString()+" and link.obj_1=note.no) order by title", "Notes");
00113 stream<<createMemo(cur.value("memo").toString());
00114 stream<<html_footer;
00115 stream<<"</body></html>";
00116 file.close();
00117 }
00118 }
00119 index+"</body></html>";
00120 QFile ifile(dir->text()+"/authorindex.html");
00121 if ( ifile.open( IO_WriteOnly ) ) {
00122 QTextStream stream( &ifile );
00123 stream<<index;
00124 }
00125 ifile.close();
00126 }
00127
00128 void CreateHtml::exportPublications() {
00129 QSqlCursor cur("publication");
00130 cur.select(cur.index("title"));
00131 progr_publ->setTotalSteps(cur.size());
00132 QString index("<html><header><title>Publication Index</title>");
00133 index+="<link rel=\"stylesheet\" type=\"text/css\" href=\"formate.css\"></header><body>";
00134 index+="<h1 class=\"maintitle\">Publication Index</h1>";
00135 while(cur.next()) {
00136 qApp->processEvents();
00137 QString path=dir->text()+"/"+cur.value("no").toString()+".html";
00138 index+="<a href=\""+path+"\">"+cur.value("title").toString()+"</a><br>";
00139 QFile file(path);
00140 if ( file.open( IO_WriteOnly ) ) {
00141 progr_publ->setProgress(cur.at()+1);
00142 QTextStream stream( &file );
00143 stream<<createHeader(cur.value("title").toString(), "<a href=\"publindex.html\">Publication Index</a>");
00144 stream<<"<ul class=\"main\">";
00145 stream<<"<li><b>Year:</b>"+cur.value("year").toString()+"</li>";
00146 QSqlQuery q("select publisher.name from publisher where publisher.no="+cur.value("publisher_no").toString());
00147 if(q.first())
00148 stream<<"<li><b>Publisher:</b>"+q.value(0).toString()+"</li>";
00149 stream<<"</ul>";
00150
00151
00152 stream<<createLinkList("select author.firstname ||' '|| author.lastname as name, author.no from author, publication_author where author.no=publication_author.author_no and publication_author.publication_no="+cur.value("no").toString()+" order by author.lastname", "Authors");
00153
00154 stream<<createLinkList("select part.title, part.no from part where part.publication_no="+cur.value("no").toString()+" order by part.title", "Parts");
00155
00156 stream<<createLinkList("select note.title, note.no from note, link where (link.obj_1="+cur.value("no").toString()+" and link.obj_2=note.no) or (link.obj_2="+cur.value("no").toString()+" and link.obj_1=note.no) order by title", "Notes");
00157
00158 stream<<createMemo(cur.value("memo").toString());
00159 stream<<html_footer;
00160 stream<<"</body></html>";
00161 file.close();
00162 }
00163 }
00164 index+"</body></html>";
00165 QFile ifile(dir->text()+"/publindex.html");
00166 if ( ifile.open( IO_WriteOnly ) ) {
00167 QTextStream stream( &ifile );
00168 stream<<index;
00169 }
00170 ifile.close();
00171 }
00172
00173 void CreateHtml::exportNotes() {
00174 QSqlCursor cur("note");
00175 cur.select(cur.index("title"));
00176 progr_notes->setTotalSteps(cur.size());
00177 QString index("<html><header><title>Note Index</title>");
00178 index+="<link rel=\"stylesheet\" type=\"text/css\" href=\"formate.css\"></header><body>";
00179 index+="<h1 class=\"maintitle\">Note Index</h1>";
00180 while(cur.next()) {
00181 qApp->processEvents();
00182 QString path=dir->text()+"/"+cur.value("no").toString()+".html";
00183 if(cur.value("type").toString()=="0" && cur.value("parent").toString()=="0")
00184 index+="<a href=\""+path+"\">"+cur.value("title").toString()+"</a><br>";
00185 QFile file(path);
00186 if ( file.open( IO_WriteOnly ) ) {
00187 progr_notes->setProgress(cur.at()+1);
00188 QTextStream stream( &file );
00189 stream<<createHeader(cur.value("title").toString(), "<a href=\"noteindex.html\">Note Index</a>");
00190
00191 QString no=cur.value("no").toString();
00192
00193 QSqlQuery q("select note.title, note.no from note where no="+cur.value("parent").toString()+"order by title");
00194 if(q.first())
00195 stream<<"<b>Parent Note:</b> <a href=\""+q.value(1).toString()+".html\">"+q.value(0).toString()+"</a>";
00196
00197 stream<<createLinkList("select note.title, note.no from note where parent="+no+"order by title", "Child Notes");
00198
00199 stream<<createLinkList("select note.title, note.no from note, link where (link.obj_1="+no+" and link.obj_2=note.no) or (link.obj_2="+no+" and link.obj_1=note.no) order by title", "Notes");
00200
00201 stream<<createLinkList("select author.firstname ||' '|| author.lastname, author.no from author, link where (author.no=link.obj_1 and link.obj_2="+no+") or (author.no=link.obj_2 and link.obj_1="+no+")", "Authors");
00202
00203 stream<<createLinkList("select publication.title, publication.no from publication, link where (publication.no=link.obj_1 and link.obj_2="+no+") or (publication.no=link.obj_2 and link.obj_1="+no+")", "Publications");
00204
00205 stream<<createLinkList("select part.title, part.no from part, link where (part.no=link.obj_1 and link.obj_2="+no+") or (part.no=link.obj_2 and link.obj_1="+no+")", "Parts");
00206
00207 stream<<createLinkList("select file.filename, file.no from file, link where (file.no=link.obj_1 and link.obj_2="+no+") or (file.no=link.obj_2 and link.obj_1="+no+")", "Files");
00208
00209 stream<<createMemo(cur.value("memo").toString());
00210 stream<<html_footer;
00211 stream<<"</body></html>";
00212 file.close();
00213 }
00214 }
00215 index+"</body></html>";
00216 QFile ifile(dir->text()+"/noteindex.html");
00217 if ( ifile.open( IO_WriteOnly ) ) {
00218 QTextStream stream( &ifile );
00219 stream<<index;
00220 }
00221 ifile.close();
00222 }
00223
00224 void CreateHtml::exportParts() {
00225 QSqlCursor cur("part");
00226 cur.select(cur.index("title"));
00227 progr_parts->setTotalSteps(cur.size());
00228 while(cur.next()) {
00229 qApp->processEvents();
00230 QString path=dir->text()+"/"+cur.value("no").toString()+".html";
00231 QFile file(path);
00232 if ( file.open( IO_WriteOnly ) ) {
00233 progr_parts->setProgress(cur.at()+1);
00234 QTextStream stream( &file );
00235 stream<<createHeader(cur.value("title").toString(), "");
00236 QSqlQuery q("select publication.title, publication.no from publication where publication.no="+cur.value("publication_no").toString());
00237 if(q.first())
00238 stream<<"<b>Publication:</b><a href=\""+q.value(1).toString()+".html\">"+q.value(0).toString()+"</a>";
00239
00240 if(inclfiles->isChecked())
00241 stream<<createLinkList("select file.filename, file.no from file where file.part_no="+cur.value("no").toString(), "Files");
00242
00243 stream<<createLinkList("select note.title, note.no from note, link where (link.obj_1="+cur.value("no").toString()+" and link.obj_2=note.no) or (link.obj_2="+cur.value("no").toString()+" and link.obj_1=note.no) order by title", "Notes");
00244
00245 stream<<createMemo(cur.value("memo").toString());
00246 stream<<html_footer;
00247 stream<<"</body></html>";
00248 file.close();
00249 }
00250 }
00251 }
00252
00253 void CreateHtml::exportFiles() {
00254 QSqlQuery cur("select no, type from partdata");
00255 progr_files->setTotalSteps(cur.size());
00256 while(cur.next()) {
00257 QString type=cur.value(1).toString();
00258 qApp->processEvents();
00259 QString path=dir->text()+"/"+cur.value(0).toString()+".html";
00260 progr_files->setProgress(cur.at()+1);
00261 QSqlQuery q("select file from file where no="+cur.value(0).toString());
00262 q.first();
00263 QCString buffer=q.value(0).toCString();
00264 QCString dec;
00265
00266 if(type=="text/html") {
00267 QFile file(path);
00268 if ( file.open( IO_WriteOnly ) ) {
00269 QTextStream stream( &file );
00270 stream<<dec;
00271 file.close();
00272 }
00273 }
00274 else if(type=="application/pdf") {
00275
00276 convert("pdftohtml #in# #out#", dec, path);
00277 }
00278 else {
00279 QFile file(path);
00280 if(file.open( IO_WriteOnly)) {
00281 QTextStream stream( &file );
00282 stream<<"<html><head></head><body><h1>No HTML file!</h1></body></html>";
00283 file.close();
00284 }
00285 }
00286 }
00287 }
00288
00289 void CreateHtml::exportStyleSheet() {
00290 QString path=dir->text()+"/formate.css";
00291 QFile file(path);
00292 if ( file.open( IO_WriteOnly ) ) {
00293 QTextStream stream( &file );
00294 stream<<"h1.maintitle { font-family:Arial,sans-serif; font-size:24pt; font-weight:normal; background-color:#AAAAFF; border-bottom:solid thick black; text-align:center}\n";
00295 stream<<"ul.main { background-color:#DDDDDD }\n";
00296 stream<<"ul.links { background-color:#DDDDDD }\n";
00297 stream<<"h2.subtitle { font-family:Arial,sans-serif; font-size:18pt; font-weight:normal; border-bottom:solid thick black }\n";
00298 stream<<".note { font-family:Arial,sans-serif; font-size:12pt; font-weight:normal }";
00299 file.close();
00300 }
00301 }
00302
00303 void CreateHtml::exportIndex() {
00304 QString path=dir->text()+"/index.html";
00305 QFile file(path);
00306 if ( file.open( IO_WriteOnly ) ) {
00307 QTextStream stream( &file );
00308 stream<<"<html><head><title>Home</title></head><body>\n";
00309 stream<<"<a href=\"publindex.html\">Publication Index</a> ";
00310 stream<<"<a href=\"noteindex.html\">Note Index</a> ";
00311 stream<<"<a href=\"authorindex.html\">Author Index</a> ";
00312 stream<<"</body></html>";
00313 file.close();
00314 }
00315
00316 }
00317
00318 void CreateHtml::convert(QString cmd, QByteArray in, QString outfilename) {
00319
00320 QString infilename=tmpnam(0L);
00321 QFile infile(infilename);
00322 infile.open(IO_WriteOnly);
00323 infile.writeBlock(in);
00324 infile.close();
00325 QProcess proc(this);
00326 cmd.replace(QRegExp("#in#"), infilename);
00327 cmd.replace(QRegExp("#out#"), outfilename);
00328
00329
00330
00331
00332
00333
00334
00335
00336 proc.addArgument("sh");
00337 qDebug("Executing \""+QString(cmd)+"\"\n");
00338 proc.addArgument(cmd);
00339
00340 proc.start();
00341 while(proc.isRunning()) {
00342 qApp->processEvents();
00343 }
00344
00345 qDebug("\nConvert2Text, exitstatus:"+QString().setNum(proc.exitStatus())+"\n");
00346
00347
00348
00349
00350
00351 infile.remove();
00352 }
00353
00354
00355
00356 void CreateHtml::start()
00357 {
00358 exportAuthors();
00359 exportNotes();
00360 exportPublications();
00361 exportParts();
00362
00363 exportStyleSheet();
00364 exportIndex();
00365 }
00366
00367 void CreateHtml::stop()
00368 {
00369
00370 }
00371
00372 void CreateHtml::newFunction()
00373 {
00374
00375 }