Mercurial > geeqie
comparison src/view_file_icon.c @ 1608:fe9ac4a5c969
Merge common thumb code from view_file_list and view_file_icon to view_file.
author | zas_ |
---|---|
date | Thu, 14 May 2009 20:32:14 +0000 |
parents | c03a8e19a43a |
children | 7d631a8de48e |
comparison
equal
deleted
inserted
replaced
1607:a088801dc7a5 | 1608:fe9ac4a5c969 |
---|---|
1559 gtk_tree_model_foreach(store, vficon_destroy_node_cb, NULL); | 1559 gtk_tree_model_foreach(store, vficon_destroy_node_cb, NULL); |
1560 | 1560 |
1561 gtk_list_store_clear(GTK_LIST_STORE(store)); | 1561 gtk_list_store_clear(GTK_LIST_STORE(store)); |
1562 } | 1562 } |
1563 | 1563 |
1564 static void vficon_set_thumb(ViewFile *vf, FileData *fd) | |
1565 { | |
1566 GtkTreeModel *store; | |
1567 GtkTreeIter iter; | |
1568 GList *list; | |
1569 | |
1570 if (!vficon_find_iter(vf, vficon_icon_data(vf, fd), &iter, NULL)) return; | |
1571 | |
1572 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)); | |
1573 | |
1574 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
1575 gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1); | |
1576 } | |
1577 | |
1578 static GList *vficon_add_row(ViewFile *vf, GtkTreeIter *iter) | 1564 static GList *vficon_add_row(ViewFile *vf, GtkTreeIter *iter) |
1579 { | 1565 { |
1580 GtkListStore *store; | 1566 GtkListStore *store; |
1581 GList *list = NULL; | 1567 GList *list = NULL; |
1582 gint i; | 1568 gint i; |
1725 } | 1711 } |
1726 } | 1712 } |
1727 | 1713 |
1728 | 1714 |
1729 vf_send_update(vf); | 1715 vf_send_update(vf); |
1730 vficon_thumb_update(vf); | 1716 vf_thumb_update(vf); |
1731 } | 1717 } |
1732 | 1718 |
1733 static void vficon_populate_at_new_size(ViewFile *vf, gint w, gint h, gboolean force) | 1719 static void vficon_populate_at_new_size(ViewFile *vf, gint w, gint h, gboolean force) |
1734 { | 1720 { |
1735 gint new_cols; | 1721 gint new_cols; |
1862 *----------------------------------------------------------------------------- | 1848 *----------------------------------------------------------------------------- |
1863 * thumb updates | 1849 * thumb updates |
1864 *----------------------------------------------------------------------------- | 1850 *----------------------------------------------------------------------------- |
1865 */ | 1851 */ |
1866 | 1852 |
1867 static gboolean vficon_thumb_next(ViewFile *vf); | 1853 void vficon_thumb_progress_count(GList *list, gint *count, gint *done) |
1868 | 1854 { |
1869 static gdouble vficon_thumb_progress(ViewFile *vf) | 1855 GList *work = list; |
1870 { | |
1871 gint count = 0; | |
1872 gint done = 0; | |
1873 | |
1874 GList *work = vf->list; | |
1875 while (work) | 1856 while (work) |
1876 { | 1857 { |
1877 IconData *id = work->data; | 1858 IconData *id = work->data; |
1878 FileData *fd = id->fd; | 1859 FileData *fd = id->fd; |
1879 work = work->next; | 1860 work = work->next; |
1880 | 1861 |
1881 if (fd->thumb_pixbuf) done++; | 1862 if (fd->thumb_pixbuf) (*done)++; |
1882 count++; | 1863 (*count)++; |
1883 } | 1864 } |
1884 DEBUG_1("thumb progress: %d of %d", done, count); | 1865 } |
1885 return (gdouble)done / count; | 1866 |
1886 } | 1867 void vficon_set_thumb_fd(ViewFile *vf, FileData *fd) |
1887 | 1868 { |
1888 static void vficon_thumb_status(ViewFile *vf, gdouble val, const gchar *text) | 1869 GtkTreeModel *store; |
1889 { | 1870 GtkTreeIter iter; |
1890 if (vf->func_thumb_status) | 1871 GList *list; |
1891 { | 1872 |
1892 vf->func_thumb_status(vf, val, text, vf->data_thumb_status); | 1873 if (!vficon_find_iter(vf, vficon_icon_data(vf, fd), &iter, NULL)) return; |
1893 } | 1874 |
1894 } | 1875 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)); |
1895 | 1876 |
1896 static void vficon_thumb_cleanup(ViewFile *vf) | 1877 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); |
1897 { | 1878 gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1); |
1898 vficon_thumb_status(vf, 0.0, NULL); | 1879 } |
1899 | 1880 |
1900 vf->thumbs_running = FALSE; | 1881 |
1901 | 1882 FileData *vficon_thumb_next_fd(ViewFile *vf) |
1902 thumb_loader_free(vf->thumbs_loader); | |
1903 vf->thumbs_loader = NULL; | |
1904 | |
1905 vf->thumbs_filedata = NULL; | |
1906 } | |
1907 | |
1908 static void vficon_thumb_stop(ViewFile *vf) | |
1909 { | |
1910 if (vf->thumbs_running) vficon_thumb_cleanup(vf); | |
1911 } | |
1912 | |
1913 static void vficon_thumb_do(ViewFile *vf, ThumbLoader *tl, FileData *fd) | |
1914 { | |
1915 if (!fd) return; | |
1916 | |
1917 vficon_set_thumb(vf, fd); | |
1918 | |
1919 vficon_thumb_status(vf, vficon_thumb_progress(vf), _("Loading thumbs...")); | |
1920 } | |
1921 | |
1922 static void vficon_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1923 { | |
1924 ViewFile *vf = data; | |
1925 | |
1926 if (vf->thumbs_filedata && vf->thumbs_loader == tl) | |
1927 { | |
1928 vficon_thumb_do(vf, tl, vf->thumbs_filedata); | |
1929 } | |
1930 | |
1931 while (vficon_thumb_next(vf)); | |
1932 } | |
1933 | |
1934 static void vficon_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1935 { | |
1936 ViewFile *vf = data; | |
1937 | |
1938 if (vf->thumbs_filedata && vf->thumbs_loader == tl) | |
1939 { | |
1940 vficon_thumb_do(vf, tl, vf->thumbs_filedata); | |
1941 } | |
1942 | |
1943 while (vficon_thumb_next(vf)); | |
1944 } | |
1945 | |
1946 static gboolean vficon_thumb_next(ViewFile *vf) | |
1947 { | 1883 { |
1948 GtkTreePath *tpath; | 1884 GtkTreePath *tpath; |
1949 FileData *fd = NULL; | 1885 FileData *fd = NULL; |
1950 | |
1951 if (!GTK_WIDGET_REALIZED(vf->listview)) | |
1952 { | |
1953 vficon_thumb_status(vf, 0.0, NULL); | |
1954 return FALSE; | |
1955 } | |
1956 | 1886 |
1957 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL)) | 1887 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL)) |
1958 { | 1888 { |
1959 GtkTreeModel *store; | 1889 GtkTreeModel *store; |
1960 GtkTreeIter iter; | 1890 GtkTreeIter iter; |
1994 | 1924 |
1995 if (!fd_p->thumb_pixbuf) fd = fd_p; | 1925 if (!fd_p->thumb_pixbuf) fd = fd_p; |
1996 } | 1926 } |
1997 } | 1927 } |
1998 | 1928 |
1999 if (!fd) | 1929 return fd; |
2000 { | 1930 } |
2001 /* done */ | 1931 |
2002 vficon_thumb_cleanup(vf); | 1932 void vficon_thumb_reset_all(ViewFile *vf) |
2003 return FALSE; | 1933 { |
2004 } | 1934 GList *work = vf->list; |
2005 | 1935 |
2006 vf->thumbs_filedata = fd; | 1936 while (work) |
2007 | 1937 { |
2008 thumb_loader_free(vf->thumbs_loader); | 1938 IconData *id = work->data; |
2009 | 1939 FileData *fd = id->fd; |
2010 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); | 1940 if (fd->thumb_pixbuf) |
2011 thumb_loader_set_callbacks(vf->thumbs_loader, | 1941 { |
2012 vficon_thumb_done_cb, | 1942 g_object_unref(fd->thumb_pixbuf); |
2013 vficon_thumb_error_cb, | 1943 fd->thumb_pixbuf = NULL; |
2014 NULL, | 1944 } |
2015 vf); | 1945 work = work->next; |
2016 | 1946 } |
2017 if (!thumb_loader_start(vf->thumbs_loader, fd)) | 1947 } |
2018 { | 1948 |
2019 /* set icon to unknown, continue */ | |
2020 DEBUG_1("thumb loader start failed %s", fd->path); | |
2021 vficon_thumb_do(vf, vf->thumbs_loader, fd); | |
2022 | |
2023 return TRUE; | |
2024 } | |
2025 | |
2026 return FALSE; | |
2027 } | |
2028 | |
2029 void vficon_thumb_update(ViewFile *vf) | |
2030 { | |
2031 vficon_thumb_stop(vf); | |
2032 | |
2033 vficon_thumb_status(vf, 0.0, _("Loading thumbs...")); | |
2034 vf->thumbs_running = TRUE; | |
2035 | |
2036 if (thumb_format_changed) | |
2037 { | |
2038 GList *work = vf->list; | |
2039 while (work) | |
2040 { | |
2041 IconData *id = work->data; | |
2042 FileData *fd = id->fd; | |
2043 if (fd->thumb_pixbuf) | |
2044 { | |
2045 g_object_unref(fd->thumb_pixbuf); | |
2046 fd->thumb_pixbuf = NULL; | |
2047 } | |
2048 work = work->next; | |
2049 } | |
2050 | |
2051 thumb_format_changed = FALSE; | |
2052 } | |
2053 | |
2054 while (vficon_thumb_next(vf)); | |
2055 } | |
2056 | 1949 |
2057 /* | 1950 /* |
2058 *----------------------------------------------------------------------------- | 1951 *----------------------------------------------------------------------------- |
2059 * row stuff | 1952 * row stuff |
2060 *----------------------------------------------------------------------------- | 1953 *----------------------------------------------------------------------------- |
2454 | 2347 |
2455 file_data_unregister_notify_func(vf_notify_cb, vf); | 2348 file_data_unregister_notify_func(vf_notify_cb, vf); |
2456 | 2349 |
2457 tip_unschedule(vf); | 2350 tip_unschedule(vf); |
2458 | 2351 |
2459 vficon_thumb_cleanup(vf); | 2352 vf_thumb_cleanup(vf); |
2460 | 2353 |
2461 iconlist_free(vf->list); | 2354 iconlist_free(vf->list); |
2462 g_list_free(VFICON(vf)->selection); | 2355 g_list_free(VFICON(vf)->selection); |
2463 } | 2356 } |
2464 | 2357 |