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