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