Diffstat (limited to 'core/apps/textedit/fileSaver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 271 |
1 files changed, 0 insertions, 271 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp deleted file mode 100644 index 209a258..0000000 --- a/core/apps/textedit/fileSaver.cpp +++ b/dev/null | |||
@@ -1,271 +0,0 @@ | |||
1 | /**************************************************************************** | ||
2 | ** copyright 2001 ljp ljp@llornkcor.com | ||
3 | ** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp | ||
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 "fileSaver.h" | ||
15 | #include <qpe/config.h> | ||
16 | #include <qpe/resource.h> | ||
17 | #include <qpe/mimetype.h> | ||
18 | |||
19 | #include <qpe/qpeapplication.h> | ||
20 | #include <qlistview.h> | ||
21 | #include <qpushbutton.h> | ||
22 | #include <qfile.h> | ||
23 | #include <qmessagebox.h> | ||
24 | #include <qlineedit.h> | ||
25 | #include <qcheckbox.h> | ||
26 | |||
27 | #include <unistd.h> | ||
28 | |||
29 | fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) | ||
30 | : QDialog( parent, name, modal, fl ) | ||
31 | { | ||
32 | if ( !name ) | ||
33 | setName( tr("fileSaver")); | ||
34 | resize( 240, 280 ); | ||
35 | setCaption(tr( name ) ); | ||
36 | QFileInfo fi(currentFileName); | ||
37 | QString tmpFileName=fi.fileName(); | ||
38 | // qDebug( tmpFileName); | ||
39 | dirLabel = new QLabel(this, "DirLabel"); | ||
40 | dirLabel->setText(currentDir.canonicalPath()); | ||
41 | dirLabel->setGeometry(10,20,230,15); | ||
42 | |||
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 | homeButton->setFlat(TRUE); | ||
47 | |||
48 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | ||
49 | docButton->setGeometry(170,4,25,25); | ||
50 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | ||
51 | |||
52 | docButton->setFlat(TRUE); | ||
53 | |||
54 | hideButton = new QPushButton( Resource::loadIconSet("textedit/s_hidden"),"",this,"hideButton"); | ||
55 | hideButton->setGeometry(140,4,25,25); | ||
56 | connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) ); | ||
57 | hideButton->setToggleButton(TRUE); | ||
58 | hideButton->setFlat(TRUE); | ||
59 | |||
60 | ListView = new QListView( this, "ListView" ); | ||
61 | ListView->addColumn( tr( "Name" ) ); | ||
62 | ListView->setColumnWidth(0,120); | ||
63 | ListView->setSorting( 2, FALSE); | ||
64 | ListView->addColumn( tr( "Size" ) ); | ||
65 | ListView->setColumnWidth(1,-1); | ||
66 | ListView->addColumn( tr("Date"),-1); | ||
67 | |||
68 | ListView->setColumnWidthMode(0,QListView::Manual); | ||
69 | ListView->setColumnAlignment(1,QListView::AlignRight); | ||
70 | // ListView->setMultiSelection(true); | ||
71 | // ListView->setSelectionMode(QListView::Extended); | ||
72 | |||
73 | ListView->setAllColumnsShowFocus( TRUE ); | ||
74 | ListView->setGeometry( QRect( 10,35,220,125)); | ||
75 | |||
76 | fileEdit= new QLineEdit(this); | ||
77 | fileEdit->setGeometry( QRect( 10, 162, 205, 17)); | ||
78 | |||
79 | fileEdit->setText( tmpFileName); | ||
80 | |||
81 | filePermCheck = new QCheckBox( this, "SetFilePerms" ); | ||
82 | filePermCheck->setText(tr("set file permissions")); | ||
83 | filePermCheck->setGeometry(10, 178, 150,17); | ||
84 | // signals and slots connections | ||
85 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | ||
86 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | ||
87 | |||
88 | // tmpFileName=fi.FilePath(); | ||
89 | // qDebug( tmpFileName); | ||
90 | currentDir.setPath( QDir::currentDirPath() ); | ||
91 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); | ||
92 | populateList(); | ||
93 | move(0,15); | ||
94 | fileEdit->setFocus(); | ||
95 | } | ||
96 | |||
97 | fileSaver::~fileSaver() | ||
98 | { | ||
99 | } | ||
100 | |||
101 | void fileSaver::populateList() | ||
102 | { | ||
103 | ListView->clear(); | ||
104 | bool isDir=FALSE; | ||
105 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
106 | currentDir.setMatchAllDirs(TRUE); | ||
107 | |||
108 | currentDir.setNameFilter("*"); | ||
109 | QString fileL, fileS, fileDate; | ||
110 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | ||
111 | QFileInfoListIterator it(*list); | ||
112 | QFileInfo *fi; | ||
113 | while ( (fi=it.current()) ) { | ||
114 | |||
115 | if (fi->isSymLink() ){ | ||
116 | QString symLink=fi->readLink(); | ||
117 | // qDebug("Symlink detected "+symLink); | ||
118 | QFileInfo sym( symLink); | ||
119 | fileS.sprintf( "%10li", sym.size() ); | ||
120 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | ||
121 | |||
122 | } else { | ||
123 | // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | ||
124 | fileS.sprintf( "%10li", fi->size() ); | ||
125 | fileL.sprintf( "%s",fi->fileName().data() ); | ||
126 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | ||
127 | fileL+="/"; | ||
128 | isDir=TRUE; | ||
129 | // qDebug(currentDir.canonicalPath()+fileL); | ||
130 | } | ||
131 | } | ||
132 | if(fileL !="./") { | ||
133 | item= new QListViewItem( ListView,fileL,fileS , fileDate); | ||
134 | QPixmap pm; | ||
135 | |||
136 | if(isDir || fileL.find("/",0,TRUE) != -1) { | ||
137 | if( !QDir( fi->filePath() ).isReadable()) | ||
138 | pm = Resource::loadPixmap( "lockedfolder" ); | ||
139 | else | ||
140 | pm= Resource::loadPixmap( "folder" ); | ||
141 | item->setPixmap( 0,pm ); | ||
142 | } else { | ||
143 | if( !fi->isReadable() ) | ||
144 | pm = Resource::loadPixmap( "locked" ); | ||
145 | else { | ||
146 | MimeType mt(fi->filePath()); | ||
147 | pm=mt.pixmap(); | ||
148 | if(pm.isNull()) | ||
149 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | ||
150 | item->setPixmap( 0,pm); | ||
151 | } | ||
152 | } | ||
153 | if( fileL.find("->",0,TRUE) != -1) { | ||
154 | // overlay link image | ||
155 | pm= Resource::loadPixmap( "folder" ); | ||
156 | QPixmap lnk = Resource::loadPixmap( "symlink" ); | ||
157 | QPainter painter( &pm ); | ||
158 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | ||
159 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | ||
160 | item->setPixmap( 0, pm); | ||
161 | } | ||
162 | } | ||
163 | isDir=FALSE; | ||
164 | ++it; | ||
165 | } | ||
166 | ListView->setSorting( 2, FALSE); | ||
167 | dirLabel->setText(currentDir.canonicalPath()); | ||
168 | |||
169 | |||
170 | } | ||
171 | |||
172 | void fileSaver::upDir() | ||
173 | { | ||
174 | // qDebug(currentDir.canonicalPath()); | ||
175 | } | ||
176 | |||
177 | void fileSaver::listDoubleClicked(QListViewItem *selectedItem) | ||
178 | { | ||
179 | } | ||
180 | |||
181 | void fileSaver::listClicked(QListViewItem *selectedItem) | ||
182 | { | ||
183 | if(selectedItem != NULL) { | ||
184 | QString strItem=selectedItem->text(0); | ||
185 | QString strSize=selectedItem->text(1); | ||
186 | // qDebug("strItem is "+strItem); | ||
187 | strSize.stripWhiteSpace(); | ||
188 | // qDebug(strSize); | ||
189 | |||
190 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | ||
191 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | ||
192 | // qDebug("strItem symlink is "+strItem2); | ||
193 | if(QDir(strItem2).exists() ) { | ||
194 | currentDir.cd(strItem2, TRUE); | ||
195 | populateList(); | ||
196 | } | ||
197 | } else { // not a symlink | ||
198 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | ||
199 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | ||
200 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | ||
201 | currentDir.cd(strItem,FALSE); | ||
202 | // qDebug("Path is "+strItem); | ||
203 | populateList(); | ||
204 | } else { | ||
205 | currentDir.cdUp(); | ||
206 | populateList(); | ||
207 | } | ||
208 | if(QDir(strItem).exists()){ | ||
209 | currentDir.cd(strItem, TRUE); | ||
210 | populateList(); | ||
211 | } | ||
212 | } // else | ||
213 | // if( QFile::exists(strItem ) ) { | ||
214 | // qDebug("We found our files!!"); | ||
215 | |||
216 | // OnOK(); | ||
217 | } //end not symlink | ||
218 | chdir(strItem.latin1()); | ||
219 | |||
220 | } | ||
221 | } | ||
222 | |||
223 | |||
224 | void fileSaver::closeEvent( QCloseEvent *e ) | ||
225 | { | ||
226 | if(e->isAccepted()) { | ||
227 | e->accept(); | ||
228 | } else { | ||
229 | qDebug("not accepted"); | ||
230 | done(-1); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | void fileSaver::accept() { | ||
235 | selectedFileName = fileEdit->text(); | ||
236 | QString path = currentDir.canonicalPath()+"/" + selectedFileName; | ||
237 | if( path.find("//",0,TRUE) ==-1 ) { | ||
238 | selectedFileName = path; | ||
239 | } else { | ||
240 | selectedFileName = currentDir.canonicalPath()+selectedFileName; | ||
241 | } | ||
242 | qDebug("going to save "+selectedFileName); | ||
243 | done(1); | ||
244 | } | ||
245 | |||
246 | void fileSaver::homeButtonPushed() { | ||
247 | chdir( QDir::homeDirPath().latin1() ); | ||
248 | currentDir.cd( QDir::homeDirPath(), TRUE); | ||
249 | populateList(); | ||
250 | update(); | ||
251 | } | ||
252 | void fileSaver::docButtonPushed() { | ||
253 | chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); | ||
254 | currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); | ||
255 | populateList(); | ||
256 | update(); | ||
257 | |||
258 | } | ||
259 | |||
260 | void fileSaver::hideButtonPushed(bool b) { | ||
261 | if (b) | ||
262 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | ||
263 | else | ||
264 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
265 | |||
266 | // chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); | ||
267 | // currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); | ||
268 | populateList(); | ||
269 | update(); | ||
270 | |||
271 | } | ||