/* This file is part of the KDE libraries
    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 as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    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 KSTORAGE_H_
#define KSTORAGE_H_

#include <QtCore/QList>
#include <QtCore/QUrl>
#include <QtCore/QString>
#include <QtCore/QObject>
#include <QtCore/QExplicitlySharedDataPointer>

class KStoragePrivate;
class KStorageIface;

class KStorage
{
public:

    enum ErrorType { NoError = 0, UnauthorizedOperation };

    /**
     * list storages
     */
    static QList<KStorage> list();

    /**
     * lookup storage
     */
    static KStorage lookup(const QString& id);

    ///// constuctors, destructors and standard operators /////

    /**
     * Null instance
     */
    KStorage();

    /**
     * @internal
     */
    KStorage(KStorageIface * backend);

    /**
     * Constructs a copy of a storage.
     *
     * @param the storage to copy
     */
    KStorage(const KStorage &storage);

    /**
     * Destructor.
     */
    ~KStorage();

    /**
     * Assignment operator
     *
     * @param device the device to assign
     * @return a reference to the device
     */
    KStorage &operator=(const KStorage &storage);

    /**
     * compare two storage objects
     */
    bool operator==(const KStorage &other) const;

    ///// properties /////

    bool isNull() const;

    /**
     * Does it still exist?
     */
    bool isValid() const;

    /**
     * unique id of this storage
     */
    QString id() const;

    /**
     * display name
     */
    QString displayName() const;

    /**
     * icon name
     */
    QString icon() const;

    /**
     * emblems
     */
    QStringList emblems() const;

    /**
     * url
     */
    QUrl url() const;

    /**
     * if this is a UNIX mount, returns the absolute path of the mountpoint
     */
    QString mountPointPath() const;

    /**
     * removable storage?
     */
    bool isRemovable() const;

    /**
     * releasable (i.e. optical disk)
     */
    bool isReleasable() const;

    /**
     * hotpluggable
     */
    bool isHotpluggable() const;

    /**
     * file system mounted?
     */
    bool isAccessible() const;

    /**
     * Pointer to the implementation of this interface
     * Use it to connect signals/slots
     */
    QObject * impl() const;

    ///// actions ////

    /**
     * SLOT(done(const KStorage &storage, const KStorage::ErrorType error, const QString &errorMessage))
     */
    void setup(QObject * doneSignalTarget, const char * doneQSlot);

    /**
     * SLOT(done(const KStorage &storage, const KStorage::ErrorType error, const QString &errorMessage))
     */
    void teardown(QObject * doneSignalTarget, const char * doneQSlot);

    /**
     * SLOT(done(const KStorage &storage, const KStorage::ErrorType error, const QString &errorMessage))
     */
    void eject(QObject * doneSignalTarget, const char * doneQSlot);

    ///// signals ////

    void connectChangedSignalTo(const QObject * obj, const char * slot);

    void connectRemovedSignalTo(const QObject * obj, const char * slot);


private:

    QExplicitlySharedDataPointer<KStoragePrivate> d;
    friend class KIOBackend;
};

uint qHash(const KStorage &storage);


#endif /* KSTORAGE_H_ */
