File indexing completed on 2024-05-05 04:59:12

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2007 by Joris Guisson                              *
0003  *   joris.guisson@gmail.com                                               *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
0019  ***************************************************************************/
0020 #ifndef KTFILEVIEW_H
0021 #define KTFILEVIEW_H
0022 
0023 #include <util/constants.h>
0024 
0025 #include <KSharedConfig>
0026 #include <QTreeView>
0027 
0028 class QMenu;
0029 class QSortFilterProxyModel;
0030 
0031 namespace bt
0032 {
0033 class TorrentInterface;
0034 class TorrentFileInterface;
0035 }
0036 
0037 namespace kt
0038 {
0039 class TorrentFileModel;
0040 
0041 /**
0042     @author Joris Guisson <joris.guisson@gmail.com>
0043 */
0044 class FileView : public QTreeView
0045 {
0046     Q_OBJECT
0047 public:
0048     FileView(QWidget *parent);
0049     ~FileView() override;
0050 
0051     void changeTC(bt::TorrentInterface *tc, KSharedConfigPtr cfg);
0052     void setShowListOfFiles(bool on, KSharedConfigPtr cfg);
0053     void saveState(KSharedConfigPtr cfg);
0054     void loadState(KSharedConfigPtr cfg);
0055     void update();
0056     void filePercentageChanged(bt::TorrentFileInterface *file, float percentage);
0057     void filePreviewChanged(bt::TorrentFileInterface *file, bool preview);
0058 
0059 public Q_SLOTS:
0060     void onTorrentRemoved(bt::TorrentInterface *tc);
0061 
0062 private Q_SLOTS:
0063     void showContextMenu(const QPoint &p);
0064     void onDoubleClicked(const QModelIndex &index);
0065     void onMissingFileMarkedDND(bt::TorrentInterface *tc);
0066 
0067 private:
0068     void changePriority(bt::Priority newpriority);
0069     void expandCollapseTree(const QModelIndex &idx, bool expand);
0070     void expandCollapseSelected(bool expand);
0071     bool viewportEvent(QEvent *event) override;
0072     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0073 
0074 private Q_SLOTS:
0075     void open();
0076     void downloadFirst();
0077     void downloadLast();
0078     void downloadNormal();
0079     void doNotDownload();
0080     void deleteFiles();
0081     void moveFiles();
0082     void collapseTree();
0083     void expandTree();
0084 
0085 private:
0086     bool redraw;
0087     bt::TorrentInterface *curr_tc;
0088     TorrentFileModel *model;
0089 
0090     QMenu *context_menu;
0091     QAction *open_action;
0092     QAction *download_first_action;
0093     QAction *download_normal_action;
0094     QAction *download_last_action;
0095     QAction *dnd_action;
0096     QAction *delete_action;
0097     QAction *move_files_action;
0098     QAction *collapse_action;
0099     QAction *expand_action;
0100 
0101     QString preview_path;
0102     bool show_list_of_files;
0103     QMap<bt::TorrentInterface *, QByteArray> expanded_state_map;
0104     QSortFilterProxyModel *proxy_model;
0105 };
0106 }
0107 
0108 #endif