Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / experimental / tools / DocumentationHelper / mainwindow.cpp
blobc312bb0ac27d438ece38282d29ac24f779a0e7b7
1 /**
2 ******************************************************************************
4 * @file mainwindow.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup DocumentationHelper
9 * @{
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "mainwindow.h"
30 #include "ui_mainwindow.h"
31 #include "QFileDialog"
32 MainWindow::MainWindow(QWidget *parent) :
33 QMainWindow(parent),
34 ui(new Ui::MainWindow)
36 ui->setupUi(this);
37 license << "/**";
38 license << "******************************************************************************";
39 license << "*";
40 license << "* @file %file";
41 license << "* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.";
42 license << "* @brief ";
43 license << "* @see The GNU Public License (GPL) Version 3";
44 license << "* @defgroup %defgroup";
45 license << "* @{";
46 license << "* ";
47 license << "*****************************************************************************/";
48 license << "/* ";
49 license << "* This program is free software; you can redistribute it and/or modify ";
50 license << "* it under the terms of the GNU General Public License as published by ";
51 license << "* the Free Software Foundation; either version 3 of the License, or ";
52 license << "* (at your option) any later version.";
53 license << "* ";
54 license << "* This program is distributed in the hope that it will be useful, but ";
55 license << "* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ";
56 license << "* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ";
57 license << "* for more details.";
58 license << "* ";
59 license << "* You should have received a copy of the GNU General Public License along ";
60 license << "* with this program; if not, write to the Free Software Foundation, Inc., ";
61 license << "* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA";
62 license << "*/";
65 MainWindow::~MainWindow()
67 delete ui;
70 void MainWindow::changeEvent(QEvent *e)
72 QMainWindow::changeEvent(e);
74 switch (e->type()) {
75 case QEvent::LanguageChange:
76 ui->retranslateUi(this);
77 break;
78 default:
79 break;
83 void MainWindow::on_cpathBT_clicked()
85 wpath = QFileDialog::getExistingDirectory(this, "Choose Work Path");
86 ui->cpathL->setText("Current Path:" + wpath);
89 void MainWindow::on_goBT_clicked()
91 QDir myDir(wpath);
92 QStringList filter;
94 filter << "*.cpp" << "*.h";
95 QStringList list = myDir.entryList(filter);
97 foreach(QString str, list) {
98 bool go = true;
100 if (ui->confirmCB->isChecked()) {
101 if (QMessageBox::question(this, "Process File?:", str, QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
102 go = false;
105 if (go) {
106 ui->cfileL->setText("Current File:" + str);
107 QFile file(wpath + QDir::separator() + str);
108 if (!file.open(QIODevice::ReadWrite)) {
109 ui->output->append("Cannot open file " + str + " for writing");
110 } else {
111 ui->output->append("Processing file " + str);
112 QTextStream out(&file);
113 QStringList filestr;
114 out.seek(0);
115 while (!out.atEnd()) {
116 filestr << out.readLine();
118 out.seek(0);
119 if (ui->licenseCB->isChecked()) {
120 bool haslicense = false;
121 foreach(QString str, filestr) {
122 if (str.contains("The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010")) {
123 haslicense = true;
124 ui->output->append("File Already has License Info");
128 if (!haslicense) {
129 bool process = true;
130 if (ui->confirmCB->isChecked()) {
131 if (QMessageBox::question(this, "Add license Info?:", str, QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
132 process = false;
135 if (process) {
136 ui->output->append("Added License info to file");
137 out.seek(0);
138 foreach(QString line, license) {
139 line.replace("%file", str);
140 line.replace("%defgroup", ui->defgroup->text());
141 out << line << "\r\n";
143 foreach(QString str, filestr) out << str + "\r\n";
146 out.flush();
148 if (ui->nameCB->isChecked()) {
149 filestr.clear();
150 out.seek(0);
151 while (!out.atEnd()) {
152 filestr << out.readLine();
154 out.reset();
155 bool process = true;
156 foreach(QString s, filestr) {
157 if (s.contains("namespace")) {
158 process = false;
159 ui->output->append("File Already has Namespace");
163 if (ui->confirmCB->isChecked() && process) {
164 if (QMessageBox::question(this, "Create Namespace?:", str, QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
165 process = false;
168 if (process) {
169 ui->output->append("Added NameSpace to file");
170 out.seek(0);
171 bool initdone = false;
172 for (int x = 0; x < filestr.count(); ++x) {
173 QString line = filestr.at(x);
174 if (!initdone) {
175 if (!(line.trimmed().startsWith("#") || line.trimmed().startsWith("/") || line.trimmed().startsWith("*") || line.trimmed().isEmpty())) {
176 filestr.insert(x, "namespace " + ui->namespa->text() + " {");
177 filestr.insert(x, " ");
178 initdone = true;
180 } else {
181 if ((QString)str.split(".").at(1) == "cpp") {
182 filestr.append("}");
183 break;
184 } else {
185 for (int y = filestr.count() - 1; y > 1; --y) {
186 QString s = filestr.at(y);
187 if (s.contains("#endif")) {
188 filestr.insert(y, "}");
189 break;
192 break;
196 foreach(QString str, filestr) out << str + "\r\n";
197 out.flush();
200 if (ui->bockifCB->isChecked()) {
201 QString genif;
202 ui->output->append("Creating block ifs");
203 filestr.clear();
204 out.seek(0);
205 while (!out.atEnd()) {
206 filestr << out.readLine();
208 out.seek(0);
209 for (int x = 1; x < filestr.count() - 1; ++x) {
210 QString before = filestr.at(x - 1);
211 QString actual = filestr.at(x);
212 QString after = filestr.at(x + 1);
213 if (actual.trimmed().startsWith("qDebug") && !before.contains("#ifdef") && !before.contains("qDebug")) {
214 filestr.insert(x, "#ifdef DEBUG_" + (QString)str.split(".").at(0).toUpper());
215 ++x;
216 genif = "#define DEBUG_" + (QString)str.split(".").at(0).toUpper();
218 if (actual.trimmed().startsWith("qDebug") && !after.contains("qDebug") && !after.contains("#endif")) {
219 filestr.insert(x + 1, "#endif //DEBUG_" + (QString)str.split(".").at(0).toUpper());
222 if (!genif.isEmpty()) {
223 ui->textEdit->append(genif);
225 foreach(QString str, filestr) out << str + "\r\n";
226 out.flush();
228 file.close();