Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

128 lines (101 sloc) 4.616 kb
/**
* Copyright (c) 2006, Benjamin C. Meyer
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef FTPMODEL_H
#define FTPMODEL_H
#include <qabstractitemmodel.h>
#include <qftp.h>
#include <qdir.h>
#include <qurl.h>
#include <qhash.h>
#include <qpair.h>
class FtpItem;
class QFileIconProvider;
class FtpModel : public QAbstractItemModel
{
Q_OBJECT
public:
FtpModel(QObject *parent = 0);
~FtpModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex parent(const QModelIndex& parent) const;
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indexes) const;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent);
Qt::DropActions supportedDropActions() const;
QModelIndex index(int, int, const QModelIndex& parent= QModelIndex()) const;
QModelIndex index(const QString &path, int column = 0) const;
QString fileName(const QModelIndex &index) const;
QString filePath(const QModelIndex &index) const;
QIcon fileIcon(const QModelIndex &index) const;
bool isDir(const QModelIndex &index) const;
QUrl url() const;
QString size(const QModelIndex &index) const;
QString type(const QModelIndex &index) const;
QString time(const QModelIndex &index) const;
QDir::Filters filter() const;
void setFilter(QDir::Filters filters);
void refresh(const QModelIndex &parent = QModelIndex());
// For progress etc...
QFtp connection;
inline bool connected() const {
return (connection.state() == QFtp::Connected || connection.state() == QFtp::LoggedIn);
}
public slots:
void setUrl(const QUrl &url);
private slots:
void gotNewListInfo(const QUrlInfo &info);
void stateChanged(int state);
void commandStarted(int id);
void commandFinished(int id, bool error);
private:
QUrl ftpUrl;
QDir::Filters filters;
QFileIconProvider *iconProvider;
FtpItem *root;
void sort(FtpItem *parent, Qt::SortOrder order);
QStringList listing;
QList<int> listingCommands;
QMap<int, QPair<QString, QString> > renameCommands;
QHash<int, QFile*> copyCommands;
QHash<int, QFile*> moveCommands;
const FtpItem *ftpItem(const QModelIndex &index) const {
return index.isValid() ? static_cast<const FtpItem*>(index.internalPointer()) : root;
}
};
#endif // FTPMODEL_H
Jump to Line
Something went wrong with that request. Please try again.