MarketClientAssistant.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file MarketClientAssistant.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_UIMARKET_MARKETCLIENTASSISTANT_HPP__
41 #define __OPENFLUID_UIMARKET_MARKETCLIENTASSISTANT_HPP__
42 
43 #include <QWizard>
44 #include <QBoxLayout>
45 #include <QLabel>
46 #include <QComboBox>
47 #include <QTabWidget>
48 #include <QPushButton>
49 #include <QScrollArea>
50 #include <QTreeWidget>
51 #include <QRadioButton>
52 #include <QTextEdit>
53 #include <QTableWidget>
54 #include <QProgressBar>
55 #include <QSplitter>
56 #include <QStandardItemModel>
57 
58 #include <openfluid/dllexport.hpp>
61 
62 
63 namespace openfluid { namespace ui { namespace market {
64 
65 class MarketPackWidget;
66 
67 // TODO review parenting of all widgets
68 class OPENFLUID_API MarketClientAssistant : public QWizard
69 {
70  Q_OBJECT
71 
72  private:
73 
74  // ===== Package selection =====//
75  MarketWizardPage m_SelectionPage;
76  QVBoxLayout m_SelectionPageBox;
77 
78  QHBoxLayout m_URLBox;
79  QLabel m_URLLabel;
80  QComboBox m_URLCombo;
81  QStandardItemModel m_RefURLComboBoxModel;
82 
83  class URLComboColumns : public QList<QStandardItem*>
84  {
85  public:
86 
87  enum { NAME, URL};
88 
89  QStandardItem* mp_Name;
90  QStandardItem* mp_URL;
91 
92  URLComboColumns() :
93  mp_Name(nullptr), mp_URL(nullptr)
94  { }
95 
96  void appendItems()
97  {
98  clear();
99  append(mp_Name);
100  append(mp_URL);
101  }
102  };
103 
104  URLComboColumns m_URLColumns;
105 
106 
107  // Tabs
108  QTabWidget m_TypesTabs;
109 
110  // Pages and main box of tab
111  std::map<openfluid::market::PackageInfo::PackageType,QWidget*> mp_TabPage;
112  std::map<openfluid::market::PackageInfo::PackageType,QVBoxLayout*> mp_TabBox;
113 
114  // Box and ScrolledWindow for packages list
115  std::map<openfluid::market::PackageInfo::PackageType,QVBoxLayout*> mp_AvailTypesPacksBox;
116  std::map<openfluid::market::PackageInfo::PackageType,QScrollArea*> mp_AvailTypesPacksSWindow;
117 
118  // Buttons of tab
119  std::map<openfluid::market::PackageInfo::PackageType,QHBoxLayout*> mp_ActionButtonsBox;
120  std::map<openfluid::market::PackageInfo::PackageType,QPushButton*> mp_SelectAllButton;
121  std::map<openfluid::market::PackageInfo::PackageType,QPushButton*> mp_SelectNoneButton;
122  std::map<openfluid::market::PackageInfo::PackageType,QPushButton*> mp_CommonBuildConfigButton;
123 
124  // List of MarketPackWidget
125  std::map<openfluid::market::PackageInfo::PackageType,std::list<MarketPackWidget*> > mp_AvailPacksWidgets;
126 
127 
128  /**
129  @return Type of current tab
130  */
132 
133 
134  /**
135  @return MarketPackWidget of ID package
136  @param ID of package
137  */
138  MarketPackWidget* availablePackWidget(const openfluid::ware::WareID_t& ID) const;
139 
140  /**
141  @return true if ID package passed as parameter has datasets selected which need it
142  @param ID of dependence
143  @param Type Type of dependence
144  */
145  bool hasParentSelected(const openfluid::ware::WareID_t& ID,
147 
148  /**
149  @return choice of user to apply action of selected dataset to this dependencies
150  @param ID of package selected
151  @param Select action applied on the package
152  @param List of dependencies to select
153  */
154  bool getUserChoice(const openfluid::ware::WareID_t& ID, const bool Select,
155  const std::map<openfluid::market::PackageInfo::PackageType,std::list<MarketPackWidget*> >& PacksToSelect);
156 
157 
158  // ===== Licenses =====//
159  MarketWizardPage m_LicensesPage;
160  QVBoxLayout m_LicensesPageBox;
161 
162  QLabel m_LicensesLabel;
163 
164  // Adjustable container for packages treeview and license text view
165  QSplitter m_LicensesReviewPaned;
166 
167  QTreeWidget *mp_LicensesTreeView;
168 
169  QTextEdit *mp_LicensesTextView;
170 
171 
172  QScrollArea m_LicensesListSWindow;
173  QScrollArea m_LicensesReviewSWindow;
174 
175  QRadioButton m_LicensesAcceptRadio;
176  QRadioButton m_LicensesDoNotRadio;
177 
178 
179 
180 
181  // ===== Download and install =====//
182  MarketWizardPage m_InstallPage;
183 
184  QVBoxLayout m_InstallPageBox;
185 
186  QTableWidget *mp_InstallTable;
187 
188 
189  class InstallTableColumns
190  {
191  public:
192 
193  enum { ID, TYPE, FORMAT, STATUS};
194 
195  QTableWidgetItem* mp_ID;
196  QTableWidgetItem* mp_Type;
197  QTableWidgetItem* mp_Format;
198  QTableWidgetItem* mp_Status;
199 
200  InstallTableColumns() :
201  mp_ID(nullptr), mp_Type(nullptr), mp_Format(nullptr), mp_Status(nullptr)
202  {
203 
204  }
205 
206  void setFlags()
207  {
208  mp_ID->setFlags(mp_ID->flags() ^ Qt::ItemIsEditable);
209  mp_Type->setFlags(mp_Type->flags() ^ Qt::ItemIsEditable);
210  mp_Format->setFlags(mp_Format->flags() ^ Qt::ItemIsEditable);
211  mp_Status->setFlags(mp_Status->flags() ^ Qt::ItemIsEditable);
212  }
213  };
214 
215  InstallTableColumns m_InstallColumns;
216 
217 
218  QScrollArea m_InstallSWindow;
219 
220  QProgressBar m_InstallProgressBar;
221  QPushButton m_ViewLogButton;
222 
223 
224  void setupSelectionPage();
225  void setupLicensesPage();
226  void setupDownloadPage();
227 
228 
229  /**
230  * Removes tabs, destroys content and clear screen
231  */
232  void clearAvailPacksTreeview();
233 
234  /**
235  * Creates tabs and display all available packages in Market-place selected
236  */
237  void updateAvailPacksTreeview();
238 
239  /**
240  * Indicates that no marketplace reached and unselects repository
241  */
242  void displayMarketplaceError();
243 
244 
245  void initializeLicencesTreeView();
246 
247  void updateInstallTreeview();
248 
249  openfluid::market::MarketClient m_MarketClient;
250 
251  int m_InstallationTimeout;
252 
253 
254  private slots:
255 
256  void onApply();
257  void onCancel();
258  void onClose();
259  void onPrepare(int Id);
260 
261  void onURLComboChanged(int RowNumber);
262 
263  /**
264  * Selects all packages of current tab
265  */
266  void onSelectAllClicked();
267 
268  /**
269  * Unselects all packages of current tab
270  */
271  void onSelectNoneClicked();
272 
273  /**
274  * Edit common options of packages of the current tab
275  */
276  void onCommonBuildConfigClicked();
277 
278 
279  /**
280  Selects dependencies of ID package
281  @param ID of package selected
282  */
283  void selectDependencies(const openfluid::ware::WareID_t& ID);
284 
285 
286  void onPackageInstallModified();
287 
288 
289  void onLicenseRadioClicked(bool Checked);
290 
291 
292  void onLicensesTreeviewChanged(QTreeWidgetItem *CurrentItem);
293 
294 
295  void onInstallTimeoutOnce();
296 
297  void onViewLogClicked();
298 
299 
300  public:
301 
302  MarketClientAssistant(QWidget* Parent);
303 
304  virtual ~MarketClientAssistant();
305 
306  /**
307  @return string name of type passed as parameter
308  @param Type Type of package
309  @param Maj First letter in maj
310  @param Plural Return plural name
311  */
312  static QString getGraphicTypeName(const openfluid::market::PackageInfo::PackageType& Type,
313  const bool Maj, const bool Plural);
314 };
315 
316 } } } // namespaces
317 
318 
319 #endif /* __OPENFLUID_UIMARKET_MARKETCLIENTASSISTANT_HPP__ */
Definition: MarketClient.hpp:68
PackageType
Definition: MarketInfos.hpp:93
std::string WareID_t
Definition: TypeDefs.hpp:50
Definition: MarketWizardPage.hpp:49
Definition: MarketPackWidget.hpp:58
Definition: ApplicationException.hpp:47
#define OPENFLUID_API
Definition: dllexport.hpp:87
Definition: MarketClientAssistant.hpp:68