MythTV  master
mythuifilebrowser.h
Go to the documentation of this file.
1 
2 #ifndef MYTHUIFILEBROWSER_H_
3 #define MYTHUIFILEBROWSER_H_
4 
5 // C++ headers
6 #include <utility>
7 
8 // QT headers
9 #include <QDir>
10 #include <QEvent>
11 #include <QFileInfo>
12 
13 #include "mythscreentype.h"
14 #include "mythuitextedit.h"
15 
16 class QString;
17 class QStringList;
18 class QTimer;
19 
21 class MythUIButtonList;
22 class MythUIButton;
23 class MythUITextEdit;
24 class MythUIImage;
25 class MythUIStateType;
26 
27 class MUI_PUBLIC MFileInfo : public QFileInfo
28 {
29  public:
30  explicit MFileInfo(const QString& fileName = "", QString sgDir = "", bool isDir = false,
31  qint64 size = 0);
32  ~MFileInfo() = default;
33 
34  MFileInfo &operator=(const MFileInfo &other);
35 
36  void init(const QString& fileName = "", QString sgDir = "", bool isDir = false,
37  qint64 size = 0);
38 
39  QString fileName(void) const;
40  QString filePath(void) const;
41  bool isRemote(void) { return m_isRemote; }
42  bool isDir(void) const;
43  bool isFile(void) const;
44  bool isParentDir(void) const;
45  bool isExecutable(void) const;
46  QString absoluteFilePath(void) const;
47  qint64 size(void) const;
48 
49  void setFile(const QString &file) { init(file); }
50  void setSize(qint64 size) { m_size = size; }
51  void setIsDir(bool isDir) { m_isDir = isDir; m_isFile = !isDir; }
52  void setIsFile(bool isFile) { m_isFile = isFile; m_isDir = !isFile; }
53  void setIsParentDir(bool isParentDir) { m_isParentDir = isParentDir; }
54  void setSGDir(QString sgDir) { m_storageGroupDir = std::move(sgDir); }
55 
56  QString hostName(void) const { return m_hostName; }
57  QString storageGroup(void) const { return m_storageGroup; }
58  QString storageGroupDir(void) const { return m_storageGroupDir; }
59  QString subDir(void) const { return m_subDir; }
60 
61  private:
62 
63  bool m_isRemote {false};
64  bool m_isDir {false};
65  bool m_isFile {true};
66  bool m_isParentDir {false};
67 
68  QString m_hostName;
69  QString m_storageGroup;
71  QString m_fileName;
72  QString m_subDir;
73 
74  qint64 m_size {0};
75 };
76 
78 
80 {
81  Q_OBJECT
82 
83  public:
84  MythUIFileBrowser(MythScreenStack *parent, const QString &startPath);
85  ~MythUIFileBrowser() override = default;
86 
87  bool Create(void) override; // MythScreenType
88 
89  void SetReturnEvent(QObject *retobject, const QString &resultid);
90 
91  void SetTypeFilter(QDir::Filters filter) { m_typeFilter = filter; }
92  void SetNameFilter(QStringList filter) { m_nameFilter = std::move(filter); }
93 
94  private slots:
95  void OKPressed(void);
96  void cancelPressed(void);
97  void backPressed(void);
98  void homePressed(void);
99  void editLostFocus(void);
100  void PathSelected(MythUIButtonListItem *item);
101  void PathClicked(MythUIButtonListItem *item);
102  void LoadPreview(void);
103 
104  private:
105  void SetPath(const QString &startPath);
106  static bool GetRemoteFileList(const QString &url, const QString &sgDir,
107  QStringList &list);
108  void updateFileList(void);
109  void updateRemoteFileList(void);
110  void updateLocalFileList(void);
111  void updateSelectedList(void);
112  void updateWidgets(void);
113 
114  static bool IsImage(QString extension);
115  static QString FormatSize(int64_t size);
116 
117  bool m_isRemote {false};
118 
119  QTimer *m_previewTimer {nullptr};
120 
122  QString m_subDirectory;
124  QString m_parentDir;
125  QString m_parentSGDir;
126 
127  QDir::Filters m_typeFilter {QDir::AllDirs | QDir::Drives |
128  QDir::Files | QDir::Readable |
129  QDir::Writable | QDir::Executable};
130  QStringList m_nameFilter;
131 
132  MythUIButtonList *m_fileList {nullptr};
133  MythUITextEdit *m_locationEdit {nullptr};
134  MythUIButton *m_okButton {nullptr};
135  MythUIButton *m_cancelButton {nullptr};
136  MythUIButton *m_backButton {nullptr};
137  MythUIButton *m_homeButton {nullptr};
138  MythUIImage *m_previewImage {nullptr};
139  MythUIText *m_infoText {nullptr};
140  MythUIText *m_filenameText {nullptr};
141  MythUIText *m_fullpathText {nullptr};
142 
143  QObject *m_retObject {nullptr};
144  QString m_id;
145 };
146 
147 #endif
148 /* vim: set expandtab tabstop=4 shiftwidth=4: */
This widget is used for grouping other widgets for display when a particular named state is called.
void setSGDir(QString sgDir)
QString m_storageGroupDir
unsigned int slots[4]
Definition: element.c:38
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
void setIsFile(bool isFile)
QString storageGroup(void) const
QString m_hostName
void setIsParentDir(bool isParentDir)
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
QStringList m_nameFilter
QString hostName(void) const
virtual bool Create(void)
Q_DECLARE_METATYPE(MFileInfo)
QString m_fileName
bool isRemote(void)
void SetNameFilter(QStringList filter)
QString storageGroupDir(void) const
QString m_subDir
void setFile(const QString &file)
QString m_storageGroup
A text entry and edit widget.
void setSize(qint64 size)
void SetTypeFilter(QDir::Filters filter)
void setIsDir(bool isDir)
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
static void init(VideoFrame *vf, VideoFrameType _codec, unsigned char *_buf, int _width, int _height, int _size, const int *p=nullptr, const int *o=nullptr, float _aspect=-1.0F, double _rate=-1.0F, int _aligned=MYTH_WIDTH_ALIGNMENT)
Definition: mythframe.h:231
A single button widget.
Definition: mythuibutton.h:21
QString subDir(void) const
#define MUI_PUBLIC
Definition: mythuiexp.h:9
Screen in which all other widgets are contained and rendered.