comparison src/filedata.c @ 1224:ebfd305d902e

improved sidecar writting private metadata can be saved in xmp format
author nadvornik
date Fri, 26 Dec 2008 14:12:36 +0000
parents 31dc2f240afb
children 2df7be0cd20b
comparison
equal deleted inserted replaced
1223:18d08b10b80e 1224:ebfd305d902e
659 659
660 if (fd) 660 if (fd)
661 fd->change = NULL; 661 fd->change = NULL;
662 } 662 }
663 663
664 664 static gboolean file_data_can_write_directly(FileData *fd)
665 {
666 return (filter_file_class(fd->extension, FORMAT_CLASS_IMAGE));
667 /* FIXME: detect what exiv2 really supports */
668 }
669
670 static gboolean file_data_can_write_sidecar(FileData *fd)
671 {
672 return (filter_file_class(fd->extension, FORMAT_CLASS_RAWIMAGE));
673 /* FIXME: detect what exiv2 really supports */
674 }
675
676 gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only)
677 {
678 gchar *sidecar_path = NULL;
679 GList *work;
680 if (!file_data_can_write_sidecar(fd)) return NULL;
681
682 work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
683 while (work)
684 {
685 FileData *sfd = work->data;
686 work = work->next;
687 if (strcasecmp(sfd->extension, ".xmp") == 0)
688 {
689 sidecar_path = g_strdup(sfd->path);
690 break;
691 }
692 }
693
694 if (!existing_only && !sidecar_path)
695 {
696 gchar *base = remove_extension_from_path(fd->path);
697 sidecar_path = g_strconcat(base, ".xmp", NULL);
698 g_free(base);
699 }
700
701 return sidecar_path;
702 }
665 703
666 704
667 /* 705 /*
668 *----------------------------------------------------------------------------- 706 *-----------------------------------------------------------------------------
669 * sidecar file info struct 707 * sidecar file info struct
1685 { 1723 {
1686 DEBUG_1("Change checked: no change info: %s", fd->path); 1724 DEBUG_1("Change checked: no change info: %s", fd->path);
1687 return ret; 1725 return ret;
1688 } 1726 }
1689 1727
1690 if (!isname(fd->path) && 1728 if (!isname(fd->path))
1691 !filter_file_class(fd->extension, FORMAT_CLASS_META)) /* xmp sidecar can be eventually created from scratch */
1692 { 1729 {
1693 /* this probably should not happen */ 1730 /* this probably should not happen */
1694 ret |= CHANGE_NO_SRC; 1731 ret |= CHANGE_NO_SRC;
1695 DEBUG_1("Change checked: file does not exist: %s", fd->path); 1732 DEBUG_1("Change checked: file does not exist: %s", fd->path);
1696 return ret; 1733 return ret;
1719 ret |= CHANGE_WARN_NO_WRITE_PERM; 1756 ret |= CHANGE_WARN_NO_WRITE_PERM;
1720 DEBUG_1("Change checked: no write permission: %s", fd->path); 1757 DEBUG_1("Change checked: no write permission: %s", fd->path);
1721 } 1758 }
1722 /* WRITE_METADATA is special because it can be configured to silently write to ~/.geeqie/... 1759 /* WRITE_METADATA is special because it can be configured to silently write to ~/.geeqie/...
1723 - that means that there are no hard errors and warnings can be disabled 1760 - that means that there are no hard errors and warnings can be disabled
1761 - the destination is determined during the check
1724 */ 1762 */
1725 else if (fd->change->type == FILEDATA_CHANGE_WRITE_METADATA && 1763 else if (fd->change->type == FILEDATA_CHANGE_WRITE_METADATA)
1726 options->metadata.save_in_image_file && options->metadata.warn_on_write_problems) 1764 {
1727 { 1765 /* determine destination file */
1728 if (isname(fd->path) && !access_file(fd->path, W_OK)) 1766 gboolean have_dest = FALSE;
1729 { 1767 gchar *dest_dir = NULL;
1730 ret |= CHANGE_WARN_NO_WRITE_PERM; 1768
1731 DEBUG_1("Change checked: file is readonly: %s", fd->path); 1769 if (options->metadata.save_in_image_file)
1732 } 1770 {
1733 1771 if (file_data_can_write_directly(fd))
1734 else if (!access_file(dir, W_OK)) 1772 {
1735 { 1773 /* we can write the file directly */
1736 ret |= CHANGE_WARN_NO_WRITE_PERM; 1774 if (access_file(fd->path, W_OK))
1737 DEBUG_1("Change checked: dir is readonly: %s", fd->path); 1775 {
1738 } 1776 have_dest = TRUE;
1739 } 1777 }
1740 1778 else
1741 if (fd->change->dest) 1779 {
1780 if (options->metadata.warn_on_write_problems)
1781 {
1782 ret |= CHANGE_WARN_NO_WRITE_PERM;
1783 DEBUG_1("Change checked: file is not writable: %s", fd->path);
1784 }
1785 }
1786 }
1787 else if (file_data_can_write_sidecar(fd))
1788 {
1789 /* we can write sidecar */
1790 gchar *sidecar = file_data_get_sidecar_path(fd, FALSE);
1791 if (access_file(sidecar, W_OK) || (!isname(sidecar) && access_file(dir, W_OK)))
1792 {
1793 file_data_update_ci_dest(fd, sidecar);
1794 have_dest = TRUE;
1795 }
1796 else
1797 {
1798 if (options->metadata.warn_on_write_problems)
1799 {
1800 ret |= CHANGE_WARN_NO_WRITE_PERM;
1801 DEBUG_1("Change checked: file is not writable: %s", sidecar);
1802 }
1803 }
1804 g_free(sidecar);
1805 }
1806 }
1807
1808 if (!have_dest)
1809 {
1810 /* write private metadata file under ~/.geeqie */
1811
1812 /* If an existing metadata file exists, we will try writing to
1813 * it's location regardless of the user's preference.
1814 */
1815 gchar *metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
1816 if (!metadata_path) metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
1817
1818 if (metadata_path && !access_file(metadata_path, W_OK))
1819 {
1820 g_free(metadata_path);
1821 metadata_path = NULL;
1822 }
1823
1824 if (!metadata_path)
1825 {
1826 mode_t mode = 0755;
1827
1828 dest_dir = cache_get_location(CACHE_TYPE_METADATA, fd->path, FALSE, &mode);
1829 if (recursive_mkdir_if_not_exists(dest_dir, mode))
1830 {
1831 gchar *filename = g_strconcat(fd->name, options->metadata.save_legacy_format ? GQ_CACHE_EXT_METADATA : GQ_CACHE_EXT_XMP_METADATA, NULL);
1832
1833 metadata_path = g_build_filename(dest_dir, filename, NULL);
1834 g_free(filename);
1835 }
1836 }
1837 if (access_file(metadata_path, W_OK) || (!isname(metadata_path) && access_file(dest_dir, W_OK)))
1838 {
1839 file_data_update_ci_dest(fd, metadata_path);
1840 have_dest = TRUE;
1841 }
1842 else
1843 {
1844 ret |= CHANGE_NO_WRITE_PERM_DEST;
1845 DEBUG_1("Change checked: file is not writable: %s", metadata_path);
1846 }
1847 g_free(metadata_path);
1848 }
1849 g_free(dest_dir);
1850 }
1851
1852 if (fd->change->dest && fd->change->type != FILEDATA_CHANGE_WRITE_METADATA)
1742 { 1853 {
1743 gboolean same; 1854 gboolean same;
1744 gchar *dest_dir; 1855 gchar *dest_dir;
1745 1856
1746 same = (strcmp(fd->path, fd->change->dest) == 0); 1857 same = (strcmp(fd->path, fd->change->dest) == 0);