mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 14:23:19 +02:00
fix history
Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
parent
024e25a62f
commit
93a9bc198d
92
src/vido.cc
92
src/vido.cc
@ -52,7 +52,7 @@ Gtk::ScrolledWindow *scrolled_window2;
|
|||||||
Gtk::Widget *html;
|
Gtk::Widget *html;
|
||||||
GtkWidget *html_wg;
|
GtkWidget *html_wg;
|
||||||
std::vector < std::pair< std::string, std::string > > history;
|
std::vector < std::pair< std::string, std::string > > history;
|
||||||
unsigned int position = 0;
|
int position;
|
||||||
bool historyCall = false;
|
bool historyCall = false;
|
||||||
// variable to keep url of currently displayed article
|
// variable to keep url of currently displayed article
|
||||||
std::string current_url = "";
|
std::string current_url = "";
|
||||||
@ -65,12 +65,12 @@ const zim::File& get_file()
|
|||||||
|
|
||||||
if (!zimFile.good())
|
if (!zimFile.good())
|
||||||
{
|
{
|
||||||
log_debug("file not initialized:" << fileName);
|
// log_debug("file not initialized:" << fileName);
|
||||||
zimFile = zim::File(fileName);
|
zimFile = zim::File(fileName);
|
||||||
log_debug("number of articles: " << zimFile.getCountArticles());
|
// log_debug("number of articles: " << zimFile.getCountArticles());
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("returning file.");
|
// log_debug("returning file.");
|
||||||
return zimFile;
|
return zimFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,29 +116,41 @@ void show_help()
|
|||||||
// fill gtkhtml widget with new content
|
// fill gtkhtml widget with new content
|
||||||
|
|
||||||
void fill_gtkhtml(std::string& html_str, std::string url, std::string title){
|
void fill_gtkhtml(std::string& html_str, std::string url, std::string title){
|
||||||
log_debug("fill gtkhtml called with " << url << " and " << title);
|
log_debug("fill gtkhtml called with " << position << " " << url << " and " << title);
|
||||||
std::string ccontent;
|
std::string ccontent;
|
||||||
ccontent = "<a name=\"top\"></a>" + html_str;
|
ccontent = "<a name=\"top\"></a>" + html_str;
|
||||||
gtk_html_flush(GTK_HTML(html_wg));
|
gtk_html_flush(GTK_HTML(html_wg));
|
||||||
gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
|
gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
|
||||||
current_url = url;
|
current_url = url;
|
||||||
if ((url != "") && title != ""){
|
if ((url != "") && title != ""){
|
||||||
if (position == 0){
|
if ((!historyCall)){
|
||||||
log_debug("adding " << title << " to history");
|
if(position != 0){
|
||||||
|
std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
|
||||||
|
log_debug("history size: " << history.size());
|
||||||
|
for (int d=0; d < history.size(); d++){
|
||||||
|
log_debug("history entry: " << d << " " << history[d].first);
|
||||||
|
}
|
||||||
|
for (int m=history.size()+position; m <= history.size(); m++){
|
||||||
|
log_debug("erasing history: number: "<< m << "title: " << history[m].first);
|
||||||
|
history.erase(iterator+m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_debug("adding " << title << " to history \n" << "position: " << position);
|
||||||
history.push_back( std::make_pair( url, title ) );
|
history.push_back( std::make_pair( url, title ) );
|
||||||
if (history.size() == 11){
|
if (history.size() == 11){
|
||||||
history.erase(history.begin());
|
history.erase(history.begin());
|
||||||
}
|
}
|
||||||
|
log_debug("history size after stuff: " << history.size());
|
||||||
}else{
|
}else{
|
||||||
if (!historyCall){
|
// if (!historyCall){
|
||||||
log_debug("clearing history");
|
// log_debug("clearing history");
|
||||||
std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
|
// std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
|
||||||
for (int m=0; m < position; m++){
|
// for (int m=0; m < position; m++){
|
||||||
history.erase(iterator+m);
|
// history.erase(iterator+m);
|
||||||
}
|
// }
|
||||||
}else{
|
// }else{
|
||||||
historyCall = false;
|
historyCall = false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -157,10 +169,13 @@ void show_history()
|
|||||||
screenblock(1);
|
screenblock(1);
|
||||||
std::string res, url, title;
|
std::string res, url, title;
|
||||||
res += "<ul style=\"list-style-type:none;\">";
|
res += "<ul style=\"list-style-type:none;\">";
|
||||||
|
log_debug("history size: " << history.size());
|
||||||
for(unsigned i=history.size()-1; i > 0; --i)
|
for (int d=0; d < history.size(); d++){
|
||||||
|
log_debug("history entry: " << d << " " << history[d].first);
|
||||||
|
}
|
||||||
|
for(int i=history.size()-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
log_debug("entry: " << i);
|
||||||
#if HAVE_ZIM_QUNICODE_H
|
#if HAVE_ZIM_QUNICODE_H
|
||||||
res += "<li><a href=" + history[i].first + ">" + history[i].second + "</a></li>";
|
res += "<li><a href=" + history[i].first + ">" + history[i].second + "</a></li>";
|
||||||
#else
|
#else
|
||||||
@ -187,15 +202,19 @@ void history_jump(int jumper){
|
|||||||
log_debug("new_pos = " << new_pos);
|
log_debug("new_pos = " << new_pos);
|
||||||
log_debug("history size = " << history.size());
|
log_debug("history size = " << history.size());
|
||||||
if ((new_pos > 0) && (new_pos <= history.size())){
|
if ((new_pos > 0) && (new_pos <= history.size())){
|
||||||
|
// position = new_rel_pos;
|
||||||
historyCall = true;
|
historyCall = true;
|
||||||
std::string url = history[new_pos-1].first;
|
std::string url = history[new_pos-1].first;
|
||||||
log_debug("url is = " << url);
|
log_debug("url is = " << url);
|
||||||
// const char* uri = url.c_str();
|
// const char* uri = url.c_str();
|
||||||
// getArticleFromUrl(const_cast<char*>(url.c_str()), 1);
|
// getArticleFromUrl(const_cast<char*>(url.c_str()), 1);
|
||||||
const char* uri = url.c_str();
|
const char* uri = url.c_str();
|
||||||
getArticleFromUrl(uri, 0);
|
getArticleFromUrl(uri, new_rel_pos);
|
||||||
position = new_rel_pos;
|
position = new_rel_pos;
|
||||||
}
|
}else{
|
||||||
|
log_debug("jump not possible");
|
||||||
|
window2->connect_all();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//UNUSED
|
//UNUSED
|
||||||
@ -214,7 +233,7 @@ void show_random()
|
|||||||
// window2->disconnect_all();
|
// window2->disconnect_all();
|
||||||
|
|
||||||
screenblock(1);
|
screenblock(1);
|
||||||
log_debug("random called. window all disconnected");
|
// log_debug("random called. window all disconnected");
|
||||||
zim::File m = get_file();
|
zim::File m = get_file();
|
||||||
zim::Article article;
|
zim::Article article;
|
||||||
do
|
do
|
||||||
@ -234,12 +253,12 @@ void show_random()
|
|||||||
|
|
||||||
std::string res = article.getPage();
|
std::string res = article.getPage();
|
||||||
|
|
||||||
log_debug("article size=" << res.size());
|
// log_debug("article size=" << res.size());
|
||||||
log_debug("article title=" << article.getTitle());
|
// log_debug("article title=" << article.getTitle());
|
||||||
log_debug("article namespace=" << article.getNamespace());
|
// log_debug("article namespace=" << article.getNamespace());
|
||||||
position = 0;
|
// position = 0;
|
||||||
fill_gtkhtml(res, article.getUrl(), article.getTitle());
|
fill_gtkhtml(res, article.getUrl(), article.getTitle());
|
||||||
log_debug("random called. window all connected");
|
// log_debug("random called. window all connected");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,15 +283,16 @@ void GoToTop()
|
|||||||
|
|
||||||
// // set displayed html to given url
|
// // set displayed html to given url
|
||||||
// // FIXME: returns several articles and displays on one page ... why?
|
// // FIXME: returns several articles and displays on one page ... why?
|
||||||
void getArticleFromUrl(const gchar *url, int pos = 0)
|
void getArticleFromUrl(const gchar *url, int pos)
|
||||||
{
|
{
|
||||||
// TODO unescape url
|
// TODO unescape url
|
||||||
|
|
||||||
// // create ZIM file accessor
|
// // create ZIM file accessor
|
||||||
zim::File m = get_file();
|
zim::File m = get_file();
|
||||||
|
|
||||||
// // convert url to string
|
// // convert url to string
|
||||||
std::string term(url);
|
std::string term;
|
||||||
|
term.assign(url);
|
||||||
|
// log_debug("str url" << term << "\n");
|
||||||
std::string content;
|
std::string content;
|
||||||
// // replace '+' signs with spaces in url
|
// // replace '+' signs with spaces in url
|
||||||
std::replace(term.begin(), term.end(), '+', ' ');
|
std::replace(term.begin(), term.end(), '+', ' ');
|
||||||
@ -315,9 +335,7 @@ void getArticleFromUrl(const gchar *url, int pos = 0)
|
|||||||
if (article.good()) // check if article is really found
|
if (article.good()) // check if article is really found
|
||||||
{
|
{
|
||||||
content = article.getPage();
|
content = article.getPage();
|
||||||
if (pos == 0){
|
position = pos;
|
||||||
position = 0;
|
|
||||||
}
|
|
||||||
fill_gtkhtml(content, article.getUrl(), article.getTitle());
|
fill_gtkhtml(content, article.getUrl(), article.getTitle());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -336,6 +354,7 @@ void getArticleFromUrl(const gchar *url, int pos = 0)
|
|||||||
// // test functions
|
// // test functions
|
||||||
void getArticleFromTitle(const gchar *phrase)
|
void getArticleFromTitle(const gchar *phrase)
|
||||||
{
|
{
|
||||||
|
historyCall = false;
|
||||||
screenblock(1);
|
screenblock(1);
|
||||||
char ns;
|
char ns;
|
||||||
ns = 'A';
|
ns = 'A';
|
||||||
@ -367,6 +386,7 @@ void getArticleFromTitle(const gchar *phrase)
|
|||||||
res = article.getPage(false, 10);
|
res = article.getPage(false, 10);
|
||||||
url = article.getUrl();
|
url = article.getUrl();
|
||||||
title = article.getTitle();
|
title = article.getTitle();
|
||||||
|
log_debug("set article from title position = 0");
|
||||||
position = 0;
|
position = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -408,11 +428,11 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
|
|||||||
term = term.substr(0, found);
|
term = term.substr(0, found);
|
||||||
//TODO make "set_html" func accept anchor name
|
//TODO make "set_html" func accept anchor name
|
||||||
const char* uri = term.c_str();
|
const char* uri = term.c_str();
|
||||||
getArticleFromUrl(uri, 0);
|
getArticleFromUrl(uri, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
getArticleFromUrl(url,0);
|
getArticleFromUrl(url,position);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -460,7 +480,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
window.add(scrolled_window);
|
window.add(scrolled_window);
|
||||||
window.show_all();
|
window.show_all();
|
||||||
|
position = 0;
|
||||||
show_random();
|
show_random();
|
||||||
gtk_html_edit_make_cursor_visible(GTK_HTML(html_wg));
|
gtk_html_edit_make_cursor_visible(GTK_HTML(html_wg));
|
||||||
Gtk::Main::run(window);
|
Gtk::Main::run(window);
|
||||||
|
Loading…
Reference in New Issue
Block a user