Exemplo n.º 1
0
        public StatusIcon()
        {
            CreateAnimationFrames();

#if HAVE_APP_INDICATOR
            this.indicator = new ApplicationIndicator("dataspacesync",
                                                      "dataspacesync-process-syncing-i", Category.ApplicationStatus);

            this.indicator.Status = Status.Active;
#else
            this.status_icon        = new Gtk.StatusIcon();
            this.status_icon.Pixbuf = this.animation_frames [0];

            this.status_icon.Activate  += OpenFolderDelegate(null); // Primary mouse button click shows default folder
            this.status_icon.PopupMenu += ShowMenu;                 // Secondary mouse button click
#endif

            CreateMenu();


            Controller.UpdateIconEvent += delegate(int icon_frame) {
                Application.Invoke(delegate {
                    if (icon_frame > -1)
                    {
#if HAVE_APP_INDICATOR
                        string icon_name = "dataspacesync-process-syncing-";
                        for (int i = 0; i <= icon_frame; i++)
                        {
                            icon_name += "i";
                        }

                        this.indicator.IconName = icon_name;

                        // Force update of the icon
                        this.indicator.Status = Status.Attention;
                        this.indicator.Status = Status.Active;
#else
                        this.status_icon.Pixbuf = this.animation_frames [icon_frame];
#endif
                    }
                    else
                    {
#if HAVE_APP_INDICATOR
                        this.indicator.IconName = "dataspacesync-process-syncing-error";

                        // Force update of the icon
                        this.indicator.Status = Status.Attention;
                        this.indicator.Status = Status.Active;
#else
                        this.status_icon.Pixbuf = UIHelpers.GetIcon("dataspacesync-process-syncing-error", 24);
#endif
                    }
                });
            };

            Controller.UpdateStatusItemEvent += delegate(string state_text) {
                if (!IsHandleCreated)
                {
                    return;
                }
                Application.Invoke(delegate {
                    (this.state_item.Child as Label).Text = state_text;
                    this.state_item.ShowAll();
                });
            };

            Controller.UpdateMenuEvent += delegate(IconState state) {
                Application.Invoke(delegate {
                    CreateMenu();
                });
            };

            Controller.UpdateSuspendSyncFolderEvent += delegate(string reponame) {
                if (!IsHandleCreated)
                {
                    return;
                }
                Application.Invoke(delegate {
                    foreach (var menuItem in this.menu.Children)
                    {
                        if (menuItem is CmisSyncMenuItem && reponame.Equals(((CmisSyncMenuItem)menuItem).RepoName))
                        {
                            foreach (Repository aRepo in Program.Controller.Repositories)
                            {
                                if (aRepo.Name.Equals(reponame))
                                {
                                    Menu submenu = (Menu)((CmisSyncMenuItem)menuItem).Submenu;
                                    CmisSyncMenuItem pauseItem = (CmisSyncMenuItem)submenu.Children[1];
                                    setSyncItemState(pauseItem, aRepo.Status);
                                    break;
                                }
                            }
                            break;
                        }
                    }
                });
            };

            Controller.UpdateTransmissionMenuEvent += delegate {
                if (!IsHandleCreated)
                {
                    return;
                }
                Application.Invoke(delegate {
                    List <FileTransmissionEvent> transmissionEvents = Program.Controller.ActiveTransmissions();
                    if (transmissionEvents.Count != 0)
                    {
                        this.state_item.Sensitive = true;

                        Menu submenu            = new Menu();
                        this.state_item.Submenu = submenu;

                        foreach (FileTransmissionEvent e in transmissionEvents)
                        {
                            ImageMenuItem transmission_sub_menu_item = new TransmissionMenuItem(e);
                            submenu.Add(transmission_sub_menu_item);
                            state_item.ShowAll();
                        }
                    }
                    else
                    {
                        this.state_item.Submenu   = null;
                        this.state_item.Sensitive = false;
                    }
                });
            };
        }
Exemplo n.º 2
0
        public StatusIcon () : base ()
        {
            using (var a = new NSAutoreleasePool ())
            {
                CreateAnimationFrames ();

                this.status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28);
                this.status_item.HighlightMode = true;
                this.status_item.Image = this.animation_frames [0];

                this.status_item.Image               = this.animation_frames [0];
                this.status_item.Image.Size          = new SizeF (16, 16);

                CreateMenu ();
            }
            

            Controller.UpdateIconEvent += delegate (int icon_frame) {
                using (var a = new NSAutoreleasePool ())
                {
                    BeginInvokeOnMainThread (delegate {
                        if (icon_frame > -1) {
                            this.status_item.Image               = this.animation_frames [icon_frame];
                            this.status_item.Image.Size          = new SizeF (16, 16);

                        } else {
                            this.status_item.Image               = this.error_image;
                            this.status_item.Image.Size          = new SizeF (16, 16);
                        }
                    });
                }
            };

            Controller.UpdateStatusItemEvent += delegate (string state_text) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.state_item.Title = state_text;
                    });
                }
            };

            Controller.UpdateMenuEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (() => CreateMenu ());
                }
            };

            Controller.UpdateSuspendSyncFolderEvent += delegate(string reponame)
            {
                using (var a = new NSAutoreleasePool()){
                    InvokeOnMainThread(delegate {
                        NSMenuItem PauseItem;
                        if(FolderItems.TryGetValue(reponame,out PauseItem)){
                            setSyncItemState(PauseItem, getSyncStatus(reponame));
                        }
                    });
                }
            };

            // TODO Need to implement this method like the COCOA way to do it
            Controller.UpdateTransmissionMenuEvent += delegate
            {
                using (var a = new NSAutoreleasePool()) {
                    InvokeOnMainThread(delegate {
                        List<FileTransmissionEvent> transmissions =    Program.Controller.ActiveTransmissions();
                        NSMenu transmissionmenu = new NSMenu();
                        foreach(FileTransmissionEvent transmission in transmissions) {
                            NSMenuItem transmissionItem = new TransmissionMenuItem(transmission);
                            transmissionmenu.AddItem(transmissionItem);
                        }
                        if(transmissions.Count > 0) {
                            state_item.Submenu = transmissionmenu;
                            state_item.Enabled = true;
                        }else{
                            state_item.Enabled = false;
                        }
                    });
                }
            };
        }
Exemplo n.º 3
0
        public StatusIcon() : base()
        {
            using (var a = new NSAutoreleasePool())
            {
                CreateAnimationFrames();

                this.status_item = NSStatusBar.SystemStatusBar.CreateStatusItem(28);
                this.status_item.HighlightMode = true;
                this.status_item.Image         = this.animation_frames [0];

                this.status_item.Image               = this.animation_frames [0];
                this.status_item.Image.Size          = new SizeF(16, 16);
                this.status_item.AlternateImage      = this.animation_frames_active [0];
                this.status_item.AlternateImage.Size = new SizeF(16, 16);

                CreateMenu();
            }


            Controller.UpdateIconEvent += delegate(int icon_frame) {
                using (var a = new NSAutoreleasePool())
                {
                    BeginInvokeOnMainThread(delegate {
                        if (icon_frame > -1)
                        {
                            this.status_item.Image               = this.animation_frames [icon_frame];
                            this.status_item.Image.Size          = new SizeF(16, 16);
                            this.status_item.AlternateImage      = this.animation_frames_active [icon_frame];
                            this.status_item.AlternateImage.Size = new SizeF(16, 16);
                        }
                        else
                        {
                            this.status_item.Image               = this.error_image;
                            this.status_item.AlternateImage      = this.error_image_active;
                            this.status_item.Image.Size          = new SizeF(16, 16);
                            this.status_item.AlternateImage.Size = new SizeF(16, 16);
                        }
                    });
                }
            };

            Controller.UpdateStatusItemEvent += delegate(string state_text) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        this.state_item.Title = state_text;
                    });
                }
            };

            Controller.UpdateMenuEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(() => CreateMenu());
                }
            };

            Controller.UpdateSuspendSyncFolderEvent += delegate(string reponame)
            {
                using (var a = new NSAutoreleasePool()){
                    InvokeOnMainThread(delegate {
                        NSMenuItem PauseItem;
                        if (FolderItems.TryGetValue(reponame, out PauseItem))
                        {
                            setSyncItemState(PauseItem, getSyncStatus(reponame));
                        }
                    });
                }
            };

            // TODO Need to implement this method like the COCOA way to do it
            Controller.UpdateTransmissionMenuEvent += delegate
            {
                using (var a = new NSAutoreleasePool()) {
                    InvokeOnMainThread(delegate {
                        List <FileTransmissionEvent> transmissions = Program.Controller.ActiveTransmissions();
                        NSMenu transmissionmenu = new NSMenu();
                        foreach (FileTransmissionEvent transmission in transmissions)
                        {
                            NSMenuItem transmissionItem = new TransmissionMenuItem(transmission);
                            transmissionmenu.AddItem(transmissionItem);
                        }
                        if (transmissions.Count > 0)
                        {
                            state_item.Submenu = transmissionmenu;
                            state_item.Enabled = true;
                        }
                        else
                        {
                            state_item.Enabled = false;
                        }
                    });
                }
            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set up the controller to create menu elements on update.
        /// </summary>
        private void CreateInvokeMethods()
        {
            // Icon.
            Controller.UpdateIconEvent += delegate(int icon_frame)
            {
                if (IsHandleCreated)
                {
                    BeginInvoke((Action) delegate
                    {
                        if (icon_frame < 0)
                        {
                            this.trayicon.Icon = SystemIcons.Error;
                            return;
                        }

                        if (icon_frame > 0)
                        {
                            this.trayicon.Icon = animationFrames[icon_frame];
                            return;
                        }

                        if (Controller.Warning)
                        {
                            this.trayicon.Icon = SystemIcons.Warning;
                            return;
                        }

                        this.trayicon.Icon = animationFrames[icon_frame];
                        return;
                    });
                }
            };

            // Status item.
            Controller.UpdateStatusItemEvent += delegate(string state_text)
            {
                if (IsHandleCreated)
                {
                    BeginInvoke((Action) delegate
                    {
                        this.stateItem.Text = state_text;
                        this.trayicon.Text  = String.Format("{0}\n{1}", Properties_Resources.ApplicationName, state_text);
                    });
                }
            };

            // Menu.
            Controller.UpdateMenuEvent += delegate(IconState state)
            {
                if (IsHandleCreated)
                {
                    BeginInvoke((Action) delegate
                    {
                        CreateMenu();
                    });
                }
            };

            // Repo Submenu.
            Controller.UpdateSuspendSyncFolderEvent += delegate(string reponame)
            {
                if (IsHandleCreated)
                {
                    BeginInvoke((Action) delegate
                    {
                        ToolStripMenuItem repoitem = (ToolStripMenuItem)this.traymenu.Items["tsmi" + reponame];
                        ToolStripMenuItem syncitem = (ToolStripMenuItem)repoitem.DropDownItems[2];
                        foreach (Repository aRepo in Program.Controller.Repositories)
                        {
                            if (aRepo.Name == reponame)
                            {
                                setSyncItemState(syncitem, aRepo.Status);
                                break;
                            }
                        }
                    });
                }
            };

            //Transmission Submenu.
            Controller.UpdateTransmissionMenuEvent += delegate
            {
                if (IsHandleCreated)
                {
                    BeginInvoke((Action) delegate
                    {
                        this.stateItem.DropDownItems.Clear();
                        if (ConfigManager.CurrentConfig.Notifications)
                        {
                            List <FileTransmissionEvent> transmissions = Program.Controller.ActiveTransmissions();
                            foreach (FileTransmissionEvent transmission in transmissions)
                            {
                                ToolStripMenuItem transmission_sub_menu_item = new TransmissionMenuItem(transmission, this);
                                this.stateItem.DropDownItems.Add(transmission_sub_menu_item);
                            }
                            if (transmissions.Count > 0)
                            {
                                this.stateItem.Enabled = true;
                            }
                            else
                            {
                                this.stateItem.Enabled = false;
                            }
                        }
                        else
                        {
                            this.stateItem.Enabled = false;
                        }
                    });
                }
            };
        }