-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 22 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 5 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 2 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 3 |
4 files changed, 23 insertions, 9 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index e103bcb..7a3a703 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp | |||
@@ -1,575 +1,587 @@ | |||
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 | #define QTOPIA_INTERNAL_MIMEEXT | ||
14 | #include "fileBrowser.h" | 15 | #include "fileBrowser.h" |
15 | //#include "inputDialog.h" | 16 | //#include "inputDialog.h" |
16 | 17 | ||
17 | #include <qpe/config.h> | 18 | #include <qpe/config.h> |
18 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
19 | #include <qpe/fileselector.h> | 20 | #include <qpe/fileselector.h> |
20 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/menubutton.h> | 22 | #include <qpe/menubutton.h> |
22 | #include <qpe/mimetype.h> | 23 | #include <qpe/mimetype.h> |
23 | 24 | ||
24 | #include <qdict.h> | 25 | #include <qdict.h> |
25 | #include <qwidgetstack.h> | 26 | #include <qwidgetstack.h> |
26 | #include <qlistview.h> | 27 | #include <qlistview.h> |
27 | #include <qcombo.h> | 28 | #include <qcombo.h> |
28 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
29 | #include <qfile.h> | 30 | #include <qfile.h> |
30 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
31 | #include <qlayout.h> | 32 | #include <qlayout.h> |
32 | #include <unistd.h> | 33 | #include <unistd.h> |
33 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
34 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
35 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
36 | 37 | ||
37 | #include <unistd.h> | 38 | #include <unistd.h> |
38 | #include <stdlib.h> | 39 | #include <stdlib.h> |
39 | 40 | ||
40 | static int u_id = 1; | 41 | static int u_id = 1; |
41 | static int get_unique_id() | 42 | static int get_unique_id() |
42 | { | 43 | { |
43 | return u_id++; | 44 | return u_id++; |
44 | } | 45 | } |
45 | 46 | ||
46 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) | 47 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString mimeFilter ) |
47 | : QDialog( parent, name, modal, fl ) | 48 | : QDialog( parent, name, modal, fl ) |
48 | { | 49 | { |
49 | if ( !name ) | 50 | if ( !name ) |
50 | setName( "fileBrowser" ); | 51 | setName( "fileBrowser" ); |
51 | setCaption(tr( name ) ); | 52 | setCaption(tr( name ) ); |
52 | filterStr = filter; | 53 | mimeType = mimeFilter; |
54 | MimeType mt( mimeType); | ||
55 | if( mt.extension().isEmpty()) | ||
56 | filterStr = "*"; | ||
57 | else | ||
58 | filterStr = "*."+ mt.extension(); | ||
59 | // qDebug("description "+mt.description()); | ||
60 | // qDebug( "id "+mt.id()); | ||
61 | // qDebug("extension "+mt.extension()); | ||
62 | |||
53 | // channel = new QCopChannel( "QPE/fileDialog", this ); | 63 | // channel = new QCopChannel( "QPE/fileDialog", this ); |
54 | // connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 64 | // connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
55 | // this, SLOT(receive(const QCString&, const QByteArray&)) ); | 65 | // this, SLOT(receive(const QCString&, const QByteArray&)) ); |
56 | 66 | ||
57 | QGridLayout *layout = new QGridLayout( this ); | 67 | QGridLayout *layout = new QGridLayout( this ); |
58 | layout->setSpacing( 4 ); | 68 | layout->setSpacing( 4 ); |
59 | layout->setMargin( 4 ); | 69 | layout->setMargin( 4 ); |
60 | 70 | ||
61 | dirPathCombo = new QComboBox( FALSE, this, "dorPathCombo" ); | 71 | dirPathCombo = new QComboBox( FALSE, this, "dorPathCombo" ); |
62 | dirPathCombo->setEditable(TRUE); | 72 | dirPathCombo->setEditable(TRUE); |
63 | 73 | ||
64 | connect( dirPathCombo, SIGNAL( activated( const QString & ) ), | 74 | connect( dirPathCombo, SIGNAL( activated( const QString & ) ), |
65 | this, SLOT( dirPathComboActivated( const QString & ) ) ); | 75 | this, SLOT( dirPathComboActivated( const QString & ) ) ); |
66 | 76 | ||
67 | connect( dirPathCombo->lineEdit(), SIGNAL( returnPressed( ) ), | 77 | connect( dirPathCombo->lineEdit(), SIGNAL( returnPressed( ) ), |
68 | this, SLOT( dirPathEditPressed( ) ) ); | 78 | this, SLOT( dirPathEditPressed( ) ) ); |
69 | 79 | ||
70 | dirPathStringList << "/"; | 80 | dirPathStringList << "/"; |
71 | // we can get the storage here | 81 | // we can get the storage here |
72 | 82 | ||
73 | layout->addMultiCellWidget( dirPathCombo, 0, 0, 0, 4 ); | 83 | layout->addMultiCellWidget( dirPathCombo, 0, 0, 0, 4 ); |
74 | 84 | ||
75 | cdUpButton = new QPushButton(Resource::loadIconSet("up"),"",this,"cdUpButton"); | 85 | cdUpButton = new QPushButton(Resource::loadIconSet("up"),"",this,"cdUpButton"); |
76 | cdUpButton ->setMinimumSize( QSize( 20, 20 ) ); | 86 | cdUpButton ->setMinimumSize( QSize( 20, 20 ) ); |
77 | cdUpButton ->setMaximumSize( QSize( 20, 20 ) ); | 87 | cdUpButton ->setMaximumSize( QSize( 20, 20 ) ); |
78 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); | 88 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); |
79 | cdUpButton ->setFlat(TRUE); | 89 | cdUpButton ->setFlat(TRUE); |
80 | layout->addMultiCellWidget( cdUpButton, 0, 0, 5, 5 ); | 90 | layout->addMultiCellWidget( cdUpButton, 0, 0, 5, 5 ); |
81 | 91 | ||
82 | |||
83 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | 92 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); |
84 | docButton->setMinimumSize( QSize( 20, 20 ) ); | 93 | docButton->setMinimumSize( QSize( 20, 20 ) ); |
85 | docButton->setMaximumSize( QSize( 20, 20 ) ); | 94 | docButton->setMaximumSize( QSize( 20, 20 ) ); |
86 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | 95 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); |
87 | docButton->setFlat(TRUE); | 96 | docButton->setFlat(TRUE); |
88 | layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); | 97 | layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); |
89 | 98 | ||
90 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); | 99 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); |
91 | homeButton->setMinimumSize( QSize( 20, 20 ) ); | 100 | homeButton->setMinimumSize( QSize( 20, 20 ) ); |
92 | homeButton->setMaximumSize( QSize( 20, 20 ) ); | 101 | homeButton->setMaximumSize( QSize( 20, 20 ) ); |
93 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | 102 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); |
94 | homeButton->setFlat(TRUE); | 103 | homeButton->setFlat(TRUE); |
95 | layout->addMultiCellWidget( homeButton, 0, 0, 7, 7 ); | 104 | layout->addMultiCellWidget( homeButton, 0, 0, 7, 7 ); |
96 | 105 | ||
97 | FileStack = new QWidgetStack( this ); | 106 | FileStack = new QWidgetStack( this ); |
98 | 107 | ||
99 | |||
100 | ListView = new QListView( this, "ListView" ); | 108 | ListView = new QListView( this, "ListView" ); |
101 | // ListView->setMinimumSize( QSize( 100, 25 ) ); | 109 | // ListView->setMinimumSize( QSize( 100, 25 ) ); |
102 | ListView->addColumn( tr( "Name" ) ); | 110 | ListView->addColumn( tr( "Name" ) ); |
103 | ListView->setColumnWidth(0,120); | 111 | ListView->setColumnWidth(0,120); |
104 | ListView->setSorting( 2, FALSE); | 112 | ListView->setSorting( 2, FALSE); |
105 | ListView->addColumn( tr( "Size" ) ); | 113 | ListView->addColumn( tr( "Size" ) ); |
106 | ListView->setColumnWidth(1,-1); | 114 | ListView->setColumnWidth(1,-1); |
107 | ListView->addColumn( "Date",-1); | 115 | ListView->addColumn( "Date",-1); |
108 | 116 | ||
109 | ListView->setColumnWidthMode(0,QListView::Manual); | 117 | ListView->setColumnWidthMode(0,QListView::Manual); |
110 | ListView->setColumnAlignment(1,QListView::AlignRight); | 118 | ListView->setColumnAlignment(1,QListView::AlignRight); |
111 | ListView->setColumnAlignment(2,QListView::AlignRight); | 119 | ListView->setColumnAlignment(2,QListView::AlignRight); |
112 | ListView->setAllColumnsShowFocus( TRUE ); | 120 | ListView->setAllColumnsShowFocus( TRUE ); |
113 | 121 | ||
114 | QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); | 122 | QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); |
115 | connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 123 | connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
116 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | 124 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); |
117 | 125 | ||
118 | connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 126 | connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
119 | 127 | ||
120 | FileStack->addWidget( ListView, get_unique_id() ); | 128 | FileStack->addWidget( ListView, get_unique_id() ); |
121 | mimeType="text/*"; | 129 | |
122 | fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy | 130 | fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy |
123 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 131 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
124 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 132 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
125 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 133 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
126 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 ); | 134 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 ); |
127 | 135 | ||
128 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); | 136 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); |
129 | SelectionCombo->insertItem( tr( "Documents" ) ); | 137 | SelectionCombo->insertItem( tr( "Documents" ) ); |
130 | SelectionCombo->insertItem( tr( "All files" ) ); | 138 | SelectionCombo->insertItem( tr( "All files" ) ); |
131 | SelectionCombo->insertItem( tr( "Hidden files" ) ); | 139 | SelectionCombo->insertItem( tr( "Hidden files" ) ); |
132 | // SelectionCombo->setMaximumWidth(120); | 140 | // SelectionCombo->setMaximumWidth(120); |
133 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 ); | 141 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 ); |
134 | 142 | ||
135 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), | 143 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), |
136 | this, SLOT( selectionChanged( const QString & ) ) ); | 144 | this, SLOT( selectionChanged( const QString & ) ) ); |
137 | 145 | ||
138 | typemb = new MenuButton(this); | 146 | typemb = new MenuButton(this); |
139 | typemb->setLabel(tr("Type: %1")); | 147 | typemb->setLabel(tr("Type: %1")); |
140 | typemb->setMinimumWidth(110); | 148 | typemb->setMinimumWidth(110); |
141 | typemb->setFixedHeight(22); | 149 | typemb->setFixedHeight(22); |
142 | layout->addMultiCellWidget( typemb, 2, 2, 4, 7 ); | 150 | layout->addMultiCellWidget( typemb, 2, 2, 4, 7 ); |
143 | updateMimeTypeMenu() ; | 151 | updateMimeTypeMenu() ; |
144 | 152 | ||
145 | currentDir.setPath(QDir::currentDirPath()); | 153 | currentDir.setPath(QDir::currentDirPath()); |
146 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); | 154 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); |
147 | 155 | ||
148 | populateList(); | 156 | populateList(); |
149 | move(0,15); | 157 | move(0,15); |
150 | } | 158 | } |
151 | 159 | ||
152 | fileBrowser::~fileBrowser() | 160 | fileBrowser::~fileBrowser() |
153 | { | 161 | { |
154 | } | 162 | } |
155 | 163 | ||
164 | void fileBrowser::setMimeType(const QString &type) { | ||
165 | mimeType = type; | ||
166 | } | ||
167 | |||
156 | void fileBrowser::setFileView( int selection ) | 168 | void fileBrowser::setFileView( int selection ) |
157 | { | 169 | { |
158 | SelectionCombo->setCurrentItem( selection ); | 170 | SelectionCombo->setCurrentItem( selection ); |
159 | selectionChanged( SelectionCombo->currentText() ); | 171 | selectionChanged( SelectionCombo->currentText() ); |
160 | } | 172 | } |
161 | 173 | ||
162 | void fileBrowser::populateList() | 174 | void fileBrowser::populateList() |
163 | { | 175 | { |
164 | ListView->clear(); | 176 | ListView->clear(); |
165 | bool isDir=FALSE; | 177 | bool isDir=FALSE; |
166 | //qDebug(currentDir.canonicalPath()); | 178 | //qDebug(currentDir.canonicalPath()); |
167 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 179 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
168 | currentDir.setMatchAllDirs(TRUE); | 180 | currentDir.setMatchAllDirs(TRUE); |
169 | 181 | ||
170 | currentDir.setNameFilter(filterStr); | 182 | currentDir.setNameFilter(filterStr); |
171 | // currentDir.setNameFilter("*.txt;*.etx"); | 183 | // currentDir.setNameFilter("*.txt;*.etx"); |
172 | QString fileL, fileS, fileDate; | 184 | QString fileL, fileS, fileDate; |
173 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 185 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
174 | QFileInfoListIterator it(*list); | 186 | QFileInfoListIterator it(*list); |
175 | QFileInfo *fi; | 187 | QFileInfo *fi; |
176 | while ( (fi=it.current()) ) { | 188 | while ( (fi=it.current()) ) { |
177 | 189 | ||
178 | if (fi->isSymLink() ){ | 190 | if (fi->isSymLink() ){ |
179 | QString symLink=fi->readLink(); | 191 | QString symLink=fi->readLink(); |
180 | // qDebug("Symlink detected "+symLink); | 192 | // qDebug("Symlink detected "+symLink); |
181 | QFileInfo sym( symLink); | 193 | QFileInfo sym( symLink); |
182 | fileS.sprintf( "%10li", sym.size() ); | 194 | fileS.sprintf( "%10li", sym.size() ); |
183 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | 195 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); |
184 | fileDate = sym.lastModified().toString(); | 196 | fileDate = sym.lastModified().toString(); |
185 | } else { | 197 | } else { |
186 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 198 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
187 | fileS.sprintf( "%10li", fi->size() ); | 199 | fileS.sprintf( "%10li", fi->size() ); |
188 | fileL.sprintf( "%s",fi->fileName().data() ); | 200 | fileL.sprintf( "%s",fi->fileName().data() ); |
189 | fileDate= fi->lastModified().toString(); | 201 | fileDate= fi->lastModified().toString(); |
190 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 202 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
191 | fileL+="/"; | 203 | fileL+="/"; |
192 | isDir=TRUE; | 204 | isDir=TRUE; |
193 | // qDebug( fileL); | 205 | // qDebug( fileL); |
194 | } | 206 | } |
195 | } | 207 | } |
196 | if(fileL !="./") { | 208 | if(fileL !="./") { |
197 | item= new QListViewItem( ListView,fileL,fileS , fileDate); | 209 | item= new QListViewItem( ListView,fileL,fileS , fileDate); |
198 | QPixmap pm; | 210 | QPixmap pm; |
199 | 211 | ||
200 | if(isDir || fileL.find("/",0,TRUE) != -1) { | 212 | if(isDir || fileL.find("/",0,TRUE) != -1) { |
201 | if( !QDir( fi->filePath() ).isReadable()) | 213 | if( !QDir( fi->filePath() ).isReadable()) |
202 | pm = Resource::loadPixmap( "lockedfolder" ); | 214 | pm = Resource::loadPixmap( "lockedfolder" ); |
203 | else | 215 | else |
204 | pm= Resource::loadPixmap( "folder" ); | 216 | pm= Resource::loadPixmap( "folder" ); |
205 | item->setPixmap( 0,pm ); | 217 | item->setPixmap( 0,pm ); |
206 | } else { | 218 | } else { |
207 | if( !fi->isReadable() ) | 219 | if( !fi->isReadable() ) |
208 | pm = Resource::loadPixmap( "locked" ); | 220 | pm = Resource::loadPixmap( "locked" ); |
209 | else { | 221 | else { |
210 | MimeType mt(fi->filePath()); | 222 | MimeType mt(fi->filePath()); |
211 | pm=mt.pixmap(); | 223 | pm=mt.pixmap(); |
212 | if(pm.isNull()) | 224 | if(pm.isNull()) |
213 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | 225 | pm = Resource::loadPixmap( "UnknownDocument-14" ); |
214 | item->setPixmap( 0,pm); | 226 | item->setPixmap( 0,pm); |
215 | } | 227 | } |
216 | } | 228 | } |
217 | if( fileL.find("->",0,TRUE) != -1) { | 229 | if( fileL.find("->",0,TRUE) != -1) { |
218 | // overlay link image | 230 | // overlay link image |
219 | pm= Resource::loadPixmap( "folder" ); | 231 | pm= Resource::loadPixmap( "folder" ); |
220 | QPixmap lnk = Resource::loadPixmap( "symlink" ); | 232 | QPixmap lnk = Resource::loadPixmap( "symlink" ); |
221 | QPainter painter( &pm ); | 233 | QPainter painter( &pm ); |
222 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 234 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
223 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 235 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
224 | item->setPixmap( 0, pm); | 236 | item->setPixmap( 0, pm); |
225 | } | 237 | } |
226 | } | 238 | } |
227 | isDir=FALSE; | 239 | isDir=FALSE; |
228 | ++it; | 240 | ++it; |
229 | } | 241 | } |
230 | ListView->setSorting( 3, FALSE); | 242 | ListView->setSorting( 3, FALSE); |
231 | QString currentPath = currentDir.canonicalPath(); | 243 | QString currentPath = currentDir.canonicalPath(); |
232 | 244 | ||
233 | fillCombo( (const QString &)currentPath); | 245 | fillCombo( (const QString &)currentPath); |
234 | // dirPathCombo->lineEdit()->setText(currentPath); | 246 | // dirPathCombo->lineEdit()->setText(currentPath); |
235 | 247 | ||
236 | // if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 248 | // if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
237 | // dirPathCombo->clear(); | 249 | // dirPathCombo->clear(); |
238 | // dirPathStringList.prepend(currentPath ); | 250 | // dirPathStringList.prepend(currentPath ); |
239 | // dirPathCombo->insertStringList( dirPathStringList,-1); | 251 | // dirPathCombo->insertStringList( dirPathStringList,-1); |
240 | // } | 252 | // } |
241 | } | 253 | } |
242 | 254 | ||
243 | void fileBrowser::upDir() | 255 | void fileBrowser::upDir() |
244 | { | 256 | { |
245 | QString current = currentDir.canonicalPath(); | 257 | QString current = currentDir.canonicalPath(); |
246 | QDir dir(current); | 258 | QDir dir(current); |
247 | dir.cdUp(); | 259 | dir.cdUp(); |
248 | current = dir.canonicalPath(); | 260 | current = dir.canonicalPath(); |
249 | chdir( current.latin1() ); | 261 | chdir( current.latin1() ); |
250 | currentDir.cd( current, TRUE); | 262 | currentDir.cd( current, TRUE); |
251 | populateList(); | 263 | populateList(); |
252 | update(); | 264 | update(); |
253 | } | 265 | } |
254 | 266 | ||
255 | // you may want to switch these 2 functions. I like single clicks | 267 | // you may want to switch these 2 functions. I like single clicks |
256 | void fileBrowser::listClicked(QListViewItem *selectedItem) | 268 | void fileBrowser::listClicked(QListViewItem *selectedItem) |
257 | { | 269 | { |
258 | QString strItem=selectedItem->text(0); | 270 | QString strItem=selectedItem->text(0); |
259 | QString strSize=selectedItem->text(1); | 271 | QString strSize=selectedItem->text(1); |
260 | // qDebug("strItem is "+strItem); | 272 | // qDebug("strItem is "+strItem); |
261 | strSize.stripWhiteSpace(); | 273 | strSize.stripWhiteSpace(); |
262 | // qDebug(strSize); | 274 | // qDebug(strSize); |
263 | 275 | ||
264 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 276 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
265 | // is symlink | 277 | // is symlink |
266 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | 278 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); |
267 | // qDebug("strItem symlink is "+strItem2); | 279 | // qDebug("strItem symlink is "+strItem2); |
268 | if(QDir(strItem2).exists() ) { | 280 | if(QDir(strItem2).exists() ) { |
269 | currentDir.cd(strItem2, TRUE); | 281 | currentDir.cd(strItem2, TRUE); |
270 | populateList(); | 282 | populateList(); |
271 | } | 283 | } |
272 | } else { // not a symlink | 284 | } else { // not a symlink |
273 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | 285 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { |
274 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | 286 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { |
275 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 287 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
276 | currentDir.cd(strItem,FALSE); | 288 | currentDir.cd(strItem,FALSE); |
277 | // qDebug("Path is "+strItem); | 289 | // qDebug("Path is "+strItem); |
278 | populateList(); | 290 | populateList(); |
279 | } else { | 291 | } else { |
280 | currentDir.cdUp(); | 292 | currentDir.cdUp(); |
281 | populateList(); | 293 | populateList(); |
282 | } | 294 | } |
283 | if(QDir(strItem).exists()){ | 295 | if(QDir(strItem).exists()){ |
284 | currentDir.cd(strItem, TRUE); | 296 | currentDir.cd(strItem, TRUE); |
285 | populateList(); | 297 | populateList(); |
286 | } | 298 | } |
287 | } else { | 299 | } else { |
288 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 300 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
289 | if( QFile::exists(strItem ) ) { | 301 | if( QFile::exists(strItem ) ) { |
290 | //currentDir.canonicalPath() | 302 | //currentDir.canonicalPath() |
291 | qDebug("We found our files!!"+strItem); | 303 | qDebug("We found our files!!"+strItem); |
292 | OnOK(); | 304 | OnOK(); |
293 | } | 305 | } |
294 | } //end not symlink | 306 | } //end not symlink |
295 | chdir(strItem.latin1()); | 307 | chdir(strItem.latin1()); |
296 | } | 308 | } |
297 | } | 309 | } |
298 | 310 | ||
299 | void fileBrowser::OnOK() | 311 | void fileBrowser::OnOK() |
300 | { | 312 | { |
301 | QListViewItemIterator it1( ListView); | 313 | QListViewItemIterator it1( ListView); |
302 | for ( ; it1.current(); ++it1 ) { | 314 | for ( ; it1.current(); ++it1 ) { |
303 | if ( it1.current()->isSelected() ) { | 315 | if ( it1.current()->isSelected() ) { |
304 | selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); | 316 | selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); |
305 | qDebug("selected filename is "+selectedFileName); | 317 | qDebug("selected filename is "+selectedFileName); |
306 | fileList.append( selectedFileName ); | 318 | fileList.append( selectedFileName ); |
307 | } | 319 | } |
308 | } | 320 | } |
309 | accept(); | 321 | accept(); |
310 | } | 322 | } |
311 | 323 | ||
312 | void fileBrowser::homeButtonPushed() { | 324 | void fileBrowser::homeButtonPushed() { |
313 | QString current = QDir::homeDirPath(); | 325 | QString current = QDir::homeDirPath(); |
314 | chdir( current.latin1() ); | 326 | chdir( current.latin1() ); |
315 | currentDir.cd( current, TRUE); | 327 | currentDir.cd( current, TRUE); |
316 | populateList(); | 328 | populateList(); |
317 | update(); | 329 | update(); |
318 | } | 330 | } |
319 | 331 | ||
320 | void fileBrowser::docButtonPushed() { | 332 | void fileBrowser::docButtonPushed() { |
321 | QString current = QPEApplication::documentDir(); | 333 | QString current = QPEApplication::documentDir(); |
322 | chdir( current.latin1() ); | 334 | chdir( current.latin1() ); |
323 | currentDir.cd( current, TRUE); | 335 | currentDir.cd( current, TRUE); |
324 | populateList(); | 336 | populateList(); |
325 | update(); | 337 | update(); |
326 | 338 | ||
327 | } | 339 | } |
328 | 340 | ||
329 | void fileBrowser::selectionChanged( const QString &select ) | 341 | void fileBrowser::selectionChanged( const QString &select ) |
330 | { | 342 | { |
331 | if ( select == "Documents") { | 343 | if ( select == "Documents") { |
332 | FileStack->raiseWidget( fileSelector ); | 344 | FileStack->raiseWidget( fileSelector ); |
333 | dirPathCombo->hide(); | 345 | dirPathCombo->hide(); |
334 | cdUpButton->hide(); | 346 | cdUpButton->hide(); |
335 | docButton->hide(); | 347 | docButton->hide(); |
336 | homeButton->hide(); | 348 | homeButton->hide(); |
337 | } else { | 349 | } else { |
338 | if ( select == "All files" ) | 350 | if ( select == "All files" ) |
339 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); | 351 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); |
340 | else | 352 | else |
341 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 353 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
342 | 354 | ||
343 | populateList(); | 355 | populateList(); |
344 | update(); | 356 | update(); |
345 | dirPathCombo->show(); | 357 | dirPathCombo->show(); |
346 | cdUpButton->show(); | 358 | cdUpButton->show(); |
347 | docButton->show(); | 359 | docButton->show(); |
348 | homeButton->show(); | 360 | homeButton->show(); |
349 | FileStack->raiseWidget( ListView ); | 361 | FileStack->raiseWidget( ListView ); |
350 | } | 362 | } |
351 | } | 363 | } |
352 | 364 | ||
353 | void fileBrowser::docOpen( const DocLnk &doc ) | 365 | void fileBrowser::docOpen( const DocLnk &doc ) |
354 | { | 366 | { |
355 | fileList.append( doc.file().latin1() ); | 367 | fileList.append( doc.file().latin1() ); |
356 | accept(); | 368 | accept(); |
357 | } | 369 | } |
358 | 370 | ||
359 | void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | 371 | void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) |
360 | { | 372 | { |
361 | switch (mouse) { | 373 | switch (mouse) { |
362 | case 1: | 374 | case 1: |
363 | break; | 375 | break; |
364 | case 2: | 376 | case 2: |
365 | showListMenu(item); | 377 | showListMenu(item); |
366 | break; | 378 | break; |
367 | }; | 379 | }; |
368 | } | 380 | } |
369 | 381 | ||
370 | void fileBrowser::showListMenu(QListViewItem *item) { | 382 | void fileBrowser::showListMenu(QListViewItem *item) { |
371 | 383 | ||
372 | QPopupMenu m;// = new QPopupMenu( Local_View ); | 384 | QPopupMenu m;// = new QPopupMenu( Local_View ); |
373 | if( item->text(0).find("/",0,TRUE)) | 385 | if( item->text(0).find("/",0,TRUE)) |
374 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); | 386 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); |
375 | else | 387 | else |
376 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); | 388 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); |
377 | m.insertItem( tr( "Rescan" ), this, SLOT( populateList()() )); | 389 | m.insertItem( tr( "Rescan" ), this, SLOT( populateList()() )); |
378 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 390 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
379 | m.insertSeparator(); | 391 | m.insertSeparator(); |
380 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 392 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
381 | m.exec( QCursor::pos() ); | 393 | m.exec( QCursor::pos() ); |
382 | 394 | ||
383 | } | 395 | } |
384 | 396 | ||
385 | void fileBrowser::doCd() { | 397 | void fileBrowser::doCd() { |
386 | listClicked( ListView->currentItem()); | 398 | listClicked( ListView->currentItem()); |
387 | } | 399 | } |
388 | 400 | ||
389 | void fileBrowser::makDir() { | 401 | void fileBrowser::makDir() { |
390 | InputDialog *fileDlg; | 402 | InputDialog *fileDlg; |
391 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); | 403 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); |
392 | fileDlg->exec(); | 404 | fileDlg->exec(); |
393 | if( fileDlg->result() == 1 ) { | 405 | if( fileDlg->result() == 1 ) { |
394 | QString filename = fileDlg->LineEdit1->text(); | 406 | QString filename = fileDlg->LineEdit1->text(); |
395 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | 407 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); |
396 | } | 408 | } |
397 | populateList(); | 409 | populateList(); |
398 | } | 410 | } |
399 | 411 | ||
400 | void fileBrowser::localRename() { | 412 | void fileBrowser::localRename() { |
401 | QString curFile = ListView->currentItem()->text(0); | 413 | QString curFile = ListView->currentItem()->text(0); |
402 | InputDialog *fileDlg; | 414 | InputDialog *fileDlg; |
403 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); | 415 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); |
404 | fileDlg->inputText = curFile; | 416 | fileDlg->inputText = curFile; |
405 | fileDlg->exec(); | 417 | fileDlg->exec(); |
406 | if( fileDlg->result() == 1 ) { | 418 | if( fileDlg->result() == 1 ) { |
407 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | 419 | QString oldname = currentDir.canonicalPath() + "/" + curFile; |
408 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | 420 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; |
409 | if( rename(oldname.latin1(), newName.latin1())== -1) | 421 | if( rename(oldname.latin1(), newName.latin1())== -1) |
410 | QMessageBox::message("Note","Could not rename"); | 422 | QMessageBox::message("Note","Could not rename"); |
411 | } | 423 | } |
412 | populateList(); | 424 | populateList(); |
413 | } | 425 | } |
414 | 426 | ||
415 | void fileBrowser::localDelete() { | 427 | void fileBrowser::localDelete() { |
416 | QString f = ListView->currentItem()->text(0); | 428 | QString f = ListView->currentItem()->text(0); |
417 | if(QDir(f).exists() ) { | 429 | if(QDir(f).exists() ) { |
418 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ | 430 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ |
419 | " ?\nIt must be empty","Yes","No",0,0,1) ) { | 431 | " ?\nIt must be empty","Yes","No",0,0,1) ) { |
420 | case 0: { | 432 | case 0: { |
421 | f=currentDir.canonicalPath()+"/"+f; | 433 | f=currentDir.canonicalPath()+"/"+f; |
422 | QString cmd="rmdir "+f; | 434 | QString cmd="rmdir "+f; |
423 | system( cmd.latin1()); | 435 | system( cmd.latin1()); |
424 | populateList(); | 436 | populateList(); |
425 | } | 437 | } |
426 | break; | 438 | break; |
427 | case 1: | 439 | case 1: |
428 | // exit | 440 | // exit |
429 | break; | 441 | break; |
430 | }; | 442 | }; |
431 | 443 | ||
432 | } else { | 444 | } else { |
433 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f | 445 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f |
434 | +" ?","Yes","No",0,0,1) ) { | 446 | +" ?","Yes","No",0,0,1) ) { |
435 | case 0: { | 447 | case 0: { |
436 | f=currentDir.canonicalPath()+"/"+f; | 448 | f=currentDir.canonicalPath()+"/"+f; |
437 | QString cmd="rm "+f; | 449 | QString cmd="rm "+f; |
438 | system( cmd.latin1()); | 450 | system( cmd.latin1()); |
439 | populateList(); | 451 | populateList(); |
440 | } | 452 | } |
441 | break; | 453 | break; |
442 | case 1: | 454 | case 1: |
443 | // exit | 455 | // exit |
444 | break; | 456 | break; |
445 | }; | 457 | }; |
446 | } | 458 | } |
447 | } | 459 | } |
448 | 460 | ||
449 | void fileBrowser::updateMimeTypeMenu() { | 461 | void fileBrowser::updateMimeTypeMenu() { |
450 | 462 | ||
451 | disconnect( typemb, SIGNAL(selected(const QString&)), | 463 | disconnect( typemb, SIGNAL(selected(const QString&)), |
452 | this, SLOT(showType(const QString&)) ); | 464 | this, SLOT(showType(const QString&)) ); |
453 | 465 | ||
454 | QString prev; | 466 | QString prev; |
455 | 467 | ||
456 | // Type filter | 468 | // Type filter |
457 | QStringList types; | 469 | QStringList types; |
458 | types << tr("All"); | 470 | types << tr("All"); |
459 | types << "--"; | 471 | types << "--"; |
460 | types += getMimeTypes(); | 472 | types += getMimeTypes(); |
461 | prev = typemb->currentText(); | 473 | prev = typemb->currentText(); |
462 | typemb->clear(); | 474 | typemb->clear(); |
463 | typemb->insertItems(types); | 475 | typemb->insertItems(types); |
464 | // typemb->select(prev); | 476 | // typemb->select(prev); |
465 | 477 | ||
466 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); | 478 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); |
467 | } | 479 | } |
468 | 480 | ||
469 | void fileBrowser::showType(const QString &t) { | 481 | void fileBrowser::showType(const QString &t) { |
470 | 482 | ||
471 | qDebug(t); | 483 | qDebug(t); |
472 | mimeType = t+"/*"; | 484 | mimeType = t+"/*"; |
473 | // if(fileSelector) { | 485 | // if(fileSelector) { |
474 | // disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 486 | // disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
475 | // delete fileSelector; | 487 | // delete fileSelector; |
476 | // } | 488 | // } |
477 | // fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy | 489 | // fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy |
478 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 490 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
479 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 491 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
480 | // connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 492 | // connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
481 | // fileSelector->reread(); | 493 | // fileSelector->reread(); |
482 | repaint(); | 494 | repaint(); |
483 | // if ( t == tr("All") ) { | 495 | // if ( t == tr("All") ) { |
484 | // icons->setTypeFilter("",TRUE); | 496 | // icons->setTypeFilter("",TRUE); |
485 | // } else { | 497 | // } else { |
486 | // icons->setTypeFilter(t+"/*",TRUE); | 498 | // icons->setTypeFilter(t+"/*",TRUE); |
487 | // } | 499 | // } |
488 | 500 | ||
489 | } | 501 | } |
490 | 502 | ||
491 | QStringList fileBrowser::getMimeTypes() { | 503 | QStringList fileBrowser::getMimeTypes() { |
492 | QStringList r; | 504 | QStringList r; |
493 | AppLnkSet apps( QPEApplication::qpeDir() + "apps" ); | 505 | AppLnkSet apps( QPEApplication::qpeDir() + "apps" ); |
494 | QFile file( QPEApplication::qpeDir()+"etc/available.mime"); | 506 | QFile file( QPEApplication::qpeDir()+"etc/available.mime"); |
495 | file.open( IO_WriteOnly|IO_Truncate);//) | 507 | file.open( IO_WriteOnly|IO_Truncate);//) |
496 | for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) { | 508 | for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) { |
497 | AppLnk* l; | 509 | AppLnk* l; |
498 | l = it.current(); | 510 | l = it.current(); |
499 | QStringList maj = l->mimeTypes(); | 511 | QStringList maj = l->mimeTypes(); |
500 | QStringList::ConstIterator f; | 512 | QStringList::ConstIterator f; |
501 | for ( f = maj.begin(); f != maj.end(); f++ ) { | 513 | for ( f = maj.begin(); f != maj.end(); f++ ) { |
502 | QString temp = *f; | 514 | QString temp = *f; |
503 | int sl = temp.find('/'); | 515 | int sl = temp.find('/'); |
504 | if (sl >= 0) { | 516 | if (sl >= 0) { |
505 | QString k = temp.left(sl); | 517 | QString k = temp.left(sl); |
506 | if( r.grep(k,TRUE).isEmpty() ) { | 518 | if( r.grep(k,TRUE).isEmpty() ) { |
507 | r << k; | 519 | r << k; |
508 | k+="\n"; | 520 | k+="\n"; |
509 | file.writeBlock( k.latin1(), k.length()); | 521 | file.writeBlock( k.latin1(), k.length()); |
510 | } | 522 | } |
511 | } | 523 | } |
512 | } | 524 | } |
513 | } | 525 | } |
514 | r.sort(); | 526 | r.sort(); |
515 | file.close(); | 527 | file.close(); |
516 | return r; | 528 | return r; |
517 | } | 529 | } |
518 | 530 | ||
519 | void fileBrowser::receive( const QCString &msg, const QByteArray &data ) { | 531 | void fileBrowser::receive( const QCString &msg, const QByteArray &data ) { |
520 | // QDataStream stream( data, IO_ReadOnly ); | 532 | // QDataStream stream( data, IO_ReadOnly ); |
521 | // if (msg == "keyRegister(int key, QString channel, QString message)") | 533 | // if (msg == "keyRegister(int key, QString channel, QString message)") |
522 | // { | 534 | // { |
523 | // int k; | 535 | // int k; |
524 | // QString c, m; | 536 | // QString c, m; |
525 | // stream >> k; | 537 | // stream >> k; |
526 | // stream >> c; | 538 | // stream >> c; |
527 | // stream >> m; | 539 | // stream >> m; |
528 | } | 540 | } |
529 | 541 | ||
530 | void fileBrowser::dirPathComboActivated( const QString & current) { | 542 | void fileBrowser::dirPathComboActivated( const QString & current) { |
531 | chdir( current.latin1() ); | 543 | chdir( current.latin1() ); |
532 | currentDir.cd( current, TRUE); | 544 | currentDir.cd( current, TRUE); |
533 | populateList(); | 545 | populateList(); |
534 | update(); | 546 | update(); |
535 | } | 547 | } |
536 | 548 | ||
537 | void fileBrowser::dirPathEditPressed() { | 549 | void fileBrowser::dirPathEditPressed() { |
538 | QString current = dirPathCombo->lineEdit()->text(); | 550 | QString current = dirPathCombo->lineEdit()->text(); |
539 | chdir( current.latin1() ); | 551 | chdir( current.latin1() ); |
540 | currentDir.cd( current, TRUE); | 552 | currentDir.cd( current, TRUE); |
541 | populateList(); | 553 | populateList(); |
542 | update(); | 554 | update(); |
543 | } | 555 | } |
544 | 556 | ||
545 | void fileBrowser::fillCombo(const QString ¤tPath) { | 557 | void fileBrowser::fillCombo(const QString ¤tPath) { |
546 | 558 | ||
547 | dirPathCombo->lineEdit()->setText(currentPath); | 559 | dirPathCombo->lineEdit()->setText(currentPath); |
548 | 560 | ||
549 | if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 561 | if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
550 | dirPathCombo->clear(); | 562 | dirPathCombo->clear(); |
551 | dirPathStringList.prepend(currentPath ); | 563 | dirPathStringList.prepend(currentPath ); |
552 | dirPathCombo->insertStringList( dirPathStringList,-1); | 564 | dirPathCombo->insertStringList( dirPathStringList,-1); |
553 | } | 565 | } |
554 | } | 566 | } |
555 | 567 | ||
556 | 568 | ||
557 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | 569 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) |
558 | : QDialog( parent, name, modal, fl ) | 570 | : QDialog( parent, name, modal, fl ) |
559 | { | 571 | { |
560 | if ( !name ) | 572 | if ( !name ) |
561 | setName( "InputDialog" ); | 573 | setName( "InputDialog" ); |
562 | resize( 234, 50 ); | 574 | resize( 234, 50 ); |
563 | setMaximumSize( QSize( 240, 50 ) ); | 575 | setMaximumSize( QSize( 240, 50 ) ); |
564 | setCaption( tr(name ) ); | 576 | setCaption( tr(name ) ); |
565 | 577 | ||
566 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | 578 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); |
567 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); | 579 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); |
568 | } | 580 | } |
569 | 581 | ||
570 | InputDialog::~InputDialog() | 582 | InputDialog::~InputDialog() |
571 | { | 583 | { |
572 | inputText= LineEdit1->text(); | 584 | inputText= LineEdit1->text(); |
573 | 585 | ||
574 | } | 586 | } |
575 | 587 | ||
diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h index 77ac166..1138d80 100644 --- a/core/apps/textedit/fileBrowser.h +++ b/core/apps/textedit/fileBrowser.h | |||
@@ -1,119 +1,120 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** | 2 | ** |
3 | ** Created: Fri Dec 14 08:16:02 2001 | 3 | ** Created: Fri Dec 14 08:16:02 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 | copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com | 13 | copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com |
14 | ****************************************************************************/ | 14 | ****************************************************************************/ |
15 | #ifndef FILEBROWSER_H | 15 | #ifndef FILEBROWSER_H |
16 | #define FILEBROWSER_H | 16 | #define FILEBROWSER_H |
17 | 17 | ||
18 | //#include <qvariant.h> | 18 | //#include <qvariant.h> |
19 | #include <qdialog.h> | 19 | #include <qdialog.h> |
20 | #include <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qdir.h> | 21 | #include <qdir.h> |
22 | #include <qstringlist.h> | 22 | #include <qstringlist.h> |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qdict.h> | 25 | #include <qdict.h> |
26 | 26 | ||
27 | #include <qpe/filemanager.h> | 27 | #include <qpe/filemanager.h> |
28 | 28 | ||
29 | #include <qvariant.h> | 29 | #include <qvariant.h> |
30 | #include <qdialog.h> | 30 | #include <qdialog.h> |
31 | class QLineEdit; | 31 | class QLineEdit; |
32 | 32 | ||
33 | class QVBoxLayout; | 33 | class QVBoxLayout; |
34 | class QHBoxLayout; | 34 | class QHBoxLayout; |
35 | class QGridLayout; | 35 | class QGridLayout; |
36 | class QListView; | 36 | class QListView; |
37 | class QListViewItem; | 37 | class QListViewItem; |
38 | class QPushButton; | 38 | class QPushButton; |
39 | class QComboBox; | 39 | class QComboBox; |
40 | class QWidgetStack; | 40 | class QWidgetStack; |
41 | class FileSelector; | 41 | class FileSelector; |
42 | class QPoint; | 42 | class QPoint; |
43 | class MenuButton; | 43 | class MenuButton; |
44 | class QRegExp; | 44 | class QRegExp; |
45 | 45 | ||
46 | 46 | ||
47 | class fileBrowser : public QDialog | 47 | class fileBrowser : public QDialog |
48 | { | 48 | { |
49 | Q_OBJECT | 49 | Q_OBJECT |
50 | 50 | ||
51 | public: | 51 | public: |
52 | fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); | 52 | fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); |
53 | ~fileBrowser(); | 53 | ~fileBrowser(); |
54 | 54 | ||
55 | QString selectedFileName, mimeType; | 55 | QString selectedFileName; |
56 | QFile file; | 56 | QFile file; |
57 | QStringList fileList; | 57 | QStringList fileList; |
58 | QComboBox *SelectionCombo; | 58 | QComboBox *SelectionCombo; |
59 | public slots: | 59 | public slots: |
60 | void setFileView( int ); | 60 | void setFileView( int ); |
61 | void setMimeType(const QString &); | ||
61 | 62 | ||
62 | private: | 63 | private: |
63 | // QDict<void> mimes; | 64 | // QDict<void> mimes; |
64 | QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; | 65 | QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; |
65 | QListView* ListView; | 66 | QListView* ListView; |
66 | QLabel *dirLabel; | 67 | QLabel *dirLabel; |
67 | QString filterStr; | 68 | QString filterStr, mimeType; |
68 | QDir currentDir; | 69 | QDir currentDir; |
69 | QStringList dirPathStringList; | 70 | QStringList dirPathStringList; |
70 | QListViewItem * item; | 71 | QListViewItem * item; |
71 | QComboBox *dirPathCombo; | 72 | QComboBox *dirPathCombo; |
72 | MenuButton *typemb; | 73 | MenuButton *typemb; |
73 | QWidgetStack *FileStack; | 74 | QWidgetStack *FileStack; |
74 | FileSelector *fileSelector; | 75 | FileSelector *fileSelector; |
75 | QRegExp tf; | 76 | QRegExp tf; |
76 | QStringList getMimeTypes(); | 77 | QStringList getMimeTypes(); |
77 | void fillCombo( const QString&); | 78 | void fillCombo( const QString&); |
78 | 79 | ||
79 | private slots: | 80 | private slots: |
80 | void populateList(); | 81 | void populateList(); |
81 | void homeButtonPushed(); | 82 | void homeButtonPushed(); |
82 | void docButtonPushed(); | 83 | void docButtonPushed(); |
83 | void ListPressed( int, QListViewItem *, const QPoint&, int); | 84 | void ListPressed( int, QListViewItem *, const QPoint&, int); |
84 | void showListMenu(QListViewItem*); | 85 | void showListMenu(QListViewItem*); |
85 | void doCd(); | 86 | void doCd(); |
86 | void makDir(); | 87 | void makDir(); |
87 | void localRename(); | 88 | void localRename(); |
88 | void localDelete(); | 89 | void localDelete(); |
89 | void receive( const QCString &msg, const QByteArray &data ); | 90 | void receive( const QCString &msg, const QByteArray &data ); |
90 | void dirPathComboActivated( const QString & ); | 91 | void dirPathComboActivated( const QString & ); |
91 | void upDir(); | 92 | void upDir(); |
92 | void listClicked( QListViewItem * ); | 93 | void listClicked( QListViewItem * ); |
93 | void selectionChanged( const QString & ); | 94 | void selectionChanged( const QString & ); |
94 | void OnOK(); | 95 | void OnOK(); |
95 | void docOpen( const DocLnk & ); | 96 | void docOpen( const DocLnk & ); |
96 | void updateMimeTypeMenu(); | 97 | void updateMimeTypeMenu(); |
97 | void showType(const QString &); | 98 | void showType(const QString &); |
98 | void dirPathEditPressed(); | 99 | void dirPathEditPressed(); |
99 | 100 | ||
100 | protected slots: | 101 | protected slots: |
101 | 102 | ||
102 | protected: | 103 | protected: |
103 | 104 | ||
104 | }; | 105 | }; |
105 | 106 | ||
106 | 107 | ||
107 | class InputDialog : public QDialog | 108 | class InputDialog : public QDialog |
108 | { | 109 | { |
109 | Q_OBJECT | 110 | Q_OBJECT |
110 | 111 | ||
111 | public: | 112 | public: |
112 | InputDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | 113 | InputDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); |
113 | ~InputDialog(); | 114 | ~InputDialog(); |
114 | QString inputText; | 115 | QString inputText; |
115 | QLineEdit* LineEdit1; | 116 | QLineEdit* LineEdit1; |
116 | 117 | ||
117 | }; | 118 | }; |
118 | 119 | ||
119 | #endif // FILEBROWSER_H | 120 | #endif // FILEBROWSER_H |
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index ecebe12..d28ece8 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,936 +1,936 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
21 | 21 | ||
22 | #include "textedit.h" | 22 | #include "textedit.h" |
23 | #include "fileBrowser.h" | 23 | #include "fileBrowser.h" |
24 | #include "fileSaver.h" | 24 | #include "fileSaver.h" |
25 | #include "filePermissions.h" | 25 | #include "filePermissions.h" |
26 | 26 | ||
27 | #include "fontDialog.h" | 27 | #include "fontDialog.h" |
28 | 28 | ||
29 | #include <qpe/fontdatabase.h> | 29 | #include <qpe/fontdatabase.h> |
30 | #include <qpe/global.h> | 30 | #include <qpe/global.h> |
31 | #include <qpe/fileselector.h> | 31 | #include <qpe/fileselector.h> |
32 | #include <qpe/applnk.h> | 32 | #include <qpe/applnk.h> |
33 | #include <qpe/resource.h> | 33 | #include <qpe/resource.h> |
34 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/qpemenubar.h> | 36 | #include <qpe/qpemenubar.h> |
37 | #include <qpe/qpetoolbar.h> | 37 | #include <qpe/qpetoolbar.h> |
38 | //#include <qpe/finddialog.h> | 38 | //#include <qpe/finddialog.h> |
39 | 39 | ||
40 | #include <qstringlist.h> | 40 | #include <qstringlist.h> |
41 | #include <qaction.h> | 41 | #include <qaction.h> |
42 | #include <qcolordialog.h> | 42 | #include <qcolordialog.h> |
43 | #include <qfileinfo.h> | 43 | #include <qfileinfo.h> |
44 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qobjectlist.h> | 46 | #include <qobjectlist.h> |
47 | #include <qpopupmenu.h> | 47 | #include <qpopupmenu.h> |
48 | #include <qspinbox.h> | 48 | #include <qspinbox.h> |
49 | #include <qtoolbutton.h> | 49 | #include <qtoolbutton.h> |
50 | #include <qwidgetstack.h> | 50 | #include <qwidgetstack.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | #include <qcombo.h> | 52 | #include <qcombo.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
55 | 55 | ||
56 | #include <stdlib.h> //getenv | 56 | #include <stdlib.h> //getenv |
57 | /* XPM */ | 57 | /* XPM */ |
58 | static char * filesave_xpm[] = { | 58 | static char * filesave_xpm[] = { |
59 | "16 16 78 1", | 59 | "16 16 78 1", |
60 | " c None", | 60 | " c None", |
61 | ". c #343434", | 61 | ". c #343434", |
62 | "+ c #A0A0A0", | 62 | "+ c #A0A0A0", |
63 | "@ c #565656", | 63 | "@ c #565656", |
64 | "# c #9E9E9E", | 64 | "# c #9E9E9E", |
65 | "$ c #525252", | 65 | "$ c #525252", |
66 | "% c #929292", | 66 | "% c #929292", |
67 | "& c #676767", | 67 | "& c #676767", |
68 | "* c #848484", | 68 | "* c #848484", |
69 | "= c #666666", | 69 | "= c #666666", |
70 | "- c #D8D8D8", | 70 | "- c #D8D8D8", |
71 | "; c #FFFFFF", | 71 | "; c #FFFFFF", |
72 | "> c #DBDBDB", | 72 | "> c #DBDBDB", |
73 | ", c #636363", | 73 | ", c #636363", |
74 | "' c #989898", | 74 | "' c #989898", |
75 | ") c #2D2D2D", | 75 | ") c #2D2D2D", |
76 | "! c #909090", | 76 | "! c #909090", |
77 | "~ c #AEAEAE", | 77 | "~ c #AEAEAE", |
78 | "{ c #EAEAEA", | 78 | "{ c #EAEAEA", |
79 | "] c #575757", | 79 | "] c #575757", |
80 | "^ c #585858", | 80 | "^ c #585858", |
81 | "/ c #8A8A8A", | 81 | "/ c #8A8A8A", |
82 | "( c #828282", | 82 | "( c #828282", |
83 | "_ c #6F6F6F", | 83 | "_ c #6F6F6F", |
84 | ": c #C9C9C9", | 84 | ": c #C9C9C9", |
85 | "< c #050505", | 85 | "< c #050505", |
86 | "[ c #292929", | 86 | "[ c #292929", |
87 | "} c #777777", | 87 | "} c #777777", |
88 | "| c #616161", | 88 | "| c #616161", |
89 | "1 c #3A3A3A", | 89 | "1 c #3A3A3A", |
90 | "2 c #BEBEBE", | 90 | "2 c #BEBEBE", |
91 | "3 c #2C2C2C", | 91 | "3 c #2C2C2C", |
92 | "4 c #7C7C7C", | 92 | "4 c #7C7C7C", |
93 | "5 c #F6F6F6", | 93 | "5 c #F6F6F6", |
94 | "6 c #FCFCFC", | 94 | "6 c #FCFCFC", |
95 | "7 c #6B6B6B", | 95 | "7 c #6B6B6B", |
96 | "8 c #959595", | 96 | "8 c #959595", |
97 | "9 c #4F4F4F", | 97 | "9 c #4F4F4F", |
98 | "0 c #808080", | 98 | "0 c #808080", |
99 | "a c #767676", | 99 | "a c #767676", |
100 | "b c #818181", | 100 | "b c #818181", |
101 | "c c #B8B8B8", | 101 | "c c #B8B8B8", |
102 | "d c #FBFBFB", | 102 | "d c #FBFBFB", |
103 | "e c #F9F9F9", | 103 | "e c #F9F9F9", |
104 | "f c #CCCCCC", | 104 | "f c #CCCCCC", |
105 | "g c #030303", | 105 | "g c #030303", |
106 | "h c #737373", | 106 | "h c #737373", |
107 | "i c #7A7A7A", | 107 | "i c #7A7A7A", |
108 | "j c #7E7E7E", | 108 | "j c #7E7E7E", |
109 | "k c #6A6A6A", | 109 | "k c #6A6A6A", |
110 | "l c #FAFAFA", | 110 | "l c #FAFAFA", |
111 | "m c #505050", | 111 | "m c #505050", |
112 | "n c #9D9D9D", | 112 | "n c #9D9D9D", |
113 | "o c #333333", | 113 | "o c #333333", |
114 | "p c #7B7B7B", | 114 | "p c #7B7B7B", |
115 | "q c #787878", | 115 | "q c #787878", |
116 | "r c #696969", | 116 | "r c #696969", |
117 | "s c #494949", | 117 | "s c #494949", |
118 | "t c #555555", | 118 | "t c #555555", |
119 | "u c #949494", | 119 | "u c #949494", |
120 | "v c #E6E6E6", | 120 | "v c #E6E6E6", |
121 | "w c #424242", | 121 | "w c #424242", |
122 | "x c #515151", | 122 | "x c #515151", |
123 | "y c #535353", | 123 | "y c #535353", |
124 | "z c #3E3E3E", | 124 | "z c #3E3E3E", |
125 | "A c #D4D4D4", | 125 | "A c #D4D4D4", |
126 | "B c #0C0C0C", | 126 | "B c #0C0C0C", |
127 | "C c #353535", | 127 | "C c #353535", |
128 | "D c #474747", | 128 | "D c #474747", |
129 | "E c #ECECEC", | 129 | "E c #ECECEC", |
130 | "F c #919191", | 130 | "F c #919191", |
131 | "G c #7D7D7D", | 131 | "G c #7D7D7D", |
132 | "H c #000000", | 132 | "H c #000000", |
133 | "I c #404040", | 133 | "I c #404040", |
134 | "J c #858585", | 134 | "J c #858585", |
135 | "K c #323232", | 135 | "K c #323232", |
136 | "L c #D0D0D0", | 136 | "L c #D0D0D0", |
137 | "M c #1C1C1C", | 137 | "M c #1C1C1C", |
138 | " ...+ ", | 138 | " ...+ ", |
139 | " @#$%&..+ ", | 139 | " @#$%&..+ ", |
140 | " .*=-;;>,..+ ", | 140 | " .*=-;;>,..+ ", |
141 | " ')!~;;;;;;{]..", | 141 | " ')!~;;;;;;{]..", |
142 | " ^/(-;;;;;;;_:<", | 142 | " ^/(-;;;;;;;_:<", |
143 | " [}|;;;;;;;{12$", | 143 | " [}|;;;;;;;{12$", |
144 | " #34-55;;;;678$+", | 144 | " #34-55;;;;678$+", |
145 | " 90ab=c;dd;e1fg ", | 145 | " 90ab=c;dd;e1fg ", |
146 | " [ahij((kbl0mn$ ", | 146 | " [ahij((kbl0mn$ ", |
147 | " op^q^^7r&]s/$+ ", | 147 | " op^q^^7r&]s/$+ ", |
148 | "@btu;vbwxy]zAB ", | 148 | "@btu;vbwxy]zAB ", |
149 | "CzDEvEv;;DssF$ ", | 149 | "CzDEvEv;;DssF$ ", |
150 | "G.H{E{E{IxsJ$+ ", | 150 | "G.H{E{E{IxsJ$+ ", |
151 | " +...vEKxzLM ", | 151 | " +...vEKxzLM ", |
152 | " +...z]n$ ", | 152 | " +...z]n$ ", |
153 | " +... "}; | 153 | " +... "}; |
154 | 154 | ||
155 | 155 | ||
156 | #if QT_VERSION < 300 | 156 | #if QT_VERSION < 300 |
157 | 157 | ||
158 | class QpeEditor : public QMultiLineEdit | 158 | class QpeEditor : public QMultiLineEdit |
159 | { | 159 | { |
160 | // Q_OBJECT | 160 | // Q_OBJECT |
161 | public: | 161 | public: |
162 | QpeEditor( QWidget *parent, const char * name = 0 ) | 162 | QpeEditor( QWidget *parent, const char * name = 0 ) |
163 | : QMultiLineEdit( parent, name ) | 163 | : QMultiLineEdit( parent, name ) |
164 | { | 164 | { |
165 | clearTableFlags(); | 165 | clearTableFlags(); |
166 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 166 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
167 | } | 167 | } |
168 | 168 | ||
169 | void find( const QString &txt, bool caseSensitive, | 169 | void find( const QString &txt, bool caseSensitive, |
170 | bool backwards ); | 170 | bool backwards ); |
171 | //public slots: | 171 | //public slots: |
172 | /* | 172 | /* |
173 | signals: | 173 | signals: |
174 | void notFound(); | 174 | void notFound(); |
175 | void searchWrapped(); | 175 | void searchWrapped(); |
176 | */ | 176 | */ |
177 | 177 | ||
178 | private: | 178 | private: |
179 | 179 | ||
180 | }; | 180 | }; |
181 | 181 | ||
182 | 182 | ||
183 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 183 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
184 | bool backwards ) | 184 | bool backwards ) |
185 | { | 185 | { |
186 | static bool wrap = FALSE; | 186 | static bool wrap = FALSE; |
187 | int line, col; | 187 | int line, col; |
188 | if ( wrap ) { | 188 | if ( wrap ) { |
189 | if ( !backwards ) | 189 | if ( !backwards ) |
190 | line = col = 0; | 190 | line = col = 0; |
191 | wrap = FALSE; | 191 | wrap = FALSE; |
192 | // emit searchWrapped(); | 192 | // emit searchWrapped(); |
193 | } else { | 193 | } else { |
194 | getCursorPosition( &line, &col ); | 194 | getCursorPosition( &line, &col ); |
195 | } | 195 | } |
196 | //ignore backwards for now.... | 196 | //ignore backwards for now.... |
197 | if ( !backwards ) { | 197 | if ( !backwards ) { |
198 | for ( ; ; ) { | 198 | for ( ; ; ) { |
199 | if ( line >= numLines() ) { | 199 | if ( line >= numLines() ) { |
200 | wrap = TRUE; | 200 | wrap = TRUE; |
201 | //emit notFound(); | 201 | //emit notFound(); |
202 | break; | 202 | break; |
203 | } | 203 | } |
204 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 204 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
205 | if ( findCol >= 0 ) { | 205 | if ( findCol >= 0 ) { |
206 | setCursorPosition( line, findCol, FALSE ); | 206 | setCursorPosition( line, findCol, FALSE ); |
207 | col = findCol + txt.length(); | 207 | col = findCol + txt.length(); |
208 | setCursorPosition( line, col, TRUE ); | 208 | setCursorPosition( line, col, TRUE ); |
209 | 209 | ||
210 | //found = TRUE; | 210 | //found = TRUE; |
211 | break; | 211 | break; |
212 | } | 212 | } |
213 | line++; | 213 | line++; |
214 | col = 0; | 214 | col = 0; |
215 | } | 215 | } |
216 | 216 | ||
217 | } | 217 | } |
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | #else | 222 | #else |
223 | 223 | ||
224 | #error "Must make a QpeEditor that inherits QTextEdit" | 224 | #error "Must make a QpeEditor that inherits QTextEdit" |
225 | 225 | ||
226 | #endif | 226 | #endif |
227 | 227 | ||
228 | 228 | ||
229 | static const int nfontsizes = 6; | 229 | static const int nfontsizes = 6; |
230 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 230 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
231 | 231 | ||
232 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 232 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
233 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 233 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) |
234 | { | 234 | { |
235 | doc = 0; | 235 | doc = 0; |
236 | edited=FALSE; | 236 | edited=FALSE; |
237 | edited1=FALSE; | 237 | edited1=FALSE; |
238 | setToolBarsMovable( FALSE ); | 238 | setToolBarsMovable( FALSE ); |
239 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 239 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
240 | 240 | ||
241 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 241 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
242 | 242 | ||
243 | QPEToolBar *bar = new QPEToolBar( this ); | 243 | QPEToolBar *bar = new QPEToolBar( this ); |
244 | bar->setHorizontalStretchable( TRUE ); | 244 | bar->setHorizontalStretchable( TRUE ); |
245 | menu = bar; | 245 | menu = bar; |
246 | 246 | ||
247 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 247 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
248 | QPopupMenu *file = new QPopupMenu( this ); | 248 | QPopupMenu *file = new QPopupMenu( this ); |
249 | QPopupMenu *edit = new QPopupMenu( this ); | 249 | QPopupMenu *edit = new QPopupMenu( this ); |
250 | font = new QPopupMenu( this ); | 250 | font = new QPopupMenu( this ); |
251 | 251 | ||
252 | bar = new QPEToolBar( this ); | 252 | bar = new QPEToolBar( this ); |
253 | editBar = bar; | 253 | editBar = bar; |
254 | 254 | ||
255 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 255 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
256 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 256 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
257 | a->addTo( bar ); | 257 | a->addTo( bar ); |
258 | a->addTo( file ); | 258 | a->addTo( file ); |
259 | 259 | ||
260 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 260 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
261 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 261 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
262 | a->addTo( bar ); | 262 | a->addTo( bar ); |
263 | a->addTo( file ); | 263 | a->addTo( file ); |
264 | 264 | ||
265 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 265 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
266 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 266 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
267 | file->insertSeparator(); | 267 | file->insertSeparator(); |
268 | a->addTo( file ); | 268 | a->addTo( file ); |
269 | 269 | ||
270 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 270 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
271 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 271 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
272 | a->addTo( file ); | 272 | a->addTo( file ); |
273 | 273 | ||
274 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 274 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
275 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 275 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
276 | a->addTo( editBar ); | 276 | a->addTo( editBar ); |
277 | a->addTo( edit ); | 277 | a->addTo( edit ); |
278 | 278 | ||
279 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 279 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
280 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 280 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
281 | a->addTo( editBar ); | 281 | a->addTo( editBar ); |
282 | a->addTo( edit ); | 282 | a->addTo( edit ); |
283 | 283 | ||
284 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 284 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
285 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 285 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
286 | a->addTo( editBar ); | 286 | a->addTo( editBar ); |
287 | a->addTo( edit ); | 287 | a->addTo( edit ); |
288 | 288 | ||
289 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 289 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
290 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 290 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
291 | edit->insertSeparator(); | 291 | edit->insertSeparator(); |
292 | a->addTo( bar ); | 292 | a->addTo( bar ); |
293 | a->addTo( edit ); | 293 | a->addTo( edit ); |
294 | 294 | ||
295 | int defsize; | 295 | int defsize; |
296 | bool defb, defi, wrap; | 296 | bool defb, defi, wrap; |
297 | 297 | ||
298 | Config cfg("TextEdit"); | 298 | Config cfg("TextEdit"); |
299 | cfg.setGroup("View"); | 299 | cfg.setGroup("View"); |
300 | defsize = cfg.readNumEntry("FontSize",10); | 300 | defsize = cfg.readNumEntry("FontSize",10); |
301 | defb = cfg.readBoolEntry("Bold",FALSE); | 301 | defb = cfg.readBoolEntry("Bold",FALSE); |
302 | defi = cfg.readBoolEntry("Italic",FALSE); | 302 | defi = cfg.readBoolEntry("Italic",FALSE); |
303 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 303 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
304 | 304 | ||
305 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 305 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
306 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 306 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
307 | zin->addTo( font ); | 307 | zin->addTo( font ); |
308 | 308 | ||
309 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 309 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
310 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 310 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
311 | zout->addTo( font ); | 311 | zout->addTo( font ); |
312 | 312 | ||
313 | font->insertSeparator(); | 313 | font->insertSeparator(); |
314 | 314 | ||
315 | #if 0 | 315 | #if 0 |
316 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 316 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
317 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 317 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
318 | ba->setToggleAction(TRUE); | 318 | ba->setToggleAction(TRUE); |
319 | ba->addTo( font ); | 319 | ba->addTo( font ); |
320 | 320 | ||
321 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 321 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
322 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 322 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
323 | ia->setToggleAction(TRUE); | 323 | ia->setToggleAction(TRUE); |
324 | ia->addTo( font ); | 324 | ia->addTo( font ); |
325 | 325 | ||
326 | ba->setOn(defb); | 326 | ba->setOn(defb); |
327 | ia->setOn(defi); | 327 | ia->setOn(defi); |
328 | 328 | ||
329 | font->insertSeparator(); | 329 | font->insertSeparator(); |
330 | #endif | 330 | #endif |
331 | 331 | ||
332 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 332 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
333 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 333 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
334 | wa->setToggleAction(TRUE); | 334 | wa->setToggleAction(TRUE); |
335 | wa->addTo( font ); | 335 | wa->addTo( font ); |
336 | 336 | ||
337 | font->insertSeparator(); | 337 | font->insertSeparator(); |
338 | font->insertItem("Font", this, SLOT(changeFont()) ); | 338 | font->insertItem("Font", this, SLOT(changeFont()) ); |
339 | 339 | ||
340 | font->insertSeparator(); | 340 | font->insertSeparator(); |
341 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 341 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
342 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 342 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
343 | nStart->setToggleAction(TRUE); | 343 | nStart->setToggleAction(TRUE); |
344 | nStart->addTo( font ); | 344 | nStart->addTo( font ); |
345 | 345 | ||
346 | mb->insertItem( tr( "File" ), file ); | 346 | mb->insertItem( tr( "File" ), file ); |
347 | mb->insertItem( tr( "Edit" ), edit ); | 347 | mb->insertItem( tr( "Edit" ), edit ); |
348 | mb->insertItem( tr( "View" ), font ); | 348 | mb->insertItem( tr( "View" ), font ); |
349 | 349 | ||
350 | searchBar = new QPEToolBar(this); | 350 | searchBar = new QPEToolBar(this); |
351 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 351 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
352 | 352 | ||
353 | searchBar->setHorizontalStretchable( TRUE ); | 353 | searchBar->setHorizontalStretchable( TRUE ); |
354 | 354 | ||
355 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 355 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
356 | searchBar->setStretchableWidget( searchEdit ); | 356 | searchBar->setStretchableWidget( searchEdit ); |
357 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 357 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
358 | this, SLOT( search() ) ); | 358 | this, SLOT( search() ) ); |
359 | 359 | ||
360 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 360 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
361 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 361 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
362 | a->addTo( searchBar ); | 362 | a->addTo( searchBar ); |
363 | a->addTo( edit ); | 363 | a->addTo( edit ); |
364 | 364 | ||
365 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 365 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
366 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 366 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
367 | a->addTo( searchBar ); | 367 | a->addTo( searchBar ); |
368 | 368 | ||
369 | edit->insertSeparator(); | 369 | edit->insertSeparator(); |
370 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 370 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
371 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 371 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
372 | a->addTo( edit ); | 372 | a->addTo( edit ); |
373 | 373 | ||
374 | searchBar->hide(); | 374 | searchBar->hide(); |
375 | 375 | ||
376 | editor = new QpeEditor( this ); | 376 | editor = new QpeEditor( this ); |
377 | setCentralWidget( editor ); | 377 | setCentralWidget( editor ); |
378 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 378 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
379 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 379 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); |
380 | 380 | ||
381 | // resize( 200, 300 ); | 381 | // resize( 200, 300 ); |
382 | 382 | ||
383 | // setFontSize(defsize,TRUE); | 383 | // setFontSize(defsize,TRUE); |
384 | FontDatabase fdb; | 384 | FontDatabase fdb; |
385 | QFont defaultFont=editor->font(); | 385 | QFont defaultFont=editor->font(); |
386 | QFontInfo fontInfo(defaultFont); | 386 | QFontInfo fontInfo(defaultFont); |
387 | 387 | ||
388 | cfg.setGroup("Font"); | 388 | cfg.setGroup("Font"); |
389 | QString family = cfg.readEntry("Family", fontInfo.family()); | 389 | QString family = cfg.readEntry("Family", fontInfo.family()); |
390 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 390 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
391 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 391 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
392 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 392 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
393 | 393 | ||
394 | defaultFont = fdb.font(family,style,i_size,charSet); | 394 | defaultFont = fdb.font(family,style,i_size,charSet); |
395 | editor->setFont( defaultFont); | 395 | editor->setFont( defaultFont); |
396 | 396 | ||
397 | wa->setOn(wrap); | 397 | wa->setOn(wrap); |
398 | updateCaption(); | 398 | updateCaption(); |
399 | 399 | ||
400 | cfg.setGroup("View"); | 400 | cfg.setGroup("View"); |
401 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 401 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { |
402 | nStart->setOn(TRUE); | 402 | nStart->setOn(TRUE); |
403 | fileNew(); | 403 | fileNew(); |
404 | } else { | 404 | } else { |
405 | fileOpen(); | 405 | fileOpen(); |
406 | } | 406 | } |
407 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 407 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
408 | } | 408 | } |
409 | 409 | ||
410 | void TextEdit::cleanUp() | 410 | void TextEdit::cleanUp() |
411 | { | 411 | { |
412 | // save(); | 412 | // save(); |
413 | Config cfg("TextEdit"); | 413 | Config cfg("TextEdit"); |
414 | cfg.setGroup("View"); | 414 | cfg.setGroup("View"); |
415 | QFont f = editor->font(); | 415 | QFont f = editor->font(); |
416 | cfg.writeEntry("FontSize",f.pointSize()); | 416 | cfg.writeEntry("FontSize",f.pointSize()); |
417 | cfg.writeEntry("Bold",f.bold()); | 417 | cfg.writeEntry("Bold",f.bold()); |
418 | cfg.writeEntry("Italic",f.italic()); | 418 | cfg.writeEntry("Italic",f.italic()); |
419 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 419 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
420 | cfg.writeEntry( "FileView", viewSelection ); | 420 | cfg.writeEntry( "FileView", viewSelection ); |
421 | 421 | ||
422 | } | 422 | } |
423 | 423 | ||
424 | TextEdit::~TextEdit() | 424 | TextEdit::~TextEdit() |
425 | { | 425 | { |
426 | } | 426 | } |
427 | 427 | ||
428 | void TextEdit::zoomIn() | 428 | void TextEdit::zoomIn() |
429 | { | 429 | { |
430 | setFontSize(editor->font().pointSize()+1,FALSE); | 430 | setFontSize(editor->font().pointSize()+1,FALSE); |
431 | } | 431 | } |
432 | 432 | ||
433 | void TextEdit::zoomOut() | 433 | void TextEdit::zoomOut() |
434 | { | 434 | { |
435 | setFontSize(editor->font().pointSize()-1,TRUE); | 435 | setFontSize(editor->font().pointSize()-1,TRUE); |
436 | } | 436 | } |
437 | 437 | ||
438 | 438 | ||
439 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 439 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
440 | { | 440 | { |
441 | int s=10; | 441 | int s=10; |
442 | for (int i=0; i<nfontsizes; i++) { | 442 | for (int i=0; i<nfontsizes; i++) { |
443 | if ( fontsize[i] == sz ) { | 443 | if ( fontsize[i] == sz ) { |
444 | s = sz; | 444 | s = sz; |
445 | break; | 445 | break; |
446 | } else if ( round_down_not_up ) { | 446 | } else if ( round_down_not_up ) { |
447 | if ( fontsize[i] < sz ) | 447 | if ( fontsize[i] < sz ) |
448 | s = fontsize[i]; | 448 | s = fontsize[i]; |
449 | } else { | 449 | } else { |
450 | if ( fontsize[i] > sz ) { | 450 | if ( fontsize[i] > sz ) { |
451 | s = fontsize[i]; | 451 | s = fontsize[i]; |
452 | break; | 452 | break; |
453 | } | 453 | } |
454 | } | 454 | } |
455 | } | 455 | } |
456 | 456 | ||
457 | QFont f = editor->font(); | 457 | QFont f = editor->font(); |
458 | f.setPointSize(s); | 458 | f.setPointSize(s); |
459 | editor->setFont(f); | 459 | editor->setFont(f); |
460 | 460 | ||
461 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 461 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
462 | zout->setEnabled(s != fontsize[0]); | 462 | zout->setEnabled(s != fontsize[0]); |
463 | } | 463 | } |
464 | 464 | ||
465 | void TextEdit::setBold(bool y) | 465 | void TextEdit::setBold(bool y) |
466 | { | 466 | { |
467 | QFont f = editor->font(); | 467 | QFont f = editor->font(); |
468 | f.setBold(y); | 468 | f.setBold(y); |
469 | editor->setFont(f); | 469 | editor->setFont(f); |
470 | } | 470 | } |
471 | 471 | ||
472 | void TextEdit::setItalic(bool y) | 472 | void TextEdit::setItalic(bool y) |
473 | { | 473 | { |
474 | QFont f = editor->font(); | 474 | QFont f = editor->font(); |
475 | f.setItalic(y); | 475 | f.setItalic(y); |
476 | editor->setFont(f); | 476 | editor->setFont(f); |
477 | } | 477 | } |
478 | 478 | ||
479 | void TextEdit::setWordWrap(bool y) | 479 | void TextEdit::setWordWrap(bool y) |
480 | { | 480 | { |
481 | bool state = editor->edited(); | 481 | bool state = editor->edited(); |
482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
483 | editor->setEdited( state ); | 483 | editor->setEdited( state ); |
484 | } | 484 | } |
485 | 485 | ||
486 | void TextEdit::fileNew() | 486 | void TextEdit::fileNew() |
487 | { | 487 | { |
488 | if( !bFromDocView ) { | 488 | if( !bFromDocView ) { |
489 | saveAs(); | 489 | saveAs(); |
490 | } | 490 | } |
491 | newFile(DocLnk()); | 491 | newFile(DocLnk()); |
492 | } | 492 | } |
493 | 493 | ||
494 | void TextEdit::fileOpen() | 494 | void TextEdit::fileOpen() |
495 | { | 495 | { |
496 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); | 496 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "text/*"); // |
497 | browseForFiles->setFileView( viewSelection ); | 497 | browseForFiles->setFileView( viewSelection ); |
498 | browseForFiles->showMaximized(); | 498 | browseForFiles->showMaximized(); |
499 | if( browseForFiles->exec() != -1 ) { | 499 | if( browseForFiles->exec() != -1 ) { |
500 | QString selFile = browseForFiles->selectedFileName; | 500 | QString selFile = browseForFiles->selectedFileName; |
501 | QStringList fileList = browseForFiles->fileList; | 501 | QStringList fileList = browseForFiles->fileList; |
502 | qDebug(selFile); | 502 | qDebug(selFile); |
503 | QStringList::ConstIterator f; | 503 | QStringList::ConstIterator f; |
504 | QString fileTemp; | 504 | QString fileTemp; |
505 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 505 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
506 | fileTemp = *f; | 506 | fileTemp = *f; |
507 | fileTemp.right( fileTemp.length()-5); | 507 | fileTemp.right( fileTemp.length()-5); |
508 | QString fileName = fileTemp; | 508 | QString fileName = fileTemp; |
509 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 509 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
510 | currentFileName = fileName; | 510 | currentFileName = fileName; |
511 | qDebug("please open "+currentFileName); | 511 | qDebug("please open "+currentFileName); |
512 | openFile(fileName ); | 512 | openFile(fileName ); |
513 | } | 513 | } |
514 | } | 514 | } |
515 | viewSelection = browseForFiles->SelectionCombo->currentItem(); | 515 | viewSelection = browseForFiles->SelectionCombo->currentItem(); |
516 | } | 516 | } |
517 | delete browseForFiles; | 517 | delete browseForFiles; |
518 | editor->setEdited( FALSE); | 518 | editor->setEdited( FALSE); |
519 | edited1=FALSE; | 519 | edited1=FALSE; |
520 | edited=FALSE; | 520 | edited=FALSE; |
521 | if(caption().left(1)=="*") | 521 | if(caption().left(1)=="*") |
522 | setCaption(caption().right(caption().length()-1)); | 522 | setCaption(caption().right(caption().length()-1)); |
523 | doSearchBar(); | 523 | doSearchBar(); |
524 | } | 524 | } |
525 | 525 | ||
526 | void TextEdit::doSearchBar() | 526 | void TextEdit::doSearchBar() |
527 | { | 527 | { |
528 | Config cfg("TextEdit"); | 528 | Config cfg("TextEdit"); |
529 | cfg.setGroup("View"); | 529 | cfg.setGroup("View"); |
530 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 530 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
531 | searchBar->hide(); | 531 | searchBar->hide(); |
532 | } | 532 | } |
533 | 533 | ||
534 | #if 0 | 534 | #if 0 |
535 | void TextEdit::slotFind() | 535 | void TextEdit::slotFind() |
536 | { | 536 | { |
537 | FindDialog frmFind( "Text Editor", this ); | 537 | FindDialog frmFind( "Text Editor", this ); |
538 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 538 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
539 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 539 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
540 | 540 | ||
541 | //case sensitive, backwards, [category] | 541 | //case sensitive, backwards, [category] |
542 | 542 | ||
543 | connect( editor, SIGNAL(notFound()), | 543 | connect( editor, SIGNAL(notFound()), |
544 | &frmFind, SLOT(slotNotFound()) ); | 544 | &frmFind, SLOT(slotNotFound()) ); |
545 | connect( editor, SIGNAL(searchWrapped()), | 545 | connect( editor, SIGNAL(searchWrapped()), |
546 | &frmFind, SLOT(slotWrapAround()) ); | 546 | &frmFind, SLOT(slotWrapAround()) ); |
547 | 547 | ||
548 | frmFind.exec(); | 548 | frmFind.exec(); |
549 | 549 | ||
550 | 550 | ||
551 | } | 551 | } |
552 | #endif | 552 | #endif |
553 | 553 | ||
554 | void TextEdit::fileRevert() | 554 | void TextEdit::fileRevert() |
555 | { | 555 | { |
556 | clear(); | 556 | clear(); |
557 | fileOpen(); | 557 | fileOpen(); |
558 | } | 558 | } |
559 | 559 | ||
560 | void TextEdit::editCut() | 560 | void TextEdit::editCut() |
561 | { | 561 | { |
562 | #ifndef QT_NO_CLIPBOARD | 562 | #ifndef QT_NO_CLIPBOARD |
563 | editor->cut(); | 563 | editor->cut(); |
564 | #endif | 564 | #endif |
565 | } | 565 | } |
566 | 566 | ||
567 | void TextEdit::editCopy() | 567 | void TextEdit::editCopy() |
568 | { | 568 | { |
569 | #ifndef QT_NO_CLIPBOARD | 569 | #ifndef QT_NO_CLIPBOARD |
570 | editor->copy(); | 570 | editor->copy(); |
571 | #endif | 571 | #endif |
572 | } | 572 | } |
573 | 573 | ||
574 | void TextEdit::editPaste() | 574 | void TextEdit::editPaste() |
575 | { | 575 | { |
576 | #ifndef QT_NO_CLIPBOARD | 576 | #ifndef QT_NO_CLIPBOARD |
577 | editor->paste(); | 577 | editor->paste(); |
578 | #endif | 578 | #endif |
579 | } | 579 | } |
580 | 580 | ||
581 | void TextEdit::editFind() | 581 | void TextEdit::editFind() |
582 | { | 582 | { |
583 | searchBar->show(); | 583 | searchBar->show(); |
584 | searchVisible = TRUE; | 584 | searchVisible = TRUE; |
585 | searchEdit->setFocus(); | 585 | searchEdit->setFocus(); |
586 | Config cfg("TextEdit"); | 586 | Config cfg("TextEdit"); |
587 | cfg.setGroup("View"); | 587 | cfg.setGroup("View"); |
588 | cfg.writeEntry("SearchBar","Opened"); | 588 | cfg.writeEntry("SearchBar","Opened"); |
589 | 589 | ||
590 | } | 590 | } |
591 | 591 | ||
592 | void TextEdit::findNext() | 592 | void TextEdit::findNext() |
593 | { | 593 | { |
594 | editor->find( searchEdit->text(), FALSE, FALSE ); | 594 | editor->find( searchEdit->text(), FALSE, FALSE ); |
595 | 595 | ||
596 | } | 596 | } |
597 | 597 | ||
598 | void TextEdit::findClose() | 598 | void TextEdit::findClose() |
599 | { | 599 | { |
600 | searchVisible = FALSE; | 600 | searchVisible = FALSE; |
601 | searchBar->hide(); | 601 | searchBar->hide(); |
602 | Config cfg("TextEdit"); | 602 | Config cfg("TextEdit"); |
603 | cfg.setGroup("View"); | 603 | cfg.setGroup("View"); |
604 | cfg.writeEntry("SearchBar","Closed"); | 604 | cfg.writeEntry("SearchBar","Closed"); |
605 | cfg.write(); | 605 | cfg.write(); |
606 | } | 606 | } |
607 | 607 | ||
608 | void TextEdit::search() | 608 | void TextEdit::search() |
609 | { | 609 | { |
610 | editor->find( searchEdit->text(), FALSE, FALSE ); | 610 | editor->find( searchEdit->text(), FALSE, FALSE ); |
611 | } | 611 | } |
612 | 612 | ||
613 | void TextEdit::newFile( const DocLnk &f ) | 613 | void TextEdit::newFile( const DocLnk &f ) |
614 | { | 614 | { |
615 | DocLnk nf = f; | 615 | DocLnk nf = f; |
616 | nf.setType("text/plain"); | 616 | nf.setType("text/plain"); |
617 | clear(); | 617 | clear(); |
618 | setWState (WState_Reserved1 ); | 618 | setWState (WState_Reserved1 ); |
619 | editor->setFocus(); | 619 | editor->setFocus(); |
620 | doc = new DocLnk(nf); | 620 | doc = new DocLnk(nf); |
621 | qDebug("newFile "+currentFileName); | 621 | qDebug("newFile "+currentFileName); |
622 | updateCaption(currentFileName); | 622 | updateCaption(currentFileName); |
623 | } | 623 | } |
624 | 624 | ||
625 | void TextEdit::openFile( const QString &f ) | 625 | void TextEdit::openFile( const QString &f ) |
626 | { | 626 | { |
627 | 627 | ||
628 | bFromDocView = TRUE; | 628 | bFromDocView = TRUE; |
629 | DocLnk nf; | 629 | DocLnk nf; |
630 | nf.setType("text/plain"); | 630 | nf.setType("text/plain"); |
631 | nf.setFile(f); | 631 | nf.setFile(f); |
632 | currentFileName=f; | 632 | currentFileName=f; |
633 | QFileInfo fi( currentFileName); | 633 | QFileInfo fi( currentFileName); |
634 | nf.setName(fi.baseName()); | 634 | nf.setName(fi.baseName()); |
635 | qDebug("openFile string"+currentFileName); | 635 | qDebug("openFile string"+currentFileName); |
636 | 636 | ||
637 | openFile(nf); | 637 | openFile(nf); |
638 | showEditTools(); | 638 | showEditTools(); |
639 | // Show filename in caption | 639 | // Show filename in caption |
640 | QString name = f; | 640 | QString name = f; |
641 | int sep = name.findRev( '/' ); | 641 | int sep = name.findRev( '/' ); |
642 | if ( sep > 0 ) | 642 | if ( sep > 0 ) |
643 | name = name.mid( sep+1 ); | 643 | name = name.mid( sep+1 ); |
644 | updateCaption( name ); | 644 | updateCaption( name ); |
645 | } | 645 | } |
646 | 646 | ||
647 | void TextEdit::openFile( const DocLnk &f ) | 647 | void TextEdit::openFile( const DocLnk &f ) |
648 | { | 648 | { |
649 | // clear(); | 649 | // clear(); |
650 | bFromDocView = TRUE; | 650 | bFromDocView = TRUE; |
651 | FileManager fm; | 651 | FileManager fm; |
652 | QString txt; | 652 | QString txt; |
653 | currentFileName=f.name(); | 653 | currentFileName=f.name(); |
654 | qDebug("openFile doclnk " + currentFileName); | 654 | qDebug("openFile doclnk " + currentFileName); |
655 | if ( !fm.loadFile( f, txt ) ) { | 655 | if ( !fm.loadFile( f, txt ) ) { |
656 | // ####### could be a new file | 656 | // ####### could be a new file |
657 | qDebug( "Cannot open file" ); | 657 | qDebug( "Cannot open file" ); |
658 | 658 | ||
659 | //return; | 659 | //return; |
660 | } | 660 | } |
661 | 661 | ||
662 | fileNew(); | 662 | fileNew(); |
663 | if ( doc ) | 663 | if ( doc ) |
664 | delete doc; | 664 | delete doc; |
665 | doc = new DocLnk(f); | 665 | doc = new DocLnk(f); |
666 | editor->setText(txt); | 666 | editor->setText(txt); |
667 | editor->setEdited( FALSE); | 667 | editor->setEdited( FALSE); |
668 | edited1=FALSE; | 668 | edited1=FALSE; |
669 | edited=FALSE; | 669 | edited=FALSE; |
670 | 670 | ||
671 | qDebug("openFile doclnk "+currentFileName); | 671 | qDebug("openFile doclnk "+currentFileName); |
672 | doc->setName(currentFileName); | 672 | doc->setName(currentFileName); |
673 | updateCaption(); | 673 | updateCaption(); |
674 | } | 674 | } |
675 | 675 | ||
676 | void TextEdit::showEditTools() | 676 | void TextEdit::showEditTools() |
677 | { | 677 | { |
678 | // if ( !doc ) | 678 | // if ( !doc ) |
679 | // close(); | 679 | // close(); |
680 | // clear(); | 680 | // clear(); |
681 | menu->show(); | 681 | menu->show(); |
682 | editBar->show(); | 682 | editBar->show(); |
683 | if ( searchVisible ) | 683 | if ( searchVisible ) |
684 | searchBar->show(); | 684 | searchBar->show(); |
685 | // updateCaption(); | 685 | // updateCaption(); |
686 | setWState (WState_Reserved1 ); | 686 | setWState (WState_Reserved1 ); |
687 | } | 687 | } |
688 | 688 | ||
689 | /*! | 689 | /*! |
690 | unprompted save */ | 690 | unprompted save */ |
691 | bool TextEdit::save() | 691 | bool TextEdit::save() |
692 | { | 692 | { |
693 | QString file = doc->file(); | 693 | QString file = doc->file(); |
694 | qDebug(file); | 694 | qDebug(file); |
695 | QString name= doc->name(); | 695 | QString name= doc->name(); |
696 | qDebug(name); | 696 | qDebug(name); |
697 | QString rt = editor->text(); | 697 | QString rt = editor->text(); |
698 | if( !rt.isEmpty() ) { | 698 | if( !rt.isEmpty() ) { |
699 | if(name.isEmpty()) { | 699 | if(name.isEmpty()) { |
700 | saveAs(); | 700 | saveAs(); |
701 | } else { | 701 | } else { |
702 | currentFileName= name ; | 702 | currentFileName= name ; |
703 | qDebug("saveFile "+currentFileName); | 703 | qDebug("saveFile "+currentFileName); |
704 | 704 | ||
705 | struct stat buf; | 705 | struct stat buf; |
706 | mode_t mode; | 706 | mode_t mode; |
707 | stat(file.latin1(), &buf); | 707 | stat(file.latin1(), &buf); |
708 | mode = buf.st_mode; | 708 | mode = buf.st_mode; |
709 | 709 | ||
710 | doc->setName( name); | 710 | doc->setName( name); |
711 | FileManager fm; | 711 | FileManager fm; |
712 | if ( !fm.saveFile( *doc, rt ) ) { | 712 | if ( !fm.saveFile( *doc, rt ) ) { |
713 | return false; | 713 | return false; |
714 | } | 714 | } |
715 | editor->setEdited( FALSE); | 715 | editor->setEdited( FALSE); |
716 | edited1=FALSE; | 716 | edited1=FALSE; |
717 | edited=FALSE; | 717 | edited=FALSE; |
718 | if(caption().left(1)=="*") | 718 | if(caption().left(1)=="*") |
719 | setCaption(caption().right(caption().length()-1)); | 719 | setCaption(caption().right(caption().length()-1)); |
720 | 720 | ||
721 | 721 | ||
722 | chmod( file.latin1(), mode); | 722 | chmod( file.latin1(), mode); |
723 | } | 723 | } |
724 | return true; | 724 | return true; |
725 | } | 725 | } |
726 | return false; | 726 | return false; |
727 | } | 727 | } |
728 | 728 | ||
729 | /*! | 729 | /*! |
730 | prompted save */ | 730 | prompted save */ |
731 | bool TextEdit::saveAs() | 731 | bool TextEdit::saveAs() |
732 | { | 732 | { |
733 | // qDebug("saveAsFile "+currentFileName); | 733 | // qDebug("saveAsFile "+currentFileName); |
734 | 734 | ||
735 | // case of nothing to save... /// there's always something to save | 735 | // case of nothing to save... /// there's always something to save |
736 | // if ( !doc )//|| !bFromDocView) | 736 | // if ( !doc )//|| !bFromDocView) |
737 | // { | 737 | // { |
738 | // qDebug("no doc"); | 738 | // qDebug("no doc"); |
739 | // return true; | 739 | // return true; |
740 | // } | 740 | // } |
741 | if ( !editor->edited() ) { | 741 | if ( !editor->edited() ) { |
742 | delete doc; | 742 | delete doc; |
743 | doc = 0; | 743 | doc = 0; |
744 | return true; | 744 | return true; |
745 | } | 745 | } |
746 | 746 | ||
747 | QString rt = editor->text(); | 747 | QString rt = editor->text(); |
748 | qDebug(currentFileName); | 748 | qDebug(currentFileName); |
749 | 749 | ||
750 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 750 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
751 | qDebug("do silly TT filename thing"); | 751 | qDebug("do silly TT filename thing"); |
752 | if ( doc->name().isEmpty() ) { | 752 | if ( doc->name().isEmpty() ) { |
753 | QString pt = rt.simplifyWhiteSpace(); | 753 | QString pt = rt.simplifyWhiteSpace(); |
754 | int i = pt.find( ' ' ); | 754 | int i = pt.find( ' ' ); |
755 | QString docname = pt; | 755 | QString docname = pt; |
756 | if ( i > 0 ) | 756 | if ( i > 0 ) |
757 | docname = pt.left( i ); | 757 | docname = pt.left( i ); |
758 | // remove "." at the beginning | 758 | // remove "." at the beginning |
759 | while( docname.startsWith( "." ) ) | 759 | while( docname.startsWith( "." ) ) |
760 | docname = docname.mid( 1 ); | 760 | docname = docname.mid( 1 ); |
761 | docname.replace( QRegExp("/"), "_" ); | 761 | docname.replace( QRegExp("/"), "_" ); |
762 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 762 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
763 | if ( docname.length() > 40 ) | 763 | if ( docname.length() > 40 ) |
764 | docname = docname.left(40); | 764 | docname = docname.left(40); |
765 | if ( docname.isEmpty() ) | 765 | if ( docname.isEmpty() ) |
766 | docname = "Unnamed"; | 766 | docname = "Unnamed"; |
767 | doc->setName(docname); | 767 | doc->setName(docname); |
768 | currentFileName=docname; | 768 | currentFileName=docname; |
769 | } | 769 | } |
770 | } | 770 | } |
771 | 771 | ||
772 | 772 | ||
773 | fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); | 773 | fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); |
774 | qDebug("wanna save filename "+currentFileName); | 774 | qDebug("wanna save filename "+currentFileName); |
775 | fileSaveDlg->exec(); | 775 | fileSaveDlg->exec(); |
776 | if( fileSaveDlg->result() == 1 ) { | 776 | if( fileSaveDlg->result() == 1 ) { |
777 | QString fileNm=fileSaveDlg->selectedFileName; | 777 | QString fileNm=fileSaveDlg->selectedFileName; |
778 | qDebug("saving filename "+fileNm); | 778 | qDebug("saving filename "+fileNm); |
779 | QFileInfo fi(fileNm); | 779 | QFileInfo fi(fileNm); |
780 | currentFileName=fi.fileName(); | 780 | currentFileName=fi.fileName(); |
781 | if(doc) { | 781 | if(doc) { |
782 | // QString file = doc->file(); | 782 | // QString file = doc->file(); |
783 | // doc->removeFiles(); | 783 | // doc->removeFiles(); |
784 | delete doc; | 784 | delete doc; |
785 | DocLnk nf; | 785 | DocLnk nf; |
786 | nf.setType("text/plain"); | 786 | nf.setType("text/plain"); |
787 | nf.setFile( fileNm); | 787 | nf.setFile( fileNm); |
788 | doc = new DocLnk(nf); | 788 | doc = new DocLnk(nf); |
789 | // editor->setText(rt); | 789 | // editor->setText(rt); |
790 | // qDebug("openFile doclnk "+currentFileName); | 790 | // qDebug("openFile doclnk "+currentFileName); |
791 | doc->setName( currentFileName); | 791 | doc->setName( currentFileName); |
792 | updateCaption( currentFileName); | 792 | updateCaption( currentFileName); |
793 | 793 | ||
794 | FileManager fm; | 794 | FileManager fm; |
795 | if ( !fm.saveFile( *doc, rt ) ) { | 795 | if ( !fm.saveFile( *doc, rt ) ) { |
796 | return false; | 796 | return false; |
797 | } | 797 | } |
798 | if( fileSaveDlg->filePermCheck->isChecked() ) { | 798 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
799 | filePermissions *filePerm; | 799 | filePermissions *filePerm; |
800 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); | 800 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); |
801 | filePerm->exec(); | 801 | filePerm->exec(); |
802 | 802 | ||
803 | if( filePerm) | 803 | if( filePerm) |
804 | delete filePerm; | 804 | delete filePerm; |
805 | } | 805 | } |
806 | } | 806 | } |
807 | } | 807 | } |
808 | editor->setEdited(TRUE); | 808 | editor->setEdited(TRUE); |
809 | edited1=FALSE; | 809 | edited1=FALSE; |
810 | edited=TRUE; | 810 | edited=TRUE; |
811 | if(caption().left(1)=="*") | 811 | if(caption().left(1)=="*") |
812 | setCaption(caption().right(caption().length()-1)); | 812 | setCaption(caption().right(caption().length()-1)); |
813 | 813 | ||
814 | if(fileSaveDlg) | 814 | if(fileSaveDlg) |
815 | delete fileSaveDlg; | 815 | delete fileSaveDlg; |
816 | return true; | 816 | return true; |
817 | } | 817 | } |
818 | 818 | ||
819 | void TextEdit::clear() | 819 | void TextEdit::clear() |
820 | { | 820 | { |
821 | delete doc; | 821 | delete doc; |
822 | doc = 0; | 822 | doc = 0; |
823 | editor->clear(); | 823 | editor->clear(); |
824 | } | 824 | } |
825 | 825 | ||
826 | void TextEdit::updateCaption( const QString &name ) | 826 | void TextEdit::updateCaption( const QString &name ) |
827 | { | 827 | { |
828 | if ( !doc ) | 828 | if ( !doc ) |
829 | setCaption( tr("Text Editor") ); | 829 | setCaption( tr("Text Editor") ); |
830 | else { | 830 | else { |
831 | QString s = name; | 831 | QString s = name; |
832 | if ( s.isNull() ) | 832 | if ( s.isNull() ) |
833 | s = doc->name(); | 833 | s = doc->name(); |
834 | if ( s.isEmpty() ) { | 834 | if ( s.isEmpty() ) { |
835 | s = tr( "Unnamed" ); | 835 | s = tr( "Unnamed" ); |
836 | currentFileName=s; | 836 | currentFileName=s; |
837 | } | 837 | } |
838 | 838 | ||
839 | setCaption( s + " - " + tr("Text Editor") ); | 839 | setCaption( s + " - " + tr("Text Editor") ); |
840 | } | 840 | } |
841 | } | 841 | } |
842 | 842 | ||
843 | void TextEdit::setDocument(const QString& fileref) | 843 | void TextEdit::setDocument(const QString& fileref) |
844 | { | 844 | { |
845 | bFromDocView = TRUE; | 845 | bFromDocView = TRUE; |
846 | qDebug("setDocument "+fileref); | 846 | qDebug("setDocument "+fileref); |
847 | bFromDocView = TRUE; | 847 | bFromDocView = TRUE; |
848 | if(fileref.find(".desktop",0,TRUE) == -1) { | 848 | if(fileref.find(".desktop",0,TRUE) == -1) { |
849 | openFile(fileref); | 849 | openFile(fileref); |
850 | } else { | 850 | } else { |
851 | openFile(DocLnk(fileref)); | 851 | openFile(DocLnk(fileref)); |
852 | } | 852 | } |
853 | editor->setEdited(TRUE); | 853 | editor->setEdited(TRUE); |
854 | edited1=FALSE; | 854 | edited1=FALSE; |
855 | edited=TRUE; | 855 | edited=TRUE; |
856 | doSearchBar(); | 856 | doSearchBar(); |
857 | } | 857 | } |
858 | 858 | ||
859 | void TextEdit::closeEvent( QCloseEvent *e ) | 859 | void TextEdit::closeEvent( QCloseEvent *e ) |
860 | { | 860 | { |
861 | bFromDocView = FALSE; | 861 | bFromDocView = FALSE; |
862 | e->accept(); | 862 | e->accept(); |
863 | } | 863 | } |
864 | 864 | ||
865 | void TextEdit::accept() | 865 | void TextEdit::accept() |
866 | { | 866 | { |
867 | QString file = doc->file(); | 867 | QString file = doc->file(); |
868 | if (file.find("_.txt",0,TRUE) ==-1) | 868 | if (file.find("_.txt",0,TRUE) ==-1) |
869 | save(); | 869 | save(); |
870 | else { | 870 | else { |
871 | QFile(file).remove(); | 871 | QFile(file).remove(); |
872 | } | 872 | } |
873 | exit(0); | 873 | exit(0); |
874 | 874 | ||
875 | } | 875 | } |
876 | 876 | ||
877 | void TextEdit::changeFont() { | 877 | void TextEdit::changeFont() { |
878 | FontDatabase fdb; | 878 | FontDatabase fdb; |
879 | QFont defaultFont=editor->font(); | 879 | QFont defaultFont=editor->font(); |
880 | QFontInfo fontInfo(defaultFont); | 880 | QFontInfo fontInfo(defaultFont); |
881 | Config cfg("TextEdit"); | 881 | Config cfg("TextEdit"); |
882 | cfg.setGroup("Font"); | 882 | cfg.setGroup("Font"); |
883 | QString family = cfg.readEntry("Family", fontInfo.family()); | 883 | QString family = cfg.readEntry("Family", fontInfo.family()); |
884 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 884 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
885 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 885 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
886 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 886 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
887 | 887 | ||
888 | defaultFont = fdb.font(family,style,i_size,charSet); | 888 | defaultFont = fdb.font(family,style,i_size,charSet); |
889 | 889 | ||
890 | FontDialog *fontDlg; | 890 | FontDialog *fontDlg; |
891 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 891 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
892 | 892 | ||
893 | fontDlg->exec(); | 893 | fontDlg->exec(); |
894 | 894 | ||
895 | QFont myFont=fontDlg->selectedFont; | 895 | QFont myFont=fontDlg->selectedFont; |
896 | editor->setFont( myFont); | 896 | editor->setFont( myFont); |
897 | delete fontDlg; | 897 | delete fontDlg; |
898 | 898 | ||
899 | } | 899 | } |
900 | 900 | ||
901 | void TextEdit::editDelete() | 901 | void TextEdit::editDelete() |
902 | { | 902 | { |
903 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 903 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
904 | case 0: | 904 | case 0: |
905 | if(doc) { | 905 | if(doc) { |
906 | doc->removeFiles(); | 906 | doc->removeFiles(); |
907 | clear(); | 907 | clear(); |
908 | setCaption( tr("Text Editor") ); | 908 | setCaption( tr("Text Editor") ); |
909 | } | 909 | } |
910 | break; | 910 | break; |
911 | case 1: | 911 | case 1: |
912 | // exit | 912 | // exit |
913 | break; | 913 | break; |
914 | }; | 914 | }; |
915 | } | 915 | } |
916 | 916 | ||
917 | void TextEdit::changeStartConfig( bool b ) { | 917 | void TextEdit::changeStartConfig( bool b ) { |
918 | 918 | ||
919 | Config cfg("TextEdit"); | 919 | Config cfg("TextEdit"); |
920 | cfg.setGroup("View"); | 920 | cfg.setGroup("View"); |
921 | if(b) { | 921 | if(b) { |
922 | qDebug("bool"); | 922 | qDebug("bool"); |
923 | cfg.writeEntry("startNew","TRUE"); | 923 | cfg.writeEntry("startNew","TRUE"); |
924 | } else { | 924 | } else { |
925 | cfg.writeEntry("startNew","FALSE"); | 925 | cfg.writeEntry("startNew","FALSE"); |
926 | } | 926 | } |
927 | update(); | 927 | update(); |
928 | } | 928 | } |
929 | 929 | ||
930 | void TextEdit::editorChanged() { | 930 | void TextEdit::editorChanged() { |
931 | if(editor->edited() && edited && !edited1) { | 931 | if(editor->edited() && edited && !edited1) { |
932 | setCaption( "*"+caption()); | 932 | setCaption( "*"+caption()); |
933 | edited1=TRUE; | 933 | edited1=TRUE; |
934 | } | 934 | } |
935 | edited=TRUE; | 935 | edited=TRUE; |
936 | } | 936 | } |
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 70cf068..af69518 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -1,120 +1,121 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 | 20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 |
21 | 21 | ||
22 | #ifndef TEXTEDIT_H | 22 | #ifndef TEXTEDIT_H |
23 | #define TEXTEDIT_H | 23 | #define TEXTEDIT_H |
24 | 24 | ||
25 | #define QTEXTEDIT_OPEN_API | 25 | #define QTEXTEDIT_OPEN_API |
26 | 26 | ||
27 | #include "fileBrowser.h" | 27 | #include "fileBrowser.h" |
28 | #include "fileSaver.h" | 28 | #include "fileSaver.h" |
29 | 29 | ||
30 | #include <qpe/filemanager.h> | 30 | #include <qpe/filemanager.h> |
31 | 31 | ||
32 | #include <qmainwindow.h> | 32 | #include <qmainwindow.h> |
33 | #include <qmultilineedit.h> | 33 | #include <qmultilineedit.h> |
34 | #include <qlist.h> | 34 | #include <qlist.h> |
35 | #include <qmap.h> | 35 | #include <qmap.h> |
36 | 36 | ||
37 | class QAction; | 37 | class QAction; |
38 | class QWidgetStack; | 38 | class QWidgetStack; |
39 | class QToolButton; | 39 | class QToolButton; |
40 | class QPopupMenu; | 40 | class QPopupMenu; |
41 | class QToolBar; | 41 | class QToolBar; |
42 | class QLineEdit; | 42 | class QLineEdit; |
43 | class QAction; | 43 | class QAction; |
44 | class FileSelector; | 44 | class FileSelector; |
45 | class QpeEditor; | 45 | class QpeEditor; |
46 | class QPopupMenu; | 46 | class QPopupMenu; |
47 | 47 | ||
48 | class TextEdit : public QMainWindow | 48 | class TextEdit : public QMainWindow |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | 51 | ||
52 | public: | 52 | public: |
53 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 53 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
54 | ~TextEdit(); | 54 | ~TextEdit(); |
55 | QPopupMenu *font; | 55 | |
56 | QPopupMenu *font; | ||
56 | QAction *nStart; | 57 | QAction *nStart; |
57 | bool edited, edited1; | 58 | bool edited, edited1; |
58 | void openFile( const QString & ); | 59 | void openFile( const QString & ); |
59 | public slots: | 60 | public slots: |
60 | void editorChanged(); | 61 | void editorChanged(); |
61 | 62 | ||
62 | protected: | 63 | protected: |
63 | void closeEvent( QCloseEvent *e ); | 64 | void closeEvent( QCloseEvent *e ); |
64 | void doSearchBar(); | 65 | void doSearchBar(); |
65 | private slots: | 66 | private slots: |
66 | void setDocument(const QString&); | 67 | void setDocument(const QString&); |
67 | void changeFont(); | 68 | void changeFont(); |
68 | void fileNew(); | 69 | void fileNew(); |
69 | void fileRevert(); | 70 | void fileRevert(); |
70 | void fileOpen(); | 71 | void fileOpen(); |
71 | void changeStartConfig(bool); | 72 | void changeStartConfig(bool); |
72 | bool save(); | 73 | bool save(); |
73 | bool saveAs(); | 74 | bool saveAs(); |
74 | void cleanUp(); | 75 | void cleanUp(); |
75 | 76 | ||
76 | 77 | ||
77 | void editCut(); | 78 | void editCut(); |
78 | void editCopy(); | 79 | void editCopy(); |
79 | void editPaste(); | 80 | void editPaste(); |
80 | void editFind(); | 81 | void editFind(); |
81 | void editDelete(); | 82 | void editDelete(); |
82 | 83 | ||
83 | void findNext(); | 84 | void findNext(); |
84 | void findClose(); | 85 | void findClose(); |
85 | 86 | ||
86 | void search(); | 87 | void search(); |
87 | void accept(); | 88 | void accept(); |
88 | 89 | ||
89 | void newFile( const DocLnk & ); | 90 | void newFile( const DocLnk & ); |
90 | void openFile( const DocLnk & ); | 91 | void openFile( const DocLnk & ); |
91 | void showEditTools(); | 92 | void showEditTools(); |
92 | 93 | ||
93 | void zoomIn(); | 94 | void zoomIn(); |
94 | void zoomOut(); | 95 | void zoomOut(); |
95 | void setBold(bool y); | 96 | void setBold(bool y); |
96 | void setItalic(bool y); | 97 | void setItalic(bool y); |
97 | void setWordWrap(bool y); | 98 | void setWordWrap(bool y); |
98 | 99 | ||
99 | private: | 100 | private: |
100 | void colorChanged( const QColor &c ); | 101 | void colorChanged( const QColor &c ); |
101 | void clear(); | 102 | void clear(); |
102 | void updateCaption( const QString &name=QString::null ); | 103 | void updateCaption( const QString &name=QString::null ); |
103 | void setFontSize(int sz, bool round_down_not_up); | 104 | void setFontSize(int sz, bool round_down_not_up); |
104 | 105 | ||
105 | private: | 106 | private: |
106 | fileSaver *fileSaveDlg; | 107 | fileSaver *fileSaveDlg; |
107 | fileBrowser *browseForFiles; | 108 | fileBrowser *browseForFiles; |
108 | 109 | ||
109 | QpeEditor* editor; | 110 | QpeEditor* editor; |
110 | QToolBar *menu, *editBar, *searchBar; | 111 | QToolBar *menu, *editBar, *searchBar; |
111 | QLineEdit *searchEdit; | 112 | QLineEdit *searchEdit; |
112 | DocLnk *doc; | 113 | DocLnk *doc; |
113 | bool searchVisible; | 114 | bool searchVisible; |
114 | bool bFromDocView; | 115 | bool bFromDocView; |
115 | int viewSelection; | 116 | int viewSelection; |
116 | QAction *zin, *zout; | 117 | QAction *zin, *zout; |
117 | QString currentFileName; | 118 | QString currentFileName; |
118 | }; | 119 | }; |
119 | 120 | ||
120 | #endif | 121 | #endif |