1 //
2 //  FLExportManager.h
3 //
4 //
5 //  Created by Sarah Denoux on 13/05/13.
6 //  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
7 //
8 // FLExportManager is the interface that establish a connection with faustweb-server to export a faust application.
9 
10 // There are multiple requests accepted by the server :
11 /*  GET /targets : sends the JSON encoding the available targets
12     POST /filepost : response with a SHA Key if the file could be compiled
13     GET /sha/platform/architecture/binary.zip : response with the requested file that can then be written on the disk
14 */
15 
16 #ifndef _FLExportManager_h
17 #define _FLExportManager_h
18 
19 #include <string>
20 #include <iostream>
21 #include <list>
22 
23 #include <QtGui>
24 #if QT_VERSION >= 0x050000
25 #include <QtWidgets>
26 #endif
27 
28 #include <QtNetwork>
29 
30 using namespace std;
31 
32 class FLTargetChooser : public QDialog {
33 
34     private:
35 
36         Q_OBJECT
37 
38         static FLTargetChooser*    _targetChooser;
39 
40 //---> a little redondant. Could it be possible to only have fTargets ??
41         vector<string>                  fPlatforms;     // list of available export platforms
42         map<string, vector<string> >    fTargets;       // plateform -> available targets
43 
44         QNetworkReply*      fTargetReply;
45 
46     //    Graphical elements
47         QGroupBox*          fMenu2Export;
48         QGridLayout*        fMenu2Layout;
49         QComboBox*          fExportFormat;
50         QComboBox*          fExportPlatform;
51         QComboBox*          fExportArchi;
52         QComboBox*          fExportChoice;
53 
54         QLabel*             fErrorText;
55 
56     //    Saving the user choices
57         QString             fLastPlatform;
58         QString             fLastArchi;
59         QString             fLastChoice;
60 
61         void                init();
62         void                sendTargetRequest();
63 
64     public:
65 
66         FLTargetChooser(QWidget* parent = NULL);
67         virtual ~FLTargetChooser();
68 
69         static FLTargetChooser* _Instance();
70 
71         QString         platform();
72         QString         architecture();
73         QString         binOrSource();
74 
75         public slots:
76 
77         void            acceptDialog();
78         void            cancelDialog();
79 
80         void            abortReply();
81         void            targetsDescriptionReceived();
82         void            platformChanged(int index);
83         void            platformChanged(const QString& index);
84         void            setLastState();
85         virtual void    closeEvent(QCloseEvent* event);
86 
87 };
88 
89 class FLExportManager : public QDialog{
90 
91     private:
92 
93         Q_OBJECT
94 
95         QString              fAppName;
96         QString              fCodeToSend;
97 
98         //Saving repository chosen by the user
99         QString				fLastOpened;
100 
101         //Target characteristics
102         QString             fUrl;
103         QString             fPlatform;
104         QString             fArchi;
105         QString             fChoice;
106 
107         //Expected network replies
108         QNetworkReply *     fPostReply;
109         QNetworkReply*      fGetKeyReply;
110 
111         int                 fStep;  // To know what step has crashed the export
112 
113         QByteArray          fDataReceived;
114 
115         //Dialog for export progress and its graphical elements
116         QGridLayout*        fMsgLayout;
117         QLabel*             fConnectionLabel;
118         QLabel*             fCompilationLabel;
119         QProgressDialog*    fPrgBar;
120         QLabel*             fCheck1;
121         QLabel*             fCheck2;
122 
123 
124         QLabel*             fQrCodeLabel;
125         QTextEdit*          fTextZone;
126 
127         QPixmap             fCheckImg;
128         QPixmap             fNotCheckImg;
129 
130         QPushButton*        fSaveB;
131         QPushButton*        fOkB;
132 
133         void                init();
134         void                abortReply(QNetworkReply* reply);
135 
136         static FLExportManager*    _exportManager;
137 
138     public:
139         FLExportManager();
140         ~FLExportManager();
141         static FLExportManager*    _Instance();
142 
143         void            exportFile(const QString& name, const QString& faustCode, const QString& p, const QString& a, const QString& sb);
144 
145         public slots:
146 
147         void            postExport();
148         void            readKey();
149         void            networkError(QNetworkReply::NetworkError msg);
150         void            getFileFromKey(const char* key);
151         void            saveFileOnDisk();
152         void            showSaveB();
153         void            redirectAbort();
154         virtual void    closeEvent(QCloseEvent* event);
155 
156 };
157 
158 #endif
159