ZIMA CAD Parts
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
serversmodel.h
Go to the documentation of this file.
1 /*
2  ZIMA-CAD-Parts
3  http://www.zima-construction.cz/software/ZIMA-Parts
4 
5  Copyright (C) 2011-2012 Jakub Skokan <aither@havefun.cz>
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SERVERSMODEL_H
22 #define SERVERSMODEL_H
23 
24 #include <QAbstractItemModel>
25 #include <QIcon>
26 #include <QList>
27 #include <QKeyEvent>
28 
29 #include "item.h"
30 #include "basedatasource.h"
31 #include "treeautodescent.h"
32 #include "transferhandler.h"
33 
34 class DownloadModel;
35 
36 class ServersModel : public QAbstractItemModel, public TransferHandler
37 {
38  Q_OBJECT
39 
40 public:
41  ServersModel(BaseDataSource *ds, QObject *parent = 0);
42  ~ServersModel();
43 
44  bool canFetchMore(const QModelIndex &parent) const;
45  void fetchMore(const QModelIndex &parent);
46 // bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
47  int columnCount(const QModelIndex &parent = QModelIndex()) const;
48  int rowCount(const QModelIndex &parent = QModelIndex()) const;
49 
50  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
51  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
52  QVariant data(const QModelIndex &index, int role) const;
53  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
54  QModelIndex parent(const QModelIndex &index) const;
55  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
56  Qt::ItemFlags flags(const QModelIndex &index) const;
57 
59  return m_datasource;
60  }
61 
62  QString translateDataSourceNameToPath(QString name);
63  QList<BaseDataSource::Error*> fileErrors(BaseDataSource::Operation op);
66 
69  return m_dataSourcerootItem;
70  }
71 
72  void stopDownload();
73  void clearQueue();
74 
76  return m_downloadModel;
77  }
78 
79 public slots:
80  void refresh(Item* item);
81  void clear();
82  void loadItem(Item *item);
83  void requestTechSpecs(const QModelIndex &index);
84  void requestTechSpecs(Item *item);
85  void deleteFiles();
86  void downloadFiles(QString dir);
87  void resumeDownload();
88  void uncheckAll(Item *item = 0);
89  void deleteDownloadQueue();
90 #if 0
91  void saveQueue(QSettings *settings);
92  int loadQueue(QSettings *settings);
93 #endif
94  void retranslateMetadata(Item *item = 0);
95  void abort();
96  void descentTo(QString path, Item *item = 0);
98 
99 protected:
100  QList<File*> getCheckedFiles(Item *item);
101 
102 protected slots:
103  void allPartsDownloaded(Item* item);
104 
105 private:
106  QIcon dirIcon, serverIcon;
107  BaseDataSource* m_datasource;
108  Item *m_dataSourcerootItem;
109  Item *m_rootItem;
110  Item *m_lastTechSpecRequest;
111  QList<BaseDataSource::Error*> m_fileErrors[BaseDataSource::OperationCount];
112  int dsDeleted;
113  QList<TreeAutoDescent*> autoDescents;
114  QHash<TreeAutoDescent*, Item*> metadataIncludeHash;
115  DownloadModel *m_downloadModel;
116 
117 private slots:
118  void dataSourceFinishedDownloading();
119  void dataSourceFinishedDeleting();
120  void metadataReady(Item *item);
121  void newItem(Item *item);
122  void itemUpdated(Item *item);
123  void forwardAutoDescentProgress(TreeAutoDescent *descent, Item *item);
124  void forwardAutoDescentCompleted(TreeAutoDescent *descent, Item *item);
125  void forwardAutoDescentNotFound(TreeAutoDescent *descent);
126  void metadataInclude(Item *item, QString path);
127  void metadataIncludeCancel(Item *item);
128 
129 signals:
130  void loadingItem(Item*);
131  void itemLoaded(const QModelIndex&);
132  void allItemsLoaded();
133  void techSpecAvailable(QUrl);
134  void statusUpdated(QString);
135  void errorOccured(const QString &error);
136  void fileProgress(File*);
137  void fileDownloaded(File*);
138  void filesDownloaded();
139  void queueChanged();
140  void autoDescentProgress(const QModelIndex&);
141  void autoDescentCompleted(const QModelIndex&);
142  void autoDescentNotFound();
145  void filesDeleted();
146 };
147 
148 #endif // SERVERSMODEL_H
bool hasErrors(BaseDataSource::Operation op)
Definition: serversmodel.cpp:672
void requestTechSpecs(const QModelIndex &index)
Definition: serversmodel.cpp:331
void fileProgress(File *)
void downloadFiles(QString dir)
Definition: serversmodel.cpp:391
QModelIndex parent(const QModelIndex &index) const
Definition: serversmodel.cpp:149
QList< BaseDataSource::Error * > fileErrors(BaseDataSource::Operation op)
Definition: serversmodel.cpp:667
void autoDescentProgress(const QModelIndex &)
void filesDownloaded()
void fetchMore(const QModelIndex &parent)
Definition: serversmodel.cpp:105
void descentTo(QString path, Item *item=0)
Definition: serversmodel.cpp:648
void refresh(Item *item)
Definition: serversmodel.cpp:303
void allItemsLoaded()
Definition: treeautodescent.h:8
void deleteFiles()
Definition: serversmodel.cpp:380
void techSpecsIndexAlreadyExists(Item *)
QVariant data(const QModelIndex &index, int role) const
Definition: serversmodel.cpp:212
void stopDownload()
Definition: serversmodel.cpp:682
Definition: basedatasource.h:60
ServersModel(BaseDataSource *ds, QObject *parent=0)
Definition: serversmodel.cpp:30
void fileDownloaded(File *)
void deleteDownloadQueue()
Definition: serversmodel.cpp:440
void uncheckAll(Item *item=0)
Definition: serversmodel.cpp:416
Operation
Definition: basedatasource.h:54
Definition: item.h:130
Item * lastTechSpecRequest()
Definition: serversmodel.cpp:677
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: serversmodel.cpp:166
void itemLoaded(const QModelIndex &)
BaseDataSource * dataSource()
Definition: serversmodel.h:58
void abort()
Definition: serversmodel.cpp:643
DownloadModel * downloadModel()
Definition: serversmodel.h:75
Definition: transferhandler.h:4
void queueChanged()
Definition: basedatasource.h:50
~ServersModel()
Definition: serversmodel.cpp:89
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: serversmodel.cpp:191
Definition: item.h:41
void retranslateMetadata(Item *item=0)
Definition: serversmodel.cpp:521
void loadingItem(Item *)
void clearQueue()
Definition: serversmodel.cpp:687
void resumeDownload()
Definition: serversmodel.cpp:410
void catchFileError(BaseDataSource::Operation op, BaseDataSource::Error *err)
Definition: serversmodel.cpp:693
void techSpecAvailable(QUrl)
void partsIndexAlreadyExists(Item *)
void allPartsDownloaded(Item *item)
Definition: serversmodel.cpp:278
void clear()
Definition: serversmodel.cpp:430
Definition: downloadmodel.h:39
void errorOccured(const QString &error)
QList< File * > getCheckedFiles(Item *item)
Definition: serversmodel.cpp:366
Definition: serversmodel.h:36
void autoDescentNotFound()
Definition: basedatasource.h:57
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Definition: serversmodel.cpp:203
QString translateDataSourceNameToPath(QString name)
Definition: serversmodel.cpp:271
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: serversmodel.cpp:125
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: serversmodel.cpp:258
Item * rootItem()
Definition: serversmodel.h:68
void autoDescentCompleted(const QModelIndex &)
bool canFetchMore(const QModelIndex &parent) const
Definition: serversmodel.cpp:97
void statusUpdated(QString)
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: serversmodel.cpp:266
void loadItem(Item *item)
Definition: serversmodel.cpp:346
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: serversmodel.cpp:143
void filesDeleted()