1 // Copyright (C) 2017-2023 CEA, EDF
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__
24 #include "RemoteFileBrowser.h"
31 class AnotherTreeView;
32 class QMachineBrowser;
33 class QRemoteFileSystemModel;
34 class TopDirDataStructure;
36 class QREMOTEFILEBROWSER_EXPORT LoadingThread : public QThread
40 LoadingThread(QThread *th, QMachineBrowser *mb):_fatherThread(th),_mb(mb),_model(nullptr) { }
41 void setGeneratedModel(QRemoteFileSystemModel *model) { _model=model; }
42 QRemoteFileSystemModel *generatedModel() const { return _model; }
44 void letsGenerateModel(TopDirDataStructure *fds);
48 QThread *_fatherThread;
50 QRemoteFileSystemModel *_model;
53 class QREMOTEFILEBROWSER_EXPORT QRemoteFileBrowser : public QWidget
57 QRemoteFileBrowser(QWidget *parent);
58 QMachineBrowser *machineBrower() const { return _mb; }
60 void onLocationChanged();
61 void locationHasBeenChanged();
63 AnotherTreeView *_treeView;
67 class QREMOTEFILEBROWSER_EXPORT QRemoteFileTransfer : public QWidget
70 QRemoteFileTransfer(QWidget *parent=0);
72 QRemoteFileBrowser *_left;
73 QRemoteFileBrowser *_right;
76 class DirDataStructure;
77 class TopDirDataStructure;
79 class QREMOTEFILEBROWSER_EXPORT DataStructure : public QObject
83 DataStructure(QObject *parent, const QString& name):QObject(parent),_name(name),_selected(false) { }
84 void select() { _selected=true; }
85 void unselect() { _selected=false; }
86 bool isSelected() const { return _selected; }
87 virtual bool isFile() const = 0;
88 virtual QString nameOnDrop() const = 0;
89 const DirDataStructure *getDirParent() const;
90 bool isRoot() const { return getDirParent()==NULL; }
91 const TopDirDataStructure *getRoot() const;
92 std::vector<const DataStructure *> getItermediateElts(const TopDirDataStructure *tpds) const;
93 virtual int size() const = 0;
94 QString entryForRSyncSrc() const;
95 virtual QString entryForRSyncDest() const = 0;
97 const QString& fullName() const { return _name; }
98 void removeFileArgs(QString& prg, QStringList& args) const;
104 class QREMOTEFILEBROWSER_EXPORT FileDataStructure : public DataStructure
107 FileDataStructure(DirDataStructure *dds, const QString& name);
108 bool isFile() const { return true; }
109 int size() const { return 0; }
110 QString entryForRSyncDest() const;
111 QString nameOnDrop() const;
114 class QREMOTEFILEBROWSER_EXPORT DirDataStructure : public DataStructure
117 DirDataStructure(DirDataStructure *dds, const QString& name):DataStructure(dds,name),_is_loaded(false),_is_expanded(false) { }
118 DirDataStructure(QObject *dds, const QString& name):DataStructure(dds,name),_is_loaded(false) { }
119 bool isFile() const { return false; }
120 int size() const { load(); return children().size(); }
121 QString entryForRSyncDest() const;
122 QString nameOnDrop() const { return name(); }
123 const DataStructure *operator[](int pos) const;
124 int posOf(const DataStructure *ds) const;
126 void markAsLoaded() const { _is_loaded=true; }
127 void setExpanded(bool status) { _is_expanded=status; }
128 bool isExpanded() const { return _is_expanded; }
130 mutable bool _is_loaded;
131 mutable bool _is_expanded;
136 class QREMOTEFILEBROWSER_EXPORT TopDirDataStructure : public DirDataStructure
139 TopDirDataStructure(QObject *dds, FileLoader *fl);
140 virtual ~TopDirDataStructure();
141 FileLoader *getLoader() const { return _fl; }
142 bool isOK() const { return _isOK; }
143 QString entryForRSync(const QString& fn) const;
144 QString getMachine() const;
145 void removeFileArgsImpl(const QString& filePath, QString& prg, QStringList& args) const;
151 class QRemoteFileSystemModel;
153 class QREMOTEFILEBROWSER_EXPORT MyTreeView : public QTreeView
157 MyTreeView(QWidget *parent);
158 void mousePressEvent(QMouseEvent *event);
159 void mouseReleaseEvent(QMouseEvent *event);
160 void mouseMoveEvent(QMouseEvent *event);
161 void keyPressEvent(QKeyEvent *event);
162 void dragEnterEvent(QDragEnterEvent *event);
163 void dragMoveEvent(QDragMoveEvent *event);
164 void dragLeaveEvent(QDragLeaveEvent *event);
165 void dropEvent(QDropEvent *event);
166 QRemoteFileSystemModel *zeModel();
167 void emitResetModel();
169 void itemExpanded(const QModelIndex &index);
170 void itemCollapsed(const QModelIndex &index);
172 void somethingChangedDueToFileModif();
174 void itemExpandedStatus(const QModelIndex &index, bool status);
175 void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const;
176 void paintEvent(QPaintEvent *event);
179 // during drag drop _sel is the element under the mouse on the drop site
181 // during drag drop _slider_pos is the pos of vertical slider on drop site
185 class AnotherTreeView;
187 class QREMOTEFILEBROWSER_EXPORT AnotherTreeViewPainter
190 virtual void paint(AnotherTreeView *atv, QPaintEvent *event) const = 0;
193 class QREMOTEFILEBROWSER_EXPORT AnotherTreeViewWaitPainter : public AnotherTreeViewPainter
196 void paint(AnotherTreeView *atv, QPaintEvent *event) const;
199 class QREMOTEFILEBROWSER_EXPORT AnotherTreeViewNothingPainter : public AnotherTreeViewPainter
202 void paint(AnotherTreeView *atv, QPaintEvent *event) const;
205 class QREMOTEFILEBROWSER_EXPORT AnotherTreeView : public QWidget
209 AnotherTreeView(QWidget *parent);
210 void generateModel(QMachineBrowser *mb);
211 QSize sizeHint() const;
212 QSize minimumSizeHint() const;
213 int getAngle() const { return _angle; }
216 void goGenerate(TopDirDataStructure *fds);
217 void modelHasBeenGenerated();
219 void modelHasBeenGeneratedSignal(bool isOK);
220 void somethingChangedDueToFileModif();
222 void paintEvent(QPaintEvent *event);
223 void timerEvent(QTimerEvent *e);
227 AnotherTreeViewPainter *_painter;
232 class QREMOTEFILEBROWSER_EXPORT FileLoader
235 FileLoader(const QString& dirName):_dirName(dirName) { }
237 QString getDirName() const { return _dirName; }
238 virtual bool load(DirDataStructure *parent) const = 0;
239 virtual QString prettyPrint() const = 0;
240 virtual QString entryForRSync(const QString& fn) const = 0;
241 virtual QString getMachine() const = 0;
242 virtual void removeFileArgs(const QString& filePath, QString& prg, QStringList& args) const = 0;
243 virtual ~FileLoader() { }
248 class QREMOTEFILEBROWSER_EXPORT LocalFileLoader : public FileLoader
251 LocalFileLoader(const QString& dirName):FileLoader(dirName) { }
252 bool load(DirDataStructure *parent) const;
253 void fillArgs(const QString& dn, QString& prg, QStringList& args) const;
254 QString prettyPrint() const;
255 QString entryForRSync(const QString& fn) const;
256 QString getMachine() const;
257 void removeFileArgs(const QString& filePath, QString& prg, QStringList& args) const;
260 class QREMOTEFILEBROWSER_EXPORT RemoteFileLoader : public FileLoader
263 RemoteFileLoader(const QString& machine,const QString& dirName):FileLoader(dirName),_machine(machine) { }
264 bool load(DirDataStructure *parent) const;
265 void fillArgs(const QString& dn, QString& prg, QStringList& args) const;
266 QString prettyPrint() const;
267 QString entryForRSync(const QString& fn) const;
268 QString getMachine() const;
269 void removeFileArgs(const QString& filePath, QString& prg, QStringList& args) const;
274 class QREMOTEFILEBROWSER_EXPORT SelectionMimeData : public QMimeData
278 SelectionMimeData(const QModelIndexList& los):_los(los) { }
279 const QModelIndexList& getSelection() const { return _los; }
281 QModelIndexList _los;
284 class QREMOTEFILEBROWSER_EXPORT QRemoteFileSystemModel : public QAbstractItemModel
288 QRemoteFileSystemModel(QObject *parent, FileLoader *fl);
289 QRemoteFileSystemModel(QObject *parent, TopDirDataStructure *fds);
290 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
291 QModelIndex parent(const QModelIndex&) const;
292 QModelIndex index(int, int, const QModelIndex&) const;
293 int rowCount(const QModelIndex&) const;
294 int columnCount(const QModelIndex&) const;
295 QVariant data(const QModelIndex&, int) const;
296 void emitResetModel();
297 FileLoader *getLoader() const { return _fds->getLoader(); }
298 bool isOK() const { return _fds->isOK(); }
299 QString getMachine() const { return _fds->getMachine(); }
301 TopDirDataStructure *_fds;