Salome HOME
Copyright update 2022
[modules/gui.git] / tools / RemoteFileBrowser / QRemoteCopyWidget.h
1 // Copyright (C) 2017-2022  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony GEAY (EDF R&D)
20
21 #ifndef __QREMOTECOPYWIDGET__
22 #define __QREMOTECOPYWIDGET__
23
24 #include "RemoteFileBrowser.h"
25
26 #include "QDialog"
27 #include "QMutex"
28 #include "QThread"
29 #include "QTreeView"
30 #include "QTableView"
31 #include "QItemDelegate"
32 #include "QPointer"
33 #include "QProcess"
34
35 class QRemoteFileSystemModel;
36 class QFilesDirsCopierModel;
37 class DataStructure;
38 class QTableView;
39
40 void PerformCopy(QWidget *parent, QRemoteFileSystemModel *srcModel, const QModelIndexList& srcSelectedFiles, DataStructure *ds);
41
42 class QREMOTEFILEBROWSER_EXPORT CopierThread : public QThread
43 {
44 public:
45   CopierThread(QObject *parent, QFilesDirsCopierModel *model):QThread(parent),_model(model) { }
46   void stopRequested();
47 protected:
48   void run();
49 private:
50   QFilesDirsCopierModel *_model;
51 };
52
53 class QREMOTEFILEBROWSER_EXPORT QFilesDirsCopierModel : public QAbstractListModel
54 {
55   Q_OBJECT
56 public:
57   QFilesDirsCopierModel(QObject *parent, const QList<const DataStructure *>& srcFiles, DataStructure *destLoc);
58   int nbOfRows() const;
59   int rowCount(const QModelIndex&) const;
60   int columnCount(const QModelIndex&) const;
61   QVariant data(const QModelIndex&, int) const;
62   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
63   const QString& getErrorStr() const { return _error; }
64   int getProgressOf(int srcFileId) const;
65   QString getFullNameOf(int srcFileId) const;
66   QString getNameOf(int srcFileId) const;
67   QString getPrettyText(int srcFileId) const;
68   QSize sizeHint() const;
69   //
70   void launchCopy();
71   void stopCurrentCopy();
72 public slots:
73   void newOutputAvailable();
74 private:
75   void fillArgsForRSync(const DataStructure *srcFile, QStringList& args) const;
76 private:
77   QList<const DataStructure *> _srcFiles;
78   //
79   mutable QMutex _mutOnProc;
80   volatile int _currentElt;
81   QPointer<QProcess> _curProc;
82   QString _error;
83   //
84   QVector<int> _progress;
85   DataStructure *_destLoc;
86 public:
87   static constexpr int PROGRESS_STATUS_START=-1;
88   static constexpr int PROGRESS_STATUS_OVER=101;
89   static const char ATOMIC_STOP_MSG[];
90 };
91
92 class QREMOTEFILEBROWSER_EXPORT ProgressDelegate : public QItemDelegate
93 {
94 public:
95   ProgressDelegate(QObject *parent, QFilesDirsCopierModel *model):QItemDelegate(parent),_model(model) { }
96   void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
97 private:
98   QFilesDirsCopierModel *_model;
99 };
100
101 class QREMOTEFILEBROWSER_EXPORT CopierTableView : public QTableView
102 {
103 public:
104   CopierTableView(QWidget *parent);
105   int sizeHintForColumn(int column) const;
106   int sizeHintForRow(int row) const;
107   void resizeEvent(QResizeEvent *event);
108   QSize sizeHint() const;
109 };
110    
111 class QREMOTEFILEBROWSER_EXPORT FilesDirsCopier : public QDialog
112 {
113   Q_OBJECT
114 public:
115   FilesDirsCopier(QWidget *parent, const QList<const DataStructure *>& srcFiles, DataStructure *destLoc);
116 public slots:
117   void cancelRequested();
118   void myAccept(bool);
119   int exec();
120   const QString& getErrorStr() const { return _model->getErrorStr(); }
121 signals:
122   void myAcceptSignal(bool);
123 private:
124   CopierTableView *_table;
125   QPushButton *_cancel;
126   CopierThread *_th;
127   QFilesDirsCopierModel *_model;
128 };
129
130 #endif