summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofiledialog.cc110
-rw-r--r--libopie/ofiledialog.h77
-rw-r--r--libopie/ofileselector.cc2
-rw-r--r--libopie/ofileselector.h7
4 files changed, 192 insertions, 4 deletions
diff --git a/libopie/ofiledialog.cc b/libopie/ofiledialog.cc
new file mode 100644
index 0000000..92b0d0a
--- a/dev/null
+++ b/libopie/ofiledialog.cc
@@ -0,0 +1,110 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include <qpe/applnk.h>
30#include <qstring.h>
31#include <qapplication.h>
32#include <qlayout.h>
33
34#include "ofiledialog.h"
35
36OFileDialog::OFileDialog(const QString &caption,
37 QWidget *wid, int mode, int selector,
38 const QString &dirName,
39 const QString &fileName,
40 const QStringList &mimetypes )
41 : QDialog( wid, "OFileDialog", true )
42{
43 QVBoxLayout *lay = new QVBoxLayout(this);
44
45 file = new OFileSelector(0 , mode, selector,
46 dirName, fileName,
47 mimetypes );
48 lay->addWidget( file );
49 //showFullScreen();
50 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
51 connect(file, SIGNAL(fileSelected(const QString&) ),
52 this, SLOT(slotFileSelected(const QString&) ) );
53
54 connect(file, SIGNAL(dirSelected(const QString &) ),
55 this, SLOT(slotDirSelected(const QString &) ) );
56 showMaximized();
57 file->setYesCancelVisible( false ); // relayout
58}
59QString OFileDialog::mimetype()const
60{
61 return QString::null;
62}
63QString OFileDialog::fileName()const
64{
65 return file->selectedName();
66}
67DocLnk OFileDialog::selectedDocument()const
68{
69 return file->selectedDocument();
70}
71QString OFileDialog::getOpenFileName(int selector,
72 const QString &startDir,
73 const QString &file,
74 const QStringList &mimes,
75 QWidget *wid,
76 const QString &caption )
77{
78 QString ret;
79 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
80 wid, OFileSelector::OPEN, selector, startDir, file, mimes);
81 if( dlg.exec() )
82 ret = dlg.fileName();
83
84 return ret;
85}
86QString OFileDialog::getSaveFileName(int selector,
87 const QString &startDir,
88 const QString &file,
89 const QStringList &mimes,
90 QWidget *wid,
91 const QString &caption )
92{
93 QString ret;
94 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
95 wid, OFileSelector::SAVE, selector, startDir, file, mimes);
96 if( dlg.exec() )
97 ret = dlg.fileName();
98
99 return ret;
100}
101
102void OFileDialog::slotFileSelected(const QString & )
103{
104 accept();
105}
106void OFileDialog::slotDirSelected(const QString & )
107{
108 // if mode
109 //accept();
110}
diff --git a/libopie/ofiledialog.h b/libopie/ofiledialog.h
new file mode 100644
index 0000000..40d147e
--- a/dev/null
+++ b/libopie/ofiledialog.h
@@ -0,0 +1,77 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29
30#ifndef OpieFileDialog_h
31#define OpieFileDialog_h
32
33#include <qdialog.h>
34
35#include <opie/ofileselector.h>
36
37class OFileDialog : public QDialog {
38 Q_OBJECT
39 public:
40 OFileDialog(const QString &caption,
41 QWidget *, int mode, int selector,
42 const QString &dirName,
43 const QString &fileName = QString::null,
44 const QStringList &mimetypes = QStringList() );
45 QString mimetype() const;
46 QString fileName() const;
47 DocLnk selectedDocument()const;
48
49 // static methods
50 static QString getOpenFileName(int selector,
51 const QString& startDir = QString::null,
52 const QString &fileName = QString::null,
53 const QStringList& mimefilter = QStringList(),
54 QWidget *wid = 0,
55 const QString &caption = QString::null );
56
57 static QString getSaveFileName(int selector,
58 const QString& startDir = QString::null,
59 const QString& fileName = QString::null,
60 const QStringList& mimefilter = QStringList(),
61 QWidget *wid = 0,
62 const QString &caption = QString::null );
63
64 //let's OFileSelector catch up first
65 //static QString getExistingDirectory(const QString& startDir = QString::null,
66 // QWidget *parent = 0,
67 // const QString& caption = QString::null );
68 private:
69 class OFileDialogPrivate;
70 OFileDialogPrivate *d;
71 OFileSelector *file;
72
73 private slots:
74 void slotFileSelected( const QString & );
75 void slotDirSelected(const QString & );
76};
77#endif
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index fbe69ed..bc7c6c2 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -32,97 +32,97 @@
32#include <qhbox.h> 32#include <qhbox.h>
33#include <qvbox.h> 33#include <qvbox.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qwidgetstack.h> 35#include <qwidgetstack.h>
36#include <qlineedit.h> 36#include <qlineedit.h>
37#include <qcheckbox.h> 37#include <qcheckbox.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qheader.h> 39#include <qheader.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qaction.h> 42#include <qaction.h>
43#include <qpopupmenu.h> 43#include <qpopupmenu.h>
44#include <qcursor.h> 44#include <qcursor.h>
45 45
46#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
47#include <qpe/fileselector.h> 47#include <qpe/fileselector.h>
48#include <qpe/applnk.h> 48#include <qpe/applnk.h>
49#include <qpe/global.h> 49#include <qpe/global.h>
50#include <qpe/mimetype.h> 50#include <qpe/mimetype.h>
51#include <qpe/resource.h> 51#include <qpe/resource.h>
52#include <qpe/storage.h> 52#include <qpe/storage.h>
53 53
54#include <unistd.h> 54#include <unistd.h>
55#include <stdlib.h> 55#include <stdlib.h>
56#include <sys/stat.h> 56#include <sys/stat.h>
57 57
58#include "ofileselector.h" 58#include "ofileselector.h"
59 59
60QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; 60QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
61 61
62namespace { 62namespace {
63 63
64 int indexByString( const QComboBox *box, const QString &str ){ 64 int indexByString( const QComboBox *box, const QString &str ){
65 int index= -1; 65 int index= -1;
66 for(int i= 0; i < box->count(); i++ ){ 66 for(int i= 0; i < box->count(); i++ ){
67 qWarning("str T%sT boxT%sT", str.latin1(), box->text(i).latin1() ); 67 qWarning("str T%sT boxT%sT", str.latin1(), box->text(i).latin1() );
68 if( str == box->text(i ) ){ 68 if( str == box->text(i ) ){
69 index= i; 69 index= i;
70 break; 70 break;
71 } 71 }
72 } 72 }
73 return index; 73 return index;
74 } 74 }
75 75
76}; 76};
77 77
78 78
79OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, 79OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName,
80 const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) 80 const QString &fileName, const QStringList &mimetypes ) : QWidget( wid )
81{ 81{
82 m_selector = selector; 82 m_selector = selector;
83 m_currentDir = dirName; 83 m_currentDir = dirName;
84 m_name = fileName; 84 m_name = fileName;
85 m_mimetypes = mimetypes; 85 m_mimetypes = mimetypes;
86 if( mimetypes.isEmpty() ) 86 if( mimetypes.isEmpty() )
87 m_autoMime = true; 87 m_autoMime = true;
88 88
89 m_mode = mode; 89 m_mode = mode;
90 m_shTool = true; 90 m_shTool = true;
91 m_shPerm = true; 91 m_shPerm = true;
92 m_shLne = true; 92 m_shLne = true;
93 m_shChooser = true; 93 m_shChooser = true;
94 m_shYesNo = true; 94 m_shYesNo = true;
95 // for FILESELECTOR only view is interesting 95 // for FILESELECTOR only view is interesting
96 m_location = 0; 96 m_location = 0;
97 m_homeButton = 0; 97 m_homeButton = 0;
98 m_docButton = 0; 98 m_docButton = 0;
99 m_hideButton = 0; 99 m_hideButton = 0;
100 m_ok = 0; 100 m_ok = 0;
101 m_cancel = 0; 101 m_cancel = 0;
102 m_reread = 0; 102 m_reread = 0;
103 m_up = 0; 103 m_up = 0;
104 m_View = 0; 104 m_View = 0;
105 m_select = 0; 105 m_select = 0;
106 m_stack = 0; 106 m_stack = 0;
107 107
108 m_select = 0; 108 m_select = 0;
109 m_stack = 0; 109 m_stack = 0;
110 m_lay = 0; 110 m_lay = 0;
111 m_boxToolbar = 0; 111 m_boxToolbar = 0;
112 m_boxOk = 0; 112 m_boxOk = 0;
113 m_edit = 0; 113 m_edit = 0;
114 114
115 m_fnLabel = 0; 115 m_fnLabel = 0;
116 m_checkPerm = 0; 116 m_checkPerm = 0;
117 m_mimeCheck = 0; 117 m_mimeCheck = 0;
118 m_viewCheck = 0; 118 m_viewCheck = 0;
119 119
120 m_pseudo = 0; 120 m_pseudo = 0;
121 m_pseudoLayout = 0; 121 m_pseudoLayout = 0;
122 122
123 m_dir = true; 123 m_dir = true;
124 m_files = true; 124 m_files = true;
125 m_custom = 0; 125 m_custom = 0;
126 m_showPopup = true; 126 m_showPopup = true;
127 127
128 if(m_pixmaps == 0 ) // init the pixmaps 128 if(m_pixmaps == 0 ) // init the pixmaps
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index bf3cb48..5e98a1e 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -71,160 +71,161 @@ class OFileSelectorItem : public QListViewItem {
71 bool isLocked=false, bool isDir=false ): QListViewItem(view) { 71 bool isLocked=false, bool isDir=false ): QListViewItem(view) {
72 setPixmap(0, pixmap ); 72 setPixmap(0, pixmap );
73 setText(1, path ); 73 setText(1, path );
74 setText(2, size ); 74 setText(2, size );
75 setText(3, date ); 75 setText(3, date );
76 //setText(4, mDir ); 76 //setText(4, mDir );
77 m_dir = mDir; 77 m_dir = mDir;
78 dir = isDir; 78 dir = isDir;
79 mLocked = isLocked; 79 mLocked = isLocked;
80 } 80 }
81 bool isLocked() const{ 81 bool isLocked() const{
82 return mLocked; 82 return mLocked;
83 } 83 }
84 QString directory()const{ 84 QString directory()const{
85 return m_dir; 85 return m_dir;
86 } 86 }
87 bool isDir()const{ 87 bool isDir()const{
88 return dir; 88 return dir;
89 } 89 }
90 QString path()const{ 90 QString path()const{
91 return text(1 ); 91 return text(1 );
92 } 92 }
93 QString key(int id, bool )const { 93 QString key(int id, bool )const {
94 QString ke; 94 QString ke;
95 if( id == 0 || id == 1 ){ // name 95 if( id == 0 || id == 1 ){ // name
96 if( dir ){ 96 if( dir ){
97 ke.append("0" ); 97 ke.append("0" );
98 ke.append( text(1) ); 98 ke.append( text(1) );
99 }else{ 99 }else{
100 ke.append("1" ); 100 ke.append("1" );
101 ke.append( text(1) ); 101 ke.append( text(1) );
102 } 102 }
103 }else if( id == 2 ){ // size 103 }else if( id == 2 ){ // size
104 return text(2); 104 return text(2);
105 }else if( id == 3 ){ // date 105 }else if( id == 3 ){ // date
106 return text(3); 106 return text(3);
107 } 107 }
108 return ke; 108 return ke;
109 }; 109 };
110 private: 110 private:
111 bool mLocked:1; 111 bool mLocked:1;
112 bool dir:1; 112 bool dir:1;
113 QString m_dir; 113 QString m_dir;
114}; 114};
115 115
116class OFileSelector : public QWidget { 116class OFileSelector : public QWidget {
117 Q_OBJECT 117 Q_OBJECT
118 public: 118 public:
119 enum Mode {OPEN=1, SAVE, FILESELECTOR }; 119 enum Mode {OPEN=1, SAVE=2, FILESELECTOR=4, DIR=8 };
120 enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; 120 enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 };
121 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; 121 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 };
122 OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); 122 OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList &mimetypes = QStringList() );
123 123 ~OFileSelector() {};
124 bool isToolbarVisible() const { return m_shTool; }; 124 bool isToolbarVisible() const { return m_shTool; };
125 bool isPermissionBarVisible() const { return m_shPerm; }; 125 bool isPermissionBarVisible() const { return m_shPerm; };
126 bool isLineEditVisible()const { return m_shLne; }; 126 bool isLineEditVisible()const { return m_shLne; };
127 bool isChooserVisible( )const { return m_shChooser; }; 127 bool isChooserVisible( )const { return m_shChooser; };
128 bool isYesCancelVisible()const { return m_shYesNo; }; 128 bool isYesCancelVisible()const { return m_shYesNo; };
129 void setYesCancelVisible( bool show ); 129 void setYesCancelVisible( bool show );
130 void setToolbarVisible( bool show ); 130 void setToolbarVisible( bool show );
131 void setPermissionBarVisible( bool show ); 131 void setPermissionBarVisible( bool show );
132 void setLineEditVisible(bool show) ; 132 void setLineEditVisible(bool show) ;
133 void setChooserVisible( bool chooser ); 133 void setChooserVisible( bool chooser );
134 134
135 QCheckBox* permissionCheckbox(); 135 QCheckBox* permissionCheckbox();
136 bool setPermission() const; 136 bool setPermission() const;
137 void setPermissionChecked( bool check ); 137 void setPermissionChecked( bool check );
138 138
139 void setMode( int ); 139 void setMode( int );
140 140
141 bool showDirs()const { return m_dir; } 141 bool showDirs()const { return m_dir; }
142 void setShowDirs(bool ); 142 void setShowDirs(bool );
143 143
144 const QListView* listView() { return m_View; }; 144 const QListView* listView() { return m_View; };
145 145
146 bool isCaseSensetive()const { return m_case; } 146 bool isCaseSensetive()const { return m_case; }
147 void setCaseSensetive(bool caSe ); 147 void setCaseSensetive(bool caSe );
148 148
149 bool showFiles()const { return m_files; }; 149 bool showFiles()const { return m_files; };
150 void setShowFiles(bool ); 150 void setShowFiles(bool );
151 bool cd(const QString &path ); 151 bool cd(const QString &path );
152 152
153 153
154 int mode()const { return m_mode; }; 154 int mode()const { return m_mode; };
155 int selector()const { return m_selector; }; 155 int selector()const { return m_selector; };
156 void setSelector( int ); 156 void setSelector( int );
157 157
158 bool showPopup()const { return m_showPopup; }; 158 bool showPopup()const { return m_showPopup; };
159 void setShowPopup( bool pop ) { m_showPopup = pop; }; 159 void setShowPopup( bool pop ) { m_showPopup = pop; };
160 void setPopupMenu( QPopupMenu * ); 160 void setPopupMenu( QPopupMenu * );
161 161
162 void updateLay(); 162 void updateLay();
163 163
164 void reparse(); // re reads the dir 164 void reparse(); // re reads the dir
165 165
166 QString selectedName( )const; 166 QString selectedName( )const;
167 QStringList selectedNames()const; 167 QStringList selectedNames()const;
168 168
169 QString selectedPath() const; 169 QString selectedPath() const;
170 QStringList selectedPaths() const; 170 QStringList selectedPaths() const;
171 171
172 QString directory()const; 172 QString directory()const;
173 int fileCount(); 173 int fileCount();
174 174
175 /* the user needs to delete it */ 175 /* the user needs to delete it */
176 DocLnk selectedDocument()const; 176 DocLnk selectedDocument()const;
177 /* the user needs to delete it */ 177 /* the user needs to delete it */
178 QValueList<DocLnk> selectedDocuments()const; 178 QValueList<DocLnk> selectedDocuments()const;
179 179
180 signals: 180 signals:
181 void fileSelected( const DocLnk & ); 181 void fileSelected( const DocLnk & );
182 void fileSelected( const QString & ); 182 void fileSelected( const QString & );
183 void dirSelected(const QString &dir );
183 void closeMe(); 184 void closeMe();
184 void ok(); 185 void ok();
185 void cancel(); 186 void cancel();
186 187
187 protected slots: 188 protected slots:
188 void slotOk(); 189 void slotOk();
189 void slotCancel(); 190 void slotCancel();
190 void slotViewCheck(const QString & ); 191 void slotViewCheck(const QString & );
191 void slotMimeCheck(const QString & ); 192 void slotMimeCheck(const QString & );
192 protected: 193 protected:
193 void init(); 194 void init();
194 void updateMimes(); 195 void updateMimes();
195 196
196 protected: 197 protected:
197 198
198 private: 199 private:
199 int m_mode, m_selector; 200 int m_mode, m_selector;
200 QComboBox *m_location, *m_mimeCheck, *m_viewCheck; 201 QComboBox *m_location, *m_mimeCheck, *m_viewCheck;
201 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; 202 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel;
202 QPushButton *m_reread, *m_up; 203 QPushButton *m_reread, *m_up;
203 QListView *m_View; 204 QListView *m_View;
204 QCheckBox *m_checkPerm; 205 QCheckBox *m_checkPerm;
205 QWidget *m_pseudo; 206 QWidget *m_pseudo;
206 QVBoxLayout *m_pseudoLayout; 207 QVBoxLayout *m_pseudoLayout;
207 208
208 QString m_currentDir; 209 QString m_currentDir;
209 QString m_name; 210 QString m_name;
210 QStringList m_mimetypes; 211 QStringList m_mimetypes;
211 212
212 FileSelector *m_select; 213 FileSelector *m_select;
213 QWidgetStack *m_stack; 214 QWidgetStack *m_stack;
214 QVBoxLayout *m_lay; 215 QVBoxLayout *m_lay;
215 QGridLayout *m_Oselector; 216 QGridLayout *m_Oselector;
216 217
217 QHBoxLayout *m_boxToolbar; 218 QHBoxLayout *m_boxToolbar;
218 QHBoxLayout *m_boxOk; 219 QHBoxLayout *m_boxOk;
219 QHBoxLayout *m_boxName; 220 QHBoxLayout *m_boxName;
220 QHBoxLayout *m_boxView; 221 QHBoxLayout *m_boxView;
221 222
222 QPopupMenu *m_custom; 223 QPopupMenu *m_custom;
223 224
224 QLineEdit *m_edit; 225 QLineEdit *m_edit;
225 QLabel *m_fnLabel; 226 QLabel *m_fnLabel;
226 bool m_shTool:1; 227 bool m_shTool:1;
227 bool m_shPerm:1; 228 bool m_shPerm:1;
228 bool m_shLne:1; 229 bool m_shLne:1;
229 bool m_shChooser:1; 230 bool m_shChooser:1;
230 bool m_shYesNo:1; 231 bool m_shYesNo:1;