• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.14
  • kdenetwork
  • kget
  • core
filemodel.h
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #ifndef FILEMODEL_H
21 #define FILEMODEL_H
22 
23 #include "kget_export.h"
24 #include "transfer.h"
25 
26 #include <KUrl>
27 
28 #include <QAbstractItemModel>
29 #include <QList>
30 #include <QVariant>
31 
32 #include <kio/global.h>
33 #include <KIcon>
34 
35 class FileModel;
36 
37 class KGET_EXPORT FileItem
38 {
39  public:
40  explicit FileItem(const QString &name, FileItem *parent = 0);
41  ~FileItem();
42 
43  enum DataType
44  {
45  File = 0,
46  Status,
47  Size,
48  ChecksumVerified,
49  SignatureVerified
50  };
51 
52  void appendChild(FileItem *child);
53 
54  FileItem *child(int row);
55  int childCount() const;
59  bool isFile() const;
60  int columnCount() const;
61  QVariant data(int column, int role) const;
62  bool setData(int column, const QVariant &value, FileModel *model, int role = Qt::EditRole);
63  int row() const;
64  FileItem *parent();
65 
66  private:
70  void addSize(KIO::fileoffset_t size, FileModel *model);
71 
76  void checkParents(Qt::CheckState state, FileModel *model);
77 
81  void checkChildren(Qt::CheckState state, FileModel *model);
82 
83  private:
84  QList<FileItem*> m_childItems;
85  mutable KIcon m_mimeType;
86  QString m_name;
87  Qt::CheckState m_state;
88  Job::Status m_status;
89  KIO::fileoffset_t m_totalSize;
90  int m_checkusmVerified;
91  int m_signatureVerified;
92  FileItem *m_parent;
93 };
94 
101 class KGET_EXPORT FileModel : public QAbstractItemModel
102 {
103  Q_OBJECT
104 
105  friend class FileItem;
106 
107  public:
108  FileModel(const QList<KUrl> &files, const KUrl &destDirectory, QObject *parent = 0);
109  ~FileModel();
110 
111  QVariant data(const QModelIndex &index, int role) const;
112  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
113  Qt::ItemFlags flags(const QModelIndex &index) const;
114  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
115  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
116  QModelIndex index(const KUrl &file, int column);
117  QModelIndex parent(const QModelIndex &index) const;
118  int rowCount(const QModelIndex &parent = QModelIndex()) const;
119  int columnCount(const QModelIndex &parent = QModelIndex()) const;
120 
121  void rename(const QModelIndex &file, const QString &newName);
122 
128  QModelIndexList fileIndexes(int column) const;
129 
134  KUrl getUrl(const QModelIndex &index);
135 
141  void setDirectory(const KUrl &newDirectory);
142 
147  void setCustomStatusText(Job::Status status, const QString &text);
148 
153  void setCustomStatusIcon(Job::Status status, const KIcon &icon);
154 
158  bool downloadFinished(const KUrl &file);
159 
163  bool isFile(const QModelIndex &index) const;
164 
165  public slots:
170  void watchCheckState();
171 
175  void stopWatchCheckState();
176 
177  Q_SIGNALS:
178  void rename(const KUrl &oldUrl, const KUrl &newUrl);
179  void checkStateChanged();
180  void fileFinished(const KUrl &file);
181 
182  private:
183  void setupModelData(const QList<KUrl> &files);
184 
189  KUrl getUrl(FileItem *item);
190 
197  QString getPath(FileItem *item);
198 
202  FileItem *getItem(const KUrl &file);
203 
204  void changeData(int row, int column, FileItem *item, bool fileFinished = false);
205 
206  private slots:
207  void renameFailed(const KUrl &beforeRename, const KUrl &afterRename);
208 
209  private:
210  FileItem *m_rootItem;
211  KUrl m_destDirectory;
212  QList<QVariant> m_header;
213  bool m_checkStateChanged;
214 
215  QHash<KUrl, FileItem*> m_itemCache; //used to make getItem faster
216 
220  QList<FileItem*> m_files;
221 
222  QHash<Job::Status, QString> m_customStatusTexts;
223  QHash<Job::Status, KIcon> m_customStatusIcons;
224 };
225 
226 #endif
QModelIndex
FileItem::parent
FileItem * parent()
Definition: filemodel.cpp:248
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
Job::Status
Status
The status property describes the current job status.
Definition: job.h:42
FileItem
Definition: filemodel.h:37
FileModel
This model represents the files that are being downloaded.
Definition: filemodel.h:101
QHash< KUrl, FileItem * >
kget_export.h
QObject
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QString
QList< FileItem * >
QAbstractItemModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
FileItem::ChecksumVerified
Definition: filemodel.h:48
FileItem::Status
Definition: filemodel.h:46
QAbstractItemModel::columnCount
virtual int columnCount(const QModelIndex &parent) const =0
FileItem::DataType
DataType
Definition: filemodel.h:43
transfer.h
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QAbstractItemModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
KGET_EXPORT
#define KGET_EXPORT
Definition: kget_export.h:24
FileItem::Size
Definition: filemodel.h:47
FileItem::isFile
bool isFile() const
Returns true if the index represents a file.
Definition: filemodel.cpp:60
QObject::parent
QObject * parent() const
FileItem::row
int row() const
Definition: filemodel.cpp:253
QVariant
Qt::ItemFlags
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal