/*
 * Copyright 2010  Jonas Emanuel Müller <zanoi@zanoi.net>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of 
 * the License, or (at your option) any later version.

 * This program 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 General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CHANNELMODEL_H
#define CHANNELMODEL_H

#include "config.h" //krazy:exclude=includes

#include <QtSql/QSqlRelationalTableModel>
#include <QtCore/QVariant>
#include <QtCore/QString>

class QModelIndex;
class QObject;

namespace Videocatcher {

enum {
    Channel_Id = 0,
    Channel_Title = 1,
    Channel_Author = 2,
    Channel_Url = 3,
    Channel_Path = 4,
    Channel_Web_Link = 5
};

enum LastLoading
{
    Last_Loading_Started = 0,
    Last_Loading_Success = 1,
    Last_Loading_Failed = 2
};

enum ChannemModelRole {
    LastLoadingRole = Qt::UserRole
};

class ChannelModel : public QSqlRelationalTableModel
{
public:
    explicit ChannelModel(QObject* parent = 0);
    ~ChannelModel();

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    bool setData(const QModelIndex &index, const QVariant &data, int role = Qt::EditRole);

    bool addChannel(const QString &title, const QString &url, const QString &author, const QString &websiteUrl, const QString &directory="");

    QModelIndex findByTitle(const QString &title) const;
    QModelIndex findByUrl(const QString &url) const;
    QModelIndex findById(int id) const;

    QModelIndexList findAllByTitle(const QString &title) const;
    QModelIndexList findAllByUrl(const QString &url) const;
    
    bool remove(const QModelIndex &modelIndex);
    
    int id(const QModelIndex &row) const;
    QString title(const QModelIndex &row) const;
    QString author(const QModelIndex &row) const;
    QString url(const QModelIndex &row) const;
    QString path(const QModelIndex &row) const;
    QString webLink(const QModelIndex &row) const;
    bool setPath(const QModelIndex &row, const QString &path);
    bool exists(const QString &url) const;

private:
    struct ChannelModelPrivate;
    ChannelModelPrivate *const d;
};

} //namespace Videocatcher

#endif
