summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-07 14:37:57 (UTC)
committer alwin <alwin>2005-03-07 14:37:57 (UTC)
commit61b9d5f646faa5bd84391318f6440bee6cbefcd8 (patch) (unidiff)
treeb05eba6d4f33dd501c8fe6af0579567de7f659ec
parent9ac0dc3c7b4e56f38c3cefce2e5699078aa3a357 (diff)
downloadopie-61b9d5f646faa5bd84391318f6440bee6cbefcd8.zip
opie-61b9d5f646faa5bd84391318f6440bee6cbefcd8.tar.gz
opie-61b9d5f646faa5bd84391318f6440bee6cbefcd8.tar.bz2
when copying a file to another storage it checks if the target-dir
(eg <storage>/Documents/<mime>/<mimesub>) exists and create it otherwise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/lnkproperties.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp
index f0f0bba..f05f398 100644
--- a/library/lnkproperties.cpp
+++ b/library/lnkproperties.cpp
@@ -23,48 +23,49 @@
23#define QTOPIA_INTERNAL_FSLP 23#define QTOPIA_INTERNAL_FSLP
24#include "lnkpropertiesbase_p.h" 24#include "lnkpropertiesbase_p.h"
25#include "lnkproperties.h" 25#include "lnkproperties.h"
26#include "ir.h" 26#include "ir.h"
27 27
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
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#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
33#include <qpe/filemanager.h> 33#include <qpe/filemanager.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/storage.h> 35#include <qpe/storage.h>
36#include <qpe/qpemessagebox.h> 36#include <qpe/qpemessagebox.h>
37#include <qpe/mimetype.h> 37#include <qpe/mimetype.h>
38 38
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qtoolbutton.h> 40#include <qtoolbutton.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qgroupbox.h> 42#include <qgroupbox.h>
43#include <qcheckbox.h> 43#include <qcheckbox.h>
44#include <qlabel.h> 44#include <qlabel.h>
45#include <qlayout.h> 45#include <qlayout.h>
46#include <qfile.h> 46#include <qfile.h>
47#include <qdir.h>
47#include <qfileinfo.h> 48#include <qfileinfo.h>
48#include <qmessagebox.h> 49#include <qmessagebox.h>
49#include <qsize.h> 50#include <qsize.h>
50#include <qcombobox.h> 51#include <qcombobox.h>
51#include <qregexp.h> 52#include <qregexp.h>
52#include <qbuttongroup.h> 53#include <qbuttongroup.h>
53 54
54#include <stdlib.h> 55#include <stdlib.h>
55 56
56LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) 57LnkProperties::LnkProperties( AppLnk* l, QWidget* parent )
57 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 ) 58 : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 )
58{ 59{
59 setCaption( tr("Properties") ); 60 setCaption( tr("Properties") );
60 61
61 QVBoxLayout *vbox = new QVBoxLayout( this ); 62 QVBoxLayout *vbox = new QVBoxLayout( this );
62 d = new LnkPropertiesBase( this ); 63 d = new LnkPropertiesBase( this );
63 vbox->add( d ); 64 vbox->add( d );
64 65
65 // hide custom rotation feature for now, need a new implementation to fit quicklauch, 66 // hide custom rotation feature for now, need a new implementation to fit quicklauch,
66 // is confusing for the user and doubtable useful since life rotation 67 // is confusing for the user and doubtable useful since life rotation
67 d->rotate->hide(); 68 d->rotate->hide();
68 d->rotateButtons->hide(); 69 d->rotateButtons->hide();
69 70
70 d->docname->setText(l->name()); 71 d->docname->setText(l->name());
@@ -226,61 +227,98 @@ void LnkProperties::duplicateLnk()
226bool LnkProperties::moveLnk() 227bool LnkProperties::moveLnk()
227{ 228{
228 DocLnk newdoc( *((DocLnk *)lnk) ); 229 DocLnk newdoc( *((DocLnk *)lnk) );
229 newdoc.setName(d->docname->text()); 230 newdoc.setName(d->docname->text());
230 231
231 if ( !copyFile( newdoc ) ) { 232 if ( !copyFile( newdoc ) ) {
232 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") ); 233 QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") );
233 return FALSE; 234 return FALSE;
234 } 235 }
235 // remove old lnk 236 // remove old lnk
236 lnk->removeFiles(); 237 lnk->removeFiles();
237 238
238 return TRUE; 239 return TRUE;
239} 240}
240 241
241void LnkProperties::beamLnk() 242void LnkProperties::beamLnk()
242{ 243{
243 Ir ir; 244 Ir ir;
244 DocLnk doc( *((DocLnk *)lnk) ); 245 DocLnk doc( *((DocLnk *)lnk) );
245 doc.setName(d->docname->text()); 246 doc.setName(d->docname->text());
246 reject(); 247 reject();
247 ir.send( doc, doc.comment() ); 248 ir.send( doc, doc.comment() );
248} 249}
249 250
251static bool createMimedir(const QString&base,const QString&mimetype)
252{
253 int pos = 0;
254 int stage = 0;
255 if (base.length()==0) return FALSE;
256 QString _tname = base+"/Documents";
257 QDir _dir(_tname+"/"+mimetype);
258 if (_dir.exists()) return TRUE;
259 pos = mimetype.find("/");
260 _dir.setPath(_tname);
261 while (stage<2) {
262 if (!_dir.exists()) {
263 if (!_dir.mkdir(_tname)) {
264 qDebug( QString("Creation of dir %1 failed\n").arg(_tname));
265 return FALSE;
266 }
267 }
268 switch(stage) {
269 case 0:
270 _tname+="/"+mimetype.left(pos);
271 break;
272 case 1:
273 _tname+="/"+mimetype.right(pos-1);
274 break;
275 default:
276 break;
277 }
278 _dir.setPath(_tname);
279 ++stage;
280 }
281 return TRUE;
282}
283
250bool LnkProperties::copyFile( DocLnk &newdoc ) 284bool LnkProperties::copyFile( DocLnk &newdoc )
251{ 285{
252 const char *linkExtn = ".desktop"; 286 const char *linkExtn = ".desktop";
253 QString fileExtn; 287 QString fileExtn;
254 int extnPos = lnk->file().findRev( '.' ); 288 int extnPos = lnk->file().findRev( '.' );
255 if ( extnPos > 0 ) 289 if ( extnPos > 0 )
256 fileExtn = lnk->file().mid( extnPos ); 290 fileExtn = lnk->file().mid( extnPos );
257 291
258 QString safename = newdoc.name(); 292 QString safename = newdoc.name();
259 safename.replace(QRegExp("/"),"_"); 293 safename.replace(QRegExp("/"),"_");
260 294
261 QString fn = locations[ d->locationCombo->currentItem() ] 295 QString fn = locations[ d->locationCombo->currentItem() ]
262 + "/Documents/" + newdoc.type() + "/" + safename; 296 + "/Documents/" + newdoc.type();
297 if (!createMimedir(locations[ d->locationCombo->currentItem() ],newdoc.type())) {
298 return FALSE;
299 }
300 fn+="/"+safename;
263 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) { 301 if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
264 int n=1; 302 int n=1;
265 QString nn = fn + "_" + QString::number(n); 303 QString nn = fn + "_" + QString::number(n);
266 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) { 304 while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
267 n++; 305 n++;
268 nn = fn + "_" + QString::number(n); 306 nn = fn + "_" + QString::number(n);
269 } 307 }
270 fn = nn; 308 fn = nn;
271 } 309 }
272 newdoc.setFile( fn + fileExtn ); 310 newdoc.setFile( fn + fileExtn );
273 newdoc.setLinkFile( fn + linkExtn ); 311 newdoc.setLinkFile( fn + linkExtn );
274 312
275 // Copy file 313 // Copy file
276 FileManager fm; 314 FileManager fm;
277 if ( !fm.copyFile( *lnk, newdoc ) ) 315 if ( !fm.copyFile( *lnk, newdoc ) )
278 return FALSE; 316 return FALSE;
279 return TRUE; 317 return TRUE;
280} 318}
281 319
282void LnkProperties::done(int ok) 320void LnkProperties::done(int ok)
283{ 321{
284 if ( ok ) { 322 if ( ok ) {
285 bool changed=FALSE; 323 bool changed=FALSE;
286 bool reloadMime=FALSE; 324 bool reloadMime=FALSE;