summaryrefslogtreecommitdiff
path: root/libopie2/opieui/fileselector/ofileselector.h
blob: d166afd63fa58c86e1700a468f7213889e1d3240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
               =.            This file is part of the OPIE Project
             .=l.            Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|.         This library is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This library is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

/*
  This is based on code and ideas of
  L. J. Potter ljp@llornkcor.com
  Thanks a lot
*/

#ifndef OFILESELECTOR_H
#define OFILESELECTOR_H

/* OPIE */
#include <qpe/applnk.h>

/* QT */
#include <qlist.h>
#include <qwidget.h>
#include <qmap.h>
#include <qvaluelist.h>
#include <qstringlist.h>
#include <qlist.h>

class QLineEdit;
class QComboBox;
class QWidgetStack;
class QHBox;

typedef QMap<QString, QStringList> MimeTypes;

namespace Opie {
namespace Ui   {

namespace Internal {
class OFileViewInterface;
class OFileViewFileListView;
}


/**
 * @short a dropin replacement for the FileSelector
 *
 * This class is first used insert the OFileDialog.
 * It supports multiple view and mimetype filtering for now.
 *
 * @see OFileDialog
 * @see FileSelector
 * @author zecke
 * @version 0.1
 */
class OFileSelector : public QWidget
{
    Q_OBJECT
    friend class Internal::OFileViewInterface;
    friend class Internal::OFileViewFileListView;

public:
    /**
     * The Mode of the Fileselector
     * Open = Open A File
     * Save = Save a File
     * FILESELECTOR = As A GUI in a screen to select a file
     * SelectDir = Select a Directory
     */
    enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, FILESELECTOR = 4 };
    //    enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
    /**
     * Normal       = The old FileSelector
     * Extended     = Dir View
     * ExtendedAll  = Dir View with all hidden files
     * Default      = What the vendor considers best
     */
    enum Selector { Normal = 0, Extended=1,  ExtendedAll =2, Default=3,  NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
    //    enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};

    OFileSelector(QWidget* parent, int mode, int selector,
                  const QString& dirName,
                  const QString& fileName,
                  const MimeTypes& mimetypes = MimeTypes(),
                  bool newVisible = FALSE, bool closeVisible = FALSE );

    OFileSelector(const QString& mimeFilter, QWidget* parent,
                  const char* name = 0,  bool newVisible = TRUE, bool closeVisible = FALSE );
    ~OFileSelector();

    const DocLnk* selected();

    QString selectedName()const;
    QString selectedPath()const;
    QString directory()const;

    DocLnk selectedDocument()const;

    int fileCount()const;
    void reread();

    int mode()const;
    int selector()const;

    /**
     * Set the Icon visible
     * @param b Show or Hide the New Button
     */
    void setNewVisible( bool b );

    /**
     * Set the Icon visible
     */
    void setCloseVisible( bool b );

    /**
     * Set the Name Line visible
     */
    void setNameVisible( bool b );

signals:
   /**
    * dirSelected is emitted whenever changed into a different dir
    */
    void dirSelected( const QString& );

   /**
    * fileSelected  is emitted when a file is selected
    * it uses a DocLnk as parameter
    */
    void fileSelected( const DocLnk& );

    /**
     * fileSelected is emitted when a file is selected
     * the complete path is a parameter
     */
    void fileSelected( const QString& );

    /**
     * Create a new File with a DocLnk
     */
    void newSelected( const DocLnk& );

    void closeMe();

   /**
    * Ok is emitted on a Qt::Key_Return or Q::Key_Enter
    * in the line edit
    */
    void ok();
    void cancel();

    /* used by the ViewInterface */
private:
    bool showNew()const;
    bool showClose()const;
    MimeTypes mimeTypes()const;
    QStringList currentMimeType()const;

private:
    /* inits the Widgets */
    void initUI();
    /* inits the MimeType ComboBox content + connects signals and slots */
    void initMime();
    /* init the Views :) */
    void initViews();


    /*
     * register a view for deletion.
     * This happens on creation of a OFileViewInterface
     */
    void registerView( const Internal::OFileViewInterface* );

private:
    QLineEdit* m_lneEdit; // the LineEdit for the Name
    QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
    QWidgetStack* m_stack;  // our widget stack which will contain the views
    Internal::OFileViewInterface* currentView() const; // returns the currentView
    Internal::OFileViewInterface* m_current; // here is the view saved
    bool m_shNew   : 1; // should we show New?
    bool m_shClose : 1; // should we show Close?
    MimeTypes m_mimeType; // list of mimetypes

    QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
    /* views register themselves automatically */
    QList<Internal::OFileViewInterface> m_viewsPtr;
    QHBox* m_nameBox; // the LineEdit + Label is hold here
    QHBox* m_cmbBox; // this holds the two combo boxes

    QString m_startDir;
    int m_mode;
    int m_selector;

    QStringList m_allList;

    struct Data; // used for future versions
    Data *d;

private slots:
    void slotMimeTypeChanged();

    /* will set the text of the lineedit and emit a fileChanged signal */
    void slotDocLnkBridge( const DocLnk& );
    void slotFileBridge( const QString& );
    void slotViewChange( const QString& );

    bool eventFilter (QObject *o, QEvent *e);

};

}
}

#endif