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 | |||
@@ -11,22 +11,29 @@ | |||
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" ); |
@@ -41,33 +48,27 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
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); |
@@ -75,30 +76,47 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
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); |
@@ -137,16 +155,12 @@ void fileBrowser::populateList() | |||
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); |
@@ -213,18 +227,36 @@ void fileBrowser::docButtonPushed() { | |||
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 | } |