Debian Codegraph @

addon/doxywizard/doxywizard.cpp

raw
1 /******************************************************************************
2 *
3 * Copyright (C) 1997-2021 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 */
12
13 #include "doxywizard.h"
14 #include "version.h"
15 #include "expert.h"
16 #include "wizard.h"
17
18 #include <QMenu>
19 #include <QMenuBar>
20 #include <QPushButton>
21 #include <QMessageBox>
22 #include <QVBoxLayout>
23 #include <QLineEdit>
24 #include <QLabel>
25 #include <QCheckBox>
26 #include <QTextBrowser>
27 #include <QStatusBar>
28 #include <QProcess>
29 #include <QTimer>
30 #include <QCloseEvent>
31 #include <QApplication>
32 #include <QDir>
33 #include <QFileDialog>
34 #include <QDesktopServices>
35 #include <QUrl>
36 #include <QTextStream>
37 #include <QRegularExpression>
38 #include <QDebug>
39 #include <QDate>
40 #include <QScrollBar>
41
42 #ifdef _WIN32
43 #include <windows.h>
44 #endif
45
46 #define MAX_RECENT_FILES 10
47
48 // globally accessible variables
49 bool DoxygenWizard::debugFlag = false;
50
51 const int messageTimeout = 5000; //!< status bar message timeout in milliseconds.
52
53 #define APPQT(x) QString::fromLatin1("<qt><pre>") + x + QString::fromLatin1("</pre></qt>")
54
55 MainWindow &MainWindow::instance()
56 {
57 static MainWindow *theInstance = new MainWindow;
58 return *theInstance;
59 }
60
61 MainWindow::MainWindow()
62 : m_settings(QString::fromLatin1("Doxygen.org"), QString::fromLatin1("Doxywizard"))
63 {
64 QMenu *file = menuBar()->addMenu(tr("File"));
65 file->addAction(tr("Open..."),
66 this, SLOT(openConfig()), QKeySequence{ Qt::CTRL | Qt::Key_O });
67 m_recentMenu = file->addMenu(tr("Open recent"));
68 file->addAction(tr("Save"),
69 this, SLOT(saveConfig()), QKeySequence{ Qt::CTRL | Qt::Key_S });
70 file->addAction(tr("Save as..."),
71 this, SLOT(saveConfigAs()), QKeySequence{ Qt::SHIFT | Qt::CTRL | Qt::Key_S });
72 file->addAction(tr("Quit"),
73 this, SLOT(quit()), QKeySequence{ Qt::CTRL | Qt::Key_Q });
74
75 QMenu *settings = menuBar()->addMenu(tr("Settings"));
76 m_resetDefault = settings->addAction(tr("Reset to factory defaults"),
77 this,SLOT(resetToDefaults()));
78 settings->addAction(tr("Use current settings at startup"),
79 this,SLOT(makeDefaults()));
80 m_clearRecent = settings->addAction(tr("Clear recent list"),
81 this,SLOT(clearRecent()));
82 settings->addSeparator();
83 m_runMenu = settings->addAction(tr("Run doxygen"),
84 this, SLOT(runDoxygenMenu()), QKeySequence{ Qt::CTRL | Qt::Key_R });
85 m_runMenu->setEnabled(false);
86
87 QMenu *help = menuBar()->addMenu(tr("Help"));
88 help->addAction(tr("Online manual"),
89 this, SLOT(manual()), Qt::Key_F1);
90 help->addAction(tr("About"),
91 this, SLOT(about()) );
92
93 m_expert = new Expert;
94 m_wizard = new Wizard(m_expert->modelData());
95
96 // ----------- top part ------------------
97 QWidget *mainPart = new QWidget;
98 QVBoxLayout *mainLayout = new QVBoxLayout(mainPart);
99 QWidget *topPart = new QWidget;
100 QVBoxLayout *rowLayout = new QVBoxLayout(topPart);
101 mainLayout->addWidget(topPart);
102
103 // select working directory
104 QHBoxLayout *dirLayout = new QHBoxLayout;
105 m_workingDir = new QLineEdit;
106 m_selWorkingDir = new QPushButton(tr("Select..."));
107 dirLayout->addWidget(m_workingDir);
108 dirLayout->addWidget(m_selWorkingDir);
109
110 //------------- bottom part --------------
111 m_runTab = new QWidget;
112 QVBoxLayout *runTabLayout = new QVBoxLayout(m_runTab);
113
114 // run doxygen
115 QHBoxLayout *runLayout = new QHBoxLayout;
116 m_run = new QPushButton(tr("Run doxygen"));
117 m_run->setEnabled(false);
118 m_runStatus = new QLabel(tr("Status: not running"));
119 m_saveLog = new QPushButton(tr("Save log..."));
120 m_saveLog->setEnabled(false);
121 QPushButton *showSettings = new QPushButton(tr("Show configuration"));
122
123 m_showCondensedSettings = new QCheckBox(this);
124 m_showCondensedSettings->setText(tr("Condensed"));
125 m_showCondensedSettings->setChecked(false);
126 m_showCondensedSettings->setToolTip(tr("Show only configuration settings different from default settings"));
127
128 // select extra run options
129 m_runOptions = new QLineEdit;
130
131 runTabLayout->addWidget(new QLabel(tr("Specify additional command line options for running doxygen")));
132 runTabLayout->addWidget(m_runOptions);
133
134 QVBoxLayout *runVLayout = new QVBoxLayout;
135 runLayout->addLayout(runVLayout);
136 QHBoxLayout *runVHLayout = new QHBoxLayout;
137 runVLayout->addLayout(runVHLayout);
138 runVHLayout->addWidget(m_run);
139 runVHLayout->addWidget(m_runStatus);
140
141 QHBoxLayout *runVH2Layout = new QHBoxLayout;
142 runVLayout->addLayout(runVH2Layout);
143 m_launchHtml = new QPushButton(tr("Show HTML output"));
144 runVH2Layout->addWidget(m_launchHtml);
145 runVH2Layout->addStretch(1); // to have launch button not being stretched
146
147 runLayout->addStretch(1);
148
149 QVBoxLayout *settingsLayout = new QVBoxLayout;
150 runLayout->addLayout(settingsLayout);
151 settingsLayout->addWidget(m_showCondensedSettings);
152 settingsLayout->addWidget(showSettings);
153
154 QVBoxLayout *saveLayout = new QVBoxLayout;
155 runLayout->addLayout(saveLayout);
156 saveLayout->addWidget(m_saveLog);
157 saveLayout->setAlignment(Qt::AlignTop);
158 // saveLayout->addWidget(new QWidget); // to have the save button at the top
159
160 // output produced by Doxygen
161 runTabLayout->addLayout(runLayout);
162 runTabLayout->addWidget(new QLabel(tr("Output produced by doxygen")));
163 QGridLayout *grid = new QGridLayout;
164 //m_outputLog = new QTextEdit;
165 m_outputLog = new QTextBrowser;
166 //m_outputLog = new QPlainTextEdit;
167 m_outputLog->setReadOnly(true);
168 m_outputLog->setFontFamily(QString::fromLatin1("courier"));
169 m_outputLog->setMinimumWidth(600);
170 grid->addWidget(m_outputLog,0,0);
171 grid->setColumnStretch(0,1);
172 grid->setRowStretch(0,1);
173 runTabLayout->addLayout(grid);
174
175 m_tabs = new QTabWidget;
176 m_tabs->addTab(m_wizard,tr("Wizard"));
177 m_tabs->addTab(m_expert,tr("Expert"));
178 m_tabs->addTab(m_runTab,tr("Run"));
179
180 rowLayout->addWidget(new QLabel(tr("Specify the working directory from which doxygen will run")));
181 rowLayout->addLayout(dirLayout);
182 rowLayout->addWidget(new QLabel(tr("Configure doxygen using the Wizard and/or Expert tab, then switch to the Run tab to generate the documentation")));
183 mainLayout->addWidget(m_tabs);
184
185 setCentralWidget(mainPart);
186 statusBar()->showMessage(tr("Welcome to Doxygen"),messageTimeout);
187
188 m_runProcess = new QProcess;
189 m_running = false;
190 m_timer = new QTimer;
191
192 // connect signals and slots
193 connect(m_tabs,SIGNAL(currentChanged(int)),SLOT(selectTab(int)));
194 connect(m_selWorkingDir,SIGNAL(clicked()),SLOT(selectWorkingDir()));
195 connect(m_recentMenu,SIGNAL(triggered(QAction*)),SLOT(openRecent(QAction*)));
196 connect(m_workingDir,SIGNAL(returnPressed()),SLOT(updateWorkingDir()));
197 connect(m_runProcess,SIGNAL(readyReadStandardOutput()),SLOT(readStdout()));
198 connect(m_runProcess,SIGNAL(finished(int, QProcess::ExitStatus)),SLOT(runComplete()));
199 connect(m_timer,SIGNAL(timeout()),SLOT(readStdout()));
200 connect(m_run,SIGNAL(clicked()),SLOT(runDoxygen()));
201 connect(m_launchHtml,SIGNAL(clicked()),SLOT(showHtmlOutput()));
202 connect(m_saveLog,SIGNAL(clicked()),SLOT(saveLog()));
203 connect(showSettings,SIGNAL(clicked()),SLOT(showSettings()));
204 connect(m_expert,SIGNAL(changed()),SLOT(configChanged()));
205 connect(m_wizard,SIGNAL(done()),SLOT(selectRunTab()));
206 connect(m_expert,SIGNAL(done()),SLOT(selectRunTab()));
207
208 loadSettings();
209 updateLaunchButtonState();
210 m_modified = false;
211 updateTitle();
212 m_wizard->refresh();
213 }
214
215 void MainWindow::closeEvent(QCloseEvent *event)
216 {
217 if (discardUnsavedChanges())
218 {
219 saveSettings();
220 event->accept();
221 }
222 else
223 {
224 event->ignore();
225 }
226 }
227
228 void MainWindow::quit()
229 {
230 if (discardUnsavedChanges())
231 {
232 saveSettings();
233 }
234 else
235 {
236 return;
237 }
238 QApplication::exit(0);
239 }
240
241 void MainWindow::setWorkingDir(const QString &dirName)
242 {
243 QDir::setCurrent(dirName);
244 m_workingDir->setText(dirName);
245 m_run->setEnabled(!dirName.isEmpty());
246 m_runMenu->setEnabled(!dirName.isEmpty());
247 }
248
249 void MainWindow::selectWorkingDir()
250 {
251 QString dirName = QFileDialog::getExistingDirectory(this,
252 tr("Select working directory"),m_workingDir->text());
253 if (!dirName.isEmpty())
254 {
255 setWorkingDir(dirName);
256 }
257 }
258
259 void MainWindow::updateWorkingDir()
260 {
261 setWorkingDir(m_workingDir->text());
262 }
263
264 void MainWindow::manual()
265 {
266 QDesktopServices::openUrl(QUrl(QString::fromLatin1("https://www.doxygen.org/manual/index.html")));
267 }
268
269 void MainWindow::about()
270 {
271 QString msg;
272 QTextStream t(&msg,QIODevice::WriteOnly);
273 t << QString::fromLatin1("<qt><center>A tool to configure and run doxygen version ")+
274 QString::fromLatin1(getDoxygenVersion().c_str())+
275 QString::fromLatin1(" on your source files.</center>")+
276 QString::fromLatin1("<center>(Created with Qt version ")+
277 QString::fromLatin1(QT_VERSION_STR);
278 if (qstrcmp(qVersion(),QT_VERSION_STR))
279 {
280 t << QString::fromLatin1(", running with ")+
281 QString::fromLatin1(qVersion());
282 }
283 t << QString::fromLatin1(")</center><p><br>"
284 "<center>Written by<br> Dimitri van Heesch<br>&copy; 2000-");
285 t << QDate::currentDate().year();
286 t << QString::fromLatin1("</center><p></qt>");
287 QMessageBox::about(this,tr("Doxygen GUI"),msg);
288 }
289
290 void MainWindow::openConfig()
291 {
292 if (discardUnsavedChanges(false))
293 {
294 QString fn = QFileDialog::getOpenFileName(this,
295 tr("Open configuration file"),
296 m_workingDir->text());
297 if (!fn.isEmpty())
298 {
299 loadConfigFromFile(fn);
300 }
301 }
302 }
303
304 void MainWindow::updateConfigFileName(const QString &fileName)
305 {
306 if (m_fileName!=fileName)
307 {
308 m_fileName = fileName;
309 QString curPath = QFileInfo(fileName).path();
310 setWorkingDir(curPath);
311 addRecentFile(fileName);
312 updateTitle();
313 }
314 }
315
316 void MainWindow::loadConfigFromFile(const QString & fileName)
317 {
318 // save full path info of original file
319 QString absFileName = QFileInfo(fileName).absoluteFilePath();
320 // updates the current directory
321 updateConfigFileName(fileName);
322 // open the specified configuration file
323 m_expert->loadConfig(absFileName);
324 m_wizard->refresh();
325 updateLaunchButtonState();
326 m_modified = false;
327 updateTitle();
328 }
329
330 void MainWindow::saveConfig(const QString &fileName)
331 {
332 if (fileName.isEmpty()) return;
333 QFile f(fileName);
334 if (!f.open(QIODevice::WriteOnly | QIODevice::Text ))
335 {
336 QMessageBox::warning(this,
337 tr("Error saving"),
338 QString(tr("Error: cannot open the file "))+fileName+tr(" for writing!\n")+
339 tr("Reason given: ")+QString::number(f.error()));
340 return;
341 }
342 QTextStream t(&f);
343 t.device()->setTextModeEnabled(false);
344 m_expert->writeConfig(t,false,false,false);
345 updateConfigFileName(fileName);
346 m_modified = false;
347 updateTitle();
348 }
349
350 bool MainWindow::saveConfig()
351 {
352 if (m_fileName.isEmpty())
353 {
354 return saveConfigAs();
355 }
356 else
357 {
358 saveConfig(m_fileName);
359 return true;
360 }
361 }
362
363 bool MainWindow::saveConfigAs()
364 {
365 QString fileName = QFileDialog::getSaveFileName(this, QString(),
366 m_workingDir->text()+QString::fromLatin1("/Doxyfile"));
367 if (fileName.isEmpty()) return false;
368 saveConfig(fileName);
369 return true;
370 }
371
372 void MainWindow::makeDefaults()
373 {
374 if (QMessageBox::question(this,tr("Use current setting at startup?"),
375 tr("Do you want to save the current settings "
376 "and use them next time Doxywizard starts?"),
377 QMessageBox::Save|
378 QMessageBox::Cancel)==QMessageBox::Save)
379 {
380 //printf("MainWindow:makeDefaults()\n");
381 m_expert->saveSettings(&m_settings);
382 m_settings.setValue(QString::fromLatin1("wizard/loadsettings"), true);
383 m_settings.sync();
384 }
385 }
386
387 void MainWindow::clearRecent()
388 {
389 if (QMessageBox::question(this,tr("Clear the list of recent files?"),
390 tr("Do you want to clear the list of recently "
391 "loaded configuration files?"),
392 QMessageBox::Yes|
393 QMessageBox::Cancel)==QMessageBox::Yes)
394 {
395 m_recentMenu->clear();
396 m_recentFiles.clear();
397 for (int i=0;i<MAX_RECENT_FILES;i++)
398 {
399 m_settings.setValue(QString::fromLatin1("recent/config%1").arg(i),QString::fromLatin1(""));
400 }
401 m_clearRecent->setEnabled(false);
402 m_recentMenu->setEnabled(false);
403 m_settings.sync();
404 }
405
406 }
407
408 void MainWindow::resetToDefaults()
409 {
410 if (QMessageBox::question(this,tr("Reset settings to their default values?"),
411 tr("Do you want to revert all settings back "
412 "to their original values?"),
413 QMessageBox::Reset|
414 QMessageBox::Cancel)==QMessageBox::Reset)
415 {
416 //printf("MainWindow:resetToDefaults()\n");
417 m_expert->resetToDefaults();
418 m_settings.setValue(QString::fromLatin1("wizard/loadsettings"), false);
419 m_settings.sync();
420 m_modified = false;
421 updateTitle();
422 m_wizard->refresh();
423 }
424 }
425
426 void MainWindow::loadSettings()
427 {
428 QVariant geometry = m_settings.value(QString::fromLatin1("main/geometry"));
429 QVariant state = m_settings.value(QString::fromLatin1("main/state"));
430 QVariant wizState = m_settings.value(QString::fromLatin1("wizard/state"));
431 QVariant loadSettings = m_settings.value(QString::fromLatin1("wizard/loadsettings"));
432 QVariant workingDir = m_settings.value(QString::fromLatin1("wizard/workingdir"));
433
434 if (!geometry.isNull()) restoreGeometry(geometry.toByteArray());
435 if (!state.isNull()) restoreState (state.toByteArray());
436 if (!wizState.isNull()) m_wizard->restoreState(wizState.toByteArray());
437 if (!loadSettings.isNull() && loadSettings.toBool())
438 {
439 m_expert->loadSettings(&m_settings);
440 if (!workingDir.isNull() && QDir(workingDir.toString()).exists())
441 {
442 setWorkingDir(workingDir.toString());
443 }
444 }
445
446 /* due to prepend use list in reversed order */
447 for (int i=MAX_RECENT_FILES;i>=0;i--)
448 {
449 QString entry = m_settings.value(QString::fromLatin1("recent/config%1").arg(i)).toString();
450 if (!entry.isEmpty() && QFileInfo(entry).exists())
451 {
452 addRecentFileList(entry);
453 }
454 }
455 updateRecentFile();
456
457 }
458
459 void MainWindow::saveSettings()
460 {
461 QSettings settings(QString::fromLatin1("Doxygen.org"), QString::fromLatin1("Doxywizard"));
462
463 m_settings.setValue(QString::fromLatin1("main/geometry"), saveGeometry());
464 m_settings.setValue(QString::fromLatin1("main/state"), saveState());
465 m_settings.setValue(QString::fromLatin1("wizard/state"), m_wizard->saveState());
466 m_settings.setValue(QString::fromLatin1("wizard/workingdir"), m_workingDir->text());
467 }
468
469 void MainWindow::selectTab(int id)
470 {
471 if (id==0) m_wizard->refresh();
472 else if (id==1) m_expert->refresh();
473 }
474
475 void MainWindow::selectRunTab()
476 {
477 m_tabs->setCurrentIndex(2);
478 }
479
480 void MainWindow::addRecentFile(const QString &fileName)
481 {
482 addRecentFileList(fileName);
483 updateRecentFile();
484 }
485 void MainWindow::addRecentFileList(const QString &fileName)
486 {
487 int i=m_recentFiles.indexOf(fileName);
488 if (i!=-1) m_recentFiles.removeAt(i);
489
490 // not found
491 if (m_recentFiles.count() < MAX_RECENT_FILES) // append
492 {
493 m_recentFiles.prepend(fileName);
494 }
495 else // add + drop last item
496 {
497 m_recentFiles.removeLast();
498 m_recentFiles.prepend(fileName);
499 }
500 m_clearRecent->setEnabled(m_recentFiles.count()>0);
501 m_recentMenu->setEnabled(m_recentFiles.count()>0);
502 m_settings.sync();
503 }
504 void MainWindow::updateRecentFile(void)
505 {
506 m_recentMenu->clear();
507 int i=0;
508 foreach( QString str, m_recentFiles )
509 {
510 m_recentMenu->addAction(str);
511 m_settings.setValue(QString::fromLatin1("recent/config%1").arg(i++),str);
512 }
513 for (;i<MAX_RECENT_FILES;i++)
514 {
515 m_settings.setValue(QString::fromLatin1("recent/config%1").arg(i),QString::fromLatin1(""));
516 }
517 m_clearRecent->setEnabled(m_recentFiles.count()>0);
518 m_recentMenu->setEnabled(m_recentFiles.count()>0);
519 m_settings.sync();
520 }
521
522 void MainWindow::openRecent(QAction *action)
523 {
524 if (discardUnsavedChanges(false))
525 {
526 loadConfigFromFile(action->text());
527 }
528 }
529
530 void MainWindow::runDoxygenMenu()
531 {
532 m_tabs->setCurrentWidget(m_runTab);
533 runDoxygen();
534 }
535
536 void MainWindow::runDoxygen()
537 {
538 if (!m_running)
539 {
540 QString doxygenPath;
541 #if defined(Q_OS_MACX)
542 doxygenPath = qApp->applicationDirPath()+QString::fromLatin1("/../Resources/");
543 qDebug() << tr("Doxygen path: ") << doxygenPath;
544 if ( !QFile(doxygenPath + QString::fromLatin1("doxygen")).exists() )
545 {
546 // No Doxygen binary in the resources, if there is a system Doxygen binary, use that instead
547 if ( QFile(QString::fromLatin1("/usr/local/bin/doxygen")).exists() )
548 {
549 doxygenPath = QString::fromLatin1("/usr/local/bin/");
550 }
551 else
552 {
553 qDebug() << tr("Can't find the doxygen command, make sure it's in your $$PATH");
554 doxygenPath = QString::fromLatin1("");
555 }
556 }
557 qDebug() << tr("Getting doxygen from: ") << doxygenPath;
558 #endif
559
560 m_runProcess->setReadChannel(QProcess::StandardOutput);
561 m_runProcess->setProcessChannelMode(QProcess::MergedChannels);
562 m_runProcess->setWorkingDirectory(m_workingDir->text());
563 QStringList env=QProcess::systemEnvironment();
564 // set PWD environment variable to m_workingDir
565 env.replaceInStrings(QRegularExpression(QString::fromLatin1("^PWD=(.*)"),QRegularExpression::CaseInsensitiveOption),
566 QString::fromLatin1("PWD=")+m_workingDir->text());
567 m_runProcess->setEnvironment(env);
568
569 QStringList args;
570 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
571 QStringList runOptions = m_runOptions->text().split(QLatin1Char(' '),QString::SkipEmptyParts);
572 #else
573 QStringList runOptions = m_runOptions->text().split(QLatin1Char(' '),Qt::SkipEmptyParts);
574 #endif
575
576 args << runOptions;
577 args << QString::fromLatin1("-b"); // make stdout unbuffered
578 args << QString::fromLatin1("-"); // read config from stdin
579
580 m_outputLog->clear();
581 m_runProcess->start(doxygenPath + QString::fromLatin1("doxygen"), args);
582
583 if (!m_runProcess->waitForStarted())
584 {
585 m_outputLog->append(APPQT(QString::fromLatin1("*** Failed to run doxygen\n")));
586 return;
587 }
588 QTextStream t(m_runProcess);
589 m_expert->writeConfig(t,false,false,false);
590 t.flush();
591 m_runProcess->closeWriteChannel();
592
593 if (m_runProcess->state() == QProcess::NotRunning)
594 {
595 m_outputLog->append(APPQT(QString::fromLatin1("*** Failed to run doxygen\n")));
596 }
597 else
598 {
599 m_saveLog->setEnabled(false);
600 m_running=true;
601 m_run->setText(tr("Stop doxygen"));
602 m_runMenu->setEnabled(false);
603 m_runStatus->setText(tr("Status: running"));
604 m_timer->start(1000);
605 }
606 }
607 else
608 {
609 m_running=false;
610 m_run->setText(tr("Run doxygen"));
611 m_runStatus->setText(tr("Status: not running"));
612 m_runProcess->kill();
613 m_timer->stop();
614 //updateRunnable(m_workingDir->text());
615 }
616 }
617
618 void MainWindow::readStdout()
619 {
620 if (m_running)
621 {
622 QByteArray data = m_runProcess->readAllStandardOutput();
623 QString text = QString::fromUtf8(data);
624 if (!text.isEmpty())
625 {
626 QScrollBar *vbar = m_outputLog->verticalScrollBar();
627
628 const QTextCursor old_cursor = m_outputLog->textCursor();
629 const bool is_scrolled_up = vbar->value() == vbar->maximum();
630 const int distanceFromBottom = vbar->minimum() - vbar->value();
631
632 m_outputLog->moveCursor(QTextCursor::End);
633
634 m_outputLog->insertPlainText(text);
635
636 if (old_cursor.hasSelection() || !is_scrolled_up)
637 {
638 m_outputLog->setTextCursor(old_cursor);
639 vbar->setValue(vbar->minimum() - distanceFromBottom);
640 }
641 else
642 {
643 m_outputLog->moveCursor(QTextCursor::End);
644 vbar->setValue(m_outputLog->verticalScrollBar()->maximum());
645 }
646 }
647 }
648 }
649
650 void MainWindow::runComplete()
651 {
652 if (m_running)
653 {
654 m_outputLog->append(APPQT(tr("*** Doxygen has finished\n")));
655 }
656 else
657 {
658 m_outputLog->append(APPQT(tr("*** Canceled by user\n")));
659 }
660 m_outputLog->ensureCursorVisible();
661 m_run->setText(tr("Run doxygen"));
662 m_runStatus->setText(tr("Status: not running"));
663 m_running=false;
664 m_runMenu->setEnabled(true);
665 updateLaunchButtonState();
666 //updateRunnable(m_workingDir->text());
667 m_saveLog->setEnabled(true);
668 }
669
670 void MainWindow::updateLaunchButtonState()
671 {
672 m_launchHtml->setEnabled(m_expert->htmlOutputPresent(m_workingDir->text()));
673 #if 0
674 m_launchPdf->setEnabled(m_expert->pdfOutputPresent(m_workingDir->text()));
675 #endif
676 }
677
678 void MainWindow::showHtmlOutput()
679 {
680 QString indexFile = m_expert->getHtmlOutputIndex(m_workingDir->text());
681 QFileInfo fi(indexFile);
682 // TODO: the following doesn't seem to work with IE
683 #ifdef _WIN32
684 //QString indexUrl(QString::fromLatin1("file:///"));
685 ShellExecute(nullptr, L"open", (LPCWSTR)fi.absoluteFilePath().utf16(), nullptr, nullptr, SW_SHOWNORMAL);
686 #else
687 QString indexUrl(QString::fromLatin1("file://"));
688 indexUrl+=fi.absoluteFilePath();
689 QDesktopServices::openUrl(QUrl(indexUrl));
690 #endif
691 }
692
693 void MainWindow::saveLog()
694 {
695 QString fn = QFileDialog::getSaveFileName(this, tr("Save log file"),
696 m_workingDir->text()+
697 QString::fromLatin1("/doxygen_log.txt"));
698 if (!fn.isEmpty())
699 {
700 QFile f(fn);
701 if (f.open(QIODevice::WriteOnly))
702 {
703 QTextStream t(&f);
704 t << m_outputLog->toPlainText();
705 statusBar()->showMessage(tr("Output log saved"),messageTimeout);
706 }
707 else
708 {
709 QMessageBox::warning(nullptr, tr("Warning"),
710 tr("Cannot open file ") + fn + tr(" for writing. Nothing saved!"), QMessageBox::Ok);
711 }
712 }
713 }
714
715 void MainWindow::showSettings()
716 {
717 QString text;
718 QTextStream t(&text);
719 if (m_showCondensedSettings->isChecked())
720 {
721 m_expert->writeConfig(t,true,true,true);
722 }
723 else
724 {
725 m_expert->writeConfig(t,true,false,true);
726 }
727 m_outputLog->clear();
728 m_outputLog->append(APPQT(text));
729 m_outputLog->ensureCursorVisible();
730 m_saveLog->setEnabled(true);
731 }
732
733 void MainWindow::configChanged()
734 {
735 m_modified = true;
736 updateTitle();
737 }
738
739 void MainWindow::updateTitle()
740 {
741 QString title = tr("Doxygen GUI frontend");
742 m_resetDefault->setEnabled(m_modified);
743 if (m_modified)
744 {
745 title+=QString::fromLatin1(" +");
746 }
747 if (!m_fileName.isEmpty())
748 {
749 title+=QString::fromLatin1(" (")+m_fileName+QString::fromLatin1(")");
750 }
751 setWindowTitle(title);
752 }
753
754 bool MainWindow::discardUnsavedChanges(bool saveOption)
755 {
756 if (m_modified)
757 {
758 QMessageBox::StandardButton button;
759 if (saveOption)
760 {
761 button = QMessageBox::question(this,
762 tr("Unsaved changes"),
763 tr("Unsaved changes will be lost! Do you want to save the configuration file?"),
764 QMessageBox::Save |
765 QMessageBox::Discard |
766 QMessageBox::Cancel
767 );
768 if (button==QMessageBox::Save)
769 {
770 return saveConfig();
771 }
772 }
773 else
774 {
775 button = QMessageBox::question(this,
776 tr("Unsaved changes"),
777 tr("Unsaved changes will be lost! Do you want to continue?"),
778 QMessageBox::Discard |
779 QMessageBox::Cancel
780 );
781 }
782 return button==QMessageBox::Discard;
783 }
784 return true;
785 }
786
787 void MainWindow::outputLogStart()
788 {
789 m_outputLogTextCount = 0;
790 m_outputLog->clear();
791 }
792 void MainWindow::outputLogText(QString text)
793 {
794 m_outputLogTextCount++;
795 m_outputLog->append(APPQT(text));
796 }
797 void MainWindow::outputLogFinish()
798 {
799 if (m_outputLogTextCount > 0)
800 {
801 selectRunTab();
802 }
803
804 m_outputLog->ensureCursorVisible();
805 m_saveLog->setEnabled(true);
806 }
807 //-----------------------------------------------------------------------
808 int main(int argc,char **argv)
809 {
810 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
811 static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO";
812 if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)
813 && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
814 && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
815 && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
816 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
817 }
818 #endif
819
820 QApplication a(argc,argv);
821 int locArgc = argc;
822
823 if (locArgc == 2)
824 {
825 if (!qstrcmp(argv[1],"--help"))
826 {
827 QMessageBox msgBox;
828 msgBox.setText(QString::fromLatin1("Usage: %1 [config file]").arg(QString::fromLatin1(argv[0])));
829 msgBox.exec();
830 exit(0);
831 }
832 else if (!qstrcmp(argv[1],"--version"))
833 {
834 QMessageBox msgBox;
835 if (!qstrcmp(qVersion(),QT_VERSION_STR))
836 {
837 msgBox.setText(QString::fromLatin1("Doxywizard version: %1, Qt version: %2").arg(QString::fromLatin1(getFullVersion().c_str()),QString::fromLatin1(QT_VERSION_STR)));
838 }
839 else
840 {
841 msgBox.setText(QString::fromLatin1("Doxywizard version: %1, Qt version: created with %2, running with %3").arg(QString::fromLatin1(getFullVersion().c_str()),QString::fromLatin1(QT_VERSION_STR),QString::fromLatin1(qVersion())));
842 }
843 msgBox.exec();
844 exit(0);
845 }
846 }
847 if (!qstrcmp(argv[1],"--debug") && ((locArgc == 2) || (locArgc == 3)))
848 {
849 DoxygenWizard::debugFlag = true;
850 locArgc--;
851 }
852
853 if (locArgc > 2)
854 {
855 QMessageBox msgBox;
856 msgBox.setText(QString::fromLatin1("Too many arguments specified\n\nUsage: %1 [config file]").arg(QString::fromLatin1(argv[0])));
857 msgBox.exec();
858 exit(1);
859 }
860 else
861 {
862 MainWindow &main = MainWindow::instance();
863 if (locArgc==2 && argv[argc-1][0]!='-') // name of config file as an argument
864 {
865 main.loadConfigFromFile(QString::fromLocal8Bit(argv[argc-1]));
866 }
867 main.show();
868 return a.exec();
869 }
870 }