]> git.sur5r.net Git - minitube/commitdiff
Moved filename chars function to DataUtils
authorFlavio Tordini <flavio.tordini@gmail.com>
Sun, 21 Sep 2014 16:43:50 +0000 (18:43 +0200)
committerFlavio <flavio.tordini@gmail.com>
Sun, 21 Sep 2014 16:43:50 +0000 (18:43 +0200)
src/datautils.cpp [new file with mode: 0644]
src/datautils.h [new file with mode: 0644]
src/downloadmanager.cpp
src/downloadsettings.cpp

diff --git a/src/datautils.cpp b/src/datautils.cpp
new file mode 100644 (file)
index 0000000..3490448
--- /dev/null
@@ -0,0 +1,22 @@
+#include "datautils.h"
+
+QString DataUtils::stringToFilename(const QString &s) {
+    QString f = s;
+    f.replace('(', '[');
+    f.replace(')', ']');
+    f.replace('/', ' ');
+    f.replace('\\', ' ');
+    f.replace('<', ' ');
+    f.replace('>', ' ');
+    f.replace(':', ' ');
+    f.replace('"', ' ');
+    f.replace('|', ' ');
+    f.replace('?', ' ');
+    f.replace('*', ' ');
+    f = f.simplified();
+
+    if (!f.isEmpty() && f.at(0) == '.')
+        f = f.mid(1).trimmed();
+
+    return f;
+}
diff --git a/src/datautils.h b/src/datautils.h
new file mode 100644 (file)
index 0000000..eb0a3c0
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef DATAUTILS_H
+#define DATAUTILS_H
+
+#include <QtCore>
+
+class DataUtils {
+
+public:
+    static QString stringToFilename(const QString &s);
+
+private:
+    DataUtils() { }
+
+};
+
+#endif // DATAUTILS_H
index c42b0746c7029ed1ccbd2ce0249dbb09985a349c..340b8d6a9a159e48b2d2edbf86b8aa716f776ddf 100644 (file)
@@ -30,6 +30,7 @@ $END_LICENSE */
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
+#include "datautils.h"
 
 static DownloadManager *downloadManagerInstance = 0;
 
@@ -123,23 +124,7 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 
     video->disconnect(this);
 
-    QString basename = video->title();
-    basename.replace('(', '[');
-    basename.replace(')', ']');
-    basename.replace('/', ' ');
-    basename.replace('\\', ' ');
-    basename.replace('<', ' ');
-    basename.replace('>', ' ');
-    basename.replace(':', ' ');
-    basename.replace('"', ' ');
-    basename.replace('|', ' ');
-    basename.replace('?', ' ');
-    basename.replace('*', ' ');
-    basename = basename.simplified();
-
-    if (!basename.isEmpty() && basename.at(0) == '.')
-        basename = basename.mid(1).trimmed();
-
+    QString basename = DataUtils::stringToFilename(video->title());
     if (basename.isEmpty()) basename = video->id();
 
     QString filename = currentDownloadFolder() + "/" + basename + ".mp4";
index 333f8e196b093be78e756ee04c034371a561d669..f04a3f215b8663f39253ef78e49581fa9f42578d 100644 (file)
@@ -56,12 +56,11 @@ void DownloadSettings::paintEvent(QPaintEvent * /*event*/) {
 }
 
 void DownloadSettings::changeFolder() {
-
+    QString path;
 #ifdef APP_MAC
     QFileDialog* dialog = new QFileDialog(this);
     dialog->setFileMode(QFileDialog::Directory);
     dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
-    QString path;
 #if QT_VERSION >= 0x050000
     path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
 #else
@@ -70,8 +69,14 @@ void DownloadSettings::changeFolder() {
     dialog->setDirectory(path);
     dialog->open(this, SLOT(folderChosen(const QString &)));
 #else
+
+#if QT_VERSION >= 0x050000
+    path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+#else
+    path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
+#endif
     QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"),
-                                                       QDesktopServices::storageLocation(QDesktopServices::HomeLocation),
+                                                       path,
                                                        QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
     folderChosen(folder);
 #endif