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