Esempio n. 1
0
        public void Add(SafeUri uri)
        {
            if (ImageFile.HasLoader(uri))
            {
                //Console.WriteLine ("using image loader {0}", uri.ToString ());
                Add(new FilePhoto(uri));
            }
            else
            {
                GLib.FileInfo info = FileFactory.NewForUri(uri).QueryInfo("standard::type,standard::content-type", FileQueryInfoFlags.None, null);

                if (info.FileType == FileType.Directory)
                {
                    new DirectoryLoader(this, uri);
                }
                else
                {
                    // FIXME ugh...
                    if (info.ContentType == "text/xml" ||
                        info.ContentType == "application/xml" ||
                        info.ContentType == "application/rss+xml" ||
                        info.ContentType == "text/plain")
                    {
                        new RssLoader(this, uri);
                    }
                }
            }
        }
Esempio n. 2
0
        public static bool CopyRecursive(this GLib.File source, GLib.File target, GLib.FileCopyFlags flags, GLib.Cancellable cancellable, GLib.FileProgressCallback callback)
        {
            bool result = true;

            GLib.FileType ft = source.QueryFileType(GLib.FileQueryInfoFlags.None, cancellable);

            if (ft != GLib.FileType.Directory)
            {
                Hyena.Log.DebugFormat("Copying \"{0}\" to \"{1}\"", source.Path, target.Path);
                return(source.Copy(target, flags, cancellable, callback));
            }

            if (!target.Exists)
            {
                Hyena.Log.DebugFormat("Creating directory: \"{0}\"", target.Path);
                result = result && target.MakeDirectoryWithParents(cancellable);
            }

            GLib.FileEnumerator fe = source.EnumerateChildren("standard::name", GLib.FileQueryInfoFlags.None, cancellable);
            GLib.FileInfo       fi = fe.NextFile();
            while (fi != null)
            {
                GLib.File source_file = GLib.FileFactory.NewForPath(Path.Combine(source.Path, fi.Name));
                GLib.File target_file = GLib.FileFactory.NewForPath(Path.Combine(target.Path, fi.Name));
                result = result && source_file.CopyRecursive(target_file, flags, cancellable, callback);
                fi     = fe.NextFile();
            }
            fe.Close(cancellable);
            fe.Dispose();
            return(result);
        }
Esempio n. 3
0
 public bool MoveNext()
 {
     current = file_enumerator.NextFile ();
     if (current == null)
         return false;
     return true;
 }
Esempio n. 4
0
        public DemuxVfs(string path)
        {
            file = path.StartsWith("/") ? FileFactory.NewForPath(path) : FileFactory.NewForUri(path);

            if (file.Exists)
            {
                file_info = file.QueryInfo("etag::value,access::can-read,access::can-write", FileQueryInfoFlags.None, null);
            }
        }
Esempio n. 5
0
		public void DirectoriesAppearBeforeFiles ()
		{
			var file = new FileInfo{ Name = "1", FileType = FileType.Directory };
			var dir = new FileInfo{ Name = "1", FileType = FileType.Regular };

			// file, dir
			var result1 = new SortedFileEnumerator (new[]{ file, dir }.GetEnumerator (), true).ToArray ();
			// dir, file
			var result2 = new SortedFileEnumerator (new[]{ dir, file }.GetEnumerator (), true).ToArray ();

			CollectionAssert.AreEqual (new[]{ dir, file }, result1);
			CollectionAssert.AreEqual (new[]{ dir, file }, result2);
		}
Esempio n. 6
0
		public void DirectoriesAppearSorted ()
		{
			var dir1 = new FileInfo{ Name = "1", FileType = FileType.Directory };
			var dir2 = new FileInfo{ Name = "2", FileType = FileType.Directory };

			// 1-2
			var result1 = new SortedFileEnumerator (new[]{ dir1, dir2 }.GetEnumerator (), true).ToArray ();
			// 2-1
			var result2 = new SortedFileEnumerator (new[]{ dir2, dir1 }.GetEnumerator (), true).ToArray ();

			CollectionAssert.AreEqual (new[]{ dir1, dir2 }, result1);
			CollectionAssert.AreEqual (new[]{ dir1, dir2 }, result2);
		}
Esempio n. 7
0
		public void FilesAppearSorted ()
		{
			var file1 = new FileInfo{ Name = "1", FileType = FileType.Regular };
			var file2 = new FileInfo{ Name = "2", FileType = FileType.Regular };

			// 1-2
			var result1 = new SortedFileEnumerator (new[]{ file1, file2 }.GetEnumerator (), true).ToArray ();
			// 2-1
			var result2 = new SortedFileEnumerator (new[]{ file2, file1 }.GetEnumerator (), true).ToArray ();

			CollectionAssert.AreEqual (new[]{ file1, file2 }, result1);
			CollectionAssert.AreEqual (new[]{ file1, file2 }, result2);
		}
Esempio n. 8
0
		public void FilesAreSkippedOnExceptions ()
		{
			var file1 = new FileInfo{ Name = "1", FileType = FileType.Regular };
			var file3 = new FileInfo{ Name = "3", FileType = FileType.Regular };

			var list = new Mock<IEnumerator> ();
			list.Setup (l => l.MoveNext ()).ReturnsInOrder (true, new GException (IntPtr.Zero), true, false);
			list.Setup (l => l.Current).ReturnsInOrder (file1, file3);

			// file, dir
			var result = new SortedFileEnumerator (list.Object, true).ToArray ();

			CollectionAssert.AreEqual (new[]{ file1, file3 }, result);
		}
Esempio n. 9
0
        private void SetupWidgets()
        {
            histogram_expander            = new Expander(Catalog.GetString("Histogram"));
            histogram_expander.Activated += delegate(object sender, EventArgs e) {
                ContextSwitchStrategy.SetHistogramVisible(Context, histogram_expander.Expanded);
                UpdateHistogram();
            };
            histogram_expander.StyleSet += delegate(object sender, StyleSetArgs args) {
                Gdk.Color c = this.Toplevel.Style.Backgrounds[(int)Gtk.StateType.Active];
                histogram.RedColorHint        = (byte)(c.Red / 0xff);
                histogram.GreenColorHint      = (byte)(c.Green / 0xff);
                histogram.BlueColorHint       = (byte)(c.Blue / 0xff);
                histogram.BackgroundColorHint = 0xff;
                UpdateHistogram();
            };
            histogram_image = new Gtk.Image();
            histogram       = new Histogram();
            histogram_expander.Add(histogram_image);

            Add(histogram_expander);

            info_expander            = new Expander(Catalog.GetString("Image Information"));
            info_expander.Activated += (sender, e) => {
                ContextSwitchStrategy.SetInfoBoxVisible(Context, info_expander.Expanded);
            };

            info_table = new Table(head_rows, 2, false)
            {
                BorderWidth = 0
            };

            AddLabelEntry(null, null, null, null,
                          photos => { return(String.Format(Catalog.GetString("{0} Photos"), photos.Length)); });

            AddLabelEntry(null, Catalog.GetString("Name"), null,
                          (photo, file) => { return(photo.Name ?? String.Empty); }, null);

            version_list  = new ListStore(typeof(IPhotoVersion), typeof(string), typeof(bool));
            version_combo = new ComboBox();
            CellRendererText version_name_cell = new CellRendererText();

            version_name_cell.Ellipsize = Pango.EllipsizeMode.End;
            version_combo.PackStart(version_name_cell, true);
            version_combo.SetCellDataFunc(version_name_cell, new CellLayoutDataFunc(VersionNameCellFunc));
            version_combo.Model    = version_list;
            version_combo.Changed += OnVersionComboChanged;

            AddEntry(null, Catalog.GetString("Version"), null, version_combo, 0.5f,
                     (widget, photo, file) => {
                version_list.Clear();
                version_combo.Changed -= OnVersionComboChanged;

                int count = 0;
                foreach (IPhotoVersion version in photo.Versions)
                {
                    version_list.AppendValues(version, version.Name, true);
                    if (version == photo.DefaultVersion)
                    {
                        version_combo.Active = count;
                    }
                    count++;
                }

                if (count <= 1)
                {
                    version_combo.Sensitive   = false;
                    version_combo.TooltipText = Catalog.GetString("(No Edits)");
                }
                else
                {
                    version_combo.Sensitive   = true;
                    version_combo.TooltipText =
                        String.Format(Catalog.GetPluralString("(One Edit)", "({0} Edits)", count - 1),
                                      count - 1);
                }
                version_combo.Changed += OnVersionComboChanged;
            }, null);

            AddLabelEntry("date", Catalog.GetString("Date"), Catalog.GetString("Show Date"),
                          (photo, file) => {
                return(String.Format("{0}{2}{1}",
                                     photo.Time.ToShortDateString(),
                                     photo.Time.ToShortTimeString(),
                                     Environment.NewLine));
            },
                          photos => {
                IPhoto first = photos[photos.Length - 1];
                IPhoto last  = photos[0];
                if (first.Time.Date == last.Time.Date)
                {
                    //Note for translators: {0} is a date, {1} and {2} are times.
                    return(String.Format(Catalog.GetString("On {0} between \n{1} and {2}"),
                                         first.Time.ToShortDateString(),
                                         first.Time.ToShortTimeString(),
                                         last.Time.ToShortTimeString()));
                }
                else
                {
                    return(String.Format(Catalog.GetString("Between {0} \nand {1}"),
                                         first.Time.ToShortDateString(),
                                         last.Time.ToShortDateString()));
                }
            });

            AddLabelEntry("size", Catalog.GetString("Size"), Catalog.GetString("Show Size"),
                          (photo, metadata) => {
                int width  = 0;
                int height = 0;
                if (null != metadata.Properties)
                {
                    width  = metadata.Properties.PhotoWidth;
                    height = metadata.Properties.PhotoHeight;
                }

                if (width != 0 && height != 0)
                {
                    return(String.Format("{0}x{1}", width, height));
                }

                return(Catalog.GetString("(Unknown)"));
            }, null);

            AddLabelEntry("exposure", Catalog.GetString("Exposure"), Catalog.GetString("Show Exposure"),
                          (photo, metadata) => {
                var fnumber       = metadata.ImageTag.FNumber;
                var exposure_time = metadata.ImageTag.ExposureTime;
                var iso_speed     = metadata.ImageTag.ISOSpeedRatings;

                string info = String.Empty;

                if (fnumber.HasValue && fnumber.Value != 0.0)
                {
                    info += String.Format("f/{0:.0} ", fnumber.Value);
                }

                if (exposure_time.HasValue)
                {
                    if (Math.Abs(exposure_time.Value) >= 1.0)
                    {
                        info += String.Format("{0} sec ", exposure_time.Value);
                    }
                    else
                    {
                        info += String.Format("1/{0} sec ", (int)(1 / exposure_time.Value));
                    }
                }

                if (iso_speed.HasValue)
                {
                    info += String.Format("{0}ISO {1}", Environment.NewLine, iso_speed.Value);
                }

                var exif = metadata.ImageTag.Exif;
                if (exif != null)
                {
                    var flash = exif.ExifIFD.GetLongValue(0, (ushort)TagLib.IFD.Tags.ExifEntryTag.Flash);

                    if (flash.HasValue)
                    {
                        if ((flash.Value & 0x01) == 0x01)
                        {
                            info += String.Format(", {0}", Catalog.GetString("flash fired"));
                        }
                        else
                        {
                            info += String.Format(", {0}", Catalog.GetString("flash didn't fire"));
                        }
                    }
                }

                if (info == String.Empty)
                {
                    return(Catalog.GetString("(None)"));
                }

                return(info);
            }, null);

            AddLabelEntry("focal_length", Catalog.GetString("Focal Length"), Catalog.GetString("Show Focal Length"),
                          false, (photo, metadata) => {
                var focal_length = metadata.ImageTag.FocalLength;

                if (focal_length == null)
                {
                    return(Catalog.GetString("(Unknown)"));
                }

                return(String.Format("{0} mm", focal_length.Value));
            }, null);

            AddLabelEntry("camera", Catalog.GetString("Camera"), Catalog.GetString("Show Camera"), false,
                          (photo, metadata) => { return(metadata.ImageTag.Model ?? Catalog.GetString("(Unknown)")); },
                          null);

            AddLabelEntry("creator", Catalog.GetString("Creator"), Catalog.GetString("Show Creator"),
                          (photo, metadata) => { return(metadata.ImageTag.Creator ?? Catalog.GetString("(Unknown)")); },
                          null);

            AddLabelEntry("file_size", Catalog.GetString("File Size"), Catalog.GetString("Show File Size"), false,
                          (photo, metadata) => {
                try {
                    GFile file          = FileFactory.NewForUri(photo.DefaultVersion.Uri);
                    GFileInfo file_info = file.QueryInfo("standard::size", FileQueryInfoFlags.None, null);
                    return(Format.SizeForDisplay(file_info.Size));
                } catch (GLib.GException e) {
                    Hyena.Log.DebugException(e);
                    return(Catalog.GetString("(File read error)"));
                }
            }, null);

            var rating_entry = new RatingEntry {
                HasFrame = false, AlwaysShowEmptyStars = true
            };

            rating_entry.Changed += HandleRatingChanged;
            var rating_align = new Gtk.Alignment(0, 0, 0, 0);

            rating_align.Add(rating_entry);
            AddEntry("rating", Catalog.GetString("Rating"), Catalog.GetString("Show Rating"), rating_align, false,
                     (widget, photo, metadata) => { ((widget as Alignment).Child as RatingEntry).Value = (int)photo.Rating; },
                     null);

            AddEntry("tag", null, Catalog.GetString("Show Tags"), new TagView(), false,
                     (widget, photo, metadata) => { (widget as TagView).Current = photo; }, null);

            UpdateTable();

            EventBox eb = new EventBox();

            eb.Add(info_table);
            info_expander.Add(eb);
            eb.ButtonPressEvent += HandleButtonPressEvent;

            Add(info_expander);
        }
Esempio n. 10
0
        static void gtml_reload()
        {
            GLib.IFile   applications = GLib.FileFactory.NewForPath("./gtml");
            GLib.KeyFile programs     = new GLib.KeyFile();
            bool         load         = false;

            if (GLib.FileFactory.NewForPath("./data").Exists)
            {
                if (GLib.FileFactory.NewForPath("./data/programs.gkf").Exists)
                {
                    load = programs.LoadFromFile("./data/programs.gkf", gkfflags);
                }
            }
            else
            {
                GLib.FileFactory.NewForPath("./data").MakeDirectoryWithParents(null);
            }
            if (load == true)
            {
                if (programs.HasGroup("Programs"))
                {
                    string[] names = programs.GetKeys("Programs");
                    int      x     = 0;
                    while (names[x].Equals("") != true || names[x] != null)
                    {
                        string location = programs.GetString("Programs", names[x]);
                        create_stacks(names[x], location);
                        location = null;
                        x++;
                        break;
                    }
                }
                else
                {
                    System.Console.WriteLine("No linked programs in data.");
                }
            }
            else
            {
                System.Console.WriteLine("No linked programs\n");
            }

            GLib.FileEnumerator apps = applications.EnumerateChildren("*", feflags, null);
            while (true)
            {
                GLib.FileInfo info = apps.NextFile();
                if (info == null)
                {
                    apps.Dispose();
                    break;
                }
                else
                {
                    GLib.IFile outf = applications.GetChildForDisplayName(info.DisplayName);
                    string     name = info.DisplayName;
                    if ((name.Equals(".") && name.Equals("..")) == false && (name.Length != 0 || name != null))
                    {
                        string path = outf.Path;
                        if (info.FileType == GLib.FileType.Directory)
                        {
                            create_stacks(name, path);

                            /*
                             * if (!gtk_stack_get_child_by_name (GTK_STACK(stack),path)) {
                             *      create_stacks (name,path);
                             * }
                             *
                             *
                             *
                             *
                             */
                        }
                    }
                }
            }

            if (stack.CurrentPageWidget == null)
            {
                ;                                             //gtml_import_full ();
            }
        }
Esempio n. 11
0
    private void UpdateDetailsBox()
    {
        if (detailsBox.Visible)
        {
            FileNode  active     = slices.ActiveSlice.GetActiveNode();
            GLib.File activeFile = GLib.FileFactory.NewForPath(active.File);
            if (!active.IsDirectory)
            {
                detailLabelContents.Visible = false;
                detailValueContents.Visible = false;


                detailEntryName.Text = active.FileName;


                String        infoString = "standard::size,standard::content-type,filesystem:free,time::modified,time::access,owner::user,owner::group";
                GLib.FileInfo info       = activeFile.QueryInfo(infoString, FileQueryInfoFlags.None, null);

                String sizeString = info.GetAttributeAsString("standard::size");
                detailValueSize.Text = String.Format(new FileSizeFormatProvider(), "{0:fs}", Convert.ToUInt64(sizeString));

                detailValueType.Text = Gnome.Vfs.Mime.GetDescription(info.ContentType) + " (" + info.ContentType + ")";

                DateTime tempTime = NodeManager.ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::access")));
                detailValueAccessed.Text = tempTime.ToString("ddd, dd MMM yyyy HH':'mm':'ss");

                tempTime = NodeManager.ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::modified")));
                detailValueModified.Text = tempTime.ToString("ddd, dd MMM yyyy HH':'mm':'ss");

                detailValueSpace.Text = String.Format(new FileSizeFormatProvider(), "{0:fs}",
                                                      Convert.ToUInt64(info.GetAttributeString("filesystem:free")));

                detailValueOwner.Text = info.GetAttributeString("owner::user");
                detailValueGroup.Text = info.GetAttributeString("owner::group");
            }
            else
            {
                detailLabelContents.Visible = true;
                detailValueContents.Visible = true;
                detailValueSize.Text        = "[unsupported]";

                detailEntryName.Text = active.FileName;
                detailValueType.Text = "Directory";

                String        infoString = "time::modified,time::access,owner::user,owner::group";
                GLib.FileInfo info       = activeFile.QueryInfo(infoString, FileQueryInfoFlags.None, null);

                DateTime tempTime = NodeManager.ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::access")));
                detailValueAccessed.Text = tempTime.ToString("ddd, dd MMM yyyy HH':'mm':'ss");

                tempTime = NodeManager.ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::modified")));
                detailValueModified.Text = tempTime.ToString("ddd, dd MMM yyyy HH':'mm':'ss");


                detailValueContents.Text = active.NumChildren + " items (" + active.NumDirs + " folders)";

                detailValueOwner.Text = info.GetAttributeString("owner::user");
                detailValueGroup.Text = info.GetAttributeString("owner::group");
            }
            Mono.Unix.Native.Statvfs fsbuf = new Mono.Unix.Native.Statvfs();
            Mono.Unix.Native.Syscall.statvfs(slices.ActiveSlice.GetActiveNode().File, out fsbuf);


            detailValueSpace.Text = String.Format(new FileSizeFormatProvider(), "{0:fs}", fsbuf.f_bavail * fsbuf.f_bsize);
            UpdateDetailPermissions();
            if (detailValueOwner.Text == Mono.Unix.UnixUserInfo.GetRealUser().UserName)
            {
                EnableDetailPermissions(true);
            }
            else
            {
                EnableDetailPermissions(false);
            }
        }
    }