Exemple #1
0
        internal static ExternalContentEntry JsonObjectToEntry(JsonObject jsonObject)
        {
            ExternalContentEntry externalContentEntry = new ExternalContentEntry();

            if (jsonObject.ContainsKey("entries"))
            {
                foreach (JsonObject item in (JsonArray)jsonObject["entries"])
                {
                    ExternalContentEntry externalContentEntry2 = new ExternalContentEntry();
                    externalContentEntry2.Path = item["path_display"].ToString();
                    externalContentEntry2.Type = ((item[".tag"].ToString() == "folder") ? ExternalContentType.Directory : ExternalContentManager.ExtensionToType(Storage.GetExtension(externalContentEntry2.Path)));
                    if (externalContentEntry2.Type != ExternalContentType.Directory)
                    {
                        externalContentEntry2.Time = (item.ContainsKey("server_modified") ? DateTime.Parse(item["server_modified"].ToString(), CultureInfo.InvariantCulture) : new DateTime(2000, 1, 1));
                        externalContentEntry2.Size = (item.ContainsKey("size") ? ((long)item["size"]) : 0);
                    }
                    externalContentEntry.ChildEntries.Add(externalContentEntry2);
                }
                return(externalContentEntry);
            }
            return(externalContentEntry);
        }
Exemple #2
0
        public ExternalContentScreen()
        {
            XElement node = ContentManager.Get <XElement>("Screens/ExternalContentScreen");

            LoadContents(this, node);
            m_directoryLabel                  = Children.Find <LabelWidget>("TopBar.Label");
            m_directoryList                   = Children.Find <ListPanelWidget>("DirectoryList");
            m_providerNameLabel               = Children.Find <LabelWidget>("ProviderName");
            m_changeProviderButton            = Children.Find <ButtonWidget>("ChangeProvider");
            m_loginLogoutButton               = Children.Find <ButtonWidget>("LoginLogout");
            m_upDirectoryButton               = Children.Find <ButtonWidget>("UpDirectory");
            m_actionButton                    = Children.Find <ButtonWidget>("Action");
            m_copyLinkButton                  = Children.Find <ButtonWidget>("CopyLink");
            m_directoryList.ItemWidgetFactory = delegate(object item)
            {
                ExternalContentEntry externalContentEntry2 = (ExternalContentEntry)item;
                XElement             node2           = ContentManager.Get <XElement>("Widgets/ExternalContentItem");
                ContainerWidget      containerWidget = (ContainerWidget)Widget.LoadWidget(this, node2, null);
                string fileName = Storage.GetFileName(externalContentEntry2.Path);
                string text     = m_downloadedFiles.ContainsKey(externalContentEntry2.Path) ? LanguageControl.Get(fName, 11) : string.Empty;
                string text2    = (externalContentEntry2.Type != ExternalContentType.Directory) ? $"{ExternalContentManager.GetEntryTypeDescription(externalContentEntry2.Type)} | {DataSizeFormatter.Format(externalContentEntry2.Size)} | {externalContentEntry2.Time:dd-MMM-yyyy HH:mm}{text}" : ExternalContentManager.GetEntryTypeDescription(externalContentEntry2.Type);
                containerWidget.Children.Find <RectangleWidget>("ExternalContentItem.Icon").Subtexture = ExternalContentManager.GetEntryTypeIcon(externalContentEntry2.Type);
                containerWidget.Children.Find <LabelWidget>("ExternalContentItem.Text").Text           = fileName;
                containerWidget.Children.Find <LabelWidget>("ExternalContentItem.Details").Text        = text2;
                return(containerWidget);
            };
            m_directoryList.ItemClicked += delegate(object item)
            {
                if (m_directoryList.SelectedItem == item)
                {
                    ExternalContentEntry externalContentEntry = item as ExternalContentEntry;
                    if (externalContentEntry != null && externalContentEntry.Type == ExternalContentType.Directory)
                    {
                        SetPath(externalContentEntry.Path);
                    }
                }
            };
        }
Exemple #3
0
        public void DownloadEntry(ExternalContentEntry entry)
        {
            CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 10), autoHideOnCancel: false);

            DialogsManager.ShowDialog(null, busyDialog);
            m_externalContentProvider.Download(entry.Path, busyDialog.Progress, delegate(Stream stream)
            {
                busyDialog.LargeMessage = LanguageControl.Get(fName, 12);
                ExternalContentManager.ImportExternalContent(stream, entry.Type, Storage.GetFileName(entry.Path), delegate
                {
                    stream.Dispose();
                    DialogsManager.HideDialog(busyDialog);
                }, delegate(Exception error)
                {
                    stream.Dispose();
                    DialogsManager.HideDialog(busyDialog);
                    DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null));
                });
            }, delegate(Exception error)
            {
                DialogsManager.HideDialog(busyDialog);
                DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null));
            });
        }
Exemple #4
0
        public override void Update()
        {
            if (m_listDirty)
            {
                m_listDirty = false;
                UpdateList();
            }
            ExternalContentEntry externalContentEntry = null;

            if (m_directoryList.SelectedIndex.HasValue)
            {
                externalContentEntry = (m_directoryList.Items[m_directoryList.SelectedIndex.Value] as ExternalContentEntry);
            }
            if (externalContentEntry != null)
            {
                m_actionButton.IsVisible = true;
                if (externalContentEntry.Type == ExternalContentType.Directory)
                {
                    m_actionButton.Text        = LanguageControl.Get(fName, 1);
                    m_actionButton.IsEnabled   = true;
                    m_copyLinkButton.IsEnabled = false;
                }
                else
                {
                    m_actionButton.Text = LanguageControl.Get(fName, 2);
                    if (ExternalContentManager.IsEntryTypeDownloadSupported(ExternalContentManager.ExtensionToType(Storage.GetExtension(externalContentEntry.Path).ToLower())))
                    {
                        m_actionButton.IsEnabled   = true;
                        m_copyLinkButton.IsEnabled = true;
                    }
                    else
                    {
                        m_actionButton.IsEnabled   = false;
                        m_copyLinkButton.IsEnabled = false;
                    }
                }
            }
            else
            {
                m_actionButton.IsVisible   = false;
                m_copyLinkButton.IsVisible = false;
            }
            m_directoryLabel.Text         = m_externalContentProvider.IsLoggedIn ? string.Format(LanguageControl.Get(fName, 3), m_path) : LanguageControl.Get(fName, 4);
            m_providerNameLabel.Text      = m_externalContentProvider.DisplayName;
            m_upDirectoryButton.IsEnabled = (m_externalContentProvider.IsLoggedIn && m_path != "/");
            m_loginLogoutButton.Text      = (m_externalContentProvider.IsLoggedIn ? LanguageControl.Get(fName, 5) : LanguageControl.Get(fName, 6));
            m_loginLogoutButton.IsVisible = m_externalContentProvider.RequiresLogin;
            m_copyLinkButton.IsVisible    = m_externalContentProvider.SupportsLinks;
            m_copyLinkButton.IsEnabled    = (externalContentEntry != null && ExternalContentManager.IsEntryTypeDownloadSupported(externalContentEntry.Type));
            if (m_changeProviderButton.IsClicked)
            {
                DialogsManager.ShowDialog(null, new SelectExternalContentProviderDialog(LanguageControl.Get(fName, 7), listingSupportRequired : true, delegate(IExternalContentProvider provider)
                {
                    m_externalContentProvider = provider;
                    m_listDirty = true;
                    SetPath(null);
                }));
            }
            if (m_upDirectoryButton.IsClicked)
            {
                string directoryName = Storage.GetDirectoryName(m_path);
                SetPath(directoryName);
            }
            if (m_actionButton.IsClicked && externalContentEntry != null)
            {
                if (externalContentEntry.Type == ExternalContentType.Directory)
                {
                    SetPath(externalContentEntry.Path);
                }
                else
                {
                    DownloadEntry(externalContentEntry);
                }
            }
            if (m_copyLinkButton.IsClicked && externalContentEntry != null && ExternalContentManager.IsEntryTypeDownloadSupported(externalContentEntry.Type))
            {
                CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 8), autoHideOnCancel: false);
                DialogsManager.ShowDialog(null, busyDialog);
                m_externalContentProvider.Link(externalContentEntry.Path, busyDialog.Progress, delegate(string link)
                {
                    DialogsManager.HideDialog(busyDialog);
                    DialogsManager.ShowDialog(null, new ExternalContentLinkDialog(link));
                }, delegate(Exception error)
                {
                    DialogsManager.HideDialog(busyDialog);
                    DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null));
                });
            }
            if (m_loginLogoutButton.IsClicked)
            {
                if (m_externalContentProvider.IsLoggedIn)
                {
                    m_externalContentProvider.Logout();
                    SetPath(null);
                    m_listDirty = true;
                }
                else
                {
                    ExternalContentManager.ShowLoginUiIfNeeded(m_externalContentProvider, showWarningDialog: false, delegate
                    {
                        SetPath(null);
                        m_listDirty = true;
                    });
                }
            }
            if (base.Input.Back || base.Input.Cancel || Children.Find <ButtonWidget>("TopBar.Back").IsClicked)
            {
                ScreensManager.SwitchScreen("Content");
            }
        }
Exemple #5
0
 public static bool EntryFilter(ExternalContentEntry entry)
 {
     return(entry.Type != ExternalContentType.Unknown);
 }