| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef Q3FILEDIALOG_H
|
|---|
| 43 | #define Q3FILEDIALOG_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qdir.h>
|
|---|
| 46 | #include <QtGui/qdialog.h>
|
|---|
| 47 | #include <Qt3Support/q3urloperator.h>
|
|---|
| 48 | #include <Qt3Support/q3valuelist.h>
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_HEADER
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_NAMESPACE
|
|---|
| 53 |
|
|---|
| 54 | QT_MODULE(Qt3SupportLight)
|
|---|
| 55 |
|
|---|
| 56 | class QAbstractButton;
|
|---|
| 57 | class QPushButton;
|
|---|
| 58 | class QLabel;
|
|---|
| 59 | class QWidget;
|
|---|
| 60 | class QFileDialog;
|
|---|
| 61 | class QTimer;
|
|---|
| 62 | class Q3NetworkOperation;
|
|---|
| 63 | class QLineEdit;
|
|---|
| 64 | class Q3ListViewItem;
|
|---|
| 65 | class Q3ListBoxItem;
|
|---|
| 66 | class Q3FileDialogPrivate;
|
|---|
| 67 | class Q3FileDialogQFileListView;
|
|---|
| 68 | class QUrlInfo;
|
|---|
| 69 |
|
|---|
| 70 | #ifndef QT_NO_FILEDIALOG
|
|---|
| 71 |
|
|---|
| 72 | class Q_COMPAT_EXPORT Q3FileIconProvider : public QObject
|
|---|
| 73 | {
|
|---|
| 74 | Q_OBJECT
|
|---|
| 75 | public:
|
|---|
| 76 | Q3FileIconProvider(QObject * parent = 0, const char* name = 0);
|
|---|
| 77 | virtual const QPixmap * pixmap(const QFileInfo &);
|
|---|
| 78 |
|
|---|
| 79 | private:
|
|---|
| 80 | Q_DISABLE_COPY(Q3FileIconProvider)
|
|---|
| 81 | };
|
|---|
| 82 |
|
|---|
| 83 | class Q_COMPAT_EXPORT Q3FilePreview
|
|---|
| 84 | {
|
|---|
| 85 | public:
|
|---|
| 86 | Q3FilePreview();
|
|---|
| 87 | virtual ~Q3FilePreview() {}
|
|---|
| 88 | virtual void previewUrl(const Q3Url &url) = 0;
|
|---|
| 89 |
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | class Q_COMPAT_EXPORT Q3FileDialog : public QDialog
|
|---|
| 93 | {
|
|---|
| 94 | Q_OBJECT
|
|---|
| 95 | Q_ENUMS(Mode ViewMode PreviewMode)
|
|---|
| 96 | // ##### Why are this read-only properties ?
|
|---|
| 97 | Q_PROPERTY(QString selectedFile READ selectedFile)
|
|---|
| 98 | Q_PROPERTY(QString selectedFilter READ selectedFilter)
|
|---|
| 99 | Q_PROPERTY(QStringList selectedFiles READ selectedFiles)
|
|---|
| 100 | // #### Should not we be able to set the path ?
|
|---|
| 101 | Q_PROPERTY(QString dirPath READ dirPath)
|
|---|
| 102 | Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles)
|
|---|
| 103 | Q_PROPERTY(Mode mode READ mode WRITE setMode)
|
|---|
| 104 | Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
|
|---|
| 105 | Q_PROPERTY(PreviewMode previewMode READ previewMode WRITE setPreviewMode)
|
|---|
| 106 | Q_PROPERTY(bool infoPreview READ isInfoPreviewEnabled WRITE setInfoPreviewEnabled)
|
|---|
| 107 | Q_PROPERTY(bool contentsPreview READ isContentsPreviewEnabled WRITE setContentsPreviewEnabled)
|
|---|
| 108 |
|
|---|
| 109 | public:
|
|---|
| 110 | Q3FileDialog(const QString& dirName, const QString& filter = QString(),
|
|---|
| 111 | QWidget* parent=0, const char* name=0, bool modal = false);
|
|---|
| 112 | Q3FileDialog(QWidget* parent=0, const char* name=0, bool modal = false);
|
|---|
| 113 | ~Q3FileDialog();
|
|---|
| 114 |
|
|---|
| 115 | // recommended static functions
|
|---|
| 116 |
|
|---|
| 117 | static QString getOpenFileName(const QString &initially = QString(),
|
|---|
| 118 | const QString &filter = QString(),
|
|---|
| 119 | QWidget *parent = 0, const char* name = 0,
|
|---|
| 120 | const QString &caption = QString(),
|
|---|
| 121 | QString *selectedFilter = 0,
|
|---|
| 122 | bool resolveSymlinks = true);
|
|---|
| 123 | static QString getSaveFileName(const QString &initially = QString(),
|
|---|
| 124 | const QString &filter = QString(),
|
|---|
| 125 | QWidget *parent = 0, const char* name = 0,
|
|---|
| 126 | const QString &caption = QString(),
|
|---|
| 127 | QString *selectedFilter = 0,
|
|---|
| 128 | bool resolveSymlinks = true);
|
|---|
| 129 | static QString getExistingDirectory(const QString &dir = QString(),
|
|---|
| 130 | QWidget *parent = 0,
|
|---|
| 131 | const char* name = 0,
|
|---|
| 132 | const QString &caption = QString(),
|
|---|
| 133 | bool dirOnly = true,
|
|---|
| 134 | bool resolveSymlinks = true);
|
|---|
| 135 | static QStringList getOpenFileNames(const QString &filter= QString(),
|
|---|
| 136 | const QString &dir = QString(),
|
|---|
| 137 | QWidget *parent = 0,
|
|---|
| 138 | const char* name = 0,
|
|---|
| 139 | const QString &caption = QString(),
|
|---|
| 140 | QString *selectedFilter = 0,
|
|---|
| 141 | bool resolveSymlinks = true);
|
|---|
| 142 |
|
|---|
| 143 | // other static functions
|
|---|
| 144 |
|
|---|
| 145 | static void setIconProvider(Q3FileIconProvider *);
|
|---|
| 146 | static Q3FileIconProvider * iconProvider();
|
|---|
| 147 |
|
|---|
| 148 | // non-static function for special needs
|
|---|
| 149 |
|
|---|
| 150 | QString selectedFile() const;
|
|---|
| 151 | QString selectedFilter() const;
|
|---|
| 152 | virtual void setSelectedFilter(const QString&);
|
|---|
| 153 | virtual void setSelectedFilter(int);
|
|---|
| 154 |
|
|---|
| 155 | void setSelection(const QString &);
|
|---|
| 156 |
|
|---|
| 157 | void selectAll(bool b);
|
|---|
| 158 |
|
|---|
| 159 | QStringList selectedFiles() const;
|
|---|
| 160 |
|
|---|
| 161 | QString dirPath() const;
|
|---|
| 162 |
|
|---|
| 163 | void setDir(const QDir &);
|
|---|
| 164 | const QDir *dir() const;
|
|---|
| 165 |
|
|---|
| 166 | void setShowHiddenFiles(bool s);
|
|---|
| 167 | bool showHiddenFiles() const;
|
|---|
| 168 |
|
|---|
| 169 | void rereadDir();
|
|---|
| 170 | void resortDir();
|
|---|
| 171 |
|
|---|
| 172 | enum Mode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
|
|---|
| 173 | void setMode(Mode);
|
|---|
| 174 | Mode mode() const;
|
|---|
| 175 |
|
|---|
| 176 | enum ViewMode { Detail, List };
|
|---|
| 177 | enum PreviewMode { NoPreview, Contents, Info };
|
|---|
| 178 | void setViewMode(ViewMode m);
|
|---|
| 179 | ViewMode viewMode() const;
|
|---|
| 180 | void setPreviewMode(PreviewMode m);
|
|---|
| 181 | PreviewMode previewMode() const;
|
|---|
| 182 |
|
|---|
| 183 | bool eventFilter(QObject *, QEvent *);
|
|---|
| 184 |
|
|---|
| 185 | bool isInfoPreviewEnabled() const;
|
|---|
| 186 | bool isContentsPreviewEnabled() const;
|
|---|
| 187 | void setInfoPreviewEnabled(bool);
|
|---|
| 188 | void setContentsPreviewEnabled(bool);
|
|---|
| 189 |
|
|---|
| 190 | void setInfoPreview(QWidget *w, Q3FilePreview *preview);
|
|---|
| 191 | void setContentsPreview(QWidget *w, Q3FilePreview *preview);
|
|---|
| 192 |
|
|---|
| 193 | Q3Url url() const;
|
|---|
| 194 |
|
|---|
| 195 | void addFilter(const QString &filter);
|
|---|
| 196 |
|
|---|
| 197 | public Q_SLOTS:
|
|---|
| 198 | void done(int);
|
|---|
| 199 | void setDir(const QString&);
|
|---|
| 200 | void setUrl(const Q3UrlOperator &url);
|
|---|
| 201 | void setFilter(const QString&);
|
|---|
| 202 | void setFilters(const QString&);
|
|---|
| 203 | void setFilters(const char **);
|
|---|
| 204 | void setFilters(const QStringList&);
|
|---|
| 205 |
|
|---|
| 206 | protected:
|
|---|
| 207 | void resizeEvent(QResizeEvent *);
|
|---|
| 208 | void keyPressEvent(QKeyEvent *);
|
|---|
| 209 |
|
|---|
| 210 | void addWidgets(QLabel *, QWidget *, QPushButton *);
|
|---|
| 211 | void addToolButton(QAbstractButton *b, bool separator = false);
|
|---|
| 212 | void addLeftWidget(QWidget *w);
|
|---|
| 213 | void addRightWidget(QWidget *w);
|
|---|
| 214 |
|
|---|
| 215 | Q_SIGNALS:
|
|---|
| 216 | void fileHighlighted(const QString&);
|
|---|
| 217 | void fileSelected(const QString&);
|
|---|
| 218 | void filesSelected(const QStringList&);
|
|---|
| 219 | void dirEntered(const QString&);
|
|---|
| 220 | void filterSelected(const QString&);
|
|---|
| 221 |
|
|---|
| 222 | private Q_SLOTS:
|
|---|
| 223 | void detailViewSelectionChanged();
|
|---|
| 224 | void listBoxSelectionChanged();
|
|---|
| 225 | void changeMode(int);
|
|---|
| 226 | void fileNameEditReturnPressed();
|
|---|
| 227 | void stopCopy();
|
|---|
| 228 | void removeProgressDia();
|
|---|
| 229 |
|
|---|
| 230 | void fileSelected(int);
|
|---|
| 231 | void fileHighlighted(int);
|
|---|
| 232 | void dirSelected(int);
|
|---|
| 233 | void pathSelected(int);
|
|---|
| 234 |
|
|---|
| 235 | void updateFileNameEdit(Q3ListViewItem *);
|
|---|
| 236 | void selectDirectoryOrFile(Q3ListViewItem *);
|
|---|
| 237 | void popupContextMenu(Q3ListViewItem *, const QPoint &, int);
|
|---|
| 238 | void popupContextMenu(Q3ListBoxItem *, const QPoint &);
|
|---|
| 239 | void updateFileNameEdit(Q3ListBoxItem *);
|
|---|
| 240 | void selectDirectoryOrFile(Q3ListBoxItem *);
|
|---|
| 241 | void fileNameEditDone();
|
|---|
| 242 |
|
|---|
| 243 | void okClicked();
|
|---|
| 244 | void filterClicked(); // not used
|
|---|
| 245 | void cancelClicked();
|
|---|
| 246 |
|
|---|
| 247 | void cdUpClicked();
|
|---|
| 248 | void newFolderClicked();
|
|---|
| 249 |
|
|---|
| 250 | void fixupNameEdit();
|
|---|
| 251 |
|
|---|
| 252 | void doMimeTypeLookup();
|
|---|
| 253 |
|
|---|
| 254 | void updateGeometries();
|
|---|
| 255 | void modeButtonsDestroyed();
|
|---|
| 256 | void urlStart(Q3NetworkOperation *op);
|
|---|
| 257 | void urlFinished(Q3NetworkOperation *op);
|
|---|
| 258 | void dataTransferProgress(int bytesDone, int bytesTotal, Q3NetworkOperation *);
|
|---|
| 259 | void insertEntry(const Q3ValueList<QUrlInfo> &fi, Q3NetworkOperation *op);
|
|---|
| 260 | void removeEntry(Q3NetworkOperation *);
|
|---|
| 261 | void createdDirectory(const QUrlInfo &info, Q3NetworkOperation *);
|
|---|
| 262 | void itemChanged(Q3NetworkOperation *);
|
|---|
| 263 | void goBack();
|
|---|
| 264 |
|
|---|
| 265 | private:
|
|---|
| 266 | Q_DISABLE_COPY(Q3FileDialog)
|
|---|
| 267 |
|
|---|
| 268 | enum PopupAction {
|
|---|
| 269 | PA_Open = 0,
|
|---|
| 270 | PA_Delete,
|
|---|
| 271 | PA_Rename,
|
|---|
| 272 | PA_SortName,
|
|---|
| 273 | PA_SortSize,
|
|---|
| 274 | PA_SortType,
|
|---|
| 275 | PA_SortDate,
|
|---|
| 276 | PA_SortUnsorted,
|
|---|
| 277 | PA_Cancel,
|
|---|
| 278 | PA_Reload,
|
|---|
| 279 | PA_Hidden
|
|---|
| 280 | };
|
|---|
| 281 |
|
|---|
| 282 | void init();
|
|---|
| 283 | bool trySetSelection(bool isDir, const Q3UrlOperator &, bool);
|
|---|
| 284 | void deleteFile(const QString &filename);
|
|---|
| 285 | void popupContextMenu(const QString &filename, bool withSort,
|
|---|
| 286 | PopupAction &action, const QPoint &p);
|
|---|
| 287 | void updatePreviews(const Q3Url &u);
|
|---|
| 288 |
|
|---|
| 289 | QString fileName;
|
|---|
| 290 |
|
|---|
| 291 | friend class Q3FileDialogQFileListView;
|
|---|
| 292 | friend class QFileListBox;
|
|---|
| 293 |
|
|---|
| 294 | Q3FileDialogPrivate *d;
|
|---|
| 295 | Q3FileDialogQFileListView *files;
|
|---|
| 296 |
|
|---|
| 297 | QLineEdit *nameEdit; // also filter
|
|---|
| 298 | QPushButton *okB;
|
|---|
| 299 | QPushButton *cancelB;
|
|---|
| 300 |
|
|---|
| 301 | #if defined(Q_WS_WIN)
|
|---|
| 302 | static QString winGetOpenFileName(const QString &initialSelection,
|
|---|
| 303 | const QString &filter,
|
|---|
| 304 | QString* workingDirectory,
|
|---|
| 305 | QWidget *parent = 0,
|
|---|
| 306 | const char* name = 0,
|
|---|
| 307 | const QString& caption = QString(),
|
|---|
| 308 | QString* selectedFilter = 0);
|
|---|
| 309 | static QString winGetSaveFileName(const QString &initialSelection,
|
|---|
| 310 | const QString &filter,
|
|---|
| 311 | QString* workingDirectory,
|
|---|
| 312 | QWidget *parent = 0,
|
|---|
| 313 | const char* name = 0,
|
|---|
| 314 | const QString& caption = QString(),
|
|---|
| 315 | QString* selectedFilter = 0);
|
|---|
| 316 | static QStringList winGetOpenFileNames(const QString &filter,
|
|---|
| 317 | QString* workingDirectory,
|
|---|
| 318 | QWidget *parent = 0,
|
|---|
| 319 | const char* name = 0,
|
|---|
| 320 | const QString& caption = QString(),
|
|---|
| 321 | QString* selectedFilter = 0);
|
|---|
| 322 | static QString winGetExistingDirectory(const QString &initialDirectory,
|
|---|
| 323 | QWidget* parent = 0,
|
|---|
| 324 | const char* name = 0,
|
|---|
| 325 | const QString& caption = QString());
|
|---|
| 326 | static QString resolveLinkFile(const QString& linkfile);
|
|---|
| 327 | int old_qt_ntfs_permission_lookup;
|
|---|
| 328 | #endif
|
|---|
| 329 | #if defined(Q_WS_MAC)
|
|---|
| 330 | static QString macGetSaveFileName(const QString &, const QString &,
|
|---|
| 331 | QString *, QWidget *, const char*,
|
|---|
| 332 | const QString&, QString *);
|
|---|
| 333 | static QStringList macGetOpenFileNames(const QString &, QString*,
|
|---|
| 334 | QWidget *, const char *,
|
|---|
| 335 | const QString&, QString *,
|
|---|
| 336 | bool = true, bool = false);
|
|---|
| 337 | #endif
|
|---|
| 338 | };
|
|---|
| 339 |
|
|---|
| 340 | #endif // QT_NO_FILEDIALOG
|
|---|
| 341 |
|
|---|
| 342 | QT_END_NAMESPACE
|
|---|
| 343 |
|
|---|
| 344 | QT_END_HEADER
|
|---|
| 345 |
|
|---|
| 346 | #endif // Q3FILEDIALOG_H
|
|---|