comparison src/view_file_list.c @ 814:721c2bbaceec

moved notification to view_file.c
author nadvornik
date Mon, 09 Jun 2008 20:27:39 +0000
parents 7c12beef474a
children a204fc1d1145
comparison
equal deleted inserted replaced
813:7c12beef474a 814:721c2bbaceec
48 48
49 49
50 static gint vflist_row_is_selected(ViewFile *vf, FileData *fd); 50 static gint vflist_row_is_selected(ViewFile *vf, FileData *fd);
51 static gint vflist_row_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data); 51 static gint vflist_row_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data);
52 static void vflist_populate_view(ViewFile *vf); 52 static void vflist_populate_view(ViewFile *vf);
53 static void vflist_notify_cb(FileData *fd, NotifyType type, gpointer data);
54 53
55 54
56 /* 55 /*
57 *----------------------------------------------------------------------------- 56 *-----------------------------------------------------------------------------
58 * misc 57 * misc
1469 GtkTreeIter iter; 1468 GtkTreeIter iter;
1470 1469
1471 gtk_tree_model_get_iter(store, &iter, tpath); 1470 gtk_tree_model_get_iter(store, &iter, tpath);
1472 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); 1471 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1);
1473 1472
1474 file_data_unregister_notify_func(vflist_notify_cb, vf); /* we don't need the notification */ 1473 file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification */
1475 1474
1476 switch (mode) 1475 switch (mode)
1477 { 1476 {
1478 case STM_MODE_SET: file_data_set_mark(fd, n, 1); 1477 case STM_MODE_SET: file_data_set_mark(fd, n, 1);
1479 break; 1478 break;
1481 break; 1480 break;
1482 case STM_MODE_TOGGLE: file_data_set_mark(fd, n, !file_data_get_mark(fd, n)); 1481 case STM_MODE_TOGGLE: file_data_set_mark(fd, n, !file_data_get_mark(fd, n));
1483 break; 1482 break;
1484 } 1483 }
1485 1484
1486 file_data_register_notify_func(vflist_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM); 1485 file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
1487 1486
1488 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_MARKS + n, file_data_get_mark(fd, n), -1); 1487 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_MARKS + n, file_data_get_mark(fd, n), -1);
1489 1488
1490 work = work->next; 1489 work = work->next;
1491 } 1490 }
1586 vf->list = NULL; 1585 vf->list = NULL;
1587 1586
1588 DEBUG_1("%s vflist_refresh: read dir", get_exec_time()); 1587 DEBUG_1("%s vflist_refresh: read dir", get_exec_time());
1589 if (vf->dir_fd) 1588 if (vf->dir_fd)
1590 { 1589 {
1591 file_data_unregister_notify_func(vflist_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */ 1590 file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */
1592 1591
1593 ret = filelist_read(vf->dir_fd, &vf->list, NULL); 1592 ret = filelist_read(vf->dir_fd, &vf->list, NULL);
1594 1593
1595 file_data_register_notify_func(vflist_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM); 1594 file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
1596 1595
1597 DEBUG_1("%s vflist_refresh: sort", get_exec_time()); 1596 DEBUG_1("%s vflist_refresh: sort", get_exec_time());
1598 vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend); 1597 vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend);
1599 } 1598 }
1600 1599
1606 DEBUG_1("%s vflist_refresh: done", get_exec_time()); 1605 DEBUG_1("%s vflist_refresh: done", get_exec_time());
1607 1606
1608 return ret; 1607 return ret;
1609 } 1608 }
1610 1609
1611 static gint vflist_refresh_idle_cb(gpointer data)
1612 {
1613 ViewFile *vf = data;
1614
1615 vflist_refresh(vf);
1616 vf->refresh_idle_id = -1;
1617 return FALSE;
1618 }
1619
1620 static void vflist_refresh_idle_cancel(ViewFile *vf)
1621 {
1622 if (vf->refresh_idle_id != -1) g_source_remove(vf->refresh_idle_id);
1623 vf->refresh_idle_id = -1;
1624 }
1625 1610
1626 1611
1627 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */ 1612 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */
1628 1613
1629 #define CELL_HEIGHT_OVERRIDE 512 1614 #define CELL_HEIGHT_OVERRIDE 512
1728 1713
1729 g_assert(col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST); 1714 g_assert(col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST);
1730 1715
1731 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &mark, -1); 1716 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &mark, -1);
1732 mark = !mark; 1717 mark = !mark;
1733 file_data_unregister_notify_func(vflist_notify_cb, vf); /* we don't need the notification */ 1718 file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification */
1734 file_data_set_mark(fd, col_idx - FILE_COLUMN_MARKS, mark); 1719 file_data_set_mark(fd, col_idx - FILE_COLUMN_MARKS, mark);
1735 file_data_register_notify_func(vflist_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM); 1720 file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
1736 1721
1737 gtk_tree_store_set(store, &iter, col_idx, mark, -1); 1722 gtk_tree_store_set(store, &iter, col_idx, mark, -1);
1738 gtk_tree_path_free(path); 1723 gtk_tree_path_free(path);
1739 } 1724 }
1740 1725
1787 1772
1788 void vflist_destroy_cb(GtkWidget *widget, gpointer data) 1773 void vflist_destroy_cb(GtkWidget *widget, gpointer data)
1789 { 1774 {
1790 ViewFile *vf = data; 1775 ViewFile *vf = data;
1791 1776
1792 file_data_unregister_notify_func(vflist_notify_cb, vf); 1777 file_data_unregister_notify_func(vf_notify_cb, vf);
1793 1778
1794 vflist_select_idle_cancel(vf); 1779 vflist_select_idle_cancel(vf);
1795 vflist_refresh_idle_cancel(vf); 1780 vf_refresh_idle_cancel(vf);
1796 vflist_thumb_stop(vf); 1781 vflist_thumb_stop(vf);
1797 1782
1798 filelist_free(vf->list); 1783 filelist_free(vf->list);
1799 } 1784 }
1800 1785
1811 VFLIST_INFO(vf, click_fd) = NULL; 1796 VFLIST_INFO(vf, click_fd) = NULL;
1812 VFLIST_INFO(vf, select_fd) = NULL; 1797 VFLIST_INFO(vf, select_fd) = NULL;
1813 VFLIST_INFO(vf, thumbs_enabled) = FALSE; 1798 VFLIST_INFO(vf, thumbs_enabled) = FALSE;
1814 1799
1815 VFLIST_INFO(vf, select_idle_id) = -1; 1800 VFLIST_INFO(vf, select_idle_id) = -1;
1816 vf->refresh_idle_id = -1;
1817
1818 1801
1819 flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER; 1802 flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER;
1820 flist_types[FILE_COLUMN_VERSION] = G_TYPE_INT; 1803 flist_types[FILE_COLUMN_VERSION] = G_TYPE_INT;
1821 flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF; 1804 flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF;
1822 flist_types[FILE_COLUMN_NAME] = G_TYPE_STRING; 1805 flist_types[FILE_COLUMN_NAME] = G_TYPE_STRING;
1848 vflist_listview_add_column(vf, FILE_COLUMN_SIDECARS, _("SC"), FALSE, FALSE, FALSE); 1831 vflist_listview_add_column(vf, FILE_COLUMN_SIDECARS, _("SC"), FALSE, FALSE, FALSE);
1849 1832
1850 vflist_listview_add_column(vf, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE); 1833 vflist_listview_add_column(vf, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE);
1851 vflist_listview_add_column(vf, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, FALSE); 1834 vflist_listview_add_column(vf, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, FALSE);
1852 1835
1853 file_data_register_notify_func(vflist_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM); 1836 file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
1854 return vf; 1837 return vf;
1855 } 1838 }
1856 1839
1857 void vflist_thumb_set(ViewFile *vf, gint enable) 1840 void vflist_thumb_set(ViewFile *vf, gint enable)
1858 { 1841 {
1885 1868
1886 g_list_free(columns); 1869 g_list_free(columns);
1887 //vf_refresh(vf); 1870 //vf_refresh(vf);
1888 } 1871 }
1889 1872
1890 /*
1891 *-----------------------------------------------------------------------------
1892 * maintenance (for rename, move, remove)
1893 *-----------------------------------------------------------------------------
1894 */
1895
1896 static void vflist_notify_cb(FileData *fd, NotifyType type, gpointer data)
1897 {
1898 ViewFile *vf = data;
1899 gboolean refresh;
1900
1901 if (vf->refresh_idle_id != -1) return;
1902
1903 refresh = (fd == vf->dir_fd);
1904
1905 if (!refresh)
1906 {
1907 gchar *base = remove_level_from_path(fd->path);
1908 refresh = (strcmp(base, vf->dir_fd->path) == 0);
1909 g_free(base);
1910 }
1911
1912 if (type == NOTIFY_TYPE_CHANGE && fd->change)
1913 {
1914 if (!refresh && fd->change->dest)
1915 {
1916 gchar *dest_base = remove_level_from_path(fd->change->dest);
1917 refresh = (strcmp(dest_base, vf->dir_fd->path) == 0);
1918 g_free(dest_base);
1919 }
1920
1921 if (!refresh && fd->change->source)
1922 {
1923 gchar *source_base = remove_level_from_path(fd->change->source);
1924 refresh = (strcmp(source_base, vf->dir_fd->path) == 0);
1925 g_free(source_base);
1926 }
1927 }
1928
1929 if (refresh && vf->refresh_idle_id == -1)
1930 {
1931 vf->refresh_idle_id = g_idle_add(vflist_refresh_idle_cb, vf);
1932 }
1933 }
1934
1935 #if 0
1936
1937 gint vflist_maint_renamed(ViewFile *vf, FileData *fd)
1938 {
1939 vflist_maint(vf, fd);
1940 return TRUE;
1941 }
1942 gint vflist_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list)
1943 {
1944 vflist_maint(vf, fd);
1945 return TRUE;
1946 }
1947 gint vflist_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list)
1948 {
1949 vflist_maint(vf, fd);
1950 return TRUE;
1951 }
1952
1953
1954 static gint vflist_maint_find_closest(ViewFile *vf, gint row, gint count, GList *ignore_list)
1955 {
1956 GList *list = NULL;
1957 GList *work;
1958 gint rev = row - 1;
1959 row ++;
1960
1961 work = ignore_list;
1962 while (work)
1963 {
1964 gint f = vf_index_by_path(vf, work->data);
1965 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f));
1966 work = work->next;
1967 }
1968
1969 while (list)
1970 {
1971 gint c = TRUE;
1972 work = list;
1973 while (work && c)
1974 {
1975 gpointer p = work->data;
1976 work = work->next;
1977 if (row == GPOINTER_TO_INT(p))
1978 {
1979 row++;
1980 c = FALSE;
1981 }
1982 if (rev == GPOINTER_TO_INT(p))
1983 {
1984 rev--;
1985 c = FALSE;
1986 }
1987 if (!c) list = g_list_remove(list, p);
1988 }
1989 if (c && list)
1990 {
1991 g_list_free(list);
1992 list = NULL;
1993 }
1994 }
1995 if (row > count - 1)
1996 {
1997 if (rev < 0)
1998 return -1;
1999 else
2000 return rev;
2001 }
2002 else
2003 {
2004 return row;
2005 }
2006 }
2007
2008 gint vflist_maint_renamed(ViewFile *vf, FileData *fd)
2009 {
2010 gint ret = FALSE;
2011 gchar *source_base;
2012 gchar *dest_base;
2013
2014 DEBUG_1("%s vflist_maint_renamed: start", get_exec_time());
2015
2016 if (g_list_index(vf->list, fd) < 0) return FALSE;
2017
2018 source_base = remove_level_from_path(fd->change->source);
2019 dest_base = remove_level_from_path(fd->change->dest);
2020
2021
2022 if (strcmp(source_base, dest_base) == 0)
2023 {
2024 GtkTreeStore *store;
2025 GtkTreeIter iter;
2026 GtkTreeIter position;
2027 gint old_row;
2028 gint n;
2029
2030 old_row = g_list_index(vf->list, fd);
2031
2032 vf->list = g_list_remove(vf->list, fd);
2033
2034 vf->list = filelist_insert_sort(vf->list, fd, vf->sort_method, vf->sort_ascend);
2035 n = g_list_index(vf->list, fd);
2036
2037 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
2038 if (vflist_find_row(vf, fd, &iter) >= 0 &&
2039 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &position, NULL, n))
2040 {
2041 if (old_row >= n)
2042 {
2043 gtk_tree_store_move_before(store, &iter, &position);
2044 }
2045 else
2046 {
2047 gtk_tree_store_move_after(store, &iter, &position);
2048 }
2049 }
2050 gtk_tree_store_set(store, &iter, FILE_COLUMN_NAME, fd->name, -1);
2051
2052 ret = TRUE;
2053 }
2054 else
2055 {
2056 ret = vflist_maint_removed(vf, fd, NULL);
2057 }
2058
2059 g_free(source_base);
2060 g_free(dest_base);
2061
2062 DEBUG_1("%s vflist_maint_renamed: done", get_exec_time());
2063
2064 return ret;
2065 }
2066
2067 gint vflist_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list)
2068 {
2069 GtkTreeIter iter;
2070 GList *list;
2071 gint row;
2072 gint new_row = -1;
2073
2074 DEBUG_1("%s vflist_maint_removed: start", get_exec_time());
2075
2076 row = g_list_index(vf->list, fd);
2077 if (row < 0) return FALSE;
2078
2079 if (vflist_index_is_selected(vf, row) &&
2080 layout_image_get_collection(vf->layout, NULL) == NULL)
2081 {
2082 gint n;
2083
2084 n = vf_count(vf, NULL);
2085 if (ignore_list)
2086 {
2087 new_row = vflist_maint_find_closest(vf, row, n, ignore_list);
2088 DEBUG_1("row = %d, closest is %d", row, new_row);
2089 }
2090 else
2091 {
2092 if (row + 1 < n)
2093 {
2094 new_row = row + 1;
2095 }
2096 else if (row > 0)
2097 {
2098 new_row = row - 1;
2099 }
2100 }
2101 vf_select_none(vf);
2102 if (new_row >= 0)
2103 {
2104 fd = vf_index_get_data(vf, new_row);
2105 if (vflist_find_row(vf, fd, &iter) >= 0)
2106 {
2107 GtkTreeSelection *selection;
2108
2109 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
2110 gtk_tree_selection_select_iter(selection, &iter);
2111 vflist_move_cursor(vf, &iter);
2112 }
2113 }
2114 }
2115
2116 fd = vf_index_get_data(vf, row);
2117 if (vflist_find_row(vf, fd, &iter) >= 0)
2118 {
2119 GtkTreeStore *store;
2120 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
2121 gtk_tree_store_remove(store, &iter);
2122 }
2123 list = g_list_nth(vf->list, row);
2124 fd = list->data;
2125
2126 /* thumbnail loader check */
2127 if (fd == vf->thumbs_filedata) vf->thumbs_filedata = NULL;
2128 if (vf->thumbs_count > 0) vf->thumbs_count--;
2129
2130 vf->list = g_list_remove(vf->list, fd);
2131 file_data_unref(fd);
2132
2133 vf_send_update(vf);
2134
2135 DEBUG_1("%s vflist_maint_removed: done", get_exec_time());
2136
2137 return TRUE;
2138 }
2139
2140 gint vflist_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list)
2141 {
2142 gint ret = FALSE;
2143 gchar *buf;
2144
2145 if (!fd->change->source || !vf->path) return FALSE;
2146
2147 buf = remove_level_from_path(fd->change->source);
2148
2149 if (strcmp(buf, vf->path) == 0)
2150 {
2151 ret = vflist_maint_removed(vf, fd, ignore_list);
2152 }
2153
2154 g_free(buf);
2155
2156 return ret;
2157 }
2158 #endif