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