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