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

Simon Schampijer simon at schampijer.de
Wed Sep 7 02:05:27 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       |   27 ++++++++++++---------------
 src/jarabe/journal/model.py          |   23 +++++++++++++++++++++++
 src/jarabe/journal/volumestoolbar.py |   26 +-------------------------
 3 files changed, 36 insertions(+), 40 deletions(-)

diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index a9f5a53..0d7e112 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -37,9 +37,6 @@ from jarabe.journal import misc
 
 UPDATE_INTERVAL = 300
 
-MESSAGE_EMPTY_JOURNAL = 0
-MESSAGE_NO_MATCH = 1
-
 
 class TreeView(gtk.TreeView):
     __gtype_name__ = 'JournalTreeView'
@@ -315,9 +312,16 @@ 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(_('Your Journal is empty'))
+                elif self._query['mountpoints'] == \
+                        [model.get_documents_path()]:
+                    self._show_message(_('Your documents folder is empty'))
+                else:
+                    self._show_message(_('The device is empty'))
             else:
-                self._show_message(MESSAGE_NO_MATCH)
+                self._show_message(_('No matching entries'),
+                                   show_clear_query=True)
         else:
             self._clear_message()
 
@@ -364,7 +368,7 @@ class BaseListView(gtk.Bin):
         self.add(self._scrolled_window)
         self._progress_bar = None
 
-    def _show_message(self, message):
+    def _show_message(self, message, show_clear_query=False):
         canvas = hippo.Canvas()
         self.remove(self.child)
         self.add(canvas)
@@ -383,20 +387,13 @@ class BaseListView(gtk.Bin):
                           fill_color=style.COLOR_TRANSPARENT.get_svg())
         box.append(icon)
 
-        if message == MESSAGE_EMPTY_JOURNAL:
-            text = _('Your Journal is empty')
-        elif message == MESSAGE_NO_MATCH:
-            text = _('No matching entries')
-        else:
-            raise ValueError('Invalid message')
-
-        text = hippo.CanvasText(text=text,
+        text = hippo.CanvasText(text=message,
                 xalign=hippo.ALIGNMENT_CENTER,
                 font_desc=style.FONT_BOLD.get_pango_desc(),
                 color=style.COLOR_BUTTON_GREY.get_int())
         box.append(text)
 
-        if message == MESSAGE_NO_MATCH:
+        if show_clear_query:
             button = gtk.Button(label=_('Clear search'))
             button.connect('clicked', self.__clear_button_clicked_cb)
             button.props.image = Icon(icon_name='dialog-cancel',
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