Initial commit
[keepassx] / src / lib / FileDialogs.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2007 by Tarek Saidi                                *
3  *   tarek.saidi@arcor.de                                                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; version 2 of the License.               *
8
9  *                                                                         *
10  *   This program 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         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef _FILE_DIALOGS_H_
21 #define _FILE_DIALOGS_H_
22
23 #include "plugins/interfaces/IFileDialog.h"
24
25
26 class FileDlgHistory:public QObject{
27         Q_OBJECT
28         public:
29                 QString getDir(const QString& name);
30                 int getFilter(const QString& name);
31         public slots:
32                 void set(const QString& name,const QString& dir,int filter);
33                 void save();
34                 void load();
35                 void clear();
36         private:
37                 class Entry{
38                         public:
39                                 Entry(){Filter=-1;}
40                                 QString Dir;
41                                 int Filter;
42                                 bool isNull(){
43                                         if(Filter==-1)
44                                                 return true;
45                                         else
46                                                 return false;
47                                 }
48                 };
49                 
50                 QHash<QString,Entry>History;
51         
52 };
53
54
55 class KpxFileDialogs{
56         public:
57         static void setPlugin(IFileDialog* FileDlgPlugin);
58         static QString openExistingFile(QWidget* parent, const QString& Name,
59                                         const QString& Title,
60                                         const QStringList& Filters,
61                                         QString Dir=QString(),
62                                         int SelectedFilter=-1);
63         static QStringList openExistingFiles(QWidget* parent, const QString& Name,
64                                              const QString& Title,
65                                              const QStringList& Filters,
66                                              const QString Dir=QString(),
67                                              int SelectedFilter=-1);
68         static QString saveFile(QWidget* parent, const QString& Name,
69                                 const QString& Title,
70                                 const QStringList& Filters,
71                                 bool ShowOverwriteWarning=true,
72                                 QString Dir=QString(),
73                                 int SelectedFilter=-1);         
74         private:
75         static IFileDialog* iFileDialog;
76 };
77
78
79 class QtStandardFileDialogs:public QObject,public IFileDialog{
80         Q_OBJECT        
81         Q_INTERFACES(IFileDialog);
82         public:
83         QString openExistingFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter);
84         QStringList openExistingFilesDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter);          
85         QString saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter,bool ShowOverwriteWarning);
86         int getLastFilter();
87         private:
88         static QString toSingleStringFilter(const QStringList& filterList);
89         int LastFilter;
90 };
91
92 extern FileDlgHistory fileDlgHistory; 
93  
94 #endif