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