~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/sched/history.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Visited URL history managment - NOT goto_url_dialog history! */
2
 
/* $Id: history.c,v 1.82 2004/06/25 09:54:46 jonas Exp $ */
3
 
 
4
 
#ifdef HAVE_CONFIG_H
5
 
#include "config.h"
6
 
#endif
7
 
 
8
 
#include <string.h>
9
 
 
10
 
#include "elinks.h"
11
 
 
12
 
#include "cache/cache.h"
13
 
#include "config/options.h"
14
 
#include "dialogs/status.h"
15
 
#include "protocol/uri.h"
16
 
#include "sched/connection.h"
17
 
#include "sched/history.h"
18
 
#include "sched/location.h"
19
 
#include "sched/session.h"
20
 
#include "sched/task.h"
21
 
#include "util/memory.h"
22
 
#include "util/string.h"
23
 
#include "viewer/text/view.h"
24
 
#include "viewer/text/vs.h"
25
 
 
26
 
 
27
 
static inline void
28
 
free_history(struct list_head *history)
29
 
{
30
 
        while (!list_empty(*history)) {
31
 
                struct location *loc = history->next;
32
 
 
33
 
                del_from_list(loc);
34
 
                destroy_location(loc);
35
 
        }
36
 
}
37
 
 
38
 
 
39
 
void
40
 
create_history(struct ses_history *history)
41
 
{
42
 
        init_list(history->history);
43
 
        history->current = NULL;
44
 
}
45
 
 
46
 
void
47
 
destroy_history(struct ses_history *history)
48
 
{
49
 
        free_history(&history->history);
50
 
        history->current = NULL;
51
 
}
52
 
 
53
 
void
54
 
clean_unhistory(struct ses_history *history)
55
 
{
56
 
        if (!history->current) return;
57
 
 
58
 
        while (list_has_next(history->history, history->current)) {
59
 
                struct location *loc = history->current->next;
60
 
 
61
 
                del_from_list(loc);
62
 
                destroy_location(loc);
63
 
        }
64
 
}
65
 
 
66
 
/* If history->current points to an entry redundant to @loc, remove that
67
 
 * entry. */
68
 
#ifdef BUG_309_FIX
69
 
void
70
 
compress_history(struct ses_history *history, struct location *loc)
71
 
{
72
 
        struct location *current = history->current;
73
 
 
74
 
        assert(current);
75
 
 
76
 
        if (uris_compare(current->vs.uri, loc->vs.uri)
77
 
            || (current->download.cached->redirect
78
 
                && current->download.cached->redirect == loc->vs.uri)) {
79
 
                del_from_history(history, current);
80
 
                destroy_location(current);
81
 
        }
82
 
}
83
 
#endif
84
 
 
85
 
 
86
 
void
87
 
ses_history_move(struct session *ses)
88
 
{
89
 
        struct location *loc;
90
 
 
91
 
        /* Prepare. */
92
 
 
93
 
        free_files(ses);
94
 
        mem_free_set(&ses->search_word, NULL);
95
 
 
96
 
        /* Does it make sense? */
97
 
 
98
 
        if (!have_location(ses) || !ses->task.target_location)
99
 
                return;
100
 
 
101
 
        if (ses->task.target_location
102
 
            == (struct location *) &ses->history.history)
103
 
                return;
104
 
 
105
 
        /* Move. */
106
 
 
107
 
        ses->history.current = ses->task.target_location;
108
 
 
109
 
        loc = cur_loc(ses);
110
 
 
111
 
        /* There can be only one ... */
112
 
        if (compare_uri(loc->vs.uri, ses->loading_uri, 0))
113
 
                return;
114
 
 
115
 
        /* Remake that location. */
116
 
 
117
 
        del_from_history(&ses->history, loc);
118
 
        destroy_location(loc);
119
 
        ses_forward(ses, 0);
120
 
 
121
 
        /* Maybe trash the unhistory. */
122
 
 
123
 
        if (get_opt_bool("document.history.keep_unhistory"))
124
 
                clean_unhistory(&ses->history);
125
 
}
126
 
 
127
 
 
128
 
void
129
 
go_history(struct session *ses, struct location *loc)
130
 
{
131
 
        ses->reloadlevel = CACHE_MODE_NORMAL;
132
 
 
133
 
        if (ses->task.type) {
134
 
                abort_loading(ses, 0);
135
 
                print_screen_status(ses);
136
 
                reload(ses, CACHE_MODE_NORMAL);
137
 
                return;
138
 
        }
139
 
 
140
 
        if (!have_location(ses)
141
 
            || loc == (struct location *) &ses->history.history) {
142
 
                /* There's no history, at most only the current location. */
143
 
                return;
144
 
        }
145
 
 
146
 
        abort_loading(ses, 0);
147
 
 
148
 
        set_session_referrer(ses, NULL);
149
 
 
150
 
        ses_goto(ses, loc->vs.uri, NULL, loc,
151
 
                 CACHE_MODE_ALWAYS, TASK_HISTORY, 0);
152
 
}