Index: programs/mythfrontend/playbackbox.cpp
===================================================================
--- programs/mythfrontend/playbackbox.cpp	(revision 8854)
+++ programs/mythfrontend/playbackbox.cpp	(working copy)
@@ -104,6 +104,62 @@
         return (dt1 > dt2 ? 1 : -1);
 }
 
+static PlaybackBox::ViewMask viewMaskToggle(PlaybackBox::ViewMask mask,
+        PlaybackBox::ViewMask toggle)
+{
+    // can only toggle a single bit at a time
+    if ((mask & toggle))
+        return (PlaybackBox::ViewMask)(mask & ~toggle);
+    return (PlaybackBox::ViewMask)(mask | toggle);
+}
+
+static QString sortTitle(QString title, PlaybackBox::ViewMask viewmask,
+        PlaybackBox::ViewTitleSort titleSort, int recpriority)
+{
+    if (title == "")
+        return title;
+
+    QRegExp prefixes = QObject::tr("^(The |A |An )");
+    QString sTitle = title;
+
+    sTitle.remove(prefixes);
+    if (viewmask == PlaybackBox::VIEW_TITLES &&
+            titleSort == PlaybackBox::TitleSortRecPriority)
+    {
+        // Also incorporate recpriority (reverse numeric sort). In
+        // case different episodes of a recording schedule somehow
+        // have different recpriority values (e.g., manual fiddling
+        // with database), the title will appear once for each
+        // distinct recpriority value among its episodes.
+        //
+        // Take advantage of QMap sorting. Positive recpriority values
+        // have a '+' prefix (sorts before '-'). Positive recpriority
+        // values are "inverted" by substracting them from 1000, so
+        // that high recpriorities are sorted first.
+        //
+        // For example (first column is sort key; second column is
+        // recpriority):
+        //
+        //      +905     95
+        //      +910     90
+        //      +911     89
+        //      +999      1
+        //      -000      0
+        //      -005     -5
+        //      -010    -10
+        //      -099    -99
+
+        QString sortprefix;
+        if (recpriority > 0)
+            sortprefix.sprintf("+%03u", 1000 - recpriority);
+        else
+            sortprefix.sprintf("-%03u", -recpriority);
+
+        sTitle = sortprefix + "-" + sTitle;
+    }
+    return sTitle;
+}
+
 PlaybackBox::PlaybackBox(BoxType ltype, MythMainWindow *parent, 
                          const char *name)
     : MythDialog(parent, name),
@@ -119,6 +175,7 @@
       groupDisplayName(tr("All Programs")),
       recGroup("All Programs"),
       recGroupPassword(""),             curGroupPassword(""),
+      viewMask(VIEW_TITLES),
       // Theme parsing
       theme(new XMLParse()),
       // Non-volatile drawing variables
@@ -180,7 +237,8 @@
         drawTransPixmap = new QPixmap();
 
     bool displayCat  = gContext->GetNumSetting("DisplayRecGroupIsCategory", 0);
-    int  defaultView = gContext->GetNumSetting("DisplayGroupDefaultView", 0);
+    ViewType defaultView = (ViewType)gContext->GetNumSetting(
+            "DisplayGroupDefaultView", TitlesOnly);
     int  initialFilt = gContext->GetNumSetting("QueryInitialFilter", 0);
 
     progLists[""];
@@ -343,26 +401,36 @@
     }
 }
 
-void PlaybackBox::setDefaultView(int defaultView)
+void PlaybackBox::setDefaultView(ViewType defaultView)
 {
+    int mask;
+
     switch (defaultView)
     {
         default:
-        case TitlesOnly: titleView = true; useCategories = false; 
-                         useRecGroups = false; break;
-        case TitlesCategories: titleView = true; useCategories = true; 
-                               useRecGroups = false; break;
-        case TitlesCategoriesRecGroups: titleView = true; useCategories = true;
-                                        useRecGroups = true; break;
-        case TitlesRecGroups: titleView = true; useCategories = false; 
-                              useRecGroups = true; break;
-        case Categories: titleView = false; useCategories = true; 
-                         useRecGroups = false; break;
-        case CategoriesRecGroups: titleView = false; useCategories = true; 
-                                  useRecGroups = true; break;
-        case RecGroups: titleView = false; useCategories = false; 
-                        useRecGroups = true; break;
+        case TitlesOnly:
+            mask = VIEW_TITLES;
+            break;
+        case TitlesCategories:
+            mask = VIEW_TITLES |    VIEW_CATEGORIES;
+            break;
+        case TitlesCategoriesRecGroups:
+            mask = VIEW_TITLES |    VIEW_CATEGORIES |   VIEW_RECGROUPS;
+            break;
+        case TitlesRecGroups:
+            mask = VIEW_TITLES |                        VIEW_RECGROUPS;
+            break;
+        case Categories:
+            mask =                  VIEW_CATEGORIES;
+            break;
+        case CategoriesRecGroups:
+            mask =                  VIEW_CATEGORIES |   VIEW_RECGROUPS;
+            break;
+        case RecGroups:
+            mask =                                      VIEW_RECGROUPS;
+            break;
     }
+    viewMask = (PlaybackBox::ViewMask)mask;
 }
 
 /* blocks until playing has stopped */
@@ -1139,7 +1207,7 @@
                     ((titleList[titleIndex] != tempInfo->title) &&
                      ((titleList[titleIndex] == tempInfo->recgroup) ||
                       (titleList[titleIndex] == tempInfo->category))) ||
-                    (!(titleView)))
+                    (!(viewMask & VIEW_TITLES)))
                     tempSubTitle = tempInfo->title; 
                 else
                     tempSubTitle = tempInfo->subtitle;
@@ -1150,7 +1218,7 @@
                         ((titleList[titleIndex] != tempInfo->title) &&
                          ((titleList[titleIndex] == tempInfo->recgroup) ||
                           (titleList[titleIndex] == tempInfo->category))) ||
-                        (!(titleView))))
+                        (!(viewMask & VIEW_TITLES))))
                 {
                     tempSubTitle = tempSubTitle + " - \"" + 
                         tempInfo->subtitle + "\"";
@@ -1361,6 +1429,7 @@
     QString oldprogramid;
     QDate oldoriginalAirDate;
     QDateTime oldstartts;
+    int oldrecpriority = 0;
     p = progLists[oldtitle].at(progIndex);
     if (p)
     {
@@ -1368,6 +1437,7 @@
         oldstartts = p->recstartts;
         oldprogramid = p->programid;
         oldoriginalAirDate = p->originalAirDate;
+        oldrecpriority = p->recpriority;
     }
 
     QMap<QString, AvailableStatusType> asCache;
@@ -1387,8 +1457,10 @@
 
     fillRecGroupPasswordCache();
 
+    ViewTitleSort titleSort = (ViewTitleSort)gContext->GetNumSetting(
+            "DisplayGroupTitleSort", TitleSortAlphabetical);
+
     QMap<QString, QString> sortedList;
-    QRegExp prefixes = tr("^(The |A |An )");
     QString sTitle = "";
 
     bool LiveTVInAllPrograms = gContext->GetNumSetting("LiveTVInAllPrograms",0);
@@ -1410,7 +1482,7 @@
                  (p->category == recGroup ) &&
                  ( !recGroupPwCache.contains(p->recgroup))))
             {
-                if ((titleView) || (useCategories) || (useRecGroups))
+                if (viewMask != VIEW_NONE)
                     progLists[""].prepend(p);
 
                 asKey = p->MakeUniqueKey();
@@ -1419,31 +1491,35 @@
                 else
                     p->availableStatus = asAvailable;
 
-                if (titleView) // Normal title view 
+                if ((viewMask & VIEW_TITLES)) // Show titles
                 {
                     progLists[p->title].prepend(p);
-                    sTitle = p->title;
-                    sTitle.remove(prefixes);
+                    sTitle = sortTitle(p->title, viewMask, titleSort,
+                            p->recpriority);
                     sTitle = sTitle.lower();
                     sortedList[sTitle] = p->title;
                 } 
 
-                if (useRecGroups && p->recgroup != "") // Show recording groups                 
+                if ((viewMask & VIEW_RECGROUPS) &&
+                    p->recgroup != "") // Show recording groups                 
                 { 
                     progLists[p->recgroup].prepend(p);
                     sortedList[p->recgroup.lower()] = p->recgroup;
 
-                    // If another view is also used, unset autodelete as another group will do it.
-                    if ((useCategories) || (titleView))
+                    // If another view is also used, unset autodelete as
+                    // another group will do it.
+                    if ((viewMask & ~VIEW_RECGROUPS))
                         progLists[p->recgroup].setAutoDelete(false);
                 }
 
-                if (useCategories && p->category != "") // Show categories
+                if ((viewMask & VIEW_CATEGORIES) &&
+                    p->category != "") // Show categories
                 {
                     progLists[p->category].prepend(p);
                     sortedList[p->category.lower()] = p->category;
-                    // If another view is also used, unset autodelete as another group will do it
-                    if ((useRecGroups) || (titleView)) 
+                    // If another view is also used, unset autodelete as
+                    // another group will do it
+                    if ((viewMask & ~VIEW_CATEGORIES))
                         progLists[p->category].setAutoDelete(false);
                 }
             }
@@ -1464,8 +1540,6 @@
         return 0;
     }
 
-    titleList = sortedList.values();
-
     QString episodeSort = gContext->GetSetting("PlayBoxEpisodeSort", "Date");
 
     if (episodeSort == "OrigAirDate")
@@ -1501,21 +1575,25 @@
     // titles backwards until we find where we were or go past.  This
     // is somewhat inefficient, but it works.
 
-    QString oldsTitle = oldtitle;
-    oldsTitle.remove(prefixes);
+    QStringList sTitleList = sortedList.keys();
+    titleList = sortedList.values();
+
+    QString oldsTitle = sortTitle(oldtitle, viewMask, titleSort,
+            oldrecpriority);
     oldsTitle = oldsTitle.lower();
     titleIndex = titleList.count() - 1;
-    for (int i = titleIndex; i >= 0; i--)
+    for (titleIndex = titleList.count() - 1; titleIndex >= 0; titleIndex--)
     {
-        sTitle = titleList[i];
-        sTitle.remove(prefixes);
+        sTitle = sTitleList[titleIndex];
         sTitle = sTitle.lower();
         
         if (oldsTitle > sTitle)
+        {
+            if (titleIndex + 1 < (int)titleList.count())
+                titleIndex++;
             break;
+        }
 
-        titleIndex = i;
-
         if (oldsTitle == sTitle)
             break;
     }
@@ -2252,7 +2330,7 @@
  
     if (inTitle)
     {
-        if (titleView)
+        if ((viewMask & VIEW_TITLES))
             popup->addButton(tr("Toggle playlist for this Category/Title"),
                              this, SLOT(togglePlayListTitle()));
         else 
@@ -3174,8 +3252,7 @@
     if (expectingPopup)
         cancelPopup();
 
-    if (titleView) titleView = false;
-    else titleView = true;
+    viewMask = viewMaskToggle(viewMask, VIEW_TITLES);
 
     playList.clear();
     connected = FillList();      
@@ -3424,8 +3501,7 @@
         }
         else if (action == "TOGGLERECORD")
         {
-            if (titleView) titleView = false;
-            else titleView = true;
+            viewMask = viewMaskToggle(viewMask, VIEW_TITLES);
             connected = FillList();
             paintSkipUpdate = false;
             update(drawTotalBounds);
@@ -3984,7 +4060,7 @@
     int result = recGroupPopup->ExecPopup();
 
     if (result == MythDialog::Accepted)
-        setDefaultView(recGroupComboBox->currentItem());
+        setDefaultView((ViewType)recGroupComboBox->currentItem());
 
     delete recGroupComboBox;
 
Index: programs/mythfrontend/globalsettings.cpp
===================================================================
--- programs/mythfrontend/globalsettings.cpp	(revision 8854)
+++ programs/mythfrontend/globalsettings.cpp	(working copy)
@@ -4,6 +4,7 @@
 #include "dbsettings.h"
 #include "langsettings.h"
 #include "mpeg/iso639.h"
+#include "playbackbox.h"
 #include "globalsettings.h"
 #include "recordingprofile.h"
 #include "scheduledrecording.h"
@@ -302,13 +303,21 @@
     HostComboBox *gc = new HostComboBox("DisplayGroupDefaultView");
     gc->setLabel(QObject::tr("Default View"));
 
-    gc->addSelection(QObject::tr("Show Titles only"), "0");
-    gc->addSelection(QObject::tr("Show Titles and Categories"), "1");
-    gc->addSelection(QObject::tr("Show Titles, Categories, and Recording Groups"), "2");
-    gc->addSelection(QObject::tr("Show Titles and Recording Groups"), "3");
-    gc->addSelection(QObject::tr("Show Categories only"), "4");
-    gc->addSelection(QObject::tr("Show Categories and Recording Groups"), "5");
-    gc->addSelection(QObject::tr("Show Recording Groups only"), "6");
+    gc->addSelection(QObject::tr("Show Titles only"),
+            QString::number(PlaybackBox::TitlesOnly));
+    gc->addSelection(QObject::tr("Show Titles and Categories"),
+            QString::number(PlaybackBox::TitlesCategories));
+    gc->addSelection(QObject::tr(
+                "Show Titles, Categories, and Recording Groups"),
+            QString::number(PlaybackBox::TitlesCategoriesRecGroups));
+    gc->addSelection(QObject::tr("Show Titles and Recording Groups"),
+            QString::number(PlaybackBox::TitlesRecGroups));
+    gc->addSelection(QObject::tr("Show Categories only"),
+            QString::number(PlaybackBox::Categories));
+    gc->addSelection(QObject::tr("Show Categories and Recording Groups"),
+            QString::number(PlaybackBox::CategoriesRecGroups));
+    gc->addSelection(QObject::tr("Show Recording Groups only"),
+            QString::number(PlaybackBox::RecGroups));
 
     gc->setHelpText(QObject::tr("Select what type of grouping to show on the Watch Recordings screen "
                     "by default."));
@@ -2269,6 +2280,35 @@
     return gc;
 }
 
+class DefaultViewSettings: public VerticalConfigurationGroup,
+                           public TriggeredConfigurationGroup {
+public:
+    DefaultViewSettings():
+            VerticalConfigurationGroup(false, false, true, true),
+            TriggeredConfigurationGroup(false) {
+
+        HostComboBox *defaultView = DefaultView();
+        addChild(defaultView);
+        setTrigger(defaultView);
+
+        HostComboBox *titleSort = new HostComboBox("DisplayGroupTitleSort");
+        titleSort->setLabel(tr("Sort Titles"));
+        titleSort->addSelection(tr("Alphabetically"),
+                QString::number(PlaybackBox::TitleSortAlphabetical));
+        titleSort->addSelection(tr("By Recording Priority"),
+                QString::number(PlaybackBox::TitleSortRecPriority));
+
+        for (unsigned int ii = 0; ii < PlaybackBox::ViewTypes; ii++)
+        {
+            if (ii == PlaybackBox::TitlesOnly)
+                addTarget(QString::number(ii), titleSort);
+            else
+                addTarget(QString::number(ii),
+                        new VerticalConfigurationGroup(false, false));
+        }
+    }
+};
+
 static HostCheckBox *PVR350OutputEnable()
 {
     HostCheckBox *gc = new HostCheckBox("PVR350OutputEnable");
@@ -3085,7 +3125,7 @@
     pbox2->addChild(RememberRecGroup());
     pbox2->addChild(UseGroupNameAsAllPrograms());
     pbox2->addChild(LiveTVInAllPrograms());
-    pbox2->addChild(DefaultView());
+    pbox2->addChild(new DefaultViewSettings());
     addChild(pbox2);
 
     addChild(new HwDecSettings());
@@ -3310,3 +3350,4 @@
     addChild(xboxset);
 }
 
+// vim:set sw=4 ts=4 expandtab:
Index: programs/mythfrontend/playbackbox.h
===================================================================
--- programs/mythfrontend/playbackbox.h	(revision 8854)
+++ programs/mythfrontend/playbackbox.h	(working copy)
@@ -1,4 +1,5 @@
 // -*- Mode: c++ -*-
+// vim:set sw=4 ts=4 expandtab:
 #ifndef PLAYBACKBOX_H_
 #define PLAYBACKBOX_H_
 
@@ -41,17 +42,33 @@
         Delete,
     } BoxType;
 
-    typedef enum
-    {
-        TitlesOnly,
-        TitlesCategories,
-        TitlesCategoriesRecGroups,
-        TitlesRecGroups,
-        Categories,
-        CategoriesRecGroups,
-        RecGroups,
+    // ViewType values cannot change; they are stored in the database.
+    typedef enum {
+        TitlesOnly = 0,
+        TitlesCategories = 1,
+        TitlesCategoriesRecGroups = 2,
+        TitlesRecGroups = 3,
+        Categories = 4,
+        CategoriesRecGroups = 5,
+        RecGroups = 6,
+        ViewTypes,                  // placeholder value, not in database
     } ViewType;
 
+    // Sort function when TitlesOnly. Values are stored in database.
+    typedef enum {
+        TitleSortAlphabetical = 0,
+        TitleSortRecPriority = 1,
+        TitleSortMethods,           // placeholder value, not in database
+    } ViewTitleSort;
+
+    typedef enum {
+        VIEW_NONE       =  0x00,
+        VIEW_TITLES     =  0x01,
+        VIEW_CATEGORIES =  0x02,
+        VIEW_RECGROUPS  =  0x04,
+        VIEW_ALL        = ~0x00,
+    } ViewMask;
+
     typedef enum
     {
         EndOfRecording,
@@ -260,7 +277,7 @@
     void updateCurGroup(QPainter *p);
     void updateGroupInfo(QPainter *p, QRect& pr, QPixmap& pix,
                          QString cont_name = "group_info");
-    void setDefaultView(int defaultView);
+    void setDefaultView(ViewType defaultView);
 
     // Settings ///////////////////////////////////////////////////////////////
     /// If "Play"  this is a recording playback selection UI,
@@ -292,6 +309,7 @@
     QString             recGroup;
     QString             recGroupPassword;
     QString             curGroupPassword;
+    ViewMask            viewMask;
 
     // Theme parsing variables
     XMLParse           *theme;
Index: programs/mythbackend/mainserver.cpp
===================================================================
--- programs/mythbackend/mainserver.cpp	(revision 8854)
+++ programs/mythbackend/mainserver.cpp	(working copy)
@@ -958,7 +958,7 @@
                        "recorded.lastmodified, recorded.findid, "
                        "recorded.originalairdate, recorded.playgroup, "
                        "recorded.basename, recorded.progstart, "
-                       "recorded.progend, recorded.stars "
+                       "recorded.progend, recorded.stars, recorded.recpriority "
                        "FROM recorded "
                        "LEFT JOIN record ON recorded.recordid = record.recordid "
                        "LEFT JOIN channel ON recorded.chanid = channel.chanid "
@@ -1070,6 +1070,8 @@
             proginfo->recgroup = query.value(16).toString();
             proginfo->playgroup = query.value(27).toString();
 
+            proginfo->recpriority = query.value(32).toInt();
+
             proginfo->recstatus = rsRecorded;
             if (proginfo->recendts > rectime)
             {
