summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-07 14:37:57 (UTC)
committer alwin <alwin>2005-03-07 14:37:57 (UTC)
commit61b9d5f646faa5bd84391318f6440bee6cbefcd8 (patch) (side-by-side diff)
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) (show whitespace changes)
-rw-r--r--library/lnkproperties.cpp40
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
@@ -46,2 +46,3 @@
#include <qfile.h>
+#include <qdir.h>
#include <qfileinfo.h>
@@ -249,2 +250,35 @@ void LnkProperties::beamLnk()
+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 )
@@ -261,3 +295,7 @@ bool LnkProperties::copyFile( DocLnk &newdoc )
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) ) {