]> git.sur5r.net Git - minitube/blobdiff - src/global.h
Imported Upstream version 2.4
[minitube] / src / global.h
index 2285b17351f491ecca9bad2d3850445ce34df5b3..e54b5d5e3e784735be6690b4ee08094d83a1509d 100644 (file)
@@ -1,30 +1,48 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #ifndef GLOBAL_H
 #define GLOBAL_H
 
 #include <QtGui>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#endif
 #include <QStringList>
 #include <QNetworkProxy>
 #include <QNetworkAccessManager>
 #include <QNetworkProxyFactory>
 #include <cstdlib>
 #include "networkaccess.h"
+#include "diskcache.h"
 
 namespace The {
 
-    static QMap<QString, QAction*> *g_actions = 0;
-
-    QMap<QString, QAction*>* globalActions() {
-        if (!g_actions)
-            g_actions = new QMap<QString, QAction*>;
-        return g_actions;
+    QHash<QString, QAction*>* globalActions() {
+        static QHash<QString, QAction*> *actions = new QHash<QString, QAction*>;
+        return actions;
     }
 
-    static QMap<QString, QMenu*> *g_menus = 0;
-
-    QMap<QString, QMenu*>* globalMenus() {
-        if (!g_menus)
-            g_menus = new QMap<QString, QMenu*>;
-        return g_menus;
+    QHash<QString, QMenu*>* globalMenus() {
+        static QHash<QString, QMenu*> *menus = new QHash<QString, QMenu*>;
+        return menus;
     }
 
     void maybeSetSystemProxy() {
@@ -123,24 +141,27 @@ namespace The {
         }
     }
 
-    static QNetworkAccessManager *nam = 0;
-
     QNetworkAccessManager* networkAccessManager() {
+        static QNetworkAccessManager *nam = 0;
         if (!nam) {
             networkHttpProxySetting();
             maybeSetSystemProxy();
             nam = new QNetworkAccessManager();
+            QNetworkDiskCache *cache = new DiskCache();
+#if QT_VERSION >= 0x050000
+            QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/qt5";
+#else
+            QString cacheLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
+#endif
+            cache->setCacheDirectory(cacheLocation);
+            nam->setCache(cache);
         }
         return nam;
     }
 
-    static NetworkAccess *g_http = 0;
     NetworkAccess* http() {
-        if (!g_http) {
-            // qDebug() << "Creating NetworkAccess";
-            g_http = new NetworkAccess();
-        }
-        return g_http;
+        static NetworkAccess *na = new NetworkAccess();
+        return na;
     }
 
 }