NCL Composer  0.1.5
 All Classes Functions Variables Pages
WelcomeWidget.h
1 /* Copyright (c) 2011 Telemidia/PUC-Rio.
2  * All rights reserved. This program and the accompanying materials
3  * are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors:
8  * Telemidia/PUC-Rio - initial API and implementation
9  */
10 #ifndef WELCOMEWIDGET_H
11 #define WELCOMEWIDGET_H
12 
13 #include <QObject>
14 #include <QDebug>
15 #include <QEvent>
16 #include <QWidget>
17 #include <QTableWidget>
18 #include <QListWidgetItem>
19 #include <QProgressDialog>
20 #include <QFileDialog>
21 
22 #include <QXmlStreamReader>
23 #include <QtNetwork>
24 #include <QUrl>
25 #include <QDesktopServices>
26 #include <QMessageBox>
27 
28 #ifdef WITH_CLUBNCL
29 #include <quazip/quazip.h>
30 #include <quazip/quazipfile.h>
31 #endif
32 
33 #define NCL_CLUB_URL "http://club.ncl.org.br/rss.xml"
34 #define MAX_RECENT_PROJECTS 6
35 
36 namespace Ui{
37 class WelcomeWidget;
38 }
39 
40 namespace composer {
41 namespace gui {
42 
43 /* FROM:
44 http://www.streamreader.org/stackoverflow/questions/2480773/qt-styling-qtabwidget
45 */
46 // Sets the style sheet of the QTabWidget to expand the tabs.
47 static void expandingTabsStyleSheet(QTabWidget *tw)
48 {
49  tw->setStyleSheet(QString("QTabBar::tab { width: %1px;} ")
50  .arg(tw->size().width()/tw->count() - 20));
51 }
52 
58 class ResizeFilter : public QObject
59 {
60  QTabWidget *target;
61 public:
62  ResizeFilter(QTabWidget *target) : QObject(target), target(target) {}
63 
64  bool eventFilter(QObject */*object*/, QEvent *event)
65  {
66  if (event->type() == QEvent::Resize)
67  expandingTabsStyleSheet(target);
68  return false;
69  }
70 };
71 /************************************************************************/
72 
81 class WelcomeWidget: public QWidget {
82  Q_OBJECT
83 
84 public:
89  WelcomeWidget(QWidget *parent = 0);
93  virtual ~WelcomeWidget();
94 
95 private slots:
96  void on_commandLinkButton_29_clicked();
97  void on_commandLinkButton_6_clicked();
98  // void on_commandLinkButton_9_clicked();
99  // void on_commandLinkButton_30_clicked();
100  void on_commandLinkButton_10_clicked();
101  void on_commandLinkButton_11_clicked();
102  void on_commandLinkButton_31_clicked();
103  void on_commandLinkButton_7_clicked();
104  void on_commandLinkButton_8_clicked();
105 
106 private:
107  int connectionId;
108  QHttp http;
109  QXmlStreamReader xmlReader;
110 
111  Ui::WelcomeWidget *ui;
112  int n_items;
113 
114  void loadRSS();
115  void parseXml();
116 
117  //TODO: Create a class to handle individual RSS items
118  QVector <QString> description;
119  QVector <QString> imgSrc;
120  QVector <QString> downloadUrl;
121  bool isImageEnclosure;
122 
123  QString currentTag, currentLink, currentTitle, currentDate, currentDesc,
124  currentImg, currentDownloadUrl;
125 
126 /* Loading Notify Messages */
127  QHttp httpNotifyMessages;
128  void updateNotifyMessages();
129 
130 private slots:
131  void notifyMessagesReadData(const QHttpResponseHeader &);
132 /* END Notify loading messages */
133 
134 #ifdef WITH_CLUBENCL
135 private:
136  /* \todo NCL Club download Application (this must be a separated class). */
137  QProgressDialog *progressDialog;
138  QUrl url;
139  QNetworkAccessManager qnam;
140  QNetworkReply *reply;
141  bool httpRequestAborted;
142  QFile *file;
143  int httpGetId;
144  int currentNCLClubItem;
145  int currentFile;
146  QuaZip zip;
147  QuaZipFile zipFile;
148  QString fileNameToImport;
149  QString projectName;
150  bool isDownloading;
151 
152  void downloadFile();
153  void startRequest(const QUrl &url);
154  bool extract( const QString & filePath,
155  const QString & extDirPath,
156  const QString & singleFileName = QString(""));
157 
158 private slots:
159  void httpFinished();
160  void httpReadyRead();
161  void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
162  void cancelDownload();
163 
164  /* END NCL Club download Application */
165 
166 private slots:
167  void changeCurrentItem(int item);
168 
169  void readData(const QHttpResponseHeader &resp);
170  void finishRSSLoad(int, bool);
171  void downloadApplication();
172 
173 
174  bool doExtractCurrentFile( QString extDirPath,
175  QString singleFileName,
176  bool stop);
177 
178 signals:
179  void extractNextFile( QString extDirPath,
180  QString singleFileName,
181  bool stop);
182 #endif
183 
184 private slots:
185  void on_commandLinkButton_pressed();
186  void on_commandLinkButton_2_pressed();
187 
188 
189 signals:
193  void userPressedOpenProject();
194 
198  void userPressedNewProject();
199 
205 
209  void userPressedRecentProject(QString project);
210 
211 private slots:
212  void sendRecentProjectClicked();
213 
214  void on_commandLinkButton_3_pressed();
215 
216 public slots:
217  void updateRecentProjects(QStringList recentProjects);
218 };
219 
220 } }
221 #endif // WELCOMEWIDGET_H