comparison src/filedata.c @ 751:f73df252aa05

improved filedata interface
author nadvornik
date Sat, 24 May 2008 09:18:09 +0000
parents eda074e91ddd
children 477f48ba28d8
comparison
equal deleted inserted replaced
750:5329797d8ff1 751:f73df252aa05
994 } 994 }
995 return TRUE; 995 return TRUE;
996 } 996 }
997 997
998 998
999 gboolean file_data_sc_add_ci_copy(FileData *fd, gchar *dest_path) 999 gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path)
1000 { 1000 {
1001 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE; 1001 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE;
1002 file_data_sc_update_ci_copy(fd, dest_path); 1002 file_data_sc_update_ci_copy(fd, dest_path);
1003 return TRUE; 1003 return TRUE;
1004 } 1004 }
1005 1005
1006 gboolean file_data_sc_add_ci_move(FileData *fd, gchar *dest_path) 1006 gboolean file_data_sc_add_ci_move(FileData *fd, const gchar *dest_path)
1007 { 1007 {
1008 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE; 1008 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE;
1009 file_data_sc_update_ci_move(fd, dest_path); 1009 file_data_sc_update_ci_move(fd, dest_path);
1010 return TRUE; 1010 return TRUE;
1011 } 1011 }
1012 1012
1013 gboolean file_data_sc_add_ci_rename(FileData *fd, gchar *dest_path) 1013 gboolean file_data_sc_add_ci_rename(FileData *fd, const gchar *dest_path)
1014 { 1014 {
1015 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE; 1015 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE;
1016 file_data_sc_update_ci_rename(fd, dest_path); 1016 file_data_sc_update_ci_rename(fd, dest_path);
1017 return TRUE; 1017 return TRUE;
1018 } 1018 }
1041 file_data_free_ci(sfd); 1041 file_data_free_ci(sfd);
1042 work = work->next; 1042 work = work->next;
1043 } 1043 }
1044 } 1044 }
1045 1045
1046 gboolean file_data_sc_add_ci_delete_list(GList *fd_list)
1047 {
1048 GList *work;
1049 gboolean ret = TRUE;
1050 work = fd_list;
1051 while (work)
1052 {
1053 FileData *fd = work->data;
1054 if (!file_data_sc_add_ci_delete(fd)) ret = FALSE;
1055 work = work->next;
1056 }
1057 return ret;
1058 }
1059
1060 gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest)
1061 {
1062 GList *work;
1063 gboolean ret = TRUE;
1064 work = fd_list;
1065 while (work)
1066 {
1067 FileData *fd = work->data;
1068 if (!file_data_sc_add_ci_copy(fd, dest)) ret = FALSE;
1069 work = work->next;
1070 }
1071 return ret;
1072 }
1073
1074 gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest)
1075 {
1076 GList *work;
1077 gboolean ret = TRUE;
1078 work = fd_list;
1079 while (work)
1080 {
1081 FileData *fd = work->data;
1082 if (!file_data_sc_add_ci_move(fd, dest)) ret = FALSE;
1083 work = work->next;
1084 }
1085 return ret;
1086 }
1087
1088 gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest)
1089 {
1090 GList *work;
1091 gboolean ret = TRUE;
1092 work = fd_list;
1093 while (work)
1094 {
1095 FileData *fd = work->data;
1096 if (!file_data_sc_add_ci_rename(fd, dest)) ret = FALSE;
1097 work = work->next;
1098 }
1099 return ret;
1100 }
1101
1102 void file_data_sc_free_ci_list(GList *fd_list)
1103 {
1104 GList *work;
1105 work = fd_list;
1106 while (work)
1107 {
1108 FileData *fd = work->data;
1109 file_data_sc_free_ci(fd);
1110 work = work->next;
1111 }
1112 }
1046 1113
1047 /* 1114 /*
1048 * update existing fd->change, it will be used from dialog callbacks for interactive editing 1115 * update existing fd->change, it will be used from dialog callbacks for interactive editing
1049 * fails if fd->change does not exist or the change type does not match 1116 * fails if fd->change does not exist or the change type does not match
1050 */ 1117 */
1051 1118
1052 static void file_data_update_ci_dest(FileData *fd, gchar *dest_path) 1119 static void file_data_update_ci_dest(FileData *fd, const gchar *dest_path)
1053 { 1120 {
1054 g_free(fd->change->dest); 1121 g_free(fd->change->dest);
1055 fd->change->dest = g_strdup(dest_path); 1122 fd->change->dest = g_strdup(dest_path);
1056 } 1123 }
1057 1124
1058 static void file_data_update_ci_dest_preserve_ext(FileData *fd, gchar *dest_path) 1125 static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *dest_path)
1059 { 1126 {
1060 const char *extension = extension_from_path(fd->change->source); 1127 const char *extension = extension_from_path(fd->change->source);
1128 gchar *base = remove_extension_from_path(dest_path);
1061 g_free(fd->change->dest); 1129 g_free(fd->change->dest);
1062 fd->change->dest = g_strdup_printf("%*s%s", (int)(extension_from_path(dest_path) - dest_path), dest_path, extension); 1130 fd->change->dest = g_strdup_printf("%s%s", base, extension);
1063 } 1131 g_free(base);
1064 1132 }
1065 static void file_data_sc_update_ci(FileData *fd, gchar *dest_path) 1133
1066 { 1134 static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path)
1067 GList *work; 1135 {
1136 GList *work;
1137 gchar *dest_path_full = NULL;
1068 if (fd->parent) fd = fd->parent; 1138 if (fd->parent) fd = fd->parent;
1139
1140 if (!dest_path) dest_path = fd->path;
1141
1142 if (!strchr(dest_path, G_DIR_SEPARATOR)) /* we got only filename, not a full path */
1143 {
1144 gchar *dir = remove_level_from_path(fd->path);
1145 dest_path_full = g_build_filename(dir, dest_path, NULL);
1146 g_free(dir);
1147 dest_path = dest_path_full;
1148 }
1149
1150 if (isdir(dest_path))
1151 {
1152 dest_path_full = g_build_filename(dest_path, fd->name, NULL);
1153 dest_path = dest_path_full;
1154 }
1155
1069 1156
1070 file_data_update_ci_dest(fd, dest_path); 1157 file_data_update_ci_dest(fd, dest_path);
1071 work = fd->sidecar_files; 1158 work = fd->sidecar_files;
1072 while (work) 1159 while (work)
1073 { 1160 {
1074 FileData *sfd = work->data; 1161 FileData *sfd = work->data;
1075 file_data_update_ci_dest_preserve_ext(sfd, dest_path); 1162 file_data_update_ci_dest_preserve_ext(sfd, dest_path);
1076 work = work->next; 1163 work = work->next;
1077 } 1164 }
1078 } 1165 g_free(dest_path_full);
1079 1166 }
1080 gint file_data_sc_update_ci_copy(FileData *fd, gchar *dest_path) 1167
1168 gint file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path)
1081 { 1169 {
1082 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE; 1170 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE;
1083 file_data_sc_update_ci(fd, dest_path); 1171 file_data_sc_update_ci(fd, dest_path);
1084 return TRUE; 1172 return TRUE;
1085 } 1173 }
1086 1174
1087 gint file_data_sc_update_ci_move(FileData *fd, gchar *dest_path) 1175 gint file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path)
1088 { 1176 {
1089 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE; 1177 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE;
1090 file_data_sc_update_ci(fd, dest_path); 1178 file_data_sc_update_ci(fd, dest_path);
1091 return TRUE; 1179 return TRUE;
1092 } 1180 }
1093 1181
1094 gint file_data_sc_update_ci_rename(FileData *fd, gchar *dest_path) 1182 gint file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path)
1095 { 1183 {
1096 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE; 1184 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE;
1097 file_data_sc_update_ci(fd, dest_path); 1185 file_data_sc_update_ci(fd, dest_path);
1098 return TRUE; 1186 return TRUE;
1099 } 1187 }
1100 1188
1189
1190 gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest)
1191 {
1192 GList *work;
1193 gboolean ret = TRUE;
1194 work = fd_list;
1195 while (work)
1196 {
1197 FileData *fd = work->data;
1198 if (!file_data_sc_update_ci_move(fd, dest)) ret = FALSE;
1199 work = work->next;
1200 }
1201 return ret;
1202 }
1203
1204 gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest)
1205 {
1206 GList *work;
1207 gboolean ret = TRUE;
1208 work = fd_list;
1209 while (work)
1210 {
1211 FileData *fd = work->data;
1212 if (!file_data_sc_update_ci_copy(fd, dest)) ret = FALSE;
1213 work = work->next;
1214 }
1215 return ret;
1216 }
1101 1217
1102 1218
1103 /* 1219 /*
1104 * check dest paths - dest image exists, etc. 1220 * check dest paths - dest image exists, etc.
1105 * returns FIXME 1221 * returns FIXME