/*  This file is part of the KDE project
    Copyright (C) 2009 Norbert Frese <nf2.email@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/
#ifndef KFILEPLACESMODELGNOME_H_
#define KFILEPLACESMODELGNOME_H_

#include <kfile_export.h>
#include <kfileplacesmodelimpl.h>

#include <QtCore/QAbstractItemModel>
#include <QtCore/QSharedPointer>
#include <QtCore/QList>
#include <kurl.h>
#include <kbookmark.h>
#include <kicon.h>
#include <solid/device.h>

#include "placesitem.h"
#include "placeslist.h"
#include "storage/kstorage.h"
#include "bookmarks/gtkbookmarks.h"

class QMimeData;
class QAction;

/**
 * implementation of the GNOME style KFilePlacesModel
 */
class KFilePlacesModelGnome : public KFilePlacesModelImpl
{
    Q_OBJECT
public:

    KFilePlacesModelGnome(KFilePlacesModel *self);

    KFilePlacesModelGnome(QObject* parent, const QVariantList&);

    virtual ~KFilePlacesModelGnome()
    {
    }

    bool isDevice(const QModelIndex &index) const;
    Solid::Device deviceForIndex(const QModelIndex &index) const;
    KBookmark bookmarkForIndex(const QModelIndex &index) const;

    QAction *teardownActionForIndex(const QModelIndex &index) const;
    QAction *ejectActionForIndex(const QModelIndex &index) const;
    void requestTeardown(const QModelIndex &index);
    void requestEject(const QModelIndex &index);
    void requestSetup(const QModelIndex &index);

    void addPlace(const QString &text, const KUrl &url, const QString &iconName = QString(), const QString &appName = QString());
    void editPlace(const QModelIndex &index, const QString &text, const KUrl &url, const QString &iconName = QString(), const QString &appName = QString());
    void removePlace(const QModelIndex &index);
    void setPlaceHidden(const QModelIndex &index, bool hidden);

    int hiddenCount() const;

    QVariant data(const QModelIndex &index, int role) const;

    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;

    int rowCount(const QModelIndex &parent = QModelIndex()) const;

    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    QModelIndex closestItem(const KUrl &url) const;

    Qt::DropActions supportedDropActions() const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QStringList mimeTypes() const;
    QMimeData *mimeData(const QModelIndexList &indexes) const;
    bool dropMimeData(const QMimeData *data, Qt::DropAction action,
                      int row, int column, const QModelIndex &parent);

private Q_SLOTS:
    void _k_storageAdded(const KStorage &storage);
    void _k_storageRemoved(const KStorage &storage);
    void _k_itemChanged(const QString &udi);
    void _k_storageChanged(const KStorage &storage);

    void _k_storageSetupDone(const KStorage &storage, const KStorage::ErrorType error, const QString &errorMessage);
    void _k_storageTeardownDone(const KStorage &storage, const KStorage::ErrorType error, const QString &errorMessage);
    void _k_storageEjectDone(const KStorage &storage, const KStorage::ErrorType error, const QString &errorMessage);

    void _k_bookmarkAdded(GtkBookmark bookmark, int index);
    void _k_bookmarkRemoved(GtkBookmark bookmark, int index);
    void _k_bookmarkModified(GtkBookmark bookmark, int index);



private:
    KStorage storageForIndex(const QModelIndex & index) const;

    QHash<KStorage, QPersistentModelIndex> storageSetupInProgress;
    PlacesList items;

    GtkBookmarks gtkBookmarks;

};

#endif

