summaryrefslogtreecommitdiff
path: root/libopie/ofileselector/ofileselector.h
blob: bf9a26b00fc1ad73292c7cc8222d973191f11a6c (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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/*
  This is based on code and ideas of
  L. J. Potter ljp@llornkcor.com
  Thanks a lot


               =.            This file is part of the OPIE Project
             .=l.            Copyright (c)  2002 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.

*/

#ifndef opiefileselector_h
#define opiefileselector_h

#include <qpe/fileselector.h>

#include <qdir.h>
#include <qwidget.h>
#include <qstring.h>
#include <qpixmap.h>
#include <qstringlist.h>
#include <qmap.h>
#include <qvaluelist.h>

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

/** This is OPIEs FileDialog Widget. You can use it
 *  as a dropin replacement of the fileselector and
 *  or use any of the new features.
 *  This is also a complete FileSave and FileLoad widget
 *  If you look for a Dialog check OFileDialog
 *
 */
class DocLnk;
class QCheckBox;
class QComboBox;
class QPushButton;
class QGridLayout;
class QLineEdit;
class QLabel;
class QWidgetStack;
class QHBoxLayout;
class QVBoxLayout;
class QPopupMenu;
class QFileInfo;
class QHBox;
class OFileView;
class OLister;
class OFileSelectorMain;
//

/* the mimetypes one name and a list of mimetypes */
typedef QMap< QString, QStringList> MimeTypes;

/**
 * FIXME later
 */
struct OPopupMenuFactory {
    OPopupMenuFactory() {}

};


/**
 * Opie the default OFileSelector
 * It features multiple views.
 */
class OFileSelector : public QWidget {
  Q_OBJECT

  /* friends are evil but I don't want to make the
   * methods public
   */
  friend class OLister;
  friend class OFileView;
 public:
  /**
   *  The mode of the file selector
   *  Either open, save, fileselector or dir browsing mode
   *
   */
  enum Mode {Open = 1, Save = 2, Fileselector = 4, Dir = 8 };

  /**
   * Selector. Either Normal for the one shipped with
   * libqpe or Extended. for the Extended
   * ExtendedAll also shows 'hidden' files
   */
  enum Selector{Normal=0, Extended = 1, ExtendedAll = 2};

  /**
   *  This is reserved for futrue views
   */
  enum View { Dirs = 1, Files = 2, Tree = 4, Icon = 8 };

  /**
   *  A c'tor which should be used for advanced mode
   *  @param wid the parent
   *  @param mode the Mode of the Selector
   *  @param selector the current View of the Selector
   *  @param dirName in which dir to start
   *  @param fileName  a proposed filename
   *  @param mimetypes A list of mimetypes \
   *   QString is for a identifier name like "Text files"
   *   the coresponding QStringList is used for the mimetypes
   *   if empty it'll fill the list of mimetypes depending
   *   on the content of the current directory
   */

  OFileSelector(QWidget *wid, int mode, int selector,
		const QString &dirName,
		const QString &fileName = QString::null,
                const MimeTypes &mimetypes = MimeTypes() );


  /**
   * This is a QPE compatible c'tor
   */
  OFileSelector(const QString &mimeFilter, QWidget *parent,
		const char *name, bool newVisible = TRUE,
		bool closeVisible = FALSE );

  ~OFileSelector();

  // currently only for the FileSelector Mode
  /* compability mode but only work
   * with FileSelector
   */
  void setNewVisible( bool /*b*/ );
  void setCloseVisible(bool /*b*/ );

  // end file selector mode
  // deprecated
  void reread();
  // make sure not to leak please
  const DocLnk *selected();
  // end deprecated

  /**
   * @return if the toolbar is visible
   */
  bool isToolbarVisible() const { return m_shTool;  };

  /**
   * @return if the permissionBas is visible
   */
  bool isPermissionBarVisible() const {  return m_shPerm; };

  /**
   * @return if the lineEdit is visible
   */
  bool isLineEditVisible()const { return m_shLne; };

  /**
   * if the chooser is visible
   */
  bool isChooserVisible( )const { return m_shChooser; };

  /**
   * @return if the yesCancel Bar is visible
   */
  bool isYesCancelVisible()const { return m_shYesNo;  };

  /**
   * set Yes/Cancel visible
   */
  void setYesCancelVisible( bool show );

  /**
   * set the toolbar visible
   */
  void setToolbarVisible( bool show );

  /**
   * set the permissionBar to be visible
   */
  void setPermissionBarVisible( bool show );

  /**
   * set the lineedit for file entering visible
   */
  void setLineEditVisible(bool show) ;

  /**
   * set the chooser is visible
   */
  void setChooserVisible( bool chooser );

  /**
   * The permissionCheckbox
   *
   */
  QCheckBox* permissionCheckbox();

  /**
   * setPermission
   */
  bool setPermission() const;

  /**
   * set ther permission to bool
   */
  void setPermissionChecked( bool check );

  /**
   * set the Selector Mode
   */
  void setMode( int );

  /**
   * whether or not to show dirs
   */
  bool showDirs()const { return m_dir; }

  /**
   * setShowDirs
   */
  void setShowDirs(bool );

  /**
   * set CaseSensetive
   */
  bool isCaseSensetive()const {  return m_case; }

  /**
   * set if to be case sensetive
   */
  void setCaseSensetive(bool caSe );

  /**
   * @return if to show files
   */
  bool showFiles()const { return m_files; };

  /**
   * set if files should be shown
   */
  void setShowFiles(bool );

  /**
   * change dir to path
   */
  bool cd(const QString &path );


  /**
   * return the mode of the fileselector
   */
  int mode()const { return m_mode;  };

  /**
   * return the selector
   */
  int selector()const { return m_selector; };

  /**
   * set the Selector
   */
  void setSelector( int );

  /**
   * wether or not to show popups
   */
  bool showPopup()const { return m_showPopup; };

  /**
   * set show popups
   */
  void setShowPopup( bool pop ) { m_showPopup = pop; }

  /**
   * set the popup factory
   */
  void setPopupFactory( OPopupMenuFactory * );

  /**
   * reparse the current directory and updates
   * the views + mimetypes
   */
  void reparse(); // re reads the dir

  /**
   * return the selected name
   */
  QString selectedName( )const;

  /**
   * for multiple selections return multiple
   * filenames
   */
  QStringList selectedNames()const;

  /**
   * return the complete to the file
   */
  QString selectedPath() const;

  /**
   * return the completed paths
   */
  QStringList selectedPaths() const;

  /**
   * the current directory
   */
  QString directory()const;

  /**
   * fileCount
   */
  int fileCount();

  DocLnk selectedDocument()const;

  QValueList<DocLnk> selectedDocuments()const;

  OFileView* currentView();
  OFileView* currentView()const;
  OLister* currentLister()const;
  int filter();
  int sorting();
  QPixmap pixmap( const QString& );
    /* our tool bar */
  QWidget* toolBar();

 signals:
  void fileSelected( const DocLnk & );
  void fileSelected( const QString & );
  void dirSelected(const QString &dir );
  void dirSelected( const QDir& );
  void closeMe();
  void ok();
  void cancel();
  void contextMenu();

 private slots:
  void slotOk();
  void slotCancel();
  void slotViewCheck(const QString & );
  void slotMimeCheck(const QString & );
  void slotLocationActivated(const QString & );
  void slotInsertLocationPath(const QString &, int);
  void locationComboChanged();

 private:
  void init();
  void updateMimes();


 private:

    OFileSelectorMain* m_mainView;
    OLister* m_lister;
    OFileView* m_fileView;
    FileSelector* m_select;
    int m_mode, m_selector;
    QComboBox *m_location,
      *m_mimeCheck,
      *m_viewCheck;

    QPushButton *m_homeButton,
      *m_docButton,
      *m_hideButton,
      *m_ok, *m_cancel;
    QPushButton  *m_reread,
      *m_up,
      *m_new,
      *m_close;
    QListView *m_View;
    QCheckBox *m_checkPerm;
    QWidget *m_pseudo;
    QVBoxLayout *m_pseudoLayout;

    QString m_currentDir;
    QString m_name;

    QMap<QString, QStringList> m_mimetypes;

    QVBoxLayout *m_lay;
    QGridLayout *m_Oselector;

    QHBox *m_boxToolbar;
    QHBox *m_boxOk;
    QHBox *m_boxName;
    QHBox *m_boxView;


    QLineEdit *m_edit;
    QLabel *m_fnLabel;

    bool m_shClose     : 1;
    bool m_shNew       : 1;
    bool m_shTool      : 1;
    bool m_shPerm      : 1;
    bool m_shLne       : 1;
    bool m_shChooser   : 1;
    bool m_shYesNo     : 1;
    bool m_boCheckPerm : 1;
    bool m_autoMime    : 1;
    bool m_case        : 1;
    bool m_dir         : 1;
    bool m_files       : 1;
    bool m_showPopup   : 1;
    bool m_showHidden : 1;

    void initVars();

    void delItems();
    void initializeName();
    void initializeYes();
    void initializeChooser();
    void initializePerm();
    void initPics();
    bool compliesMime(const QString &path,
                      const QString &mime);
    bool compliesMime(const QString& mime );
    /**
     * Updates the QComboBox with the current mimetypes
     */
    void updateMimeCheck();

    void initializeOldSelector();
    void initLister();
    void initToolbar();
    void initLocations();
    void initializeView() {}; // FIXME
    /**
     * Returns the current mimetype
     */
    QString currentMimeType()const;
    class OFileSelectorPrivate;
    OFileSelectorPrivate *d;
    static QMap<QString,QPixmap> *m_pixmaps;

private slots:
    void slotFileSelected(const QString & ); // not really meant to be a slot
    void slotFileBridgeSelected( const DocLnk & );
    // listview above
    // popup below
    virtual void slotDelete();
    virtual void cdUP();
    virtual void slotHome();
    virtual void slotDoc();
    virtual void slotNavigate( );

    /* for OLister */
private:

    /* for OFileView */
private:
    void internFileSelected( const QString& );
    void internFileSelected( const DocLnk& );
    void internContextMenu();
    void internChangedDir( const QString& );
    void internChangedDir( const QDir& ) ;

};


#endif