Diffstat (limited to 'noncore/apps/opie-reader/fileBrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/fileBrowser.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp index ebd14f3..e1cde6c 100644 --- a/noncore/apps/opie-reader/fileBrowser.cpp +++ b/noncore/apps/opie-reader/fileBrowser.cpp | |||
@@ -1,176 +1,176 @@ | |||
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 <qlineedit.h> |
14 | #include <qpushbutton.h> | 14 | #include <qpushbutton.h> |
15 | #ifndef _WINDOWS | 15 | #ifndef _WINDOWS |
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #endif | 17 | #endif |
18 | #include <qlayout.h> | 18 | #include <qlayout.h> |
19 | #ifdef _WINDOWS | 19 | #ifdef _WINDOWS |
20 | #include <direct.h> | 20 | #include <direct.h> |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | 24 | ||
25 | 25 | ||
26 | fileBrowser::fileBrowser( bool allownew, QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) | 26 | fileBrowser::fileBrowser( bool allownew, QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) |
27 | : QDialog( parent, name, true, | 27 | : QDialog( parent, name, true, |
28 | fl/* | WStyle_Customize | WStyle_Tool*/), | 28 | fl/* | WStyle_Customize | WStyle_Tool*/), |
29 | filterspec(QDir::All) | 29 | filterspec(QDir::All) |
30 | { | 30 | { |
31 | // showMaximized(); | 31 | // showMaximized(); |
32 | if ( !name ) | 32 | if ( !name ) |
33 | setName( "fileBrowser" ); | 33 | setName( "fileBrowser" ); |
34 | /* | 34 | /* |
35 | if (parent != NULL) | 35 | if (parent != NULL) |
36 | { | 36 | { |
37 | #ifdef OPIE | 37 | #ifdef OPIE |
38 | move(0,0); | 38 | move(0,0); |
39 | resize( parent->width(), parent->height() ); | 39 | resize( parent->width(), parent->height() ); |
40 | #else | 40 | #else |
41 | setGeometry(parent->x(), parent->y(), parent->width(), parent->height() ); | 41 | setGeometry(parent->x(), parent->y(), parent->width(), parent->height() ); |
42 | #endif | 42 | #endif |
43 | } | 43 | } |
44 | */ | 44 | */ |
45 | // showFullScreen(); | 45 | // showFullScreen(); |
46 | setCaption(tr( "Browse for file" ) ); | 46 | setCaption(tr( "Browse for file" ) ); |
47 | filterStr=filter; | 47 | filterStr=filter; |
48 | 48 | ||
49 | buttonOk = new QPushButton( this, "buttonOk" ); | 49 | buttonOk = new QPushButton( this, "buttonOk" ); |
50 | buttonOk->setFixedSize( 25, 25 ); | 50 | buttonOk->setFixedSize( 25, 25 ); |
51 | buttonOk->setAutoDefault( false ); | 51 | buttonOk->setAutoDefault( false ); |
52 | buttonOk->setText( tr( "/" ) ); | 52 | buttonOk->setText( tr( "/" ) ); |
53 | 53 | ||
54 | buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); | 54 | buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); |
55 | // buttonShowHidden->setFixedSize( 50, 25 ); | 55 | // buttonShowHidden->setFixedSize( 50, 25 ); |
56 | buttonShowHidden->setText( tr( "Hidden" ) ); | 56 | buttonShowHidden->setText( tr( "Hidden" ) ); |
57 | buttonShowHidden->setAutoDefault( false ); | 57 | buttonShowHidden->setAutoDefault( false ); |
58 | buttonShowHidden->setToggleButton( true ); | 58 | buttonShowHidden->setToggleButton( true ); |
59 | buttonShowHidden->setOn( false ); | 59 | buttonShowHidden->setOn( false ); |
60 | 60 | ||
61 | dirLabel = new QLabel(this, "DirLabel"); | 61 | dirLabel = new QLabel(this, "DirLabel"); |
62 | dirLabel->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak); | 62 | dirLabel->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak); |
63 | dirLabel->setText(currentDir.canonicalPath()); | 63 | dirLabel->setText(currentDir.canonicalPath()); |
64 | 64 | ||
65 | ListView = new QtrListView( this, "ListView" ); | 65 | ListView = new QtrListView( this, "ListView" ); |
66 | ListView->addColumn( tr( "Name" ) ); | 66 | ListView->addColumn( tr( "Name" ) ); |
67 | ListView->setSorting( 2, FALSE); | 67 | ListView->setSorting( 2, FALSE); |
68 | ListView->addColumn( tr( "Size" ) ); | 68 | ListView->addColumn( tr( "Size" ) ); |
69 | ListView->setSelectionMode(QListView::Single); | 69 | ListView->setSelectionMode(QListView::Single); |
70 | ListView->setAllColumnsShowFocus( TRUE ); | 70 | ListView->setAllColumnsShowFocus( TRUE ); |
71 | ListView->setColumnWidthMode(0, QListView::Manual); | 71 | ListView->setColumnWidthMode(0, QListView::Manual); |
72 | ListView->setColumnWidthMode(1, QListView::Manual); | 72 | ListView->setColumnWidthMode(1, QListView::Manual); |
73 | 73 | ||
74 | // signals and slots connections | 74 | // signals and slots connections |
75 | connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); | 75 | connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); |
76 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); | 76 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); |
77 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | 77 | connect( ListView, SIGNAL(doubleClicked(QListViewItem*)), SLOT(listDoubleClicked(QListViewItem*)) ); |
78 | connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 78 | connect( ListView, SIGNAL(clicked(QListViewItem*)), SLOT(listClicked(QListViewItem*)) ); |
79 | connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 79 | connect( ListView, SIGNAL(OnOKButton(QListViewItem*)), SLOT(listClicked(QListViewItem*)) ); |
80 | connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 80 | connect( ListView, SIGNAL(OnCentreButton(QListViewItem*)), SLOT(listClicked(QListViewItem*)) ); |
81 | connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); | 81 | connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); |
82 | 82 | ||
83 | QVBoxLayout* grid = new QVBoxLayout(this); | 83 | QVBoxLayout* grid = new QVBoxLayout(this); |
84 | QHBoxLayout* hgrid = new QHBoxLayout(grid); | 84 | QHBoxLayout* hgrid = new QHBoxLayout(grid); |
85 | hgrid->addWidget(dirLabel,1); | 85 | hgrid->addWidget(dirLabel,1); |
86 | hgrid->addWidget(buttonShowHidden); | 86 | hgrid->addWidget(buttonShowHidden); |
87 | hgrid->addWidget(buttonOk); | 87 | hgrid->addWidget(buttonOk); |
88 | grid->addWidget(ListView,1); | 88 | grid->addWidget(ListView,1); |
89 | if (allownew) | 89 | if (allownew) |
90 | { | 90 | { |
91 | m_filename = new QLineEdit(this); | 91 | m_filename = new QLineEdit(this); |
92 | grid->addWidget(m_filename); | 92 | grid->addWidget(m_filename); |
93 | connect( m_filename, SIGNAL( returnPressed() ), this, SLOT( onReturn() )); | 93 | connect( m_filename, SIGNAL( returnPressed() ), this, SLOT( onReturn() )); |
94 | } | 94 | } |
95 | else | 95 | else |
96 | { | 96 | { |
97 | m_filename = NULL; | 97 | m_filename = NULL; |
98 | } | 98 | } |
99 | 99 | ||
100 | if (QFileInfo(iPath).exists()) | 100 | if (QFileInfo(iPath).exists()) |
101 | { | 101 | { |
102 | currentDir.setPath(iPath); | 102 | currentDir.setPath(iPath); |
103 | #ifdef _WINDOWS | 103 | #ifdef _WINDOWS |
104 | _chdir(iPath.latin1()); | 104 | _chdir(iPath.latin1()); |
105 | #else | 105 | #else |
106 | chdir(iPath.latin1()); | 106 | chdir(iPath.latin1()); |
107 | #endif | 107 | #endif |
108 | } | 108 | } |
109 | else | 109 | else |
110 | { | 110 | { |
111 | currentDir.setPath(QDir::currentDirPath()); | 111 | currentDir.setPath(QDir::currentDirPath()); |
112 | chdir(QDir::currentDirPath().latin1()); | 112 | chdir(QDir::currentDirPath().latin1()); |
113 | } | 113 | } |
114 | 114 | ||
115 | populateList(); | 115 | populateList(); |
116 | 116 | ||
117 | if (modal) | 117 | if (modal) |
118 | QPEApplication::showDialog( this ); | 118 | QPEApplication::showDialog( this ); |
119 | } | 119 | } |
120 | 120 | ||
121 | void fileBrowser::resizeEvent(QResizeEvent* e) | 121 | void fileBrowser::resizeEvent(QResizeEvent* e) |
122 | { | 122 | { |
123 | ListView->setColumnWidth(1,(ListView->width())/4); | 123 | ListView->setColumnWidth(1,(ListView->width())/4); |
124 | ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1)); | 124 | ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1)); |
125 | } | 125 | } |
126 | 126 | ||
127 | fileBrowser::~fileBrowser() | 127 | fileBrowser::~fileBrowser() |
128 | { | 128 | { |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | void fileBrowser::populateList() | 132 | void fileBrowser::populateList() |
133 | { | 133 | { |
134 | ListView->clear(); | 134 | ListView->clear(); |
135 | ////qDebug(currentDir.canonicalPath()); | 135 | ////qDebug(currentDir.canonicalPath()); |
136 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); | 136 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); |
137 | currentDir.setFilter( filterspec ); | 137 | currentDir.setFilter( filterspec ); |
138 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 138 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
139 | currentDir.setMatchAllDirs(TRUE); | 139 | currentDir.setMatchAllDirs(TRUE); |
140 | 140 | ||
141 | currentDir.setNameFilter(filterStr); | 141 | currentDir.setNameFilter(filterStr); |
142 | // currentDir.setNameFilter("*.txt;*.etx"); | 142 | // currentDir.setNameFilter("*.txt;*.etx"); |
143 | QString fileL, fileS; | 143 | QString fileL, fileS; |
144 | const QFileInfoList *list = currentDir.entryInfoList(); | 144 | const QFileInfoList *list = currentDir.entryInfoList(); |
145 | QFileInfoListIterator it(*list); | 145 | QFileInfoListIterator it(*list); |
146 | QFileInfo *fi; | 146 | QFileInfo *fi; |
147 | while ( (fi=it.current()) ) | 147 | while ( (fi=it.current()) ) |
148 | { | 148 | { |
149 | if (fi->fileName() != ".") | 149 | if (fi->fileName() != ".") |
150 | { | 150 | { |
151 | fileS.sprintf( "%10li", fi->size() ); | 151 | fileS.sprintf( "%10li", fi->size() ); |
152 | fileL.sprintf( "%s",fi->fileName().data() ); | 152 | fileL.sprintf( "%s",fi->fileName().data() ); |
153 | if( fi->isDir() ) | 153 | if( fi->isDir() ) |
154 | { | 154 | { |
155 | fileL+="/"; | 155 | fileL+="/"; |
156 | } | 156 | } |
157 | else | 157 | else |
158 | { | 158 | { |
159 | //// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 159 | //// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
160 | } | 160 | } |
161 | new QListViewItem( ListView,fileL,fileS ); | 161 | new QListViewItem( ListView,fileL,fileS ); |
162 | } | 162 | } |
163 | ++it; | 163 | ++it; |
164 | } | 164 | } |
165 | ListView->setSorting( 2, FALSE); | 165 | ListView->setSorting( 2, FALSE); |
166 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); | 166 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); |
167 | ListView->setFocus(); | 167 | ListView->setFocus(); |
168 | } | 168 | } |
169 | 169 | ||
170 | void fileBrowser::upDir() | 170 | void fileBrowser::upDir() |
171 | { | 171 | { |
172 | //// qDebug(currentDir.canonicalPath()); | 172 | //// qDebug(currentDir.canonicalPath()); |
173 | } | 173 | } |
174 | 174 | ||
175 | void fileBrowser::listClicked(QListViewItem *selectedItem) | 175 | void fileBrowser::listClicked(QListViewItem *selectedItem) |
176 | { | 176 | { |