Skip to content

Commit

Permalink
Merge pull request #1256 from itzexor/text-previews-removal
Browse files Browse the repository at this point in the history
remove "Show text in icon" preference
  • Loading branch information
clefebvre committed Aug 17, 2016
2 parents eb4df87 + 70753fa commit f7b9fd7
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 751 deletions.
260 changes: 0 additions & 260 deletions libnemo-private/nemo-directory-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@
/* Keep async. jobs down to this number for all directories. */
#define MAX_ASYNC_JOBS 10

struct TopLeftTextReadState {
NemoDirectory *directory;
NemoFile *file;
gboolean large;
GCancellable *cancellable;
};

struct LinkInfoReadState {
NemoDirectory *directory;
GCancellable *cancellable;
Expand Down Expand Up @@ -518,18 +511,6 @@ mime_list_cancel (NemoDirectory *directory)
}
}

static void
top_left_cancel (NemoDirectory *directory)
{
if (directory->details->top_left_read_state != NULL) {
g_cancellable_cancel (directory->details->top_left_read_state->cancellable);
directory->details->top_left_read_state->directory = NULL;
directory->details->top_left_read_state = NULL;

async_job_end (directory, "top left");
}
}

static void
link_info_cancel (NemoDirectory *directory)
{
Expand Down Expand Up @@ -686,16 +667,6 @@ nemo_directory_set_up_request (NemoFileAttributes file_attributes)
REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
REQUEST_SET_TYPE (request, REQUEST_LINK_INFO);
}

if (file_attributes & NEMO_FILE_ATTRIBUTE_TOP_LEFT_TEXT) {
REQUEST_SET_TYPE (request, REQUEST_TOP_LEFT_TEXT);
REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
}

if (file_attributes & NEMO_FILE_ATTRIBUTE_LARGE_TOP_LEFT_TEXT) {
REQUEST_SET_TYPE (request, REQUEST_LARGE_TOP_LEFT_TEXT);
REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
}

if ((file_attributes & NEMO_FILE_ATTRIBUTE_EXTENSION_INFO) != 0) {
REQUEST_SET_TYPE (request, REQUEST_EXTENSION_INFO);
Expand Down Expand Up @@ -1575,11 +1546,6 @@ nemo_async_destroying_file (NemoFile *file)
directory->details->get_info_file = NULL;
changed = TRUE;
}
if (directory->details->top_left_read_state != NULL
&& directory->details->top_left_read_state->file == file) {
directory->details->top_left_read_state->file = NULL;
changed = TRUE;
}
if (directory->details->link_info_read_state != NULL &&
directory->details->link_info_read_state->file == file) {
directory->details->link_info_read_state->file = NULL;
Expand Down Expand Up @@ -1628,22 +1594,6 @@ should_get_directory_count_now (NemoFile *file)
&& !file->details->loading_directory;
}

static gboolean
lacks_top_left (NemoFile *file)
{
return file->details->file_info_is_up_to_date &&
!file->details->top_left_text_is_up_to_date
&& nemo_file_should_get_top_left_text (file);
}

static gboolean
lacks_large_top_left (NemoFile *file)
{
return file->details->file_info_is_up_to_date &&
(!file->details->top_left_text_is_up_to_date ||
file->details->got_large_top_left_text != file->details->got_top_left_text)
&& nemo_file_should_get_top_left_text (file);
}
static gboolean
lacks_info (NemoFile *file)
{
Expand Down Expand Up @@ -1772,18 +1722,6 @@ request_is_satisfied (NemoDirectory *directory,
}
}

if (REQUEST_WANTS_TYPE (request, REQUEST_TOP_LEFT_TEXT)) {
if (has_problem (directory, file, lacks_top_left)) {
return FALSE;
}
}

if (REQUEST_WANTS_TYPE (request, REQUEST_LARGE_TOP_LEFT_TEXT)) {
if (has_problem (directory, file, lacks_large_top_left)) {
return FALSE;
}
}

if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT)) {
if (has_problem (directory, file, lacks_deep_count)) {
return FALSE;
Expand Down Expand Up @@ -3234,185 +3172,6 @@ mime_list_start (NemoDirectory *directory,
g_object_unref (location);
}

static void
top_left_stop (NemoDirectory *directory)
{
NemoFile *file;

if (directory->details->top_left_read_state != NULL) {
file = directory->details->top_left_read_state->file;
if (file != NULL) {
g_assert (NEMO_IS_FILE (file));
g_assert (file->details->directory == directory);
if (is_needy (file,
lacks_top_left,
REQUEST_TOP_LEFT_TEXT) ||
is_needy (file,
lacks_large_top_left,
REQUEST_LARGE_TOP_LEFT_TEXT)) {
return;
}
}

/* The top left is not wanted, so stop it. */
top_left_cancel (directory);
}
}

static void
top_left_read_state_free (TopLeftTextReadState *state)
{
g_object_unref (state->cancellable);
g_free (state);
}

static void
top_left_read_callback (GObject *source_object,
GAsyncResult *res,
gpointer callback_data)
{
TopLeftTextReadState *state;
NemoDirectory *directory;
NemoFileDetails *file_details;
gsize file_size;
char *file_contents;

state = callback_data;

if (state->directory == NULL) {
/* Operation was cancelled. Bail out */
top_left_read_state_free (state);
return;
}

directory = nemo_directory_ref (state->directory);

file_details = state->file->details;

file_details->top_left_text_is_up_to_date = TRUE;
g_free (file_details->top_left_text);

if (g_file_load_partial_contents_finish (G_FILE (source_object),
res,
&file_contents, &file_size,
NULL, NULL)) {
file_details->top_left_text = nemo_extract_top_left_text (file_contents, state->large, file_size);
file_details->got_top_left_text = TRUE;
file_details->got_large_top_left_text = state->large;
g_free (file_contents);
} else {
file_details->top_left_text = NULL;
file_details->got_top_left_text = FALSE;
file_details->got_large_top_left_text = FALSE;
}

nemo_file_changed (state->file);

directory->details->top_left_read_state = NULL;
async_job_end (directory, "top left");

top_left_read_state_free (state);

nemo_directory_async_state_changed (directory);

nemo_directory_unref (directory);
}

static int
count_lines (const char *text, int length)
{
int count, i;

count = 0;
for (i = 0; i < length; i++) {
count += *text++ == '\n';
}
return count;
}

static gboolean
top_left_read_more_callback (const char *file_contents,
goffset bytes_read,
gpointer callback_data)
{
TopLeftTextReadState *state;

state = callback_data;

/* Stop reading when we have enough. */
if (state->large) {
return bytes_read < NEMO_FILE_LARGE_TOP_LEFT_TEXT_MAXIMUM_BYTES &&
count_lines (file_contents, bytes_read) <= NEMO_FILE_LARGE_TOP_LEFT_TEXT_MAXIMUM_LINES;
} else {
return bytes_read < NEMO_FILE_TOP_LEFT_TEXT_MAXIMUM_BYTES &&
count_lines (file_contents, bytes_read) <= NEMO_FILE_TOP_LEFT_TEXT_MAXIMUM_LINES;
}
}

static void
top_left_start (NemoDirectory *directory,
NemoFile *file,
gboolean *doing_io)
{
GFile *location;
gboolean needs_large;
TopLeftTextReadState *state;

if (directory->details->top_left_read_state != NULL) {
*doing_io = TRUE;
return;
}

needs_large = FALSE;

if (is_needy (file,
lacks_large_top_left,
REQUEST_LARGE_TOP_LEFT_TEXT)) {
needs_large = TRUE;
}

/* Figure out which file to read the top left for. */
if (!(needs_large ||
is_needy (file,
lacks_top_left,
REQUEST_TOP_LEFT_TEXT))) {
return;
}
*doing_io = TRUE;

if (!nemo_file_contains_text (file)) {
g_free (file->details->top_left_text);
file->details->top_left_text = NULL;
file->details->got_top_left_text = FALSE;
file->details->got_large_top_left_text = FALSE;
file->details->top_left_text_is_up_to_date = TRUE;

nemo_directory_async_state_changed (directory);
return;
}

if (!async_job_start (directory, "top left")) {
return;
}

/* Start reading. */
state = g_new0 (TopLeftTextReadState, 1);
state->directory = directory;
state->cancellable = g_cancellable_new ();
state->large = needs_large;
state->file = file;

directory->details->top_left_read_state = state;

location = nemo_file_get_location (file);
g_file_load_partial_contents_async (location,
state->cancellable,
top_left_read_more_callback,
top_left_read_callback,
state);
g_object_unref (location);
}

static void
get_info_state_free (GetInfoState *state)
{
Expand Down Expand Up @@ -4544,7 +4303,6 @@ start_or_stop_io (NemoDirectory *directory)
directory_count_stop (directory);
deep_count_stop (directory);
mime_list_stop (directory);
top_left_stop (directory);
link_info_stop (directory);
extension_info_stop (directory);
mount_stop (directory);
Expand Down Expand Up @@ -4576,7 +4334,6 @@ start_or_stop_io (NemoDirectory *directory)
directory_count_start (directory, file, &doing_io);
deep_count_start (directory, file, &doing_io);
mime_list_start (directory, file, &doing_io);
top_left_start (directory, file, &doing_io);
thumbnail_start (directory, file, &doing_io);
filesystem_info_start (directory, file, &doing_io);

Expand Down Expand Up @@ -4646,7 +4403,6 @@ nemo_directory_cancel (NemoDirectory *directory)
link_info_cancel (directory);
mime_list_cancel (directory);
new_files_cancel (directory);
top_left_cancel (directory);
extension_info_cancel (directory);
thumbnail_cancel (directory);
mount_cancel (directory);
Expand Down Expand Up @@ -4690,16 +4446,6 @@ cancel_mime_list_for_file (NemoDirectory *directory,
}
}

static void
cancel_top_left_text_for_file (NemoDirectory *directory,
NemoFile *file)
{
if (directory->details->top_left_read_state != NULL &&
directory->details->top_left_read_state->file == file) {
top_left_cancel (directory);
}
}

static void
cancel_file_info_for_file (NemoDirectory *directory,
NemoFile *file)
Expand Down Expand Up @@ -4767,9 +4513,6 @@ cancel_loading_attributes (NemoDirectory *directory,
if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
mime_list_cancel (directory);
}
if (REQUEST_WANTS_TYPE (request, REQUEST_TOP_LEFT_TEXT)) {
top_left_cancel (directory);
}
if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
file_info_cancel (directory);
}
Expand Down Expand Up @@ -4815,9 +4558,6 @@ nemo_directory_cancel_loading_file_attributes (NemoDirectory *directory,
if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
cancel_mime_list_for_file (directory, file);
}
if (REQUEST_WANTS_TYPE (request, REQUEST_TOP_LEFT_TEXT)) {
cancel_top_left_text_for_file (directory, file);
}
if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
cancel_file_info_for_file (directory, file);
}
Expand Down
5 changes: 0 additions & 5 deletions libnemo-private/nemo-directory-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <libxml/tree.h>

typedef struct LinkInfoReadState LinkInfoReadState;
typedef struct TopLeftTextReadState TopLeftTextReadState;
typedef struct FileMonitors FileMonitors;
typedef struct DirectoryLoadState DirectoryLoadState;
typedef struct DirectoryCountState DirectoryCountState;
Expand All @@ -51,8 +50,6 @@ typedef enum {
REQUEST_FILE_INFO,
REQUEST_FILE_LIST, /* always FALSE if file != NULL */
REQUEST_MIME_LIST,
REQUEST_TOP_LEFT_TEXT,
REQUEST_LARGE_TOP_LEFT_TEXT,
REQUEST_EXTENSION_INFO,
REQUEST_THUMBNAIL,
REQUEST_MOUNT,
Expand Down Expand Up @@ -128,8 +125,6 @@ struct NemoDirectoryDetails
MountState *mount_state;

FilesystemInfoState *filesystem_info_state;

TopLeftTextReadState *top_left_read_state;

LinkInfoReadState *link_info_read_state;

Expand Down
Loading

0 comments on commit f7b9fd7

Please sign in to comment.