wadseekerwadstable.h
1 //------------------------------------------------------------------------------
2 // wadseekerwadstable.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2011 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __WADSEEKERWADSTABLE_H__
24 #define __WADSEEKERWADSTABLE_H__
25 
26 #include <QElapsedTimer>
27 #include <QMap>
28 #include <QMenu>
29 
30 #include "gui/widgets/tablewidgetmouseaware.h"
31 
32 class SpeedCalculator;
33 class ModFile;
34 
36 {
37  Q_OBJECT
38 
39 public:
40  class ContextMenu : public QMenu
41  {
42  friend class WadseekerWadsTable;
43 
44  public:
45  QAction *actionSkipCurrentSite;
46 
47  private:
48  ContextMenu(QWidget *pParent = nullptr);
49  };
50 
51  static const int IDX_NAME_COLUMN = 0;
52  static const int IDX_URL_COLUMN = 1;
53  static const int IDX_PROGRESS_COLUMN = 2;
54  static const int IDX_SPEED_COLUMN = 3;
55  static const int IDX_ETA_COLUMN = 4;
56  static const int IDX_SIZE_COLUMN = 5;
57 
58  WadseekerWadsTable(QWidget *pParent = nullptr);
59  ~WadseekerWadsTable() override;
60 
61  void addFile(const QString &filename);
62 
63  ContextMenu *contextMenu(const QModelIndex &index, const QPoint &cursorPosition);
64 
71  qint64 expectedDataSize(int row) const;
72 
73  QString fileNameAtRow(int row) const;
74 
82  double totalDonePercentage() const;
83 
84 public slots:
85  void setFileDownloadFinished(const ModFile &filename);
86  void setFileFailed(const ModFile &filename);
87  void setFileProgress(const ModFile &filename, qint64 current, qint64 total);
88  void setFileSuccessful(const ModFile &filename);
89 
93  void setFileUrl(const ModFile &filename, const QUrl &url);
94 
95 protected:
96  void showEvent(QShowEvent *pEvent) override;
97 
98 private:
99  class PrivData
100  {
101  public:
102  bool bAlreadyShownOnce;
103 
111  QMap<QString, SpeedCalculator *> speedCalculators;
112  QElapsedTimer updateClock;
113  };
114 
115  static const int UPDATE_INTERVAL_MS = 1000;
116 
117  PrivData d;
118 
119  int findFileRow(const QString &filename);
120  void updateDataInfoValues(bool bForce);
121 };
122 
123 #endif