Skip to content
This repository
Browse code

Add GUI support for configuring the autologin profile in profiles.xml

  • Loading branch information...
commit eab6f80c1e73979124f631d4abcb7938ca489b5c 1 parent 17411f2
leechguy authored April 08, 2013
5  language/English/strings.po
@@ -11887,3 +11887,8 @@ msgstr ""
11887 11887
 msgctxt "#37013"
11888 11888
 msgid "(Directors Comments)"
11889 11889
 msgstr ""
  11890
+
  11891
+#: xbmc/GUIInfoManager.cpp
  11892
+msgctxt "#37014"
  11893
+msgid "Most recent"
  11894
+msgstr ""
13  xbmc/GUIInfoManager.cpp
@@ -268,6 +268,7 @@ const infomap system_labels[] =  {{ "hasnetwork",       SYSTEM_ETHERNET_LINK_ACT
268 268
                                   { "profilename",      SYSTEM_PROFILENAME },
269 269
                                   { "profilethumb",     SYSTEM_PROFILETHUMB },
270 270
                                   { "profilecount",     SYSTEM_PROFILECOUNT },
  271
+                                  { "profileautologin", SYSTEM_PROFILEAUTOLOGIN },
271 272
                                   { "progressbar",      SYSTEM_PROGRESS_BAR },
272 273
                                   { "batterylevel",     SYSTEM_BATTERY_LEVEL },
273 274
                                   { "friendlyname",     SYSTEM_FRIENDLY_NAME },
@@ -1751,6 +1752,18 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow, CStdString *fa
1751 1752
   case SYSTEM_PROFILECOUNT:
1752 1753
     strLabel.Format("%i", CProfilesManager::Get().GetNumberOfProfiles());
1753 1754
     break;
  1755
+  case SYSTEM_PROFILEAUTOLOGIN:
  1756
+    {
  1757
+      int profileId = CProfilesManager::Get().GetAutoLoginProfileId();
  1758
+      if (profileId == -1)
  1759
+        strLabel = g_localizeStrings.Get(37014); // Most recent
  1760
+      else
  1761
+      {
  1762
+        const CProfile *profile = CProfilesManager::Get().GetProfile(profileId);
  1763
+        strLabel = profile->getName();
  1764
+      }
  1765
+    }
  1766
+    break;
1754 1767
   case SYSTEM_LANGUAGE:
1755 1768
     strLabel = g_guiSettings.GetString("locale.language");
1756 1769
     break;
2  xbmc/GUIInfoManager.h
@@ -418,6 +418,8 @@ namespace INFO
418 418
 #define FANART_COLOR3               1002
419 419
 #define FANART_IMAGE                1003
420 420
 
  421
+#define SYSTEM_PROFILEAUTOLOGIN     1004
  422
+
421 423
 #define PVR_CONDITIONS_START        1100
422 424
 #define PVR_IS_RECORDING            (PVR_CONDITIONS_START)
423 425
 #define PVR_HAS_TIMER               (PVR_CONDITIONS_START + 1)
14  xbmc/profiles/ProfilesManager.h
@@ -142,6 +142,20 @@ class CProfilesManager : public ISettingsHandler
142 142
 
143 143
   int GetCurrentProfileId() const { return GetCurrentProfile().getId(); }
144 144
 
  145
+  /*! \brief Retrieve the autologin profile id
  146
+    Retrieves the autologin profile id. When set to -1, then the last
  147
+    used profile will be loaded
  148
+    \return the id to the autologin profile
  149
+    */
  150
+  int GetAutoLoginProfileId() const { return m_autoLoginProfile; }
  151
+
  152
+  /*! \brief Retrieve the autologin profile id
  153
+    Retrieves the autologin profile id. When set to -1, then the last
  154
+    used profile will be loaded
  155
+    \return the id to the autologin profile
  156
+    */
  157
+  void SetAutoLoginProfileId(const int profileId) { m_autoLoginProfile = profileId; }
  158
+
145 159
   std::string GetUserDataFolder() const;
146 160
   std::string GetProfileUserDataFolder() const;
147 161
   std::string GetDatabaseFolder() const;
54  xbmc/profiles/windows/GUIWindowSettingsProfile.cpp
@@ -24,6 +24,7 @@
24 24
 #include "profiles/ProfilesManager.h"
25 25
 #include "Application.h"
26 26
 #include "dialogs/GUIDialogContextMenu.h"
  27
+#include "dialogs/GUIDialogSelect.h"
27 28
 #include "profiles/dialogs/GUIDialogProfileSettings.h"
28 29
 #include "network/Network.h"
29 30
 #include "utils/URIUtils.h"
@@ -41,6 +42,7 @@ using namespace XFILE;
41 42
 #define CONTROL_PROFILES 2
42 43
 #define CONTROL_LASTLOADED_PROFILE 3
43 44
 #define CONTROL_LOGINSCREEN 4
  45
+#define CONTROL_AUTOLOGIN 5
44 46
 
45 47
 CGUIWindowSettingsProfile::CGUIWindowSettingsProfile(void)
46 48
     : CGUIWindow(WINDOW_SETTINGS_PROFILES, "SettingsProfile.xml")
@@ -168,6 +170,17 @@ bool CGUIWindowSettingsProfile::OnMessage(CGUIMessage& message)
168 170
         CProfilesManager::Get().Save();
169 171
         return true;
170 172
       }
  173
+      else if (iControl == CONTROL_AUTOLOGIN)
  174
+      {
  175
+    	int currentId = CProfilesManager::Get().GetAutoLoginProfileId();
  176
+        int profileId;
  177
+        if (GetAutoLoginProfileChoice(profileId) && (currentId != profileId))
  178
+        {
  179
+          CProfilesManager::Get().SetAutoLoginProfileId(profileId);
  180
+          CProfilesManager::Get().Save();
  181
+        }
  182
+        return true;
  183
+      }
171 184
     }
172 185
     break;
173 186
   }
@@ -219,3 +232,44 @@ void CGUIWindowSettingsProfile::OnInitWindow()
219 232
   CGUIWindow::OnInitWindow();
220 233
 }
221 234
 
  235
+bool CGUIWindowSettingsProfile::GetAutoLoginProfileChoice(int &iProfile)
  236
+{
  237
+  CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  238
+  if (!dialog) return false;
  239
+
  240
+  // add items
  241
+  // "Most recent" option comes first, so up indices by 1
  242
+  int autoLoginProfileId = CProfilesManager::Get().GetAutoLoginProfileId() + 1;
  243
+  CFileItemList items;
  244
+  CFileItemPtr item(new CFileItem());
  245
+  item->SetLabel(g_localizeStrings.Get(37014)); // Most recent
  246
+  item->SetIconImage("unknown-user.png");
  247
+  items.Add(item);
  248
+
  249
+  for (unsigned int i = 0; i < CProfilesManager::Get().GetNumberOfProfiles(); i++)
  250
+  {
  251
+    const CProfile *profile = CProfilesManager::Get().GetProfile(i);
  252
+    CStdString locked = g_localizeStrings.Get(profile->getLockMode() > 0 ? 20166 : 20165);
  253
+    CFileItemPtr item(new CFileItem(profile->getName()));
  254
+    item->SetProperty("Addon.Summary", locked); // lock setting
  255
+    CStdString thumb = profile->getThumb();
  256
+    if (thumb.IsEmpty())
  257
+      thumb = "unknown-user.png";
  258
+    item->SetIconImage(thumb);
  259
+    items.Add(item);
  260
+  }
  261
+
  262
+  dialog->SetHeading(20093); // Profile name
  263
+  dialog->Reset();
  264
+  dialog->SetUseDetails(true);
  265
+  dialog->EnableButton(true, 222); // Cancel
  266
+  dialog->SetItems(&items);
  267
+  dialog->SetSelected(autoLoginProfileId);
  268
+  dialog->DoModal();
  269
+
  270
+  if (dialog->IsButtonPressed() || dialog->GetSelectedLabel() < 0)
  271
+    return false; // user cancelled
  272
+  iProfile = dialog->GetSelectedLabel() - 1;
  273
+
  274
+  return true;
  275
+}
1  xbmc/profiles/windows/GUIWindowSettingsProfile.h
@@ -41,4 +41,5 @@ class CGUIWindowSettingsProfile :
41 41
   void LoadList();
42 42
   void SetLastLoaded();
43 43
   void ClearListItems();
  44
+  bool GetAutoLoginProfileChoice(int &iProfile);
44 45
 };

0 notes on commit eab6f80

jmarshallnz

Can you guarantee this pointer?

jmarshallnz

hack, hack. Why is this information useful to the user?

jmarshallnz

This seems a little bit clunky to me UI-wise. You have a list of profiles already anyway on the screen, yet you pop up a dialog with the exact same list (with the "recent" item appended) to choose one.

Perhaps it can be done without the repetition?

leechguy

Good catch. When deleting the configured auto login profile this returns NULL and XBMC is no more.
I will add a check when deleting the profile and set m_autoLoginProfile to -1 when auto login profile is deleted.
I will also add a check in GetAutoLoginProfileId() and have it return -1 in case the m_autoLoginProfile is no longer valid.

jmarshallnz

It makes sense to just check the profile pointer returned to be sure, to be sure.

leechguy

Don't kill the messenger, I just refactored :)

I can imagine that this could be useful but at the moment it has no added value. I can imagine that locked profiles cannot be used as an auto login profile because you would need to enter the password when starting XBMC. However, at the moment this is not the case. When the profile is locked, it will still log you in automatically (this was also the case before this feature was merged when the most recent profile was password protected -> no password query next on startup).

I see two possible solutions:
1) Don't allow locked profiles to be used for auto login and as such also not offer them in the selection window. In this case the "Not locked" below the profile name would give a hint on what difference is between the listed and not listed profiles.
2) When a locked profile is selected as autologin profile, popup a window on startup with the option to either enter the password, or login as a different user.

May be for now it is just an indicator to make you think it through when you select a locked profile. You locked it for a reason, are you sure you want XBMC to always startup with this profile? Other than that I can't think of anything.

leechguy

I think it is quite ok as it is. It gives a clear indication that you are configuring the auto login profile. Another option could be to repopulate the right part of the window, but I think it is then less obvious. At one time when I press the icon, it does 'this' and at another time it doest 'that'.
I could also make it such that simply clicking the Auto login button would cycle through 'Most recent' and the available profiles.
I've also thought about adding the option 'Use as Autologin' to the context menu, but then where are you going to put the 'Most recent' option? In the context menu, this seems a bit out of context.

Please sign in to comment.
Something went wrong with that request. Please try again.