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