Qmmp
|
00001 /************************************************************************** 00002 * Copyright (C) 2008-2009 by Ilya Kotov * 00003 * forkotov02@hotmail.ru * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00019 ***************************************************************************/ 00020 00021 #ifndef FILEDIALOG_H 00022 #define FILEDIALOG_H 00023 00024 #include <QString> 00025 #include <QStringList> 00026 00027 #include <QFileDialog> 00028 #include <QMap> 00029 00030 #include "filedialogfactory.h" 00031 00032 00036 class FileDialog : public QObject 00037 { 00038 Q_OBJECT 00039 public: 00043 enum Mode 00044 { 00045 AddFile = 0, 00046 AddDir, 00047 AddFiles, 00048 AddDirs, 00049 AddDirsFiles, 00050 SaveFile 00051 }; 00059 static QString getExistingDirectory(QWidget *parent = 0, 00060 const QString &caption = QString(), 00061 const QString &dir = QString()); 00072 static QString getOpenFileName(QWidget *parent = 0, 00073 const QString &caption = QString(), 00074 const QString &dir = QString(), 00075 const QString &filter = QString(), 00076 QString *selectedFilter = 0); 00087 static QStringList getOpenFileNames(QWidget *parent = 0, 00088 const QString &caption = QString(), 00089 const QString &dir = QString(), 00090 const QString &filter = QString(), 00091 QString *selectedFilter = 0); 00102 static QString getSaveFileName (QWidget *parent = 0, 00103 const QString &caption = QString(), 00104 const QString &dir = QString(), 00105 const QString &filter = QString(), 00106 QString *selectedFilter = 0); 00123 static void popup(QWidget *parent = 0, 00124 Mode mode = AddFiles, 00125 QString *dir = 0, 00126 QObject *receiver = 0, 00127 const char *member = 0, 00128 const QString &caption = QString(), 00129 const QString &filters = QString()); 00133 static QList <FileDialogFactory*> registeredFactories(); 00137 static bool isModal(); 00141 static void setEnabled(FileDialogFactory *factory); 00145 static bool isEnabled(FileDialogFactory *factory); 00146 00147 signals: 00151 void filesAdded(const QStringList&); 00152 protected: 00156 FileDialog(); 00165 virtual QString existingDirectory(QWidget *parent, 00166 const QString &caption, 00167 const QString &dir); 00179 virtual QString openFileName( QWidget *parent, 00180 const QString &caption, 00181 const QString &dir, 00182 const QString &filter, 00183 QString *selectedFilter); 00195 virtual QStringList openFileNames(QWidget *parent, 00196 const QString &caption, 00197 const QString &dir, 00198 const QString &filter, 00199 QString *selectedFilter); 00211 virtual QString saveFileName ( QWidget *parent , 00212 const QString &caption, 00213 const QString &dir, 00214 const QString &filter , 00215 QString *selectedFilter); 00220 virtual bool modal()const 00221 { 00222 return true; 00223 } 00227 virtual ~FileDialog() 00228 { 00229 ; 00230 }; 00240 virtual void raise(const QString &dir = QString(), 00241 Mode mode = AddFiles, 00242 const QString &caption = QString(), 00243 const QStringList &mask = QStringList()) 00244 { 00245 Q_UNUSED(dir); 00246 Q_UNUSED(mode); 00247 Q_UNUSED(caption); 00248 Q_UNUSED(mask); 00249 } 00253 static FileDialog* instance(); 00257 static FileDialog* defaultInstance(); 00262 static bool registerFactory(FileDialogFactory *factory); 00263 00264 private slots: 00265 void updateLastDir(const QStringList&); 00266 00267 private: 00268 void init(QObject* receiver, const char* member, QString *dir); 00269 static void registerBuiltinFactories(); 00270 static void registerExternalFactories(); 00271 static QMap <QString,FileDialogFactory*> factories; 00272 static FileDialog* _instance; 00273 static QString m_current_factory; 00274 bool m_initialized; 00275 QString *m_lastDir; 00276 }; 00277 00278 #endif 00279 00280