summaryrefslogtreecommitdiff
path: root/library/lnkproperties.cpp
Unidiff
Diffstat (limited to 'library/lnkproperties.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/lnkproperties.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp
index 50cf5af..8dca4ab 100644
--- a/library/lnkproperties.cpp
+++ b/library/lnkproperties.cpp
@@ -1,340 +1,347 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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 20
21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class. 22// have this class.
23#define QTOPIA_INTERNAL_FSLP 23#define QTOPIA_INTERNAL_FSLP
24#include "lnkproperties.h" 24#include "lnkproperties.h"
25#include "lnkproperties.h" 25#include "lnkproperties.h"
26#include "lnkpropertiesbase_p.h" 26#include "lnkpropertiesbase_p.h"
27#include "ir.h" 27#include "ir.h"
28 28
29#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
30#include <qpe/applnk.h> 30#include <qpe/applnk.h>
31#include <qpe/global.h> 31#include <qpe/global.h>
32#include <qpe/categorywidget.h> 32#include <qpe/categorywidget.h>
33#include <qpe/qcopenvelope_qws.h> 33#include <qpe/qcopenvelope_qws.h>
34#include <qpe/filemanager.h> 34#include <qpe/filemanager.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/storage.h> 36#include <qpe/storage.h>
37#include <qpe/qpemessagebox.h> 37#include <qpe/qpemessagebox.h>
38#include <qpe/mimetype.h> 38#include <qpe/mimetype.h>
39 39
40#include <qlineedit.h> 40#include <qlineedit.h>
41#include <qtoolbutton.h> 41#include <qtoolbutton.h>
42#include <qpushbutton.h> 42#include <qpushbutton.h>
43#include <qgroupbox.h> 43#include <qgroupbox.h>
44#include <qcheckbox.h> 44#include <qcheckbox.h>
45#include <qlabel.h> 45#include <qlabel.h>
46#include <qlayout.h> 46#include <qlayout.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qfileinfo.h> 48#include <qfileinfo.h>
49#include <qmessagebox.h> 49#include <qmessagebox.h>
50#include <qsize.h> 50#include <qsize.h>
51#include <qcombobox.h> 51#include <qcombobox.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qbuttongroup.h> 53#include <qbuttongroup.h>
54 54
55#include <stdlib.h> 55#include <stdlib.h>
56 56
57LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) 57LnkProperties::LnkProperties( AppLnk* l, QWidget* parent )
58 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 ) 58 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 )
59{ 59{
60 setCaption( tr("Properties") ); 60 setCaption( tr("Properties") );
61 61
62 QVBoxLayout *vbox = new QVBoxLayout( this ); 62 QVBoxLayout *vbox = new QVBoxLayout( this );
63 d = new LnkPropertiesBase( this ); 63 d = new LnkPropertiesBase( this );
64 vbox->add( d ); 64 vbox->add( d );
65 65
66 // hide custom rotation feature for now, need a new implementation to fit quicklauch,
67 // is confusing for the user and doubtable useful since life rotation
68 d->rotate->hide();
69 d->rotateButtons->hide();
70
66 d->docname->setText(l->name()); 71 d->docname->setText(l->name());
67 QString inf; 72 QString inf;
68 if ( l->type().isEmpty() ) { 73 if ( l->type().isEmpty() ) {
69 d->type->hide(); 74 d->type->hide();
70 d->typeLabel->hide(); 75 d->typeLabel->hide();
71 } else { 76 } else {
72 d->type->setText( l->type() ); 77 d->type->setText( l->type() );
73 } 78 }
74 79
75 if ( l->comment().isEmpty() ) { 80 if ( l->comment().isEmpty() ) {
76 d->comment->hide(); 81 d->comment->hide();
77 d->commentLabel->hide(); 82 d->commentLabel->hide();
78 } else { 83 } else {
79 d->comment->setText( l->comment() ); 84 d->comment->setText( l->comment() );
80 } 85 }
81 86
82 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk())); 87 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk()));
83 if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed) 88 if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed)
84 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk())); 89 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk()));
85 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk())); 90 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk()));
86 91
87 d->docname->setReadOnly( FALSE ); 92 d->docname->setReadOnly( FALSE );
88 d->preload->hide(); 93 d->preload->hide();
89 d->rotate->hide(); 94 d->rotate->hide();
90 d->rotateButtons->hide(); 95 d->rotateButtons->hide();
91 d->labelspacer->hide(); 96 d->labelspacer->hide();
92 97
93 // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT 98 // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT
94 d->categoryEdit->kludge(); 99 d->categoryEdit->kludge();
95 100
96 d->categoryEdit->setCategories( lnk->categories(), 101 d->categoryEdit->setCategories( lnk->categories(),
97 "Document View", 102 "Document View",
98 tr("Document View") ); 103 tr("Document View") );
99 setupLocations(); 104 setupLocations();
100 } else { 105 } else {
101 d->unlink->hide(); 106 d->unlink->hide();
102 d->duplicate->hide(); 107 d->duplicate->hide();
103 d->beam->hide(); 108 d->beam->hide();
104 d->hline->hide(); 109 d->hline->hide();
105 d->locationLabel->hide(); 110 d->locationLabel->hide();
106 d->locationCombo->hide(); 111 d->locationCombo->hide();
107 112
108 // Can't edit categories, since the app .desktop files are global, 113 // Can't edit categories, since the app .desktop files are global,
109 // possibly read-only. 114 // possibly read-only.
110 d->categoryEdit->hide(); 115 d->categoryEdit->hide();
111 116
112 d->docname->setReadOnly( TRUE ); 117 d->docname->setReadOnly( TRUE );
113 118
114 if ( l->property("CanFastload") == "0" ) 119 if ( l->property("CanFastload") == "0" )
115 d->preload->hide(); 120 d->preload->hide();
116 if ( !l->property("Rotation"). isEmpty ()) { 121 if ( !l->property("Rotation"). isEmpty ()) {
117 d->rotate->setChecked ( true ); 122 d->rotate->setChecked ( true );
118 d->rotateButtons->setButton((l->rotation().toInt()%360)/90); 123 //don't use rotate buttons for now (see comment above)
124 //d->rotateButtons->setButton((l->rotation().toInt()%360)/90);
119 } 125 }
120 else { 126 else {
121 d->rotateButtons->setEnabled(false); 127 d->rotateButtons->setEnabled(false);
122 } 128 }
123 129
124 Config cfg("Launcher"); 130 Config cfg("Launcher");
125 cfg.setGroup("Preload"); 131 cfg.setGroup("Preload");
126 QStringList apps = cfg.readListEntry("Apps",','); 132 QStringList apps = cfg.readListEntry("Apps",',');
127 d->preload->setChecked( apps.contains(l->exec()) ); 133 d->preload->setChecked( apps.contains(l->exec()) );
128 if ( Global::isBuiltinCommand(lnk->exec()) ) 134 if ( Global::isBuiltinCommand(lnk->exec()) )
129 d->preload->hide(); // builtins are always fast 135 d->preload->hide(); // builtins are always fast
130 136
131 currentLocation = 0; // apps not movable (yet) 137 currentLocation = 0; // apps not movable (yet)
132 } 138 }
133} 139}
134 140
135LnkProperties::~LnkProperties() 141LnkProperties::~LnkProperties()
136{ 142{
137} 143}
138 144
139void LnkProperties::unlinkLnk() 145void LnkProperties::unlinkLnk()
140{ 146{
141 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) { 147 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) {
142 lnk->removeFiles(); 148 lnk->removeFiles();
143 if ( QFile::exists(lnk->file()) ) { 149 if ( QFile::exists(lnk->file()) ) {
144 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") ); 150 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") );
145 } else { 151 } else {
146 reject(); 152 reject();
147 } 153 }
148 } 154 }
149} 155}
150 156
151void LnkProperties::setupLocations() 157void LnkProperties::setupLocations()
152{ 158{
153 QFileInfo fi( lnk->file() ); 159 QFileInfo fi( lnk->file() );
154 fileSize = fi.size(); 160 fileSize = fi.size();
155 StorageInfo storage; 161 StorageInfo storage;
156 const QList<FileSystem> &fs = storage.fileSystems(); 162 const QList<FileSystem> &fs = storage.fileSystems();
157 QListIterator<FileSystem> it ( fs ); 163 QListIterator<FileSystem> it ( fs );
158 QString s; 164 QString s;
159 QString homeDir = getenv("HOME"); 165 QString homeDir = getenv("HOME");
160 QString hardDiskHome; 166 QString hardDiskHome;
161 QString hardDiskPath; 167 QString hardDiskPath;
162 int index = 0; 168 int index = 0;
163 currentLocation = -1; 169 currentLocation = -1;
164 for ( ; it.current(); ++it ) { 170 for ( ; it.current(); ++it ) {
165 // we add 10k to the file size so we are sure we can also save the desktop file 171 // we add 10k to the file size so we are sure we can also save the desktop file
166 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) { 172 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) {
167 if ( (*it)->isRemovable() || 173 if ( (*it)->isRemovable() ||
168 (*it)->disk() == "/dev/mtdblock1" || 174 (*it)->disk() == "/dev/mtdblock1" ||
169 (*it)->disk() == "/dev/mtdblock/1" || 175 (*it)->disk() == "/dev/mtdblock/1" ||
170 (*it)->disk().left(13) == "/dev/mtdblock" || 176 (*it)->disk().left(13) == "/dev/mtdblock" ||
171 (*it)->disk() == "/dev/mtdblock6" || 177 (*it)->disk() == "/dev/mtdblock6" ||
178 (*it )->disk() == "/dev/root" ||
172 (*it)->disk() == "tmpfs" ) { 179 (*it)->disk() == "tmpfs" ) {
173 d->locationCombo->insertItem( (*it)->name(), index ); 180 d->locationCombo->insertItem( (*it)->name(), index );
174 locations.append( ( ((*it)->isRemovable() || 181 locations.append( ( ((*it)->isRemovable() ||
175 (*it)->disk() == "/dev/mtdblock6" || 182 (*it)->disk() == "/dev/mtdblock6" ||
176 (*it)->disk() == "tmpfs" ) 183 (*it)->disk() == "tmpfs" )
177 ? (*it)->path() : homeDir) ); 184 ? (*it)->path() : homeDir) );
178 if ( lnk->file().contains( (*it)->path() ) ) { 185 if ( lnk->file().contains( (*it)->path() ) ) {
179 d->locationCombo->setCurrentItem( index ); 186 d->locationCombo->setCurrentItem( index );
180 currentLocation = index; 187 currentLocation = index;
181 } 188 }
182 index++; 189 index++;
183 } else if ( (*it)->name().contains( tr("Hard Disk") ) && 190 } else if ( (*it)->name().contains( tr("Hard Disk") ) &&
184 homeDir.contains( (*it)->path() ) && 191 homeDir.contains( (*it)->path() ) &&
185 (*it)->path().length() > hardDiskHome.length() ) { 192 (*it)->path().length() > hardDiskHome.length() ) {
186 hardDiskHome = (*it)->name(); 193 hardDiskHome = (*it)->name();
187 hardDiskPath = (*it)->path(); 194 hardDiskPath = (*it)->path();
188 } 195 }
189 } 196 }
190 } 197 }
191 if ( !hardDiskHome.isEmpty() ) { 198 if ( !hardDiskHome.isEmpty() ) {
192 d->locationCombo->insertItem( hardDiskHome ); 199 d->locationCombo->insertItem( hardDiskHome );
193 locations.append( hardDiskPath ); 200 locations.append( hardDiskPath );
194 if ( currentLocation == -1 ) { // assume it's the hard disk 201 if ( currentLocation == -1 ) { // assume it's the hard disk
195 d->locationCombo->setCurrentItem( index ); 202 d->locationCombo->setCurrentItem( index );
196 currentLocation = index; 203 currentLocation = index;
197 } 204 }
198 } 205 }
199} 206}
200 207
201void LnkProperties::duplicateLnk() 208void LnkProperties::duplicateLnk()
202{ 209{
203 // The duplicate takes the new properties. 210 // The duplicate takes the new properties.
204 DocLnk newdoc( *((DocLnk *)lnk) ); 211 DocLnk newdoc( *((DocLnk *)lnk) );
205 if ( d->docname->text() == lnk->name() ) 212 if ( d->docname->text() == lnk->name() )
206 newdoc.setName(tr("Copy of ")+d->docname->text()); 213 newdoc.setName(tr("Copy of ")+d->docname->text());
207 else 214 else
208 newdoc.setName(d->docname->text()); 215 newdoc.setName(d->docname->text());
209 216
210 if ( !copyFile( newdoc ) ) { 217 if ( !copyFile( newdoc ) ) {
211 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") ); 218 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") );
212 return; 219 return;
213 } 220 }
214 reject(); 221 reject();
215} 222}
216 223
217bool LnkProperties::moveLnk() 224bool LnkProperties::moveLnk()
218{ 225{
219 DocLnk newdoc( *((DocLnk *)lnk) ); 226 DocLnk newdoc( *((DocLnk *)lnk) );
220 newdoc.setName(d->docname->text()); 227 newdoc.setName(d->docname->text());
221 228
222 if ( !copyFile( newdoc ) ) { 229 if ( !copyFile( newdoc ) ) {
223 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") ); 230 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") );
224 return FALSE; 231 return FALSE;
225 } 232 }
226 // remove old lnk 233 // remove old lnk
227 lnk->removeFiles(); 234 lnk->removeFiles();
228 235
229 return TRUE; 236 return TRUE;
230} 237}
231 238
232void LnkProperties::beamLnk() 239void LnkProperties::beamLnk()
233{ 240{
234 Ir ir; 241 Ir ir;
235 DocLnk doc( *((DocLnk *)lnk) ); 242 DocLnk doc( *((DocLnk *)lnk) );
236 doc.setName(d->docname->text()); 243 doc.setName(d->docname->text());
237 reject(); 244 reject();
238 ir.send( doc, doc.comment() ); 245 ir.send( doc, doc.comment() );
239} 246}
240 247
241bool LnkProperties::copyFile( DocLnk &newdoc ) 248bool LnkProperties::copyFile( DocLnk &newdoc )
242{ 249{
243 const char *linkExtn = ".desktop"; 250 const char *linkExtn = ".desktop";
244 QString fileExtn; 251 QString fileExtn;
245 int extnPos = lnk->file().findRev( '.' ); 252 int extnPos = lnk->file().findRev( '.' );
246 if ( extnPos > 0 ) 253 if ( extnPos > 0 )
247 fileExtn = lnk->file().mid( extnPos ); 254 fileExtn = lnk->file().mid( extnPos );
248 255
249 QString safename = newdoc.name(); 256 QString safename = newdoc.name();
250 safename.replace(QRegExp("/"),"_"); 257 safename.replace(QRegExp("/"),"_");
251 258
252 QString fn = locations[ d->locationCombo->currentItem() ] 259 QString fn = locations[ d->locationCombo->currentItem() ]
253 + "/Documents/" + newdoc.type() + "/" + safename; 260 + "/Documents/" + newdoc.type() + "/" + safename;
254 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) { 261 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
255 int n=1; 262 int n=1;
256 QString nn = fn + "_" + QString::number(n); 263 QString nn = fn + "_" + QString::number(n);
257 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) { 264 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
258 n++; 265 n++;
259 nn = fn + "_" + QString::number(n); 266 nn = fn + "_" + QString::number(n);
260 } 267 }
261 fn = nn; 268 fn = nn;
262 } 269 }
263 newdoc.setFile( fn + fileExtn ); 270 newdoc.setFile( fn + fileExtn );
264 newdoc.setLinkFile( fn + linkExtn ); 271 newdoc.setLinkFile( fn + linkExtn );
265 272
266 // Copy file 273 // Copy file
267 FileManager fm; 274 FileManager fm;
268 if ( !fm.copyFile( *lnk, newdoc ) ) 275 if ( !fm.copyFile( *lnk, newdoc ) )
269 return FALSE; 276 return FALSE;
270 return TRUE; 277 return TRUE;
271} 278}
272 279
273void LnkProperties::done(int ok) 280void LnkProperties::done(int ok)
274{ 281{
275 if ( ok ) { 282 if ( ok ) {
276 bool changed=FALSE; 283 bool changed=FALSE;
277 bool reloadMime=FALSE; 284 bool reloadMime=FALSE;
278 285
279 if ( lnk->name() != d->docname->text() ) { 286 if ( lnk->name() != d->docname->text() ) {
280 lnk->setName(d->docname->text()); 287 lnk->setName(d->docname->text());
281 changed=TRUE; 288 changed=TRUE;
282 } 289 }
283 if ( d->categoryEdit->isVisible() ) { 290 if ( d->categoryEdit->isVisible() ) {
284 QArray<int> tmp = d->categoryEdit->newCategories(); 291 QArray<int> tmp = d->categoryEdit->newCategories();
285 if ( lnk->categories() != tmp ) { 292 if ( lnk->categories() != tmp ) {
286 lnk->setCategories( tmp ); 293 lnk->setCategories( tmp );
287 changed = TRUE; 294 changed = TRUE;
288 } 295 }
289 } 296 }
290 if ( !d->rotate->isHidden()) { 297 if ( !d->rotate->isHidden()) {
291 QString newrot; 298 QString newrot;
292 299
293 if ( d->rotate->isChecked() ) { 300 if ( d->rotate->isChecked() ) {
294 int rot=0; 301 int rot=0;
295 for(; rot<4; rot++) { 302 for(; rot<4; rot++) {
296 if (d->rotateButtons->find(rot)->isOn()) 303 if (d->rotateButtons->find(rot)->isOn())
297 break; 304 break;
298 } 305 }
299 newrot = QString::number((rot*90)%360); 306 newrot = QString::number((rot*90)%360);
300 } 307 }
301 if ( newrot != lnk->rotation() ) { 308 if ( newrot != lnk->rotation() ) {
302 lnk-> setRotation(newrot); 309 lnk-> setRotation(newrot);
303 changed = TRUE; 310 changed = TRUE;
304 reloadMime = TRUE; 311 reloadMime = TRUE;
305 } 312 }
306 } 313 }
307 if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) { 314 if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) {
308 moveLnk(); 315 moveLnk();
309 } else if ( changed ) { 316 } else if ( changed ) {
310 lnk->writeLink(); 317 lnk->writeLink();
311 } 318 }
312 319
313 if ( !d->preload->isHidden() ) { 320 if ( !d->preload->isHidden() ) {
314 Config cfg("Launcher"); 321 Config cfg("Launcher");
315 cfg.setGroup("Preload"); 322 cfg.setGroup("Preload");
316 QStringList apps = cfg.readListEntry("Apps",','); 323 QStringList apps = cfg.readListEntry("Apps",',');
317 QString exe = lnk->exec(); 324 QString exe = lnk->exec();
318 if ( apps.contains(exe) != d->preload->isChecked() ) { 325 if ( apps.contains(exe) != d->preload->isChecked() ) {
319 if ( d->preload->isChecked() ) { 326 if ( d->preload->isChecked() ) {
320 apps.append(exe); 327 apps.append(exe);
321#ifndef QT_NO_COP 328#ifndef QT_NO_COP
322 QCopEnvelope e("QPE/Application/"+exe.local8Bit(), 329 QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
323 "enablePreload()"); 330 "enablePreload()");
324#endif 331#endif
325 } else { 332 } else {
326 apps.remove(exe); 333 apps.remove(exe);
327#ifndef QT_NO_COP 334#ifndef QT_NO_COP
328 QCopEnvelope e("QPE/Application/"+exe.local8Bit(), 335 QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
329 "quitIfInvisible()"); 336 "quitIfInvisible()");
330#endif 337#endif
331 } 338 }
332 cfg.writeEntry("Apps",apps,','); 339 cfg.writeEntry("Apps",apps,',');
333 } 340 }
334 } 341 }
335 if ( reloadMime ) 342 if ( reloadMime )
336 MimeType::updateApplications ( ); 343 MimeType::updateApplications ( );
337 } 344 }
338 QDialog::done( ok ); 345 QDialog::done( ok );
339} 346}
340 347