public void SetBook(DatabaseAlbumInfo book)
        {
            ThreadAssist.AssertInMainThread();
            Book = book;

            title_label.Markup = String.Format(
                "<span size=\"x-large\" weight=\"bold\">{0}</span>\n" +
                "{1}",
                GLib.Markup.EscapeText(book.Title),
                GLib.Markup.EscapeText(book.ArtistName)
                );

            var bookmark = library.GetLastPlayedBookmark(book.DbId);

            UpdateResumeButton(bookmark);

            UpdateCover();

            /*var bookmarks = Bookmark.Provider.FetchAllMatching (
             *  "TrackID IN (SELECT TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND AlbumID = ?)",
             *  library.DbId, book.DbId
             * );*/

            rating_entry.Value = (int)Math.Round(ServiceManager.DbConnection.Query <double> (
                                                     "SELECT AVG(RATING) FROM CoreTracks WHERE PrimarySourceID = ? AND AlbumID = ?", library.DbId, book.DbId
                                                     ));
        }
Exemplo n.º 2
0
        public UserJobTileHost() : base(0.0f, 0.0f, 1.0f, 1.0f)
        {
            ThreadAssist.AssertInMainThread();
            LeftPadding = 4;

            box = new AnimatedVBox();
            box.StartPadding = 8;
            box.Spacing      = 8;

            Add(box);
            ShowAll();

            if (ServiceManager.Contains <JobScheduler> ())
            {
                JobScheduler job_manager = ServiceManager.Get <JobScheduler> ();
                job_manager.JobAdded   += OnJobAdded;
                job_manager.JobRemoved += OnJobRemoved;
            }

            if (ApplicationContext.CommandLine.Contains("test-user-job"))
            {
                int fish;
                if (!Int32.TryParse(ApplicationContext.CommandLine["test-user-job"], out fish))
                {
                    fish = 5;
                }
                TestUserJob.SpawnLikeFish(fish);
            }
        }
Exemplo n.º 3
0
 public void Refresh()
 {
     ThreadAssist.AssertInMainThread();
     Clear();
     foreach (Source source in ServiceManager.SourceManager.Sources)
     {
         AddSource(source);
     }
 }
Exemplo n.º 4
0
 private void RemoveJob(Job job)
 {
     lock (this) {
         if (job_tiles.ContainsKey(job))
         {
             ThreadAssist.AssertInMainThread();
             UserJobTile tile = job_tiles[job];
             box.Remove(tile);
             job_tiles.Remove(job);
             job_start_times.Remove(job);
         }
     }
 }
Exemplo n.º 5
0
        public void RemoveSource(Source source)
        {
            ThreadAssist.AssertInMainThread();
            lock (sync) {
                TreeIter iter = FindSource(source);
                if (!iter.Equals(TreeIter.Zero))
                {
                    Remove(ref iter);
                }

                source.ChildSourceAdded   -= OnSourceChildSourceAdded;
                source.ChildSourceRemoved -= OnSourceChildSourceRemoved;

                OnSourceRowRemoved(source, iter);
            }
        }
Exemplo n.º 6
0
        private void BuildWidget()
        {
            ThreadAssist.AssertInMainThread();
            ColumnSpacing = 5;
            RowSpacing    = 2;

            icon = new Image();

            tooltips              = TooltipSetter.CreateHost();
            title_label           = new Label();
            title_label.Xalign    = 0.0f;
            title_label.Ellipsize = Pango.EllipsizeMode.End;

            status_label           = new Label();
            status_label.Xalign    = 0.0f;
            status_label.Ellipsize = Pango.EllipsizeMode.End;

            progress_bar = new ProgressBar();
            progress_bar.SetSizeRequest(0, -1);
            progress_bar.Text = " ";
            progress_bar.Show();

            cancel_button        = new Button(new Image(Stock.Stop, IconSize.Menu));
            cancel_button.Relief = ReliefStyle.None;
            cancel_button.ShowAll();
            cancel_button.Clicked += OnCancelClicked;

            Attach(title_label, 0, 3, 0, 1,
                   AttachOptions.Expand | AttachOptions.Fill,
                   AttachOptions.Expand | AttachOptions.Fill, 0, 0);

            Attach(status_label, 0, 3, 1, 2,
                   AttachOptions.Expand | AttachOptions.Fill,
                   AttachOptions.Expand | AttachOptions.Fill, 0, 0);

            Attach(icon, 0, 1, 2, 3,
                   AttachOptions.Shrink | AttachOptions.Fill,
                   AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            Attach(progress_bar, 1, 2, 2, 3,
                   AttachOptions.Expand | AttachOptions.Fill,
                   AttachOptions.Shrink, 0, 0);

            Attach(cancel_button, 2, 3, 2, 3,
                   AttachOptions.Shrink | AttachOptions.Fill,
                   AttachOptions.Shrink | AttachOptions.Fill, 0, 0);
        }
Exemplo n.º 7
0
        private void ConnectEvents()
        {
            ServiceManager.SourceManager.ActiveSourceChanged += delegate(SourceEventArgs args) {
                ThreadAssist.ProxyToMain(ResetSelection);
            };

            ServiceManager.SourceManager.SourceUpdated += delegate(SourceEventArgs args) {
                ThreadAssist.ProxyToMain(delegate {
                    lock (args.Source) {
                        TreeIter iter = store.FindSource(args.Source);
                        if (!TreeIter.Zero.Equals(iter))
                        {
                            if (args.Source.Expanded)
                            {
                                Expand(args.Source);
                            }

                            need_resort = true;
                            QueueDraw();
                        }
                    }
                });
            };

            ServiceManager.PlaybackController.NextSourceChanged += delegate {
                ThreadAssist.ProxyToMain(QueueDraw);
            };

            notify_stage.ActorStep += delegate(Actor <TreeIter> actor) {
                ThreadAssist.AssertInMainThread();
                if (!store.IterIsValid(actor.Target))
                {
                    return(false);
                }

                using (var path = store.GetPath(actor.Target)) {
                    Gdk.Rectangle rect = GetBackgroundArea(path, source_column);
                    QueueDrawArea(rect.X, rect.Y, rect.Width, rect.Height);
                }
                return(true);
            };

            ServiceManager.Get <InterfaceActionService> ().SourceActions["OpenSourceSwitcher"].Activated += delegate {
                new SourceSwitcherEntry(this);
            };
        }
Exemplo n.º 8
0
        public void AddSource(Source source, TreeIter parent)
        {
            ThreadAssist.AssertInMainThread();
            lock (sync) {
                if (Filter != null && !Filter(source))
                {
                    return;
                }

                // Don't add duplicates
                if (!FindSource(source).Equals(TreeIter.Zero))
                {
                    return;
                }

                // Don't add a child source before its parent
                if (parent.Equals(TreeIter.Zero) && source.Parent != null)
                {
                    return;
                }

                int position = source.Order;

                var args = new object [] {
                    source,
                    position,
                    source is SourceManager.GroupSource ? EntryType.Group : EntryType.Source
                };

                TreeIter iter = parent.Equals(TreeIter.Zero)
                    ? InsertWithValues(position, args)
                    : InsertWithValues(parent, position, args);

                lock (source.Children) {
                    foreach (Source child in source.Children)
                    {
                        AddSource(child, iter);
                    }
                }

                source.ChildSourceAdded   += OnSourceChildSourceAdded;
                source.ChildSourceRemoved += OnSourceChildSourceRemoved;

                OnSourceRowInserted(source, iter, parent);
            }
        }
Exemplo n.º 9
0
        void UpdateForDocument()
        {
            ThreadAssist.AssertInMainThread();
            var    current_size = Document.FileSize;
            string size_str     = null;

            if (original_size_string == null)
            {
                size_str      = original_size_string = new Hyena.Query.FileSizeQueryValue(current_size).ToUserQuery();
                original_size = current_size;
            }
            else if (current_size == original_size)
            {
                size_str = original_size_string;
            }
            else
            {
                string current_size_string = new Hyena.Query.FileSizeQueryValue(current_size).ToUserQuery();
                if (current_size_string == original_size_string)
                {
                    size_str = original_size_string;
                }
                else
                {
                    // Translators: this string is used to show current/original file size, eg "2 MB (originally 1 MB)"
                    size_str = String.Format(Catalog.GetString("{0} (originally {1})"), current_size_string, original_size_string);
                }
            }

            status_label.Text = String.Format("{0} \u2013 {1}",
                                              String.Format(Catalog.GetPluralString("{0} page", "{0} pages", Document.Count), Document.Count),
                                              size_str
                                              );

            var title    = Document.Title;
            var filename = Document.Filename;

            if (Document.HasUnsavedChanges)
            {
                filename = "*" + filename;
            }
            Window.Title = title == null ? filename : String.Format("{0} - {1}", filename, title);
        }
Exemplo n.º 10
0
        void IExtensionService.Initialize()
        {
            artwork_manager_service = ServiceManager.Get <ArtworkManager> ();

            ThreadAssist.AssertInMainThread();

            ServiceManager.PlayerEngine.ConnectEvent(OnPlayerEvent,
                                                     PlayerEvent.StartOfStream |
                                                     PlayerEvent.TrackInfoUpdated);

            // capture the current wallpaper to reestablish when exiting or in albums with no art
            gClient = new GConf.Client();
            try {
                userWallpaper = (string)gClient.Get(GCONF_BACKGROUND_PATH);
            } catch (GConf.NoSuchKeyException ex) {
                Log.Error(ex.Message);
                //TODO: handle this exception (shouldn't happen though)
            }
        }
Exemplo n.º 11
0
        private void AddJob(Job job)
        {
            lock (this) {
                if (job == null || job.IsFinished)
                {
                    return;
                }

                if ((job.DelayShow && job.Progress < 0.33) || !job.DelayShow)
                {
                    ThreadAssist.AssertInMainThread();
                    UserJobTile tile = new UserJobTile(job);
                    job_tiles.Add(job, tile);
                    job_start_times.Add(job, DateTime.Now);
                    box.PackEnd(tile, Easing.QuadraticOut);
                    tile.Show();
                }
            }
        }
Exemplo n.º 12
0
        public void SetActiveSource(Source source, bool notify)
        {
            ThreadAssist.AssertInMainThread();
            if (source == null || !source.CanActivate || active_source == source)
            {
                return;
            }

            if (active_source != null)
            {
                active_source.Deactivate();
            }

            active_source = source;
            if (source.Parent != null)
            {
                source.Parent.Expanded = true;
            }

            if (!notify)
            {
                source.Activate();
                return;
            }

            SourceEventHandler handler = ActiveSourceChanged;

            if (handler != null)
            {
                SourceEventArgs args = new SourceEventArgs();
                args.Source = active_source;
                handler(args);
            }

            source.Activate();
        }
Exemplo n.º 13
0
        private void UpdateFromJob()
        {
            ThreadAssist.AssertInMainThread();
            if (cancel_dialog != null && !job.CanCancel)
            {
                cancel_dialog.Respond(Gtk.ResponseType.Cancel);
            }

            if (job.IsCancelRequested)
            {
                SetTitle(Catalog.GetString("Stopping..."));
            }
            else if (title != job.Title)
            {
                SetTitle(job.Title);
            }

            if (status != job.Status)
            {
                // If we've ever had the status in this job, don't hide it b/c that'll make
                // the tile change width, possibly repeatedly and annoyingly
                if (String.IsNullOrEmpty(job.Status) && never_had_status)
                {
                    status_label.Hide();
                }
                else
                {
                    never_had_status    = false;
                    status_label.Markup = String.Format("<small>{0}</small>", GLib.Markup.EscapeText(job.Status ?? String.Empty));
                    TooltipSetter.Set(tooltips, status_label, job.Status ?? String.Empty);
                    status_label.Show();
                }
                status = job.Status;
            }

            if (icon_names == null || icon_names.Length != job.IconNames.Length)
            {
                UpdateIcons();
            }
            else
            {
                for (int i = 0; i < job.IconNames.Length; i++)
                {
                    if (icon_names[i] != job.IconNames[i])
                    {
                        UpdateIcons();
                        break;
                    }
                }
            }

            cancel_button.Sensitive = job.CanCancel && !job.IsCancelRequested;

            if (job.Progress == 0 && progress_bounce_id > 0)
            {
                return;
            }

            progress_bar.Fraction = job.Progress;

            if (job.Progress == 0.0 && progress_bounce_id == 0)
            {
                progress_bounce_id = GLib.Timeout.Add(100, delegate {
                    progress_bar.Text = " ";
                    progress_bar.Pulse();
                    return(true);
                });
            }
            else if (job.Progress > 0.0)
            {
                if (progress_bounce_id > 0)
                {
                    GLib.Source.Remove(progress_bounce_id);
                    progress_bounce_id = 0;
                }

                progress_bar.Text = String.Format("{0}%", (int)(job.Progress * 100.0));
            }
        }
Exemplo n.º 14
0
        public void AddSource(Source source, bool isDefault)
        {
            ThreadAssist.AssertInMainThread();
            if (source == null || ContainsSource(source))
            {
                return;
            }

            GroupSource group_source = source as GroupSource;

            if (group_source != null && !group_sources.Contains(group_source))
            {
                group_sources.Add(group_source);
                return;
            }

            AddSource(FindAssociatedGroupSource(source.Order));

            int position = FindSourceInsertPosition(source);

            sources.Insert(position, source);

            if (isDefault)
            {
                default_source = source;
            }

            source.Updated            += OnSourceUpdated;
            source.ChildSourceAdded   += OnChildSourceAdded;
            source.ChildSourceRemoved += OnChildSourceRemoved;

            if (source is MusicLibrarySource)
            {
                music_library = source as MusicLibrarySource;
            }

            SourceAdded.SafeInvoke(new SourceAddedArgs()
            {
                Position = position,
                Source   = source
            });

            IDBusExportable exportable = source as IDBusExportable;

            if (exportable != null)
            {
                ServiceManager.DBusServiceManager.RegisterObject(exportable);
            }

            List <Source> children = new List <Source> (source.Children);

            foreach (Source child_source in children)
            {
                AddSource(child_source, false);
            }

            if (isDefault && ActiveSource == null)
            {
                SetActiveSource(source);
            }
        }
Exemplo n.º 15
0
        public HeaderWidget(Shuffler shuffler, string shuffle_mode_id, string source_name) : base(0, 0, 0, 0)
        {
            ThreadAssist.AssertInMainThread();

            var box = new HBox();

            box.Spacing = 6;

            var fill_label = new Label(Catalog.GetString("_Fill"));

            mode_combo = new DictionaryComboBox <RandomBy> ();
            foreach (var random_by in shuffler.RandomModes.OrderBy(r => r.Adverb))
            {
                mode_combo.Add(random_by.Adverb, random_by);
                if (random_by.Id == "off")
                {
                    mode_combo.Default = random_by;
                }
            }

            fill_label.MnemonicWidget = mode_combo;
            mode_combo.Changed       += OnModeComboChanged;

            var from_label       = new Label(Catalog.GetString("f_rom"));
            var source_combo_box = new QueueableSourceComboBox(source_name);

            from_label.MnemonicWidget = source_combo_box;

            sensitive_widgets.Add(source_combo_box);
            sensitive_widgets.Add(from_label);

            source_combo_box.Changed += delegate {
                var handler = SourceChanged;
                if (handler != null)
                {
                    handler(this, new EventArgs <DatabaseSource> (source_combo_box.Source));
                }
            };

            box.PackStart(fill_label, false, false, 0);
            box.PackStart(mode_combo, false, false, 0);
            box.PackStart(from_label, false, false, 0);
            box.PackStart(source_combo_box, false, false, 0);
            this.SetPadding(0, 0, 6, 6);
            this.Add(box);

            // Select the saved population mode.
            var default_randomby = shuffler.RandomModes.FirstOrDefault(r => r.Id == shuffle_mode_id);

            if (default_randomby != null)
            {
                mode_combo.ActiveValue = default_randomby;
            }
            else if (mode_combo.Default != null)
            {
                mode_combo.ActiveValue = mode_combo.Default;
            }

            shuffler.RandomModeAdded   += (r) => mode_combo.Add(r.Adverb, r);
            shuffler.RandomModeRemoved += (r) => mode_combo.Remove(r);
        }
Exemplo n.º 16
0
 public void SetManual()
 {
     ThreadAssist.AssertInMainThread();
     mode_combo.ActiveValue = mode_combo.Default;
 }