コード例 #1
0
        SafeUri FindImportDestination(SafeUri uri, DateTime time)
        {
            // Find a new unique location inside the photo folder
            string name = uri.GetFilename();

            var dest_uri = FSpot.Core.Global.PhotoUri.Append(time.Year.ToString())
                           .Append(String.Format("{0:D2}", time.Month))
                           .Append(String.Format("{0:D2}", time.Day));

            EnsureDirectory(dest_uri);

            // If the destination we'd like to use is the file itself return that
            if (dest_uri.Append(name) == uri)
            {
                return(uri);
            }

            // Find an unused name
            int i    = 1;
            var dest = dest_uri.Append(name);
            var file = GLib.FileFactory.NewForUri(dest);

            while (file.Exists)
            {
                var filename  = uri.GetFilenameWithoutExtension();
                var extension = uri.GetExtension();
                dest = dest_uri.Append(String.Format("{0}-{1}{2}", filename, i++, extension));
                file = GLib.FileFactory.NewForUri(dest);
            }

            return(dest);
        }
コード例 #2
0
        public static string GetFilenameWithoutExtension(this SafeUri uri)
        {
            var name  = uri.GetFilename();
            var index = name.LastIndexOf('.');

            return(index > -1 ? name.Substring(0, index) : name);
        }
コード例 #3
0
 public void TestFileUris()
 {
     foreach (var test in tests)
     {
         var suri = new SafeUri(test.Uri);
         Assert.AreEqual(suri.AbsoluteUri, test.AbsoluteUri, String.Format("AbsoluteUri for {0}", test.Uri));
         Assert.AreEqual(suri.GetExtension(), test.Extension, String.Format("Extension for {0}", test.Uri));
         Assert.AreEqual(suri.GetBaseUri().ToString(), test.BaseUri, String.Format("BaseUri for {0}", test.Uri));
         Assert.AreEqual(suri.GetFilename(), test.Filename, String.Format("Filename for {0}", test.Uri));
         Assert.AreEqual(suri.GetFilenameWithoutExtension(), test.FilenameWithoutExtension, String.Format("FilenameWithoutExtension for {0}", test.Uri));
     }
 }
コード例 #4
0
        public void SwitchToFolderSource(SafeUri uri)
        {
            IImportSource source;

            if (!history_sources.TryGetValue(uri, out source))
            {
                var name = uri.GetFilename();
                source = new FileImportSource(uri, name, "folder");
                history_sources[uri] = source;
            }

            PopulateSourceCombo(source);
            Controller.ActiveSource = source;
        }
コード例 #5
0
ファイル: PhotoStore.cs プロジェクト: Yetangitu/f-spot
        public Photo GetByUri(SafeUri uri)
        {
            Photo photo = null;

            var base_uri = uri.GetBaseUri();
            var filename = uri.GetFilename();

            Hyena.Data.Sqlite.IDataReader reader =
                Database.Query(new HyenaSqliteCommand("SELECT id, time, description, roll_id, default_version_id, rating " +
                                                      " FROM photos " +
                                                      " LEFT JOIN photo_versions AS pv ON photos.id = pv.photo_id" +
                                                      " WHERE (photos.base_uri = ? AND photos.filename = ?)" +
                                                      " OR (pv.base_uri = ? AND pv.filename = ?)",
                                                      base_uri.ToString(), filename,
                                                      base_uri.ToString(), filename));

            if (reader.Read())
            {
                photo = new Photo(Convert.ToUInt32(reader ["id"]),
                                  Convert.ToInt64(reader ["time"]));

                photo.Description      = reader["description"].ToString();
                photo.RollId           = Convert.ToUInt32(reader["roll_id"]);
                photo.DefaultVersionId = Convert.ToUInt32(reader["default_version_id"]);
                photo.Rating           = Convert.ToUInt32(reader ["rating"]);
            }

            reader.Dispose();

            if (photo == null)
            {
                return(null);
            }

            Photo cached = LookupInCache(photo.Id);

            if (cached != null)
            {
                return(cached);
            }

            AddToCache(photo);

            GetTags(photo);
            GetVersions(photo);

            return(photo);
        }
コード例 #6
0
ファイル: PhotoStore.cs プロジェクト: ermshiperete/f-spot
        public Photo [] Query(SafeUri uri)
        {
            string filename = uri.GetFilename();

            /* query by file */
            if (!String.IsNullOrEmpty(filename))
            {
                return(Query(new HyenaSqliteCommand(
                                 "SELECT id, " +
                                 "time, " +
                                 "base_uri, " +
                                 "filename, " +
                                 "description, " +
                                 "roll_id, " +
                                 "default_version_id, " +
                                 "rating " +
                                 "FROM photos " +
                                 "WHERE base_uri LIKE ?" +
                                 "AND filename LIKE ?",
                                 uri.GetBaseUri().ToString(),
                                 filename)));
            }

            /* query by directory */
            return(Query(new HyenaSqliteCommand(
                             "SELECT id, " +
                             "time, " +
                             "base_uri, " +
                             "filename, " +
                             "description, " +
                             "roll_id, " +
                             "default_version_id, " +
                             "rating " +
                             "FROM photos " +
                             "WHERE base_uri LIKE ?" +
                             "AND base_uri NOT LIKE ?",
                             uri + "%",
                             uri + "/%/%")));
        }