-rw-r--r-- | library/lnkproperties.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp index f0f0bba..f05f398 100644 --- a/library/lnkproperties.cpp +++ b/library/lnkproperties.cpp @@ -15,64 +15,65 @@ ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT // have this class. #define QTOPIA_INTERNAL_FSLP #include "lnkpropertiesbase_p.h" #include "lnkproperties.h" #include "ir.h" #include <qpe/qpeapplication.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/categorywidget.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/filemanager.h> #include <qpe/config.h> #include <qpe/storage.h> #include <qpe/qpemessagebox.h> #include <qpe/mimetype.h> #include <qlineedit.h> #include <qtoolbutton.h> #include <qpushbutton.h> #include <qgroupbox.h> #include <qcheckbox.h> #include <qlabel.h> #include <qlayout.h> #include <qfile.h> +#include <qdir.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qsize.h> #include <qcombobox.h> #include <qregexp.h> #include <qbuttongroup.h> #include <stdlib.h> LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 ) { setCaption( tr("Properties") ); QVBoxLayout *vbox = new QVBoxLayout( this ); d = new LnkPropertiesBase( this ); vbox->add( d ); // hide custom rotation feature for now, need a new implementation to fit quicklauch, // is confusing for the user and doubtable useful since life rotation d->rotate->hide(); d->rotateButtons->hide(); d->docname->setText(l->name()); QString inf; if ( l->type().isEmpty() ) { d->type->hide(); d->typeLabel->hide(); } else { d->type->setText( l->type() ); } @@ -218,77 +219,114 @@ void LnkProperties::duplicateLnk() if ( !copyFile( newdoc ) ) { QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") ); return; } reject(); } bool LnkProperties::moveLnk() { DocLnk newdoc( *((DocLnk *)lnk) ); newdoc.setName(d->docname->text()); if ( !copyFile( newdoc ) ) { QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") ); return FALSE; } // remove old lnk lnk->removeFiles(); return TRUE; } void LnkProperties::beamLnk() { Ir ir; DocLnk doc( *((DocLnk *)lnk) ); doc.setName(d->docname->text()); reject(); ir.send( doc, doc.comment() ); } +static bool createMimedir(const QString&base,const QString&mimetype) +{ + int pos = 0; + int stage = 0; + if (base.length()==0) return FALSE; + QString _tname = base+"/Documents"; + QDir _dir(_tname+"/"+mimetype); + if (_dir.exists()) return TRUE; + pos = mimetype.find("/"); + _dir.setPath(_tname); + while (stage<2) { + if (!_dir.exists()) { + if (!_dir.mkdir(_tname)) { + qDebug( QString("Creation of dir %1 failed\n").arg(_tname)); + return FALSE; + } + } + switch(stage) { + case 0: + _tname+="/"+mimetype.left(pos); + break; + case 1: + _tname+="/"+mimetype.right(pos-1); + break; + default: + break; + } + _dir.setPath(_tname); + ++stage; + } + return TRUE; +} + bool LnkProperties::copyFile( DocLnk &newdoc ) { const char *linkExtn = ".desktop"; QString fileExtn; int extnPos = lnk->file().findRev( '.' ); if ( extnPos > 0 ) fileExtn = lnk->file().mid( extnPos ); QString safename = newdoc.name(); safename.replace(QRegExp("/"),"_"); QString fn = locations[ d->locationCombo->currentItem() ] - + "/Documents/" + newdoc.type() + "/" + safename; + + "/Documents/" + newdoc.type(); + if (!createMimedir(locations[ d->locationCombo->currentItem() ],newdoc.type())) { + return FALSE; + } + fn+="/"+safename; if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) { int n=1; QString nn = fn + "_" + QString::number(n); while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) { n++; nn = fn + "_" + QString::number(n); } fn = nn; } newdoc.setFile( fn + fileExtn ); newdoc.setLinkFile( fn + linkExtn ); // Copy file FileManager fm; if ( !fm.copyFile( *lnk, newdoc ) ) return FALSE; return TRUE; } void LnkProperties::done(int ok) { if ( ok ) { bool changed=FALSE; bool reloadMime=FALSE; if ( lnk->name() != d->docname->text() ) { lnk->setName(d->docname->text()); changed=TRUE; } if ( d->categoryEdit->isVisible() ) { QArray<int> tmp = d->categoryEdit->newCategories(); if ( lnk->categories() != tmp ) { |