summaryrefslogtreecommitdiffabout
path: root/microkde/ofileselector_p.h
blob: a7d97fec772976e9da16870760c0c583137b6551 (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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#ifndef OPIE_OFILE_SELECTOR_PRIVATE_H
#define OPIE_OFILE_SELECTOR_PRIVATE_H

//US
#pragma message("microkde/ofileselector_p.h")

#include <qmap.h>
#include <qstringlist.h>
#include <qwidget.h>
#include <qlistview.h>

#include <qpe/applnk.h>
#include <qpe/fileselector.h>


/*
 * How to avoid having really two different objects
 * for Extended and ExtendedAll
 * The only difference is the Lister...
 * a) static object?
 * b) leave some object inside the OFileSelector which can be used?
 * c) when switching views tell which view we want o have.. internally we can switch then
 *
 * I'll take c) -zecke
 */


/* the View Interface */
class OFileSelector;
typedef QMap<QString, QStringList> MimeTypes;
class QFileInfo;
class QToolButton;
class OFileViewInterface {
public:
    OFileViewInterface( OFileSelector* selector );
    virtual ~OFileViewInterface();
    virtual QString selectedName()const = 0;
    virtual QString selectedPath()const = 0;
    virtual QString directory()const = 0;
    virtual void reread() = 0;
    virtual int fileCount()const = 0;
    virtual DocLnk selectedDocument()const;
    virtual QWidget* widget( QWidget* parent) = 0;
    virtual void activate( const QString& );
    QString name()const;
protected:
    OFileSelector* selector()const;
    void setName( const QString& );
    bool showNew()const;
    bool showClose()const;
    MimeTypes mimeTypes()const;
    QStringList currentMimeType()const;
    QString startDirectory()const;
protected:
    void ok();
    void cancel();
    void closeMe();
    void fileSelected( const QString& );
    void fileSelected( const DocLnk& );
    void setCurrentFileName( const QString& );
    QString currentFileName()const;

private:
    QString m_name;
    OFileSelector* m_selector;
};


/* THE Document View hosting a FileSelector*/
class ODocumentFileView : public OFileViewInterface {
public:
    ODocumentFileView( OFileSelector* selector );
    ~ODocumentFileView();

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

    QString directory() const;
    void reread();
    int fileCount()const;
    DocLnk selectedDocument()const;

    QWidget* widget( QWidget* parent );

private:
    mutable FileSelector* m_selector;

};

class OFileSelectorItem : public QListViewItem {
public:
    OFileSelectorItem( QListView* view, const QPixmap& pixmap,
                       const QString& path, const QString& date,
                       const QString& size, const QString& mDir,
                       bool isLocked = false, bool isDir = false );
    ~OFileSelectorItem();
    bool isLocked()const;
    bool isDir()const;
    QString directory()const;
    QString path()const;
    QString key(int id, bool )const;

private:
    bool m_locked : 1;
    bool m_isDir    : 1;
    QString m_dir;
};

class OFileViewFileListView : public QWidget {
    Q_OBJECT
public:
    OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector );
    ~OFileViewFileListView();

    OFileSelectorItem* currentItem()const;
    void reread( bool all = false );
    int fileCount()const;
    QString currentDir()const;
protected:
    bool eventFilter (QObject *o, QEvent *e);
private slots:
    void slotNew(); // will emit newSelected
    void cdUP();
    void cdHome();
    void cdDoc();
    void changeDir( const QString& );
    void slotCurrentChanged( QListViewItem* );
    void slotClicked(int, QListViewItem*, const QPoint&, int );
    void slotDoubleClicked(QListViewItem*);
    void slotFSActivated(int);

protected:

    OFileSelector* selector();

private:
    QMap<QString, QString> m_dev;
    bool m_all : 1;
    OFileSelector* m_sel;
    Q3PopupMenu* m_fsPop;
    bool compliesMime( const QString& );
    QStringList m_mimes; // used in compy mime
    QString m_currentDir;
    QToolButton *m_btnNew, *m_btnClose;
    void connectSlots();
    void addFile( QFileInfo* info, bool symlink = FALSE );
    void addDir ( QFileInfo* info, bool symlink = FALSE );
    void addSymlink( QFileInfo* info, bool = FALSE );


private:
    QListView* m_view;
};

typedef QMap<QString, QStringList> MimeTypes;

class OFileViewInterface;
class OFileViewFileListView;
class QLineEdit;
class QComboBox;
class QWidgetStack;
class QHBox;
class OFileSelector : public QWidget {
    Q_OBJECT
    friend class OFileViewInterface;
    friend class OFileViewFileListView;
public:
    enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
//    enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
    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;


    void setNewVisible( bool b );
    void setCloseVisible( bool b );
    void setNameVisible( bool b );

signals:
    void dirSelected( const QString& );
    void fileSelected( const DocLnk& );
    void fileSelected( const QString& );
    void newSelected( const DocLnk& );
    void closeMe();
    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();

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
    OFileViewInterface* currentView()const; // returns the currentView
    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, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
    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;

    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