[Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders

Simon Schampijer simon at schampijer.de
Tue Sep 6 14:14:47 EDT 2011


Currently the message will be the same for an empty Journal
or an empty external device or an empty documents folder. This
patch does distinguish between the different cases. In order to
get the path of the documents folder as well from the listview
the function has been moved to the model.

@design team: because I could not figure out an easy way to get
the volume's label in the listview I did change the text for an
empty device to: 'The device is empty'

This patch depends on the previous patch: "Only show DOCUMENTS
folder when it is not $HOME"

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 src/jarabe/journal/listview.py       |   16 ++++++++++++++--
 src/jarabe/journal/model.py          |   23 +++++++++++++++++++++++
 src/jarabe/journal/volumestoolbar.py |   26 +-------------------------
 3 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index a9f5a53..c642617 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -38,7 +38,9 @@ from jarabe.journal import misc
 UPDATE_INTERVAL = 300
 
 MESSAGE_EMPTY_JOURNAL = 0
-MESSAGE_NO_MATCH = 1
+MESSAGE_EMPTY_DOCUMENTS_FOLDER = 1
+MESSAGE_EMPTY_DEVICE = 2
+MESSAGE_NO_MATCH = 3
 
 
 class TreeView(gtk.TreeView):
@@ -315,7 +317,13 @@ class BaseListView(gtk.Bin):
 
         if len(tree_model) == 0:
             if self._is_query_empty():
-                self._show_message(MESSAGE_EMPTY_JOURNAL)
+                if self._query['mountpoints'] == ['/']:
+                    self._show_message(MESSAGE_EMPTY_JOURNAL)
+                elif self._query['mountpoints'] == \
+                        [model.get_documents_path()]:
+                    self._show_message(MESSAGE_EMPTY_DOCUMENTS_FOLDER)
+                else:
+                    self._show_message(MESSAGE_EMPTY_DEVICE)
             else:
                 self._show_message(MESSAGE_NO_MATCH)
         else:
@@ -385,6 +393,10 @@ class BaseListView(gtk.Bin):
 
         if message == MESSAGE_EMPTY_JOURNAL:
             text = _('Your Journal is empty')
+        elif message == MESSAGE_EMPTY_DOCUMENTS_FOLDER:
+            text = _('Your documents folder is empty')
+        elif message == MESSAGE_EMPTY_DEVICE:
+            text = _('The device is empty')
         elif message == MESSAGE_NO_MATCH:
             text = _('No matching entries')
         else:
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 1242787..c57dfc4 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -17,6 +17,7 @@
 import logging
 import os
 import errno
+import subprocess
 from datetime import datetime
 import time
 import shutil
@@ -794,3 +795,25 @@ def is_editable(metadata):
         return True
     else:
         return os.access(metadata['mountpoint'], os.W_OK)
+
+
+def get_documents_path():
+    """Gets the path of the DOCUMENTS folder
+
+    If xdg-user-dir can not find the DOCUMENTS folder it will
+    return the user directory instead. It also handles
+    localization (i.e. translation) of the filenames.
+
+    Returns: Path to $HOME/DOCUMENTS or None if an error occurs
+    """
+    try:
+        pipe = subprocess.Popen(['xdg-user-dir', 'DOCUMENTS'],
+                                stdout=subprocess.PIPE)
+        documents_path = os.path.normpath(pipe.communicate()[0].strip())
+        if os.path.exists(documents_path) and \
+                os.environ.get('HOME') != documents_path:
+            return documents_path
+    except OSError, exception:
+        if exception.errno != errno.ENOENT:
+            logging.exception('Could not run xdg-user-dir')
+    return None
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 1cc764f..77bb955 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -16,8 +16,6 @@
 
 import logging
 import os
-import subprocess
-import errno
 import statvfs
 from gettext import gettext as _
 
@@ -55,28 +53,6 @@ def _get_id(document):
         return None
 
 
-def _get_documents_path():
-    """Gets the path of the DOCUMENTS folder
-
-    If xdg-user-dir can not find the DOCUMENTS folder it will
-    return the user directory instead. It also handles
-    localization (i.e. translation) of the filenames.
-
-    Returns: Path to $HOME/DOCUMENTS or None if an error occurs
-    """
-    try:
-        pipe = subprocess.Popen(['xdg-user-dir', 'DOCUMENTS'],
-                                stdout=subprocess.PIPE)
-        documents_path = os.path.normpath(pipe.communicate()[0].strip())
-        if os.path.exists(documents_path) and \
-                os.environ.get('HOME') != documents_path:
-            return documents_path
-    except OSError, exception:
-        if exception.errno != errno.ENOENT:
-            logging.exception('Could not run xdg-user-dir')
-    return None
-
-
 def _convert_entries(root):
     """Convert entries written by the datastore version 0.
 
@@ -225,7 +201,7 @@ class VolumesToolbar(gtk.Toolbar):
             self._add_button(mount)
 
     def _set_up_documents_button(self):
-        documents_path = _get_documents_path()
+        documents_path = model.get_documents_path()
         if documents_path is not None:
             button = DocumentsButton(documents_path)
             button.props.group = self._volume_buttons[0]
-- 
1.7.4.4



More information about the Sugar-devel mailing list