author | llornkcor <llornkcor> | 2002-02-18 14:08:55 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-18 14:08:55 (UTC) |
commit | 9741205aa0b0892b870d2b7df7c5dd7e25b0bb18 (patch) (unidiff) | |
tree | 7f2f3d44ff3215984bd8b487b206d3d958a498da /core/apps/textedit/fileSaver.cpp | |
parent | 0640b30f13beb9d6480d8042ec5397a68e6247fc (diff) | |
download | opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.zip opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.tar.gz opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.tar.bz2 |
added fontDialog, fileBrowserDialog, and fileSave dialog, so we can edit anyfile, save anywhere,
using a user selected name.
Changed what is seen when it opens. It now opens with the texteditor opened to a new
file, instead of the file selector, unless one is specified from commandline, or setDocument message.
FileSelector is still available, but from a menu item.
Diffstat (limited to 'core/apps/textedit/fileSaver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp new file mode 100644 index 0000000..d01daee --- a/dev/null +++ b/core/apps/textedit/fileSaver.cpp | |||
@@ -0,0 +1,164 @@ | |||
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/qpeapplication.h> | ||
17 | |||
18 | #include <qlistview.h> | ||
19 | #include <qpushbutton.h> | ||
20 | #include <qfile.h> | ||
21 | #include <qmessagebox.h> | ||
22 | #include <unistd.h> | ||
23 | #include <qlineedit.h> | ||
24 | |||
25 | fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) | ||
26 | : QDialog( parent, name, modal, fl ) | ||
27 | { | ||
28 | if ( !name ) | ||
29 | setName( "fileSaver" ); | ||
30 | resize( 236, 280 ); | ||
31 | setCaption(tr( "Save file" ) ); | ||
32 | // filterStr=currentFileName; | ||
33 | |||
34 | dirLabel = new QLabel(this, "DirLabel"); | ||
35 | dirLabel->setText(currentDir.canonicalPath()); | ||
36 | dirLabel->setGeometry(10,4,230,30); | ||
37 | |||
38 | ListView = new QListView( this, "ListView" ); | ||
39 | ListView->addColumn( tr( "Name" ) ); | ||
40 | ListView->setColumnWidth(0,140); | ||
41 | ListView->setSorting( 2, FALSE); | ||
42 | ListView->addColumn( tr( "Size" ) ); | ||
43 | ListView->setColumnWidth(1,59); | ||
44 | // ListView->setMultiSelection(true); | ||
45 | // ListView->setSelectionMode(QListView::Extended); | ||
46 | |||
47 | ListView->setAllColumnsShowFocus( TRUE ); | ||
48 | ListView->setGeometry( QRect( 10, 35, 220, 160 ) ); | ||
49 | |||
50 | fileEdit= new QLineEdit(this); | ||
51 | fileEdit->setGeometry( QRect( 10, 230, 200, 25)); | ||
52 | fileEdit->setText(currentFileName); | ||
53 | // signals and slots connections | ||
54 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | ||
55 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | ||
56 | currentDir.setPath(QDir::currentDirPath() ); | ||
57 | populateList(); | ||
58 | } | ||
59 | |||
60 | fileSaver::~fileSaver() | ||
61 | { | ||
62 | } | ||
63 | |||
64 | |||
65 | void fileSaver::populateList() | ||
66 | { | ||
67 | ListView->clear(); | ||
68 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); | ||
69 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
70 | currentDir.setMatchAllDirs(TRUE); | ||
71 | |||
72 | currentDir.setNameFilter("*"); | ||
73 | QString fileL, fileS; | ||
74 | const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); | ||
75 | QFileInfoListIterator it(*list); | ||
76 | QFileInfo *fi; | ||
77 | while ( (fi=it.current()) ) { | ||
78 | |||
79 | if (fi->isSymLink() ){ | ||
80 | QString symLink=fi->readLink(); | ||
81 | // qDebug("Symlink detected "+symLink); | ||
82 | QFileInfo sym( symLink); | ||
83 | fileS.sprintf( "%10li", sym.size() ); | ||
84 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | ||
85 | |||
86 | } else { | ||
87 | // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | ||
88 | fileS.sprintf( "%10li", fi->size() ); | ||
89 | fileL.sprintf( "%s",fi->fileName().data() ); | ||
90 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | ||
91 | fileL+="/"; | ||
92 | // qDebug(currentDir.canonicalPath()+fileL); | ||
93 | } | ||
94 | } | ||
95 | item= new QListViewItem( ListView,fileL,fileS ); | ||
96 | ++it; | ||
97 | } | ||
98 | ListView->setSorting( 2, FALSE); | ||
99 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); | ||
100 | |||
101 | |||
102 | } | ||
103 | |||
104 | void fileSaver::upDir() | ||
105 | { | ||
106 | // qDebug(currentDir.canonicalPath()); | ||
107 | } | ||
108 | |||
109 | void fileSaver::listDoubleClicked(QListViewItem *selectedItem) | ||
110 | { | ||
111 | } | ||
112 | |||
113 | void fileSaver::listClicked(QListViewItem *selectedItem) | ||
114 | { | ||
115 | QString strItem=selectedItem->text(0); | ||
116 | QString strSize=selectedItem->text(1); | ||
117 | // qDebug("strItem is "+strItem); | ||
118 | strSize.stripWhiteSpace(); | ||
119 | // qDebug(strSize); | ||
120 | |||
121 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | ||
122 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | ||
123 | // qDebug("strItem symlink is "+strItem2); | ||
124 | if(QDir(strItem2).exists() ) { | ||
125 | currentDir.cd(strItem2, TRUE); | ||
126 | populateList(); | ||
127 | } | ||
128 | } else { // not a symlink | ||
129 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | ||
130 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | ||
131 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | ||
132 | currentDir.cd(strItem,FALSE); | ||
133 | // qDebug("Path is "+strItem); | ||
134 | populateList(); | ||
135 | } else { | ||
136 | currentDir.cdUp(); | ||
137 | populateList(); | ||
138 | } | ||
139 | if(QDir(strItem).exists()){ | ||
140 | currentDir.cd(strItem, TRUE); | ||
141 | populateList(); | ||
142 | } | ||
143 | } // else | ||
144 | // if( QFile::exists(strItem ) ) { | ||
145 | // qDebug("We found our files!!"); | ||
146 | |||
147 | // OnOK(); | ||
148 | } //end not symlink | ||
149 | chdir(strItem.latin1()); | ||
150 | |||
151 | |||
152 | } | ||
153 | |||
154 | |||
155 | void fileSaver::OnOK() | ||
156 | { | ||
157 | // reject(); | ||
158 | } | ||
159 | |||
160 | void fileSaver::accept() { | ||
161 | selectedFileName = fileEdit->text(); | ||
162 | selectedFileName = currentDir.canonicalPath()+ selectedFileName; | ||
163 | reject(); | ||
164 | } | ||