Example #1
0
        public override void Dispose()
        {
            OwnedFile.RemoveAction(OnOwnedFileMount);
            OwnedFile = null;

            base.Dispose();
        }
Example #2
0
        public static JiraConfig GetJiraConfig(this OwnedItem item)
        {
            if (!item.AttachedFiles.Any(f => f.Name == Global.JiraConfigAttachmentName))
            {
                return(null);
            }
            OwnedFile file        = item.AttachedFiles.First(x => x.Name == Global.JiraConfigAttachmentName);
            string    fileContent = Encoding.Default.GetString(file.EmbeddedContent.Data);

            return(JsonConvert.DeserializeObject <JiraConfig>(fileContent));
        }
Example #3
0
        protected override bool OnCanAcceptDrop(IEnumerable <string> uris)
        {
            bool can_write = false;

            try {
                if (!string.IsNullOrEmpty(OwnedFile.Path))
                {
                    can_write = OwnedFile.QueryInfo <bool> ("access::can-write");
                }
            } catch { }

            // only accept the drop if it's a folder, and we can write to it
            return(is_folder && can_write);
        }
Example #4
0
        protected FileDockItem(string uri)
        {
            this.uri  = uri;
            OwnedFile = FileFactory.NewForUri(uri);

            OnOwnedFileMount = new Action(() => {
                UpdateInfo();
                OnPaintNeeded();
            });

            // update this file on successful mount
            OwnedFile.AddMountAction(OnOwnedFileMount);

            UpdateInfo();
        }
Example #5
0
        protected override bool OnAcceptDrop(IEnumerable <string> uris)
        {
            // verify there is enough space to move/copy everything
            long fileSize = 0;

            foreach (File file in uris.Select(uri => FileFactory.NewForUri(uri)))
            {
                if (!file.Exists)
                {
                    continue;
                }
                fileSize += file.GetSize();
            }

            if ((ulong)fileSize > OwnedFile.QueryInfo <ulong> (FilesystemFreeKey))
            {
                Docky.Services.Log.Notify(Catalog.GetString("Error performing drop action"), Gtk.Stock.DialogError, Catalog.GetString("Not enough free space on destination."));
                return(true);
            }

            DockServices.System.RunOnThread(() => {
                // do the move/copy
                string ownedFSID  = OwnedFile.QueryInfo <string> (FilesystemIDKey);
                Notification note = null;
                bool performing   = true;

                foreach (File file in uris.Select(uri => FileFactory.NewForUri(uri)))
                {
                    if (!file.Exists)
                    {
                        continue;
                    }

                    long cur = 0, tot = 10;

                    if (note == null)
                    {
                        note = Docky.Services.Log.Notify("", file.Icon(), string.Format("{0}% " + Catalog.GetString("Complete") + "...", cur / tot));

                        GLib.Timeout.Add(250, () => {
                            note.Body = string.Format("{0:00.0}% ", ((float)Math.Min(cur, tot) / tot) * 100) + Catalog.GetString("Complete") + "...";
                            return(performing);
                        });
                    }

                    string nameAfterMove = file.NewFileName(OwnedFile);

                    try {
                        // check the filesystem IDs, if they are the same, we move, otherwise we copy.
                        if (ownedFSID == file.QueryInfo <string> (FilesystemIDKey))
                        {
                            note.Summary = Catalog.GetString("Moving") + string.Format(" {0}...", file.Basename);
                            file.Move(OwnedFile.GetChild(nameAfterMove), FileCopyFlags.NofollowSymlinks | FileCopyFlags.AllMetadata | FileCopyFlags.NoFallbackForMove, null, (current, total) => {
                                cur = current;
                                tot = total;
                            });
                        }
                        else
                        {
                            note.Summary = Catalog.GetString("Copying") + string.Format(" {0}...", file.Basename);
                            file.Copy_Recurse(OwnedFile.GetChild(nameAfterMove), 0, (current, total) => {
                                cur = current;
                                tot = total;
                            });
                        }
                    } catch (Exception e) {
                        // until we use a new version of GTK# which supports getting the GLib.Error code
                        // this is about the best we can do.
                        Docky.Services.Log.Notify(Catalog.GetString("Error performing drop action"), Gtk.Stock.DialogError, e.Message);
                        Log <FileDockItem> .Error("Error performing drop action: " + e.Message);
                        Log <FileDockItem> .Debug("Error moving file '" + file.Path + "' to '" + OwnedFile.GetChild(nameAfterMove) + "'");
                        Log <FileDockItem> .Debug(e.StackTrace);
                    }

                    performing = false;
                    note.Body  = string.Format("100% {0}.", Catalog.GetString("Complete"));
                }
            });
            return(true);
        }
Example #6
0
        // this should be called after a successful mount of the file
        public void UpdateInfo()
        {
            is_folder = OwnedFile.QueryFileType(0, null) == FileType.Directory;

            // only check the icon if it's mounted (ie: .Path != null)
            if (!string.IsNullOrEmpty(OwnedFile.Path))
            {
                string   customIconPath = OwnedFile.QueryInfo <string> (CustomIconKey);
                string   thumbnailPath  = OwnedFile.QueryInfo <string> (ThumbnailPathKey);
                string[] emblems        = OwnedFile.QueryInfo <string[]> (EmblemsKey);

                // if the icon lives inside the folder (or one of its subdirs) then this
                // is actually a relative path... not a file uri.
                // we need to make this a file:// uri regardless.
                if (!string.IsNullOrEmpty(customIconPath))
                {
                    if (!customIconPath.StartsWith("file://"))
                    {
                        customIconPath = System.IO.Path.Combine(OwnedFile.StringUri(), customIconPath);
                    }
                    Icon = customIconPath;
                }
                else if (!string.IsNullOrEmpty(thumbnailPath))
                {
                    Icon = thumbnailPath;
                }
                else
                {
                    Icon = OwnedFile.Icon();
                }

                // process the emblems
                if (emblems.Length != 0)
                {
                    int [] emblemPositions = { 2, 1, 0, 3 };
                    int    i = 0;
                    emblems.Reverse()
                    .Where(e => !string.IsNullOrEmpty(e))
                    .Take(4)
                    .ToList()
                    .ForEach(e => {
                        AddEmblem(new IconEmblem(emblemPositions[i], string.Format("emblem-{0}", e), 128));
                        i++;
                    });
                }
            }
            else if (!string.IsNullOrEmpty(backup_icon))
            {
                Icon = backup_icon;
            }
            else
            {
                Icon = "";
            }

            if (string.IsNullOrEmpty(ForcedHoverText))
            {
                HoverText = OwnedFile.Basename;
            }
            else
            {
                HoverText = ForcedHoverText;
            }

            OnPaintNeeded();
        }