NCL Composer  0.1.5
 All Classes Functions Variables Pages
ComposerMainWindow.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 COMPOSERMAINWINDOW_H
11 #define COMPOSERMAINWINDOW_H
12 
13 #include <QtDebug>
14 #include <QStringList>
15 #include <QMap>
16 #include <QFileSystemModel>
17 
18 #include <QCoreApplication>
19 #include <QApplication>
20 #include <QTimer>
21 #include <QtGui/QMainWindow>
22 #include <QtGui/QTabWidget>
23 #include <QtGui/QStatusBar>
24 #include <QtGui/QMenu>
25 #include <QtGui/QAction>
26 #include <QtGui/QMessageBox>
27 #include <QtGui/QMenuBar>
28 #include <QtGui/QTreeWidget>
29 #include <QtGui/QWizardPage>
30 #include <QtGui/QWizard>
31 #include <QtGui/QVBoxLayout>
32 #include <QtGui/QFileDialog>
33 #include <QtGui/QPushButton>
34 #include <QtGui/QLabel>
35 #include <QtGui/QGridLayout>
36 #include <QtGui/QLineEdit>
37 #include <QtGui/QToolBar>
38 #include <QtGui/QSplashScreen>
39 #include <QtGui/QListWidget>
40 #include <QtGui/QDialog>
41 #include <QtGui/QBitmap>
42 #include <QtGui/QPainter>
43 #include <QtGui/QTreeView>
44 #include <QToolButton>
45 #include <QDockWidget>
46 #include <QAtomicInt>
47 
48 #include <core/modules/PluginControl.h>
49 #include <core/modules/ProjectControl.h>
50 #include <core/modules/LanguageControl.h>
51 using namespace composer::core;
52 
53 #include <core/util/ComposerSettings.h>
54 using namespace composer::core::util;
55 
56 #include "PerspectiveManager.h"
57 #include "PreferencesDialog.h"
58 #include "PluginDetailsDialog.h"
59 #include "WelcomeWidget.h"
60 #include "AboutDialog.h"
61 #include "ComposerHelpWidget.h"
62 #include "ClickableDockWidget.h"
63 
64 #include "RunGingaConfig.h"
65 
66 #ifdef WITH_LIBSSH2
67 #include "RunRemoteGingaVM.h"
68 #endif
69 
70 using namespace composer::gui;
71 
72 namespace Ui {
73 class ComposerMainWindow;
74 }
75 
76 namespace composer {
77 namespace gui {
78 
79 class QThreadEx : public QThread
80 {
81 protected:
82  void run() { exec(); }
83 };
84 
90 class ComposerMainWindow : public QMainWindow {
91  Q_OBJECT
92 
93 private:
94  static const int maximumRecentProjectsSize = 10;
95 
96  Ui::ComposerMainWindow *ui;
97  QTabWidget *tabProjects;
100  QToolButton *tbPerspectiveDropList;
102  QMenu *menu_Perspective;
104  QToolButton *tbLanguageDropList;
106  QMenu *menu_Language;
108  QMap<QString, QMainWindow*> projectsWidgets;
110  QMap<QString, QDockWidget*> firstDock;
113  QList <QDockWidget*> allDocks;
115  QMutex allDocksMutex;
116 
117  QAction *fullScreenViewAct;
118  QAction *projectViewAct;
119  QAction *editPreferencesAct;
121  QAction *saveCurrentPluginsLayoutAct;
123  QAction *restorePluginsLayoutAct;
127  QListWidget *profilesExt;
129  QTreeWidget *pluginsExt;
132  QMap <QTreeWidgetItem*, IPluginFactory*> treeWidgetItem2plFactory;
133 
134  PreferencesDialog *preferences;
136  QDialog *aboutPluginsDialog;
137  QPushButton *detailsButton;
138 
139  QStringList extensions_paths;
141  WelcomeWidget *welcomeWidget;
143  PerspectiveManager *perspectiveManager;
144  PluginDetailsDialog *pluginDetailsDialog;
145 
146  QProcess localGingaProcess;
147 #ifdef WITH_LIBSSH2
148  QThreadEx runRemoteGingaVMThread;
149  RunRemoteGingaVMAction runRemoteGingaVMAction;
150  StopRemoteGingaVMAction stopRemoteGingaVMAction;
151 #endif
152  QProgressDialog *taskProgressBar;
153 
154  QTimer *autoSaveTimer; // auto save timer
155 
156  ComposerHelpWidget composerHelpWidget;
157 
158 private:
165  QString promptChooseExtDirectory();
169  void initModules();
173  void initGUI();
177  void createAboutPlugins();
181  void createStatusBar();
185  void createMenus();
189  void createActions();
193  void createFileSystem();
197  void readSettings();
201  void readExtensions();
207  void closeEvent(QCloseEvent *event);
211  void cleanUp();
212 
213  void updateRecentProjectsMenu(QStringList &recentProjects);
214 
215  void updateDockStyle(QDockWidget *titleBar, bool selected=false);
216 
217  void addButtonToDockTitleBar(QFrame *titleBar, QPushButton *button);
218 
219  void updateTabWithProject(int index, QString newLocation);
220 
221  QTranslator m_translator;
222  QTranslator m_translatorQt;
223  QString m_currLang;
224  QString m_langPath;
230  void loadLanguage(const QString& rLanguage);
234  void createLanguageMenu(void);
235 
236  void switchTranslator(QTranslator& translator, const QString& filename);
237 
238 protected:
243  void changeEvent(QEvent*);
244 
245  virtual void keyPressEvent(QKeyEvent *event);
246 
247 protected slots:
251  void slotLanguageChanged(QAction* action);
252 
256  void saveLoadPluginData(int);
257 
258 private slots:
262  void about();
266  void aboutPlugins();
270  void updateViewMenu();
274  void showEditPreferencesDialog();
279  void tabClosed(int index);
283  void closeCurrentTab();
287  void showCurrentWidgetFullScreen();
291  void closeAllFiles();
295  void startOpenProject(QString projectLoc);
296  void endOpenProject(QString projectLoc);
297 
298  void saveCurrentGeometryAsPerspective();
299  void restorePerspective();
300  void savePerspective(QString layoutName);
301  void saveDefaultPerspective(QString defaultPerspectiveName);
302  void restorePerspective(QString layoutName);
303 
305  void runNCL();
306  void stopNCL();
307  bool isRunningNCL();
308  void runOnLocalGinga();
309  void runOnRemoteGingaVM();
310  void runHasFinished();
311  void updateRunActions();
312 
313  void launchProjectWizard();
314  void addToRecentProjects(QString projectUrl);
315  void userPressedRecentProject(QString src);
316  void userPressedRecentProject();
317  void clearRecentProjects(void);
318  void importFromDocument();
322  void selectedAboutCurrentPluginFactory();
326  void showPluginDetails();
327 
328  void updateMenuPerspectives();
329  void updateMenuLanguages();
330 
331  void restorePerspectiveFromMenu();
332 
333  void currentTabChanged(int n);
334 
335  void focusChanged(QWidget *old, QWidget *now);
336 
337  void setProjectDirty(QString location, bool isDirty);
338 
339  void gotoNCLClubWebsite();
340 
341  void autoSaveCurrentProjects();
342 
343  // TODO: Remove this function from here.
344  void updateLastFileDialogPath(QString filepath);
345 
346  // TODO: Remove this function from here.
347  QString getLastFileDialogPath();
348 
349  void addDefaultStructureToProject(Project *project,
350  bool shouldCopyDefaultConnBase = true,
351  bool shouldCreateADefaultRegion = true,
352  bool save = true);
353  void on_actionReport_Bug_triggered();
354 
355 public:
361  explicit ComposerMainWindow(QWidget *parent = 0);
362 
369  void init(const QApplication &app);
374 
375 public slots:
381  void errorDialog(QString);
390  void addPluginWidget(IPluginFactory *fac, IPlugin *plugin,
391  Project *project, int n);
397  void onOpenProjectTab(QString location);
398 
402  void saveCurrentProject();
406  void saveAsCurrentProject();
407 
411  void openProject();
412 
417  void checkTemporaryFileLastModified(QString filename);
418 
423  bool removeTemporaryFile(QString location);
424 
428  bool showHelp();
429 
430  void undo();
431  void redo();
432 
433  void openProjects(const QStringList &projects);
434 
435 signals:
440  void writeSettings();
441 };
442 
443 } } //end namespace
444 
445 #endif // COMPOSERMAINWINDOW_H