ZIMA CAD Parts
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
basedatasource.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 BASEDATASOURCE_H
22 #define BASEDATASOURCE_H
23 
24 #include <QObject>
25 #include <QStringList>
26 #include <QUrl>
27 #include <QIcon>
28 #include <QApplication>
29 
30 #include "item.h"
31 
32 #define TECHSPEC_DIR "0000-index"
33 #define METADATA_FILE "metadata.ini"
34 #define LOGO_FILE "logo.png"
35 #define LOGO_TEXT_FILE "logo-text.png"
36 
37 class QListWidgetItem;
38 class Item;
39 class Thumbnail;
40 struct File;
41 
43  LOCAL=0,
44  FTP,
46 };
47 
48 
49 
50 class BaseDataSource : public QObject
51 {
52  Q_OBJECT
53 public:
54  enum Operation {
58  };
59 
60  struct Error {
62  QString error;
63 
64  Error(File *f, QString s) : file(f), error(s) {}
65  };
66 
67  explicit BaseDataSource(QObject *parent = 0);
68  Item *getRootItem();
69  virtual QString internalName() = 0;
70  virtual QIcon itemIcon(Item *item);
71  virtual QIcon dataSourceIcon();
72  virtual QString pathToDataRoot() = 0;
73  virtual QString getTechSpecPathForItem(Item *item) = 0;
74  virtual QString getPathForItem(Item *item) = 0;
75  virtual QString getRelativePathForItem(Item *item) = 0;
76  virtual QString name() = 0;
77 
79  QString label;
81 public slots:
82  virtual void loadRootItem(Item *item) = 0;
83  virtual void loadDirectory(Item* item) = 0;
84  virtual void sendTechSpecUrl(Item* item);
85  virtual void deleteFiles(QList<File*> files) = 0;
86  virtual void addFileToDownload(File *f) = 0;
87  virtual void downloadFiles(QList<File*> files, QString dir) = 0;
88  virtual void downloadFile(File* file) = 0;
89  virtual void resumeDownload() = 0;
90  virtual void abort() = 0;
91  virtual void deleteDownloadQueue();
92  void assignThumbnailsToFiles(Item *item, QList<Thumbnail*> thumbnails = QList<Thumbnail*>());
93  void determineFileVersions(Item *item);
94  void retranslate(QString lang = QString());
95  virtual void assignTechSpecUrlToItem(QString url, Item *item, QString lang, bool overwrite = false) = 0;
96  virtual void assignPartsIndexUrlToItem(QString url, Item *item, QString lang, bool overwrite = false) = 0;
97 protected:
98  virtual void loadItemLogo(Item *item) = 0;
99  void createMetadata(Item *item);
100 
102 
103 signals:
104  //void partDownloaded(Item*);
105  void itemInserted(Item*);
106  void updateAvailable(Item*);
107  void loadingItem(Item*);
108  void itemLoaded(Item*);
109  void allItemsLoaded();
110  void fileProgress(File*);
111  void fileDownloaded(File*);
112  void filesDownloaded(); //TODO: identify this somehow
113  void thumbnailLoaded(File*);
114  void statusUpdated(QString);
115  void techSpecAvailable(QUrl);
116  void metadataInclude(Item *item, QString path);
117  void metadataIncludeCancelled(Item *item);
118  void metadataReady(Item*);
119  void errorOccured(const QString &error);
123  void filesDeleted();
124 };
125 
126 
127 typedef QList<BaseDataSource*> DataSourceList;
128 
129 #endif // BASEDATASOURCE_H
void itemLoaded(Item *)
virtual QString getPathForItem(Item *item)=0
virtual void resumeDownload()=0
void fileProgress(File *)
void fileError(BaseDataSource::Operation op, BaseDataSource::Error *err)
void filesDeleted()
Definition: basedatasource.h:55
virtual QIcon itemIcon(Item *item)
Definition: basedatasource.cpp:39
void techSpecsIndexAlreadyExists(Item *)
virtual void assignTechSpecUrlToItem(QString url, Item *item, QString lang, bool overwrite=false)=0
virtual QString internalName()=0
QString label
Definition: basedatasource.h:79
void errorOccured(const QString &error)
Definition: basedatasource.h:56
virtual void deleteFiles(QList< File * > files)=0
void createMetadata(Item *item)
Definition: basedatasource.cpp:146
void thumbnailLoaded(File *)
Item * getRootItem()
Definition: basedatasource.cpp:34
void metadataIncludeCancelled(Item *item)
void loadingItem(Item *)
virtual void loadDirectory(Item *item)=0
Definition: basedatasource.h:60
Definition: basedatasource.h:44
void allItemsLoaded()
virtual QString getTechSpecPathForItem(Item *item)=0
Operation
Definition: basedatasource.h:54
Definition: item.h:130
void metadataReady(Item *)
File * file
Definition: basedatasource.h:61
Error(File *f, QString s)
Definition: basedatasource.h:64
virtual void abort()=0
virtual void addFileToDownload(File *f)=0
virtual QString name()=0
void techSpecAvailable(QUrl)
Definition: basedatasource.h:50
BaseDataSource(QObject *parent=0)
Definition: basedatasource.cpp:27
virtual void loadRootItem(Item *item)=0
Definition: item.h:41
void fileDownloaded(File *)
QString currentMetadataLang
Definition: basedatasource.h:101
void determineFileVersions(Item *item)
Definition: basedatasource.cpp:87
DataSources dataSource
Definition: basedatasource.h:80
Definition: thumbnail.h:6
virtual void loadItemLogo(Item *item)=0
virtual QString getRelativePathForItem(Item *item)=0
void updateAvailable(Item *)
virtual QIcon dataSourceIcon()
Definition: basedatasource.cpp:46
Definition: basedatasource.h:57
Definition: basedatasource.h:43
void partsIndexAlreadyExists(Item *)
virtual void deleteDownloadQueue()
Definition: basedatasource.cpp:51
void metadataInclude(Item *item, QString path)
Item * rootItem
Definition: basedatasource.h:78
void statusUpdated(QString)
virtual void sendTechSpecUrl(Item *item)
Definition: basedatasource.cpp:106
virtual void downloadFiles(QList< File * > files, QString dir)=0
DataSources
Definition: basedatasource.h:42
virtual void assignPartsIndexUrlToItem(QString url, Item *item, QString lang, bool overwrite=false)=0
virtual QString pathToDataRoot()=0
void filesDownloaded()
void retranslate(QString lang=QString())
Definition: basedatasource.cpp:138
void assignThumbnailsToFiles(Item *item, QList< Thumbnail * > thumbnails=QList< Thumbnail * >())
Definition: basedatasource.cpp:56
virtual void downloadFile(File *file)=0
QList< BaseDataSource * > DataSourceList
Definition: basedatasource.h:127
void itemInserted(Item *)
QString error
Definition: basedatasource.h:62
Definition: basedatasource.h:45