From ca242b74df2767a0374dbdbefd436fdd427e8e47 Mon Sep 17 00:00:00 2001
From: astaric <anze.staric@gmail.com>
Date: Tue, 12 Nov 2013 14:38:58 +0100
Subject: [PATCH 7/7] Store all orange settings in one folder.

---
 Orange/canvas/config.py        |  4 +++
 Orange/canvas/utils/environ.py | 55 ++++++++++--------------------------------
 2 files changed, 17 insertions(+), 42 deletions(-)

diff --git a/Orange/canvas/config.py b/Orange/canvas/config.py
index df43de2..4075194 100644
--- a/Orange/canvas/config.py
+++ b/Orange/canvas/config.py
@@ -151,9 +151,11 @@ def data_dir():
     does not yet exists then create it.
 
     """
+    import Orange
     init()
     datadir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
     datadir = str(datadir)
+    datadir = os.path.join(datadir, Orange.__version__)
     if not os.path.exists(datadir):
         os.makedirs(datadir)
     return datadir
@@ -164,9 +166,11 @@ def cache_dir():
     does not yet exists then create it.
 
     """
+    import Orange
     init()
     cachedir = QDesktopServices.storageLocation(QDesktopServices.CacheLocation)
     cachedir = str(cachedir)
+    cachedir = os.path.join(cachedir, Orange.__version__)
     if not os.path.exists(cachedir):
         os.makedirs(cachedir)
     return cachedir
diff --git a/Orange/canvas/utils/environ.py b/Orange/canvas/utils/environ.py
index 69812db..adc43a9 100644
--- a/Orange/canvas/utils/environ.py
+++ b/Orange/canvas/utils/environ.py
@@ -77,9 +77,6 @@ The following variables are exposed as top level module members
 `orange_settings_dir`:
     Directory where Orange settings are saved.
 
-`canvas_settings_dir`:
-    Directory where Orange Canvas settings are saved.
-
 `widget_settings_dir`:
     Directory where Orange Widgets settings are saved.
 
@@ -91,36 +88,21 @@ The following variables are exposed as top level module members
 
 """
 
+
+from .. import config
 import os, sys
 import configparser
 import pkg_resources
 from pkg_resources import working_set
-from functools import cmp_to_key
 
-def _path_fix():
-    """ Fix some common problems with $(PATH) and sys.path
-    """
-    if os.name == "nt":
-        ## Move any miktex paths containing Qt's dll to the end of the %PATH%
-        paths = os.environ["PATH"].split(";")
-        paths.sort(key = cmp_to_key(lambda x,y: -1 if "PyQt4" in x else (1 if "miktex" in y and\
-                                                              os.path.exists(os.path.join(y, "QtCore4.dll")) else 0)))
-        os.environ["PATH"] = ";".join(paths)
-
-    if sys.platform == "darwin":
-        ## PyQt4 installed from fink is installed in %{FINK_ROOT}lib/qt4-mac/lib/python${PYVERSION}/site-packages"
-        posible_fink_pyqt4_path = os.path.join(sys.prefix,
-                                               "lib/qt4-mac/lib/python" + sys.version[:3] + "/site-packages")
-        if os.path.exists(posible_fink_pyqt4_path):
-            sys.path.append(posible_fink_pyqt4_path)
-
-_path_fix()
+import Orange
+
 
 def _get_default_env():
     """ Return a dictionary with default Orange environment."""
 
-    version = "orange"
-    version_display = "Orange 2.6"
+    version = Orange.__version__
+    version_display = "Orange %s" % version
     orange_no_deprecated_members = "False"
 
     install_dir = os.path.dirname(os.path.abspath(__file__)) # Orange/canvas/utils
@@ -137,20 +119,14 @@ def _get_default_env():
 
     home = os.path.expanduser("~/")
 
+    application_dir = config.data_dir()
+    output_dir = application_dir
+
     if sys.platform == "win32":
         if home[-1] == ":":
             home += "\\"
-        application_dir = os.environ["APPDATA"]
-        output_dir = os.path.join(application_dir, version)
         default_reports_dir = os.path.join(home, "My Documents")
-    elif sys.platform == "darwin":
-        application_dir = os.path.join(home, "Library", "Application Support")
-        output_dir = os.path.join(application_dir, version)
-        default_reports_dir = os.path.join(home, "Documents")
     else:
-        application_dir = home
-        output_dir = os.path.join(home, "." + version)
-
         documents = os.path.join(home, "Documents")
         # Need to make sure Documents folder actually exists
         if os.path.exists(documents) and os.path.isdir(documents):
@@ -161,13 +137,9 @@ def _get_default_env():
     add_ons_dir_user = os.path.join(output_dir, "add-ons")
 
     orange_settings_dir = output_dir
-    canvas_settings_dir = os.path.join(output_dir, "OrangeCanvasQt4")
-    widget_settings_dir = os.path.join(output_dir, "widgetSettingsOrange3")
+    widget_settings_dir = os.path.join(output_dir, "widgets")
 
-    if sys.platform == "darwin":
-        buffer_dir = os.path.join(home, "Library", "Caches", version)
-    else:
-        buffer_dir = os.path.join(output_dir, "buffer")
+    buffer_dir = config.cache_dir()
 
     return locals()
 
@@ -179,7 +151,7 @@ _ALL_DIR_OPTIONS = ["install_dir", "canvas_install_dir",
                     "doc_install_dir", "dataset_install_dir",
                     "add_ons_dir", "add_ons_dir_user",
                     "application_dir", "output_dir", "default_reports_dir",
-                    "orange_settings_dir", "canvas_settings_dir",
+                    "orange_settings_dir",
                     "widget_settings_dir", "buffer_dir"]
 
 def get_platform_option(section, option):
@@ -239,7 +211,6 @@ if not os.path.isdir(widget_install_dir) or not os.path.isdir(widget_install_dir
     # Canvas and widgets are not installed
     canvas_install_dir = None
     widget_install_dir = None
-    canvas_settings_dir = None
     widget_settings_dir = None
     is_canvas_installed = False
 else:
@@ -257,7 +228,7 @@ version = get_platform_option("Orange", "version")
 # TODO: This are not needed if using orange without the GUI
 
 _directories_to_create = ["application_dir", "orange_settings_dir",
-                          "buffer_dir", "widget_settings_dir", "canvas_settings_dir"]
+                          "buffer_dir", "widget_settings_dir"]
 
 for dname in _directories_to_create:
     dname = globals()[dname]
-- 
1.8.4.3

