File indexing completed on 2024-04-14 04:29:47

0001 /*
0002  * This file is part of KDevelop project
0003  * Copyright 2016 Patrick José Pereira <patrickelectric@gmail.com>
0004  * Based onde the work Arduide Project of:
0005  *  Denis Martinez
0006  *  Martin Peres
0007  *
0008  * This program is free software; you can redistribute it and/or modify
0009  * it under the terms of the GNU Library General Public License as
0010  * published by the Free Software Foundation; either version 2 of the
0011  * License, or (at your option) any later version.
0012  *
0013  * This program is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  * GNU General Public License for more details.
0017  *
0018  * You should have received a copy of the GNU General Public
0019  * License along with this program; if not, write to the
0020  * Free Software Foundation, Inc.,
0021  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0022  */
0023 
0024 #pragma once
0025 
0026 // first time wizard configuration
0027 
0028 #include <QWizard>
0029 #include <QProcess>
0030 #include <QLoggingCategory>
0031 
0032 #include "ui_firsttimewizard.h"
0033 
0034 #include "arduinoversion.h"
0035 
0036 Q_DECLARE_LOGGING_CATEGORY(FtwIo)
0037 Q_DECLARE_LOGGING_CATEGORY(FtwMsg)
0038 
0039 class QNetworkAccessManager;
0040 class QNetworkReply;
0041 class KFormat;
0042 
0043 class FirstTimeWizard : public QWizard, Ui::FirstTimeWizard
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     explicit FirstTimeWizard(QWidget *parent = nullptr);
0049     ~FirstTimeWizard() override;
0050 
0051     QNetworkAccessManager *m_mDownloadManager;
0052     QNetworkReply *m_reply;
0053 
0054     static QString arduinoDownloadUrl;
0055     static QString downloadExtensionUrl;
0056     static QString downloadArchUrl;
0057     static QString downloadOsUrl;
0058 
0059     bool m_downloadRunning;
0060     bool m_downloadFinished;
0061     bool m_installFinished;
0062 
0063     //get mcu list from avrdude
0064     QProcess *m_avrdudeProcess;
0065     KFormat  *m_format;
0066 
0067     /**
0068      * @brief Populate `Arduino Path` field with valid path to a Arduino install.
0069      *
0070      * If a setting exists, it is used, otherwise standard paths are verified
0071      * and if a valid one is found, it is used.
0072      */
0073     void fetchArduinoPath();
0074     /**
0075      * @brief Populate `Sketchbook Path` field with valid projects path.
0076      *
0077      * If a setting exists, it is used, otherwise standard paths are verified
0078      * and if a valid one is found, it is used.
0079      */
0080     void fetchSketchbookPath();
0081     QString downloadAndInstallArduino();
0082     bool validateCurrentPage() override;
0083     int  nextId() const override;
0084     bool finish();
0085 
0086     void onDownloadProgress(qint64 received, qint64 total);
0087     void chooseArduinoPath();
0088     void validateCurrentId(int id);
0089     void cancelButtonClicked(bool state);
0090     void chooseSketchbookPath();
0091     void download();
0092     void install();
0093 
0094     void avrdudeStdout();
0095     void avrdudeStderr(int exitCode, QProcess::ExitStatus exitStatus);
0096 
0097 };