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