예제 #1
0
파일: hash.c 프로젝트: zaenal1234/gtkhash
void gtkhash_hash_file_finish_cb(G_GNUC_UNUSED void *data)
{
	const bool stop = gtkhash_hash_file_get_stop(&hash_priv.file_data);

	switch (gui_get_view()) {
		case GUI_VIEW_FILE: {
			if (stop)
				break;

			for (int i = 0; i < HASH_FUNCS_N; i++) {
				const char *digest = gtkhash_hash_func_get_digest(&hash.funcs[i],
					gui_get_digest_format());
				gtk_entry_set_text(gui.hash_widgets[i].entry_file, digest);
			}

			break;
		}
		case GUI_VIEW_FILE_LIST: {
			g_assert(hash_priv.uris);
			g_assert(hash_priv.uris->data);

			if (stop)
				break;

			for (int i = 0; i < HASH_FUNCS_N; i++) {
				const char *digest = gtkhash_hash_func_get_digest(&hash.funcs[i],
					gui_get_digest_format());
				list_set_digest(hash_priv.uris->data, i, digest);
			}

			g_free(hash_priv.uris->data);
			hash_priv.uris = g_slist_delete_link(hash_priv.uris, hash_priv.uris);
			if (hash_priv.uris) {
				hash_file_start(hash_priv.uris->data);
				return;
			}

			break;
		}
		default:
			g_assert_not_reached();
	}

	gui_set_state(GUI_STATE_IDLE);
}
예제 #2
0
void gtkhash_hash_string(struct hash_func_s *funcs, const char *str,
	const enum digest_format_e format)
{
	g_assert(str);
	g_assert(DIGEST_FORMAT_IS_VALID(format));

	for (int i = 0; i < HASH_FUNCS_N; i++) {
		if (!funcs[i].enabled)
			continue;
		gtkhash_hash_lib_start(&funcs[i]);
		// Assuming this won't take too long
		gtkhash_hash_lib_update(&funcs[i], (const uint8_t *)str, strlen(str));
		gtkhash_hash_lib_finish(&funcs[i]);

		const char *digest = gtkhash_hash_func_get_digest(&funcs[i], format);
		gtkhash_hash_string_finish_cb(funcs[i].id, digest);
	}
}
예제 #3
0
void gtkhash_properties_list_update_digests(struct page_s *page)
{
	GtkTreeModel *model = gtkhash_properties_list_get_model(page);
	GtkListStore *store = gtkhash_properties_list_get_store(page);
	GtkTreeIter iter;

	if (!gtk_tree_model_get_iter_first(model, &iter))
		return;

	do {
		int id;
		gtk_tree_model_get(model, &iter, COL_ID, &id, -1);

		const char *digest = gtkhash_hash_func_get_digest(
			&page->hash_file.funcs[id], DIGEST_FORMAT_HEX_LOWER);
		gtk_list_store_set(store, &iter, COL_DIGEST, digest, -1);
	} while (gtk_tree_model_iter_next(model, &iter));

	gtk_tree_view_columns_autosize(page->treeview);
}
예제 #4
0
void gtkhash_properties_list_check_digests(struct page_s *page)
{
	const char *str_in = gtk_entry_get_text(page->entry_check);
	const char *icon = NULL;

	if (*str_in) {
		for (int i = 0; i < HASH_FUNCS_N; i++) {
			if (!page->hash_file.funcs[i].enabled)
				continue;

			const char *str_out = gtkhash_hash_func_get_digest(
				&page->hash_file.funcs[i], DIGEST_FORMAT_HEX_LOWER);
			if (strcasecmp(str_in, str_out) == 0) {
				icon = GTK_STOCK_YES;
				break;
			}
		}
	}

	gtk_entry_set_icon_from_stock(page->entry_check, GTK_ENTRY_ICON_SECONDARY,
		icon);
}
예제 #5
0
void gtkhash_properties_list_update_enabled(struct page_s *page, char *path_str)
{
	GtkTreeModel *model = gtkhash_properties_list_get_model(page);
	GtkListStore *store = gtkhash_properties_list_get_store(page);
	GtkTreeIter iter;

	gtk_tree_model_get_iter_from_string(model, &iter, path_str);

	int id;
	gboolean enabled;
	gtk_tree_model_get(model, &iter, COL_ID, &id, COL_ENABLED, &enabled, -1);
	enabled = !enabled;
	gtk_list_store_set(store, &iter, COL_ENABLED, enabled, -1);

	if (!enabled) {
		// Clear digest for disabled func
		gtkhash_hash_func_clear_digest(&page->hash_file.funcs[id]);
		const char *digest = gtkhash_hash_func_get_digest(
			&page->hash_file.funcs[id], DIGEST_FORMAT_HEX_LOWER);
		gtk_list_store_set(store, &iter, COL_DIGEST, digest, -1);
	}

	page->hash_file.funcs[id].enabled = enabled;
}
예제 #6
0
void gtkhash_properties_list_init(struct page_s *page)
{
	GtkListStore *store = gtkhash_properties_list_get_store(page);

	for (int i = 0; i < HASH_FUNCS_N; i++) {
		if (!page->hash_file.funcs[i].supported)
			continue;
		const char *digest = gtkhash_hash_func_get_digest(
			&page->hash_file.funcs[i], DIGEST_FORMAT_HEX_LOWER);
		gtk_list_store_insert_with_values(store, NULL, i,
			COL_ID, i,
			COL_ENABLED, page->hash_file.funcs[i].enabled,
			COL_HASH_FUNC, page->hash_file.funcs[i].name,
			COL_DIGEST, digest,
			-1);
	}

	GtkTreeModelFilter *filter = gtkhash_properties_list_get_filter(page);
	gtk_tree_model_filter_set_visible_func(filter,
		(GtkTreeModelFilterVisibleFunc)gtkhash_properties_list_filter, page,
		NULL);

	gtkhash_properties_list_refilter(page);
}