/*
 * Copyright 2010  Jonas Emanuel Müller <zanoi@zanoi.net>
 *           2004, 2005  Frank Osterfeld <osterfeld@kde.org>
 *           2004  Stanislav Karchebny <Stanislav.Karchebny@kdemail.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 MAINWINDOW_H
#define MAINWINDOW_H

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

#include "episodeproxymodel.h"
#include "episodeinformationwidget.h"
#include "loader.h"

#include "ui_configurewidget.h"

#include <QMap>

#include <KXmlGuiWindow>
#include <Solid/Networking>
#include <kdeversion.h>

class QTableView;
class QWidget;
class QModelIndex;
class QString;
class QDomNode;

class KJob;
class KUrl;
class KStatusNotifierItem;
class KLineEdit;

namespace Videocatcher {

class Channel;
class ChannelModel;
class EpisodeModel;
class EpisodeView;
class EpisodeProxyModel;

class MainWindow : public KXmlGuiWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void playEpisode(const QModelIndex row, const QString &preferredServiceName = "");
    void refreshChannel(QModelIndex index);
    void cancelEpisodeDownload(QModelIndex index);
    void cancelAllEpisodeDownloads();

private slots:
    void updateEpisodeView();
    void currentEpisodeChanged(const QModelIndex &current, const QModelIndex &previous);
    void updateActions();
    void addChannel();
    void loadChannelResult(Channel *channel, ErrorCode status, const QString url);
    void removeChannel();
//     void editChannel();
    void autoRefreshChannels();
    void refreshChannel();
    void refreshAllChannels();
    void downloadEpisode();
    void updateDownloadSpeed(KJob* job, unsigned long speed);
    void downloadEpisodeResult(KJob *job);
    void cancelEpisodeDownload();
    void playEpisode();
    void streamEpisode();
    void deleteEpisode();
    void deleteEpisodeResult(KJob *job);
    void configure();
    void settingsChanged(const QString& dialogName);
    void updateDownloadStatus(KJob* job, unsigned long percent);
    void episodeDoubleClicked(const QModelIndex &index);
    void searchChanged(const QString & str);
    void showEpisodeViewContextMenu(const QPoint&);
    void showChannelViewContextMenu(const QPoint&);
    void copyEpisodeURLToClipboard();
    void importChannels();
    void quit();
    void networkStatusChanged(Solid::Networking::Status status);

protected:
    void updatePlayMenu(const QString &mimeType);
    void closeEvent(QCloseEvent *event);
    KUrl calculateEpisodeVideoPath(QModelIndex episode);
    KUrl calculateChannelPath(QModelIndex channel);
    KUrl calculateChannelPath(QString webLink);
    bool readFromOpml(const QDomDocument& doc);
    void parseChildNodes(QDomNode &node);
    bool submitChannels();
    bool submitEpisodes();
    bool submitChannelsAndEpisodes();

private:
    void initAutoRefreshChannels();
    void createChannelPanel();
    void createEpisodePanel();
    void createInformationPanel();
    void setupActions();

    struct MainWindowPrivate;
    MainWindowPrivate *const d;
};

} //namespace Videocatcher

#endif 
