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