1 // Copyright (C) 2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony GEAY (EDF R&D)
21 #ifndef __QREMOTEFILEBROWSER__
22 #define __QREMOTEFILEBROWSER__
29 class AnotherTreeView;
30 class QMachineBrowser;
31 class QRemoteFileSystemModel;
32 class TopDirDataStructure;
34 class LoadingThread : public QThread
38 LoadingThread(QThread *th, QMachineBrowser *mb):_fatherThread(th),_mb(mb),_model(nullptr) { }
39 void setGeneratedModel(QRemoteFileSystemModel *model) { _model=model; }
40 QRemoteFileSystemModel *generatedModel() const { return _model; }
42 void letsGenerateModel(TopDirDataStructure *fds);
46 QThread *_fatherThread;
48 QRemoteFileSystemModel *_model;
51 class QRemoteFileBrowser : public QWidget
55 QRemoteFileBrowser(QWidget *parent);
56 QMachineBrowser *machineBrower() const { return _mb; }
58 void onLocationChanged();
59 void locationHasBeenChanged();
61 AnotherTreeView *_treeView;
65 class QRemoteFileTransfer : public QWidget
68 QRemoteFileTransfer(QWidget *parent=0);
70 QRemoteFileBrowser *_left;
71 QRemoteFileBrowser *_right;
74 class DirDataStructure;
75 class TopDirDataStructure;
77 class DataStructure : public QObject
81 DataStructure(QObject *parent, const QString& name):QObject(parent),_name(name),_selected(false) { }
82 void select() { _selected=true; }
83 void unselect() { _selected=false; }
84 bool isSelected() const { return _selected; }
85 virtual bool isFile() const = 0;
86 virtual QString nameOnDrop() const = 0;
87 const DirDataStructure *getDirParent() const;
88 bool isRoot() const { return getDirParent()==NULL; }
89 const TopDirDataStructure *getRoot() const;
90 std::vector<const DataStructure *> getItermediateElts(const TopDirDataStructure *tpds) const;
91 virtual int size() const = 0;
92 QString entryForRSyncSrc() const;
93 virtual QString entryForRSyncDest() const = 0;
95 const QString& fullName() const { return _name; }
96 void removeFileArgs(QString& prg, QStringList& args) const;
102 class FileDataStructure : public DataStructure
105 FileDataStructure(DirDataStructure *dds, const QString& name);
106 bool isFile() const { return true; }
107 int size() const { return 0; }
108 QString entryForRSyncDest() const;
109 QString nameOnDrop() const;
112 class DirDataStructure : public DataStructure
115 DirDataStructure(DirDataStructure *dds, const QString& name):DataStructure(dds,name),_is_loaded(false),_is_expanded(false) { }
116 DirDataStructure(QObject *dds, const QString& name):DataStructure(dds,name),_is_loaded(false) { }
117 bool isFile() const { return false; }
118 int size() const { load(); return children().size(); }
119 QString entryForRSyncDest() const;
120 QString nameOnDrop() const { return name(); }
121 const DataStructure *operator[](int pos) const;
122 int posOf(const DataStructure *ds) const;
124 void markAsLoaded() const { _is_loaded=true; }
125 void setExpanded(bool status) { _is_expanded=status; }
126 bool isExpanded() const { return _is_expanded; }
128 mutable bool _is_loaded;
129 mutable bool _is_expanded;
134 class TopDirDataStructure : public DirDataStructure
137 TopDirDataStructure(QObject *dds, FileLoader *fl);
138 virtual ~TopDirDataStructure();
139 FileLoader *getLoader() const { return _fl; }
140 bool isOK() const { return _isOK; }
141 QString entryForRSync(const QString& fn) const;
142 QString getMachine() const;
143 void removeFileArgsImpl(const QString& filePath, QString& prg, QStringList& args) const;
149 class QRemoteFileSystemModel;
151 class MyTreeView : public QTreeView
155 MyTreeView(QWidget *parent);
156 void mousePressEvent(QMouseEvent *event);
157 void mouseReleaseEvent(QMouseEvent *event);
158 void mouseMoveEvent(QMouseEvent *event);
159 void keyPressEvent(QKeyEvent *event);
160 void dragEnterEvent(QDragEnterEvent *event);
161 void dragMoveEvent(QDragMoveEvent *event);
162 void dragLeaveEvent(QDragLeaveEvent *event);
163 void dropEvent(QDropEvent *event);
164 QRemoteFileSystemModel *zeModel();
165 void emitResetModel();
167 void itemExpanded(const QModelIndex &index);
168 void itemCollapsed(const QModelIndex &index);
170 void somethingChangedDueToFileModif();
172 void itemExpandedStatus(const QModelIndex &index, bool status);
173 void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const;
174 void paintEvent(QPaintEvent *event);
177 // during drag drop _sel is the element under the mouse on the drop site
179 // during drag drop _slider_pos is the pos of vertical slider on drop site
183 class AnotherTreeView;
185 class AnotherTreeViewPainter
188 virtual void paint(AnotherTreeView *atv, QPaintEvent *event) const = 0;
191 class AnotherTreeViewWaitPainter : public AnotherTreeViewPainter
194 void paint(AnotherTreeView *atv, QPaintEvent *event) const;
197 class AnotherTreeViewNothingPainter : public AnotherTreeViewPainter
200 void paint(AnotherTreeView *atv, QPaintEvent *event) const;
203 class AnotherTreeView : public QWidget
207 AnotherTreeView(QWidget *parent);
208 void generateModel(QMachineBrowser *mb);
209 QSize sizeHint() const;
210 QSize minimumSizeHint() const;
211 int getAngle() const { return _angle; }
214 void goGenerate(TopDirDataStructure *fds);
215 void modelHasBeenGenerated();
217 void modelHasBeenGeneratedSignal(bool isOK);
218 void somethingChangedDueToFileModif();
220 void paintEvent(QPaintEvent *event);
221 void timerEvent(QTimerEvent *e);
225 AnotherTreeViewPainter *_painter;
233 FileLoader(const QString& dirName):_dirName(dirName) { }
235 QString getDirName() const { return _dirName; }
236 virtual bool load(DirDataStructure *parent) const = 0;
237 virtual QString prettyPrint() const = 0;
238 virtual QString entryForRSync(const QString& fn) const = 0;
239 virtual QString getMachine() const = 0;
240 virtual void removeFileArgs(const QString& filePath, QString& prg, QStringList& args) const = 0;
241 virtual ~FileLoader() { }
246 class LocalFileLoader : public FileLoader
249 LocalFileLoader(const QString& dirName):FileLoader(dirName) { }
250 bool load(DirDataStructure *parent) const;
251 void fillArgs(const QString& dn, QString& prg, QStringList& args) const;
252 QString prettyPrint() const;
253 QString entryForRSync(const QString& fn) const;
254 QString getMachine() const;
255 void removeFileArgs(const QString& filePath, QString& prg, QStringList& args) const;
258 class RemoteFileLoader : public FileLoader
261 RemoteFileLoader(const QString& machine,const QString& dirName):FileLoader(dirName),_machine(machine) { }
262 bool load(DirDataStructure *parent) const;
263 void fillArgs(const QString& dn, QString& prg, QStringList& args) const;
264 QString prettyPrint() const;
265 QString entryForRSync(const QString& fn) const;
266 QString getMachine() const;
267 void removeFileArgs(const QString& filePath, QString& prg, QStringList& args) const;
272 class SelectionMimeData : public QMimeData
276 SelectionMimeData(const QModelIndexList& los):_los(los) { }
277 const QModelIndexList& getSelection() const { return _los; }
279 QModelIndexList _los;
282 class QRemoteFileSystemModel : public QAbstractItemModel
286 QRemoteFileSystemModel(QObject *parent, FileLoader *fl);
287 QRemoteFileSystemModel(QObject *parent, TopDirDataStructure *fds);
288 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
289 QModelIndex parent(const QModelIndex&) const;
290 QModelIndex index(int, int, const QModelIndex&) const;
291 int rowCount(const QModelIndex&) const;
292 int columnCount(const QModelIndex&) const;
293 QVariant data(const QModelIndex&, int) const;
294 void emitResetModel();
295 FileLoader *getLoader() const { return _fds->getLoader(); }
296 bool isOK() const { return _fds->isOK(); }
297 QString getMachine() const { return _fds->getMachine(); }
299 TopDirDataStructure *_fds;