lnkproperties.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define QTOPIA_INTERNAL_FSLP
00024 #include "lnkproperties.h"
00025 #include "lnkproperties.h"
00026 #include "lnkpropertiesbase_p.h"
00027 #include "ir.h"
00028
00029 #include <qpe/qpeapplication.h>
00030 #include <qpe/applnk.h>
00031 #include <qpe/global.h>
00032 #include <qpe/categorywidget.h>
00033 #include <qpe/qcopenvelope_qws.h>
00034 #include <qpe/filemanager.h>
00035 #include <qpe/config.h>
00036 #include <qpe/storage.h>
00037 #include <qpe/qpemessagebox.h>
00038 #include <qpe/mimetype.h>
00039
00040 #include <qlineedit.h>
00041 #include <qtoolbutton.h>
00042 #include <qpushbutton.h>
00043 #include <qgroupbox.h>
00044 #include <qcheckbox.h>
00045 #include <qlabel.h>
00046 #include <qlayout.h>
00047 #include <qfile.h>
00048 #include <qfileinfo.h>
00049 #include <qmessagebox.h>
00050 #include <qsize.h>
00051 #include <qcombobox.h>
00052 #include <qregexp.h>
00053 #include <qbuttongroup.h>
00054
00055 #include <stdlib.h>
00056
00057 LnkProperties::LnkProperties( AppLnk* l, QWidget* parent )
00058 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 )
00059 {
00060 setCaption( tr("Properties") );
00061
00062 QVBoxLayout *vbox = new QVBoxLayout( this );
00063 d = new LnkPropertiesBase( this );
00064 vbox->add( d );
00065
00066 d->docname->setText(l->name());
00067 QString inf;
00068 if ( l->type().isEmpty() ) {
00069 d->type->hide();
00070 d->typeLabel->hide();
00071 } else {
00072 d->type->setText( l->type() );
00073 }
00074
00075 if ( l->comment().isEmpty() ) {
00076 d->comment->hide();
00077 d->commentLabel->hide();
00078 } else {
00079 d->comment->setText( l->comment() );
00080 }
00081
00082 connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk()));
00083 if ( lnk->type().contains('/') ) {
00084 connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk()));
00085 connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk()));
00086
00087 d->docname->setReadOnly( FALSE );
00088 d->preload->hide();
00089 d->rotate->hide();
00090 d->rotateButtons->hide();
00091 d->labelspacer->hide();
00092
00093
00094 d->categoryEdit->kludge();
00095
00096 d->categoryEdit->setCategories( lnk->categories(),
00097 "Document View",
00098 tr("Document View") );
00099 setupLocations();
00100 } else {
00101 d->unlink->hide();
00102 d->duplicate->hide();
00103 d->beam->hide();
00104 d->hline->hide();
00105 d->locationLabel->hide();
00106 d->locationCombo->hide();
00107
00108
00109
00110 d->categoryEdit->hide();
00111
00112 d->docname->setReadOnly( TRUE );
00113
00114 if ( l->property("CanFastload") == "0" )
00115 d->preload->hide();
00116 if ( !l->property("Rotation"). isEmpty ()) {
00117 d->rotate->setChecked ( true );
00118 d->rotateButtons->setButton((l->rotation().toInt()%360)/90);
00119 }
00120 else {
00121 d->rotateButtons->setEnabled(false);
00122 }
00123
00124 Config cfg("Launcher");
00125 cfg.setGroup("Preload");
00126 QStringList apps = cfg.readListEntry("Apps",',');
00127 d->preload->setChecked( apps.contains(l->exec()) );
00128 if ( Global::isBuiltinCommand(lnk->exec()) )
00129 d->preload->hide();
00130
00131 currentLocation = 0;
00132 }
00133 }
00134
00135 LnkProperties::~LnkProperties()
00136 {
00137 }
00138
00139 void LnkProperties::unlinkLnk()
00140 {
00141 if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) {
00142 lnk->removeFiles();
00143 if ( QFile::exists(lnk->file()) ) {
00144 QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") );
00145 } else {
00146 reject();
00147 }
00148 }
00149 }
00150
00151 void LnkProperties::setupLocations()
00152 {
00153 QFileInfo fi( lnk->file() );
00154 fileSize = fi.size();
00155 StorageInfo storage;
00156 const QList<FileSystem> &fs = storage.fileSystems();
00157 QListIterator<FileSystem> it ( fs );
00158 QString s;
00159 QString homeDir = getenv("HOME");
00160 QString hardDiskHome;
00161 QString hardDiskPath;
00162 int index = 0;
00163 currentLocation = -1;
00164 for ( ; it.current(); ++it ) {
00165
00166 if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) {
00167 if ( (*it)->isRemovable() ||
00168 (*it)->disk() == "/dev/mtdblock1" ||
00169 (*it)->disk() == "/dev/mtdblock/1" ||
00170 (*it)->disk().left(13) == "/dev/mtdblock" ||
00171 (*it)->disk() == "/dev/mtdblock6" ||
00172 (*it)->disk() == "tmpfs" ) {
00173 d->locationCombo->insertItem( (*it)->name(), index );
00174 locations.append( ( ((*it)->isRemovable() ||
00175 (*it)->disk() == "/dev/mtdblock6" ||
00176 (*it)->disk() == "tmpfs" )
00177 ? (*it)->path() : homeDir) );
00178 if ( lnk->file().contains( (*it)->path() ) ) {
00179 d->locationCombo->setCurrentItem( index );
00180 currentLocation = index;
00181 }
00182 index++;
00183 } else if ( (*it)->name().contains( tr("Hard Disk") ) &&
00184 homeDir.contains( (*it)->path() ) &&
00185 (*it)->path().length() > hardDiskHome.length() ) {
00186 hardDiskHome = (*it)->name();
00187 hardDiskPath = (*it)->path();
00188 }
00189 }
00190 }
00191 if ( !hardDiskHome.isEmpty() ) {
00192 d->locationCombo->insertItem( hardDiskHome );
00193 locations.append( hardDiskPath );
00194 if ( currentLocation == -1 ) {
00195 d->locationCombo->setCurrentItem( index );
00196 currentLocation = index;
00197 }
00198 }
00199 }
00200
00201 void LnkProperties::duplicateLnk()
00202 {
00203
00204 DocLnk newdoc( *((DocLnk *)lnk) );
00205 if ( d->docname->text() == lnk->name() )
00206 newdoc.setName(tr("Copy of ")+d->docname->text());
00207 else
00208 newdoc.setName(d->docname->text());
00209
00210 if ( !copyFile( newdoc ) ) {
00211 QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") );
00212 return;
00213 }
00214 reject();
00215 }
00216
00217 bool LnkProperties::moveLnk()
00218 {
00219 DocLnk newdoc( *((DocLnk *)lnk) );
00220 newdoc.setName(d->docname->text());
00221
00222 if ( !copyFile( newdoc ) ) {
00223 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") );
00224 return FALSE;
00225 }
00226
00227 lnk->removeFiles();
00228
00229 return TRUE;
00230 }
00231
00232 void LnkProperties::beamLnk()
00233 {
00234 Ir ir;
00235 DocLnk doc( *((DocLnk *)lnk) );
00236 doc.setName(d->docname->text());
00237 reject();
00238 ir.send( doc, doc.comment() );
00239 }
00240
00241 bool LnkProperties::copyFile( DocLnk &newdoc )
00242 {
00243 const char *linkExtn = ".desktop";
00244 QString fileExtn;
00245 int extnPos = lnk->file().findRev( '.' );
00246 if ( extnPos > 0 )
00247 fileExtn = lnk->file().mid( extnPos );
00248
00249 QString safename = newdoc.name();
00250 safename.replace(QRegExp("/"),"_");
00251
00252 QString fn = locations[ d->locationCombo->currentItem() ]
00253 + "/Documents/" + newdoc.type() + "/" + safename;
00254 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
00255 int n=1;
00256 QString nn = fn + "_" + QString::number(n);
00257 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
00258 n++;
00259 nn = fn + "_" + QString::number(n);
00260 }
00261 fn = nn;
00262 }
00263 newdoc.setFile( fn + fileExtn );
00264 newdoc.setLinkFile( fn + linkExtn );
00265
00266
00267 FileManager fm;
00268 if ( !fm.copyFile( *lnk, newdoc ) )
00269 return FALSE;
00270 return TRUE;
00271 }
00272
00273 void LnkProperties::done(int ok)
00274 {
00275 if ( ok ) {
00276 bool changed=FALSE;
00277 bool reloadMime=FALSE;
00278
00279 if ( lnk->name() != d->docname->text() ) {
00280 lnk->setName(d->docname->text());
00281 changed=TRUE;
00282 }
00283 if ( d->categoryEdit->isVisible() ) {
00284 QArray<int> tmp = d->categoryEdit->newCategories();
00285 if ( lnk->categories() != tmp ) {
00286 lnk->setCategories( tmp );
00287 changed = TRUE;
00288 }
00289 }
00290 if ( !d->rotate->isHidden()) {
00291 QString newrot;
00292
00293 if ( d->rotate->isChecked() ) {
00294 int rot=0;
00295 for(; rot<4; rot++) {
00296 if (d->rotateButtons->find(rot)->isOn())
00297 break;
00298 }
00299 newrot = QString::number((rot*90)%360);
00300 }
00301 if ( newrot != lnk->rotation() ) {
00302 lnk-> setRotation(newrot);
00303 changed = TRUE;
00304 reloadMime = TRUE;
00305 }
00306 }
00307 if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) {
00308 moveLnk();
00309 } else if ( changed ) {
00310 lnk->writeLink();
00311 }
00312
00313 if ( !d->preload->isHidden() ) {
00314 Config cfg("Launcher");
00315 cfg.setGroup("Preload");
00316 QStringList apps = cfg.readListEntry("Apps",',');
00317 QString exe = lnk->exec();
00318 if ( apps.contains(exe) != d->preload->isChecked() ) {
00319 if ( d->preload->isChecked() ) {
00320 apps.append(exe);
00321 #ifndef QT_NO_COP
00322 QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
00323 "enablePreload()");
00324 #endif
00325 } else {
00326 apps.remove(exe);
00327 #ifndef QT_NO_COP
00328 QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
00329 "quitIfInvisible()");
00330 #endif
00331 }
00332 cfg.writeEntry("Apps",apps,',');
00333 }
00334 }
00335 if ( reloadMime )
00336 MimeType::updateApplications ( );
00337 }
00338 QDialog::done( ok );
00339 }
00340
This file is part of the documentation for OPIE Version 1.5.5.