[Uml-devel] KDE/kdesdk/umbrello/umbrello

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Fri Apr 10 19:16:43 UTC 2009


SVN commit 952053 by chehrlic:

remove some win32 hacks
KUrl::path() -> KUrl::toLocalFile()/pathOrUrl()

 M  +11 -35    uml.cpp  
 M  +21 -28    umldoc.cpp  


--- trunk/KDE/kdesdk/umbrello/umbrello/uml.cpp #952052:952053
@@ -59,11 +59,7 @@
 #include <kconfig.h>
 #include <kcursor.h>
 #include <kdebug.h>
-#ifdef Q_WS_WIN
-#include <QtGui/QFileDialog>
-#else
 #include <kfiledialog.h>
-#endif
 #include <klocale.h>
 #include <kmenubar.h>
 #include <kmessagebox.h>
@@ -904,22 +900,12 @@
         // here saving wasn't successful
     } 
     else {
-#ifdef Q_WS_WIN
-        KUrl url=QFileDialog::getOpenFileName(    //krazy:exclude=qclasses
-            this,
-            i18n("Open File"),
-            "",
-            i18n("All Supported Files (*.xmi *.mdl);;"
-                 "XMI Files (*.xmi);;"
-                 "Rose model files (*.mdl)"));
-#else
         KUrl url=KFileDialog::getOpenUrl(KUrl(),
             i18n("*.xmi *.xmi.tgz *.xmi.tar.bz2 *.mdl|All Supported Files (*.xmi, *.xmi.tgz, *.xmi.tar.bz2, *.mdl)\n"
                  "*.xmi|Uncompressed XMI Files (*.xmi)\n"
                  "*.xmi.tgz|Gzip Compressed XMI Files (*.xmi.tgz)\n"
                  "*.xmi.tar.bz2|Bzip2 Compressed XMI Files (*.xmi.tar.bz2)\n"
                  "*.mdl|Rose model files"), this, i18n("Open File"));
-#endif
         if (!url.isEmpty()) {
             if (m_doc->openDocument(url)) {
                 fileOpenRecent->addUrl( url );
@@ -980,15 +966,7 @@
     KUrl url;
     QString ext;
     while (cont) {
-#ifdef Q_WS_WIN
-        url=QFileDialog::getSaveFileName(    //krazy:exclude=qclasses
-            this,
-            i18n("Save As"),
-            "",
-            i18n("XMI File (*.xmi);;All Files (*.*"));
-#else
         url=KFileDialog::getSaveUrl(KUrl(), i18n("*.xmi|XMI File\n*.xmi.tgz|Gzip Compressed XMI File\n*.xmi.tar.bz2|Bzip2 Compressed XMI File\n*|All Files"), this, i18n("Save As"));
-#endif
         if (url.isEmpty()) {
             cont = false;
         }
@@ -1002,16 +980,20 @@
             //    url.setFileName(url.fileName() + ".xmi");
             //    ext = "xmi";
             //}
-            QDir d = url.path( KUrl::RemoveTrailingSlash );
+            if (url.isLocalFile()) {
+                QString file = url.toLocalFile( KUrl::RemoveTrailingSlash );
 
-            if (QFile::exists(d.path())) {
-                int want_save = KMessageBox::warningContinueCancel(this, i18n("The file %1 exists.\nDo you wish to overwrite it?", url.path()), 
-                                                                   i18n("Warning"), KGuiItem(i18n("Overwrite")));
-                if (want_save == KMessageBox::Continue) {
+                if (QFile::exists(file)) {
+                    int want_save = KMessageBox::warningContinueCancel(this, i18n("The file %1 exists.\nDo you wish to overwrite it?", url.toLocalFile()), 
+                                                                       i18n("Warning"), KGuiItem(i18n("Overwrite")));
+                    if (want_save == KMessageBox::Continue) {
+                        cont = false;
+                    }
+                }
+                else {
                     cont = false;
                 }
-            }
-            else {
+            } else {
                 cont = false;
             }
         }
@@ -1857,14 +1839,8 @@
         preselectedExtension = i18n("*.h *.hh *.hpp *.hxx *.H|Header Files (*.h *.hh *.hpp *.hxx *.H)");
     }
     preselectedExtension.append("\n*|" + i18n("All Files"));
-#ifdef Q_WS_WIN
-    QStringList extList = preselectedExtension.split('|');
-    QStringList fileList = QFileDialog::getOpenFileNames(this, i18n("Select Code to Import"),    //krazy:exclude=qclasses
-                                "", extList[1] );
-#else
     QStringList fileList = KFileDialog::getOpenFileNames(KUrl(), preselectedExtension,
                            this, i18n("Select Code to Import") );
-#endif
     importFiles(&fileList);
 }
 
--- trunk/KDE/kdesdk/umbrello/umbrello/umldoc.cpp #952052:952053
@@ -349,7 +349,6 @@
     }
 
     m_doc_url = url;
-    QDir d = url.path(KUrl::AddTrailingSlash);
     closeDocument();
     // IMPORTANT: set m_bLoading to true
     // _AFTER_ the call of UMLDoc::closeDocument()
@@ -362,7 +361,7 @@
                             );
     QFile file( tmpfile );
     if ( !file.exists() ) {
-        KMessageBox::error(0, i18n("The file %1 does not exist.", d.path()), i18n("Load Error"));
+        KMessageBox::error(0, i18n("The file %1 does not exist.", url.pathOrUrl()), i18n("Load Error"));
         m_doc_url.setFileName(i18n("Untitled"));
         m_bLoading = false;
         newDocument();
@@ -387,7 +386,7 @@
         KTar archive(tmpfile, mimetype);
         if (archive.open(QIODevice::ReadOnly) == false)
         {
-            KMessageBox::error(0, i18n("The file %1 seems to be corrupted.", d.path()), i18n("Load Error"));
+            KMessageBox::error(0, i18n("The file %1 seems to be corrupted.", url.pathOrUrl()), i18n("Load Error"));
             m_doc_url.setFileName(i18n("Untitled"));
             m_bLoading = false;
             newDocument();
@@ -429,7 +428,7 @@
             entry = const_cast<KArchiveEntry*>(rootDir->entry(*it));
             if (entry == 0)
             {
-                KMessageBox::error(0, i18n("There was no XMI file found in the compressed file %1.", d.path()),
+                KMessageBox::error(0, i18n("There was no XMI file found in the compressed file %1.", url.pathOrUrl()),
                                    i18n("Load Error"));
                 m_doc_url.setFileName(i18n("Untitled"));
                 m_bLoading = false;
@@ -442,7 +441,7 @@
             fileEntry = dynamic_cast<KArchiveFile*>(entry);
             if (fileEntry == 0)
             {
-                KMessageBox::error(0, i18n("There was no XMI file found in the compressed file %1.", d.path()),
+                KMessageBox::error(0, i18n("There was no XMI file found in the compressed file %1.", url.pathOrUrl()),
                                    i18n("Load Error"));
                 m_doc_url.setFileName(i18n("Untitled"));
                 m_bLoading = false;
@@ -457,7 +456,7 @@
             QFile xmi_file(tmp_dir.name() + *it);
             if( !xmi_file.open( QIODevice::ReadOnly ) )
             {
-                KMessageBox::error(0, i18n("There was a problem loading the extracted file: %1", d.path()),
+                KMessageBox::error(0, i18n("There was a problem loading the extracted file: %1", url.pathOrUrl()),
                                    i18n("Load Error"));
                 m_doc_url.setFileName(i18n("Untitled"));
                 m_bLoading = false;
@@ -469,7 +468,7 @@
             // close the extracted file and the temporary directory
             xmi_file.close();
         } else {
-            KMessageBox::error(0, i18n("There was no XMI file found in the compressed file %1.", d.path()),
+            KMessageBox::error(0, i18n("There was no XMI file found in the compressed file %1.", url.pathOrUrl()),
                                i18n("Load Error"));
             m_doc_url.setFileName(i18n("Untitled"));
             m_bLoading = false;
@@ -482,7 +481,7 @@
     {
         // no, it seems to be an ordinary file
         if( !file.open( QIODevice::ReadOnly ) ) {
-            KMessageBox::error(0, i18n("There was a problem loading file: %1", d.path()),
+            KMessageBox::error(0, i18n("There was a problem loading file: %1", url.pathOrUrl()),
                                i18n("Load Error"));
             m_doc_url.setFileName(i18n("Untitled"));
             m_bLoading = false;
@@ -499,7 +498,7 @@
     KIO::NetAccess::removeTempFile( tmpfile );
     if( !status )
     {
-        KMessageBox::error(0, i18n("There was a problem loading file: %1", d.path()),
+        KMessageBox::error(0, i18n("There was a problem loading file: %1", url.pathOrUrl()),
                            i18n("Load Error"));
         m_bLoading = false;
         newDocument();
@@ -521,7 +520,6 @@
 {
     Q_UNUSED(format);
     m_doc_url = url;
-    QDir d = m_doc_url.path(KUrl::AddTrailingSlash);
     bool uploaded = true;
 
     // first, we have to find out which format to use
@@ -554,9 +552,9 @@
         {
             if (fileFormat == "tgz") // check tgz or bzip2
             {
-                archive = new KTar(d.path(), "application/x-gzip");
+                archive = new KTar(url.toLocalFile(), "application/x-gzip");
             } else {
-                archive = new KTar(d.path(), "application/x-bzip");
+                archive = new KTar(url.toLocalFile(), "application/x-bzip");
             }
         } else {
             if (fileFormat == "tgz") // check tgz or bzip2
@@ -570,7 +568,7 @@
         // now check if we can write to the file
         if (archive->open(QIODevice::WriteOnly) == false)
         {
-            KMessageBox::error(0, i18n("There was a problem saving file: %1", d.path()), i18n("Save Error"));
+            KMessageBox::error(0, i18n("There was a problem saving file: %1", url.pathOrUrl()), i18n("Save Error"));
             delete archive;
             return false;
         }
@@ -580,7 +578,7 @@
         KTemporaryFile tmp_xmi_file;
         tmp_xmi_file.setAutoRemove(false);
         if ( !tmp_xmi_file.open() ) {
-            KMessageBox::error(0, i18n("There was a problem saving file: %1", d.path()), i18n("Save Error"));
+            KMessageBox::error(0, i18n("There was a problem saving file: %1", url.pathOrUrl()), i18n("Save Error"));
             delete archive;
             return false;
         }
@@ -597,7 +595,7 @@
         archive->addLocalFile(tmp_xmi_file.fileName(), tmpQString);
 
         if (!archive->close()) {
-            KMessageBox::error(0, i18n("There was a problem saving file: %1", d.path()), i18n("Save Error"));
+            KMessageBox::error(0, i18n("There was a problem saving file: %1", url.pathOrUrl()), i18n("Save Error"));
             delete archive;
             return false;
         }
@@ -631,7 +629,7 @@
 
         // lets open the file for writing
         if( !tmpfile.open() ) {
-            KMessageBox::error(0, i18n("There was a problem saving file: %1", d.path()), i18n("Save Error"));
+            KMessageBox::error(0, i18n("There was a problem saving file: %1", url.pathOrUrl()), i18n("Save Error"));
             return false;
         }
         saveToXMI(tmpfile); // save the xmi stuff to it
@@ -643,27 +641,22 @@
                                              );
         }
         else {
+            // now remove the original file
 #ifdef Q_WS_WIN
-            // use Qt way of file copying until broken KIO::file_move() is fixed
-            QFile::remove(url.toLocalFile());
-            if ( !QFile::copy(tmpfile.fileName(),url.toLocalFile()) ) {
-                KMessageBox::error(0, i18n("There was a problem saving file: %1", url.toLocalFile()), i18n("Save Error"));
-                m_doc_url.setFileName(i18n("Untitled"));
-                return false;
-            }
+            tmpfile.setAutoRemove(true);
+            KIO::FileCopyJob* fcj = KIO::file_copy( tmpfile.fileName(), url, -1, KIO::Overwrite );
 #else
-            // now remove the original file
-            KIO::FileCopyJob* fcj = KIO::file_move( tmpfile.fileName(), d.path(), -1, KIO::Overwrite );
+            KIO::FileCopyJob* fcj = KIO::file_move( tmpfile.fileName(), url, -1, KIO::Overwrite );
+#endif
             if ( KIO::NetAccess::synchronousRun( fcj, (QWidget*)UMLApp::app() ) == false ) {
-                KMessageBox::error(0, i18n("There was a problem saving file: %1", d.path()), i18n("Save Error"));
+                KMessageBox::error(0, i18n("There was a problem saving file: %1", url.pathOrUrl()), i18n("Save Error"));
                 m_doc_url.setFileName(i18n("Untitled"));
                 return false;
             }
-#endif
         }
     }
     if( !uploaded ) {
-        KMessageBox::error(0, i18n("There was a problem uploading file: %1", d.path()), i18n("Save Error"));
+        KMessageBox::error(0, i18n("There was a problem uploading file: %1", url.pathOrUrl()), i18n("Save Error"));
         m_doc_url.setFileName(i18n("Untitled"));
     }
     setModified(false);




More information about the umbrello-devel mailing list