2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup DocumentationHelper
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
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
) :
34 ui(new Ui::MainWindow
)
38 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";
47 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.";
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.";
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";
65 MainWindow::~MainWindow()
70 void MainWindow::changeEvent(QEvent
*e
)
72 QMainWindow::changeEvent(e
);
75 case QEvent::LanguageChange
:
76 ui
->retranslateUi(this);
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()
94 filter
<< "*.cpp" << "*.h";
95 QStringList list
= myDir
.entryList(filter
);
97 foreach(QString str
, list
) {
100 if (ui
->confirmCB
->isChecked()) {
101 if (QMessageBox::question(this, "Process File?:", str
, QMessageBox::Yes
, QMessageBox::No
) == QMessageBox::No
) {
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");
111 ui
->output
->append("Processing file " + str
);
112 QTextStream
out(&file
);
115 while (!out
.atEnd()) {
116 filestr
<< out
.readLine();
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")) {
124 ui
->output
->append("File Already has License Info");
130 if (ui
->confirmCB
->isChecked()) {
131 if (QMessageBox::question(this, "Add license Info?:", str
, QMessageBox::Yes
, QMessageBox::No
) == QMessageBox::No
) {
136 ui
->output
->append("Added License info to file");
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";
148 if (ui
->nameCB
->isChecked()) {
151 while (!out
.atEnd()) {
152 filestr
<< out
.readLine();
156 foreach(QString s
, filestr
) {
157 if (s
.contains("namespace")) {
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
) {
169 ui
->output
->append("Added NameSpace to file");
171 bool initdone
= false;
172 for (int x
= 0; x
< filestr
.count(); ++x
) {
173 QString line
= filestr
.at(x
);
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
, " ");
181 if ((QString
)str
.split(".").at(1) == "cpp") {
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
, "}");
196 foreach(QString str
, filestr
) out
<< str
+ "\r\n";
200 if (ui
->bockifCB
->isChecked()) {
202 ui
->output
->append("Creating block ifs");
205 while (!out
.atEnd()) {
206 filestr
<< out
.readLine();
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());
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";