Diffstat (limited to 'noncore/apps/opie-reader/fileBrowser.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/fileBrowser.cpp | 76 |
1 files changed, 49 insertions, 27 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 | |||
@@ -9,48 +9,35 @@ Extensive modification by Tim Wentford to allow it to work in rotated mode | |||
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" ) ); |
@@ -78,16 +65,32 @@ fileBrowser::fileBrowser( bool allownew, QWidget* parent, const char* name, boo | |||
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() )); |
@@ -111,14 +114,13 @@ fileBrowser::fileBrowser( bool allownew, QWidget* parent, const char* name, boo | |||
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)); |
@@ -129,13 +131,13 @@ fileBrowser::~fileBrowser() | |||
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); |
@@ -153,34 +155,34 @@ void fileBrowser::populateList() | |||
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 | ||
@@ -229,15 +231,13 @@ 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 | } |
@@ -261,6 +261,28 @@ void fileBrowser::onReturn() | |||
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 | } | ||