author | llornkcor <llornkcor> | 2002-09-14 02:19:09 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-14 02:19:09 (UTC) |
commit | 2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (unidiff) | |
tree | eeed16b5f80dd5883991a7a06133f5f7a6936256 /noncore/apps/opie-reader/fileBrowser.cpp | |
parent | 5a95ed6a000a56849b8f093deea500214856c626 (diff) | |
download | opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2 |
update by Tim
Diffstat (limited to 'noncore/apps/opie-reader/fileBrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/fileBrowser.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp index def988f..b21d59d 100644 --- a/noncore/apps/opie-reader/fileBrowser.cpp +++ b/noncore/apps/opie-reader/fileBrowser.cpp | |||
@@ -8,59 +8,68 @@ 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 <qpushbutton.h> | 13 | #include <qpushbutton.h> |
14 | #include <qfile.h> | 14 | #include <qfile.h> |
15 | #include <qmessagebox.h> | 15 | #include <qmessagebox.h> |
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #include <qlayout.h> | 17 | #include <qlayout.h> |
18 | 18 | ||
19 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) | 19 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) |
20 | : QDialog( parent, name, modal, fl ) | 20 | : QDialog( parent, name, modal, fl ), filterspec(QDir::All) |
21 | { | 21 | { |
22 | // showMaximized(); | 22 | // showMaximized(); |
23 | if ( !name ) | 23 | if ( !name ) |
24 | setName( "fileBrowser" ); | 24 | setName( "fileBrowser" ); |
25 | if (parent != NULL) resize( parent->width(), parent->height() ); | 25 | if (parent != NULL) resize( parent->width(), parent->height() ); |
26 | setCaption(tr( "Browse for file" ) ); | 26 | setCaption(tr( "Browse for file" ) ); |
27 | filterStr=filter; | 27 | filterStr=filter; |
28 | 28 | ||
29 | buttonOk = new QPushButton( this, "buttonOk" ); | 29 | buttonOk = new QPushButton( this, "buttonOk" ); |
30 | buttonOk->setFixedSize( 25, 25 ); | 30 | buttonOk->setFixedSize( 25, 25 ); |
31 | buttonOk->setAutoDefault( false ); | ||
31 | buttonOk->setText( tr( "/" ) ); | 32 | buttonOk->setText( tr( "/" ) ); |
32 | 33 | ||
34 | buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); | ||
35 | // buttonShowHidden->setFixedSize( 50, 25 ); | ||
36 | buttonShowHidden->setText( tr( "Hidden" ) ); | ||
37 | buttonShowHidden->setAutoDefault( false ); | ||
38 | buttonShowHidden->setToggleButton( true ); | ||
39 | buttonShowHidden->setOn( false ); | ||
40 | |||
33 | dirLabel = new QLabel(this, "DirLabel"); | 41 | dirLabel = new QLabel(this, "DirLabel"); |
34 | dirLabel->setText(currentDir.canonicalPath()); | 42 | dirLabel->setText(currentDir.canonicalPath()); |
35 | 43 | ||
36 | ListView = new QtrListView( this, "ListView" ); | 44 | ListView = new QtrListView( this, "ListView" ); |
37 | ListView->addColumn( tr( "Name" ) ); | 45 | ListView->addColumn( tr( "Name" ) ); |
38 | ListView->setSorting( 2, FALSE); | 46 | ListView->setSorting( 2, FALSE); |
39 | ListView->addColumn( tr( "Size" ) ); | 47 | ListView->addColumn( tr( "Size" ) ); |
40 | ListView->setSelectionMode(QListView::Single); | 48 | ListView->setSelectionMode(QListView::Single); |
41 | |||
42 | ListView->setAllColumnsShowFocus( TRUE ); | 49 | ListView->setAllColumnsShowFocus( TRUE ); |
43 | 50 | ||
44 | // signals and slots connections | 51 | // signals and slots connections |
52 | connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); | ||
45 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); | 53 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); |
46 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | 54 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); |
47 | connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 55 | connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
48 | connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 56 | connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
49 | connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 57 | connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
50 | connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); | 58 | connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); |
51 | 59 | ||
52 | QVBoxLayout* grid = new QVBoxLayout(this); | 60 | QVBoxLayout* grid = new QVBoxLayout(this); |
53 | QHBoxLayout* hgrid = new QHBoxLayout(grid); | 61 | QHBoxLayout* hgrid = new QHBoxLayout(grid); |
54 | hgrid->addWidget(dirLabel,1); | 62 | hgrid->addWidget(dirLabel,1); |
63 | hgrid->addWidget(buttonShowHidden); | ||
55 | hgrid->addWidget(buttonOk); | 64 | hgrid->addWidget(buttonOk); |
56 | grid->addWidget(ListView,1); | 65 | grid->addWidget(ListView,1); |
57 | 66 | ||
58 | if (QFileInfo(iPath).exists()) | 67 | if (QFileInfo(iPath).exists()) |
59 | { | 68 | { |
60 | currentDir.setPath(iPath); | 69 | currentDir.setPath(iPath); |
61 | chdir(iPath.latin1()); | 70 | chdir(iPath.latin1()); |
62 | } | 71 | } |
63 | else | 72 | else |
64 | { | 73 | { |
65 | currentDir.setPath(QDir::currentDirPath()); | 74 | currentDir.setPath(QDir::currentDirPath()); |
66 | chdir(QDir::currentDirPath().latin1()); | 75 | chdir(QDir::currentDirPath().latin1()); |
@@ -76,54 +85,55 @@ void fileBrowser::resizeEvent(QResizeEvent* e) | |||
76 | } | 85 | } |
77 | 86 | ||
78 | fileBrowser::~fileBrowser() | 87 | fileBrowser::~fileBrowser() |
79 | { | 88 | { |
80 | } | 89 | } |
81 | 90 | ||
82 | 91 | ||
83 | void fileBrowser::populateList() | 92 | void fileBrowser::populateList() |
84 | { | 93 | { |
85 | ListView->clear(); | 94 | ListView->clear(); |
86 | //qDebug(currentDir.canonicalPath()); | 95 | //qDebug(currentDir.canonicalPath()); |
87 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); | 96 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); |
88 | currentDir.setFilter( QDir::All ); | 97 | currentDir.setFilter( filterspec ); |
89 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 98 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
90 | currentDir.setMatchAllDirs(TRUE); | 99 | currentDir.setMatchAllDirs(TRUE); |
91 | 100 | ||
92 | currentDir.setNameFilter(filterStr); | 101 | currentDir.setNameFilter(filterStr); |
93 | // currentDir.setNameFilter("*.txt;*.etx"); | 102 | // currentDir.setNameFilter("*.txt;*.etx"); |
94 | QString fileL, fileS; | 103 | QString fileL, fileS; |
95 | const QFileInfoList *list = currentDir.entryInfoList(QDir::All); | 104 | const QFileInfoList *list = currentDir.entryInfoList(); |
96 | QFileInfoListIterator it(*list); | 105 | QFileInfoListIterator it(*list); |
97 | QFileInfo *fi; | 106 | QFileInfo *fi; |
98 | while ( (fi=it.current()) ) | 107 | while ( (fi=it.current()) ) |
99 | { | 108 | { |
100 | if (fi->fileName() != ".") | 109 | if (fi->fileName() != ".") |
101 | { | 110 | { |
102 | fileS.sprintf( "%10li", fi->size() ); | 111 | fileS.sprintf( "%10li", fi->size() ); |
103 | fileL.sprintf( "%s",fi->fileName().data() ); | 112 | fileL.sprintf( "%s",fi->fileName().data() ); |
104 | if( fi->isDir() ) | 113 | if( fi->isDir() ) |
105 | { | 114 | { |
106 | fileL+="/"; | 115 | fileL+="/"; |
107 | } | 116 | } |
108 | else | 117 | else |
109 | { | 118 | { |
110 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 119 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
111 | } | 120 | } |
112 | new QListViewItem( ListView,fileL,fileS ); | 121 | new QListViewItem( ListView,fileL,fileS ); |
113 | } | 122 | } |
114 | ++it; | 123 | ++it; |
115 | } | 124 | } |
116 | ListView->setSorting( 2, FALSE); | 125 | ListView->setSorting( 2, FALSE); |
117 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); | 126 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); |
127 | ListView->setFocus(); | ||
118 | } | 128 | } |
119 | 129 | ||
120 | void fileBrowser::upDir() | 130 | void fileBrowser::upDir() |
121 | { | 131 | { |
122 | // qDebug(currentDir.canonicalPath()); | 132 | // qDebug(currentDir.canonicalPath()); |
123 | } | 133 | } |
124 | 134 | ||
125 | void fileBrowser::listClicked(QListViewItem *selectedItem) | 135 | void fileBrowser::listClicked(QListViewItem *selectedItem) |
126 | { | 136 | { |
127 | if (selectedItem == NULL) return; | 137 | if (selectedItem == NULL) return; |
128 | QString strItem=selectedItem->text(0); | 138 | QString strItem=selectedItem->text(0); |
129 | 139 | ||
@@ -174,12 +184,21 @@ void fileBrowser::OnOK() { | |||
174 | 184 | ||
175 | void fileBrowser::OnRoot() | 185 | void fileBrowser::OnRoot() |
176 | { | 186 | { |
177 | currentDir.cd("/", TRUE); | 187 | currentDir.cd("/", TRUE); |
178 | populateList(); | 188 | populateList(); |
179 | chdir("/"); | 189 | chdir("/"); |
180 | } | 190 | } |
181 | 191 | ||
182 | void fileBrowser::OnCancel() | 192 | void fileBrowser::OnCancel() |
183 | { | 193 | { |
184 | reject(); | 194 | reject(); |
185 | } | 195 | } |
196 | |||
197 | void fileBrowser::setHidden(bool _hidden) | ||
198 | { | ||
199 | if (_hidden) | ||
200 | filterspec = QDir::All | QDir::Hidden; | ||
201 | else | ||
202 | filterspec = QDir::All; | ||
203 | populateList(); | ||
204 | } | ||