author | drw <drw> | 2002-03-18 00:02:20 (UTC) |
---|---|---|
committer | drw <drw> | 2002-03-18 00:02:20 (UTC) |
commit | b02657a01fc513e099c2d66be48d5a7b46cf6074 (patch) (unidiff) | |
tree | 1222fd77f10de1b1948b38bfb5fbe5656f8fa5c6 /core/apps/textedit/fileBrowser.cpp | |
parent | 378db8490c6c80ced939622605be1500fa126a2d (diff) | |
download | opie-b02657a01fc513e099c2d66be48d5a7b46cf6074.zip opie-b02657a01fc513e099c2d66be48d5a7b46cf6074.tar.gz opie-b02657a01fc513e099c2d66be48d5a7b46cf6074.tar.bz2 |
Combined file open & filebrowse into one dialog
Diffstat (limited to 'core/apps/textedit/fileBrowser.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 2e88067..92c15cb 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp | |||
@@ -5,106 +5,124 @@ | |||
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ****************************************************************************/ | 13 | ****************************************************************************/ |
14 | #include "fileBrowser.h" | 14 | #include "fileBrowser.h" |
15 | #include <qpe/config.h> | 15 | #include <qpe/config.h> |
16 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
17 | #include <qpe/fileselector.h> | ||
17 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
18 | 19 | ||
20 | #include <qwidgetstack.h> | ||
19 | #include <qlistview.h> | 21 | #include <qlistview.h> |
22 | #include <qcombo.h> | ||
20 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
21 | #include <qfile.h> | 24 | #include <qfile.h> |
22 | #include <qmessagebox.h> | 25 | #include <qmessagebox.h> |
23 | #include <qlayout.h> | 26 | #include <qlayout.h> |
24 | #include <unistd.h> | 27 | #include <unistd.h> |
25 | 28 | ||
26 | 29 | static int u_id = 1; | |
30 | static int get_unique_id() | ||
31 | { | ||
32 | return u_id++; | ||
33 | } | ||
27 | 34 | ||
28 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) | 35 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) |
29 | : QDialog( parent, name, modal, fl ) | 36 | : QDialog( parent, name, modal, fl ) |
30 | { | 37 | { |
31 | if ( !name ) | 38 | if ( !name ) |
32 | setName( "fileBrowser" ); | 39 | setName( "fileBrowser" ); |
33 | setCaption(tr( name ) ); | 40 | setCaption(tr( name ) ); |
34 | filterStr=filter; | 41 | filterStr=filter; |
35 | 42 | ||
36 | QGridLayout *layout = new QGridLayout( this ); | 43 | QGridLayout *layout = new QGridLayout( this ); |
37 | layout->setSpacing( 4 ); | 44 | layout->setSpacing( 4 ); |
38 | layout->setMargin( 4 ); | 45 | layout->setMargin( 4 ); |
39 | 46 | ||
40 | 47 | ||
41 | dirLabel = new QLabel(this, "DirLabel"); | 48 | dirLabel = new QLabel(this, "DirLabel"); |
42 | dirLabel->setText(currentDir.canonicalPath()); | 49 | dirLabel->setText(currentDir.canonicalPath()); |
43 | dirLabel->setMinimumSize( QSize( 50, 15 ) ); | 50 | dirLabel->setMinimumSize( QSize( 50, 15 ) ); |
44 | dirLabel->setMaximumSize( QSize( 250, 15 ) ); | 51 | dirLabel->setMaximumSize( QSize( 250, 15 ) ); |
45 | layout->addWidget( dirLabel, 0, 0 ); | 52 | layout->addWidget( dirLabel, 0, 0 ); |
46 | 53 | ||
47 | hideButton = new QPushButton( Resource::loadIconSet("s_hidden"),"",this,"hideButton"); | ||
48 | hideButton->setMinimumSize( QSize( 25, 25 ) ); | ||
49 | hideButton->setMaximumSize( QSize( 25, 25 ) ); | ||
50 | connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) ); | ||
51 | hideButton->setToggleButton(TRUE); | ||
52 | hideButton->setFlat(TRUE); | ||
53 | layout->addWidget( hideButton, 0, 1 ); | ||
54 | |||
55 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | 54 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); |
56 | docButton->setMinimumSize( QSize( 25, 25 ) ); | 55 | docButton->setMinimumSize( QSize( 25, 25 ) ); |
57 | docButton->setMaximumSize( QSize( 25, 25 ) ); | 56 | docButton->setMaximumSize( QSize( 25, 25 ) ); |
58 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | 57 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); |
59 | docButton->setFlat(TRUE); | 58 | docButton->setFlat(TRUE); |
60 | layout->addWidget( docButton, 0, 2 ); | 59 | layout->addWidget( docButton, 0, 1 ); |
61 | 60 | ||
62 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); | 61 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); |
63 | homeButton->setMinimumSize( QSize( 25, 25 ) ); | 62 | homeButton->setMinimumSize( QSize( 25, 25 ) ); |
64 | homeButton->setMaximumSize( QSize( 25, 25 ) ); | 63 | homeButton->setMaximumSize( QSize( 25, 25 ) ); |
65 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | 64 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); |
66 | homeButton->setFlat(TRUE); | 65 | homeButton->setFlat(TRUE); |
67 | layout->addWidget( homeButton, 0, 3 ); | 66 | layout->addWidget( homeButton, 0, 2 ); |
67 | |||
68 | FileStack = new QWidgetStack( this ); | ||
68 | 69 | ||
69 | ListView = new QListView( this, "ListView" ); | 70 | ListView = new QListView( this, "ListView" ); |
70 | ListView->setMinimumSize( QSize( 100, 25 ) ); | 71 | ListView->setMinimumSize( QSize( 100, 25 ) ); |
71 | ListView->addColumn( tr( "Name" ) ); | 72 | ListView->addColumn( tr( "Name" ) ); |
72 | ListView->setColumnWidth(0,140); | 73 | ListView->setColumnWidth(0,140); |
73 | ListView->setSorting( 2, FALSE); | 74 | ListView->setSorting( 2, FALSE); |
74 | ListView->addColumn( tr( "Size" ) ); | 75 | ListView->addColumn( tr( "Size" ) ); |
75 | ListView->setColumnWidth(1,59); | 76 | ListView->setColumnWidth(1,59); |
76 | // ListView->addColumn( tr( "" ) ); | 77 | // ListView->addColumn( tr( "" ) ); |
77 | ListView->setColumnWidthMode(0,QListView::Manual); | 78 | ListView->setColumnWidthMode(0,QListView::Manual); |
78 | ListView->setColumnAlignment(1,QListView::AlignRight); | 79 | ListView->setColumnAlignment(1,QListView::AlignRight); |
79 | // ListView->setMultiSelection(true); | 80 | // ListView->setMultiSelection(true); |
80 | // ListView->setSelectionMode(QListView::Extended); | 81 | // ListView->setSelectionMode(QListView::Extended); |
81 | |||
82 | ListView->setAllColumnsShowFocus( TRUE ); | 82 | ListView->setAllColumnsShowFocus( TRUE ); |
83 | layout->addMultiCellWidget( ListView, 1, 1, 0, 3 ); | ||
84 | |||
85 | // signals and slots connections | ||
86 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | ||
87 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 83 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
84 | FileStack->addWidget( ListView, get_unique_id() ); | ||
85 | |||
86 | fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy | ||
87 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | ||
88 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | ||
89 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | ||
90 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 ); | ||
91 | |||
92 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); | ||
93 | SelectionCombo->setMinimumSize( QSize( 200, 25 ) ); | ||
94 | SelectionCombo->insertItem( tr( "Documents" ) ); | ||
95 | SelectionCombo->insertItem( tr( "All files" ) ); | ||
96 | SelectionCombo->insertItem( tr( "All files (incl. hidden)" ) ); | ||
97 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 2 ); | ||
98 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), | ||
99 | this, SLOT( selectionChanged( const QString & ) ) ); | ||
100 | |||
88 | currentDir.setPath(QDir::currentDirPath()); | 101 | currentDir.setPath(QDir::currentDirPath()); |
89 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); | 102 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); |
90 | 103 | ||
91 | populateList(); | 104 | populateList(); |
92 | move(0,15); | 105 | move(0,15); |
93 | } | 106 | } |
94 | 107 | ||
95 | fileBrowser::~fileBrowser() | 108 | fileBrowser::~fileBrowser() |
96 | { | 109 | { |
97 | } | 110 | } |
98 | 111 | ||
112 | void fileBrowser::setFileView( int selection ) | ||
113 | { | ||
114 | SelectionCombo->setCurrentItem( selection ); | ||
115 | selectionChanged( SelectionCombo->currentText() ); | ||
116 | } | ||
99 | 117 | ||
100 | void fileBrowser::populateList() | 118 | void fileBrowser::populateList() |
101 | { | 119 | { |
102 | ListView->clear(); | 120 | ListView->clear(); |
103 | //qDebug(currentDir.canonicalPath()); | 121 | //qDebug(currentDir.canonicalPath()); |
104 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 122 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
105 | currentDir.setMatchAllDirs(TRUE); | 123 | currentDir.setMatchAllDirs(TRUE); |
106 | 124 | ||
107 | currentDir.setNameFilter(filterStr); | 125 | currentDir.setNameFilter(filterStr); |
108 | // currentDir.setNameFilter("*.txt;*.etx"); | 126 | // currentDir.setNameFilter("*.txt;*.etx"); |
109 | QString fileL, fileS; | 127 | QString fileL, fileS; |
110 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 128 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
@@ -131,28 +149,24 @@ void fileBrowser::populateList() | |||
131 | item= new QListViewItem( ListView,fileL,fileS ); | 149 | item= new QListViewItem( ListView,fileL,fileS ); |
132 | ++it; | 150 | ++it; |
133 | } | 151 | } |
134 | ListView->setSorting( 2, FALSE); | 152 | ListView->setSorting( 2, FALSE); |
135 | dirLabel->setText(currentDir.canonicalPath()); | 153 | dirLabel->setText(currentDir.canonicalPath()); |
136 | } | 154 | } |
137 | 155 | ||
138 | void fileBrowser::upDir() | 156 | void fileBrowser::upDir() |
139 | { | 157 | { |
140 | // qDebug(currentDir.canonicalPath()); | 158 | // qDebug(currentDir.canonicalPath()); |
141 | } | 159 | } |
142 | 160 | ||
143 | void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) | ||
144 | { | ||
145 | } | ||
146 | |||
147 | // you may want to switch these 2 functions. I like single clicks | 161 | // you may want to switch these 2 functions. I like single clicks |
148 | void fileBrowser::listClicked(QListViewItem *selectedItem) | 162 | void fileBrowser::listClicked(QListViewItem *selectedItem) |
149 | { | 163 | { |
150 | QString strItem=selectedItem->text(0); | 164 | QString strItem=selectedItem->text(0); |
151 | QString strSize=selectedItem->text(1); | 165 | QString strSize=selectedItem->text(1); |
152 | // qDebug("strItem is "+strItem); | 166 | // qDebug("strItem is "+strItem); |
153 | strSize.stripWhiteSpace(); | 167 | strSize.stripWhiteSpace(); |
154 | // qDebug(strSize); | 168 | // qDebug(strSize); |
155 | 169 | ||
156 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 170 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
157 | // is symlink | 171 | // is symlink |
158 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | 172 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); |
@@ -207,24 +221,42 @@ void fileBrowser::homeButtonPushed() { | |||
207 | populateList(); | 221 | populateList(); |
208 | update(); | 222 | update(); |
209 | } | 223 | } |
210 | 224 | ||
211 | void fileBrowser::docButtonPushed() { | 225 | void fileBrowser::docButtonPushed() { |
212 | chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); | 226 | chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); |
213 | currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); | 227 | currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); |
214 | populateList(); | 228 | populateList(); |
215 | update(); | 229 | update(); |
216 | 230 | ||
217 | } | 231 | } |
218 | 232 | ||
219 | void fileBrowser::hideButtonPushed(bool b) { | 233 | void fileBrowser::selectionChanged( const QString &select ) |
220 | if (b) | 234 | { |
221 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 235 | if ( select == "Documents") |
236 | { | ||
237 | FileStack->raiseWidget( fileSelector ); | ||
238 | dirLabel->hide(); | ||
239 | docButton->hide(); | ||
240 | homeButton->hide(); | ||
241 | } | ||
222 | else | 242 | else |
223 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 243 | { |
244 | if ( select == "All files" ) | ||
245 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); | ||
246 | else | ||
247 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | ||
224 | 248 | ||
225 | // chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); | ||
226 | // currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); | ||
227 | populateList(); | 249 | populateList(); |
228 | update(); | 250 | update(); |
251 | dirLabel->show(); | ||
252 | docButton->show(); | ||
253 | homeButton->show(); | ||
254 | FileStack->raiseWidget( ListView ); | ||
255 | } | ||
256 | } | ||
229 | 257 | ||
258 | void fileBrowser::docOpen( const DocLnk &doc ) | ||
259 | { | ||
260 | fileList.append( doc.file().latin1() ); | ||
261 | accept(); | ||
230 | } | 262 | } |