Example #1
0
        void ShowAddin(object data)
        {
            AddinHeader sinfo        = null;
            Addin       installed    = null;
            AddinHeader updateInfo   = null;
            string      repo         = "";
            string      downloadSize = null;

            topHeaderBox.Hide();

            if (data is Addin)
            {
                installed = (Addin)data;
                sinfo     = SetupService.GetAddinHeader(installed);
                var entry = GetUpdate(installed);
                if (entry != null)
                {
                    updateInfo = entry.Addin;
                    selectedEntry.Add(entry);
                }
                foreach (var prop in sinfo.Properties)
                {
                    if (prop.Name.StartsWith("PreviewImage"))
                    {
                        previewImages.Add(new ImageContainer(installed, prop.Value));
                    }
                }
                string icon32 = sinfo.Properties.GetPropertyValue("Icon32");
                if (icon32.Length > 0)
                {
                    titleIcon = new ImageContainer(installed, icon32);
                }
            }
            else if (data is AddinRepositoryEntry)
            {
                AddinRepositoryEntry entry = (AddinRepositoryEntry)data;
                sinfo     = entry.Addin;
                installed = AddinManager.Registry.GetAddin(Addin.GetIdName(sinfo.Id));
                if (installed != null && Addin.CompareVersions(installed.Version, sinfo.Version) > 0)
                {
                    updateInfo = sinfo;
                }
                selectedEntry.Add(entry);
                string rname = !string.IsNullOrEmpty(entry.RepositoryName) ? entry.RepositoryName : entry.RepositoryUrl;
                repo = "<small><b>" + Catalog.GetString("Available in repository:") + "</b>\n" + GLib.Markup.EscapeText(rname) + "\n\n</small>";
                foreach (var prop in sinfo.Properties)
                {
                    if (prop.Name.StartsWith("PreviewImage"))
                    {
                        previewImages.Add(new ImageContainer(entry, prop.Value));
                    }
                }
                string icon32 = sinfo.Properties.GetPropertyValue("Icon32");
                if (icon32.Length > 0)
                {
                    titleIcon = new ImageContainer(entry, icon32);
                }
                int size;
                if (int.TryParse(sinfo.Properties.GetPropertyValue("DownloadSize"), out size))
                {
                    float fs = ((float)size) / 1048576f;
                    downloadSize = fs.ToString("0.00 MB");
                }
            }
            else
            {
                selectedEntry.Clear();
            }

            if (installed != null)
            {
                selectedAddin.Add(installed);
            }

            string missingDepsTxt = null;

            if (sinfo == null)
            {
                btnDisable.Visible   = false;
                btnUninstall.Visible = false;
                btnUpdate.Visible    = false;
            }
            else
            {
                string version;
                string newVersion = null;
                if (installed != null)
                {
                    btnInstall.Visible   = false;
                    btnUpdate.Visible    = updateInfo != null && AllowInstall;
                    btnDisable.Visible   = true;
                    btnDisable.Label     = installed.Enabled ? Catalog.GetString("Disable") : Catalog.GetString("Enable");
                    btnDisable.Visible   = installed.Description.CanDisable;
                    btnUninstall.Visible = installed.Description.CanUninstall;
                    version = installed.Version;
                    var missingDeps = Services.GetMissingDependencies(installed);
                    if (updateInfo != null)
                    {
                        newVersion         = updateInfo.Version;
                        labelHeader.Markup = "<b><span color='black'>" + Catalog.GetString("Update available") + "</span></b>";
//						topHeaderBox.BackgroundColor = new Gdk.Color (0, 132, 208);
                        imageHeader.Pixbuf           = Gdk.Pixbuf.LoadFromResource("update-16.png");
                        topHeaderBox.BackgroundColor = new Gdk.Color(255, 176, 0);
                        topHeaderBox.Show();
                    }
                    else if (missingDeps.Any())
                    {
                        labelHeader.Markup           = "<b><span color='black'>" + Catalog.GetString("This extension package can't be loaded due to missing dependencies") + "</span></b>";
                        topHeaderBox.BackgroundColor = new Gdk.Color(255, 176, 0);
                        imageHeader.SetFromStock(Gtk.Stock.DialogWarning, Gtk.IconSize.Menu);
                        topHeaderBox.Show();
                        missingDepsTxt = "";
                        foreach (var mdep in missingDeps)
                        {
                            if (mdep.Found != null)
                            {
                                missingDepsTxt += "\n" + string.Format(Catalog.GetString("Required: {0} v{1}, found v{2}"), mdep.Addin, mdep.Required, mdep.Found);
                            }
                            else
                            {
                                missingDepsTxt += "\n" + string.Format(Catalog.GetString("Missing: {0} v{1}"), mdep.Addin, mdep.Required);
                            }
                        }
                    }
                }
                else
                {
                    btnInstall.Visible   = AllowInstall;
                    btnUpdate.Visible    = false;
                    btnDisable.Visible   = false;
                    btnUninstall.Visible = false;
                    version = sinfo.Version;
                }
                labelName.Markup = "<b><big>" + GLib.Markup.EscapeText(sinfo.Name) + "</big></b>";

                string ver;
                if (newVersion != null)
                {
                    ver  = "<small><b>" + Catalog.GetString("Installed version") + ":</b> " + version + "</small>\n";
                    ver += "<small><b>" + Catalog.GetString("Repository version") + ":</b> " + newVersion + "</small>";
                }
                else
                {
                    ver = "<small><b>" + Catalog.GetString("Version") + " " + version + "</b></small>";
                }

                if (downloadSize != null)
                {
                    ver += "\n<small><b>" + Catalog.GetString("Download size") + ":</b> " + downloadSize + "</small>";
                }
                if (missingDepsTxt != null)
                {
                    ver += "\n\n" + GLib.Markup.EscapeText(Catalog.GetString("The following dependencies required by this extension package are not available:")) + missingDepsTxt;
                }
                labelVersion.Markup = ver;

                string desc = GLib.Markup.EscapeText(sinfo.Description);
                labelDesc.Markup = repo + GLib.Markup.EscapeText(desc);

                foreach (var img in previewImages)
                {
                    vboxDesc.PackStart(img, false, false, 0);
                }

                urlButton.Visible = !string.IsNullOrEmpty(sinfo.Url);
                infoUrl           = sinfo.Url;

                if (titleIcon != null)
                {
                    boxTitle.PackEnd(titleIcon, false, false, 0);
                    labelName.WidthRequest    = titleWidth - 32;
                    labelVersion.WidthRequest = titleWidth - 32;
                }
                else
                {
                    labelName.WidthRequest    = titleWidth;
                    labelVersion.WidthRequest = titleWidth;
                }

                if (IsRealized)
                {
                    SetComponentsBg();
                }
            }
        }
        void StoreIcon(TreeIter it, string iconId, Gdk.Pixbuf customPix, AddinStatus status)
        {
            if (customPix == null)
            {
                customPix = iconInstalled;
            }

            if ((status & AddinStatus.Installed) == 0)
            {
                treeStore.SetValue(it, ColImage, customPix);
                return;
            }
            else if (ShowInstalledMarkers && (status & AddinStatus.HasUpdate) == 0)
            {
                customPix = GetCachedIcon(iconId, "InstalledOverlay", delegate { return(Services.AddIconOverlay(customPix, installedOverlay)); });
                iconId    = iconId + "_Installed";
            }

            if ((status & AddinStatus.Disabled) != 0)
            {
                customPix = GetCachedIcon(iconId, "Desaturate", delegate { return(Services.DesaturateIcon(customPix)); });
                iconId    = iconId + "_Desaturate";
            }
            if ((status & AddinStatus.HasUpdate) != 0)
            {
                customPix = GetCachedIcon(iconId, "UpdateOverlay", delegate { return(Services.AddIconOverlay(customPix, updateOverlay)); });
            }

            treeStore.SetValue(it, ColImage, customPix);
        }
        protected void OnAdd(object sender, EventArgs e)
        {
            NewSiteDialog dlg = new NewSiteDialog(this);

            try
            {
                if (dlg.Run())
                {
                    string url = dlg.Url;
                    if (!url.StartsWith("http://") && !url.StartsWith("https://") && !url.StartsWith("file://"))
                    {
                        url = "http://" + url;
                    }

                    try
                    {
                        new Uri(url);
                    }
                    catch
                    {
                        Services.ShowError(null, "Invalid url: " + url, null, true);
                    }

                    if (!service.Repositories.ContainsRepository(url))
                    {
                        ProgressDialog pdlg = new ProgressDialog(this);
                        pdlg.Show();
                        pdlg.SetMessage(AddinManager.CurrentLocalizer.GetString("Registering repository"));

                        bool            done  = false;
                        AddinRepository rr    = null;
                        Exception       error = null;

                        ThreadPool.QueueUserWorkItem(delegate
                        {
                            try
                            {
                                rr = service.Repositories.RegisterRepository(pdlg, url, true);
                            }
                            catch (System.Exception ex)
                            {
                                error = ex;
                            }
                            finally
                            {
                                done = true;
                            }
                        });

                        while (!done)
                        {
                            if (Gtk.Application.EventsPending())
                            {
                                Gtk.Application.RunIteration();
                            }
                            else
                            {
                                Thread.Sleep(100);
                            }
                        }

                        pdlg.Destroy();

                        if (pdlg.HadError)
                        {
                            if (rr != null)
                            {
                                service.Repositories.RemoveRepository(rr.Url);
                            }
                            return;
                        }

                        if (error != null)
                        {
                            Services.ShowError(error, "The repository could not be registered", null, true);
                            return;
                        }

                        AppendRepository(rr);
                    }
                }
            }
            finally
            {
                dlg.Destroy();
            }
        }