summaryrefslogtreecommitdiff
path: root/core/apps/textedit/fileBrowser.cpp
Unidiff
Diffstat (limited to 'core/apps/textedit/fileBrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileBrowser.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp
index 2275388..3e3cc3a 100644
--- a/core/apps/textedit/fileBrowser.cpp
+++ b/core/apps/textedit/fileBrowser.cpp
@@ -1,164 +1,180 @@
1/**************************************************************************** 1/****************************************************************************
2** copyright 2001 ljp ljp@llornkcor.com 2** copyright 2001 ljp ljp@llornkcor.com
3** Created: Fri Dec 14 08:16:46 2001 3** Created: Fri Dec 14 08:16:46 2001
4** 4**
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 17
17#include <qlistview.h> 18#include <qlistview.h>
18#include <qpushbutton.h> 19#include <qpushbutton.h>
19#include <qfile.h> 20#include <qfile.h>
20#include <qmessagebox.h> 21#include <qmessagebox.h>
21#include <unistd.h> 22#include <unistd.h>
22 23
23fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) 24fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter )
24 : QDialog( parent, name, modal, fl ) 25 : QDialog( parent, name, modal, fl )
25{ 26{
26 if ( !name ) 27 if ( !name )
27 setName( "fileBrowser" ); 28 setName( "fileBrowser" );
28 resize( 236, 280 ); 29 resize( 240, 280 );
29 setCaption(tr( "Browse for file" ) ); 30 setCaption(tr( "Browse for file" ) );
30 filterStr=filter; 31 filterStr=filter;
32
31 dirLabel = new QLabel(this, "DirLabel"); 33 dirLabel = new QLabel(this, "DirLabel");
32 dirLabel->setText(currentDir.canonicalPath()); 34 dirLabel->setText(currentDir.canonicalPath());
33 dirLabel->setGeometry(10,4,230,30); 35 dirLabel->setGeometry(10,20,230,15);
36
37 QPushButton *homeButton;
38 homeButton = new QPushButton(Resource::loadIconSet("home"),"",this,"homeButton");
39 homeButton->setGeometry(200,4,25,25);
40 connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) );
41
34 ListView = new QListView( this, "ListView" ); 42 ListView = new QListView( this, "ListView" );
35 ListView->addColumn( tr( "Name" ) ); 43 ListView->addColumn( tr( "Name" ) );
36 ListView->setColumnWidth(0,140); 44 ListView->setColumnWidth(0,140);
37 ListView->setSorting( 2, FALSE); 45 ListView->setSorting( 2, FALSE);
38 ListView->addColumn( tr( "Size" ) ); 46 ListView->addColumn( tr( "Size" ) );
39 ListView->setColumnWidth(1,59); 47 ListView->setColumnWidth(1,59);
40// ListView->addColumn( tr( "" ) ); 48// ListView->addColumn( tr( "" ) );
41 ListView->setColumnWidthMode(0,QListView::Manual); 49 ListView->setColumnWidthMode(0,QListView::Manual);
42 ListView->setColumnAlignment(1,QListView::AlignRight); 50 ListView->setColumnAlignment(1,QListView::AlignRight);
43// ListView->setMultiSelection(true); 51// ListView->setMultiSelection(true);
44// ListView->setSelectionMode(QListView::Extended); 52// ListView->setSelectionMode(QListView::Extended);
45 53
46 ListView->setAllColumnsShowFocus( TRUE ); 54 ListView->setAllColumnsShowFocus( TRUE );
47 ListView->setGeometry( QRect( 10, 35, 220, 240 ) ); 55 ListView->setGeometry( QRect( 10, 35, 220, 240 ) );
48 56
49 // signals and slots connections 57 // signals and slots connections
50 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); 58 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
51 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 59 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
52 currentDir.setPath(QDir::currentDirPath()); 60 currentDir.setPath(QDir::currentDirPath());
53 populateList(); 61 populateList();
62 move(0,15);
54} 63}
55 64
56fileBrowser::~fileBrowser() 65fileBrowser::~fileBrowser()
57{ 66{
58} 67}
59 68
60 69
61void fileBrowser::populateList() 70void fileBrowser::populateList()
62{ 71{
63 ListView->clear(); 72 ListView->clear();
64//qDebug(currentDir.canonicalPath()); 73//qDebug(currentDir.canonicalPath());
65 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); 74 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
66 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 75 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
67 currentDir.setMatchAllDirs(TRUE); 76 currentDir.setMatchAllDirs(TRUE);
68 77
69 currentDir.setNameFilter(filterStr); 78 currentDir.setNameFilter(filterStr);
70// currentDir.setNameFilter("*.txt;*.etx"); 79// currentDir.setNameFilter("*.txt;*.etx");
71 QString fileL, fileS; 80 QString fileL, fileS;
72 const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); 81 const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/);
73 QFileInfoListIterator it(*list); 82 QFileInfoListIterator it(*list);
74 QFileInfo *fi; 83 QFileInfo *fi;
75 while ( (fi=it.current()) ) { 84 while ( (fi=it.current()) ) {
76 85
77 if (fi->isSymLink() ){ 86 if (fi->isSymLink() ){
78 QString symLink=fi->readLink(); 87 QString symLink=fi->readLink();
79// qDebug("Symlink detected "+symLink); 88// qDebug("Symlink detected "+symLink);
80 QFileInfo sym( symLink); 89 QFileInfo sym( symLink);
81 fileS.sprintf( "%10li", sym.size() ); 90 fileS.sprintf( "%10li", sym.size() );
82 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); 91 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
83 92
84 } else { 93 } else {
85// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 94// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
86 fileS.sprintf( "%10li", fi->size() ); 95 fileS.sprintf( "%10li", fi->size() );
87 fileL.sprintf( "%s",fi->fileName().data() ); 96 fileL.sprintf( "%s",fi->fileName().data() );
88 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { 97 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
89 fileL+="/"; 98 fileL+="/";
90// qDebug(currentDir.canonicalPath()+fileL); 99// qDebug(currentDir.canonicalPath()+fileL);
91 } 100 }
92 } 101 }
93 item= new QListViewItem( ListView,fileL,fileS ); 102 item= new QListViewItem( ListView,fileL,fileS );
94 ++it; 103 ++it;
95 } 104 }
96 ListView->setSorting( 2, FALSE); 105 ListView->setSorting( 2, FALSE);
97 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); 106 dirLabel->setText(currentDir.canonicalPath());
98} 107}
99 108
100void fileBrowser::upDir() 109void fileBrowser::upDir()
101{ 110{
102// qDebug(currentDir.canonicalPath()); 111// qDebug(currentDir.canonicalPath());
103} 112}
104 113
105void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) 114void fileBrowser::listDoubleClicked(QListViewItem *selectedItem)
106{ 115{
107} 116}
108 117
109// you may want to switch these 2 functions. I like single clicks 118// you may want to switch these 2 functions. I like single clicks
110void fileBrowser::listClicked(QListViewItem *selectedItem) 119void fileBrowser::listClicked(QListViewItem *selectedItem)
111{ 120{
112 QString strItem=selectedItem->text(0); 121 QString strItem=selectedItem->text(0);
113 QString strSize=selectedItem->text(1); 122 QString strSize=selectedItem->text(1);
114// qDebug("strItem is "+strItem); 123// qDebug("strItem is "+strItem);
115 strSize.stripWhiteSpace(); 124 strSize.stripWhiteSpace();
116// qDebug(strSize); 125// qDebug(strSize);
117 126
118 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink 127 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
119 // is symlink 128 // is symlink
120 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); 129 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4);
121// qDebug("strItem symlink is "+strItem2); 130// qDebug("strItem symlink is "+strItem2);
122 if(QDir(strItem2).exists() ) { 131 if(QDir(strItem2).exists() ) {
123 currentDir.cd(strItem2, TRUE); 132 currentDir.cd(strItem2, TRUE);
124 populateList(); 133 populateList();
125 } 134 }
126 } else { // not a symlink 135 } else { // not a symlink
127 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 136 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
128 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { 137 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
129 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 138 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
130 currentDir.cd(strItem,FALSE); 139 currentDir.cd(strItem,FALSE);
131// qDebug("Path is "+strItem); 140// qDebug("Path is "+strItem);
132 populateList(); 141 populateList();
133 } else { 142 } else {
134 currentDir.cdUp(); 143 currentDir.cdUp();
135 populateList(); 144 populateList();
136 } 145 }
137 if(QDir(strItem).exists()){ 146 if(QDir(strItem).exists()){
138 currentDir.cd(strItem, TRUE); 147 currentDir.cd(strItem, TRUE);
139 populateList(); 148 populateList();
140 } 149 }
141 } else { 150 } else {
142 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 151 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
143 if( QFile::exists(strItem ) ) { 152 if( QFile::exists(strItem ) ) {
144//currentDir.canonicalPath() 153//currentDir.canonicalPath()
145 qDebug("We found our files!!"+strItem); 154 qDebug("We found our files!!"+strItem);
146 OnOK(); 155 OnOK();
147 } 156 }
148 } //end not symlink 157 } //end not symlink
149 chdir(strItem.latin1()); 158 chdir(strItem.latin1());
150 } 159 }
151} 160}
152 161
153void fileBrowser::OnOK() 162void fileBrowser::OnOK()
154{ 163{
155 QListViewItemIterator it1( ListView); 164 QListViewItemIterator it1( ListView);
156 for ( ; it1.current(); ++it1 ) { 165 for ( ; it1.current(); ++it1 ) {
157 if ( it1.current()->isSelected() ) { 166 if ( it1.current()->isSelected() ) {
158 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); 167 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0));
159 qDebug("selected filename is "+selectedFileName); 168 qDebug("selected filename is "+selectedFileName);
160 fileList.append( selectedFileName ); 169 fileList.append( selectedFileName );
161 } 170 }
162 } 171 }
163 accept(); 172 accept();
164} 173}
174
175void fileBrowser::homeButtonPushed() {
176 chdir( QDir::homeDirPath().latin1() );
177 currentDir.cd( QDir::homeDirPath(), TRUE);
178 populateList();
179 update();
180}