예제 #1
0
 public void Initialize(ExchangeViewModel vm)
 {
     viewModel = vm;
     sorted    = new TreeModelSort(store);
     sorted.SetSortFunc(0, SortBySymbol);
     sorted.SetSortFunc(4, SortByDistance);
     sorted.SetSortColumnId(4, SortType.Ascending);
     nodeview1.Model = sorted;
     viewModel.MarketSummaries.CollectionChanged += MarketSummaries_CollectionChanged;
 }
예제 #2
0
 /// <summary>the sort column.</summary>
 private void SetTreeSortModel()
 {
     if (sortColumn != null)
     {
         var sortColumnIndex = columns.FindIndex(c => c.Title == sortColumn);
         if (sortColumnIndex != -1)
         {
             var sortMultpilier = 1;
             if (!SortAscending)
             {
                 sortMultpilier = -1;
             }
             sort = new TreeModelSort(new TreeModelFilter(store, null))
             {
                 // By default, sort by start time descending.
                 DefaultSortFunc = (model, a, b) => sortMultpilier *SortData(model, a, b, sortColumnIndex)
             };
             for (int i = 0; i < columns.Count; i++)
             {
                 sort.SetSortFunc(i, (model, a, b) => SortData(model, a, b, i));
             }
             tree.Model = sort;
         }
     }
 }
예제 #3
0
        protected virtual void HandleViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "SortType")
            {
                /* Hack to make it actually resort */
                sort?.SetSortFunc(COL_DATA, HandleSort);
            }

            if (e.PropertyName == "FilterText")
            {
                filter?.Refilter();
            }

            if (e.PropertyName == "Collection_" + nameof(viewModel.Selection))
            {
                //Sincronization of the first external selection
                if (ViewModel.Selection.Count == 1 && Selection.CountSelectedRows() == 0)
                {
                    foreach (TreeIter element in dictionaryStore[ViewModel.Selection.FirstOrDefault()])
                    {
                        TreeIter externalSelected = element;
                        if (filter != null)
                        {
                            externalSelected = filter.ConvertChildIterToIter(externalSelected);
                            externalSelected = sort.ConvertChildIterToIter(externalSelected);
                        }
                        Selection.SelectIter(externalSelected);
                    }
                }
            }
        }
예제 #4
0
    public ClipboardItemListView()
    {
        HeadersVisible = true;

        Selection.Mode = SelectionMode.Multiple;

        int columnId = -1;

        var renderer = new CellRendererText();

        var textColumn = AppendColumn("Items", renderer, "text", 0);

        InitColumn(textColumn, ++columnId);

        var dateTimeColumn = AppendColumn("Created", renderer, SetDateTimeRendererText);

        InitColumn(dateTimeColumn, ++columnId);

        store = new ClipboardItemStore();

        modelFilter             = new TreeModelFilter(store, null);
        modelFilter.VisibleFunc = FilterFunc;

        modelSort = new TreeModelSort(modelFilter);
        modelSort.SetSortFunc(1, CompareDateTime);

        Model = modelSort;
    }
예제 #5
0
        public LoadBackup() : base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            // determine available backups and append to store
            string dir          = System.IO.Path.GetDirectoryName(AppSettings.I.TournamentFile);
            string backupPrefix = System.IO.Path.GetFileName(
                System.IO.Path.ChangeExtension(AppSettings.I.TournamentFile, "backup"));
            DateTime now = DateTime.Now;

            store = new ListStore(typeof(string), typeof(TimeSpan));

            foreach (string backupFile in Directory.GetFiles(dir, backupPrefix + "*"))
            {
                TimeSpan lastWriteAgo = now.Subtract(Directory.GetLastWriteTime(backupFile));
                store.AppendValues(backupFile, lastWriteAgo);
            }
            // setup combobox
            TreeModelSort sortedStore = new TreeModelSort(store);

            sortedStore.SetSortFunc(0, delegate(TreeModel model, TreeIter a, TreeIter b) {
                TimeSpan tsA = (TimeSpan)model.GetValue(a, 1);
                TimeSpan tsB = (TimeSpan)model.GetValue(b, 1);
                return(tsA.CompareTo(tsB));
            });
            sortedStore.SetSortColumnId(0, SortType.Ascending);
            cbBackupFiles.Model = sortedStore;
            CellRendererText cellFile = new CellRendererText();

            cbBackupFiles.PackStart(cellFile, false);
            cbBackupFiles.SetCellDataFunc(cellFile, delegate(CellLayout layout,
                                                             CellRenderer cell,
                                                             TreeModel model,
                                                             TreeIter iter) {
                object o = model.GetValue(iter, 0);
                if (o == null)
                {
                    return;
                }
                (cell as CellRendererText).Text = System.IO.Path.GetFileName(o as string);
            });
            CellRendererText cellLastWrite = new CellRendererText();

            cbBackupFiles.PackStart(cellLastWrite, false);

            cbBackupFiles.SetCellDataFunc(cellLastWrite, delegate(CellLayout layout,
                                                                  CellRenderer cell,
                                                                  TreeModel model,
                                                                  TreeIter iter) {
                object o = model.GetValue(iter, 1);
                if (o == null)
                {
                    return;
                }
                CellRendererText cellText = cell as CellRendererText;
                cellText.Xpad             = 10;
                cellText.Markup           = "<i><small>" + FormatTimeSpan((TimeSpan)o) + " ago</small></i>";
            });
        }
예제 #6
0
 protected void CreateFilterAndSort()
 {
     filter             = new TreeModelFilter(store, null);
     filter.VisibleFunc = new TreeModelFilterVisibleFunc(HandleFilter);
     sort = new TreeModelSort(filter);
     sort.SetSortFunc(COL_DATA, HandleSort);
     sort.SetSortColumnId(COL_DATA, SortType.Ascending);
     Model = sort;
 }
예제 #7
0
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();
        note_store = new NoteStore(basedir);

        preview.ModifyFont(Pango.FontDescription.FromString("Monospace 12"));

        Gtk.TreeViewColumn titleColumn = new Gtk.TreeViewColumn();
        titleColumn.Title = "Title";
        Gtk.CellRendererText titleCell = new Gtk.CellRendererText();
        titleColumn.PackStart(titleCell, true);
        titleColumn.AddAttribute(titleCell, "text", 0);
        titleColumn.SortColumnId = 0;
        titleColumn.Expand       = true;
        filenames.AppendColumn(titleColumn);

/*
 *      if (false) {
 *          Gtk.TreeViewColumn filenameColumn = new Gtk.TreeViewColumn ();
 *          filenameColumn.Title = "Filename";
 *          Gtk.CellRendererText filenameCell = new Gtk.CellRendererText();
 *          filenameColumn.PackStart(filenameCell, true);
 *          filenameColumn.AddAttribute(filenameCell, "text", 1);
 *          filenameColumn.SortColumnId = 1;
 *          filenames.AppendColumn(filenameColumn);
 *      }
 */

        Gtk.TreeViewColumn dateColumn = new Gtk.TreeViewColumn();
        dateColumn.Title = "Date added";
        Gtk.CellRendererText dateCell = new Gtk.CellRendererText();
        dateColumn.PackStart(dateCell, true);
        dateColumn.SetCellDataFunc(dateCell, this.RenderDate);
        dateColumn.SortColumnId = 2;

        filenames.AppendColumn(dateColumn);

        filename_list = new ListStore(typeof(String), typeof(String), typeof(DateTime), typeof(Note));
        UpdateFiles();

        filename_list.SetSortColumnId(0, SortType.Ascending);

        filter = new Gtk.TreeModelFilter(filename_list, null);

        filter.VisibleFunc = new TreeModelFilterVisibleFunc(FilterTree);

        TreeModelSort tm = new TreeModelSort(filter);

        tm.SetSortFunc(2, this.SortDates);
        filenames.Model = tm;

        preview.WrapMode = WrapMode.Word;
        preview.ModifyFont(Pango.FontDescription.FromString("Droid Sans Mono 10"));
        preview.Buffer.Changed += new EventHandler(this.WriteToNotefile);
    }
예제 #8
0
        void HandleEditPlayEvent(object sender, EventArgs e)
        {
            List <Player> players = SelectedPlay.Players.ToList();

            Config.GUIToolkit.EditPlay(SelectedPlay, Project, true, true, true, true);

            if (!Enumerable.SequenceEqual(players, SelectedPlay.Players))
            {
                Config.EventsBroker.EmitTeamTagsChanged();
            }
            Config.EventsBroker.EmitEventEdited(SelectedPlay);
            modelSort.SetSortFunc(0, SortFunction);
            modelSort.SetSortColumnId(0, SortType.Ascending);
        }
예제 #9
0
        public ProjectListWidget()
        {
            this.Build();
            selectedProjects = new List <LMProject> ();

            CreateStore();
            CreateViews();

            sortcombobox.Active   = (int)App.Current.Config.ProjectSortMethod;
            sortcombobox.Changed += (sender, e) => {
                /* Hack to make it actually resort */
                sort.SetSortFunc(COL_DISPLAY_NAME, SortFunc);
                App.Current.Config.ProjectSortMethod = (ProjectSortMethod)sortcombobox.Active;
            };
            focusimage.Image = App.Current.ResourcesLocator.LoadIcon("vas-search", 27);
            ViewMode         = ProjectListViewMode.List;
        }
예제 #10
0
        void HandleEditPlayEvent(object sender, EventArgs e)
        {
            LMTimelineEvent selectedEvent = SelectedPlay;
            List <Player>   players       = selectedEvent.Players.ToList();

            App.Current.EventsBroker.Publish <EditEventEvent> (
                new EditEventEvent {
                TimelineEvent = selectedEvent
            });

            if (!players.SequenceEqual(selectedEvent.Players))
            {
                App.Current.EventsBroker.Publish <TeamTagsChangedEvent> ();
            }

            modelSort.SetSortFunc(0, SortFunction);
            modelSort.SetSortColumnId(0, SortType.Ascending);
        }
예제 #11
0
        public PodcastPlaylistView(PodcastPlaylistModel model)
        {
            if (model == null)
            {
                throw new NullReferenceException("model");
            }

            columns = new ArrayList(3);
            schemas = new ArrayList(3);

            RulesHint      = true;
            Selection.Mode = SelectionMode.Multiple;

            filter             = new TreeModelFilter(model, null);
            filter.VisibleFunc = PodcastFilterFunc;

            sort = new TreeModelSort(filter);
            sort.DefaultSortFunc = PodcastFeedTitleTreeIterCompareFunc;

            Model = sort;

            podcast_title_column = NewColumn(
                Catalog.GetString("Title"),
                (int)Column.PodcastTitle,
                GConfSchemas.PodcastTitleColumnSchema
                );

            feed_title_column = NewColumn(
                Catalog.GetString("Feed"),
                (int)Column.FeedTitle,
                GConfSchemas.PodcastFeedColumnSchema
                );

            pubdate_column = NewColumn(
                Catalog.GetString("Date"),
                (int)Column.PubDate,
                GConfSchemas.PodcastDateColumnSchema
                );

            /********************************************/

            download_column = new TreeViewColumn();

            Gtk.Image download_image = new Gtk.Image(
                PodcastPixbufs.DownloadColumnIcon
                );

            download_image.Show();

            download_column.Expand      = false;
            download_column.Resizable   = false;
            download_column.Clickable   = false;
            download_column.Reorderable = false;
            download_column.Visible     = true;
            download_column.Widget      = download_image;

            CellRendererToggle download_renderer = new CellRendererToggle();

            download_renderer.Activatable = true;
            download_renderer.Toggled    += OnDownloadToggled;
            download_column.PackStart(download_renderer, true);

            download_column.SetCellDataFunc(
                download_renderer, new TreeCellDataFunc(DownloadCellToggle));

            /********************************************/
            activity_column = new TreeViewColumn();

            Gtk.Image activity_image = new Gtk.Image(
                PodcastPixbufs.ActivityColumnIcon
                );

            activity_image.Show();

            activity_column.Expand      = false;
            activity_column.Resizable   = false;
            activity_column.Clickable   = false;
            activity_column.Reorderable = false;
            activity_column.Visible     = true;
            activity_column.Widget      = activity_image;

            CellRendererPixbuf activity_renderer = new CellRendererPixbuf();

            activity_column.PackStart(activity_renderer, true);

            activity_column.SetCellDataFunc(activity_renderer,
                                            new TreeCellDataFunc(TrackCellActivity));

            /********************************************/

            CellRendererText podcast_title_renderer = new CellRendererText();
            CellRendererText feed_title_renderer    = new CellRendererText();
            CellRendererText pubdate_renderer       = new CellRendererText();

            podcast_title_column.PackStart(podcast_title_renderer, false);
            podcast_title_column.SetCellDataFunc(podcast_title_renderer,
                                                 new TreeCellDataFunc(TrackCellPodcastTitle));

            feed_title_column.PackStart(feed_title_renderer, true);
            feed_title_column.SetCellDataFunc(feed_title_renderer,
                                              new TreeCellDataFunc(TrackCellPodcastFeedTitle));

            pubdate_column.PackStart(pubdate_renderer, true);
            pubdate_column.SetCellDataFunc(pubdate_renderer,
                                           new TreeCellDataFunc(TrackCellPubDate));

            sort.SetSortFunc((int)Column.PodcastTitle,
                             new TreeIterCompareFunc(PodcastTitleTreeIterCompareFunc));
            sort.SetSortFunc((int)Column.FeedTitle,
                             new TreeIterCompareFunc(PodcastFeedTitleTreeIterCompareFunc));
            sort.SetSortFunc((int)Column.PubDate,
                             new TreeIterCompareFunc(PodcastPubDateTreeIterCompareFunc));

            InsertColumn(activity_column, (int)Column.Activity);
            InsertColumn(download_column, (int)Column.Download);
            InsertColumn(podcast_title_column, (int)Column.PodcastTitle);
            InsertColumn(feed_title_column, (int)Column.FeedTitle);
            InsertColumn(pubdate_column, (int)Column.PubDate);
        }
예제 #12
0
        public WindowBuilder()
        {
            _columnFilter = 0;
            _textToFilter = "";

            _processIdToKill = new List <int>();
            _listStore       = new ListStore(typeof(string), typeof(string), typeof(string), typeof(string),
                                             typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));

            Application.Init();

            _window = new Window("Label sample");
            _window.Resize(1300, 600);
            _window.Title = "Process Watch";
            _window.SetIconFromFile("icons/processIconSmall.png");
            _window.BorderWidth  = 5;
            _window.DeleteEvent += OnWindowClose;

            var aboutButton = new Button();
            var aboutIcon   = new Image();

            aboutIcon.Pixbuf        = new Pixbuf("icons/information.png");
            aboutButton.Image       = aboutIcon;
            aboutButton.TooltipText = "About Process Watch";
            aboutButton.Clicked    += (sender, args) =>
            {
                _aboutDialog.Show();
            };

            _aboutDialog = CreateAboutDialog();

            var filterButton = new Button();

            filterButton.Image       = new Image(Stock.Find, IconSize.Button);
            filterButton.TooltipText = "Filtration utilities";
            filterButton.Clicked    += (sender, args) =>
            {
                if (_filtrationHBox.IsVisible)
                {
                    _filtrationHBox.Hide();
                }
                else
                {
                    _filtrationHBox.ShowAll();
                }
            };

            var windowHBox = new HBox(false, 5);

            windowHBox.PackEnd(aboutButton, false, false, 0);
            windowHBox.PackEnd(filterButton, false, false, 0);

            _processNameEntry          = new Entry();
            _processNameEntry.Changed += OnChanged;

            _processIdEntry               = new Entry();
            _processIdEntry.Changed      += OnChanged;
            _processIdEntry.TextInserted += OnlyNumerical;

            // String values for the combobox - filtration direction
            _filtrationDirectionOptions = new[]
            {
                ">",
                "≥",
                "=",
                "≤",
                "<"
            };

            // String values for the combobox - memory usage units
            _memoryFiltrationDirectionUnits = new[]
            {
                "B",
                "KB",
                "MB",
                "GB"
            };


            _memoryFiltrationEntry = new Entry();
            _memoryFiltrationEntry.MaxWidthChars = 7;
            _memoryFiltrationEntry.WidthChars    = 7;
            _memoryFiltrationEntry.Changed      += OnChanged;
            _memoryFiltrationEntry.TextInserted += OnlyNumerical;

            _memoryFiltrationDirectionComboBox          = new ComboBox(_filtrationDirectionOptions);
            _memoryFiltrationDirectionComboBox.Changed += OnChanged;

            _memoryFiltrationUnitsComboBox          = new ComboBox(_memoryFiltrationDirectionUnits);
            _memoryFiltrationUnitsComboBox.Changed += OnChanged;

            _memoryFiltrationHbox = new HBox();
            _memoryFiltrationHbox.PackStart(_memoryFiltrationDirectionComboBox, false, false, 0);
            _memoryFiltrationHbox.PackStart(_memoryFiltrationEntry, false, false, 0);
            _memoryFiltrationHbox.PackStart(_memoryFiltrationUnitsComboBox, false, false, 0);


            _cpuFiltrationEntry = new Entry();
            _cpuFiltrationEntry.MaxWidthChars = 7;
            _cpuFiltrationEntry.WidthChars    = 7;
            _cpuFiltrationEntry.Changed      += OnChanged;
            _cpuFiltrationEntry.TextInserted += OnlyNumerical;

            _cpuFiltrationDirectionComboBox          = new ComboBox(_filtrationDirectionOptions);
            _cpuFiltrationDirectionComboBox.Changed += OnChanged;

            var cpuFiltrationLabel = new Label("%");

            _cpuFiltrationHbox = new HBox();
            _cpuFiltrationHbox.PackStart(_cpuFiltrationDirectionComboBox, false, false, 0);
            _cpuFiltrationHbox.PackStart(_cpuFiltrationEntry, false, false, 0);
            _cpuFiltrationHbox.PackStart(cpuFiltrationLabel, false, false, 0);


            _filtrationOptions = new[]
            {
                "All processes",
                "Filter by PID",
                "Filter by Process Name",
                "Filter by Memory Usage",
                "Filter by CPU usage",
            };

            var filtrationCombo = new ComboBox(_filtrationOptions);

            filtrationCombo.Changed += ComboOnChanged;

            _filtrationHBox = new HBox(false, 5);
            _filtrationHBox.PackStart(filtrationCombo, false, false, 0);


            string[] columnLabels =
            {
                "PID",
                "Process name",
                "Memory usage",
                "Priority",
                "User CPU Time",
                "Privileged CPU Time",
                "Total CPU Time",
                "CPU usage",
                "Threads",
                "Start Time"
            };


            _treeModelFilter             = new TreeModelFilter(_listStore, null);
            _treeModelFilter.VisibleFunc = Filter;

            var treeModelSort = new TreeModelSort(_treeModelFilter);

            treeModelSort.SetSortFunc(0, WindowBuilderHelper.IdSortFunc);
            treeModelSort.SetSortFunc(1, WindowBuilderHelper.ProcessNameSortFunc);
            treeModelSort.SetSortFunc(2, WindowBuilderHelper.MemoryUsageSortFunc);
            treeModelSort.SetSortFunc(3, WindowBuilderHelper.PrioritySortFunc);
            treeModelSort.SetSortFunc(4, WindowBuilderHelper.UserCpuTimeSortFunc);
            treeModelSort.SetSortFunc(5, WindowBuilderHelper.PrivilegedCpuTimeSortFunc);
            treeModelSort.SetSortFunc(6, WindowBuilderHelper.TotalCpuTimeSortFunc);
            treeModelSort.SetSortFunc(7, WindowBuilderHelper.CpuUsageSortFunc);
            treeModelSort.SetSortFunc(8, WindowBuilderHelper.ThreadCountSortFunc);
            treeModelSort.SetSortFunc(9, WindowBuilderHelper.StartTimeSortFunc);

            var treeView = new TreeView();

            treeView.Model              = treeModelSort;
            treeView.Selection.Mode     = SelectionMode.Multiple;
            treeView.Selection.Changed += OnSelectionChanged;
            treeView.TooltipColumn      = 1;

            // Create a scrollable window
            var scrolledWindow = new ScrolledWindow();

            scrolledWindow.Add(treeView);

            // Create a CellRendererText responsible for proper rendering cell data
            var cellRendererText = new CellRendererText();

            cellRendererText.Alignment = Pango.Alignment.Right;
            cellRendererText.Xalign    = 0.5f;

            // Load the _treeView with TreeViewColumns
            for (int i = 0; i < 10; i++)
            {
                var treeViewColumn = new TreeViewColumn();
                treeViewColumn.Clickable     = true;
                treeViewColumn.Resizable     = true;
                treeViewColumn.Title         = columnLabels[i];
                treeViewColumn.SortIndicator = true;
                treeViewColumn.Alignment     = 0.5f;
                treeViewColumn.Expand        = true;
                treeViewColumn.SortColumnId  = i;
                treeViewColumn.PackStart(cellRendererText, true);
                treeViewColumn.AddAttribute(cellRendererText, "text", i);

                switch (i)
                {
                case 0:
                    break;

                case 1:
                    _window.GetSize(out int width, out int height);
                    treeViewColumn.MaxWidth = Math.Abs(width / 2);
                    break;

                case 2:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.MemoryUsageFormatter);
                    break;

                case 3:
                    break;

                case 4:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.UserCpuTimeFormatter);
                    break;

                case 5:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.PrivilegedCpuTimeFormatter);
                    break;

                case 6:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.TotalCpuTimeFormatter);
                    break;

                case 7:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.CpuUsageFormatter);
                    break;

                case 8:
                    break;

                case 9:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.StartTimeFormatter);
                    break;
                }

                treeView.AppendColumn(treeViewColumn);
            }

            var killButton = new Button("Kill process");

            killButton.Clicked += KillProcess;

            var windowVBox = new VBox(false, 5);

            windowVBox.PackStart(windowHBox, false, false, 0);
            windowVBox.PackStart(_filtrationHBox, false, false, 0);
            windowVBox.PackStart(scrolledWindow, true, true, 0);
            windowVBox.PackStart(killButton, false, false, 0);

            _window.Add(windowVBox);

            // Create an instance of the object Updater
            _processGrabber = new ProcessGrabber();
            // Add a callback executed when _processGrabber takes process data.
            // The callback clears the _treeView content and loads new data
            // Before clearing the _treeView content the callback saves the current scroll position
            _processGrabber.OnResult += (sender, processList) =>
            {
                Application.Invoke(delegate
                {
                    _currentScrollPosition = treeView.Vadjustment.Value;
                    StoreClear();
                    LoadStore(processList);

                    treeView.ShowAll();
                });
            };

            // Add a callback executed after 'Changed' event raised after changing the position of the _treeView
            // When the _treeView content is reloaded the previous scroll position is updated
            treeView.Vadjustment.Changed += (sender, args) =>
            {
                treeView.Vadjustment.Value = _currentScrollPosition;
            };

            // Start the Timer process responsible for grabbing process data periodically
            _processGrabber.Run();

            treeView.ShowAll();
            _window.ShowAll();

            // Hide widgets related to process filtration
            _filtrationHBox.Hide();
        }
예제 #13
0
        public SearchResultsPage(FileSearch search)
        {
            VPaned         paned;
            TreeViewColumn column;
            ToolItem       spacerItem;
            ToolItem       filterItem;
            Alignment      filterAlignment;
            ToolButton     searchAgainToolButton;

            this.search = search;

            downloadToolButton             = new ToolButton(new Image("gtk-save", IconSize.LargeToolbar), "Download");
            downloadToolButton.IsImportant = true;
            downloadToolButton.Sensitive   = false;
            downloadToolButton.Clicked    += DownloadToolButtonClicked;

            searchAgainToolButton             = new ToolButton(new Image("gtk-refresh", IconSize.LargeToolbar), "Search Again");
            searchAgainToolButton.IsImportant = true;
            searchAgainToolButton.Clicked    += SearchAgainToolButtonClicked;

            spacerItem        = new ToolItem();
            spacerItem.Expand = true;

            filterButton          = new ToggleButton("Filter Results");
            filterButton.Image    = new Image(Gui.LoadIcon(16, "application-x-executable"));
            filterButton.Toggled += delegate(object o, EventArgs args) {
                this.ShowFilter = filterButton.Active;
            };

            filterAlignment = new Alignment(0.5f, 0.5f, 0, 0);
            filterAlignment.Add(filterButton);

            filterItem = new ToolItem();
            filterItem.Add(filterAlignment);

            browseToolButton             = new ToolButton(new Image("gtk-open", IconSize.LargeToolbar), "Browse");
            browseToolButton.IsImportant = true;
            browseToolButton.Sensitive   = false;
            browseToolButton.Clicked    += BrowseToolButtonClicked;

            toolbar = new Toolbar();
            toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
            toolbar.Insert(downloadToolButton, -1);
            toolbar.Insert(browseToolButton, -1);
            toolbar.Insert(spacerItem, -1);
            toolbar.Insert(filterItem, -1);
            toolbar.Insert(new SeparatorToolItem(), -1);
            toolbar.Insert(searchAgainToolButton, -1);
            toolbar.ShowAll();

            this.PackStart(toolbar, false, false, 0);

            resultCountByTypeCache = new Dictionary <FilterType, int>();

            Gdk.Pixbuf audioPixbuf = Gui.LoadIcon(16, "audio-x-generic");
            Gdk.Pixbuf videoPixbuf = Gui.LoadIcon(16, "video-x-generic");
            Gdk.Pixbuf imagePixbuf = Gui.LoadIcon(16, "image-x-generic");
            Gdk.Pixbuf docPixbuf   = Gui.LoadIcon(16, "x-office-document");
            unknownPixbuf = Gui.LoadIcon(16, "text-x-generic");
            folderPixbuf  = Gui.LoadIcon(16, "folder");

            typeStore = new ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(FilterType));
            typeStore.AppendValues(null, "All Results", FilterType.All);
            typeStore.AppendValues(null, "-");
            typeStore.AppendValues(audioPixbuf, "Audio", FilterType.Audio);
            typeStore.AppendValues(videoPixbuf, "Video", FilterType.Video);
            typeStore.AppendValues(imagePixbuf, "Images", FilterType.Image);
            typeStore.AppendValues(docPixbuf, "Documents", FilterType.Document);
            typeStore.AppendValues(folderPixbuf, "Folders", FilterType.Folder);
            typeStore.AppendValues(unknownPixbuf, "Other", FilterType.Other);

            typeTree = new TreeView();
            typeTree.HeadersVisible   = false;
            typeTree.RowSeparatorFunc = delegate(TreeModel m, TreeIter i) {
                string text = (string)m.GetValue(i, 1);
                return(text == "-");
            };
            typeTree.Selection.Changed += TypeSelectionChanged;

            typeTree.Model = typeStore;

            CellRendererPixbuf pixbufCell    = new CellRendererPixbuf();
            CellRendererText   textCell      = new CellRendererText();
            CellRendererText   countTextCell = new CellRendererText();

            countTextCell.Sensitive = false;
            countTextCell.Alignment = Pango.Alignment.Right;
            countTextCell.Xalign    = 1;

            column = new TreeViewColumn();
            column.PackStart(pixbufCell, false);
            column.PackStart(textCell, true);
            column.PackStart(countTextCell, false);
            column.AddAttribute(pixbufCell, "pixbuf", 0);
            column.AddAttribute(textCell, "text", 1);
            column.SetCellDataFunc(countTextCell, new TreeCellDataFunc(TypeCountCellFunc));

            typeTree.AppendColumn(column);

            TreeView artistTree = new TreeView();

            artistTree.HeadersVisible = false;

            TreeView albumTree = new TreeView();

            albumTree.HeadersVisible = false;

            HBox topBox = new HBox();

            topBox.PackStart(Gui.AddScrolledWindow(typeTree), true, true, 0);
            topBox.PackStart(Gui.AddScrolledWindow(artistTree), true, true, 1);
            topBox.PackStart(Gui.AddScrolledWindow(albumTree), true, true, 0);
            topBox.Homogeneous = true;

            resultsStore              = new ListStore(typeof(SearchResult));
            resultsStore.RowInserted += delegate {
                Refilter();
            };
            resultsStore.RowDeleted += delegate {
                Refilter();
            };
            resultsTree = new TreeView();
            resultsTree.RowActivated      += resultsTree_RowActivated;
            resultsTree.ButtonPressEvent  += resultsTree_ButtonPressEvent;
            resultsTree.Selection.Changed += ResultsTreeSelectionChanged;

            imageColumns      = new List <TreeViewColumn>();
            audioColumns      = new List <TreeViewColumn>();
            videoColumns      = new List <TreeViewColumn>();
            fileOnlyColumns   = new List <TreeViewColumn>();
            folderOnlyColumns = new List <TreeViewColumn>();

            column              = new TreeViewColumn();
            column.Title        = "File Name";
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Autosize;
            column.Resizable    = true;
            column.SortColumnId = 0;
            //resultsTree.ExpanderColumn = column;

            CellRenderer cell = new CellRendererPixbuf();

            column.PackStart(cell, false);
            column.SetCellDataFunc(cell, new TreeCellDataFunc(IconFunc));

            cell = new CellRendererText();
            column.PackStart(cell, true);
            column.SetCellDataFunc(cell, new TreeCellDataFunc(FileNameFunc));

            resultsTree.AppendColumn(column);

            column              = resultsTree.AppendColumn("Codec", new CellRendererText(), new TreeCellDataFunc(CodecFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 120;
            column.Resizable    = true;
            column.SortColumnId = 1;
            videoColumns.Add(column);

            column              = resultsTree.AppendColumn("Format", new CellRendererText(), new TreeCellDataFunc(FormatFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 90;
            column.Resizable    = true;
            column.SortColumnId = 2;
            imageColumns.Add(column);

            column              = resultsTree.AppendColumn("Resolution", new CellRendererText(), new TreeCellDataFunc(ResolutionFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 90;
            column.Resizable    = true;
            column.SortColumnId = 3;
            videoColumns.Add(column);
            imageColumns.Add(column);

            column              = resultsTree.AppendColumn("Artist", new CellRendererText(), new TreeCellDataFunc(ArtistFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 110;
            column.Resizable    = true;
            column.SortColumnId = 4;
            audioColumns.Add(column);

            column              = resultsTree.AppendColumn("Album", new CellRendererText(), new TreeCellDataFunc(AlbumFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 110;
            column.Resizable    = true;
            column.SortColumnId = 5;
            audioColumns.Add(column);

            column              = resultsTree.AppendColumn("Bitrate", new CellRendererText(), new TreeCellDataFunc(BitrateFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 70;
            column.Resizable    = true;
            column.SortColumnId = 6;
            audioColumns.Add(column);

            column              = resultsTree.AppendColumn("Size", new CellRendererText(), new TreeCellDataFunc(SizeFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 70;
            column.SortColumnId = 7;
            column.Resizable    = true;
            fileOnlyColumns.Add(column);

            column              = resultsTree.AppendColumn("Sources", new CellRendererText(), new TreeCellDataFunc(SourcesFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 85;
            column.SortColumnId = 8;
            column.Resizable    = true;
            fileOnlyColumns.Add(column);

            column              = resultsTree.AppendColumn("User", new CellRendererText(), new TreeCellDataFunc(UserFunc));
            column.Clickable    = true;
            column.Sizing       = TreeViewColumnSizing.Fixed;
            column.FixedWidth   = 85;
            column.SortColumnId = 8;
            column.Resizable    = true;
            folderOnlyColumns.Add(column);

            column              = resultsTree.AppendColumn("Full Path", new CellRendererText(), new TreeCellDataFunc(FullPathFunc));
            column.Clickable    = true;
            column.Resizable    = true;
            column.SortColumnId = 9;

            column              = resultsTree.AppendColumn("Info Hash", new CellRendererText(), new TreeCellDataFunc(InfoHashFunc));
            column.Clickable    = true;
            column.Resizable    = true;
            column.SortColumnId = 10;
            fileOnlyColumns.Add(column);

            resultsFilter             = new TreeModelFilter(resultsStore, null);
            resultsFilter.VisibleFunc = resultsFilterFunc;

            resultsSort = new TreeModelSort(resultsFilter);
            for (int x = 0; x < resultsTree.Columns.Length; x++)
            {
                resultsSort.SetSortFunc(x, resultsSortFunc);
            }
            resultsTree.Model = resultsSort;

            ScrolledWindow resultsTreeSW = new ScrolledWindow();

            resultsTreeSW.Add(resultsTree);

            paned = new VPaned();
            paned.Add1(topBox);
            paned.Add2(resultsTreeSW);
            paned.Position = 160;
            paned.ShowAll();

            filterWidget = new FilterWidget(search);
            filterWidget.FiltersChanged += filterWidget_FiltersChanged;
            filterWidget.Hidden         += filterWidget_Hidden;

            this.PackStart(filterWidget, false, false, 0);
            this.PackStart(paned, true, true, 0);

            TypeSelectionChanged(typeTree, EventArgs.Empty);

            search.NewResults     += (EventHandler <SearchResultsEventArgs>)DispatchService.GuiDispatch(new EventHandler <SearchResultsEventArgs>(search_NewResults));
            search.ClearedResults += (EventHandler)DispatchService.GuiDispatch(new EventHandler(search_ClearedResults));

            resultPopupMenu = new Menu();

            browseResultMenuItem            = new ImageMenuItem("Browse");
            browseResultMenuItem.Image      = new Image(Gui.LoadIcon(16, "document-open"));
            browseResultMenuItem.Activated += BrowseToolButtonClicked;
            resultPopupMenu.Append(browseResultMenuItem);

            downloadResultMenuItem            = new ImageMenuItem("Download");
            downloadResultMenuItem.Image      = new Image(Gui.LoadIcon(16, "go-down"));
            downloadResultMenuItem.Activated += DownloadToolButtonClicked;
            resultPopupMenu.Append(downloadResultMenuItem);

            resultPropertiesMenuItem            = new ImageMenuItem(Gtk.Stock.Properties, null);
            resultPropertiesMenuItem.Activated += FilePropertiesButtonClicked;
            resultPopupMenu.Append(resultPropertiesMenuItem);
        }
예제 #14
0
        /// <summary>
        /// Constructor. Initialises the jobs TreeView and the controls associated with it.
        /// </summary>
        /// <param name="owner"></param>
        public CloudJobView(ViewBase owner) : base(owner)
        {
            dl           = new CloudDownloadView(this);
            dl.Download += OnDoDownload;
            dl.Visible   = false;

            // Give the ListStore 1 more column than the tree view.
            // This last column displays the job owner but is not shown by the TreeView in its own column.
            store = new ListStore(Enumerable.Repeat(typeof(string), Enum.GetValues(typeof(Columns)).Length + 1).ToArray());
            tree  = new Gtk.TreeView()
            {
                CanFocus = true, RubberBanding = true
            };
            tree.Selection.Mode = SelectionMode.Multiple;

            for (int i = 0; i < columnTitles.Length; i++)
            {
                TreeViewColumn col = new TreeViewColumn
                {
                    Title        = columnTitles[i],
                    SortColumnId = i,
                    Resizable    = true,
                    Sizing       = TreeViewColumnSizing.GrowOnly
                };
                CellRendererText cell = new CellRendererText();
                col.PackStart(cell, false);
                col.AddAttribute(cell, "text", i);
                col.SetCellDataFunc(cell, OnSetCellData);
                tree.AppendColumn(col);
            }

            // this filter holds the model (data) and is used to filter jobs based on whether
            // they were submitted by the user
            filterOwner = new TreeModelFilter(store, null)
            {
                VisibleFunc = FilterOwnerFunc
            };
            filterOwner.Refilter();

            // the filter then goes into this TreeModelSort, which is used to sort results when
            // the user clicks on a column header
            sort = new TreeModelSort(filterOwner)
            {
                // By default, sort by start time descending.
                DefaultSortFunc = (model, a, b) => - 1 * SortData(model, a, b, (int)Columns.StartTime)
            };
            for (int i = 0; i < columnTitles.Length; i++)
            {
                sort.SetSortFunc(i, (model, a, b) => SortData(model, a, b, i));
            }

            // the tree holds the sorted, filtered data
            tree.Model = sort;

            // the tree goes into this ScrolledWindow, allowing users to scroll down
            // to view more jobs
            ScrolledWindow scroll = new ScrolledWindow();

            scroll.Add(tree);

            // never allow horizontal scrolling, and only allow vertical scrolling when needed
            scroll.HscrollbarPolicy = PolicyType.Automatic;
            scroll.VscrollbarPolicy = PolicyType.Automatic;

            // The scrolled window goes into this frame to distinguish the job view
            // from the controls beside it.
            Frame treeContainer = new Frame("Cloud Jobs");

            treeContainer.Add(scroll);

            chkMyJobsOnly          = new CheckButton("Display my jobs only");
            chkMyJobsOnly.Toggled += OnToggleFilter;
            // Display only the user's jobs by default.
            chkMyJobsOnly.Active = true;
            chkMyJobsOnly.Yalign = 0;

            downloadProgress          = new ProgressBar(new Adjustment(0, 0, 1, 0.01, 0.01, 1));
            downloadProgressContainer = new HBox();
            downloadProgressContainer.PackStart(new Label("Downloading: "), false, false, 0);
            downloadProgressContainer.PackStart(downloadProgress, false, false, 0);

            loadingProgress = new ProgressBar(new Adjustment(0, 0, 100, 0.01, 0.01, 100));
            loadingProgress.Adjustment.Lower = 0;
            loadingProgress.Adjustment.Upper = 100;

            btnChangeDownloadDir          = new Button("Change Download Directory");
            btnChangeDownloadDir.Clicked += OnChangeDownloadPath;

            Table tblButtonContainer = new Table(1, 1, false);

            tblButtonContainer.Attach(btnChangeDownloadDir, 0, 1, 0, 1, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);

            btnDownload          = new Button("Download");
            btnDownload.Clicked += OnDownloadJobs;
            HBox downloadButtonContainer = new HBox();

            downloadButtonContainer.PackStart(btnDownload, false, true, 0);

            btnDelete          = new Button("Delete Job(s)");
            btnDelete.Clicked += OnDeleteJobs;
            HBox deleteButtonContainer = new HBox();

            deleteButtonContainer.PackStart(btnDelete, false, true, 0);

            btnStop          = new Button("Stop Job(s)");
            btnStop.Clicked += OnStopJobs;
            HBox stopButtonContainer = new HBox();

            stopButtonContainer.PackStart(btnStop, false, true, 0);

            btnSetup          = new Button("Credentials");
            btnSetup.Clicked += OnSetupClicked;
            HBox setupButtonContainer = new HBox();

            setupButtonContainer.PackStart(btnSetup, false, true, 0);

            jobLoadProgressContainer = new HBox();
            jobLoadProgressContainer.PackStart(new Label("Loading Jobs: "), false, false, 0);
            jobLoadProgressContainer.PackStart(loadingProgress, false, false, 0);

            VBox controlsContainer = new VBox();

            controlsContainer.PackStart(chkMyJobsOnly, false, false, 0);
            controlsContainer.PackStart(downloadButtonContainer, false, false, 0);
            controlsContainer.PackStart(stopButtonContainer, false, false, 0);
            controlsContainer.PackStart(deleteButtonContainer, false, false, 0);
            controlsContainer.PackStart(setupButtonContainer, false, false, 0);
            controlsContainer.PackEnd(tblButtonContainer, false, false, 0);

            HBox hboxPrimary = new HBox();

            hboxPrimary.PackStart(treeContainer, true, true, 0);
            hboxPrimary.PackStart(controlsContainer, false, true, 0);


            VBox vboxPrimary = new VBox();

            vboxPrimary.PackStart(hboxPrimary);
            vboxPrimary.PackEnd(jobLoadProgressContainer, false, false, 0);
            vboxPrimary.PackEnd(downloadProgressContainer, false, false, 0);

            mainWidget            = vboxPrimary;
            mainWidget.Destroyed += OnDestroyed;
            vboxPrimary.ShowAll();

            downloadProgressContainer.HideAll();
            HideLoadingProgressBar();
        }