Diffstat (limited to 'noncore/apps/opie-reader/fileBrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/fileBrowser.cpp | 84 |
1 files changed, 53 insertions, 31 deletions
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp index 72a1222..2291c85 100644 --- a/noncore/apps/opie-reader/fileBrowser.cpp +++ b/noncore/apps/opie-reader/fileBrowser.cpp | |||
@@ -1,204 +1,206 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | 2 | ||
3 | Derived from a file browser which was | 3 | Derived from a file browser which was |
4 | 4 | ||
5 | ** copyright 2001 ljp ljp@llornkcor.com | 5 | ** copyright 2001 ljp ljp@llornkcor.com |
6 | 6 | ||
7 | Extensive modification by Tim Wentford to allow it to work in rotated mode | 7 | Extensive modification by Tim Wentford to allow it to work in rotated mode |
8 | 8 | ||
9 | ****************************************************************************/ | 9 | ****************************************************************************/ |
10 | #include "fileBrowser.h" | 10 | #include "fileBrowser.h" |
11 | 11 | ||
12 | #include "QtrListView.h" | 12 | #include "QtrListView.h" |
13 | #include <qlineedit.h> | 13 | #include <qlineedit.h> |
14 | #include <qpushbutton.h> | 14 | #include <qpushbutton.h> |
15 | #include <qfile.h> | ||
16 | #include <qmessagebox.h> | ||
15 | #ifndef _WINDOWS | 17 | #ifndef _WINDOWS |
16 | #include <unistd.h> | 18 | #include <unistd.h> |
17 | #endif | 19 | #endif |
18 | #include <qlayout.h> | 20 | #include <qlayout.h> |
19 | #ifdef _WINDOWS | 21 | #ifdef _WINDOWS |
20 | #include <direct.h> | 22 | #include <direct.h> |
21 | #endif | 23 | #endif |
22 | 24 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | |||
25 | |||
26 | fileBrowser::fileBrowser( bool allownew, QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) | 25 | fileBrowser::fileBrowser( bool allownew, QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) |
27 | : QDialog( parent, name, true, | 26 | : QDialog( parent, name, true, |
28 | fl/* | WStyle_Customize | WStyle_Tool*/), | 27 | fl/* | WStyle_Customize | WStyle_Tool*/), |
29 | filterspec(QDir::All) | 28 | filterspec(QDir::All) |
30 | { | 29 | { |
31 | // showMaximized(); | 30 | // showMaximized(); |
32 | if ( !name ) | 31 | if ( !name ) |
33 | setName( "fileBrowser" ); | 32 | setName( "fileBrowser" ); |
34 | /* | ||
35 | if (parent != NULL) | ||
36 | { | ||
37 | #ifdef OPIE | ||
38 | move(0,0); | ||
39 | resize( parent->width(), parent->height() ); | ||
40 | #else | ||
41 | setGeometry(parent->x(), parent->y(), parent->width(), parent->height() ); | ||
42 | #endif | ||
43 | } | ||
44 | */ | ||
45 | // showFullScreen(); | ||
46 | setCaption(tr( "Browse for file" ) ); | 33 | setCaption(tr( "Browse for file" ) ); |
47 | filterStr=filter; | 34 | filterStr=filter; |
48 | 35 | ||
49 | buttonOk = new QPushButton( this, "buttonOk" ); | 36 | buttonOk = new QPushButton( this, "buttonOk" ); |
50 | buttonOk->setFixedSize( 25, 25 ); | 37 | // buttonOk->setFixedSize( 25, 25 ); |
51 | buttonOk->setAutoDefault( false ); | 38 | buttonOk->setAutoDefault( false ); |
52 | buttonOk->setText( tr( "/" ) ); | 39 | buttonOk->setText( tr( "/" ) ); |
53 | 40 | ||
54 | buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); | 41 | buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); |
55 | // buttonShowHidden->setFixedSize( 50, 25 ); | 42 | // buttonShowHidden->setFixedSize( 50, 25 ); |
56 | buttonShowHidden->setText( tr( "Hidden" ) ); | 43 | buttonShowHidden->setText( tr( "Hidden" ) ); |
57 | buttonShowHidden->setAutoDefault( false ); | 44 | buttonShowHidden->setAutoDefault( false ); |
58 | buttonShowHidden->setToggleButton( true ); | 45 | buttonShowHidden->setToggleButton( true ); |
59 | buttonShowHidden->setOn( false ); | 46 | buttonShowHidden->setOn( false ); |
60 | 47 | ||
61 | dirLabel = new QLabel(this, "DirLabel"); | 48 | dirLabel = new QLabel(this, "DirLabel"); |
62 | dirLabel->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak); | 49 | dirLabel->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak); |
63 | dirLabel->setText(currentDir.canonicalPath()); | 50 | dirLabel->setText(currentDir.canonicalPath()); |
64 | 51 | ||
65 | ListView = new QtrListView( this, "ListView" ); | 52 | ListView = new QtrListView( this, "ListView" ); |
66 | ListView->addColumn( tr( "Name" ) ); | 53 | ListView->addColumn( tr( "Name" ) ); |
67 | ListView->setSorting( 2, FALSE); | 54 | ListView->setSorting( 2, FALSE); |
68 | ListView->addColumn( tr( "Size" ) ); | 55 | ListView->addColumn( tr( "Size" ) ); |
69 | ListView->setSelectionMode(QListView::Single); | 56 | ListView->setSelectionMode(QListView::Single); |
70 | ListView->setAllColumnsShowFocus( TRUE ); | 57 | ListView->setAllColumnsShowFocus( TRUE ); |
71 | ListView->setColumnWidthMode(0, QListView::Manual); | 58 | ListView->setColumnWidthMode(0, QListView::Manual); |
72 | ListView->setColumnWidthMode(1, QListView::Manual); | 59 | ListView->setColumnWidthMode(1, QListView::Manual); |
73 | 60 | ||
74 | // signals and slots connections | 61 | // signals and slots connections |
75 | connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); | 62 | connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); |
76 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); | 63 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); |
77 | connect( ListView, SIGNAL(doubleClicked(QListViewItem*)), SLOT(listDoubleClicked(QListViewItem*)) ); | 64 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); |
78 | connect( ListView, SIGNAL(clicked(QListViewItem*)), SLOT(listClicked(QListViewItem*)) ); | 65 | connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
79 | connect( ListView, SIGNAL(OnOKButton(QListViewItem*)), SLOT(listClicked(QListViewItem*)) ); | 66 | connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
80 | connect( ListView, SIGNAL(OnCentreButton(QListViewItem*)), SLOT(listClicked(QListViewItem*)) ); | 67 | connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
81 | connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); | 68 | connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); |
82 | 69 | ||
83 | QVBoxLayout* grid = new QVBoxLayout(this); | 70 | QVBoxLayout* grid = new QVBoxLayout(this); |
71 | grid->addWidget(dirLabel); | ||
84 | QHBoxLayout* hgrid = new QHBoxLayout(grid); | 72 | QHBoxLayout* hgrid = new QHBoxLayout(grid); |
85 | hgrid->addWidget(dirLabel,1); | 73 | |
86 | hgrid->addWidget(buttonShowHidden); | 74 | QPushButton* bt = new QPushButton( this ); |
75 | bt->setText( tr( "SD" ) ); | ||
76 | connect( bt, SIGNAL( clicked() ), this, SLOT( onSD() ) ); | ||
77 | hgrid->addWidget(bt); | ||
78 | |||
79 | bt = new QPushButton( this ); | ||
80 | bt->setText( tr( "CF" ) ); | ||
81 | connect( bt, SIGNAL( clicked() ), this, SLOT( onCF() ) ); | ||
82 | hgrid->addWidget(bt); | ||
83 | |||
84 | bt = new QPushButton( this ); | ||
85 | bt->setText( tr( "Home" ) ); | ||
86 | connect( bt, SIGNAL( clicked() ), this, SLOT( onHome() ) ); | ||
87 | hgrid->addWidget(bt); | ||
88 | |||
87 | hgrid->addWidget(buttonOk); | 89 | hgrid->addWidget(buttonOk); |
90 | hgrid->addWidget(buttonShowHidden); | ||
88 | grid->addWidget(ListView,1); | 91 | grid->addWidget(ListView,1); |
89 | if (allownew) | 92 | if (allownew) |
90 | { | 93 | { |
91 | m_filename = new QLineEdit(this); | 94 | m_filename = new QLineEdit(this); |
92 | grid->addWidget(m_filename); | 95 | grid->addWidget(m_filename); |
93 | connect( m_filename, SIGNAL( returnPressed() ), this, SLOT( onReturn() )); | 96 | connect( m_filename, SIGNAL( returnPressed() ), this, SLOT( onReturn() )); |
94 | } | 97 | } |
95 | else | 98 | else |
96 | { | 99 | { |
97 | m_filename = NULL; | 100 | m_filename = NULL; |
98 | } | 101 | } |
99 | 102 | ||
100 | if (QFileInfo(iPath).exists()) | 103 | if (QFileInfo(iPath).exists()) |
101 | { | 104 | { |
102 | currentDir.setPath(iPath); | 105 | currentDir.setPath(iPath); |
103 | #ifdef _WINDOWS | 106 | #ifdef _WINDOWS |
104 | _chdir(iPath.latin1()); | 107 | _chdir(iPath.latin1()); |
105 | #else | 108 | #else |
106 | chdir(iPath.latin1()); | 109 | chdir(iPath.latin1()); |
107 | #endif | 110 | #endif |
108 | } | 111 | } |
109 | else | 112 | else |
110 | { | 113 | { |
111 | currentDir.setPath(QDir::currentDirPath()); | 114 | currentDir.setPath(QDir::currentDirPath()); |
112 | chdir(QDir::currentDirPath().latin1()); | 115 | chdir(QDir::currentDirPath().latin1()); |
113 | } | 116 | } |
114 | 117 | ||
115 | populateList(); | 118 | populateList(); |
116 | 119 | ||
117 | if (modal) | 120 | if (modal) showMaximized(); |
118 | QPEApplication::showDialog( this ); | ||
119 | } | 121 | } |
120 | 122 | ||
121 | void fileBrowser::resizeEvent(QResizeEvent* e) | 123 | void fileBrowser::resizeEvent(QResizeEvent* e) |
122 | { | 124 | { |
123 | ListView->setColumnWidth(1,(ListView->width())/4); | 125 | ListView->setColumnWidth(1,(ListView->width())/4); |
124 | ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1)); | 126 | ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1)); |
125 | } | 127 | } |
126 | 128 | ||
127 | fileBrowser::~fileBrowser() | 129 | fileBrowser::~fileBrowser() |
128 | { | 130 | { |
129 | } | 131 | } |
130 | 132 | ||
131 | 133 | ||
132 | void fileBrowser::populateList() | 134 | void fileBrowser::populateList() |
133 | { | 135 | { |
134 | ListView->clear(); | 136 | ListView->clear(); |
135 | ////odebug << currentDir.canonicalPath() << oendl; | 137 | ////qDebug(currentDir.canonicalPath()); |
136 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); | 138 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); |
137 | currentDir.setFilter( filterspec ); | 139 | currentDir.setFilter( filterspec ); |
138 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 140 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
139 | currentDir.setMatchAllDirs(TRUE); | 141 | currentDir.setMatchAllDirs(TRUE); |
140 | 142 | ||
141 | currentDir.setNameFilter(filterStr); | 143 | currentDir.setNameFilter(filterStr); |
142 | // currentDir.setNameFilter("*.txt;*.etx"); | 144 | // currentDir.setNameFilter("*.txt;*.etx"); |
143 | QString fileL, fileS; | 145 | QString fileL, fileS; |
144 | const QFileInfoList *list = currentDir.entryInfoList(); | 146 | const QFileInfoList *list = currentDir.entryInfoList(); |
145 | QFileInfoListIterator it(*list); | 147 | QFileInfoListIterator it(*list); |
146 | QFileInfo *fi; | 148 | QFileInfo *fi; |
147 | while ( (fi=it.current()) ) | 149 | while ( (fi=it.current()) ) |
148 | { | 150 | { |
149 | if (fi->fileName() != ".") | 151 | if (fi->fileName() != ".") |
150 | { | 152 | { |
151 | fileS.sprintf( "%10li", fi->size() ); | 153 | fileS.sprintf( "%10li", fi->size() ); |
152 | fileL.sprintf( "%s",fi->fileName().data() ); | 154 | fileL.sprintf( "%s",fi->fileName().data() ); |
153 | if( fi->isDir() ) | 155 | if( fi->isDir() ) |
154 | { | 156 | { |
155 | fileL+="/"; | 157 | fileL+="/"; |
156 | } | 158 | } |
157 | else | 159 | else |
158 | { | 160 | { |
159 | //// odebug << "Not a dir: "+currentDir.canonicalPath()+fileL << oendl; | 161 | //// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
160 | } | 162 | } |
161 | new QListViewItem( ListView,fileL,fileS ); | 163 | new QListViewItem( ListView,fileL,fileS ); |
162 | } | 164 | } |
163 | ++it; | 165 | ++it; |
164 | } | 166 | } |
165 | ListView->setSorting( 2, FALSE); | 167 | ListView->setSorting( 2, FALSE); |
166 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); | 168 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); |
167 | ListView->setFocus(); | 169 | ListView->setFocus(); |
168 | } | 170 | } |
169 | 171 | ||
170 | void fileBrowser::upDir() | 172 | void fileBrowser::upDir() |
171 | { | 173 | { |
172 | //// odebug << currentDir.canonicalPath() << oendl; | 174 | //// qDebug(currentDir.canonicalPath()); |
173 | } | 175 | } |
174 | 176 | ||
175 | void fileBrowser::listClicked(QListViewItem *selectedItem) | 177 | void fileBrowser::listClicked(QListViewItem *selectedItem) |
176 | { | 178 | { |
177 | if (selectedItem == NULL) return; | 179 | if (selectedItem == NULL) return; |
178 | QString strItem=selectedItem->text(0); | 180 | QString strItem=selectedItem->text(0); |
179 | 181 | ||
180 | //// odebug << "" << strItem << "" << oendl; | 182 | //// qDebug("%s", (const char*)strItem); |
181 | 183 | ||
182 | 184 | ||
183 | QString strSize=selectedItem->text(1); | 185 | QString strSize=selectedItem->text(1); |
184 | 186 | ||
185 | strSize.stripWhiteSpace(); | 187 | strSize.stripWhiteSpace(); |
186 | 188 | ||
187 | bool ok; | 189 | bool ok; |
188 | 190 | ||
189 | QFileInfo fi(strItem); | 191 | QFileInfo fi(strItem); |
190 | while (fi.isSymLink()) fi.setFile(fi.readLink()); | 192 | while (fi.isSymLink()) fi.setFile(fi.readLink()); |
191 | if (fi.isDir()) | 193 | if (fi.isDir()) |
192 | { | 194 | { |
193 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 195 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
194 | 196 | ||
195 | if(QDir(strItem).exists()) | 197 | if(QDir(strItem).exists()) |
196 | { | 198 | { |
197 | currentDir.cd(strItem, TRUE); | 199 | currentDir.cd(strItem, TRUE); |
198 | populateList(); | 200 | populateList(); |
199 | } | 201 | } |
200 | } else | 202 | } else |
201 | { | 203 | { |
202 | QListViewItem *selectedItem = ListView->selectedItem(); | 204 | QListViewItem *selectedItem = ListView->selectedItem(); |
203 | if (selectedItem == NULL) | 205 | if (selectedItem == NULL) |
204 | { | 206 | { |
@@ -211,56 +213,76 @@ void fileBrowser::listClicked(QListViewItem *selectedItem) | |||
211 | OnOK(); | 213 | OnOK(); |
212 | } | 214 | } |
213 | chdir(strItem.latin1()); | 215 | chdir(strItem.latin1()); |
214 | // | 216 | // |
215 | 217 | ||
216 | } | 218 | } |
217 | 219 | ||
218 | // you may want to switch these 2 functions. I like single clicks | 220 | // you may want to switch these 2 functions. I like single clicks |
219 | void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) | 221 | void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) |
220 | { | 222 | { |
221 | } | 223 | } |
222 | 224 | ||
223 | QString fileBrowser::getCurrentFile() | 225 | QString fileBrowser::getCurrentFile() |
224 | { | 226 | { |
225 | return filename; | 227 | return filename; |
226 | } | 228 | } |
227 | 229 | ||
228 | void fileBrowser::OnOK() | 230 | void fileBrowser::OnOK() |
229 | { | 231 | { |
230 | accept(); | 232 | accept(); |
231 | } | 233 | } |
232 | 234 | ||
233 | void fileBrowser::OnRoot() | 235 | void fileBrowser::OnRoot() |
234 | { | 236 | { |
235 | currentDir.cd("/", TRUE); | 237 | setdir("/"); |
236 | populateList(); | ||
237 | chdir("/"); | ||
238 | } | 238 | } |
239 | 239 | ||
240 | void fileBrowser::OnCancel() | 240 | void fileBrowser::OnCancel() |
241 | { | 241 | { |
242 | reject(); | 242 | reject(); |
243 | } | 243 | } |
244 | 244 | ||
245 | void fileBrowser::setHidden(bool _hidden) | 245 | void fileBrowser::setHidden(bool _hidden) |
246 | { | 246 | { |
247 | if (_hidden) | 247 | if (_hidden) |
248 | filterspec = QDir::All | QDir::Hidden; | 248 | filterspec = QDir::All | QDir::Hidden; |
249 | else | 249 | else |
250 | filterspec = QDir::All; | 250 | filterspec = QDir::All; |
251 | populateList(); | 251 | populateList(); |
252 | } | 252 | } |
253 | 253 | ||
254 | void fileBrowser::onReturn() | 254 | void fileBrowser::onReturn() |
255 | { | 255 | { |
256 | QListViewItem *selectedItem = ListView->selectedItem(); | 256 | QListViewItem *selectedItem = ListView->selectedItem(); |
257 | if (selectedItem == NULL) | 257 | if (selectedItem == NULL) |
258 | { | 258 | { |
259 | filename = m_filename->text(); | 259 | filename = m_filename->text(); |
260 | } | 260 | } |
261 | else | 261 | else |
262 | { | 262 | { |
263 | filename = QDir::cleanDirPath(currentDir.canonicalPath()+"/"+m_filename->text()); | 263 | filename = QDir::cleanDirPath(currentDir.canonicalPath()+"/"+m_filename->text()); |
264 | } | 264 | } |
265 | OnOK(); | 265 | OnOK(); |
266 | } | 266 | } |
267 | |||
268 | void fileBrowser::onCF() | ||
269 | { | ||
270 | setdir("/mnt/cf"); | ||
271 | } | ||
272 | |||
273 | void fileBrowser::onSD() | ||
274 | { | ||
275 | setdir("/mnt/card"); | ||
276 | } | ||
277 | |||
278 | void fileBrowser::onHome() | ||
279 | { | ||
280 | setdir(QDir::homeDirPath()); | ||
281 | } | ||
282 | |||
283 | void fileBrowser::setdir(const QString& s) | ||
284 | { | ||
285 | currentDir.cd(s, TRUE); | ||
286 | populateList(); | ||
287 | chdir(s); | ||
288 | } | ||